LadybirdBrowser / ladybird

Truly independent web browser
https://ladybird.org
BSD 2-Clause "Simplified" License
19.99k stars 827 forks source link

LibCore+LibWeb: Use Metal backend for Skia painter on macOS #294

Closed kalenikaliaksandr closed 3 months ago

kalenikaliaksandr commented 3 months ago

If Metal context and IOSurface are available, Skia painter will use Ganesh GPU backend on macOS, which is noticeably faster than the default CPU backend.

Painting pipeline:

  1. (WebContent) Allocate IOSurface for backing store
  2. (WebContent) Allocate MTLTexture that wraps IOSurface
  3. (WebContent) Paint into MTLTexture using Skia
  4. (Browser) Wrap IOSurface into Gfx::Painter and use QPainter/CoreGraphics to blit backing store into viewport.

Things we should improve in the future:

  1. Upload textures for images in advance instead of doing that before every repaint.
  2. Teach AppKit client to read directly from IOSurface instead of copying.
kalenikaliaksandr commented 3 months ago

macOS CI failure doesn't seem to be related to the changes:

VERIFICATION FAILED: m_pointer at /Users/runner/work/ladybird/ladybird/AK/Optional.h:428
VERIFICATION FAILED: m_pointer at /Users/runner/work/ladybird/ladybird/AK/Optional.h:428
VERIFICATION FAILED: m_pointer at /Users/runner/work/ladybird/ladybird/AK/Optional.h:428
0   liblagom-ak.0.0.0.dylib             0x0000000104c1ee40 ak_verification_failed + 560
1   liblagom-core.0.0.0.dylib           0x0000000103a6aa88 Core::(anonymous namespace)::ThreadData::for_thread(_opaque_pthread_t*) + 496
2   liblagom-core.0.0.0.dylib           0x0000000103a6b4c8 Core::EventLoopManagerUnix::unregister_notifier(Core::Notifier&) + 320
3   liblagom-core.0.0.0.dylib           0x0000000103ad1904 Core::PosixSocketHelper::close() + 404
4   liblagom-protocol.0.0.0.dylib       0x0000000103417850 Core::LocalSocket::~LocalSocket() + 144
5   liblagom-protocol.0.0.0.dylib       0x0000000103417714 AK::NonnullOwnPtr<Core::LocalSocket>::clear() + 176
6   liblagom-protocol.0.0.0.dylib       0x000000010340efb8 IPC::ConnectionBase::~ConnectionBase() + 236
7   liblagom-protocol.0.0.0.dylib       0x0000000103405bc8 Protocol::RequestClient::~RequestClient() + 36
8   liblagom-webview.0.0.0.dylib        0x0000000103e00c88 AK::RefCounted<Core::EventReceiver>::unref() const + 384
9   liblagom-webview.0.0.0.dylib        0x0000000103e78e74 WebView::RequestServerAdapter::~RequestServerAdapter() + 132
10  liblagom-webview.0.0.0.dylib        0x0000000103e78fac WebView::RequestServerAdapter::~RequestServerAdapter() + 36
11  liblagom-web.0.0.0.dylib            0x000000011076f1b8 AK::RefCounted<Web::ResourceLoaderConnector>::unref() const + 384
12  liblagom-web.0.0.0.dylib            0x00000001107860b0 Web::ResourceLoader::~ResourceLoader() + 176
13  liblagom-web.0.0.0.dylib            0x000000011076d4b4 Web::ResourceLoader::~ResourceLoader() + 36
14  liblagom-web.0.0.0.dylib            0x000000010f47ed08 AK::RefCounted<Core::EventReceiver>::unref() const + 384
15  liblagom-web.0.0.0.dylib            0x000000011075e9c0 AK::RefPtr<Web::ResourceLoader>::~RefPtr() + 96
16  libsystem_c.dylib                   0x00000001881d02e8 __cxa_finalize_ranges + 476
17  libsystem_c.dylib                   0x00000001881d0070 exit + 44
18  libdyld.dylib                       0x000000018832b8d0 dyld4::LibSystemHelpers::getenv(char const*) const + 0
19  dyld                                0x0000000187f8a12c start + 2436
tcl3 commented 3 months ago

macOS CI failure doesn't seem to be related to the changes:

FWIW, I'm seeing the same failure on my latest PR: https://github.com/LadybirdBrowser/ladybird/actions/runs/9697507525/job/26761801460?pr=299

ADKaster commented 3 months ago

@alimpfard this ThreadData crash looks related to your changes that I pulled in? Did I miss some prep commits?

alimpfard commented 3 months ago

Looks like I put some changes in the wrong commit, you also need the EventLoopManager changes from https://github.com/SerenityOS/serenity/commit/9f4f319277f90e7534de2b39edcc98387fc68b1d