diff options
author | Liav A <liavalb@gmail.com> | 2021-05-20 21:28:18 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-21 08:08:33 +0200 |
commit | db268efa6936a57bf142f5fd67b2fd556be2032e (patch) | |
tree | 68d11c5acc093ea9e855c5864856199e2727a491 | |
parent | 87f8f892d858a14b5c03b7bd7fdc9517a8f4cb84 (diff) | |
download | serenity-db268efa6936a57bf142f5fd67b2fd556be2032e.zip |
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.
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.cpp | 11 | ||||
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.h | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/Kernel/Graphics/FramebufferDevice.cpp b/Kernel/Graphics/FramebufferDevice.cpp index 1daf3f287e..cfe7d2db23 100644 --- a/Kernel/Graphics/FramebufferDevice.cpp +++ b/Kernel/Graphics/FramebufferDevice.cpp @@ -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 diff --git a/Kernel/Graphics/FramebufferDevice.h b/Kernel/Graphics/FramebufferDevice.h index f52f20ff4c..45e9bd0c54 100644 --- a/Kernel/Graphics/FramebufferDevice.h +++ b/Kernel/Graphics/FramebufferDevice.h @@ -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 }; }; |