Skip to content

Truly independent web browser

LibWeb+LibWebView+WebContent+Hub+UI/Qt: Add a Debug window for layers

Aliaksandr Kalenike8138ace716b
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index 40224331c16..987b614a0e2 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -275,6 +275,32 @@ Utf16String serialize_painting_dump(Layout::BegunRead const& read, DOM::Document
return move(context.dump);
}
+OwnersOfVisualContextNodes describe_owners_of_visual_context_nodes(DOM::Document const& document, ReadonlySpan<u32> spatial_node_indices, ReadonlySpan<u32> effect_node_indices)
+{
+ struct DescribeContext {
+ GC::Ref<DOM::Document const> document;
+ Vector<String> owners;
+ } context { document, {} };
+ context.owners.resize(spatial_node_indices.size() + effect_node_indices.size());
+
+ Layout::ForcedReadScope read_scope { document };
+ Layout::BegunRead const& read = read_scope;
+ if (!document.has_committed_viewport_box())
+ return { .structural_epoch = 0, .owners = move(context.owners) };
+
+ Layout::RustFFI::FfiVisualContextNodeOwnerCallbacks callbacks {
+ .context = &context,
+ .debug_description = [](void* context_pointer, Compositing::RustFFI::NodeSlotId slot, void* description_sink) { push_debug_description(*static_cast<DescribeContext*>(context_pointer)->document, slot, description_sink); },
+ .take_owner = [](void* context_pointer, size_t position, u8 const* bytes, size_t byte_count) {
+ auto& context = *static_cast<DescribeContext*>(context_pointer);
+ VERIFY(position < context.owners.size());
+ context.owners[position] = String::from_utf8_with_replacement_character(StringView { bytes, byte_count }); },
+ };
+ auto structural_epoch = Layout::RustFFI::painting_describe_owners_of_visual_context_nodes(document_host(document), &read, viewport_row_slot(read, document),
+ spatial_node_indices.data(), spatial_node_indices.size(), effect_node_indices.data(), effect_node_indices.size(), callbacks);
+ return { .structural_epoch = structural_epoch, .owners = move(context.owners) };
+}
+
Utf16String display_list_dump_changes(Optional<StringView> previous_jsonl, StringView jsonl)
{
Utf16String changes;
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.h b/Libraries/LibWeb/Painting/PaintingRustBridge.h
index 09a9b1d7931..563ef753c33 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.h
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.h
@@ -76,6 +76,16 @@ WEB_API void take_recording_trace_if_pending(Layout::BegunRead const&, DOM::Docu
WEB_API Utf16String serialize_painting_dump(Layout::BegunRead const&, DOM::Document const&, DisplayListDumpOptions const&);
WEB_API Utf16String display_list_dump_changes(Optional<StringView> previous_jsonl, StringView jsonl);
+struct OwnersOfVisualContextNodes {
+ // Zero for a document without a visual context tree.
+ u64 structural_epoch { 0 };
+ // By the position of each node among the spatial nodes and then the effect nodes asked of, empty for a node without
+ // a live owner.
+ Vector<String> owners;
+};
+// Describes the boxes that own the nodes of the document's visual context tree, as the boxes describe themselves.
+WEB_API OwnersOfVisualContextNodes describe_owners_of_visual_context_nodes(DOM::Document const&, ReadonlySpan<u32> spatial_node_indices, ReadonlySpan<u32> effect_node_indices);
+
WEB_API Layout::RustFFI::FfiVectorImageKey vector_image_key_to_ffi(VectorImageKey const&);
// Has the compositor rasterize `paint` into `target` as `request` asks, which must be a shareable BGRA8888 bitmap with
// premultiplied alpha. Returns false if nothing was drawn.
diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
index 9faf525c291..02d1fa4a3a1 100644
--- a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
+++ b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
@@ -199,6 +199,88 @@ pub unsafe extern "C" fn render_state_dump_compositor_animations(
flags
}
+/// What describing the owners of nodes of the visual context tree asks the document. The fields are private: the
+/// callbacks are reached only through the method below, which takes the main thread token.
+///
+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export whose
+/// safety contract keeps them callable, and the private fields let nothing else call them.
+#[derive(Clone, Copy)]
+#[repr(C)]
+pub struct FfiVisualContextNodeOwnerCallbacks {
+ context: *mut c_void,
+ /// Describes the row in the slot, as its layout node describes itself.
+ debug_description: extern "C" fn(context: *mut c_void, slot: NodeSlotId, description_sink: *mut c_void),
+ /// Takes the description of the owner of the node at `position` among the nodes asked of.
+ take_owner: extern "C" fn(context: *mut c_void, position: usize, bytes: *const u8, byte_count: usize),
+}
+
+impl FfiVisualContextNodeOwnerCallbacks {
+ fn take_owner(&self, _: &MainThread, slot: NodeSlotId, position: usize) {
+ let mut description = Vec::new();
+ // The C++ host fills the description sink synchronously through the exported push function, and copies the
+ // description it takes.
+ (self.debug_description)(self.context, slot, (&raw mut description).cast());
+ (self.take_owner)(self.context, position, description.as_ptr(), description.len());
+ }
+}
+
+/// Describes the boxes that own the nodes of the visual context tree of `host`'s document, prepared up to date, that
+/// `spatial_node_indices` and then `effect_node_indices` name: `take_owner` gets the description of each live owner,
+/// by the position of its node among those asked of. Answers the structural epoch of the tree, or zero where the
+/// document has none, when nothing is described.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread. Each pointer and count of indices must make a
+/// valid slice for this call, and the callbacks are called synchronously, with a `Vec<u8>` sink the host fills through
+/// `layout_arena_paint_push_bytes`.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn painting_describe_owners_of_visual_context_nodes(
+ host: &crate::render_state::DocumentHost,
+ read: &crate::render_state::BegunRead,
+ viewport: NodeSlotId,
+ spatial_node_indices: *const u32,
+ spatial_node_count: usize,
+ effect_node_indices: *const u32,
+ effect_node_count: usize,
+ callbacks: FfiVisualContextNodeOwnerCallbacks,
+) -> u64 {
+ // SAFETY: Guaranteed by the entry point's contract.
+ let main_thread = unsafe { main_thread(host) };
+ // SAFETY: As above.
+ let Some(visual_context_tree) = (unsafe { crate::painting::ffi::main_visual_context_tree(host, read) }) else {
+ return 0;
+ };
+ // SAFETY: Guaranteed by the entry point's contract.
+ let slice_of = |indices: *const u32, count: usize| unsafe { ak::slice_from_raw_parts(indices, count) }.to_vec();
+ let nodes: Vec<(SlotKind, u32)> = slice_of(spatial_node_indices, spatial_node_count)
+ .into_iter()
+ .map(|index| (SlotKind::Spatial, index))
+ .chain(
+ slice_of(effect_node_indices, effect_node_count)
+ .into_iter()
+ .map(|index| (SlotKind::Effect, index)),
+ )
+ .collect();
+ let live_owners = crate::painting::ffi::read_arena(host, read, (viewport, nodes), |arena, (viewport, nodes)| {
+ let owners = VisualContextNodeOwners::collect(arena, viewport);
+ nodes
+ .into_iter()
+ .map(|(kind, index)| {
+ owners
+ .owner(kind, index)
+ .filter(|&owner| owner != NodeSlotId::INVALID && arena.slot_is_live(owner))
+ })
+ .collect::<Vec<_>>()
+ });
+ for (position, owner) in live_owners.into_iter().enumerate() {
+ if let Some(owner) = owner {
+ callbacks.take_owner(&main_thread, owner, position);
+ }
+ }
+ visual_context_tree.structural_epoch
+}
+
/// # Safety
///
/// Dumps `display_list` with the nodes it names of the visual context tree of `host`'s document, prepared up to date.
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 76f9ccfe10b..861492d25e2 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -3025,6 +3025,15 @@ void Application::set_shows_caret_hit_test_debug_overlay(bool shows)
send_debug_switch_to_every_view("set-caret-hit-test-debug-overlay"sv, shows);
}
+void Application::set_shows_compositor_layers(bool shows)
+{
+ m_shows_compositor_layers = shows;
+ ViewImplementation::for_each_view([](ViewImplementation& view) {
+ view.update_ui_overlays();
+ return IterationDecision::Continue;
+ });
+}
+
void Application::dump_cookies() const
{
m_default_session->cookie_jar->dump_cookies();
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index 4f0ac6d6065..34bb2de287d 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -394,6 +394,8 @@ public:
void set_blocks_pop_ups(bool);
void set_shows_line_box_borders(bool);
void set_shows_caret_hit_test_debug_overlay(bool);
+ bool shows_compositor_layers() const { return m_shows_compositor_layers; }
+ void set_shows_compositor_layers(bool);
bool devtools_enabled() const { return m_devtools; }
void dump_cookies() const;
@@ -741,6 +743,7 @@ private:
bool m_blocks_pop_ups { true };
bool m_shows_line_box_borders { false };
bool m_shows_caret_hit_test_debug_overlay { false };
+ bool m_shows_compositor_layers { false };
Web::Clipboard::SystemClipboardItem m_clipboard;
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 921c7f9f72b..628b31c18e5 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -2763,13 +2763,160 @@ void ViewImplementation::update_ui_overlays()
.hovered_control = m_picture_in_picture_controls_pointer_state.hovered_action(),
};
}
+ if (Application::the().shows_compositor_layers()) {
+ overlays.compositor_layers = Compositing::CompositorLayersOverlayState {
+ .font_family = Application::the().ui_font_family(),
+ .hidden_layer_ids = m_ids_of_hidden_compositor_layers,
+ .selected_layer_ids = m_ids_of_selected_compositor_layers,
+ .hovered_layer_id = m_id_of_hovered_compositor_layer,
+ .raster_count_reset_generation = m_compositor_layer_raster_count_reset_generation,
+ };
+ } else {
+ m_ids_of_hidden_compositor_layers.clear();
+ m_ids_of_selected_compositor_layers.clear();
+ m_id_of_hovered_compositor_layer.clear();
+ m_latest_compositor_layers.clear();
+ m_owners_of_visual_context_nodes = {};
+ }
Application::the().update_compositor_ui_overlays(page().compositor_context_id(), overlays);
}
+static u64 key_of_visual_context_node(Compositing::VisualContextNodeKind kind, u32 index)
+{
+ return (static_cast<u64>(kind) << 32) | index;
+}
+
+void ViewImplementation::set_compositor_layer_hidden(u64 layer_id, bool hidden)
+{
+ if (hidden == m_ids_of_hidden_compositor_layers.contains_slow(layer_id))
+ return;
+ if (hidden)
+ m_ids_of_hidden_compositor_layers.append(layer_id);
+ else
+ m_ids_of_hidden_compositor_layers.remove_first_matching([&](auto id) { return id == layer_id; });
+ update_ui_overlays();
+}
+
+void ViewImplementation::set_selected_compositor_layers(Vector<u64> layer_ids)
+{
+ if (m_ids_of_selected_compositor_layers == layer_ids)
+ return;
+ m_ids_of_selected_compositor_layers = move(layer_ids);
+ update_ui_overlays();
+}
+
+void ViewImplementation::set_hovered_compositor_layer(Optional<u64> layer_id)
+{
+ if (m_id_of_hovered_compositor_layer == layer_id)
+ return;
+ m_id_of_hovered_compositor_layer = layer_id;
+ update_ui_overlays();
+}
+
+void ViewImplementation::show_only_compositor_layers(Vector<u64> const& layer_ids)
+{
+ if (!m_latest_compositor_layers.has_value())
+ return;
+ m_ids_of_hidden_compositor_layers.clear();
+ for (auto const& layer : m_latest_compositor_layers->layers) {
+ if (!layer_ids.contains_slow(layer.id))
+ m_ids_of_hidden_compositor_layers.append(layer.id);
+ }
+ update_ui_overlays();
+}
+
+void ViewImplementation::show_all_compositor_layers()
+{
+ if (m_ids_of_hidden_compositor_layers.is_empty())
+ return;
+ m_ids_of_hidden_compositor_layers.clear();
+ update_ui_overlays();
+}
+
+void ViewImplementation::reset_compositor_layer_raster_counts()
+{
+ ++m_compositor_layer_raster_count_reset_generation;
+ update_ui_overlays();
+}
+
void ViewImplementation::did_update_compositor_layers(Badge<WebContentPage>, Compositing::CompositorLayersDescription const& layers)
{
- if (on_compositor_layers_change)
- on_compositor_layers_change(layers);
+ auto describes_layer = [&](u64 id) {
+ return layers.layers.contains([&](auto const& layer) { return layer.id == id; });
+ };
+ // A layer the compositor no longer keeps would stay hidden or selected unseen if it ever came back under the same id,
+ // so the compositor forgets it too.
+ auto forgets_layers = m_ids_of_hidden_compositor_layers.remove_all_matching([&](auto id) { return !describes_layer(id); });
+ forgets_layers |= m_ids_of_selected_compositor_layers.remove_all_matching([&](auto id) { return !describes_layer(id); });
+ if (m_id_of_hovered_compositor_layer.has_value() && !describes_layer(*m_id_of_hovered_compositor_layer)) {
+ m_id_of_hovered_compositor_layer.clear();
+ forgets_layers = true;
+ }
+ if (forgets_layers)
+ update_ui_overlays();
+
+ m_latest_compositor_layers = layers;
+
+ // The page names the elements of the nodes of its tree only while it holds the tree the compositor composites.
+ auto& owners = m_owners_of_visual_context_nodes;
+ if (owners.structural_epoch != layers.visual_context_tree_structural_epoch) {
+ owners = {};
+ owners.structural_epoch = layers.visual_context_tree_structural_epoch;
+ }
+ Vector<u32> spatial_node_indices;
+ Vector<u32> effect_node_indices;
+ for (auto const& layer : layers.layers) {
+ for (auto const& node : layer.nodes) {
+ auto key = key_of_visual_context_node(node.kind, node.index);
+ if (owners.owner_by_node.contains(key) || owners.nodes_asked.contains(key))
+ continue;
+ owners.nodes_asked.set(key);
+ (node.kind == Compositing::VisualContextNodeKind::Spatial ? spatial_node_indices : effect_node_indices).append(node.index);
+ }
+ }
+ if (!spatial_node_indices.is_empty() || !effect_node_indices.is_empty())
+ page().async_describe_owners_of_visual_context_nodes(move(spatial_node_indices), move(effect_node_indices));
+
+ tell_of_compositor_layers_with_owners_of_nodes();
+}
+
+void ViewImplementation::did_describe_owners_of_visual_context_nodes(Badge<WebContentPage>, u64 structural_epoch, Vector<u32> const& spatial_node_indices, Vector<u32> const& effect_node_indices, Vector<String> const& owners_of_nodes)
+{
+ if (owners_of_nodes.size() != spatial_node_indices.size() + effect_node_indices.size()) {
+ page().client().did_misbehave("did_describe_owners_of_visual_context_nodes"sv, "an owner for each node asked of"sv);
+ return;
+ }
+ auto& owners = m_owners_of_visual_context_nodes;
+ // Nodes the page described for another tree are asked of it again with the next layers the compositor tells of.
+ auto describes_tree_of_layers = structural_epoch == owners.structural_epoch;
+ size_t owner_index = 0;
+ auto take_owners_of = [&](Compositing::VisualContextNodeKind kind, Vector<u32> const& indices) {
+ for (auto index : indices) {
+ auto key = key_of_visual_context_node(kind, index);
+ owners.nodes_asked.remove(key);
+ if (describes_tree_of_layers)
+ owners.owner_by_node.set(key, owners_of_nodes[owner_index]);
+ ++owner_index;
+ }
+ };
+ take_owners_of(Compositing::VisualContextNodeKind::Spatial, spatial_node_indices);
+ take_owners_of(Compositing::VisualContextNodeKind::Effect, effect_node_indices);
+ if (describes_tree_of_layers)
+ tell_of_compositor_layers_with_owners_of_nodes();
+}
+
+void ViewImplementation::tell_of_compositor_layers_with_owners_of_nodes()
+{
+ if (!on_compositor_layers_change || !m_latest_compositor_layers.has_value())
+ return;
+ auto layers = *m_latest_compositor_layers;
+ for (auto& layer : layers.layers) {
+ for (auto& node : layer.nodes) {
+ if (auto owner = m_owners_of_visual_context_nodes.owner_by_node.get(key_of_visual_context_node(node.kind, node.index)); owner.has_value())
+ node.element = *owner;
+ }
+ }
+ on_compositor_layers_change(layers);
}
void ViewImplementation::update_debugger_blackboxing(Utf16String url, Vector<DebuggerBlackboxRange> ranges, DebuggerBlackboxingOperation operation)
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 16efbc41097..136c2ae9ac6 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -262,6 +262,14 @@ public:
void set_hosts_remote_layer(bool);
// What the view shows, from the Compositor, scaled down to fit within the size given.
void take_frame_snapshot(Function<void(Optional<Gfx::ShareableBitmap>)>);
+ void update_ui_overlays();
+ void set_compositor_layer_hidden(u64 layer_id, bool hidden);
+ void set_selected_compositor_layers(Vector<u64> layer_ids);
+ void set_hovered_compositor_layer(Optional<u64> layer_id);
+ // Hides every layer the compositor tells of but these.
+ void show_only_compositor_layers(Vector<u64> const& layer_ids);
+ void show_all_compositor_layers();
+ void reset_compositor_layer_raster_counts();
// The Compositor's remote layers went with its process, so the view asks the new one for another.
void recreate_remote_layer_after_compositor_reconnect(Badge<WebContentClient>);
static ViewImplementation* find_view_showing_remote_layer(u64 remote_layer_id);
@@ -371,6 +379,7 @@ public:
void did_lose_input_event_endpoint(Badge<WebContentPage>, WebContentPage&);
void did_consume_input_event_in_compositor(Badge<WebContentPage>, u64 event_id);
void did_update_compositor_layers(Badge<WebContentPage>, Compositing::CompositorLayersDescription const&);
+ void did_describe_owners_of_visual_context_nodes(Badge<WebContentPage>, u64 structural_epoch, Vector<u32> const& spatial_node_indices, Vector<u32> const& effect_node_indices, Vector<String> const& owners);
void did_not_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id);
void did_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id, bool performed_default_action);
void discard_input_events_routed_through_lost_compositor(Badge<Application>);
@@ -911,7 +920,7 @@ protected:
bool is_ui_overlay_hovered() const { return m_debugger_overlay_pointer_state.hovered_action().has_value() || m_picture_in_picture_controls_pointer_state.hovered_action().has_value(); }
void apply_cursor();
void apply_tooltip();
- void update_ui_overlays();
+ void tell_of_compositor_layers_with_owners_of_nodes();
void set_page_background_color_to_system_canvas(bool dark);
void set_page_background_color(Gfx::Color);
Gfx::Color preferred_canvas_background_color() const;
@@ -1082,6 +1091,19 @@ protected:
bool m_debugger_paused { false };
Compositing::OverlayPointerState<Compositing::PausedDebuggerOverlayAction> m_debugger_overlay_pointer_state;
bool m_has_picture_in_picture_controls { false };
+ Vector<u64> m_ids_of_hidden_compositor_layers;
+ Vector<u64> m_ids_of_selected_compositor_layers;
+ Optional<u64> m_id_of_hovered_compositor_layer;
+ u64 m_compositor_layer_raster_count_reset_generation { 0 };
+ Optional<Compositing::CompositorLayersDescription> m_latest_compositor_layers;
+ // The elements whose boxes own the nodes of the visual context tree that the compositor layers name, as the page
+ // described them for the tree of one structural epoch, by node, and the nodes asked of the page and not described.
+ struct OwnersOfVisualContextNodes {
+ u64 structural_epoch { 0 };
+ HashMap<u64, String> owner_by_node;
+ HashTable<u64> nodes_asked;
+ };
+ OwnersOfVisualContextNodes m_owners_of_visual_context_nodes;
bool m_picture_in_picture_controls_shown { false };
bool m_picture_in_picture_player_controls_shown { false };
Compositing::OverlayPointerState<Compositing::PictureInPictureControl> m_picture_in_picture_controls_pointer_state;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 36746a86896..90367317599 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1310,6 +1310,12 @@ void WebContentPage::did_get_internal_page_info(WebView::PageInfoType type, Opti
view().did_receive_internal_page_info({}, type, info);
}
+void WebContentPage::did_describe_owners_of_visual_context_nodes(u64 structural_epoch, Vector<u32> spatial_node_indices, Vector<u32> effect_node_indices, Vector<String> owners)
+{
+ if (displays_tab())
+ view().did_describe_owners_of_visual_context_nodes({}, structural_epoch, spatial_node_indices, effect_node_indices, owners);
+}
+
void WebContentPage::did_get_selected_text(u64 request_id, ByteString selection)
{
view().did_receive_selected_text({}, request_id, move(selection));
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index aa495acb9e1..ae697d8f63d 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -252,6 +252,7 @@ private:
virtual void did_complete_debugger_breakpoint_operation(u64 request_id, Optional<String> error) override;
virtual void did_take_screenshot(Gfx::ShareableBitmap screenshot) override;
virtual void did_get_internal_page_info(WebView::PageInfoType type, Optional<Core::AnonymousBuffer> info) override;
+ virtual void did_describe_owners_of_visual_context_nodes(u64 structural_epoch, Vector<u32> spatial_node_indices, Vector<u32> effect_node_indices, Vector<String> owners) override;
virtual void did_get_selected_text(u64 request_id, ByteString selection) override;
virtual void did_get_selected_text_for_lookup(u64 request_id, Optional<DictionaryLookup> lookup) override;
virtual void did_select_word_for_dictionary_lookup(u64 request_id, bool selected) override;
diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cpp
index 091b2893bd2..b082d256afc 100644
--- a/Services/Hub/ConnectionFromUI.cpp
+++ b/Services/Hub/ConnectionFromUI.cpp
@@ -450,6 +450,42 @@ void ConnectionFromUI::view_set_reports_session_history(u64 view_id, bool report
view->set_reports_session_history(reports_session_history);
}
+void ConnectionFromUI::view_set_compositor_layer_hidden(u64 view_id, u64 layer_id, bool hidden)
+{
+ if (auto* view = find_view(view_id))
+ view->set_compositor_layer_hidden(layer_id, hidden);
+}
+
+void ConnectionFromUI::view_set_selected_compositor_layers(u64 view_id, Vector<u64> layer_ids)
+{
+ if (auto* view = find_view(view_id))
+ view->set_selected_compositor_layers(move(layer_ids));
+}
+
+void ConnectionFromUI::view_set_hovered_compositor_layer(u64 view_id, Optional<u64> layer_id)
+{
+ if (auto* view = find_view(view_id))
+ view->set_hovered_compositor_layer(layer_id);
+}
+
+void ConnectionFromUI::view_show_only_compositor_layers(u64 view_id, Vector<u64> layer_ids)
+{
+ if (auto* view = find_view(view_id))
+ view->show_only_compositor_layers(layer_ids);
+}
+
+void ConnectionFromUI::view_show_all_compositor_layers(u64 view_id)
+{
+ if (auto* view = find_view(view_id))
+ view->show_all_compositor_layers();
+}
+
+void ConnectionFromUI::view_reset_compositor_layer_raster_counts(u64 view_id)
+{
+ if (auto* view = find_view(view_id))
+ view->reset_compositor_layer_raster_counts();
+}
+
void ConnectionFromUI::view_file_picker_closed(u64 view_id, Vector<Web::HTML::SelectedFile> selected_files)
{
if (auto* view = find_view(view_id))
@@ -751,6 +787,11 @@ void ConnectionFromUI::set_shows_caret_hit_test_debug_overlay(bool shows)
Application::the().set_shows_caret_hit_test_debug_overlay(shows);
}
+void ConnectionFromUI::set_shows_compositor_layers(bool shows)
+{
+ Application::the().set_shows_compositor_layers(shows);
+}
+
void ConnectionFromUI::dump_cookies()
{
Application::the().dump_cookies();
diff --git a/Services/Hub/ConnectionFromUI.h b/Services/Hub/ConnectionFromUI.h
index 9c5cd613935..e51861c7d44 100644
--- a/Services/Hub/ConnectionFromUI.h
+++ b/Services/Hub/ConnectionFromUI.h
@@ -78,6 +78,7 @@ private:
virtual void set_blocks_pop_ups(bool blocks) override;
virtual void set_shows_line_box_borders(bool shows) override;
virtual void set_shows_caret_hit_test_debug_overlay(bool shows) override;
+ virtual void set_shows_compositor_layers(bool shows) override;
virtual void dump_cookies() override;
virtual void crash_compositor_process() override;
virtual void launch_devtools_client() override;
@@ -104,6 +105,12 @@ private:
virtual void view_open_navigation_in_new_window(u64 view_id, Web::HTML::PreparedNavigationDescriptor navigation, WebView::IsPrivate is_private) override;
virtual void view_traverse_the_history_to_step(u64 view_id, i32 step) override;
virtual void view_set_reports_session_history(u64 view_id, bool reports_session_history) override;
+ virtual void view_set_compositor_layer_hidden(u64 view_id, u64 layer_id, bool hidden) override;
+ virtual void view_set_selected_compositor_layers(u64 view_id, Vector<u64> layer_ids) override;
+ virtual void view_set_hovered_compositor_layer(u64 view_id, Optional<u64> layer_id) override;
+ virtual void view_show_only_compositor_layers(u64 view_id, Vector<u64> layer_ids) override;
+ virtual void view_show_all_compositor_layers(u64 view_id) override;
+ virtual void view_reset_compositor_layer_raster_counts(u64 view_id) override;
virtual void view_file_picker_closed(u64 view_id, Vector<Web::HTML::SelectedFile> selected_files) override;
virtual void view_save_screenshot(u64 view_id, Gfx::ShareableBitmap bitmap) override;
virtual void view_request_selected_text(u64 view_id, u64 request_id) override;
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index 0f9fcbd8b79..ac51cdf84e3 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -410,4 +410,5 @@ endpoint HubClient
view_crash_overlay_state_change(u64 view_id, bool active) =|
view_crash_report_saved(u64 view_id) =|
view_performance_stats(u64 view_id, WebView::TabPerformanceStats stats) =|
+ view_compositor_layers_change(u64 view_id, Compositing::CompositorLayersDescription layers) =|
}
diff --git a/Services/Hub/HubServer.ipc b/Services/Hub/HubServer.ipc
index 5861d57eccd..6bbc856be22 100644
--- a/Services/Hub/HubServer.ipc
+++ b/Services/Hub/HubServer.ipc
@@ -149,6 +149,7 @@ endpoint HubServer
set_blocks_pop_ups(bool blocks) =|
set_shows_line_box_borders(bool shows) =|
set_shows_caret_hit_test_debug_overlay(bool shows) =|
+ set_shows_compositor_layers(bool shows) =|
dump_cookies() =|
crash_compositor_process() =|
launch_devtools_client() =|
@@ -189,6 +190,12 @@ endpoint HubServer
view_learn_misspelling(u64 view_id, Utf16String word) =|
view_do_context_menu_media_action(u64 view_id, WebView::ContextMenuMediaAction action) =|
view_set_reports_session_history(u64 view_id, bool reports_session_history) =|
+ view_set_compositor_layer_hidden(u64 view_id, u64 layer_id, bool hidden) =|
+ view_set_selected_compositor_layers(u64 view_id, Vector<u64> layer_ids) =|
+ view_set_hovered_compositor_layer(u64 view_id, Optional<u64> layer_id) =|
+ view_show_only_compositor_layers(u64 view_id, Vector<u64> layer_ids) =|
+ view_show_all_compositor_layers(u64 view_id) =|
+ view_reset_compositor_layer_raster_counts(u64 view_id) =|
view_file_picker_closed(u64 view_id, Vector<Web::HTML::SelectedFile> selected_files) =|
view_save_screenshot(u64 view_id, Gfx::ShareableBitmap bitmap) =|
view_request_selected_text(u64 view_id, u64 request_id) =|
diff --git a/Services/Hub/View.cpp b/Services/Hub/View.cpp
index 10cae4db355..c3836ff1fa1 100644
--- a/Services/Hub/View.cpp
+++ b/Services/Hub/View.cpp
@@ -630,6 +630,11 @@ void View::forward_callbacks_to_ui(bool is_tab)
ui->async_view_performance_stats(view_id(), arguments...);
}
};
+
+ on_compositor_layers_change = [this](auto const&... arguments) {
+ if (auto* ui = ConnectionFromUI::the())
+ ui->async_view_compositor_layers_change(view_id(), arguments...);
+ };
}
ViewState View::current_state() const
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index d82664a42f0..f9b38875b2c 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -2915,6 +2915,17 @@ static void append_gc_graph(StringBuilder& builder)
gc_graph.serialize(builder);
}
+void ConnectionFromClient::describe_owners_of_visual_context_nodes(Web::PageId page_id, Vector<u32> spatial_node_indices, Vector<u32> effect_node_indices)
+{
+ Web::Painting::OwnersOfVisualContextNodes owners;
+ auto page = this->page(page_id);
+ if (auto document = page.has_value() && page->page().has_local_traversable() ? page->page().local_traversable()->active_document() : nullptr)
+ owners = Web::Painting::describe_owners_of_visual_context_nodes(*document, spatial_node_indices, effect_node_indices);
+ else
+ owners.owners.resize(spatial_node_indices.size() + effect_node_indices.size());
+ async_did_describe_owners_of_visual_context_nodes(page_id, owners.structural_epoch, move(spatial_node_indices), move(effect_node_indices), move(owners.owners));
+}
+
void ConnectionFromClient::request_internal_page_info(Web::PageId page_id, WebView::PageInfoType type)
{
auto page = this->page(page_id);
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index 5a422074e2c..ccc4ab65305 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -329,6 +329,7 @@ private:
virtual void take_dom_node_screenshot(Web::PageId page_id, Web::UniqueNodeID node_id) override;
virtual void request_internal_page_info(Web::PageId page_id, WebView::PageInfoType) override;
+ virtual void describe_owners_of_visual_context_nodes(Web::PageId page_id, Vector<u32> spatial_node_indices, Vector<u32> effect_node_indices) override;
virtual void get_selected_text(Web::PageId page_id, u64 request_id) override;
virtual void generate_text_fragment_url(Web::PageId page_id, u64 request_id, u64 generation_id) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index ecbbd60e471..e76cb2abaae 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -180,6 +180,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_take_screenshot(Web::PageId page_id, Gfx::ShareableBitmap screenshot) =|
did_get_internal_page_info(Web::PageId page_id, WebView::PageInfoType type, Optional<Core::AnonymousBuffer> info) =|
+ did_describe_owners_of_visual_context_nodes(Web::PageId page_id, u64 structural_epoch, Vector<u32> spatial_node_indices, Vector<u32> effect_node_indices, Vector<String> owners) =|
did_get_selected_text(Web::PageId page_id, u64 request_id, ByteString selection) =|
did_get_selected_text_for_lookup(Web::PageId page_id, u64 request_id, Optional<WebView::DictionaryLookup> lookup) =|
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index 46ec057afe3..94083a7e466 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -240,6 +240,7 @@ endpoint WebContentServer routed by Web::PageId page_id
take_dom_node_screenshot(Web::PageId page_id, Web::UniqueNodeID node_id) =|
request_internal_page_info(Web::PageId page_id, WebView::PageInfoType type) =|
+ describe_owners_of_visual_context_nodes(Web::PageId page_id, Vector<u32> spatial_node_indices, Vector<u32> effect_node_indices) =|
get_selected_text(Web::PageId page_id, u64 request_id) =|
generate_text_fragment_url(Web::PageId page_id, u64 request_id, u64 generation_id) =|
diff --git a/UI/Qt/Actions.h b/UI/Qt/Actions.h
index 7ef3ba6d6af..32c2b9fbac1 100644
--- a/UI/Qt/Actions.h
+++ b/UI/Qt/Actions.h
@@ -140,6 +140,7 @@ enum class ActionID {
ReportLeakedDocuments,
ShowLineBoxBorders,
ShowCaretHitTestDebugOverlay,
+ ShowCompositorLayers,
ShowTabPerformanceMonitor,
CollectGarbage,
CrashCurrentPage,
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 147ee8b03f2..5207cd3814d 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -58,6 +58,7 @@
#include <UI/Qt/BookmarkDialog.h>
#include <UI/Qt/Bookmarks.h>
#include <UI/Qt/ChromeLayout.h>
+#include <UI/Qt/CompositorLayersWindow.h>
#include <UI/Qt/DownloadsPage.h>
#include <UI/Qt/EventLoopImplementationQt.h>
#include <UI/Qt/ExternalURLHandler.h>
@@ -1167,6 +1168,74 @@ Application::~Application()
m_picture_in_picture_windows.clear();
}
+static void place_beside_browser_window_or_over_its_top_right_corner(QWidget& window, QWidget const& browser_window)
+{
+ constexpr int GAP = 12;
+ auto browser_frame = browser_window.frameGeometry();
+ auto window_size = window.size();
+ auto screen = browser_window.screen()->availableGeometry();
+ auto x = browser_frame.right() + GAP;
+ if (x + window_size.width() > screen.right())
+ x = browser_frame.right() - window_size.width() - GAP;
+ window.move(x, browser_frame.top() + GAP);
+}
+
+void Application::set_shows_compositor_layers(bool shows)
+{
+ HubConnection::the().async_set_shows_compositor_layers(shows);
+ if (!shows) {
+ if (m_compositor_layers_window)
+ m_compositor_layers_window->hide();
+ return;
+ }
+ if (!m_compositor_layers_window) {
+ m_compositor_layers_window = make<CompositorLayersWindow>(CompositorLayersWindow::Source {
+ .layers_of_active_tab = [this]() -> Optional<Compositing::CompositorLayersDescription> {
+ if (auto* tab = active_tab())
+ return tab->compositor_layers();
+ return {};
+ },
+ .set_layer_hidden_in_active_tab = [this](u64 layer_id, bool hidden) {
+ if (auto* tab = active_tab(); tab && tab->is_loaded())
+ tab->view().set_compositor_layer_hidden(layer_id, hidden); },
+ .set_selected_layers_in_active_tab = [this](Vector<u64> layer_ids) {
+ if (auto* tab = active_tab(); tab && tab->is_loaded())
+ tab->view().set_selected_compositor_layers(AK::move(layer_ids)); },
+ .set_hovered_layer_in_active_tab = [this](Optional<u64> layer_id) {
+ if (auto* tab = active_tab(); tab && tab->is_loaded())
+ tab->view().set_hovered_compositor_layer(layer_id); },
+ .show_only_layers_in_active_tab = [this](Vector<u64> layer_ids) {
+ if (auto* tab = active_tab(); tab && tab->is_loaded())
+ tab->view().show_only_compositor_layers(AK::move(layer_ids)); },
+ .show_all_layers_in_active_tab = [this] {
+ if (auto* tab = active_tab(); tab && tab->is_loaded())
+ tab->view().show_all_compositor_layers(); },
+ .reset_raster_counts_in_active_tab = [this] {
+ if (auto* tab = active_tab(); tab && tab->is_loaded())
+ tab->view().reset_compositor_layer_raster_counts(); },
+ .start_picking_layer_in_active_tab = [this](CompositorLayerPicker picker) {
+ auto* tab = active_tab();
+ if (!tab || !tab->is_loaded())
+ return false;
+ m_view_picking_compositor_layer = &tab->view();
+ tab->view().start_compositor_layer_picker(AK::move(picker));
+ return true; },
+ .stop_picking_layer_in_active_tab = [this] {
+ if (m_view_picking_compositor_layer)
+ m_view_picking_compositor_layer->stop_compositor_layer_picker();
+ m_view_picking_compositor_layer = nullptr; },
+ });
+ m_compositor_layers_window->on_close = [] {
+ ApplicationActions::the().show_compositor_layers_action().set_checked(false);
+ HubConnection::the().async_set_shows_compositor_layers(false);
+ };
+ if (auto* browser_window = active_window_if_any())
+ place_beside_browser_window_or_over_its_top_right_corner(*m_compositor_layers_window, *browser_window);
+ }
+ m_compositor_layers_window->show();
+ m_compositor_layers_window->raise();
+}
+
void Application::show_process_manager()
{
if (!m_process_manager_window) {
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index ceb9bf403bd..8e51f70359f 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -39,8 +39,10 @@ namespace Ladybird {
class WebUIPages;
class Bookmarks;
+class CompositorLayersWindow;
class ProcessManagerWindow;
class SoftwareUpdater;
+class WebContentView;
struct WindowConfiguration {
Optional<Web::DevicePixels> x {};
@@ -147,6 +149,7 @@ public:
void restart_private_browsing_session();
void focus_location_editor();
void show_process_manager();
+ void set_shows_compositor_layers(bool);
// Asks every window's pages if they may unload, one window at a time. Once all of them agree, it confirms stopping
// the downloads and quits; if a page refuses or the downloads are kept, the quit is canceled and no window closes.
void quit();
@@ -388,6 +391,8 @@ private:
u64 m_next_external_url_handler_id { 1 };
BrowserWindow* m_active_window { nullptr };
OwnPtr<ProcessManagerWindow> m_process_manager_window;
+ OwnPtr<CompositorLayersWindow> m_compositor_layers_window;
+ QPointer<WebContentView> m_view_picking_compositor_layer;
RefPtr<Action> m_open_task_manager_action;
bool m_private_session_restart_in_progress { false };
diff --git a/UI/Qt/ApplicationActions.cpp b/UI/Qt/ApplicationActions.cpp
index de3cda3ea6e..752fbdeb799 100644
--- a/UI/Qt/ApplicationActions.cpp
+++ b/UI/Qt/ApplicationActions.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibCore/Environment.h>
#include <LibURL/InternalURLs.h>
#include <LibWebCommon/CSS/PreferredContrast.h>
#include <LibWebCommon/CSS/PreferredMotion.h>
@@ -18,6 +19,7 @@
#include <QClipboard>
#include <QLineEdit>
#include <QPlainTextEdit>
+#include <QTimer>
namespace Ladybird {
@@ -297,6 +299,14 @@ void ApplicationActions::create_debug_menu(PageOptions const& options)
add_switch(m_show_caret_hit_test_debug_overlay_action, "Show Caret Hit Test Debug Overlay"sv, ActionID::ShowCaretHitTestDebugOverlay, false, [](bool shows) {
HubConnection::the().async_set_shows_caret_hit_test_debug_overlay(shows);
});
+ auto shows_compositor_layers = Core::Environment::has("LADYBIRD_SHOW_COMPOSITOR_LAYERS"sv);
+ add_switch(m_show_compositor_layers_action, "Show Compositor Layers and Tiles"sv, ActionID::ShowCompositorLayers, shows_compositor_layers, [](bool shows) {
+ Application::the().set_shows_compositor_layers(shows);
+ });
+ if (shows_compositor_layers) {
+ // The window that lists the layers opens once the application runs.
+ QTimer::singleShot(0, [] { Application::the().set_shows_compositor_layers(true); });
+ }
m_show_tab_performance_monitor_action = Action::create_checkable("Show Tab Performance Monitor"sv, ActionID::ShowTabPerformanceMonitor, [this] {
Application::settings().set_config_variable(WebView::ConfigVariableID::ShowTabPerformanceMonitor, m_show_tab_performance_monitor_action->checked());
diff --git a/UI/Qt/ApplicationActions.h b/UI/Qt/ApplicationActions.h
index dd1afedef97..6d541c0cb85 100644
--- a/UI/Qt/ApplicationActions.h
+++ b/UI/Qt/ApplicationActions.h
@@ -41,6 +41,7 @@ public:
void devtools_enabled_changed(bool enabled);
Action& reload_action() { return *m_reload_action; }
+ Action& show_compositor_layers_action() { return *m_show_compositor_layers_action; }
Action& reload_bypassing_cache_action() { return *m_reload_bypassing_cache_action; }
Action& copy_selection_action() { return *m_copy_selection_action; }
Action& undo_action() { return *m_undo_action; }
@@ -106,6 +107,7 @@ private:
RefPtr<Action> m_show_tab_performance_monitor_action;
RefPtr<Action> m_show_line_box_borders_action;
RefPtr<Action> m_show_caret_hit_test_debug_overlay_action;
+ RefPtr<Action> m_show_compositor_layers_action;
RefPtr<Action> m_enable_scripting_action;
RefPtr<Action> m_block_pop_ups_action;
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index f03130a7dd1..f26f17c7271 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -28,6 +28,7 @@ add_library(ladybird_impl STATIC
DownloadsPage.cpp
BrowserWindow.cpp
ChromeStyle.cpp
+ CompositorLayersWindow.cpp
ContextMenus.cpp
CrashReportReviewWidget.cpp
DevToolsBanner.cpp
diff --git a/UI/Qt/CompositorLayerPicker.h b/UI/Qt/CompositorLayerPicker.h
new file mode 100644
index 00000000000..59f37b06059
--- /dev/null
+++ b/UI/Qt/CompositorLayerPicker.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Function.h>
+#include <LibGfx/Point.h>
+
+namespace Ladybird {
+
+// What a page tells the compositor layers window of the pointer while the window picks a layer from it, in the device
+// pixels of the page's viewport. The page takes no input of the pointer or the keyboard meanwhile, and stops after a
+// pick or a cancel.
+struct CompositorLayerPicker {
+ Function<void(Gfx::IntPoint)> on_hover;
+ Function<void()> on_leave;
+ Function<void(Gfx::IntPoint)> on_pick;
+ Function<void()> on_cancel;
+};
+
+}
diff --git a/UI/Qt/CompositorLayersWindow.cpp b/UI/Qt/CompositorLayersWindow.cpp
new file mode 100644
index 00000000000..f24042a6d1e
--- /dev/null
+++ b/UI/Qt/CompositorLayersWindow.cpp
@@ -0,0 +1,511 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/AnyOf.h>
+#include <AK/HashTable.h>
+#include <AK/QuickSort.h>
+#include <UI/Qt/CompositorLayersWindow.h>
+#include <UI/Qt/StringUtils.h>
+
+#include <QEvent>
+#include <QHBoxLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QPainter>
+#include <QPixmap>
+#include <QPlainTextEdit>
+#include <QProxyStyle>
+#include <QPushButton>
+#include <QRegularExpression>
+#include <QSignalBlocker>
+#include <QStyleOption>
+#include <QTextDocument>
+#include <QTimer>
+#include <QTreeWidget>
+#include <QVBoxLayout>
+
+namespace Ladybird {
+
+namespace {
+
+enum Column {
+ Layer,
+ Elements,
+ Holds,
+ Rastered,
+};
+
+constexpr int LayerIDRole = Qt::UserRole + 1;
+constexpr int StackPositionRole = Qt::UserRole + 2;
+constexpr int TilesRasteredSinceResetRole = Qt::UserRole + 3;
+constexpr int REFRESH_INTERVAL_IN_MILLISECONDS = 150;
+constexpr int SWATCH_SIZE = 12;
+constexpr int INITIAL_WIDTH_OF_LAYER_COLUMN = 280;
+constexpr int MAXIMUM_VISIBLE_DETAIL_LINE_COUNT = 10;
+
+QIcon swatch_of(u32 rgb)
+{
+ QPixmap pixmap(SWATCH_SIZE, SWATCH_SIZE);
+ pixmap.fill(QColor::fromRgb(rgb));
+ return QIcon(pixmap);
+}
+
+// Sorts the layer column by where each layer is in the stack, and the rastered column by how many tiles were rastered.
+class LayerItem final : public QTreeWidgetItem {
+public:
+ AK_ALLOC_WITH_KMALLOC;
+
+ using QTreeWidgetItem::QTreeWidgetItem;
+
+ virtual bool operator<(QTreeWidgetItem const& other) const override
+ {
+ switch (treeWidget()->sortColumn()) {
+ case Layer:
+ return data(Layer, StackPositionRole).toInt() < other.data(Layer, StackPositionRole).toInt();
+ case Rastered:
+ return data(Rastered, TilesRasteredSinceResetRole).toULongLong() < other.data(Rastered, TilesRasteredSinceResetRole).toULongLong();
+ default:
+ return QTreeWidgetItem::operator<(other);
+ }
+ }
+};
+
+#if defined(AK_OS_MACOS)
+// The macOS style draws its native check box through a painter only once: the checks of the rows after the first, which
+// an item view draws through the same painter, come out blank. Each is drawn through a painter of its own instead.
+class StyleDrawingEachItemCheckThroughPainterOfItsOwn final : public QProxyStyle {
+public:
+ virtual void drawPrimitive(PrimitiveElement element, QStyleOption const* option, QPainter* painter, QWidget const* widget) const override
+ {
+ auto const* item_option = qstyleoption_cast<QStyleOptionViewItem const*>(option);
+ if (element != PE_IndicatorItemViewItemCheck || !item_option || option->rect.isEmpty()) {
+ QProxyStyle::drawPrimitive(element, option, painter, widget);
+ return;
+ }
+ auto device_pixel_ratio = painter->device()->devicePixelRatioF();
+ QPixmap check(option->rect.size() * device_pixel_ratio);
+ check.setDevicePixelRatio(device_pixel_ratio);
+ check.fill(Qt::transparent);
+ auto check_option = *item_option;
+ check_option.rect = QRect({}, option->rect.size());
+ {
+ QPainter check_painter(&check);
+ QProxyStyle::drawPrimitive(element, &check_option, &check_painter, widget);
+ }
+ painter->drawPixmap(option->rect.topLeft(), check);
+ }
+};
+#endif
+
+// What the dump and the name of a layer call the node.
+QString name_of_node(Compositing::CompositorLayerNodeDescription const& node)
+{
+ return QString("%1%2").arg(node.kind == Compositing::VisualContextNodeKind::Spatial ? 's' : 'e').arg(node.index);
+}
+
+QString elements_of_layer(Compositing::CompositorLayerDescription const& layer)
+{
+ QStringList elements;
+ for (auto const& node : layer.nodes) {
+ auto element = qstring_from_ak_string(node.element);
+ if (!element.isEmpty() && !elements.contains(element))
+ elements.append(element);
+ }
+ return elements.join(", ");
+}
+
+QString nodes_of_layer_with_elements(Compositing::CompositorLayerDescription const& layer)
+{
+ QStringList lines;
+ for (auto const& node : layer.nodes) {
+ auto element = qstring_from_ak_string(node.element);
+ lines.append(QString("%1: %2").arg(name_of_node(node), element.isEmpty() ? "no live element" : element));
+ }
+ return lines.join('\n');
+}
+
+bool note_mentions_node(QString const& note, QString const& name_of_node)
+{
+ return note.contains(QRegularExpression(QString("\\b%1\\b").arg(name_of_node)));
+}
+
+}
+
+CompositorLayersWindow::CompositorLayersWindow(Source source)
+ : QDialog(nullptr, Qt::Tool)
+ , m_source(AK::move(source))
+{
+ setWindowTitle("Compositor Layers");
+ resize(720, 560);
+
+ m_pick_button = new QPushButton("Pick on Page", this);
+ m_pick_button->setCheckable(true);
+ m_pick_button->setToolTip("Click a layer on the page to select it: the smallest layer shown under the pointer. Escape cancels.");
+ m_show_only_selected_button = new QPushButton("Show Only Selected", this);
+ m_show_only_selected_button->setToolTip("Uncheck every layer but the selected ones.");
+ m_show_only_selected_button->setEnabled(false);
+ m_show_all_button = new QPushButton("Show All", this);
+ m_show_all_button->setToolTip("Check every layer.");
+ m_reset_button = new QPushButton("Reset Raster Counts", this);
+ m_reset_button->setToolTip("Count the tiles rastered from now on.");
+ auto* buttons = new QHBoxLayout;
+ buttons->addWidget(m_pick_button);
+ buttons->addWidget(m_show_only_selected_button);
+ buttons->addWidget(m_show_all_button);
+ buttons->addStretch();
+ buttons->addWidget(m_reset_button);
+
+ m_layer_tree = new QTreeWidget(this);
+#if defined(AK_OS_MACOS)
+ // The tree does not own its style. As a child of the window made after the tree, the style outlives it.
+ auto* style_of_layer_tree = new StyleDrawingEachItemCheckThroughPainterOfItsOwn;
+ style_of_layer_tree->setParent(this);
+ m_layer_tree->setStyle(style_of_layer_tree);
+#endif
+ m_layer_tree->setColumnCount(4);
+ m_layer_tree->setHeaderLabels({ "Layer", "Elements", "Holds", "Rastered" });
+ m_layer_tree->setRootIsDecorated(false);
+ m_layer_tree->setUniformRowHeights(true);
+ // Each selected layer shows its tiles over the page.
+ m_layer_tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ m_layer_tree->setMouseTracking(true);
+ m_layer_tree->viewport()->installEventFilter(this);
+ m_layer_tree->header()->setStretchLastSection(false);
+ m_layer_tree->header()->setSectionResizeMode(Layer, QHeaderView::Interactive);
+ m_layer_tree->header()->setSectionResizeMode(Elements, QHeaderView::Stretch);
+ m_layer_tree->header()->setSectionResizeMode(Holds, QHeaderView::ResizeToContents);
+ m_layer_tree->header()->setSectionResizeMode(Rastered, QHeaderView::ResizeToContents);
+ m_layer_tree->setColumnWidth(Layer, INITIAL_WIDTH_OF_LAYER_COLUMN);
+ m_layer_tree->setSortingEnabled(true);
+ m_layer_tree->sortByColumn(Layer, Qt::DescendingOrder);
+
+ // The details and the summaries show text from other processes. Do not read that text as markup. The details of a
+ // layer can run long, so they scroll within a few lines.
+ m_details = new QPlainTextEdit(this);
+ m_details->setReadOnly(true);
+ auto margins_of_details = 2 * (m_details->frameWidth() + static_cast<int>(m_details->document()->documentMargin()));
+ m_details->setMaximumHeight(m_details->fontMetrics().lineSpacing() * MAXIMUM_VISIBLE_DETAIL_LINE_COUNT + margins_of_details);
+ m_summary_of_last_frame = new QLabel(this);
+ m_summary_of_last_frame->setTextFormat(Qt::PlainText);
+ m_summary_of_last_frame->setWordWrap(true);
+ m_summary_since_reset = new QLabel(this);
+ m_summary_since_reset->setTextFormat(Qt::PlainText);
+ m_summary_since_reset->setWordWrap(true);
+ m_tile_highlight_legend = new QLabel(this);
+ m_tile_highlight_legend->setTextFormat(Qt::RichText);
+ m_tile_highlight_legend->setWordWrap(true);
+
+ auto* layout = new QVBoxLayout(this);
+ layout->addLayout(buttons);
+ layout->addWidget(m_layer_tree, 1);
+ layout->addWidget(m_details);
+ layout->addWidget(m_summary_of_last_frame);
+ layout->addWidget(m_summary_since_reset);
+ layout->addWidget(m_tile_highlight_legend);
+
+ QObject::connect(m_layer_tree, &QTreeWidget::itemChanged, this, [this](QTreeWidgetItem* item, int column) {
+ if (column != Layer)
+ return;
+ auto layer_id = item->data(Layer, LayerIDRole).toULongLong();
+ m_source.set_layer_hidden_in_active_tab(layer_id, item->checkState(Layer) == Qt::Unchecked);
+ });
+ QObject::connect(m_layer_tree, &QTreeWidget::itemSelectionChanged, this, [this] { tell_tab_of_selected_layers(); });
+ QObject::connect(m_layer_tree, &QTreeWidget::currentItemChanged, this, [this] { show_details_of_selected_layer(); });
+ QObject::connect(m_layer_tree, &QTreeWidget::itemEntered, this, [this](QTreeWidgetItem* item, int) {
+ set_hovered_layer(item->data(Layer, LayerIDRole).toULongLong());
+ });
+ QObject::connect(m_pick_button, &QPushButton::toggled, this, [this](bool checked) {
+ set_picks_layer_on_page(checked);
+ });
+ QObject::connect(m_show_only_selected_button, &QPushButton::clicked, this, [this] { show_only_selected_layers(); });
+ QObject::connect(m_show_all_button, &QPushButton::clicked, this, [this] { show_all_layers(); });
+ QObject::connect(m_reset_button, &QPushButton::clicked, this, [this] {
+ m_source.reset_raster_counts_in_active_tab();
+ });
+
+ m_refresh_timer = new QTimer(this);
+ m_refresh_timer->setInterval(REFRESH_INTERVAL_IN_MILLISECONDS);
+ QObject::connect(m_refresh_timer, &QTimer::timeout, this, [this] { refresh(); });
+}
+
+void CompositorLayersWindow::showEvent(QShowEvent* event)
+{
+ QDialog::showEvent(event);
+ refresh();
+ m_refresh_timer->start();
+}
+
+void CompositorLayersWindow::hideEvent(QHideEvent* event)
+{
+ m_refresh_timer->stop();
+ m_pick_button->setChecked(false);
+ set_hovered_layer({});
+ QDialog::hideEvent(event);
+}
+
+// All ways to close the dialog call done(): the Escape key and the close button of the window call reject(), which
+// calls done().
+void CompositorLayersWindow::done(int result)
+{
+ QDialog::done(result);
+ if (on_close)
+ on_close();
+}
+
+bool CompositorLayersWindow::eventFilter(QObject* watched, QEvent* event)
+{
+ if (watched == m_layer_tree->viewport() && event->type() == QEvent::Leave)
+ set_hovered_layer({});
+ return QDialog::eventFilter(watched, event);
+}
+
+void CompositorLayersWindow::set_hovered_layer(Optional<u64> layer_id)
+{
+ if (m_id_of_hovered_layer == layer_id)
+ return;
+ m_id_of_hovered_layer = layer_id;
+ m_source.set_hovered_layer_in_active_tab(layer_id);
+}
+
+void CompositorLayersWindow::set_picks_layer_on_page(bool picks)
+{
+ if (!picks) {
+ m_source.stop_picking_layer_in_active_tab();
+ set_hovered_layer({});
+ return;
+ }
+ // The page stops picking by itself after a pick or a cancel.
+ auto picking_ended = [this] {
+ QSignalBlocker block_stop_request_for_page_that_stopped(m_pick_button);
+ m_pick_button->setChecked(false);
+ set_hovered_layer({});
+ };
+ auto started = m_source.start_picking_layer_in_active_tab(CompositorLayerPicker {
+ .on_hover = [this](Gfx::IntPoint point) { set_hovered_layer(id_of_layer_to_pick_at(point)); },
+ .on_leave = [this] { set_hovered_layer({}); },
+ .on_pick = [this, picking_ended](Gfx::IntPoint point) {
+ picking_ended();
+ auto layer_id = id_of_layer_to_pick_at(point);
+ if (!layer_id.has_value())
+ return;
+ if (auto item = m_item_by_layer_id.get(*layer_id); item.has_value()) {
+ m_layer_tree->setCurrentItem(*item);
+ m_layer_tree->scrollToItem(*item);
+ }
+ // The selection shows in the window that has the focus, which takes the arrow keys that walk the list.
+ raise();
+ activateWindow(); },
+ .on_cancel = [picking_ended] { picking_ended(); },
+ });
+ if (!started) {
+ QSignalBlocker block_stop_request_for_page_that_never_started(m_pick_button);
+ m_pick_button->setChecked(false);
+ }
+}
+
+Vector<u64> CompositorLayersWindow::ids_of_selected_layers() const
+{
+ Vector<u64> layer_ids;
+ for (auto const* item : m_layer_tree->selectedItems())
+ layer_ids.append(item->data(Layer, LayerIDRole).toULongLong());
+ quick_sort(layer_ids);
+ return layer_ids;
+}
+
+void CompositorLayersWindow::tell_tab_of_selected_layers()
+{
+ auto layer_ids = ids_of_selected_layers();
+ m_show_only_selected_button->setEnabled(!layer_ids.is_empty());
+ if (layer_ids != m_ids_of_selected_layers_told_to_tab) {
+ m_ids_of_selected_layers_told_to_tab = layer_ids;
+ m_source.set_selected_layers_in_active_tab(AK::move(layer_ids));
+ }
+ show_details_of_selected_layer();
+}
+
+// The checkboxes change at once, and stay as they are once the compositor tells what it hides.
+void CompositorLayersWindow::show_only_selected_layers()
+{
+ auto layer_ids = ids_of_selected_layers();
+ if (layer_ids.is_empty())
+ return;
+ {
+ QSignalBlocker block_hide_requests_for_each_row(m_layer_tree);
+ for (auto const& [layer_id, item] : m_item_by_layer_id)
+ item->setCheckState(Layer, layer_ids.contains_slow(layer_id) ? Qt::Checked : Qt::Unchecked);
+ }
+ m_source.show_only_layers_in_active_tab(AK::move(layer_ids));
+}
+
+void CompositorLayersWindow::show_all_layers()
+{
+ {
+ QSignalBlocker block_hide_requests_for_each_row(m_layer_tree);
+ for (auto const& [layer_id, item] : m_item_by_layer_id)
+ item->setCheckState(Layer, Qt::Checked);
+ }
+ m_source.show_all_layers_in_active_tab();
+}
+
+Compositing::CompositorLayerDescription const* CompositorLayersWindow::shown_layer_with_id(u64 layer_id) const
+{
+ if (!m_shown_description.has_value())
+ return nullptr;
+ for (auto const& layer : m_shown_description->layers) {
+ if (layer.id == layer_id)
+ return &layer;
+ }
+ return nullptr;
+}
+
+// The outline of a layer bounds the tiles it holds, and a layer that holds content all over the page bounds most of
+// the viewport. The smallest shown layer under the pointer is what the pointer is over, and of layers as large, the
+// topmost.
+Optional<u64> CompositorLayersWindow::id_of_layer_to_pick_at(Gfx::IntPoint point) const
+{
+ if (!m_shown_description.has_value())
+ return {};
+ Optional<u64> picked_layer_id;
+ i64 area_of_picked_layer = 0;
+ for (auto const& layer : m_shown_description->layers) {
+ auto const& rect = layer.visible_rect_in_viewport;
+ if (layer.hidden || !rect.contains(point))
+ continue;
+ auto area = static_cast<i64>(rect.width()) * rect.height();
+ if (!picked_layer_id.has_value() || area <= area_of_picked_layer) {
+ picked_layer_id = layer.id;
+ area_of_picked_layer = area;
+ }
+ }
+ return picked_layer_id;
+}
+
+void CompositorLayersWindow::refresh()
+{
+ auto description = m_source.layers_of_active_tab();
+ if (description == m_shown_description)
+ return;
+
+ {
+ QSignalBlocker block_requests_while_showing_what_compositor_does(m_layer_tree);
+
+ // Keeping the rows of the layers that stay keeps the selection and where the list was scrolled to.
+ HashTable<u64> ids_of_described_layers;
+ if (description.has_value()) {
+ for (auto const& layer : description->layers)
+ ids_of_described_layers.set(layer.id);
+ }
+ Vector<u64> ids_of_layers_gone;
+ for (auto const& [layer_id, item] : m_item_by_layer_id) {
+ if (!ids_of_described_layers.contains(layer_id))
+ ids_of_layers_gone.append(layer_id);
+ }
+ for (auto layer_id : ids_of_layers_gone)
+ delete m_item_by_layer_id.take(layer_id).value();
+
+ auto layer_count = description.has_value() ? description->layers.size() : 0;
+ for (size_t position = 0; position < layer_count; ++position) {
+ auto const& layer = description->layers[position];
+ auto* item = m_item_by_layer_id.get(layer.id).value_or(nullptr);
+ if (!item) {
+ item = new LayerItem(m_layer_tree);
+ item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
+ item->setData(Layer, LayerIDRole, QVariant::fromValue<qulonglong>(layer.id));
+ item->setTextAlignment(Rastered, Qt::AlignRight | Qt::AlignVCenter);
+ m_item_by_layer_id.set(layer.id, item);
+ }
+ auto name = qstring_from_ak_string(layer.name);
+ item->setData(Layer, StackPositionRole, static_cast<int>(position));
+ item->setCheckState(Layer, layer.hidden ? Qt::Unchecked : Qt::Checked);
+ item->setIcon(Layer, swatch_of(layer.rgb_of_outline));
+ item->setText(Layer, name);
+ item->setToolTip(Layer, name);
+ item->setText(Elements, elements_of_layer(layer));
+ item->setToolTip(Elements, nodes_of_layer_with_elements(layer));
+ item->setText(Holds, qstring_from_ak_string(layer.details));
+ item->setData(Rastered, TilesRasteredSinceResetRole, QVariant::fromValue<qulonglong>(layer.tiles_rastered_since_reset));
+ item->setText(Rastered, layer.tiles_rastered_since_reset == 0 ? QString {} : QString::number(layer.tiles_rastered_since_reset));
+ item->setToolTip(Rastered, qstring_from_ak_string(layer.raster_causes_since_reset));
+ }
+ }
+
+ m_shown_description = AK::move(description);
+ if (!m_shown_description.has_value()) {
+ m_summary_of_last_frame->setText("The active tab has presented no frame since the layers were shown.");
+ m_summary_since_reset->clear();
+ m_tile_highlight_legend->clear();
+ } else {
+ m_summary_of_last_frame->setText(qstring_from_ak_string(m_shown_description->summary_of_last_frame));
+ m_summary_since_reset->setText(qstring_from_ak_string(m_shown_description->summary_since_reset));
+ QStringList tile_highlight_legend_entries;
+ for (auto const& highlight : m_shown_description->tile_highlights) {
+ auto color = QColor::fromRgb(highlight.rgb).name();
+ tile_highlight_legend_entries.append(QString("<span style=\"color: %1\">&#9632;</span> %2").arg(color, qstring_from_ak_string(highlight.raster_cause).toHtmlEscaped()));
+ }
+ m_tile_highlight_legend->setText("Tiles rastered are highlighted by why: " + tile_highlight_legend_entries.join("&nbsp;&nbsp; "));
+ }
+
+ // The row of a layer that left the stack went with the selection.
+ tell_tab_of_selected_layers();
+}
+
+void CompositorLayersWindow::show_details_of_selected_layer()
+{
+ if (!m_shown_description.has_value()) {
+ m_details->clear();
+ return;
+ }
+ QStringList notes;
+ for (auto const& note : m_shown_description->notes)
+ notes.append(qstring_from_ak_string(note));
+
+ // Of the selected layers, the details are of the one clicked last.
+ QStringList lines;
+ auto const* current_item = m_layer_tree->currentItem();
+ auto selected_items = m_layer_tree->selectedItems();
+ auto const* item = current_item && current_item->isSelected() ? current_item : (selected_items.isEmpty() ? nullptr : selected_items.first());
+ auto const* layer = item ? shown_layer_with_id(item->data(Layer, LayerIDRole).toULongLong()) : nullptr;
+ if (!layer) {
+ lines.append("Select layers, or pick one on the page, to see their tiles and the elements that made them. Cmd-click or Shift-click selects more than one.");
+ if (!notes.isEmpty()) {
+ lines.append(QString {});
+ lines.append(notes);
+ }
+ } else {
+ if (selected_items.size() > 1)
+ lines.append(QString("%1 layers selected; this one was clicked last:").arg(selected_items.size()));
+ lines.append(qstring_from_ak_string(layer->name));
+ if (!layer->nodes.is_empty()) {
+ lines.append("Nodes its name mentions:");
+ for (auto const& line : nodes_of_layer_with_elements(*layer).split('\n'))
+ lines.append(" " + line);
+ }
+ lines.append("Holds: " + qstring_from_ak_string(layer->details));
+ auto raster_causes = qstring_from_ak_string(layer->raster_causes_since_reset);
+ lines.append(QString("Tiles rastered since reset: %1%2").arg(layer->tiles_rastered_since_reset).arg(raster_causes.isEmpty() ? QString {} : QString(" (%1)").arg(raster_causes)));
+ auto rect = layer->visible_rect_in_viewport;
+ if (rect.is_empty())
+ lines.append("Not shown in the viewport");
+ else
+ lines.append(QString("Shown at %1,%2 %3x%4 in device pixels").arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height()));
+ QStringList notes_of_layer;
+ for (auto const& note : notes) {
+ auto mentions_node_of_layer = any_of(layer->nodes, [&](auto const& node) { return note_mentions_node(note, name_of_node(node)); });
+ if (mentions_node_of_layer)
+ notes_of_layer.append(" " + note);
+ }
+ if (!notes_of_layer.isEmpty()) {
+ lines.append("Notes of its nodes:");
+ lines.append(notes_of_layer);
+ }
+ }
+ // Setting the same text again would scroll the details back to the top.
+ auto text = lines.join('\n');
+ if (m_details->toPlainText() != text)
+ m_details->setPlainText(text);
+}
+
+}
diff --git a/UI/Qt/CompositorLayersWindow.h b/UI/Qt/CompositorLayersWindow.h
new file mode 100644
index 00000000000..b4422dc9dae
--- /dev/null
+++ b/UI/Qt/CompositorLayersWindow.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Function.h>
+#include <AK/HashMap.h>
+#include <AK/Optional.h>
+#include <AK/kmalloc.h>
+#include <LibCompositing/Types.h>
+#include <UI/Qt/CompositorLayerPicker.h>
+
+#include <QDialog>
+
+class QLabel;
+class QPlainTextEdit;
+class QPushButton;
+class QTimer;
+class QTreeWidget;
+class QTreeWidgetItem;
+
+namespace Ladybird {
+
+class CompositorLayersWindow final : public QDialog {
+public:
+ AK_ALLOC_WITH_KMALLOC;
+
+ struct Source {
+ Function<Optional<Compositing::CompositorLayersDescription>()> layers_of_active_tab;
+ Function<void(u64 layer_id, bool hidden)> set_layer_hidden_in_active_tab;
+ Function<void(Vector<u64> layer_ids)> set_selected_layers_in_active_tab;
+ Function<void(Optional<u64> layer_id)> set_hovered_layer_in_active_tab;
+ Function<void(Vector<u64> layer_ids)> show_only_layers_in_active_tab;
+ Function<void()> show_all_layers_in_active_tab;
+ Function<void()> reset_raster_counts_in_active_tab;
+ // Answers false where no tab can be picked from.
+ Function<bool(CompositorLayerPicker)> start_picking_layer_in_active_tab;
+ Function<void()> stop_picking_layer_in_active_tab;
+ };
+
+ explicit CompositorLayersWindow(Source);
+
+ Function<void()> on_close;
+
+private:
+ virtual void showEvent(QShowEvent*) override;
+ virtual void hideEvent(QHideEvent*) override;
+ virtual void done(int result) override;
+ virtual bool eventFilter(QObject*, QEvent*) override;
+
+ void refresh();
+ void tell_tab_of_selected_layers();
+ void show_details_of_selected_layer();
+ void set_hovered_layer(Optional<u64> layer_id);
+ void set_picks_layer_on_page(bool);
+ void show_only_selected_layers();
+ void show_all_layers();
+ Vector<u64> ids_of_selected_layers() const;
+ Compositing::CompositorLayerDescription const* shown_layer_with_id(u64 layer_id) const;
+ Optional<u64> id_of_layer_to_pick_at(Gfx::IntPoint) const;
+
+ Source m_source;
+ Optional<Compositing::CompositorLayersDescription> m_shown_description;
+ HashMap<u64, QTreeWidgetItem*> m_item_by_layer_id;
+ Vector<u64> m_ids_of_selected_layers_told_to_tab;
+ Optional<u64> m_id_of_hovered_layer;
+ QPushButton* m_pick_button { nullptr };
+ QPushButton* m_show_only_selected_button { nullptr };
+ QPushButton* m_show_all_button { nullptr };
+ QPushButton* m_reset_button { nullptr };
+ QTreeWidget* m_layer_tree { nullptr };
+ QPlainTextEdit* m_details { nullptr };
+ QLabel* m_summary_of_last_frame { nullptr };
+ QLabel* m_summary_since_reset { nullptr };
+ QLabel* m_tile_highlight_legend { nullptr };
+ QTimer* m_refresh_timer { nullptr };
+};
+
+}
diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cpp
index 8b16aa305c7..8b59c058f62 100644
--- a/UI/Qt/HubConnection.cpp
+++ b/UI/Qt/HubConnection.cpp
@@ -1179,4 +1179,10 @@ void HubConnection::view_performance_stats(u64 view_id, WebView::TabPerformanceS
view->on_performance_stats(move(stats));
}
+void HubConnection::view_compositor_layers_change(u64 view_id, Compositing::CompositorLayersDescription layers)
+{
+ if (auto* view = RemoteView::find(view_id); view && view->on_compositor_layers_change)
+ view->on_compositor_layers_change(layers);
+}
+
}
diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.h
index a3442356721..c6e410e6823 100644
--- a/UI/Qt/HubConnection.h
+++ b/UI/Qt/HubConnection.h
@@ -234,6 +234,7 @@ private:
virtual void view_crash_overlay_state_change(u64 view_id, bool active) override;
virtual void view_crash_report_saved(u64 view_id) override;
virtual void view_performance_stats(u64 view_id, WebView::TabPerformanceStats stats) override;
+ virtual void view_compositor_layers_change(u64 view_id, Compositing::CompositorLayersDescription layers) override;
};
}
diff --git a/UI/Qt/RemoteView.cpp b/UI/Qt/RemoteView.cpp
index f2879aed693..ca346e15e6c 100644
--- a/UI/Qt/RemoteView.cpp
+++ b/UI/Qt/RemoteView.cpp
@@ -133,6 +133,36 @@ void RemoteView::set_device_pixel_ratio_and_viewport(double device_pixel_ratio,
HubConnection::the().async_view_set_viewport(view_id(), size, device_pixel_ratio);
}
+void RemoteView::set_compositor_layer_hidden(u64 layer_id, bool hidden)
+{
+ HubConnection::the().async_view_set_compositor_layer_hidden(view_id(), layer_id, hidden);
+}
+
+void RemoteView::set_selected_compositor_layers(Vector<u64> layer_ids)
+{
+ HubConnection::the().async_view_set_selected_compositor_layers(view_id(), move(layer_ids));
+}
+
+void RemoteView::set_hovered_compositor_layer(Optional<u64> layer_id)
+{
+ HubConnection::the().async_view_set_hovered_compositor_layer(view_id(), layer_id);
+}
+
+void RemoteView::show_only_compositor_layers(Vector<u64> layer_ids)
+{
+ HubConnection::the().async_view_show_only_compositor_layers(view_id(), move(layer_ids));
+}
+
+void RemoteView::show_all_compositor_layers()
+{
+ HubConnection::the().async_view_show_all_compositor_layers(view_id());
+}
+
+void RemoteView::reset_compositor_layer_raster_counts()
+{
+ HubConnection::the().async_view_reset_compositor_layer_raster_counts(view_id());
+}
+
u64 RemoteView::add_navigation_listener(NavigationListener listener)
{
auto id = m_next_navigation_listener_id++;
diff --git a/UI/Qt/RemoteView.h b/UI/Qt/RemoteView.h
index fed3f713202..c33ee6678f3 100644
--- a/UI/Qt/RemoteView.h
+++ b/UI/Qt/RemoteView.h
@@ -219,6 +219,12 @@ public:
void request_close_preflight(Function<void(bool)> on_complete);
bool needs_beforeunload_check() const;
u64 add_navigation_listener(NavigationListener);
+ void set_compositor_layer_hidden(u64 layer_id, bool hidden);
+ void set_selected_compositor_layers(Vector<u64> layer_ids);
+ void set_hovered_compositor_layer(Optional<u64> layer_id);
+ void show_only_compositor_layers(Vector<u64> layer_ids);
+ void show_all_compositor_layers();
+ void reset_compositor_layer_raster_counts();
void remove_navigation_listener(u64 listener_id) { m_navigation_listeners.remove(listener_id); }
Action& navigate_back_action() { return *m_navigate_back_action; }
Action& navigate_forward_action() { return *m_navigate_forward_action; }
@@ -358,6 +364,7 @@ public:
Function<void()> on_load_from_user_input;
decltype(Hub::View::on_ready_to_paint) on_ready_to_paint;
decltype(Hub::View::on_performance_stats) on_performance_stats;
+ decltype(Hub::View::on_compositor_layers_change) on_compositor_layers_change;
Function<void(Web::HTML::ActivateTab, Web::HTML::WebViewHints, u64 view_id)> on_open_new_view;
decltype(Hub::View::on_activate_tab) on_activate_tab;
decltype(Hub::View::on_close) on_close;
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index 6db05198180..a2c3d920e19 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -269,6 +269,9 @@ void Tab::initialize(Optional<u64> hub_view_id)
m_performance_stats = stats;
emit performance_stats_changed();
};
+ view().on_compositor_layers_change = [this](Compositing::CompositorLayersDescription const& layers) {
+ m_compositor_layers = layers;
+ };
recreate_location_edit_icons();
update_chrome_style();
diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.h
index eeeace85719..facd92d9fc9 100644
--- a/UI/Qt/Tab.h
+++ b/UI/Qt/Tab.h
@@ -13,6 +13,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <AK/kmalloc.h>
+#include <LibCompositing/Types.h>
#include <LibWakeLock/DisplaySleepInhibitor.h>
#include <LibWebCommon/Page/PageId.h>
#include <LibWebCommon/Page/ScreenWakeLockState.h>
@@ -146,6 +147,7 @@ public:
LocationEdit& location_edit() { return *m_location_edit; }
WebView::TabPerformanceStats const& performance_stats() const { return m_performance_stats; }
+ Optional<Compositing::CompositorLayersDescription> const& compositor_layers() const { return m_compositor_layers; }
void set_window(BrowserWindow&);
void update_hover_label();
@@ -260,6 +262,7 @@ private:
QAction* m_pin_tab_action { nullptr };
WebView::TabPerformanceStats m_performance_stats;
+ Optional<Compositing::CompositorLayersDescription> m_compositor_layers;
JavaScriptDialog* m_javascript_dialog { nullptr };
Function<void(bool)> m_before_unload_completion;
diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp
index 7b525529df6..88731a57a5e 100644
--- a/UI/Qt/WebContentView.cpp
+++ b/UI/Qt/WebContentView.cpp
@@ -817,6 +817,16 @@ static bool is_browser_reserved_shortcut(QKeyEvent const& event)
void WebContentView::keyPressEvent(QKeyEvent* event)
{
+ if (m_compositor_layer_picker.has_value()) {
+ if (event->key() == Qt::Key_Escape) {
+ auto picker = m_compositor_layer_picker.release_value();
+ unsetCursor();
+ picker.on_cancel();
+ }
+ event->accept();
+ return;
+ }
+
if (is_node_picker_active()) {
if (event->key() == Qt::Key_Escape)
node_picker_cancel();
@@ -837,7 +847,7 @@ void WebContentView::keyPressEvent(QKeyEvent* event)
void WebContentView::keyReleaseEvent(QKeyEvent* event)
{
- if (is_node_picker_active()) {
+ if (m_compositor_layer_picker.has_value() || is_node_picker_active()) {
event->accept();
return;
}
@@ -874,6 +884,11 @@ void WebContentView::leaveEvent(QEvent* event)
void WebContentView::handle_pointer_leave()
{
+ if (m_compositor_layer_picker.has_value()) {
+ m_compositor_layer_picker->on_leave();
+ return;
+ }
+
if (is_node_picker_active()) {
clear_node_picker();
return;
@@ -891,6 +906,13 @@ void WebContentView::cancel_mouse_press()
void WebContentView::mouseMoveEvent(QMouseEvent* event)
{
+ if (m_compositor_layer_picker.has_value()) {
+ auto position = node_picker_position_for(*event);
+ m_compositor_layer_picker->on_hover({ position.x().value(), position.y().value() });
+ event->accept();
+ return;
+ }
+
if (is_node_picker_active()) {
node_picker_hover(node_picker_position_for(*event));
event->accept();
@@ -906,6 +928,18 @@ void WebContentView::mouseMoveEvent(QMouseEvent* event)
void WebContentView::mousePressEvent(QMouseEvent* event)
{
+ if (m_compositor_layer_picker.has_value()) {
+ if (event->button() == Qt::MouseButton::LeftButton) {
+ auto position = node_picker_position_for(*event);
+ auto picker = m_compositor_layer_picker.release_value();
+ unsetCursor();
+ m_swallows_mouse_release_after_compositor_layer_pick = true;
+ picker.on_pick({ position.x().value(), position.y().value() });
+ }
+ event->accept();
+ return;
+ }
+
if (is_node_picker_active()) {
if (event->button() == Qt::MouseButton::LeftButton) {
auto position = node_picker_position_for(*event);
@@ -936,7 +970,13 @@ void WebContentView::mousePressEvent(QMouseEvent* event)
void WebContentView::mouseReleaseEvent(QMouseEvent* event)
{
- if (is_node_picker_active()) {
+ if (m_swallows_mouse_release_after_compositor_layer_pick) {
+ m_swallows_mouse_release_after_compositor_layer_pick = false;
+ event->accept();
+ return;
+ }
+
+ if (m_compositor_layer_picker.has_value() || is_node_picker_active()) {
event->accept();
return;
}
@@ -2405,6 +2445,24 @@ void WebContentView::update_cursor(Gfx::Cursor cursor)
});
}
+void WebContentView::start_compositor_layer_picker(CompositorLayerPicker picker)
+{
+ stop_compositor_layer_picker();
+ m_compositor_layer_picker = AK::move(picker);
+ setCursor(Qt::CrossCursor);
+ // The page takes the Escape key that cancels the picking.
+ window()->activateWindow();
+ setFocus();
+}
+
+void WebContentView::stop_compositor_layer_picker()
+{
+ if (!m_compositor_layer_picker.has_value())
+ return;
+ m_compositor_layer_picker.clear();
+ unsetCursor();
+}
+
Web::DevicePixelPoint WebContentView::node_picker_position_for(QSinglePointEvent const& event) const
{
return { event.position().x() * device_pixel_ratio(), event.position().y() * device_pixel_ratio() };
diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.h
index 5be5accd2f3..96351b09f6a 100644
--- a/UI/Qt/WebContentView.h
+++ b/UI/Qt/WebContentView.h
@@ -28,6 +28,7 @@
#include <LibWebView/BrowsingSession.h>
#include <LibWebView/WebCompatReport.h>
#include <UI/Qt/BackingStoreRelease.h>
+#include <UI/Qt/CompositorLayerPicker.h>
#include <UI/Qt/RemoteView.h>
#include <UI/Qt/ScreenshotSelectionOverlay.h>
@@ -189,6 +190,8 @@ public:
void leave_report_review();
void review_web_compat_report(WebCompatReportCapture);
void select_web_compat_report_screenshot(Function<void(QImage)> on_selected, Function<void()> on_close = {});
+ void start_compositor_layer_picker(CompositorLayerPicker);
+ void stop_compositor_layer_picker();
Function<void(WebCompatReportCapture)> on_request_web_compat_report_review;
Function<void(Function<void(QImage)> on_selected)> on_request_web_compat_report_screenshot;
@@ -344,6 +347,8 @@ private:
CrashReportReviewWidget* m_crash_report_review { nullptr };
QPointer<ScreenshotSelectionOverlay> m_screenshot_selection_overlay;
+ Optional<CompositorLayerPicker> m_compositor_layer_picker;
+ bool m_swallows_mouse_release_after_compositor_layer_pick { false };
size_t m_frame_notification_interest { 0 };
QPointer<ScreenshotViewer> m_screenshot_viewer;
struct FloatingSurface {