ladybird/Libraries/LibWeb/Painting/BackingStore.h
Aliaksandr Kalenik e33174fca1
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
LibWeb: Make BackingStore atomic ref-counted
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
2025-04-01 03:05:21 +02:00

67 lines
1.6 KiB
C++

/*
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Noncopyable.h>
#include <LibGfx/Size.h>
#ifdef AK_OS_MACOS
# include <LibCore/IOSurface.h>
#endif
namespace Web::Painting {
class BackingStore : public AtomicRefCounted<BackingStore> {
AK_MAKE_NONCOPYABLE(BackingStore);
public:
virtual Gfx::IntSize size() const = 0;
virtual Gfx::Bitmap& bitmap() const = 0;
BackingStore() { }
virtual ~BackingStore() { }
};
class BitmapBackingStore final : public BackingStore {
public:
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:
static NonnullRefPtr<IOSurfaceBackingStore> create(Core::IOSurfaceHandle&& iosurface_handle)
{
return adopt_ref(*new IOSurfaceBackingStore(move(iosurface_handle)));
}
Gfx::IntSize size() const override;
Core::IOSurfaceHandle& iosurface_handle() { return m_iosurface_handle; }
Gfx::Bitmap& bitmap() const override { return *m_bitmap_wrapper; }
private:
IOSurfaceBackingStore(Core::IOSurfaceHandle&&);
Core::IOSurfaceHandle m_iosurface_handle;
RefPtr<Gfx::Bitmap> m_bitmap_wrapper;
};
#endif
}