LibWeb+WebContent+WebWorker: Move backing store allocation in Navigable

Making navigables responsible for backing store allocation will allow us
to have separate backing stores for iframes and run paint updates for
them independently, which is a step toward isolating them into separate
processes.

Another nice side effect is that now Skia backend context is ready by
the time backing stores are allocated, so we will be able to get rid of
BackingStore class in the upcoming changes and allocate PaintingSurface
directly.
This commit is contained in:
Aliaksandr Kalenik 2025-06-26 22:33:58 +02:00 committed by Jelle Raaijmakers
commit 082053d781
Notes: github-actions[bot] 2025-07-04 14:14:12 +00:00
23 changed files with 265 additions and 262 deletions

View file

@ -684,6 +684,7 @@ set(SOURCES
Painting/AudioPaintable.cpp Painting/AudioPaintable.cpp
Painting/BackgroundPainting.cpp Painting/BackgroundPainting.cpp
Painting/BackingStore.cpp Painting/BackingStore.cpp
Painting/BackingStoreManager.cpp
Painting/BorderPainting.cpp Painting/BorderPainting.cpp
Painting/BorderRadiiData.cpp Painting/BorderRadiiData.cpp
Painting/BorderRadiusCornerClipper.cpp Painting/BorderRadiusCornerClipper.cpp

View file

@ -6444,7 +6444,7 @@ void Document::invalidate_display_list()
} }
} }
RefPtr<Painting::DisplayList> Document::record_display_list(PaintConfig config) RefPtr<Painting::DisplayList> Document::record_display_list(HTML::PaintConfig config)
{ {
if (m_cached_display_list && m_cached_display_list_paint_config == config) { if (m_cached_display_list && m_cached_display_list_paint_config == config) {
return m_cached_display_list; return m_cached_display_list;

View file

@ -832,14 +832,7 @@ public:
void set_needs_display(InvalidateDisplayList = InvalidateDisplayList::Yes); void set_needs_display(InvalidateDisplayList = InvalidateDisplayList::Yes);
void set_needs_display(CSSPixelRect const&, InvalidateDisplayList = InvalidateDisplayList::Yes); void set_needs_display(CSSPixelRect const&, InvalidateDisplayList = InvalidateDisplayList::Yes);
struct PaintConfig { RefPtr<Painting::DisplayList> record_display_list(HTML::PaintConfig);
bool paint_overlay { false };
bool should_show_line_box_borders { false };
Optional<Gfx::IntRect> canvas_fill_rect {};
bool operator==(PaintConfig const& other) const = default;
};
RefPtr<Painting::DisplayList> record_display_list(PaintConfig);
void invalidate_display_list(); void invalidate_display_list();
@ -1235,7 +1228,7 @@ private:
bool m_enable_cookies_on_file_domains { false }; bool m_enable_cookies_on_file_domains { false };
Optional<PaintConfig> m_cached_display_list_paint_config; Optional<HTML::PaintConfig> m_cached_display_list_paint_config;
RefPtr<Painting::DisplayList> m_cached_display_list; RefPtr<Painting::DisplayList> m_cached_display_list;
mutable OwnPtr<Unicode::Segmenter> m_grapheme_segmenter; mutable OwnPtr<Unicode::Segmenter> m_grapheme_segmenter;

View file

@ -468,16 +468,14 @@ void EventLoop::update_the_rendering()
// 22. For each doc of docs, update the rendering or user interface of doc and its node navigable to reflect the current state. // 22. For each doc of docs, update the rendering or user interface of doc and its node navigable to reflect the current state.
for (auto& document : docs) { for (auto& document : docs) {
document->page().client().process_screenshot_requests();
auto navigable = document->navigable(); auto navigable = document->navigable();
if (!navigable->is_traversable()) if (!navigable->is_traversable())
continue; continue;
auto traversable = navigable->traversable_navigable(); auto traversable = navigable->traversable_navigable();
if (traversable && traversable->needs_repaint()) { traversable->process_screenshot_requests();
auto& page = traversable->page(); if (!navigable->needs_repaint())
VERIFY(page.client().is_ready_to_paint()); continue;
page.client().paint_next_frame(); navigable->paint_next_frame();
}
} }
// 23. For each doc of docs, process top layer removals given doc. // 23. For each doc of docs, process top layer removals given doc.

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2022-2024, Andreas Kling <andreas@ladybird.org> * Copyright (c) 2022-2024, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> * Copyright (c) 2023-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org> * Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
@ -109,11 +109,50 @@ bool Navigable::is_ancestor_of(GC::Ref<Navigable> other) const
return false; return false;
} }
Navigable::Navigable(GC::Ref<Page> page) static RefPtr<Gfx::SkiaBackendContext> g_cached_skia_backend_context;
static RefPtr<Gfx::SkiaBackendContext> get_skia_backend_context()
{
if (!g_cached_skia_backend_context) {
#ifdef AK_OS_MACOS
auto metal_context = Gfx::get_metal_context();
g_cached_skia_backend_context = Gfx::SkiaBackendContext::create_metal_context(*metal_context);
#elif USE_VULKAN
auto maybe_vulkan_context = Gfx::create_vulkan_context();
if (maybe_vulkan_context.is_error()) {
dbgln("Vulkan context creation failed: {}", maybe_vulkan_context.error());
return {};
}
auto vulkan_context = maybe_vulkan_context.release_value();
g_cached_skia_backend_context = Gfx::SkiaBackendContext::create_vulkan_context(vulkan_context);
#endif
}
return g_cached_skia_backend_context;
}
Navigable::Navigable(GC::Ref<Page> page, bool is_svg_page)
: m_page(page) : m_page(page)
, m_event_handler({}, *this) , m_event_handler({}, *this)
, m_is_svg_page(is_svg_page)
, m_backing_store_manager(heap().allocate<Painting::BackingStoreManager>(*this))
{ {
all_navigables().set(*this); all_navigables().set(*this);
if (!m_is_svg_page) {
auto display_list_player_type = page->client().display_list_player_type();
OwnPtr<Painting::DisplayListPlayerSkia> skia_player;
if (display_list_player_type == DisplayListPlayerType::SkiaGPUIfAvailable) {
m_skia_backend_context = get_skia_backend_context();
skia_player = make<Painting::DisplayListPlayerSkia>(m_skia_backend_context);
} else {
skia_player = make<Painting::DisplayListPlayerSkia>();
}
m_rendering_thread.set_skia_player(move(skia_player));
m_rendering_thread.set_skia_backend_context(m_skia_backend_context);
m_rendering_thread.start(display_list_player_type);
}
} }
Navigable::~Navigable() = default; Navigable::~Navigable() = default;
@ -133,6 +172,7 @@ void Navigable::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_active_session_history_entry); visitor.visit(m_active_session_history_entry);
visitor.visit(m_container); visitor.visit(m_container);
visitor.visit(m_navigation_observers); visitor.visit(m_navigation_observers);
visitor.visit(m_backing_store_manager);
m_event_handler.visit_edges(visitor); m_event_handler.visit_edges(visitor);
for (auto& navigation_params : m_pending_navigations) { for (auto& navigation_params : m_pending_navigations) {
@ -2287,6 +2327,14 @@ void Navigable::set_viewport_size(CSSPixelSize size)
if (m_viewport_size == size) if (m_viewport_size == size)
return; 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);
m_pending_set_browser_zoom_request = false;
}
m_viewport_size = size; m_viewport_size = size;
if (auto document = active_document()) { if (auto document = active_document()) {
// NOTE: Resizing the viewport changes the reference value for viewport-relative CSS lengths. // NOTE: Resizing the viewport changes the reference value for viewport-relative CSS lengths.
@ -2338,10 +2386,7 @@ bool Navigable::has_a_rendering_opportunity() const
// Rendering opportunities typically occur at regular intervals. // Rendering opportunities typically occur at regular intervals.
// FIXME: Return `false` here if we're an inactive browser tab. // FIXME: Return `false` here if we're an inactive browser tab.
auto browsing_context = const_cast<Navigable*>(this)->active_browsing_context(); return is_ready_to_paint();
if (!browsing_context)
return false;
return browsing_context->page().client().is_ready_to_paint();
} }
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#inform-the-navigation-api-about-child-navigable-destruction // https://html.spec.whatwg.org/multipage/nav-history-apis.html#inform-the-navigation-api-about-child-navigable-destruction
@ -2499,4 +2544,52 @@ void Navigable::set_has_session_history_entry_and_ready_for_navigation()
} }
} }
bool Navigable::is_ready_to_paint() const
{
return m_number_of_queued_rasterization_tasks <= 1;
}
void Navigable::ready_to_paint()
{
m_number_of_queued_rasterization_tasks--;
VERIFY(m_number_of_queued_rasterization_tasks >= 0 && m_number_of_queued_rasterization_tasks < 2);
}
void Navigable::paint_next_frame()
{
auto [backing_store_id, back_store] = m_backing_store_manager->acquire_store_for_next_frame();
if (!back_store)
return;
VERIFY(m_number_of_queued_rasterization_tasks <= 1);
m_number_of_queued_rasterization_tasks++;
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] {
if (!is_top_level_traversable())
return;
auto& traversable = *page().top_level_traversable();
traversable.page().client().page_did_paint(viewport_rect.to_type<int>(), backing_store_id);
});
}
void Navigable::start_display_list_rendering(Painting::BackingStore& target, PaintConfig paint_config, Function<void()>&& callback)
{
m_needs_repaint = false;
auto document = active_document();
if (!document) {
callback();
return;
}
document->paintable()->refresh_scroll_state();
auto display_list = document->record_display_list(paint_config);
if (!display_list) {
callback();
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));
}
} }

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org> * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> * Copyright (c) 2023-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -17,12 +17,14 @@
#include <LibWeb/HTML/HistoryHandlingBehavior.h> #include <LibWeb/HTML/HistoryHandlingBehavior.h>
#include <LibWeb/HTML/NavigationParams.h> #include <LibWeb/HTML/NavigationParams.h>
#include <LibWeb/HTML/POSTResource.h> #include <LibWeb/HTML/POSTResource.h>
#include <LibWeb/HTML/RenderingThread.h>
#include <LibWeb/HTML/SandboxingFlagSet.h> #include <LibWeb/HTML/SandboxingFlagSet.h>
#include <LibWeb/HTML/SourceSnapshotParams.h> #include <LibWeb/HTML/SourceSnapshotParams.h>
#include <LibWeb/HTML/StructuredSerialize.h> #include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/HTML/TokenizedFeatures.h> #include <LibWeb/HTML/TokenizedFeatures.h>
#include <LibWeb/InvalidateDisplayList.h> #include <LibWeb/InvalidateDisplayList.h>
#include <LibWeb/Page/EventHandler.h> #include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Painting/BackingStoreManager.h>
#include <LibWeb/PixelUnits.h> #include <LibWeb/PixelUnits.h>
#include <LibWeb/XHR/FormDataEntry.h> #include <LibWeb/XHR/FormDataEntry.h>
@ -38,6 +40,14 @@ struct TargetSnapshotParams {
SandboxingFlagSet sandboxing_flags {}; SandboxingFlagSet sandboxing_flags {};
}; };
struct PaintConfig {
bool paint_overlay { false };
bool should_show_line_box_borders { false };
Optional<Gfx::IntRect> canvas_fill_rect {};
bool operator==(PaintConfig const& other) const = default;
};
// https://html.spec.whatwg.org/multipage/document-sequences.html#navigable // https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
class Navigable : public JS::Cell class Navigable : public JS::Cell
, public Weakable<Navigable> { , public Weakable<Navigable> {
@ -170,7 +180,7 @@ public:
CSSPixelPoint viewport_scroll_offset() const { return m_viewport_scroll_offset; } CSSPixelPoint viewport_scroll_offset() const { return m_viewport_scroll_offset; }
CSSPixelRect viewport_rect() const { return { m_viewport_scroll_offset, m_viewport_size }; } CSSPixelRect viewport_rect() const { return { m_viewport_scroll_offset, m_viewport_size }; }
CSSPixelSize viewport_size() const { return m_viewport_size; } CSSPixelSize viewport_size() const { return m_viewport_size; }
virtual void set_viewport_size(CSSPixelSize); void set_viewport_size(CSSPixelSize);
void perform_scroll_of_viewport(CSSPixelPoint position); void perform_scroll_of_viewport(CSSPixelPoint position);
// https://html.spec.whatwg.org/multipage/webappapis.html#rendering-opportunity // https://html.spec.whatwg.org/multipage/webappapis.html#rendering-opportunity
@ -195,11 +205,26 @@ public:
bool has_pending_navigations() const { return !m_pending_navigations.is_empty(); } bool has_pending_navigations() const { return !m_pending_navigations.is_empty(); }
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);
bool needs_repaint() const { return m_needs_repaint; }
void set_needs_repaint() { m_needs_repaint = true; }
RefPtr<Gfx::SkiaBackendContext> skia_backend_context() const { return m_skia_backend_context; }
void set_pending_set_browser_zoom_request(bool value) { m_pending_set_browser_zoom_request = value; }
bool pending_set_browser_zoom_request() const { return m_pending_set_browser_zoom_request; }
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
template<typename T> template<typename T>
bool fast_is() const = delete; bool fast_is() const = delete;
protected: protected:
explicit Navigable(GC::Ref<Page>); explicit Navigable(GC::Ref<Page>, bool is_svg_page);
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
virtual void finalize() override; virtual void finalize() override;
@ -253,6 +278,15 @@ private:
bool m_has_session_history_entry_and_ready_for_navigation { false }; bool m_has_session_history_entry_and_ready_for_navigation { false };
Vector<NavigateParams> m_pending_navigations; Vector<NavigateParams> m_pending_navigations;
bool m_is_svg_page { false };
bool m_needs_repaint { true };
bool m_pending_set_browser_zoom_request { false };
bool m_should_show_line_box_borders { false };
i32 m_number_of_queued_rasterization_tasks { 0 };
GC::Ref<Painting::BackingStoreManager> m_backing_store_manager;
RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
RenderingThread m_rendering_thread;
}; };
HashTable<GC::RawRef<Navigable>>& all_navigables(); HashTable<GC::RawRef<Navigable>>& all_navigables();

View file

@ -95,7 +95,7 @@ WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable(GC::Ptr
document_state->set_about_base_url(document->about_base_url()); document_state->set_about_base_url(document->about_base_url());
// 7. Let navigable be a new navigable. // 7. Let navigable be a new navigable.
GC::Ref<Navigable> navigable = *heap().allocate<Navigable>(page); GC::Ref<Navigable> navigable = *heap().allocate<Navigable>(page, false);
// 8. Initialize the navigable navigable given documentState and parentNavigable. // 8. Initialize the navigable navigable given documentState and parentNavigable.
TRY_OR_THROW_OOM(vm(), navigable->initialize_navigable(document_state, parent_navigable)); TRY_OR_THROW_OOM(vm(), navigable->initialize_navigable(document_state, parent_navigable));

View file

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org> * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org> * Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
* Copyright (c) 2023-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -18,6 +19,7 @@
#include <LibWeb/HTML/SessionHistoryEntry.h> #include <LibWeb/HTML/SessionHistoryEntry.h>
#include <LibWeb/HTML/TraversableNavigable.h> #include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Page/Page.h> #include <LibWeb/Page/Page.h>
#include <LibWeb/Painting/BackingStore.h> #include <LibWeb/Painting/BackingStore.h>
#include <LibWeb/Painting/ViewportPaintable.h> #include <LibWeb/Painting/ViewportPaintable.h>
@ -27,47 +29,11 @@ namespace Web::HTML {
GC_DEFINE_ALLOCATOR(TraversableNavigable); GC_DEFINE_ALLOCATOR(TraversableNavigable);
static RefPtr<Gfx::SkiaBackendContext> g_cached_skia_backend_context;
static RefPtr<Gfx::SkiaBackendContext> get_skia_backend_context()
{
if (!g_cached_skia_backend_context) {
#ifdef AK_OS_MACOS
auto metal_context = Gfx::get_metal_context();
g_cached_skia_backend_context = Gfx::SkiaBackendContext::create_metal_context(*metal_context);
#elif USE_VULKAN
auto maybe_vulkan_context = Gfx::create_vulkan_context();
if (maybe_vulkan_context.is_error()) {
dbgln("Vulkan context creation failed: {}", maybe_vulkan_context.error());
return {};
}
auto vulkan_context = maybe_vulkan_context.release_value();
g_cached_skia_backend_context = Gfx::SkiaBackendContext::create_vulkan_context(vulkan_context);
#endif
}
return g_cached_skia_backend_context;
}
TraversableNavigable::TraversableNavigable(GC::Ref<Page> page) TraversableNavigable::TraversableNavigable(GC::Ref<Page> page)
: Navigable(page) : Navigable(page, page->client().is_svg_page_client())
, m_storage_shed(StorageAPI::StorageShed::create(page->heap())) , m_storage_shed(StorageAPI::StorageShed::create(page->heap()))
, m_session_history_traversal_queue(vm().heap().allocate<SessionHistoryTraversalQueue>()) , m_session_history_traversal_queue(vm().heap().allocate<SessionHistoryTraversalQueue>())
{ {
if (!page->client().is_svg_page_client()) {
auto display_list_player_type = page->client().display_list_player_type();
OwnPtr<Painting::DisplayListPlayerSkia> skia_player;
if (display_list_player_type == DisplayListPlayerType::SkiaGPUIfAvailable) {
m_skia_backend_context = get_skia_backend_context();
skia_player = make<Painting::DisplayListPlayerSkia>(m_skia_backend_context);
} else {
skia_player = make<Painting::DisplayListPlayerSkia>();
}
m_rendering_thread.set_skia_player(move(skia_player));
m_rendering_thread.set_skia_backend_context(m_skia_backend_context);
m_rendering_thread.start(display_list_player_type);
}
} }
TraversableNavigable::~TraversableNavigable() = default; TraversableNavigable::~TraversableNavigable() = default;
@ -1420,40 +1386,6 @@ GC::Ptr<DOM::Node> TraversableNavigable::currently_focused_area()
return candidate; return candidate;
} }
void TraversableNavigable::set_viewport_size(CSSPixelSize size)
{
Navigable::set_viewport_size(size);
// Invalidate the surface cache if the traversable changed size.
m_rendering_thread.clear_bitmap_to_surface_cache();
}
RefPtr<Painting::DisplayList> TraversableNavigable::record_display_list(DevicePixelRect const& content_rect, PaintOptions paint_options)
{
m_needs_repaint = false;
auto document = active_document();
if (!document)
return {};
for (auto& navigable : all_navigables()) {
if (auto active_document = navigable->active_document(); active_document && active_document->paintable())
active_document->paintable()->refresh_scroll_state();
}
DOM::Document::PaintConfig paint_config;
paint_config.paint_overlay = paint_options.paint_overlay == PaintOptions::PaintOverlay::Yes;
paint_config.should_show_line_box_borders = paint_options.should_show_line_box_borders;
paint_config.canvas_fill_rect = Gfx::IntRect { {}, content_rect.size() };
return document->record_display_list(paint_config);
}
void TraversableNavigable::start_display_list_rendering(NonnullRefPtr<Painting::DisplayList> display_list, NonnullRefPtr<Painting::BackingStore> backing_store, Function<void()>&& callback)
{
auto scroll_state_snapshot = active_document()->paintable()->scroll_state().snapshot();
m_rendering_thread.enqueue_rendering_task(move(display_list), move(scroll_state_snapshot), move(backing_store), move(callback));
}
// https://w3c.github.io/geolocation/#dfn-emulated-position-data // https://w3c.github.io/geolocation/#dfn-emulated-position-data
Geolocation::EmulatedPositionData const& TraversableNavigable::emulated_position_data() const Geolocation::EmulatedPositionData const& TraversableNavigable::emulated_position_data() const
{ {
@ -1468,4 +1400,35 @@ void TraversableNavigable::set_emulated_position_data(Geolocation::EmulatedPosit
m_emulated_position_data = data; m_emulated_position_data = data;
} }
void TraversableNavigable::process_screenshot_requests()
{
auto& client = page().client();
while (!m_screenshot_tasks.is_empty()) {
auto task = m_screenshot_tasks.dequeue();
if (task.node_id.has_value()) {
auto* dom_node = DOM::Node::from_unique_id(*task.node_id);
if (!dom_node || !dom_node->paintable_box()) {
client.page_did_take_screenshot({});
continue;
}
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);
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());
});
} 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);
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());
});
}
}
}
} }

View file

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org> * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org> * Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
* Copyright (c) 2023-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -102,9 +103,6 @@ public:
[[nodiscard]] GC::Ptr<DOM::Node> currently_focused_area(); [[nodiscard]] GC::Ptr<DOM::Node> currently_focused_area();
RefPtr<Painting::DisplayList> record_display_list(DevicePixelRect const&, PaintOptions);
void start_display_list_rendering(NonnullRefPtr<Painting::DisplayList>, NonnullRefPtr<Painting::BackingStore>, Function<void()>&& callback);
enum class CheckIfUnloadingIsCanceledResult { enum class CheckIfUnloadingIsCanceledResult {
CanceledByBeforeUnload, CanceledByBeforeUnload,
CanceledByNavigate, CanceledByNavigate,
@ -112,20 +110,20 @@ public:
}; };
CheckIfUnloadingIsCanceledResult check_if_unloading_is_canceled(Vector<GC::Root<Navigable>> navigables_that_need_before_unload); CheckIfUnloadingIsCanceledResult check_if_unloading_is_canceled(Vector<GC::Root<Navigable>> navigables_that_need_before_unload);
RefPtr<Gfx::SkiaBackendContext> skia_backend_context() const { return m_skia_backend_context; }
StorageAPI::StorageShed& storage_shed() { return m_storage_shed; } StorageAPI::StorageShed& storage_shed() { return m_storage_shed; }
StorageAPI::StorageShed const& storage_shed() const { return m_storage_shed; } StorageAPI::StorageShed const& storage_shed() const { return m_storage_shed; }
void set_viewport_size(CSSPixelSize) override;
bool needs_repaint() const { return m_needs_repaint; }
void set_needs_repaint() { m_needs_repaint = true; }
// https://w3c.github.io/geolocation/#dfn-emulated-position-data // https://w3c.github.io/geolocation/#dfn-emulated-position-data
Geolocation::EmulatedPositionData const& emulated_position_data() const; Geolocation::EmulatedPositionData const& emulated_position_data() const;
void set_emulated_position_data(Geolocation::EmulatedPositionData data); void set_emulated_position_data(Geolocation::EmulatedPositionData data);
void process_screenshot_requests();
void queue_screenshot_task(Optional<UniqueNodeID> node_id)
{
m_screenshot_tasks.enqueue({ node_id });
set_needs_repaint();
}
private: private:
TraversableNavigable(GC::Ref<Page>); TraversableNavigable(GC::Ref<Page>);
@ -149,8 +147,6 @@ private:
[[nodiscard]] bool can_go_forward() const; [[nodiscard]] bool can_go_forward() const;
RenderingThread m_rendering_thread;
// https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
int m_current_session_history_step { 0 }; int m_current_session_history_step { 0 };
@ -176,12 +172,13 @@ private:
String m_window_handle; String m_window_handle;
RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
bool m_needs_repaint { true };
// https://w3c.github.io/geolocation/#dfn-emulated-position-data // https://w3c.github.io/geolocation/#dfn-emulated-position-data
Geolocation::EmulatedPositionData m_emulated_position_data; Geolocation::EmulatedPositionData m_emulated_position_data;
struct ScreenshotTask {
Optional<Web::UniqueNodeID> node_id;
};
Queue<ScreenshotTask> m_screenshot_tasks;
}; };
struct BrowsingContextAndDocument { struct BrowsingContextAndDocument {

View file

@ -301,16 +301,6 @@ private:
bool m_listen_for_dom_mutations { false }; bool m_listen_for_dom_mutations { false };
}; };
struct PaintOptions {
enum class PaintOverlay {
No,
Yes,
};
PaintOverlay paint_overlay { PaintOverlay::Yes };
bool should_show_line_box_borders { false };
};
enum class DisplayListPlayerType { enum class DisplayListPlayerType {
SkiaGPUIfAvailable, SkiaGPUIfAvailable,
SkiaCPU, SkiaCPU,
@ -320,6 +310,7 @@ class PageClient : public JS::Cell {
GC_CELL(PageClient, JS::Cell); GC_CELL(PageClient, JS::Cell);
public: public:
virtual u64 id() const = 0;
virtual Page& page() = 0; virtual Page& page() = 0;
virtual Page const& page() const = 0; virtual Page const& page() const = 0;
virtual bool is_connection_open() const = 0; virtual bool is_connection_open() const = 0;
@ -331,9 +322,6 @@ public:
virtual CSS::PreferredColorScheme preferred_color_scheme() const = 0; virtual CSS::PreferredColorScheme preferred_color_scheme() const = 0;
virtual CSS::PreferredContrast preferred_contrast() const = 0; virtual CSS::PreferredContrast preferred_contrast() const = 0;
virtual CSS::PreferredMotion preferred_motion() const = 0; virtual CSS::PreferredMotion preferred_motion() const = 0;
virtual void paint_next_frame() = 0;
virtual void process_screenshot_requests() = 0;
virtual void start_display_list_rendering(DevicePixelRect const&, Painting::BackingStore&, PaintOptions, Function<void()>&& callback) = 0;
virtual Queue<QueuedInputEvent>& input_event_queue() = 0; virtual Queue<QueuedInputEvent>& input_event_queue() = 0;
virtual void report_finished_handling_input_event(u64 page_id, EventResult event_was_handled) = 0; virtual void report_finished_handling_input_event(u64 page_id, EventResult event_was_handled) = 0;
virtual void page_did_change_title(ByteString const&) { } virtual void page_did_change_title(ByteString const&) { }
@ -415,9 +403,10 @@ public:
virtual void page_did_mutate_dom([[maybe_unused]] FlyString const& type, [[maybe_unused]] DOM::Node const& target, [[maybe_unused]] DOM::NodeList& added_nodes, [[maybe_unused]] DOM::NodeList& removed_nodes, [[maybe_unused]] GC::Ptr<DOM::Node> previous_sibling, [[maybe_unused]] GC::Ptr<DOM::Node> next_sibling, [[maybe_unused]] Optional<String> const& attribute_name) { } virtual void page_did_mutate_dom([[maybe_unused]] FlyString const& type, [[maybe_unused]] DOM::Node const& target, [[maybe_unused]] DOM::NodeList& added_nodes, [[maybe_unused]] DOM::NodeList& removed_nodes, [[maybe_unused]] GC::Ptr<DOM::Node> previous_sibling, [[maybe_unused]] GC::Ptr<DOM::Node> next_sibling, [[maybe_unused]] Optional<String> const& attribute_name) { }
virtual void received_message_from_web_ui([[maybe_unused]] String const& name, [[maybe_unused]] JS::Value data) { } virtual void page_did_paint([[maybe_unused]] Gfx::IntRect const& content_rect, [[maybe_unused]] i32 bitmap_id) { }
virtual void page_did_take_screenshot(Gfx::ShareableBitmap const&) { }
virtual bool is_ready_to_paint() const = 0; virtual void received_message_from_web_ui([[maybe_unused]] String const& name, [[maybe_unused]] JS::Value data) { }
virtual DisplayListPlayerType display_list_player_type() const = 0; virtual DisplayListPlayerType display_list_player_type() const = 0;

View file

@ -8,6 +8,7 @@
#include <AK/AtomicRefCounted.h> #include <AK/AtomicRefCounted.h>
#include <AK/Noncopyable.h> #include <AK/Noncopyable.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Size.h> #include <LibGfx/Size.h>
#ifdef AK_OS_MACOS #ifdef AK_OS_MACOS

View file

@ -6,7 +6,7 @@
#include <LibCore/Timer.h> #include <LibCore/Timer.h>
#include <LibWeb/HTML/TraversableNavigable.h> #include <LibWeb/HTML/TraversableNavigable.h>
#include <WebContent/BackingStoreManager.h> #include <LibWeb/Painting/BackingStoreManager.h>
#include <WebContent/PageClient.h> #include <WebContent/PageClient.h>
#ifdef AK_OS_MACOS #ifdef AK_OS_MACOS
@ -15,7 +15,9 @@
# include <LibCore/Platform/MachMessageTypes.h> # include <LibCore/Platform/MachMessageTypes.h>
#endif #endif
namespace WebContent { namespace Web::Painting {
GC_DEFINE_ALLOCATOR(BackingStoreManager);
#ifdef AK_OS_MACOS #ifdef AK_OS_MACOS
static Optional<Core::MachPort> s_browser_mach_port; static Optional<Core::MachPort> s_browser_mach_port;
@ -25,14 +27,20 @@ void BackingStoreManager::set_browser_mach_port(Core::MachPort&& port)
} }
#endif #endif
BackingStoreManager::BackingStoreManager(PageClient& page_client) BackingStoreManager::BackingStoreManager(HTML::Navigable& navigable)
: m_page_client(page_client) : m_navigable(navigable)
{ {
m_backing_store_shrink_timer = Core::Timer::create_single_shot(3000, [this] { m_backing_store_shrink_timer = Core::Timer::create_single_shot(3000, [this] {
resize_backing_stores_if_needed(WindowResizingInProgress::No); resize_backing_stores_if_needed(WindowResizingInProgress::No);
}); });
} }
void BackingStoreManager::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_navigable);
}
void BackingStoreManager::restart_resize_timer() void BackingStoreManager::restart_resize_timer()
{ {
m_backing_store_shrink_timer->restart(); m_backing_store_shrink_timer->restart();
@ -41,7 +49,7 @@ void BackingStoreManager::restart_resize_timer()
void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size) void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size)
{ {
#ifdef AK_OS_MACOS #ifdef AK_OS_MACOS
if (s_browser_mach_port.has_value()) { if (m_navigable->is_top_level_traversable() && s_browser_mach_port.has_value()) {
auto back_iosurface = Core::IOSurfaceHandle::create(size.width(), size.height()); auto back_iosurface = Core::IOSurfaceHandle::create(size.width(), size.height());
auto back_iosurface_port = back_iosurface.create_mach_port(); auto back_iosurface_port = back_iosurface.create_mach_port();
@ -51,8 +59,10 @@ void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size)
m_front_bitmap_id = m_next_bitmap_id++; m_front_bitmap_id = m_next_bitmap_id++;
m_back_bitmap_id = m_next_bitmap_id++; m_back_bitmap_id = m_next_bitmap_id++;
auto& page_client = m_navigable->top_level_traversable()->page().client();
Core::Platform::BackingStoreMetadata metadata; Core::Platform::BackingStoreMetadata metadata;
metadata.page_id = m_page_client.m_id; metadata.page_id = page_client.id();
metadata.front_backing_store_id = m_front_bitmap_id; metadata.front_backing_store_id = m_front_bitmap_id;
metadata.back_backing_store_id = m_back_bitmap_id; metadata.back_backing_store_id = m_back_bitmap_id;
@ -83,8 +93,8 @@ void BackingStoreManager::reallocate_backing_stores(Gfx::IntSize size)
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
m_front_store = Web::Painting::IOSurfaceBackingStore::create(move(front_iosurface)); m_front_store = IOSurfaceBackingStore::create(move(front_iosurface));
m_back_store = Web::Painting::IOSurfaceBackingStore::create(move(back_iosurface)); m_back_store = IOSurfaceBackingStore::create(move(back_iosurface));
return; return;
} }
@ -96,17 +106,18 @@ 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 = Web::Painting::BitmapBackingStore::create(front_bitmap); m_front_store = BitmapBackingStore::create(front_bitmap);
m_back_store = Web::Painting::BitmapBackingStore::create(back_bitmap); m_back_store = 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()); if (m_navigable->is_top_level_traversable()) {
auto& page_client = m_navigable->top_level_traversable()->page().client();
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());
}
} }
void BackingStoreManager::resize_backing_stores_if_needed(WindowResizingInProgress window_resize_in_progress) void BackingStoreManager::resize_backing_stores_if_needed(WindowResizingInProgress window_resize_in_progress)
{ {
auto css_pixels_viewpor_rect = m_page_client.page().top_level_traversable()->viewport_rect(); auto viewport_size = m_navigable->page().css_to_device_rect(m_navigable->viewport_rect()).size();
auto viewport_size = m_page_client.page().css_to_device_rect(css_pixels_viewpor_rect).size();
if (viewport_size.is_empty()) if (viewport_size.is_empty())
return; return;

View file

@ -6,12 +6,15 @@
#pragma once #pragma once
#include <LibWeb/HTML/Navigable.h>
#include <LibWeb/Painting/BackingStore.h> #include <LibWeb/Painting/BackingStore.h>
#include <WebContent/Forward.h>
namespace WebContent { namespace Web::Painting {
class BackingStoreManager : public JS::Cell {
GC_CELL(BackingStoreManager, JS::Cell);
GC_DECLARE_ALLOCATOR(BackingStoreManager);
class BackingStoreManager {
public: public:
#ifdef AK_OS_MACOS #ifdef AK_OS_MACOS
static void set_browser_mach_port(Core::MachPort&&); static void set_browser_mach_port(Core::MachPort&&);
@ -39,18 +42,19 @@ public:
return backing_store; return backing_store;
} }
BackingStoreManager(PageClient&); virtual void visit_edges(Cell::Visitor& visitor) override;
BackingStoreManager(HTML::Navigable&);
private: private:
void swap_back_and_front(); void swap_back_and_front();
// FIXME: We should come up with an ownership model for this class that makes the GC-checker happy GC::Ref<HTML::Navigable> m_navigable;
IGNORE_GC PageClient& m_page_client;
i32 m_front_bitmap_id { -1 }; i32 m_front_bitmap_id { -1 };
i32 m_back_bitmap_id { -1 }; i32 m_back_bitmap_id { -1 };
RefPtr<Web::Painting::BackingStore> m_front_store; RefPtr<Painting::BackingStore> m_front_store;
RefPtr<Web::Painting::BackingStore> m_back_store; RefPtr<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;

View file

@ -55,7 +55,7 @@ void NavigableContainerViewportPaintable::paint(PaintContext& context, PaintPhas
context.display_list_recorder().add_clip_rect(clip_rect.to_type<int>()); context.display_list_recorder().add_clip_rect(clip_rect.to_type<int>());
DOM::Document::PaintConfig paint_config; HTML::PaintConfig paint_config;
paint_config.paint_overlay = context.should_paint_overlay(); paint_config.paint_overlay = context.should_paint_overlay();
paint_config.should_show_line_box_borders = context.should_show_line_box_borders(); paint_config.should_show_line_box_borders = context.should_show_line_box_borders();
auto display_list = const_cast<DOM::Document*>(hosted_document)->record_display_list(paint_config); auto display_list = const_cast<DOM::Document*>(hosted_document)->record_display_list(paint_config);

View file

@ -66,6 +66,7 @@ public:
GC::Ref<Page> m_host_page; GC::Ref<Page> m_host_page;
GC::Ptr<Page> m_svg_page; GC::Ptr<Page> m_svg_page;
virtual u64 id() const override { VERIFY_NOT_REACHED(); }
virtual Page& page() override { return *m_svg_page; } virtual Page& page() override { return *m_svg_page; }
virtual Page const& page() const override { return *m_svg_page; } virtual Page const& page() const override { return *m_svg_page; }
virtual bool is_connection_open() const override { return false; } virtual bool is_connection_open() const override { return false; }
@ -76,10 +77,6 @@ public:
virtual CSS::PreferredContrast preferred_contrast() const override { return m_host_page->client().preferred_contrast(); } virtual CSS::PreferredContrast preferred_contrast() const override { return m_host_page->client().preferred_contrast(); }
virtual CSS::PreferredMotion preferred_motion() const override { return m_host_page->client().preferred_motion(); } virtual CSS::PreferredMotion preferred_motion() const override { return m_host_page->client().preferred_motion(); }
virtual void request_file(FileRequest) override { } virtual void request_file(FileRequest) override { }
virtual void paint_next_frame() override { }
virtual void process_screenshot_requests() override { }
virtual void start_display_list_rendering(DevicePixelRect const&, Painting::BackingStore&, PaintOptions, Function<void()>&&) override { }
virtual bool is_ready_to_paint() const override { return true; }
virtual Queue<QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); } virtual Queue<QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); }
virtual void report_finished_handling_input_event([[maybe_unused]] u64 page_id, [[maybe_unused]] EventResult event_was_handled) override { } virtual void report_finished_handling_input_event([[maybe_unused]] u64 page_id, [[maybe_unused]] EventResult event_was_handled) override { }

View file

@ -58,7 +58,8 @@ ErrorOr<GC::Ref<HTML::HTMLCanvasElement>, WebDriver::Error> draw_bounding_box_fr
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 = Painting::BitmapBackingStore::create(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] { HTML::PaintConfig paint_config { .canvas_fill_rect = paint_rect };
browsing_context.active_document()->navigable()->start_display_list_rendering(backing_store, paint_config, [&did_paint] {
did_paint = true; did_paint = true;
}); });
HTML::main_thread_event_loop().spin_until(GC::create_function(HTML::main_thread_event_loop().heap(), [&] { HTML::main_thread_event_loop().spin_until(GC::create_function(HTML::main_thread_event_loop().heap(), [&] {

View file

@ -1,7 +1,6 @@
include(audio) include(audio)
set(SOURCES set(SOURCES
BackingStoreManager.cpp
ConnectionFromClient.cpp ConnectionFromClient.cpp
ConsoleGlobalEnvironmentExtensions.cpp ConsoleGlobalEnvironmentExtensions.cpp
DevToolsConsoleClient.cpp DevToolsConsoleClient.cpp

View file

@ -334,8 +334,9 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString request, ByteSt
if (request == "set-line-box-borders") { if (request == "set-line-box-borders") {
bool state = argument == "on"; bool state = argument == "on";
page->set_should_show_line_box_borders(state); auto traversable = page->page().top_level_traversable();
page->page().top_level_traversable()->set_needs_repaint(); traversable->set_should_show_line_box_borders(state);
traversable->set_needs_repaint();
return; return;
} }

View file

@ -65,7 +65,6 @@ PageClient::PageClient(PageHost& owner, u64 id)
: m_owner(owner) : m_owner(owner)
, m_page(Web::Page::create(Web::Bindings::main_thread_vm(), *this)) , m_page(Web::Page::create(Web::Bindings::main_thread_vm(), *this))
, m_id(id) , m_id(id)
, m_backing_store_manager(*this)
{ {
setup_palette(); setup_palette();
@ -79,11 +78,6 @@ PageClient::PageClient(PageHost& owner, u64 id)
PageClient::~PageClient() = default; PageClient::~PageClient() = default;
bool PageClient::is_ready_to_paint() const
{
return m_number_of_queued_rasterization_tasks <= 1;
}
void PageClient::visit_edges(JS::Cell::Visitor& visitor) void PageClient::visit_edges(JS::Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
@ -188,64 +182,9 @@ Web::Layout::Viewport* PageClient::layout_root()
return document->layout_node(); return document->layout_node();
} }
void PageClient::process_screenshot_requests()
{
while (!m_screenshot_tasks.is_empty()) {
auto task = m_screenshot_tasks.dequeue();
if (task.node_id.has_value()) {
auto* dom_node = Web::DOM::Node::from_unique_id(*task.node_id);
if (!dom_node || !dom_node->paintable_box()) {
client().async_did_take_screenshot(m_id, {});
continue;
}
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 = Web::Painting::BitmapBackingStore::create(*bitmap);
start_display_list_rendering(rect, backing_store, { .paint_overlay = Web::PaintOptions::PaintOverlay::No }, [this, backing_store] {
client().async_did_take_screenshot(m_id, backing_store->bitmap().to_shareable_bitmap());
});
} else {
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 backing_store = Web::Painting::BitmapBackingStore::create(*bitmap);
start_display_list_rendering(rect, backing_store, {}, [this, backing_store] {
client().async_did_take_screenshot(m_id, backing_store->bitmap().to_shareable_bitmap());
});
}
}
}
void PageClient::ready_to_paint() void PageClient::ready_to_paint()
{ {
m_number_of_queued_rasterization_tasks--; page().top_level_traversable()->ready_to_paint();
VERIFY(m_number_of_queued_rasterization_tasks >= 0 && m_number_of_queued_rasterization_tasks < 2);
}
void PageClient::paint_next_frame()
{
auto [backing_store_id, back_store] = m_backing_store_manager.acquire_store_for_next_frame();
if (!back_store)
return;
VERIFY(m_number_of_queued_rasterization_tasks <= 1);
m_number_of_queued_rasterization_tasks++;
auto viewport_rect = page().css_to_device_rect(page().top_level_traversable()->viewport_rect());
start_display_list_rendering(viewport_rect, *back_store, {}, [this, viewport_rect, backing_store_id] {
client().async_did_paint(m_id, viewport_rect.to_type<int>(), backing_store_id);
});
}
void PageClient::start_display_list_rendering(Web::DevicePixelRect const& content_rect, Web::Painting::BackingStore& target, Web::PaintOptions paint_options, Function<void()>&& callback)
{
paint_options.should_show_line_box_borders = m_should_show_line_box_borders;
auto& traversable = *page().top_level_traversable();
auto display_list = traversable.record_display_list(content_rect, paint_options);
if (!display_list) {
callback();
return;
}
traversable.start_display_list_rendering(*display_list, target, move(callback));
} }
Queue<Web::QueuedInputEvent>& PageClient::input_event_queue() Queue<Web::QueuedInputEvent>& PageClient::input_event_queue()
@ -261,10 +200,6 @@ void PageClient::report_finished_handling_input_event(u64 page_id, Web::EventRes
void PageClient::set_viewport_size(Web::DevicePixelSize const& size) void PageClient::set_viewport_size(Web::DevicePixelSize const& size)
{ {
page().top_level_traversable()->set_viewport_size(page().device_to_css_size(size)); page().top_level_traversable()->set_viewport_size(page().device_to_css_size(size));
m_backing_store_manager.restart_resize_timer();
m_backing_store_manager.resize_backing_stores_if_needed(BackingStoreManager::WindowResizingInProgress::Yes);
m_pending_set_browser_zoom_request = false;
} }
void PageClient::page_did_request_cursor_change(Gfx::Cursor const& cursor) void PageClient::page_did_request_cursor_change(Gfx::Cursor const& cursor)
@ -411,12 +346,12 @@ void PageClient::page_did_set_test_timeout(double milliseconds)
void PageClient::page_did_set_browser_zoom(double factor) void PageClient::page_did_set_browser_zoom(double factor)
{ {
m_pending_set_browser_zoom_request = true; auto traversable = page().top_level_traversable();
traversable->set_pending_set_browser_zoom_request(true);
client().async_did_set_browser_zoom(m_id, factor); client().async_did_set_browser_zoom(m_id, factor);
auto& event_loop = Web::HTML::main_thread_event_loop(); auto& event_loop = Web::HTML::main_thread_event_loop();
event_loop.spin_until(GC::create_function(event_loop.heap(), [&]() { event_loop.spin_until(GC::create_function(event_loop.heap(), [this, traversable]() {
return !m_pending_set_browser_zoom_request || !is_connection_open(); return !traversable->pending_set_browser_zoom_request() || !is_connection_open();
})); }));
} }
@ -765,6 +700,16 @@ void PageClient::page_did_mutate_dom(FlyString const& type, Web::DOM::Node const
client().async_did_mutate_dom(m_id, { type.to_string(), target.unique_id(), move(serialized_target), mutation.release_value() }); client().async_did_mutate_dom(m_id, { type.to_string(), target.unique_id(), move(serialized_target), mutation.release_value() });
} }
void PageClient::page_did_paint(Gfx::IntRect const& content_rect, i32 bitmap_id)
{
client().async_did_paint(m_id, content_rect, bitmap_id);
}
void PageClient::page_did_take_screenshot(Gfx::ShareableBitmap const& screenshot)
{
client().async_did_take_screenshot(m_id, screenshot);
}
ErrorOr<void> PageClient::connect_to_webdriver(ByteString const& webdriver_ipc_path) ErrorOr<void> PageClient::connect_to_webdriver(ByteString const& webdriver_ipc_path)
{ {
VERIFY(!m_webdriver); VERIFY(!m_webdriver);
@ -961,8 +906,7 @@ Web::DisplayListPlayerType PageClient::display_list_player_type() const
void PageClient::queue_screenshot_task(Optional<Web::UniqueNodeID> node_id) void PageClient::queue_screenshot_task(Optional<Web::UniqueNodeID> node_id)
{ {
m_screenshot_tasks.enqueue({ node_id }); page().top_level_traversable()->queue_screenshot_task(node_id);
page().top_level_traversable()->set_needs_repaint();
} }
} }

View file

@ -13,11 +13,11 @@
#include <LibWeb/HTML/AudioPlayState.h> #include <LibWeb/HTML/AudioPlayState.h>
#include <LibWeb/HTML/FileFilter.h> #include <LibWeb/HTML/FileFilter.h>
#include <LibWeb/Page/Page.h> #include <LibWeb/Page/Page.h>
#include <LibWeb/Painting/BackingStoreManager.h>
#include <LibWeb/PixelUnits.h> #include <LibWeb/PixelUnits.h>
#include <LibWeb/StorageAPI/StorageEndpoint.h> #include <LibWeb/StorageAPI/StorageEndpoint.h>
#include <LibWebView/Forward.h> #include <LibWebView/Forward.h>
#include <LibWebView/StorageOperationError.h> #include <LibWebView/StorageOperationError.h>
#include <WebContent/BackingStoreManager.h>
#include <WebContent/Forward.h> #include <WebContent/Forward.h>
namespace WebContent { namespace WebContent {
@ -31,6 +31,8 @@ public:
virtual ~PageClient() override; virtual ~PageClient() override;
virtual u64 id() const override { return m_id; }
enum class UseSkiaPainter { enum class UseSkiaPainter {
CPUBackend, CPUBackend,
GPUBackendIfAvailable, GPUBackendIfAvailable,
@ -40,18 +42,12 @@ public:
virtual bool is_headless() const override; virtual bool is_headless() const override;
static void set_is_headless(bool); static void set_is_headless(bool);
virtual bool is_ready_to_paint() const override;
virtual Web::Page& page() override { return *m_page; } virtual Web::Page& page() override { return *m_page; }
virtual Web::Page const& page() const override { return *m_page; } virtual Web::Page const& page() const override { return *m_page; }
ErrorOr<void> connect_to_webdriver(ByteString const& webdriver_ipc_path); ErrorOr<void> connect_to_webdriver(ByteString const& webdriver_ipc_path);
ErrorOr<void> connect_to_web_ui(IPC::File); ErrorOr<void> connect_to_web_ui(IPC::File);
virtual void paint_next_frame() override;
virtual void process_screenshot_requests() override;
virtual void start_display_list_rendering(Web::DevicePixelRect const& content_rect, Web::Painting::BackingStore&, Web::PaintOptions, Function<void()>&& callback) override;
virtual Queue<Web::QueuedInputEvent>& input_event_queue() override; virtual Queue<Web::QueuedInputEvent>& input_event_queue() override;
virtual void report_finished_handling_input_event(u64 page_id, Web::EventResult event_was_handled) override; virtual void report_finished_handling_input_event(u64 page_id, Web::EventResult event_was_handled) override;
@ -62,7 +58,6 @@ public:
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme); void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
void set_preferred_contrast(Web::CSS::PreferredContrast); void set_preferred_contrast(Web::CSS::PreferredContrast);
void set_preferred_motion(Web::CSS::PreferredMotion); void set_preferred_motion(Web::CSS::PreferredMotion);
void set_should_show_line_box_borders(bool b) { m_should_show_line_box_borders = b; }
void set_has_focus(bool); void set_has_focus(bool);
void set_is_scripting_enabled(bool); void set_is_scripting_enabled(bool);
void set_window_position(Web::DevicePixelPoint); void set_window_position(Web::DevicePixelPoint);
@ -102,8 +97,6 @@ public:
void queue_screenshot_task(Optional<Web::UniqueNodeID> node_id); void queue_screenshot_task(Optional<Web::UniqueNodeID> node_id);
friend class BackingStoreManager;
private: private:
PageClient(PageHost&, u64 id); PageClient(PageHost&, u64 id);
@ -182,6 +175,8 @@ private:
virtual void page_did_allocate_backing_stores(i32 front_bitmap_id, Gfx::ShareableBitmap front_bitmap, i32 back_bitmap_id, Gfx::ShareableBitmap back_bitmap) override; virtual void page_did_allocate_backing_stores(i32 front_bitmap_id, Gfx::ShareableBitmap front_bitmap, i32 back_bitmap_id, Gfx::ShareableBitmap back_bitmap) override;
virtual IPC::File request_worker_agent(Web::Bindings::AgentType) override; virtual IPC::File request_worker_agent(Web::Bindings::AgentType) override;
virtual void page_did_mutate_dom(FlyString const& type, Web::DOM::Node const& target, Web::DOM::NodeList& added_nodes, Web::DOM::NodeList& removed_nodes, GC::Ptr<Web::DOM::Node> previous_sibling, GC::Ptr<Web::DOM::Node> next_sibling, Optional<String> const& attribute_name) override; virtual void page_did_mutate_dom(FlyString const& type, Web::DOM::Node const& target, Web::DOM::NodeList& added_nodes, Web::DOM::NodeList& removed_nodes, GC::Ptr<Web::DOM::Node> previous_sibling, GC::Ptr<Web::DOM::Node> next_sibling, Optional<String> const& attribute_name) override;
virtual void page_did_paint(Gfx::IntRect const& content_rect, i32 bitmap_id) override;
virtual void page_did_take_screenshot(Gfx::ShareableBitmap const& screenshot) override;
virtual void received_message_from_web_ui(String const& name, JS::Value data) override; virtual void received_message_from_web_ui(String const& name, JS::Value data) override;
Web::Layout::Viewport* layout_root(); Web::Layout::Viewport* layout_root();
@ -195,16 +190,8 @@ private:
Web::DevicePixelSize m_content_size; Web::DevicePixelSize m_content_size;
float m_device_pixels_per_css_pixel { 1.0f }; float m_device_pixels_per_css_pixel { 1.0f };
u64 m_id { 0 }; u64 m_id { 0 };
bool m_should_show_line_box_borders { false };
bool m_has_focus { false }; bool m_has_focus { false };
i32 m_number_of_queued_rasterization_tasks { 0 };
struct ScreenshotTask {
Optional<Web::UniqueNodeID> node_id;
};
Queue<ScreenshotTask> m_screenshot_tasks;
Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto }; Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto };
Web::CSS::PreferredContrast m_preferred_contrast { Web::CSS::PreferredContrast::NoPreference }; Web::CSS::PreferredContrast m_preferred_contrast { Web::CSS::PreferredContrast::NoPreference };
Web::CSS::PreferredMotion m_preferred_motion { Web::CSS::PreferredMotion::NoPreference }; Web::CSS::PreferredMotion m_preferred_motion { Web::CSS::PreferredMotion::NoPreference };
@ -212,15 +199,11 @@ private:
RefPtr<WebDriverConnection> m_webdriver; RefPtr<WebDriverConnection> m_webdriver;
RefPtr<WebUIConnection> m_web_ui; RefPtr<WebUIConnection> m_web_ui;
BackingStoreManager m_backing_store_manager;
WeakPtr<WebContentConsoleClient> m_top_level_document_console_client; WeakPtr<WebContentConsoleClient> m_top_level_document_console_client;
GC::Root<JS::GlobalObject> m_console_global_object; GC::Root<JS::GlobalObject> m_console_global_object;
RefPtr<Core::Timer> m_paint_refresh_timer; RefPtr<Core::Timer> m_paint_refresh_timer;
bool m_pending_set_browser_zoom_request = false;
}; };
} }

View file

@ -24,6 +24,7 @@
#include <LibWeb/Loader/ContentFilter.h> #include <LibWeb/Loader/ContentFilter.h>
#include <LibWeb/Loader/GeneratedPagesLoader.h> #include <LibWeb/Loader/GeneratedPagesLoader.h>
#include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Painting/BackingStoreManager.h>
#include <LibWeb/Painting/PaintableBox.h> #include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Platform/AudioCodecPluginAgnostic.h> #include <LibWeb/Platform/AudioCodecPluginAgnostic.h>
#include <LibWeb/Platform/EventLoopPluginSerenity.h> #include <LibWeb/Platform/EventLoopPluginSerenity.h>
@ -186,7 +187,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// FIXME: For some reason, our implementation of IOSurface does not work on Intel macOS. Remove this conditional // FIXME: For some reason, our implementation of IOSurface does not work on Intel macOS. Remove this conditional
// compilation when that is resolved. // compilation when that is resolved.
# if ARCH(AARCH64) # if ARCH(AARCH64)
WebContent::BackingStoreManager::set_browser_mach_port(move(server_port)); Web::Painting::BackingStoreManager::set_browser_mach_port(move(server_port));
# endif # endif
} }
#endif #endif

View file

@ -77,10 +77,6 @@ Web::CSS::PreferredMotion PageHost::preferred_motion() const
return Web::CSS::PreferredMotion::Auto; return Web::CSS::PreferredMotion::Auto;
} }
void PageHost::start_display_list_rendering(Web::DevicePixelRect const&, Web::Painting::BackingStore&, Web::PaintOptions, Function<void()>&&)
{
}
void PageHost::request_file(Web::FileRequest request) void PageHost::request_file(Web::FileRequest request)
{ {
m_client.request_file(move(request)); m_client.request_file(move(request));

View file

@ -22,6 +22,7 @@ public:
virtual ~PageHost(); virtual ~PageHost();
virtual u64 id() const override { VERIFY_NOT_REACHED(); }
virtual Web::Page& page() override; virtual Web::Page& page() override;
virtual Web::Page const& page() const override; virtual Web::Page const& page() const override;
virtual bool is_connection_open() const override; virtual bool is_connection_open() const override;
@ -31,11 +32,7 @@ public:
virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override; virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override;
virtual Web::CSS::PreferredContrast preferred_contrast() const override; virtual Web::CSS::PreferredContrast preferred_contrast() const override;
virtual Web::CSS::PreferredMotion preferred_motion() const override; virtual Web::CSS::PreferredMotion preferred_motion() const override;
virtual void paint_next_frame() override { }
virtual void process_screenshot_requests() override { }
virtual void start_display_list_rendering(Web::DevicePixelRect const&, Web::Painting::BackingStore&, Web::PaintOptions, Function<void()>&& callback) override;
virtual void request_file(Web::FileRequest) override; virtual void request_file(Web::FileRequest) override;
virtual bool is_ready_to_paint() const override { return true; }
virtual Web::DisplayListPlayerType display_list_player_type() const override { VERIFY_NOT_REACHED(); } virtual Web::DisplayListPlayerType display_list_player_type() const override { VERIFY_NOT_REACHED(); }
virtual bool is_headless() const override { VERIFY_NOT_REACHED(); } virtual bool is_headless() const override { VERIFY_NOT_REACHED(); }
virtual Queue<Web::QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); } virtual Queue<Web::QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); }