mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 18:02:20 +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,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
|
||||
*/
|
||||
|
@ -58,7 +58,7 @@ NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_bitmap(Bitmap& bitmap)
|
|||
}
|
||||
|
||||
#ifdef AK_OS_MACOS
|
||||
NonnullRefPtr<PaintingSurface> PaintingSurface::wrap_iosurface(Core::IOSurfaceHandle const& iosurface_handle, RefPtr<SkiaBackendContext> context, Origin origin)
|
||||
NonnullRefPtr<PaintingSurface> PaintingSurface::create_from_iosurface(Core::IOSurfaceHandle&& iosurface_handle, NonnullRefPtr<SkiaBackendContext> context, Origin origin)
|
||||
{
|
||||
context->lock();
|
||||
ScopeGuard unlock_guard([&context] {
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
static NonnullRefPtr<PaintingSurface> wrap_bitmap(Bitmap&);
|
||||
|
||||
#ifdef AK_OS_MACOS
|
||||
static NonnullRefPtr<PaintingSurface> wrap_iosurface(Core::IOSurfaceHandle const&, RefPtr<SkiaBackendContext>, Origin = Origin::TopLeft);
|
||||
static NonnullRefPtr<PaintingSurface> create_from_iosurface(Core::IOSurfaceHandle&&, NonnullRefPtr<SkiaBackendContext>, Origin = Origin::TopLeft);
|
||||
#endif
|
||||
|
||||
void read_into_bitmap(Bitmap&);
|
||||
|
|
|
@ -683,7 +683,6 @@ set(SOURCES
|
|||
Page/Page.cpp
|
||||
Painting/AudioPaintable.cpp
|
||||
Painting/BackgroundPainting.cpp
|
||||
Painting/BackingStore.cpp
|
||||
Painting/BackingStoreManager.cpp
|
||||
Painting/BorderPainting.cpp
|
||||
Painting/BorderRadiiData.cpp
|
||||
|
|
|
@ -2327,8 +2327,6 @@ void Navigable::set_viewport_size(CSSPixelSize size)
|
|||
if (m_viewport_size == size)
|
||||
return;
|
||||
|
||||
m_rendering_thread.clear_bitmap_to_surface_cache();
|
||||
|
||||
if (!m_is_svg_page) {
|
||||
m_backing_store_manager->restart_resize_timer();
|
||||
m_backing_store_manager->resize_backing_stores_if_needed(Web::Painting::BackingStoreManager::WindowResizingInProgress::Yes);
|
||||
|
@ -2557,8 +2555,8 @@ void Navigable::ready_to_paint()
|
|||
|
||||
void Navigable::paint_next_frame()
|
||||
{
|
||||
auto [backing_store_id, back_store] = m_backing_store_manager->acquire_store_for_next_frame();
|
||||
if (!back_store)
|
||||
auto [backing_store_id, painting_surface] = m_backing_store_manager->acquire_store_for_next_frame();
|
||||
if (!painting_surface)
|
||||
return;
|
||||
|
||||
VERIFY(m_number_of_queued_rasterization_tasks <= 1);
|
||||
|
@ -2566,7 +2564,7 @@ void Navigable::paint_next_frame()
|
|||
|
||||
auto viewport_rect = page().css_to_device_rect(this->viewport_rect());
|
||||
PaintConfig paint_config { .paint_overlay = true, .should_show_line_box_borders = m_should_show_line_box_borders, .canvas_fill_rect = Gfx::IntRect { {}, viewport_rect.size().to_type<int>() } };
|
||||
start_display_list_rendering(*back_store, paint_config, [this, viewport_rect, backing_store_id] {
|
||||
start_display_list_rendering(*painting_surface, paint_config, [this, viewport_rect, backing_store_id] {
|
||||
if (!is_top_level_traversable())
|
||||
return;
|
||||
auto& traversable = *page().top_level_traversable();
|
||||
|
@ -2574,7 +2572,7 @@ void Navigable::paint_next_frame()
|
|||
});
|
||||
}
|
||||
|
||||
void Navigable::start_display_list_rendering(Painting::BackingStore& target, PaintConfig paint_config, Function<void()>&& callback)
|
||||
void Navigable::start_display_list_rendering(Gfx::PaintingSurface& painting_surface, PaintConfig paint_config, Function<void()>&& callback)
|
||||
{
|
||||
m_needs_repaint = false;
|
||||
auto document = active_document();
|
||||
|
@ -2589,7 +2587,7 @@ void Navigable::start_display_list_rendering(Painting::BackingStore& target, Pai
|
|||
return;
|
||||
}
|
||||
auto scroll_state_snapshot = document->paintable()->scroll_state().snapshot();
|
||||
m_rendering_thread.enqueue_rendering_task(*display_list, move(scroll_state_snapshot), target, move(callback));
|
||||
m_rendering_thread.enqueue_rendering_task(*display_list, move(scroll_state_snapshot), painting_surface, move(callback));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ public:
|
|||
bool is_ready_to_paint() const;
|
||||
void ready_to_paint();
|
||||
void paint_next_frame();
|
||||
void start_display_list_rendering(Painting::BackingStore&, PaintConfig, Function<void()>&& callback);
|
||||
void start_display_list_rendering(Gfx::PaintingSurface&, PaintConfig, Function<void()>&& callback);
|
||||
|
||||
bool needs_repaint() const { return m_needs_repaint; }
|
||||
void set_needs_repaint() { m_needs_repaint = true; }
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <LibCore/EventLoop.h>
|
||||
#include <LibWeb/HTML/RenderingThread.h>
|
||||
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||
#include <LibWeb/Painting/BackingStore.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -49,10 +48,6 @@ void RenderingThread::rendering_thread_loop()
|
|||
while (true) {
|
||||
auto task = [this]() -> Optional<Task> {
|
||||
Threading::MutexLocker const locker { m_rendering_task_mutex };
|
||||
if (m_needs_to_clear_bitmap_to_surface_cache) {
|
||||
m_bitmap_to_surface.clear();
|
||||
m_needs_to_clear_bitmap_to_surface_cache = false;
|
||||
}
|
||||
while (m_rendering_tasks.is_empty() && !m_exit) {
|
||||
m_rendering_task_ready_wake_condition.wait();
|
||||
}
|
||||
|
@ -66,8 +61,7 @@ void RenderingThread::rendering_thread_loop()
|
|||
break;
|
||||
}
|
||||
|
||||
auto painting_surface = painting_surface_for_backing_store(task->backing_store);
|
||||
m_skia_player->execute(*task->display_list, task->scroll_state_snapshot, painting_surface);
|
||||
m_skia_player->execute(*task->display_list, task->scroll_state_snapshot, task->painting_surface);
|
||||
if (m_exit)
|
||||
break;
|
||||
m_main_thread_event_loop.deferred_invoke([callback = move(task->callback)] {
|
||||
|
@ -76,48 +70,11 @@ void RenderingThread::rendering_thread_loop()
|
|||
}
|
||||
}
|
||||
|
||||
void RenderingThread::enqueue_rendering_task(NonnullRefPtr<Painting::DisplayList> display_list, Painting::ScrollStateSnapshot&& scroll_state_snapshot, NonnullRefPtr<Painting::BackingStore> backing_store, Function<void()>&& callback)
|
||||
void RenderingThread::enqueue_rendering_task(NonnullRefPtr<Painting::DisplayList> display_list, Painting::ScrollStateSnapshot&& scroll_state_snapshot, NonnullRefPtr<Gfx::PaintingSurface> painting_surface, Function<void()>&& callback)
|
||||
{
|
||||
Threading::MutexLocker const locker { m_rendering_task_mutex };
|
||||
m_rendering_tasks.enqueue(Task { move(display_list), move(scroll_state_snapshot), move(backing_store), move(callback) });
|
||||
m_rendering_tasks.enqueue(Task { move(display_list), move(scroll_state_snapshot), move(painting_surface), move(callback) });
|
||||
m_rendering_task_ready_wake_condition.signal();
|
||||
}
|
||||
|
||||
NonnullRefPtr<Gfx::PaintingSurface> RenderingThread::painting_surface_for_backing_store(Painting::BackingStore& backing_store)
|
||||
{
|
||||
auto& bitmap = backing_store.bitmap();
|
||||
auto cached_surface = m_bitmap_to_surface.find(&bitmap);
|
||||
if (cached_surface != m_bitmap_to_surface.end())
|
||||
return cached_surface->value;
|
||||
|
||||
RefPtr<Gfx::PaintingSurface> new_surface;
|
||||
if (m_display_list_player_type == DisplayListPlayerType::SkiaGPUIfAvailable && m_skia_backend_context) {
|
||||
#ifdef USE_VULKAN
|
||||
// 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->on_flush = [backing_store = static_cast<NonnullRefPtr<Painting::BackingStore>>(backing_store)](auto& surface) { surface.read_into_bitmap(backing_store->bitmap()); };
|
||||
#endif
|
||||
#ifdef AK_OS_MACOS
|
||||
// macOS: Wrap an IOSurface if available.
|
||||
if (is<Painting::IOSurfaceBackingStore>(backing_store)) {
|
||||
auto& iosurface_backing_store = static_cast<Painting::IOSurfaceBackingStore&>(backing_store);
|
||||
new_surface = Gfx::PaintingSurface::wrap_iosurface(iosurface_backing_store.iosurface_handle(), *m_skia_backend_context);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// CPU and fallback: wrap the backing store bitmap directly.
|
||||
if (!new_surface)
|
||||
new_surface = Gfx::PaintingSurface::wrap_bitmap(bitmap);
|
||||
|
||||
m_bitmap_to_surface.set(&bitmap, *new_surface);
|
||||
return *new_surface;
|
||||
}
|
||||
|
||||
void RenderingThread::clear_bitmap_to_surface_cache()
|
||||
{
|
||||
Threading::MutexLocker const locker { m_rendering_task_mutex };
|
||||
m_needs_to_clear_bitmap_to_surface_cache = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,12 +29,10 @@ public:
|
|||
void start(DisplayListPlayerType);
|
||||
void set_skia_player(OwnPtr<Painting::DisplayListPlayerSkia>&& player) { m_skia_player = move(player); }
|
||||
void set_skia_backend_context(RefPtr<Gfx::SkiaBackendContext> context) { m_skia_backend_context = move(context); }
|
||||
void enqueue_rendering_task(NonnullRefPtr<Painting::DisplayList>, Painting::ScrollStateSnapshot&&, NonnullRefPtr<Painting::BackingStore>, Function<void()>&& callback);
|
||||
void clear_bitmap_to_surface_cache();
|
||||
void enqueue_rendering_task(NonnullRefPtr<Painting::DisplayList>, Painting::ScrollStateSnapshot&&, NonnullRefPtr<Gfx::PaintingSurface>, Function<void()>&& callback);
|
||||
|
||||
private:
|
||||
void rendering_thread_loop();
|
||||
NonnullRefPtr<Gfx::PaintingSurface> painting_surface_for_backing_store(Painting::BackingStore& backing_store);
|
||||
|
||||
Core::EventLoop& m_main_thread_event_loop;
|
||||
DisplayListPlayerType m_display_list_player_type;
|
||||
|
@ -49,7 +47,7 @@ private:
|
|||
struct Task {
|
||||
NonnullRefPtr<Painting::DisplayList> display_list;
|
||||
Painting::ScrollStateSnapshot scroll_state_snapshot;
|
||||
NonnullRefPtr<Painting::BackingStore> backing_store;
|
||||
NonnullRefPtr<Gfx::PaintingSurface> painting_surface;
|
||||
Function<void()> callback;
|
||||
};
|
||||
// NOTE: Queue will only contain multiple items in case tasks were scheduled by screenshot requests.
|
||||
|
@ -57,9 +55,6 @@ private:
|
|||
Queue<Task> m_rendering_tasks;
|
||||
Threading::Mutex m_rendering_task_mutex;
|
||||
Threading::ConditionVariable m_rendering_task_ready_wake_condition { m_rendering_task_mutex };
|
||||
|
||||
HashMap<Gfx::Bitmap*, NonnullRefPtr<Gfx::PaintingSurface>> m_bitmap_to_surface;
|
||||
bool m_needs_to_clear_bitmap_to_surface_cache { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Layout/Viewport.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/Painting/BackingStore.h>
|
||||
#include <LibWeb/Painting/ViewportPaintable.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -1413,19 +1412,19 @@ void TraversableNavigable::process_screenshot_requests()
|
|||
}
|
||||
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 backing_store = Painting::BitmapBackingStore::create(*bitmap);
|
||||
auto painting_surface = Gfx::PaintingSurface::wrap_bitmap(*bitmap);
|
||||
PaintConfig paint_config { .canvas_fill_rect = rect.to_type<int>() };
|
||||
start_display_list_rendering(backing_store, paint_config, [backing_store, &client] {
|
||||
client.page_did_take_screenshot(backing_store->bitmap().to_shareable_bitmap());
|
||||
start_display_list_rendering(painting_surface, paint_config, [bitmap, &client] {
|
||||
client.page_did_take_screenshot(bitmap->to_shareable_bitmap());
|
||||
});
|
||||
} else {
|
||||
auto scrollable_overflow_rect = active_document()->layout_node()->paintable_box()->scrollable_overflow_rect();
|
||||
auto rect = page().enclosing_device_rect(scrollable_overflow_rect.value());
|
||||
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors();
|
||||
auto backing_store = Painting::BitmapBackingStore::create(*bitmap);
|
||||
auto painting_surface = Gfx::PaintingSurface::wrap_bitmap(*bitmap);
|
||||
PaintConfig paint_config { .paint_overlay = true, .canvas_fill_rect = rect.to_type<int>() };
|
||||
start_display_list_rendering(backing_store, paint_config, [backing_store, &client] {
|
||||
client.page_did_take_screenshot(backing_store->bitmap().to_shareable_bitmap());
|
||||
start_display_list_rendering(painting_surface, paint_config, [bitmap, &client] {
|
||||
client.page_did_take_screenshot(bitmap->to_shareable_bitmap());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/Painting/BackingStore.h>
|
||||
#include <LibWeb/WebDriver/Screenshot.h>
|
||||
|
||||
namespace Web::WebDriver {
|
||||
|
@ -56,10 +55,10 @@ ErrorOr<GC::Ref<HTML::HTMLCanvasElement>, WebDriver::Error> draw_bounding_box_fr
|
|||
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 backing_store = Painting::BitmapBackingStore::create(bitmap);
|
||||
auto painting_surface = Gfx::PaintingSurface::wrap_bitmap(bitmap);
|
||||
IGNORE_USE_IN_ESCAPING_LAMBDA bool did_paint = false;
|
||||
HTML::PaintConfig paint_config { .canvas_fill_rect = paint_rect };
|
||||
browsing_context.active_document()->navigable()->start_display_list_rendering(backing_store, paint_config, [&did_paint] {
|
||||
browsing_context.active_document()->navigable()->start_display_list_rendering(painting_surface, paint_config, [&did_paint] {
|
||||
did_paint = true;
|
||||
});
|
||||
HTML::main_thread_event_loop().spin_until(GC::create_function(HTML::main_thread_event_loop().heap(), [&] {
|
||||
|
|
|
@ -176,7 +176,6 @@ void OpenGLContext::allocate_painting_surface_if_needed()
|
|||
VERIFY(!m_size.is_empty());
|
||||
|
||||
auto iosurface = Core::IOSurfaceHandle::create(m_size.width(), m_size.height());
|
||||
m_painting_surface = Gfx::PaintingSurface::wrap_iosurface(iosurface, m_skia_backend_context, Gfx::PaintingSurface::Origin::BottomLeft);
|
||||
|
||||
auto width = m_size.width();
|
||||
auto height = m_size.height();
|
||||
|
@ -229,6 +228,8 @@ void OpenGLContext::allocate_painting_surface_if_needed()
|
|||
glBindRenderbuffer(GL_RENDERBUFFER, m_impl->depth_buffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_impl->depth_buffer);
|
||||
|
||||
m_painting_surface = Gfx::PaintingSurface::create_from_iosurface(move(iosurface), m_skia_backend_context, Gfx::PaintingSurface::Origin::BottomLeft);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue