From dfd0daa15762873f05705aa42689e63a451ed7d1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 9 Dec 2019 20:08:44 +0100 Subject: [PATCH] LibGUI: Mark window back buffers as volatile while not painting We now take advantage of SharedBuffers being purgeable memory by setting the volatile flag on window back buffers while not painting into them. This means that one of the two backing stores used by each window is purgeable+volatile most of the time, allowing the kernel to purge it to recover memory if needed. Note that this is only relevant when double-buffering is turned on, but since that is the default, this does affect most apps. :^) --- Libraries/LibGUI/GWindow.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/GWindow.cpp b/Libraries/LibGUI/GWindow.cpp index 556103ff61..eb4ac46de6 100644 --- a/Libraries/LibGUI/GWindow.cpp +++ b/Libraries/LibGUI/GWindow.cpp @@ -210,8 +210,15 @@ void GWindow::event(CEvent& event) m_back_bitmap = nullptr; } bool created_new_backing_store = !m_back_bitmap; - if (!m_back_bitmap) + if (!m_back_bitmap) { m_back_bitmap = create_backing_bitmap(paint_event.window_size()); + } else if (m_double_buffering_enabled) { + bool still_has_pixels = m_back_bitmap->shared_buffer()->set_nonvolatile(); + if (!still_has_pixels) { + m_back_bitmap = create_backing_bitmap(paint_event.window_size()); + created_new_backing_store = true; + } + } auto rect = rects.first(); if (rect.is_empty() || created_new_backing_store) { @@ -547,6 +554,8 @@ void GWindow::flip(const Vector& dirty_rects) Painter painter(*m_back_bitmap); for (auto& dirty_rect : dirty_rects) painter.blit(dirty_rect.location(), *m_front_bitmap, dirty_rect); + + m_back_bitmap->shared_buffer()->set_volatile(); } NonnullRefPtr GWindow::create_shared_bitmap(GraphicsBitmap::Format format, const Size& size)