mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
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
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:
parent
a0bb31f7a0
commit
e33174fca1
Notes:
github-actions[bot]
2025-04-01 01:06:13 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: e33174fca1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4167
6 changed files with 28 additions and 17 deletions
|
@ -1414,7 +1414,7 @@ NonnullRefPtr<Gfx::PaintingSurface> TraversableNavigable::painting_surface_for_b
|
||||||
#ifdef USE_VULKAN
|
#ifdef USE_VULKAN
|
||||||
// Vulkan: Try to create an accelerated surface.
|
// Vulkan: Try to create an accelerated surface.
|
||||||
new_surface = Gfx::PaintingSurface::create_with_size(m_skia_backend_context, backing_store.size(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
new_surface = Gfx::PaintingSurface::create_with_size(m_skia_backend_context, backing_store.size(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
||||||
new_surface->on_flush = [&bitmap = bitmap](auto& surface) { surface.read_into_bitmap(bitmap); };
|
new_surface->on_flush = [backing_store = static_cast<NonnullRefPtr<Painting::BackingStore>>(backing_store)](auto& surface) { surface.read_into_bitmap(backing_store->bitmap()); };
|
||||||
#endif
|
#endif
|
||||||
#ifdef AK_OS_MACOS
|
#ifdef AK_OS_MACOS
|
||||||
// macOS: Wrap an IOSurface if available.
|
// macOS: Wrap an IOSurface if available.
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/AtomicRefCounted.h>
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#include <LibGfx/Size.h>
|
#include <LibGfx/Size.h>
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
|
|
||||||
namespace Web::Painting {
|
namespace Web::Painting {
|
||||||
|
|
||||||
class BackingStore {
|
class BackingStore : public AtomicRefCounted<BackingStore> {
|
||||||
AK_MAKE_NONCOPYABLE(BackingStore);
|
AK_MAKE_NONCOPYABLE(BackingStore);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -28,19 +29,27 @@ public:
|
||||||
|
|
||||||
class BitmapBackingStore final : public BackingStore {
|
class BitmapBackingStore final : public BackingStore {
|
||||||
public:
|
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::IntSize size() const override { return m_bitmap->size(); }
|
||||||
Gfx::Bitmap& bitmap() const override { return *m_bitmap; }
|
Gfx::Bitmap& bitmap() const override { return *m_bitmap; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BitmapBackingStore(RefPtr<Gfx::Bitmap>);
|
||||||
|
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef AK_OS_MACOS
|
#ifdef AK_OS_MACOS
|
||||||
class IOSurfaceBackingStore final : public BackingStore {
|
class IOSurfaceBackingStore final : public BackingStore {
|
||||||
public:
|
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;
|
Gfx::IntSize size() const override;
|
||||||
|
|
||||||
|
@ -48,6 +57,8 @@ public:
|
||||||
Gfx::Bitmap& bitmap() const override { return *m_bitmap_wrapper; }
|
Gfx::Bitmap& bitmap() const override { return *m_bitmap_wrapper; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
IOSurfaceBackingStore(Core::IOSurfaceHandle&&);
|
||||||
|
|
||||||
Core::IOSurfaceHandle m_iosurface_handle;
|
Core::IOSurfaceHandle m_iosurface_handle;
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap_wrapper;
|
RefPtr<Gfx::Bitmap> m_bitmap_wrapper;
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,7 +56,7 @@ ErrorOr<GC::Ref<HTML::HTMLCanvasElement>, WebDriver::Error> draw_bounding_box_fr
|
||||||
Gfx::IntRect paint_rect { rect.x(), rect.y(), paint_width, paint_height };
|
Gfx::IntRect paint_rect { rect.x(), rect.y(), paint_width, paint_height };
|
||||||
|
|
||||||
auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, canvas.surface()->size()));
|
auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, canvas.surface()->size()));
|
||||||
auto backing_store = Web::Painting::BitmapBackingStore(bitmap);
|
auto backing_store = Painting::BitmapBackingStore::create(bitmap);
|
||||||
IGNORE_USE_IN_ESCAPING_LAMBDA bool did_paint = false;
|
IGNORE_USE_IN_ESCAPING_LAMBDA bool did_paint = false;
|
||||||
browsing_context.page().client().start_display_list_rendering(paint_rect.to_type<Web::DevicePixels>(), backing_store, {}, [&did_paint] {
|
browsing_context.page().client().start_display_list_rendering(paint_rect.to_type<Web::DevicePixels>(), backing_store, {}, [&did_paint] {
|
||||||
did_paint = true;
|
did_paint = true;
|
||||||
|
|
|
@ -83,8 +83,8 @@ void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_front_store = make<Web::Painting::IOSurfaceBackingStore>(move(front_iosurface));
|
m_front_store = Web::Painting::IOSurfaceBackingStore::create(move(front_iosurface));
|
||||||
m_back_store = make<Web::Painting::IOSurfaceBackingStore>(move(back_iosurface));
|
m_back_store = Web::Painting::IOSurfaceBackingStore::create(move(back_iosurface));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,8 @@ 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 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();
|
auto back_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, size).release_value();
|
||||||
|
|
||||||
m_front_store = make<Web::Painting::BitmapBackingStore>(front_bitmap);
|
m_front_store = Web::Painting::BitmapBackingStore::create(front_bitmap);
|
||||||
m_back_store = make<Web::Painting::BitmapBackingStore>(back_bitmap);
|
m_back_store = Web::Painting::BitmapBackingStore::create(back_bitmap);
|
||||||
|
|
||||||
m_page_client.page_did_allocate_backing_stores(m_front_bitmap_id, front_bitmap->to_shareable_bitmap(), m_back_bitmap_id, back_bitmap->to_shareable_bitmap());
|
m_page_client.page_did_allocate_backing_stores(m_front_bitmap_id, front_bitmap->to_shareable_bitmap(), m_back_bitmap_id, back_bitmap->to_shareable_bitmap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ private:
|
||||||
|
|
||||||
i32 m_front_bitmap_id { -1 };
|
i32 m_front_bitmap_id { -1 };
|
||||||
i32 m_back_bitmap_id { -1 };
|
i32 m_back_bitmap_id { -1 };
|
||||||
OwnPtr<Web::Painting::BackingStore> m_front_store;
|
RefPtr<Web::Painting::BackingStore> m_front_store;
|
||||||
OwnPtr<Web::Painting::BackingStore> m_back_store;
|
RefPtr<Web::Painting::BackingStore> m_back_store;
|
||||||
int m_next_bitmap_id { 0 };
|
int m_next_bitmap_id { 0 };
|
||||||
|
|
||||||
RefPtr<Core::Timer> m_backing_store_shrink_timer;
|
RefPtr<Core::Timer> m_backing_store_shrink_timer;
|
||||||
|
|
|
@ -205,16 +205,16 @@ void PageClient::process_screenshot_requests()
|
||||||
}
|
}
|
||||||
auto rect = page().enclosing_device_rect(dom_node->paintable_box()->absolute_border_box_rect());
|
auto rect = page().enclosing_device_rect(dom_node->paintable_box()->absolute_border_box_rect());
|
||||||
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors();
|
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors();
|
||||||
auto backing_store = Web::Painting::BitmapBackingStore(*bitmap);
|
auto backing_store = Web::Painting::BitmapBackingStore::create(*bitmap);
|
||||||
start_display_list_rendering(rect, backing_store, { .paint_overlay = Web::PaintOptions::PaintOverlay::No }, [this, bitmap] {
|
start_display_list_rendering(rect, backing_store, { .paint_overlay = Web::PaintOptions::PaintOverlay::No }, [this, backing_store] {
|
||||||
client().async_did_take_screenshot(m_id, bitmap->to_shareable_bitmap());
|
client().async_did_take_screenshot(m_id, backing_store->bitmap().to_shareable_bitmap());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Web::DevicePixelRect rect { { 0, 0 }, content_size() };
|
Web::DevicePixelRect rect { { 0, 0 }, content_size() };
|
||||||
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors();
|
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors();
|
||||||
auto backing_store = Web::Painting::BitmapBackingStore(*bitmap);
|
auto backing_store = Web::Painting::BitmapBackingStore::create(*bitmap);
|
||||||
start_display_list_rendering(rect, backing_store, {}, [this, bitmap] {
|
start_display_list_rendering(rect, backing_store, {}, [this, backing_store] {
|
||||||
client().async_did_take_screenshot(m_id, bitmap->to_shareable_bitmap());
|
client().async_did_take_screenshot(m_id, backing_store->bitmap().to_shareable_bitmap());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue