diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-26 12:06:07 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-26 12:06:07 +0100 |
commit | 519cb80a9680fdd806667ee100e495994ce3abbc (patch) | |
tree | f4088e11b768b8ddc942ce1e1a3fa08c03a423e2 /Libraries | |
parent | 23591f2a952bbe73be1b7a72b34d4233f820a1c7 (diff) | |
download | serenity-519cb80a9680fdd806667ee100e495994ce3abbc.zip |
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! :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/GWindow.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibGUI/GWindow.h | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/GWindowServerConnection.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibGUI/GWindowServerConnection.h | 1 |
4 files changed, 23 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GWindow.cpp b/Libraries/LibGUI/GWindow.cpp index c9d1511392..3533a4c7a9 100644 --- a/Libraries/LibGUI/GWindow.cpp +++ b/Libraries/LibGUI/GWindow.cpp @@ -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; + } +} diff --git a/Libraries/LibGUI/GWindow.h b/Libraries/LibGUI/GWindow.h index b345bda92e..0a6219ecb5 100644 --- a/Libraries/LibGUI/GWindow.h +++ b/Libraries/LibGUI/GWindow.h @@ -136,6 +136,7 @@ public: void schedule_relayout(); static void update_all_windows(Badge<GWindowServerConnection>); + void notify_state_changed(Badge<GWindowServerConnection>, bool minimized); protected: GWindow(CObject* parent = nullptr); diff --git a/Libraries/LibGUI/GWindowServerConnection.cpp b/Libraries/LibGUI/GWindowServerConnection.cpp index b1e6447629..9bb86ef936 100644 --- a/Libraries/LibGUI/GWindowServerConnection.cpp +++ b/Libraries/LibGUI/GWindowServerConnection.cpp @@ -295,3 +295,9 @@ void GWindowServerConnection::handle(const WindowClient::DragCancelled&) { GDragOperation::notify_cancelled({}); } + +void GWindowServerConnection::handle(const WindowClient::WindowStateChanged& message) +{ + if (auto* window = GWindow::from_window_id(message.window_id())) + window->notify_state_changed({}, message.minimized()); +} diff --git a/Libraries/LibGUI/GWindowServerConnection.h b/Libraries/LibGUI/GWindowServerConnection.h index 1647d5fc85..10b9d976bd 100644 --- a/Libraries/LibGUI/GWindowServerConnection.h +++ b/Libraries/LibGUI/GWindowServerConnection.h @@ -45,4 +45,5 @@ private: virtual void handle(const WindowClient::DragAccepted&) override; virtual void handle(const WindowClient::DragCancelled&) override; virtual void handle(const WindowClient::UpdateSystemTheme&) override; + virtual void handle(const WindowClient::WindowStateChanged&) override; }; |