[haiku-development] Help needed for WebKit2 port about app_server and bitmaps

  • From: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
  • To: superstippi@xxxxxx
  • Date: Sun, 21 Jul 2019 15:20:04 +0200

Hi there,

We have reached a point in the WebKit2 port where we need some advice on
app_server internals and how the memory for BBitmap is managed. I hope
you can help us find a solution for this and some hints for implementing
it.

As you know, WebKit2 uses a multi-process approach to isolate various
aspects of a web browser and provide more sandboxing between them. For
the parts we are concerned with, there is an "UI process" that runs the
window, menus, tabs, etc. It communicates with a "Web Process" that
manages the core of the web engine: parsing of HTML, layouting and
rendering the page.

To get the rendered page to the UI process, WebKit relies on a
"Shareable Bitmap" class
(https://github.com/haiku/webkit/blob/webkit2/Source/WebKit/Shared/ShareableBitmap.h)

The idea of this class is that on WebProcess side, we will create a
graphics context (a BView) to draw on it, and on the UI Process side, we
will simply paint the bitmap on an existing view (making it visible on
the screen).

The cross platform implementation of the shareable bitmap creates a
shared memory section, and then expects us to draw directly on this.
Unfortunately, BBitmap does not allow us to do this, as it manages its
own memory and does not let us access it.

Moreover, we would like to leverage the fact that on Haiku, drawing
happens on the server side. This means, ideally, the UI process does not
really need to access the bitmap data, it can just ask app_server to
draw it.

So we came to the conclusion that the more efficient way to do this
would be:
- On WebProcess side, allocate the bitmap as usual with its memory
  shared with app_server. Attach a BView to it and run our drawing
  operations.
- On UI process side, we only need some kind of token to identify the
  bitmap, we could then tell app_server to draw said bitmap even if it
  comes from another application. I don't know what we could use as a
  token, we may currently get the area_id of the bitmap but I'm not sure
  that's enough. How are bitmaps identified on app_server side? Would it
  be possible to refer to another app's bitmaps?

If we manage to do things this way, we would reduce the memory sharing
and data copying to a minimum, allowing to keep decent rendering
performance even in the multi process model. But I don't know if that
approach can be fitted in the existing app_server design and how much
things would need to be changed.

Thanks for your help,
-- 
Adrien.

Other related posts: