mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
Kernel/Graphics: Bring back the mmap interface for DisplayConnectors
The mmap interface was removed when we introduced the DisplayConnector class, as it was quite unsafe to use and didn't handle switching between graphical and text modes safely. By using the SharedFramebufferVMObject, we are able to elegantly coordinate the switch by remapping the attached mmap'ed-Memory::Region(s) with different mappings, therefore, keeping WindowServer to think that the mappings it has are still valid, while they are going to a different physical range until we are back to the graphical mode (after a switch from text mode). Most drivers take advantage of the fact that we know where is the actual framebuffer in physical memory space, the SharedFramebufferVMObject is created with that information. However, the VirtIO driver is different in that aspect, because it relies on DMA transactions to show graphics on the framebuffer, so the SharedFramebufferVMObject is created with that mindset to support the arbitrary framebuffer location in physical memory space.
This commit is contained in:
parent
3d22917548
commit
e2ed6ef741
19 changed files with 309 additions and 341 deletions
|
@ -29,20 +29,15 @@ class VirtIODisplayConnector final : public DisplayConnector {
|
|||
friend class Graphics::VirtIOGPU::Console;
|
||||
friend class DeviceManagement;
|
||||
|
||||
private:
|
||||
struct Buffer {
|
||||
size_t framebuffer_offset { 0 };
|
||||
u8* framebuffer_data { nullptr };
|
||||
Graphics::VirtIOGPU::Protocol::Rect dirty_rect {};
|
||||
Graphics::VirtIOGPU::ResourceID resource_id { 0 };
|
||||
};
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<VirtIODisplayConnector> must_create(VirtIOGraphicsAdapter& graphics_adapter, Graphics::VirtIOGPU::ScanoutID scanout_id);
|
||||
|
||||
void set_edid_bytes(Badge<VirtIOGraphicsAdapter>, Array<u8, 128> const& edid_bytes);
|
||||
void set_safe_mode_setting_after_initialization(Badge<VirtIOGraphicsAdapter>);
|
||||
Graphics::VirtIOGPU::Protocol::DisplayInfoResponse::Display display_information(Badge<VirtIOGraphicsAdapter>);
|
||||
Graphics::VirtIOGPU::ScanoutID scanout_id() const { return m_scanout_id; }
|
||||
Graphics::VirtIOGPU::Protocol::DisplayInfoResponse::Display display_information(Badge<VirtIOGraphicsAdapter>) const;
|
||||
|
||||
void draw_ntsc_test_pattern(Badge<VirtIOGraphicsAdapter>);
|
||||
|
||||
private:
|
||||
void initialize_console();
|
||||
|
@ -59,45 +54,28 @@ private:
|
|||
// Note: Paravirtualized hardware doesn't require a defined refresh rate for modesetting.
|
||||
virtual bool refresh_rate_support() const override { return false; }
|
||||
|
||||
virtual ErrorOr<size_t> write_to_first_surface(u64 offset, UserOrKernelBuffer const&, size_t length) override;
|
||||
virtual ErrorOr<void> flush_first_surface() override;
|
||||
virtual ErrorOr<void> flush_rectangle(size_t buffer_index, FBRect const& rect) override;
|
||||
|
||||
virtual void enable_console() override;
|
||||
virtual void disable_console() override;
|
||||
|
||||
static bool is_valid_buffer_index(size_t buffer_index)
|
||||
{
|
||||
return buffer_index == 0 || buffer_index == 1;
|
||||
}
|
||||
|
||||
private:
|
||||
VirtIODisplayConnector(VirtIOGraphicsAdapter& graphics_adapter, Graphics::VirtIOGPU::ScanoutID scanout_id);
|
||||
|
||||
void flush_displayed_image(Graphics::VirtIOGPU::Protocol::Rect const& dirty_rect, bool main_buffer);
|
||||
void set_dirty_displayed_rect(Graphics::VirtIOGPU::Protocol::Rect const& dirty_rect, bool main_buffer);
|
||||
|
||||
void query_display_information();
|
||||
ErrorOr<void> query_edid_from_virtio_adapter();
|
||||
void query_display_edid();
|
||||
|
||||
void flush_dirty_window(Graphics::VirtIOGPU::Protocol::Rect const&, Buffer&);
|
||||
void transfer_framebuffer_data_to_host(Graphics::VirtIOGPU::Protocol::Rect const&, Buffer&);
|
||||
void flush_displayed_image(Graphics::VirtIOGPU::Protocol::Rect const&, Buffer&);
|
||||
|
||||
// Basic 2D framebuffer methods
|
||||
static size_t calculate_framebuffer_size(size_t width, size_t height)
|
||||
{
|
||||
// VirtIO resources can only map on page boundaries!
|
||||
return Memory::page_round_up(sizeof(u32) * width * height).value();
|
||||
}
|
||||
u8* framebuffer_data();
|
||||
void draw_ntsc_test_pattern(Buffer&);
|
||||
void clear_to_black(Buffer&);
|
||||
ErrorOr<void> create_framebuffer();
|
||||
void create_buffer(Buffer&, size_t, size_t);
|
||||
void set_buffer(int);
|
||||
static bool is_valid_buffer_index(int buffer_index)
|
||||
{
|
||||
return buffer_index == 0 || buffer_index == 1;
|
||||
}
|
||||
Buffer& buffer_from_index(int buffer_index)
|
||||
{
|
||||
return buffer_index == 0 ? m_main_buffer : m_back_buffer;
|
||||
}
|
||||
Buffer& current_buffer() const { return *m_current_buffer; }
|
||||
void clear_to_black();
|
||||
|
||||
// Member data
|
||||
// Context used for kernel operations (e.g. flushing resources to scanout)
|
||||
|
@ -109,13 +87,7 @@ private:
|
|||
Graphics::VirtIOGPU::ScanoutID m_scanout_id;
|
||||
|
||||
// 2D framebuffer Member data
|
||||
size_t m_buffer_size { 0 };
|
||||
Buffer* m_current_buffer { nullptr };
|
||||
Atomic<int, AK::memory_order_relaxed> m_last_set_buffer_index { 0 };
|
||||
Buffer m_main_buffer;
|
||||
Buffer m_back_buffer;
|
||||
OwnPtr<Memory::Region> m_framebuffer;
|
||||
RefPtr<Memory::VMObject> m_framebuffer_sink_vmobject;
|
||||
Atomic<size_t, AK::memory_order_relaxed> m_last_set_buffer_index { 0 };
|
||||
|
||||
constexpr static size_t NUM_TRANSFER_REGION_PAGES = 256;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue