Kernel/Graphics: Choose VMObject considering enabled state when mmaping

When mmaping a Framebuffer from userspace, we need to check whether the
framebuffer device is actually enabled (e.g. graphical mode is being
used) or a textual VirtualConsole is active.

Considering the above state, we mmap the right VMObject to ensure we
don't have graphical artifacts if we change the resolution from
DisplaySettings, changed to textual mode and after the resolution change
was reverted, we will see the Desktop reappearing even though we are
still in textual mode.
This commit is contained in:
Liav A 2021-05-20 21:28:18 +03:00 committed by Andreas Kling
parent 87f8f892d8
commit db268efa69
Notes: sideshowbarker 2024-07-18 17:39:04 +09:00
2 changed files with 12 additions and 1 deletions

View File

@ -22,6 +22,7 @@ namespace Kernel {
KResultOr<Region*> FramebufferDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared)
{
ScopedSpinLock lock(m_activation_lock);
REQUIRE_PROMISE(video);
if (!shared)
return ENODEV;
@ -40,9 +41,15 @@ KResultOr<Region*> FramebufferDevice::mmap(Process& process, FileDescription&, c
m_real_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, page_round_up(framebuffer_size_in_bytes()), "Framebuffer", Region::Access::Read | Region::Access::Write);
m_swapped_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, page_round_up(framebuffer_size_in_bytes()), "Framebuffer Swap (Blank)", Region::Access::Read | Region::Access::Write);
RefPtr<VMObject> chosen_vmobject;
if (m_graphical_writes_enabled) {
chosen_vmobject = m_real_framebuffer_vmobject;
} else {
chosen_vmobject = m_swapped_framebuffer_vmobject;
}
auto result = process.space().allocate_region_with_vmobject(
range,
vmobject.release_nonnull(),
chosen_vmobject.release_nonnull(),
0,
"Framebuffer",
prot,
@ -62,6 +69,7 @@ void FramebufferDevice::dectivate_writes()
auto vmobject = m_swapped_framebuffer_vmobject;
m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull());
m_userspace_framebuffer_region->remap();
m_graphical_writes_enabled = false;
}
void FramebufferDevice::activate_writes()
{
@ -75,6 +83,7 @@ void FramebufferDevice::activate_writes()
auto vmobject = m_userspace_real_framebuffer_vmobject;
m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull());
m_userspace_framebuffer_region->remap();
m_graphical_writes_enabled = true;
}
String FramebufferDevice::device_name() const

View File

@ -59,6 +59,8 @@ private:
OwnPtr<Region> m_real_framebuffer_region;
OwnPtr<Region> m_swapped_framebuffer_region;
bool m_graphical_writes_enabled { true };
RefPtr<AnonymousVMObject> m_userspace_real_framebuffer_vmobject;
Region* m_userspace_framebuffer_region { nullptr };
};