LibWeb: Make BackingStore atomic ref-counted
Some checks are pending
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

This is required to make sure rendering thread will keep backing stores
alive in case backing stores reallocation happens during rasterization.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/4164
This commit is contained in:
Aliaksandr Kalenik 2025-04-01 01:44:35 +02:00 committed by Alexander Kalenik
commit e33174fca1
Notes: github-actions[bot] 2025-04-01 01:06:13 +00:00
6 changed files with 28 additions and 17 deletions

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Noncopyable.h>
#include <LibGfx/Size.h>
@ -15,7 +16,7 @@
namespace Web::Painting {
class BackingStore {
class BackingStore : public AtomicRefCounted<BackingStore> {
AK_MAKE_NONCOPYABLE(BackingStore);
public:
@ -28,19 +29,27 @@ public:
class BitmapBackingStore final : public BackingStore {
public:
BitmapBackingStore(RefPtr<Gfx::Bitmap>);
static NonnullRefPtr<BitmapBackingStore> create(RefPtr<Gfx::Bitmap> bitmap)
{
return adopt_ref(*new BitmapBackingStore(move(bitmap)));
}
Gfx::IntSize size() const override { return m_bitmap->size(); }
Gfx::Bitmap& bitmap() const override { return *m_bitmap; }
private:
BitmapBackingStore(RefPtr<Gfx::Bitmap>);
RefPtr<Gfx::Bitmap> m_bitmap;
};
#ifdef AK_OS_MACOS
class IOSurfaceBackingStore final : public BackingStore {
public:
IOSurfaceBackingStore(Core::IOSurfaceHandle&&);
static NonnullRefPtr<IOSurfaceBackingStore> create(Core::IOSurfaceHandle&& iosurface_handle)
{
return adopt_ref(*new IOSurfaceBackingStore(move(iosurface_handle)));
}
Gfx::IntSize size() const override;
@ -48,6 +57,8 @@ public:
Gfx::Bitmap& bitmap() const override { return *m_bitmap_wrapper; }
private:
IOSurfaceBackingStore(Core::IOSurfaceHandle&&);
Core::IOSurfaceHandle m_iosurface_handle;
RefPtr<Gfx::Bitmap> m_bitmap_wrapper;
};