mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 02:09:24 +00:00
LibWeb+LibGfx: Replace BackingStore with PaintingSurface
Now, when Skia backend context is available by the time backing stores are allocated, there is no need to have a separate BackingStore class. This allows us to get rid of BackingStore -> PaintingSurface cache.
This commit is contained in:
parent
082053d781
commit
c18314b942
Notes:
github-actions[bot]
2025-07-04 14:14:05 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: c18314b942
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5259
Reviewed-by: https://github.com/gmta ✅
14 changed files with 52 additions and 189 deletions
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibWeb/Painting/BackingStore.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
BitmapBackingStore::BitmapBackingStore(RefPtr<Gfx::Bitmap> bitmap)
|
||||
: m_bitmap(move(bitmap))
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef AK_OS_MACOS
|
||||
IOSurfaceBackingStore::IOSurfaceBackingStore(Core::IOSurfaceHandle&& iosurface_handle)
|
||||
: m_iosurface_handle(move(iosurface_handle))
|
||||
{
|
||||
auto bytes_per_row = m_iosurface_handle.bytes_per_row();
|
||||
auto bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, size(), bytes_per_row, m_iosurface_handle.data());
|
||||
m_bitmap_wrapper = bitmap.release_value();
|
||||
}
|
||||
|
||||
Gfx::IntSize IOSurfaceBackingStore::size() const
|
||||
{
|
||||
return { m_iosurface_handle.width(), m_iosurface_handle.height() };
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* 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/Bitmap.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
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -48,8 +48,9 @@ void BackingStoreManager::restart_resize_timer()
|
|||
|
||||
void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size)
|
||||
{
|
||||
auto skia_backend_context = m_navigable->skia_backend_context();
|
||||
#ifdef AK_OS_MACOS
|
||||
if (m_navigable->is_top_level_traversable() && s_browser_mach_port.has_value()) {
|
||||
if (skia_backend_context && s_browser_mach_port.has_value()) {
|
||||
auto back_iosurface = Core::IOSurfaceHandle::create(size.width(), size.height());
|
||||
auto back_iosurface_port = back_iosurface.create_mach_port();
|
||||
|
||||
|
@ -93,8 +94,8 @@ void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
m_front_store = IOSurfaceBackingStore::create(move(front_iosurface));
|
||||
m_back_store = IOSurfaceBackingStore::create(move(back_iosurface));
|
||||
m_front_store = Gfx::PaintingSurface::create_from_iosurface(move(front_iosurface), *skia_backend_context);
|
||||
m_back_store = Gfx::PaintingSurface::create_from_iosurface(move(back_iosurface), *skia_backend_context);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -106,8 +107,23 @@ void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size)
|
|||
auto front_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, size).release_value();
|
||||
auto back_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, size).release_value();
|
||||
|
||||
m_front_store = BitmapBackingStore::create(front_bitmap);
|
||||
m_back_store = BitmapBackingStore::create(back_bitmap);
|
||||
#ifdef USE_VULKAN
|
||||
if (skia_backend_context) {
|
||||
m_front_store = Gfx::PaintingSurface::create_with_size(skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
||||
m_front_store->on_flush = [front_bitmap](auto& surface) {
|
||||
surface.read_into_bitmap(*front_bitmap);
|
||||
};
|
||||
m_back_store = Gfx::PaintingSurface::create_with_size(skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
||||
m_back_store->on_flush = [back_bitmap](auto& surface) {
|
||||
surface.read_into_bitmap(*back_bitmap);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_front_store)
|
||||
m_front_store = Gfx::PaintingSurface::wrap_bitmap(*front_bitmap);
|
||||
if (!m_back_store)
|
||||
m_back_store = Gfx::PaintingSurface::wrap_bitmap(*back_bitmap);
|
||||
|
||||
if (m_navigable->is_top_level_traversable()) {
|
||||
auto& page_client = m_navigable->top_level_traversable()->page().client();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -7,7 +7,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/Navigable.h>
|
||||
#include <LibWeb/Painting/BackingStore.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
|
@ -30,14 +29,14 @@ public:
|
|||
|
||||
struct BackingStore {
|
||||
i32 bitmap_id { -1 };
|
||||
Web::Painting::BackingStore* store { nullptr };
|
||||
RefPtr<Gfx::PaintingSurface> store;
|
||||
};
|
||||
|
||||
BackingStore acquire_store_for_next_frame()
|
||||
{
|
||||
BackingStore backing_store;
|
||||
backing_store.bitmap_id = m_back_bitmap_id;
|
||||
backing_store.store = m_back_store.ptr();
|
||||
backing_store.store = m_back_store;
|
||||
swap_back_and_front();
|
||||
return backing_store;
|
||||
}
|
||||
|
@ -53,8 +52,8 @@ private:
|
|||
|
||||
i32 m_front_bitmap_id { -1 };
|
||||
i32 m_back_bitmap_id { -1 };
|
||||
RefPtr<Painting::BackingStore> m_front_store;
|
||||
RefPtr<Painting::BackingStore> m_back_store;
|
||||
RefPtr<Gfx::PaintingSurface> m_front_store;
|
||||
RefPtr<Gfx::PaintingSurface> m_back_store;
|
||||
int m_next_bitmap_id { 0 };
|
||||
|
||||
RefPtr<Core::Timer> m_backing_store_shrink_timer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue