mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +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
|
@ -24,8 +24,7 @@ NonnullRefPtr<GenericDisplayConnector> GenericDisplayConnector::must_create_with
|
|||
}
|
||||
|
||||
GenericDisplayConnector::GenericDisplayConnector(PhysicalAddress framebuffer_address, size_t width, size_t height, size_t pitch)
|
||||
: DisplayConnector()
|
||||
, m_framebuffer_address(framebuffer_address)
|
||||
: DisplayConnector(framebuffer_address, height * pitch, true)
|
||||
{
|
||||
m_current_mode_setting.horizontal_active = width;
|
||||
m_current_mode_setting.vertical_active = height;
|
||||
|
@ -38,24 +37,11 @@ ErrorOr<void> GenericDisplayConnector::create_attached_framebuffer_console()
|
|||
auto height = m_current_mode_setting.vertical_active;
|
||||
auto pitch = m_current_mode_setting.horizontal_stride;
|
||||
|
||||
auto rounded_size = TRY(Memory::page_round_up(pitch * height));
|
||||
m_framebuffer_region = TRY(MM.allocate_kernel_region(m_framebuffer_address.page_base(), rounded_size, "Framebuffer"sv, Memory::Region::Access::ReadWrite));
|
||||
[[maybe_unused]] auto result = m_framebuffer_region->set_write_combine(true);
|
||||
m_framebuffer_data = m_framebuffer_region->vaddr().offset(m_framebuffer_address.offset_in_page()).as_ptr();
|
||||
m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(m_framebuffer_address, width, height, pitch);
|
||||
m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(m_framebuffer_address.value(), width, height, pitch);
|
||||
GraphicsManagement::the().set_console(*m_framebuffer_console);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<size_t> GenericDisplayConnector::write_to_first_surface(u64 offset, UserOrKernelBuffer const& buffer, size_t length)
|
||||
{
|
||||
VERIFY(m_control_lock.is_locked());
|
||||
if (offset + length > m_framebuffer_region->size())
|
||||
return Error::from_errno(EOVERFLOW);
|
||||
TRY(buffer.read(m_framebuffer_data + offset, 0, length));
|
||||
return length;
|
||||
}
|
||||
|
||||
void GenericDisplayConnector::enable_console()
|
||||
{
|
||||
VERIFY(m_control_lock.is_locked());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue