1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:17:42 +00:00

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.
This commit is contained in:
Andreas Kling 2019-02-26 10:50:25 +01:00
parent 1effe70543
commit ae90043424
5 changed files with 12 additions and 5 deletions

View file

@ -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 {

View file

@ -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<GPaintEvent>(event.paint.rect));
post_event(window, make<GPaintEvent>(event.paint.rect, event.paint.window_size));
}
void GEventLoop::handle_resize_event(const WSAPI_ServerMessage& event, GWindow& window)

View file

@ -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);

View file

@ -101,6 +101,7 @@ struct WSAPI_ServerMessage {
} window;
struct {
WSAPI_Rect rect;
WSAPI_Size window_size;
} paint;
struct {
WSAPI_Point position;

View file

@ -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);
}