1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 18:35:07 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2019-12-09 20:08:44 +01:00
parent 0317ca5ccc
commit dfd0daa157

View file

@ -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<Rect, 32>& 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<GraphicsBitmap> GWindow::create_shared_bitmap(GraphicsBitmap::Format format, const Size& size)