1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 15:55:07 +00:00

LibGUI+WindowServer: Mark minimized window backing stores as volatile

WindowServer will now send out a WindowStateChanged message to clients
when one of their windows is minimized.

This is then forwarded to the GWindow, which will try to mark its
underlying window backing store as volatile.

This allows the kernel to steal the memory used by minimized windows
in case it starts running low. Very cool! :^)
This commit is contained in:
Andreas Kling 2019-12-26 12:06:07 +01:00
parent 23591f2a95
commit 519cb80a96
6 changed files with 27 additions and 0 deletions

View file

@ -693,3 +693,18 @@ void GWindow::update_all_windows(Badge<GWindowServerConnection>)
window->update();
}
}
void GWindow::notify_state_changed(Badge<GWindowServerConnection>, bool minimized)
{
// When double buffering is enabled, minimization means we can mark the front bitmap volatile (in addition to the back bitmap.)
// When double buffering is disabled, there is only the back bitmap (which we can now mark volatile!)
RefPtr<GraphicsBitmap>& bitmap = m_double_buffering_enabled ? m_front_bitmap : m_back_bitmap;
if (!bitmap)
return;
if (minimized) {
bitmap->shared_buffer()->set_volatile();
} else {
if (!bitmap->shared_buffer()->set_nonvolatile())
bitmap = nullptr;
}
}