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

LibWeb+WebContent: Use anonymous files for OOPWV backing stores

To support this, the GUI process and the WebContent service will now
coordinate their backing store bitmaps. Each backing store can be
referred to by a serial ID, and we don't need to keep resending it
as a file descriptor.

We should probably do something similar in WindowServer. :^)
This commit is contained in:
Andreas Kling 2021-01-16 23:15:32 +01:00
parent 04b2aeef33
commit b5d98c0945
7 changed files with 52 additions and 32 deletions

View file

@ -102,33 +102,33 @@ void ClientConnection::handle(const Messages::WebContentServer::SetViewportRect&
m_page_host->set_viewport_rect(message.rect());
}
void ClientConnection::handle(const Messages::WebContentServer::AddBackingStore& message)
{
m_backing_stores.set(message.backing_store_id(), *message.bitmap().bitmap());
}
void ClientConnection::handle(const Messages::WebContentServer::RemoveBackingStore& message)
{
m_backing_stores.remove(message.backing_store_id());
}
void ClientConnection::handle(const Messages::WebContentServer::Paint& message)
{
#ifdef DEBUG_SPAM
dbg() << "handle: WebContentServer::Paint: content_rect=" << message.content_rect() << ", shbuf_id=" << message.shbuf_id();
#endif
for (auto& pending_paint : m_pending_paint_requests) {
if (pending_paint.bitmap->shbuf_id() == message.shbuf_id()) {
if (pending_paint.bitmap_id == message.backing_store_id()) {
pending_paint.content_rect = message.content_rect();
return;
}
}
auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.shbuf_id());
if (!shared_buffer) {
#ifdef DEBUG_SPAM
dbgln("WebContentServer::Paint: SharedBuffer already gone! Ignoring :^)");
#endif
return;
}
auto shared_bitmap = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGB32, shared_buffer.release_nonnull(), message.content_rect().size());
if (!shared_bitmap) {
did_misbehave("WebContentServer::Paint: Cannot create Gfx::Bitmap wrapper around SharedBuffer");
auto it = m_backing_stores.find(message.backing_store_id());
if (it == m_backing_stores.end()) {
did_misbehave("Client requested paint with backing store ID");
return;
}
m_pending_paint_requests.append({ message.content_rect(), shared_bitmap.release_nonnull() });
auto& bitmap = *it->value;
m_pending_paint_requests.append({ message.content_rect(), bitmap, message.backing_store_id() });
m_paint_flush_timer->start();
}
@ -136,7 +136,7 @@ void ClientConnection::flush_pending_paint_requests()
{
for (auto& pending_paint : m_pending_paint_requests) {
m_page_host->paint(pending_paint.content_rect, *pending_paint.bitmap);
post_message(Messages::WebContentClient::DidPaint(pending_paint.content_rect, pending_paint.bitmap->shbuf_id()));
post_message(Messages::WebContentClient::DidPaint(pending_paint.content_rect, pending_paint.bitmap_id));
}
m_pending_paint_requests.clear();
}

View file

@ -60,6 +60,8 @@ private:
virtual void handle(const Messages::WebContentServer::MouseMove&) override;
virtual void handle(const Messages::WebContentServer::MouseUp&) override;
virtual void handle(const Messages::WebContentServer::KeyDown&) override;
virtual void handle(const Messages::WebContentServer::AddBackingStore&) override;
virtual void handle(const Messages::WebContentServer::RemoveBackingStore&) override;
void flush_pending_paint_requests();
@ -68,9 +70,12 @@ private:
struct PaintRequest {
Gfx::IntRect content_rect;
NonnullRefPtr<Gfx::Bitmap> bitmap;
i32 bitmap_id { -1 };
};
Vector<PaintRequest> m_pending_paint_requests;
RefPtr<Core::Timer> m_paint_flush_timer;
HashMap<i32, NonnullRefPtr<Gfx::Bitmap>> m_backing_stores;
};
}

View file

@ -2,7 +2,7 @@ endpoint WebContentClient = 90
{
DidStartLoading(URL url) =|
DidFinishLoading(URL url) =|
DidPaint(Gfx::IntRect content_rect, i32 shbuf_id) =|
DidPaint(Gfx::IntRect content_rect, i32 bitmap_id) =|
DidInvalidateContentRect(Gfx::IntRect content_rect) =|
DidChangeSelection() =|
DidLayout(Gfx::IntSize content_size) =|

View file

@ -7,7 +7,10 @@ endpoint WebContentServer = 89
LoadURL(URL url) =|
LoadHTML(String html, URL url) =|
Paint(Gfx::IntRect content_rect, i32 shbuf_id) =|
AddBackingStore(i32 backing_store_id, Gfx::ShareableBitmap bitmap) =|
RemoveBackingStore(i32 backing_store_id) =|
Paint(Gfx::IntRect content_rect, i32 backing_store_id) =|
SetViewportRect(Gfx::IntRect rect) =|
MouseDown(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) =|