From ae9004342462e6cce4eb6f980825ade641b2c1a2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 26 Feb 2019 10:50:25 +0100 Subject: [PATCH] WindowServer+LibGUI: Send the window size along with Paint server messages. This way GWindow doesn't need to do synchronous IPC to fetch the appropriate size for the window's backing store. This is mostly only relevant during live resize. --- LibGUI/GEvent.h | 8 ++++++-- LibGUI/GEventLoop.cpp | 2 +- LibGUI/GWindow.cpp | 4 ++-- WindowServer/WSAPITypes.h | 1 + WindowServer/WSClientConnection.cpp | 2 ++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/LibGUI/GEvent.h b/LibGUI/GEvent.h index a0cdff198c8..5f1527c5a2a 100644 --- a/LibGUI/GEvent.h +++ b/LibGUI/GEvent.h @@ -56,15 +56,19 @@ public: class GPaintEvent final : public GEvent { public: - explicit GPaintEvent(const Rect& rect = Rect()) + explicit GPaintEvent(const Rect& rect, const Size& window_size = Size()) : GEvent(GEvent::Paint) , m_rect(rect) + , m_window_size(window_size) { } - const Rect& rect() const { return m_rect; } + Rect rect() const { return m_rect; } + Size window_size() const { return m_window_size; } + private: Rect m_rect; + Size m_window_size; }; class GResizeEvent final : public GEvent { diff --git a/LibGUI/GEventLoop.cpp b/LibGUI/GEventLoop.cpp index 2e0a2ba4c9c..d1353e433cf 100644 --- a/LibGUI/GEventLoop.cpp +++ b/LibGUI/GEventLoop.cpp @@ -119,7 +119,7 @@ void GEventLoop::handle_paint_event(const WSAPI_ServerMessage& event, GWindow& w #ifdef GEVENTLOOP_DEBUG dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); #endif - post_event(window, make(event.paint.rect)); + post_event(window, make(event.paint.rect, event.paint.window_size)); } void GEventLoop::handle_resize_event(const WSAPI_ServerMessage& event, GWindow& window) diff --git a/LibGUI/GWindow.cpp b/LibGUI/GWindow.cpp index 0b61f922cfa..7bcca700152 100644 --- a/LibGUI/GWindow.cpp +++ b/LibGUI/GWindow.cpp @@ -168,9 +168,9 @@ void GWindow::event(GEvent& event) auto rect = paint_event.rect(); bool created_new_backing_store = !m_backing; if (!m_backing) { - // NOTE: size() may change at any time since it's synchronously retrieved from the WindowServer. ASSERT(GEventLoop::main().server_pid()); - Size new_backing_store_size = size(); + ASSERT(!paint_event.window_size().is_empty()); + Size new_backing_store_size = paint_event.window_size(); size_t size_in_bytes = new_backing_store_size.area() * sizeof(RGBA32); void* buffer; int shared_buffer_id = create_shared_buffer(GEventLoop::main().server_pid(), size_in_bytes, (void**)&buffer); diff --git a/WindowServer/WSAPITypes.h b/WindowServer/WSAPITypes.h index 9084190ad7f..e7fd570809f 100644 --- a/WindowServer/WSAPITypes.h +++ b/WindowServer/WSAPITypes.h @@ -101,6 +101,7 @@ struct WSAPI_ServerMessage { } window; struct { WSAPI_Rect rect; + WSAPI_Size window_size; } paint; struct { WSAPI_Point position; diff --git a/WindowServer/WSClientConnection.cpp b/WindowServer/WSClientConnection.cpp index 2e5fcf5e075..0cf421b0f4e 100644 --- a/WindowServer/WSClientConnection.cpp +++ b/WindowServer/WSClientConnection.cpp @@ -349,10 +349,12 @@ void WSClientConnection::handle_request(WSAPIInvalidateRectRequest& request) post_error("Bad window ID"); return; } + auto& window = *(*it).value; WSAPI_ServerMessage response; response.type = WSAPI_ServerMessage::Type::Paint; response.window_id = window_id; response.paint.rect = request.rect(); + response.paint.window_size = window.size(); post_message(response); }