From 794c81626e548311e31ff28871c3482a873ff566 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 18 Mar 2019 20:52:23 +0100 Subject: [PATCH] WindowServer: Cache the last two backing stores to make flipping faster. Instead of reattaching to the shared buffer on every flip, keep a reference to the last seen backing store GraphicsBitmap. This way we can simply swap the two last buffers when a flip happens. This does increase memory consumption in apps that disable double-buffering but I'll address that issue separately. --- WindowServer/WSClientConnection.cpp | 20 ++++++++++++-------- WindowServer/WSWindow.h | 13 ++++++++++++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/WindowServer/WSClientConnection.cpp b/WindowServer/WSClientConnection.cpp index 0ad739b82d..f8f00db758 100644 --- a/WindowServer/WSClientConnection.cpp +++ b/WindowServer/WSClientConnection.cpp @@ -445,14 +445,18 @@ void WSClientConnection::handle_request(WSAPISetWindowBackingStoreRequest& reque return; } auto& window = *(*it).value; - auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(request.shared_buffer_id()); - if (!shared_buffer) - return; - auto backing_store = GraphicsBitmap::create_with_shared_buffer( - request.has_alpha_channel() ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32, - *shared_buffer, - request.size()); - window.set_backing_store(move(backing_store)); + if (window.last_backing_store() && window.last_backing_store()->shared_buffer_id() == request.shared_buffer_id()) { + window.swap_backing_stores(); + } else { + auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(request.shared_buffer_id()); + if (!shared_buffer) + return; + auto backing_store = GraphicsBitmap::create_with_shared_buffer( + request.has_alpha_channel() ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32, + *shared_buffer, + request.size()); + window.set_backing_store(move(backing_store)); + } if (request.flush_immediately()) window.invalidate(); diff --git a/WindowServer/WSWindow.h b/WindowServer/WSWindow.h index 7d0273a742..dc116ccdf7 100644 --- a/WindowServer/WSWindow.h +++ b/WindowServer/WSWindow.h @@ -58,7 +58,17 @@ public: virtual void on_message(WSMessage&) override; GraphicsBitmap* backing_store() { return m_backing_store.ptr(); } - void set_backing_store(RetainPtr&& backing_store) { m_backing_store = move(backing_store); } + void set_backing_store(RetainPtr&& backing_store) + { + m_last_backing_store = move(m_backing_store); + m_backing_store = move(backing_store); + } + void swap_backing_stores() + { + swap(m_backing_store, m_last_backing_store); + } + + GraphicsBitmap* last_backing_store() { return m_last_backing_store.ptr(); } void set_global_cursor_tracking_enabled(bool); bool global_cursor_tracking() const { return m_global_cursor_tracking_enabled; } @@ -97,6 +107,7 @@ private: bool m_has_alpha_channel { false }; bool m_has_painted_since_last_resize { false }; RetainPtr m_backing_store; + RetainPtr m_last_backing_store; int m_window_id { -1 }; float m_opacity { 1 }; Rect m_last_lazy_resize_rect;