Truly independent web browser
LibCompositing+Compositor: Record the compositor's overlays in Rust
Aliaksandr Kalenikf88adb34966a
diff --git a/Libraries/LibCompositing/OverlayFade.h b/Libraries/LibCompositing/OverlayFade.hdeleted file mode 100644index 93df8d8f6b6..00000000000--- a/Libraries/LibCompositing/OverlayFade.h+++ /dev/null@@ -1,64 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Optional.h>-#include <AK/StdLibExtras.h>-#include <AK/Time.h>--namespace Compositing {--// A fade that turns back from whatever opacity it has reached.-class OverlayFade {-public:- static constexpr auto duration = AK::Duration::from_milliseconds(150);-- void fade_to(float target_opacity, MonotonicTime now)- {- if (target_opacity == m_target_opacity)- return;- m_initial_opacity = m_opacity;- m_target_opacity = target_opacity;- m_started_at = now;- }-- // Returns whether the opacity changed.- bool advance_to(MonotonicTime frame_time)- {- auto opacity = opacity_at(frame_time);- if (opacity == m_opacity)- return false;- m_opacity = opacity;- return true;- }-- float opacity() const { return m_opacity; }- bool is_fading() const { return m_opacity != m_target_opacity; }--private:- float opacity_at(MonotonicTime frame_time) const- {- if (!m_started_at.has_value())- return m_target_opacity;-- auto progress = (frame_time - *m_started_at).to_seconds_f64() / duration.to_seconds_f64();- if (progress >= 1)- return m_target_opacity;- progress = max(progress, 0.0);-- // Smoothstep, so that the fade starts and ends gently.- auto eased_progress = static_cast<float>(progress * progress * (3 - 2 * progress));- return m_initial_opacity + (m_target_opacity - m_initial_opacity) * eased_progress;- }-- float m_opacity { 0 };- float m_initial_opacity { 0 };- float m_target_opacity { 0 };- Optional<MonotonicTime> m_started_at;-};--}diff --git a/Libraries/LibCompositing/OverlayGeometry.h b/Libraries/LibCompositing/OverlayGeometry.hindex 93535cec19d..cdf4932be0d 100644--- a/Libraries/LibCompositing/OverlayGeometry.h+++ b/Libraries/LibCompositing/OverlayGeometry.h@@ -9,15 +9,14 @@#include <AK/Array.h>#include <AK/Math.h>#include <AK/Optional.h>+#include <LibCompositing/Export.h>#include <LibGfx/Point.h>#include <LibGfx/Rect.h>namespace Compositing {-inline int scaled_overlay_length(int length, double device_pixel_ratio)-{- return max(1, static_cast<int>(round(length * device_pixel_ratio)));-}+// A length of an overlay in CSS pixels, in whole device pixels.+COMPOSITING_API int scaled_overlay_length(int length, double device_pixel_ratio);enum class OverlayButtonShape : u8 {Rectangle,diff --git a/Libraries/LibCompositing/PausedDebuggerOverlay.h b/Libraries/LibCompositing/PausedDebuggerOverlay.hindex 91c9ec02318..7bd1fb7de5a 100644--- a/Libraries/LibCompositing/PausedDebuggerOverlay.h+++ b/Libraries/LibCompositing/PausedDebuggerOverlay.h@@ -47,21 +47,7 @@ struct PausedDebuggerOverlayGeometry {}};-inline PausedDebuggerOverlayGeometry paused_debugger_overlay_geometry(Gfx::IntSize viewport_size, double device_pixel_ratio)-{- auto width = min(viewport_size.width(), scaled_overlay_length(250, device_pixel_ratio));- auto height = min(viewport_size.height(), scaled_overlay_length(38, device_pixel_ratio));- auto x = max(0, (viewport_size.width() - width) / 2);- auto y = min(scaled_overlay_length(30, device_pixel_ratio), max(0, viewport_size.height() - height));- auto button_width = min(scaled_overlay_length(40, device_pixel_ratio), width / 2);- auto message_width = width - button_width * 2;-- return {- .toolbar = { x, y, width, height },- .message = { x, y, message_width, height },- .step_over_button = { x + message_width, y, button_width, height },- .continue_button = { x + message_width + button_width, y, button_width, height },- };-}+// The compositor paints the overlay with this same geometry.+COMPOSITING_API PausedDebuggerOverlayGeometry paused_debugger_overlay_geometry(Gfx::IntSize viewport_size, double device_pixel_ratio);}diff --git a/Libraries/LibCompositing/PictureInPictureControls.h b/Libraries/LibCompositing/PictureInPictureControls.hindex 4768ac9e1c7..7eb791ddead 100644--- a/Libraries/LibCompositing/PictureInPictureControls.h+++ b/Libraries/LibCompositing/PictureInPictureControls.h@@ -45,16 +45,7 @@ struct PictureInPictureControlsGeometry {}};-inline PictureInPictureControlsGeometry picture_in_picture_controls_geometry(Gfx::IntSize viewport_size, double device_pixel_ratio)-{- // Close is in the top left corner, and the way back to the tab in the top right one.- auto button_size = scaled_overlay_length(28, device_pixel_ratio);- auto inset = scaled_overlay_length(10, device_pixel_ratio);-- return {- .back_to_tab_button = { viewport_size.width() - inset - button_size, inset, button_size, button_size },- .close_button = { inset, inset, button_size, button_size },- };-}+// The compositor paints the controls with this same geometry.+COMPOSITING_API PictureInPictureControlsGeometry picture_in_picture_controls_geometry(Gfx::IntSize viewport_size, double device_pixel_ratio);}diff --git a/Libraries/LibCompositing/Rust/build.rs b/Libraries/LibCompositing/Rust/build.rsindex ca5d6449397..afc1b965bdb 100644--- a/Libraries/LibCompositing/Rust/build.rs+++ b/Libraries/LibCompositing/Rust/build.rs@@ -434,6 +434,7 @@ fn main() -> Result<(), Box<dyn Error>> {manifest_dir.join("src/filter_bytes.rs"),manifest_dir.join("src/visual_context/ffi_types.rs"),manifest_dir.join("src/host/replay.rs"),+ manifest_dir.join("src/overlays.rs"),manifest_dir.join("src/display_list/storage.rs"),manifest_dir.join("src/display_list/canvas_2d.rs"),manifest_dir.join("src/display_list/canvas_2d_recorder.rs"),diff --git a/Libraries/LibCompositing/Rust/src/lib.rs b/Libraries/LibCompositing/Rust/src/lib.rsindex 98e712a7485..fb2d613acf0 100644--- a/Libraries/LibCompositing/Rust/src/lib.rs+++ b/Libraries/LibCompositing/Rust/src/lib.rs@@ -23,6 +23,7 @@ pub mod force_dark;pub mod host;pub mod ipc_types;pub mod node_slot_id;+pub mod overlays;pub mod scrolling;#[cfg(test)]mod test_stubs;diff --git a/Libraries/LibCompositing/Rust/src/overlays.rs b/Libraries/LibCompositing/Rust/src/overlays.rsnew file mode 100644index 00000000000..070d75d504a--- /dev/null+++ b/Libraries/LibCompositing/Rust/src/overlays.rs@@ -0,0 +1,97 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! Where the overlays the browser draws over a page put their parts. The compositor paints them there, and the browser+//! finds the buttons a press lands on with the same geometry.++use libgfx_rust::{IntRect, IntSize};++/// A length of an overlay in CSS pixels, in whole device pixels.+pub fn scaled_overlay_length(length: i32, device_pixel_ratio: f64) -> i32 {+ 1.max((f64::from(length) * device_pixel_ratio).round() as i32)+}++#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[repr(C)]+pub struct PausedDebuggerOverlayGeometry {+ pub toolbar: IntRect,+ pub message: IntRect,+ pub step_over_button: IntRect,+ pub continue_button: IntRect,+}++pub fn paused_debugger_overlay_geometry(+ viewport_size: IntSize,+ device_pixel_ratio: f64,+) -> PausedDebuggerOverlayGeometry {+ let width = viewport_size.width.min(scaled_overlay_length(250, device_pixel_ratio));+ let height = viewport_size.height.min(scaled_overlay_length(38, device_pixel_ratio));+ let x = 0.max((viewport_size.width - width) / 2);+ let y = scaled_overlay_length(30, device_pixel_ratio).min(0.max(viewport_size.height - height));+ let button_width = scaled_overlay_length(40, device_pixel_ratio).min(width / 2);+ let message_width = width - button_width * 2;+ PausedDebuggerOverlayGeometry {+ toolbar: IntRect::new(x, y, width, height),+ message: IntRect::new(x, y, message_width, height),+ step_over_button: IntRect::new(x + message_width, y, button_width, height),+ continue_button: IntRect::new(x + message_width + button_width, y, button_width, height),+ }+}++#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[repr(C)]+pub struct PictureInPictureControlsGeometry {+ pub back_to_tab_button: IntRect,+ pub close_button: IntRect,+}++impl PictureInPictureControlsGeometry {+ /// The rect that holds both buttons.+ pub fn buttons_bounds(&self) -> IntRect {+ self.back_to_tab_button.united(self.close_button)+ }+}++pub fn picture_in_picture_controls_geometry(+ viewport_size: IntSize,+ device_pixel_ratio: f64,+) -> PictureInPictureControlsGeometry {+ // Close is in the top left corner, and the way back to the tab in the top right one.+ let button_size = scaled_overlay_length(28, device_pixel_ratio);+ let inset = scaled_overlay_length(10, device_pixel_ratio);+ PictureInPictureControlsGeometry {+ back_to_tab_button: IntRect::new(+ viewport_size.width - inset - button_size,+ inset,+ button_size,+ button_size,+ ),+ close_button: IntRect::new(inset, inset, button_size, button_size),+ }+}++#[unsafe(no_mangle)]+pub extern "C" fn compositing_scaled_overlay_length(length: i32, device_pixel_ratio: f64) -> i32 {+ scaled_overlay_length(length, device_pixel_ratio)+}++#[unsafe(no_mangle)]+pub extern "C" fn compositing_paused_debugger_overlay_geometry(+ viewport_size: IntSize,+ device_pixel_ratio: f64,+ geometry: &mut PausedDebuggerOverlayGeometry,+) {+ *geometry = paused_debugger_overlay_geometry(viewport_size, device_pixel_ratio);+}++#[unsafe(no_mangle)]+pub extern "C" fn compositing_picture_in_picture_controls_geometry(+ viewport_size: IntSize,+ device_pixel_ratio: f64,+ geometry: &mut PictureInPictureControlsGeometry,+) {+ *geometry = picture_in_picture_controls_geometry(viewport_size, device_pixel_ratio);+}diff --git a/Libraries/LibCompositing/Rust/src/scrolling/overlay_fade.rs b/Libraries/LibCompositing/Rust/src/scrolling/overlay_fade.rsindex 1d06a52fffd..2d4e6491497 100644--- a/Libraries/LibCompositing/Rust/src/scrolling/overlay_fade.rs+++ b/Libraries/LibCompositing/Rust/src/scrolling/overlay_fade.rs@@ -69,3 +69,89 @@ impl OverlayFade {self.initial_opacity + (self.target_opacity - self.initial_opacity) * eased_progress}}++#[cfg(test)]+mod tests {+ use super::*;++ const START_NANOSECONDS: i64 = 1_000_000_000;++ fn after(milliseconds: i64) -> MonotonicTime {+ MonotonicTime::from_nanoseconds(START_NANOSECONDS + milliseconds * 1_000_000)+ }++ fn assert_approximately(actual: f32, expected: f32, error: f32) {+ assert!(+ (actual - expected).abs() <= error,+ "{actual} is not within {error} of {expected}"+ );+ }++ #[test]+ fn a_fade_starts_transparent_and_at_rest() {+ let fade = OverlayFade::default();+ assert_eq!(fade.opacity(), 0.0);+ assert!(!fade.is_fading());+ }++ #[test]+ fn a_fade_eases_in_and_out_to_its_target() {+ let mut fade = OverlayFade::default();+ fade.fade_to(1.0, after(0));+ assert!(fade.is_fading());++ assert!(!fade.advance_to(after(0)));+ assert_eq!(fade.opacity(), 0.0);++ assert!(fade.advance_to(after(30)));+ assert_approximately(fade.opacity(), 0.104, 0.0001);++ fade.advance_to(after(75));+ assert_approximately(fade.opacity(), 0.5, 0.000001);++ fade.advance_to(after(150));+ assert_eq!(fade.opacity(), 1.0);+ assert!(!fade.is_fading());++ assert!(!fade.advance_to(after(300)));+ assert_eq!(fade.opacity(), 1.0);+ }++ #[test]+ fn a_fade_does_not_go_back_in_time() {+ let mut fade = OverlayFade::default();+ fade.fade_to(1.0, after(0));++ assert!(!fade.advance_to(after(-10)));+ assert_eq!(fade.opacity(), 0.0);+ }++ #[test]+ fn a_fade_turns_back_from_where_it_has_reached() {+ let mut fade = OverlayFade::default();+ fade.fade_to(1.0, after(0));+ fade.advance_to(after(75));++ fade.fade_to(0.0, after(75));+ assert!(!fade.advance_to(after(75)));+ assert_approximately(fade.opacity(), 0.5, 0.000001);++ fade.advance_to(after(150));+ assert_approximately(fade.opacity(), 0.25, 0.000001);++ fade.advance_to(after(225));+ assert_eq!(fade.opacity(), 0.0);+ assert!(!fade.is_fading());+ }++ #[test]+ fn fading_to_the_same_target_keeps_the_fade_going() {+ let mut fade = OverlayFade::default();+ fade.fade_to(1.0, after(0));+ fade.advance_to(after(75));++ fade.fade_to(1.0, after(75));+ fade.advance_to(after(150));+ assert_eq!(fade.opacity(), 1.0);+ }+}diff --git a/Libraries/LibCompositing/UIOverlays.cpp b/Libraries/LibCompositing/UIOverlays.cppindex 43a3cc745d7..7dfa341fbaa 100644--- a/Libraries/LibCompositing/UIOverlays.cpp+++ b/Libraries/LibCompositing/UIOverlays.cpp@@ -4,10 +4,39 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibCompositing/RustFFI.h>#include <LibCompositing/UIOverlays.h>#include <LibIPC/Decoder.h>#include <LibIPC/Encoder.h>+namespace Compositing {++int scaled_overlay_length(int length, double device_pixel_ratio)+{+ return RustFFI::compositing_scaled_overlay_length(length, device_pixel_ratio);+}++PictureInPictureControlsGeometry picture_in_picture_controls_geometry(Gfx::IntSize viewport_size, double device_pixel_ratio)+{+ RustFFI::PictureInPictureControlsGeometry geometry;+ RustFFI::compositing_picture_in_picture_controls_geometry(viewport_size, device_pixel_ratio, &geometry);+ return { .back_to_tab_button = geometry.back_to_tab_button, .close_button = geometry.close_button };+}++PausedDebuggerOverlayGeometry paused_debugger_overlay_geometry(Gfx::IntSize viewport_size, double device_pixel_ratio)+{+ RustFFI::PausedDebuggerOverlayGeometry geometry;+ RustFFI::compositing_paused_debugger_overlay_geometry(viewport_size, device_pixel_ratio, &geometry);+ return {+ .toolbar = geometry.toolbar,+ .message = geometry.message,+ .step_over_button = geometry.step_over_button,+ .continue_button = geometry.continue_button,+ };+}++}+namespace IPC {template<typename Action, typename Callback>diff --git a/Services/Compositor/CMakeLists.txt b/Services/Compositor/CMakeLists.txtindex 35818f2d71e..8b43366d354 100644--- a/Services/Compositor/CMakeLists.txt+++ b/Services/Compositor/CMakeLists.txt@@ -21,8 +21,6 @@ set(SOURCESOpenGLContext.cppPaintingSurface.cppPresentableSurface.cpp- PausedDebuggerOverlay.cpp- PictureInPictureControls.cppRasterizeDisplayList.cppRenderClockConnection.cppSkiaBackendContext.cppdiff --git a/Services/Compositor/CompositorCore.cpp b/Services/Compositor/CompositorCore.cppindex 64f05d904e7..245de6a17d6 100644--- a/Services/Compositor/CompositorCore.cpp+++ b/Services/Compositor/CompositorCore.cpp@@ -54,6 +54,26 @@ static void cancel_timer(void* host, u64 context_id, ContextTimer timer)static_cast<CompositorCoreHost*>(host)->cancel_timer(Web::CompositorContextId { context_id }, timer);}+static void shape_overlay_label(void* host, u64 context_id, bool has_font_family, ReadonlyBytes font_family, double device_pixel_ratio, ReadonlyBytes text, void* receiver, void (*receive)(void*, RustFFI::FfiOverlayLabel const*))+{+ Optional<StringView> font_family_view;+ if (has_font_family)+ font_family_view = StringView { font_family };+ auto label = static_cast<CompositorCoreHost*>(host)->shape_overlay_label(Web::CompositorContextId { context_id }, font_family_view, device_pixel_ratio, StringView { text });+ if (!label.has_value())+ return;+ RustFFI::FfiOverlayLabel ffi_label {+ .font_id = label->font_id,+ .glyph_ids = label->glyph_ids.span(),+ .glyph_x_positions = label->glyph_x_positions.span(),+ .width = label->width,+ .ascent = label->ascent,+ .descent = label->descent,+ .font_ascent = label->font_ascent,+ };+ receive(receiver, &ffi_label);+}+CompositorCore::CompositorCore(CompositorCoreHost& host, bool scrollbars_always_shown){RustFFI::FfiCompositorCoreHost ffi_host {@@ -64,6 +84,7 @@ CompositorCore::CompositorCore(CompositorCoreHost& host, bool scrollbars_always_.request_display_ticks = Compositor::request_display_ticks,.set_timer = Compositor::set_timer,.cancel_timer = Compositor::cancel_timer,+ .shape_overlay_label = Compositor::shape_overlay_label,};m_core = RustFFI::compositor_core_create(ffi_host, scrollbars_always_shown);}@@ -103,14 +124,28 @@ void CompositorCore::set_visibility(Web::CompositorContextId context_id, ComposiRustFFI::compositor_core_set_visibility(m_core, context_id.value(), visibility == Compositing::ContextVisibility::Visible, now.nanoseconds());}-void CompositorCore::viewport_size_updated(Web::CompositorContextId context_id, Gfx::IntSize viewport_size)+void CompositorCore::viewport_size_updated(Web::CompositorContextId context_id, Gfx::IntSize viewport_size, double device_pixel_ratio){- RustFFI::compositor_core_viewport_size_updated(m_core, context_id.value(), viewport_size);+ RustFFI::compositor_core_viewport_size_updated(m_core, context_id.value(), viewport_size, device_pixel_ratio);}-void CompositorCore::set_paused_debugger_overlay_is_shown(Web::CompositorContextId context_id, bool is_shown)+void CompositorCore::set_ui_overlays(Web::CompositorContextId context_id, Compositing::UIOverlays const& overlays, MonotonicTime now){- RustFFI::compositor_core_set_paused_debugger_overlay_is_shown(m_core, context_id.value(), is_shown);+ auto const& paused_debugger = overlays.paused_debugger;+ auto const& picture_in_picture_controls = overlays.picture_in_picture_controls;+ auto font_family = paused_debugger.has_value() && paused_debugger->font_family.has_value() ? paused_debugger->font_family->bytes() : ReadonlyBytes {};+ RustFFI::FfiUIOverlays ffi_overlays {+ .has_paused_debugger = paused_debugger.has_value(),+ .paused_debugger_has_font_family = paused_debugger.has_value() && paused_debugger->font_family.has_value(),+ .paused_debugger_font_family = font_family,+ .paused_debugger_has_hovered_action = paused_debugger.has_value() && paused_debugger->hovered_action.has_value(),+ .paused_debugger_hovered_action = paused_debugger.has_value() && paused_debugger->hovered_action.has_value() ? to_underlying(*paused_debugger->hovered_action) : u8 { 0 },+ .has_picture_in_picture_controls = picture_in_picture_controls.has_value(),+ .picture_in_picture_controls_shown = picture_in_picture_controls.has_value() && picture_in_picture_controls->shown,+ .picture_in_picture_controls_has_hovered_control = picture_in_picture_controls.has_value() && picture_in_picture_controls->hovered_control.has_value(),+ .picture_in_picture_controls_hovered_control = picture_in_picture_controls.has_value() && picture_in_picture_controls->hovered_control.has_value() ? to_underlying(*picture_in_picture_controls->hovered_control) : u8 { 0 },+ };+ RustFFI::compositor_core_set_ui_overlays(m_core, context_id.value(), &ffi_overlays, now.nanoseconds());}void CompositorCore::set_bound_presentation(Web::CompositorContextId context_id, Optional<PresentationId> presentation_id)@@ -161,7 +196,6 @@ DisplayTickResult CompositorCore::display_tick(Web::CompositorContextId context_{.context_is_on_tick_display = inputs.context_is_on_tick_display,.present_is_scheduled_on_tick_display = inputs.present_is_scheduled_on_tick_display,- .ui_overlay_fades_need_frame = inputs.ui_overlay_fades_need_frame,.clock_tick_is_due = inputs.clock_tick_interval_in_milliseconds.has_value(),.clock_tick_interval_in_milliseconds = inputs.clock_tick_interval_in_milliseconds.value_or(0),});diff --git a/Services/Compositor/CompositorCore.h b/Services/Compositor/CompositorCore.hindex 604d07ecb95..e1fe5abb063 100644--- a/Services/Compositor/CompositorCore.h+++ b/Services/Compositor/CompositorCore.h@@ -14,6 +14,7 @@#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/Types.h>+#include <LibCompositing/UIOverlays.h>#include <LibIPC/Encoded.h>#include <LibIPC/Message.h>#include <LibIPC/RawMessage.h>@@ -44,8 +45,8 @@ public:void stop_presenting_to_client(Web::CompositorContextId);// Ends the fling of a context that is hidden, whether or not it was visible.void set_visibility(Web::CompositorContextId, Compositing::ContextVisibility, MonotonicTime now);- void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize);- void set_paused_debugger_overlay_is_shown(Web::CompositorContextId, bool);+ void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, double device_pixel_ratio);+ void set_ui_overlays(Web::CompositorContextId, Compositing::UIOverlays const&, MonotonicTime now);void set_bound_presentation(Web::CompositorContextId, Optional<PresentationId>);void set_scroll_capabilities(Web::CompositorContextId, ScrollCapabilities const&);diff --git a/Services/Compositor/CompositorCoreHost.h b/Services/Compositor/CompositorCoreHost.hindex 46307862035..f634c683589 100644--- a/Services/Compositor/CompositorCoreHost.h+++ b/Services/Compositor/CompositorCoreHost.h@@ -8,7 +8,9 @@#include <AK/DistinctNumeric.h>#include <AK/Optional.h>+#include <AK/StringView.h>#include <AK/Time.h>+#include <AK/Vector.h>#include <Compositor/CompositorCoreRustFFI.h>#include <LibGfx/Rect.h>#include <LibIPC/Forward.h>@@ -43,7 +45,6 @@ struct PresentRequest {struct DisplayTickInputs {bool context_is_on_tick_display { false };bool present_is_scheduled_on_tick_display { false };- bool ui_overlay_fades_need_frame { false };// Set when the render clock of the context is due a tick now.Optional<double> clock_tick_interval_in_milliseconds;};@@ -52,6 +53,20 @@ using DisplayTickResult = RustFFI::DisplayTickResult;using ContextTimer = RustFFI::ContextTimer;+// A label of an overlay, shaped in a font that the overlays' resources of its context hold: the glyphs, where each goes+// along the line in device pixels, and the metrics of the font that placing the line needs.+struct OverlayLabel {+ u64 font_id { 0 };+ Vector<u32> glyph_ids;+ Vector<float> glyph_x_positions;+ float width { 0 };+ // At the size the label is shaped at: the ascent above the baseline, which is negative, and the descent.+ float ascent { 0 };+ float descent { 0 };+ // The ascent that the painter places glyphs below, at the font's own size.+ float font_ascent { 0 };+};+// What the scroll and input logic of the contexts asks of the process around it. None of these calls comes back into// that logic before it returns.class CompositorCoreHost {@@ -69,6 +84,8 @@ public:// Each timer of a context fires once after the delay, and setting it again replaces the delay.virtual void set_timer(Web::CompositorContextId, ContextTimer, AK::Duration delay) = 0;virtual void cancel_timer(Web::CompositorContextId, ContextTimer) = 0;+ // In the font family given, or the default one. Empty where no font draws the label.+ virtual Optional<OverlayLabel> shape_overlay_label(Web::CompositorContextId, Optional<StringView> font_family, double device_pixel_ratio, StringView text) = 0;};}diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 5e180c2417e..95847d45ce9 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -1067,35 +1067,29 @@ void CompositorState::viewport_size_updated(Web::CompositorContextId context_id,if (!context)return;- auto only_the_pixel_ratio_changed = viewport_size == context->presenter.viewport_size() && device_pixel_ratio != context->presenter.device_pixel_ratio();- m_core.viewport_size_updated(context_id, viewport_size);+ m_core.viewport_size_updated(context_id, viewport_size, device_pixel_ratio);auto is_page_presentation_context = context->page_id.has_value() && !context->parent_context_id.has_value();context->presenter.set_viewport_size(viewport_size, device_pixel_ratio, is_page_presentation_context ? window_resize_in_progress : Compositing::WindowResizingInProgress::No);resize_backing_stores_if_needed(context_id, *context);-- // The paused debugger's page will not paint again. Any other page's next frame damages the whole viewport when its- // size changes, but a new pixel ratio alone need not damage the overlays.- auto const& overlays = context->presenter.ui_overlays();- if (overlays.paused_debugger.has_value() || (only_the_pixel_ratio_changed && overlays.picture_in_picture_controls.has_value())) {- if (auto viewport_rect = context->presenter.viewport_rect_for_ui_overlay(); viewport_rect.has_value())- schedule_present_frame(context_id, *context, *viewport_rect);- }+ schedule_requested_presents();if (context->presenter.should_shrink_backing_stores_after_resize())schedule_backing_store_shrink(context_id, *context);}-void CompositorState::set_ui_overlays(Web::CompositorContextId context_id, Compositing::UIOverlays overlays)+Optional<OverlayLabel> CompositorState::shape_overlay_label(Web::CompositorContextId context_id, Optional<StringView> font_family, double device_pixel_ratio, StringView text){auto* context = presented_context_if_present(context_id);if (!context)- return;- if (context->presenter.ui_overlays() == overlays)- return;- m_core.set_paused_debugger_overlay_is_shown(context_id, overlays.paused_debugger.has_value());- context->presenter.set_ui_overlays(move(overlays));+ return {};+ return context->presenter.shape_overlay_label(font_family, device_pixel_ratio, text);+}- if (auto viewport_rect = context->presenter.viewport_rect_for_ui_overlay(); viewport_rect.has_value())- schedule_present_frame(context_id, *context, *viewport_rect);+void CompositorState::set_ui_overlays(Web::CompositorContextId context_id, Compositing::UIOverlays overlays)+{+ if (!presented_context_if_present(context_id))+ return;+ m_core.set_ui_overlays(context_id, overlays, MonotonicTime::now());+ schedule_requested_presents();}void CompositorState::set_display_metadata(Web::CompositorContextId context_id, Optional<u64> display_id, double refresh_rate)@@ -1362,7 +1356,8 @@ void CompositorState::schedule_pending_present_frame(Web::CompositorContextId cobool CompositorState::needs_animation_frames(Web::CompositorContextId context_id, PresentedContext const& context, MonotonicTime now){- return m_core.needs_animation_frames(context_id, now) || context.presenter.ui_overlay_fades_need_frame();+ (void)context;+ return m_core.needs_animation_frames(context_id, now);}bool CompositorState::has_pending_present_frame_scheduled_on(PresentedContext const& context, Optional<u64> display_id)@@ -1458,7 +1453,6 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,DisplayTickInputs inputs {.context_is_on_tick_display = context_is_on_tick_display,.present_is_scheduled_on_tick_display = has_pending_present_frame_scheduled_on(context, display_id),- .ui_overlay_fades_need_frame = context.presenter.ui_overlay_fades_need_frame(),.clock_tick_interval_in_milliseconds = {},};if (context.clock_tick_request.is_requested() && context_is_on_tick_display) {@@ -1475,11 +1469,9 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,schedule_requested_presents();if (!tick.presents_on_display)continue;- if (auto fade_frame = context.presenter.advance_ui_overlay_fades(frame_time); fade_frame.has_value())- context.presenter.queue_present_frame(*fade_frame);add_backing_store_for_pending_frame_if_needed(context_id, context);- auto needs_animation_frames = tick.needs_animation_frames || context.presenter.ui_overlay_fades_need_frame();+ auto needs_animation_frames = tick.needs_animation_frames;auto pending_present_frame = context.presenter.take_pending_present_frame_if_unblocked();if (!pending_present_frame.has_value()) {if (has_pending_present_frame_scheduled_on(context, display_id) || (needs_animation_frames && context_is_on_tick_display))diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex 6eaea41133b..954790dc3ea 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -205,6 +205,7 @@ private:virtual void request_display_ticks(Web::CompositorContextId) override;virtual void set_timer(Web::CompositorContextId, ContextTimer, AK::Duration delay) override;virtual void cancel_timer(Web::CompositorContextId, ContextTimer) override;+ virtual Optional<OverlayLabel> shape_overlay_label(Web::CompositorContextId, Optional<StringView> font_family, double device_pixel_ratio, StringView text) override;void context_timer_fired(Web::CompositorContextId, ContextTimer);// What the compositor keeps of a context to present it.diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cppindex 58edc831a9c..e9f8fe41b42 100644--- a/Services/Compositor/ContextPresenter.cpp+++ b/Services/Compositor/ContextPresenter.cpp@@ -9,16 +9,18 @@#include <Compositor/CanvasSurfaceRegistry.h>#include <Compositor/ContextPresenter.h>#include <Compositor/DisplayListPlayerSkia.h>-#include <Compositor/PausedDebuggerOverlay.h>-#include <Compositor/PictureInPictureControls.h>+#include <Compositor/FontSkia.h>#include <Compositor/SkiaUtils.h>-#include <LibCompositing/PictureInPictureControls.h>#include <LibCore/Timer.h>#include <LibGfx/Bitmap.h>+#include <LibGfx/Font/Font.h>+#include <LibGfx/Font/FontDatabase.h>#include <LibMedia/Sinks/VideoSink.h>#include <LibMediaCodecs/VideoFrame.h>#include <LibMediaCodecs/VideoSurface.h>#include <core/SkCanvas.h>+#include <core/SkFont.h>+#include <core/SkFontMetrics.h>#include <core/SkImage.h>#include <math.h>@@ -96,25 +98,37 @@ void ContextPresenter::finish_window_resize()m_window_resize_in_progress = Compositing::WindowResizingInProgress::No;}-void ContextPresenter::set_ui_overlays(Compositing::UIOverlays overlays)+Optional<OverlayLabel> ContextPresenter::shape_overlay_label(Optional<StringView> font_family, double device_pixel_ratio, StringView text){- m_ui_overlays = move(overlays);-- auto const& picture_in_picture_controls = m_ui_overlays.picture_in_picture_controls;- auto shows_picture_in_picture_controls = picture_in_picture_controls.has_value() && picture_in_picture_controls->shown;- m_picture_in_picture_controls_fade.fade_to(shows_picture_in_picture_controls ? 1 : 0, MonotonicTime::now());-}--Optional<PendingFrame> ContextPresenter::advance_ui_overlay_fades(MonotonicTime frame_time)-{- if (!m_picture_in_picture_controls_fade.advance_to(frame_time))+ RefPtr<Gfx::Font> font;+ if (font_family.has_value())+ font = Gfx::FontDatabase::the().get(MUST(FlyString::from_utf8(*font_family)), 12, 400, Gfx::FontWidth::Normal, 0);+ if (!font)+ font = Gfx::FontDatabase::the().get("SerenitySans"_fly_string, 12, 400, Gfx::FontWidth::Normal, 0);+ if (!font)return {};-- auto viewport_rect = viewport_rect_for_ui_overlay();- if (!viewport_rect.has_value())+ auto skia_font = Compositor::skia_font(*font, static_cast<float>(device_pixel_ratio));+ if (!skia_font.has_value())return {};- auto geometry = Compositing::picture_in_picture_controls_geometry(m_viewport_size, m_device_pixel_ratio);- return PendingFrame { *viewport_rect, Compositing::overlay_buttons_bounds(geometry.buttons()) };++ OverlayLabel label;+ auto glyph_count = skia_font->countText(text.characters_without_null_termination(), text.length(), SkTextEncoding::kUTF8);+ Vector<SkGlyphID> glyphs;+ glyphs.resize(glyph_count);+ skia_font->textToGlyphs(text.characters_without_null_termination(), text.length(), SkTextEncoding::kUTF8, { glyphs.data(), glyphs.size() });+ label.glyph_x_positions.resize(glyph_count);+ skia_font->getXPos({ glyphs.data(), glyphs.size() }, { label.glyph_x_positions.data(), label.glyph_x_positions.size() });+ label.glyph_ids.ensure_capacity(glyph_count);+ for (auto glyph : glyphs)+ label.glyph_ids.unchecked_append(glyph);+ label.width = skia_font->measureText(text.characters_without_null_termination(), text.length(), SkTextEncoding::kUTF8);+ SkFontMetrics font_metrics;+ skia_font->getMetrics(&font_metrics);+ label.ascent = font_metrics.fAscent;+ label.descent = font_metrics.fDescent;+ label.font_ascent = font->pixel_metrics().ascent;+ label.font_id = m_overlay_resource_storage.add_font(*font).value();+ return label;}Optional<Gfx::IntRect> ContextPresenter::viewport_rect_for_ui_overlay() const@@ -763,14 +777,9 @@ Optional<u64> ContextPresenter::current_video_frame_id(Compositing::VideoSinkResvoid ContextPresenter::paint_compositor_overlays(DisplayListPlayerSkia& display_list_player, Gfx::PaintingSurface& target_surface, FrameInputs const& frame_inputs, PaintUIOverlay paint_ui_overlay){- display_list_player.paint_scrollbars_into(target_surface, frame_inputs.scrollbars_painted_by_compositor());- if (paint_ui_overlay == PaintUIOverlay::No)- return;-- if (m_ui_overlays.paused_debugger.has_value())- paint_paused_debugger_overlay(target_surface, m_viewport_size, m_device_pixel_ratio, *m_ui_overlays.paused_debugger);- if (auto opacity = m_picture_in_picture_controls_fade.opacity(); m_ui_overlays.picture_in_picture_controls.has_value() && opacity > 0)- paint_picture_in_picture_controls(target_surface, m_viewport_size, m_device_pixel_ratio, *m_ui_overlays.picture_in_picture_controls, opacity);+ auto painter = display_list_player.begin_painting(target_surface, m_overlay_resource_storage, m_overlay_raster_cache, nullptr, nullptr);+ frame_inputs.paint_overlays(painter, paint_ui_overlay == PaintUIOverlay::Yes);+ display_list_player.end_painting();}Gfx::IntRect ContextPresenter::paint_frame(DisplayListPlayerSkia& display_list_player, Gfx::PaintingSurface& surface, FrameInputs const& frame_inputs, CompositedContextResolver const* composited_context_resolver, Gfx::IntRect damage_rect, LayerUpdate& layers)@@ -936,26 +945,9 @@ bool ContextPresenter::present_painted_layers_to_window_server(LayerPlan const&return true;}-Gfx::IntRect ContextPresenter::compositor_overlay_bounds(FrameInputs const& frame_inputs) const-{- Gfx::IntRect viewport_rect { {}, m_viewport_size };- if (m_ui_overlays.paused_debugger.has_value())- return viewport_rect;- if (m_ui_overlays.picture_in_picture_controls.has_value() && m_picture_in_picture_controls_fade.opacity() > 0)- return viewport_rect;- Gfx::IntRect bounds;- for (auto const& scrollbar : frame_inputs.scrollbars()) {- if (!scrollbar.is_painted_by_compositor || scrollbar.opacity <= 0)- continue;- // The thumb's outline is drawn around the gutter.- bounds.unite(Gfx::enclosing_int_rect(scrollbar.gutter_rect).united(scrollbar.thin_and_expanded_gutter_rect).inflated(2, 2));- }- return bounds.intersected(viewport_rect);-}-bool ContextPresenter::present_compositor_overlays_to_window_server(DisplayListPlayerSkia& display_list_player, FrameInputs const& frame_inputs, RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context){- auto bounds = compositor_overlay_bounds(frame_inputs);+ auto bounds = frame_inputs.overlay_bounds();m_compositor_overlay_rect = bounds;if (bounds.is_empty()) {m_latest_compositor_overlay_surface = nullptr;diff --git a/Services/Compositor/ContextPresenter.h b/Services/Compositor/ContextPresenter.hindex e7d96677bf2..414f3ee4728 100644--- a/Services/Compositor/ContextPresenter.h+++ b/Services/Compositor/ContextPresenter.h@@ -28,9 +28,7 @@#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>#include <LibCompositing/Forward.h>-#include <LibCompositing/OverlayFade.h>#include <LibCompositing/Types.h>-#include <LibCompositing/UIOverlays.h>#include <LibCore/Forward.h>#include <LibGfx/Rect.h>#include <LibGfx/ShareableBitmap.h>@@ -88,11 +86,10 @@ public:void schedule_backing_store_shrink(Function<void()>);void finish_window_resize();- Compositing::UIOverlays const& ui_overlays() const { return m_ui_overlays; }- void set_ui_overlays(Compositing::UIOverlays);+ // The viewport rect of the next frame, or of the frame presented last.Optional<Gfx::IntRect> viewport_rect_for_ui_overlay() const;- bool ui_overlay_fades_need_frame() const { return m_picture_in_picture_controls_fade.is_fading(); }- Optional<PendingFrame> advance_ui_overlay_fades(MonotonicTime frame_time);+ // Shapes a label of the overlays, in a font that the overlays' resources then hold.+ Optional<OverlayLabel> shape_overlay_label(Optional<StringView> font_family, double device_pixel_ratio, StringView text);ErrorOr<Optional<BackingStoreManager::Publication>> resize_backing_stores_if_needed(RefPtr<Gfx::SkiaBackendContext> const&, BackingStoreManager::GpuSharing, BackingStoreManager::PublicationMode, RefPtr<WindowServer> window_server_showing_stores = {});void invalidate_backing_stores();@@ -198,7 +195,6 @@ private:bool window_server_can_show_media_layers_of(LayerPlan const&);bool present_painted_layers_to_window_server(LayerPlan const&, RefPtr<Gfx::SkiaBackendContext> const&);bool present_compositor_overlays_to_window_server(DisplayListPlayerSkia&, FrameInputs const&, RefPtr<Gfx::SkiaBackendContext> const&);- Gfx::IntRect compositor_overlay_bounds(FrameInputs const&) const;Vector<RemoteSublayer> sublayers_shown_by_window_server();RefPtr<Media::VideoFrame> current_video_frame(Compositing::VideoSinkResourceId);void paint_compositor_overlays(DisplayListPlayerSkia&, Gfx::PaintingSurface&, FrameInputs const&, PaintUIOverlay);@@ -225,8 +221,9 @@ private:Gfx::IntSize m_viewport_size;double m_device_pixel_ratio { 1.0 };Compositing::WindowResizingInProgress m_window_resize_in_progress { Compositing::WindowResizingInProgress::No };- Compositing::UIOverlays m_ui_overlays;- Compositing::OverlayFade m_picture_in_picture_controls_fade;+ // The resources that the overlays draw with, apart from those of the page.+ Compositing::DisplayListResourceStorage m_overlay_resource_storage;+ DisplayListRasterCache m_overlay_raster_cache;BackingStoreManager m_backing_store_manager;RefPtr<Gfx::PaintingSurface> m_latest_rendered_surface;diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cppindex 1de3bea3585..89976636b95 100644--- a/Services/Compositor/DisplayListPlayerSkia.cpp+++ b/Services/Compositor/DisplayListPlayerSkia.cpp@@ -295,12 +295,6 @@ static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, Presentecanvas.drawRRect(thumb_rrect, stroke_paint);}-void DisplayListPlayerSkia::paint_scrollbars_into(Gfx::PaintingSurface& surface, ReadonlySpan<PresentedScrollbar> scrollbars)-{- for (auto const& scrollbar : scrollbars)- paint_scrollbar_into_surface(surface, scrollbar);-}-void DisplayListPlayerSkia::paint_scrollbar(PresentedScrollbar const& scrollbar){paint_scrollbar_into_surface(surface(), scrollbar);diff --git a/Services/Compositor/DisplayListPlayerSkia.h b/Services/Compositor/DisplayListPlayerSkia.hindex 27dc266a962..24eedd7c9db 100644--- a/Services/Compositor/DisplayListPlayerSkia.h+++ b/Services/Compositor/DisplayListPlayerSkia.h@@ -54,7 +54,6 @@ public:void flush(Gfx::PaintingSurface&);void flush_async(Gfx::PaintingSurface&, Function<void()>&&);- void paint_scrollbars_into(Gfx::PaintingSurface&, ReadonlySpan<PresentedScrollbar>);private:struct PainterCallbacks;diff --git a/Services/Compositor/FrameInputs.cpp b/Services/Compositor/FrameInputs.cppindex 9221f10d490..beab24bef87 100644--- a/Services/Compositor/FrameInputs.cpp+++ b/Services/Compositor/FrameInputs.cpp@@ -57,24 +57,16 @@ void FrameInputs::replay(Compositing::DisplayList const& display_list, CompositiRustFFI::compositor_frame_inputs_replay(m_frame_inputs, display_list.rust_handle(), display_list.root_group_color(), &selection, &painter);}-Vector<PresentedScrollbar> FrameInputs::scrollbars_painted_by_compositor() const+void FrameInputs::paint_overlays(Compositing::RustFFI::FfiRasterPainter const& painter, bool paints_ui_overlays) const{- Vector<PresentedScrollbar> presented_scrollbars;- for (auto const& scrollbar : scrollbars()) {- if (!scrollbar.is_painted_by_compositor)- continue;- // The gutter of a thin scrollbar is not painted, so the gutter grows out of the thin track as it fades in.- auto track_alpha = roundf(static_cast<float>(scrollbar.track_color.alpha()) * scrollbar.expansion);- presented_scrollbars.append({- .gutter_rect = scrollbar.gutter_rect,- .thumb_rect = scrollbar.thumb_rect,- .thumb_color = scrollbar.thumb_color,- .thumb_outline_color = scrollbar.thumb_outline_color,- .track_color = scrollbar.track_color.with_alpha(static_cast<u8>(track_alpha)),- .opacity = scrollbar.opacity,- });- }- return presented_scrollbars;+ RustFFI::compositor_frame_inputs_paint_overlays(m_frame_inputs, &painter, paints_ui_overlays);+}++Gfx::IntRect FrameInputs::overlay_bounds() const+{+ Gfx::IntRect bounds;+ RustFFI::compositor_frame_inputs_overlay_bounds(m_frame_inputs, &bounds);+ return bounds;}RustFFI::ContextLayerPlan* FrameInputs::build_layer_plan(Compositing::DisplayList const& display_list, Gfx::IntRect viewport_rect, ReadonlySpan<RustFFI::FfiLiveMedia> active_media) constdiff --git a/Services/Compositor/FrameInputs.h b/Services/Compositor/FrameInputs.hindex 14d17662398..b5915a0cfe6 100644--- a/Services/Compositor/FrameInputs.h+++ b/Services/Compositor/FrameInputs.h@@ -69,8 +69,11 @@ public:// Replays the list through a painter as the frame shows it.void replay(Compositing::DisplayList const&, Compositing::RustFFI::FfiRasterPainter const&, ReplaySelection const& = replaying_everything()) const;- // The scrollbars the compositor paints over the page, as the frame shows them.- Vector<PresentedScrollbar> scrollbars_painted_by_compositor() const;+ // Paints what the compositor draws over the page: its scrollbars, and unless they are left out, the overlays of the+ // browser.+ void paint_overlays(Compositing::RustFFI::FfiRasterPainter const&, bool paints_ui_overlays) const;+ // The part of the viewport that the overlays cover.+ Gfx::IntRect overlay_bounds() const;RustFFI::ContextLayerPlan* build_layer_plan(Compositing::DisplayList const&, Gfx::IntRect viewport_rect, ReadonlySpan<RustFFI::FfiLiveMedia> active_media) const;bool places_content_like(FrameInputs const&) const;diff --git a/Services/Compositor/PausedDebuggerOverlay.cpp b/Services/Compositor/PausedDebuggerOverlay.cppdeleted file mode 100644index b9dfc8136a7..00000000000--- a/Services/Compositor/PausedDebuggerOverlay.cpp+++ /dev/null@@ -1,149 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <AK/Math.h>-#include <Compositor/FontSkia.h>-#include <Compositor/PaintingSurface.h>-#include <Compositor/PausedDebuggerOverlay.h>-#include <Compositor/SkiaUtils.h>-#include <LibCompositing/UIOverlays.h>-#include <LibGfx/Font/Font.h>-#include <LibGfx/Font/FontDatabase.h>-#include <core/SkCanvas.h>-#include <core/SkFont.h>-#include <core/SkFontMetrics.h>-#include <core/SkPaint.h>-#include <core/SkPathBuilder.h>-#include <core/SkRRect.h>--namespace Compositor {--void paint_paused_debugger_overlay(Gfx::PaintingSurface& surface, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::PausedDebuggerOverlayState const& state)-{- auto const& font_family = state.font_family;- auto const& hovered_action = state.hovered_action;-- // These colors are equivalent to those produced by UI/Qt/ChromeStyle.cpp in light mode. The compositor cannot use- // those colors directly because it does not depend on Qt, so we have to copy their resolved values here.- static constexpr auto overlay_color = Color(0xee, 0xee, 0xef, 168);- static constexpr auto toolbar_color = Color(0xff, 0xff, 0xff);- static constexpr auto toolbar_border_color = Color(0xce, 0xce, 0xcf);- static constexpr auto button_hover_color = Color(0xf1, 0xf1, 0xf2);- static constexpr auto text_color = Color(0x18, 0x1d, 0x24);- static constexpr auto shadow_color = Color(0x18, 0x1d, 0x24, 66);-- auto& canvas = surface.canvas();- auto geometry = Compositing::paused_debugger_overlay_geometry(viewport_size, device_pixel_ratio);- auto radius = max(1.0f, static_cast<float>(4 * device_pixel_ratio));-- SkPaint paint;- paint.setAntiAlias(true);- paint.setColor(Gfx::to_skia_color(overlay_color));- canvas.drawRect(SkRect::MakeWH(viewport_size.width(), viewport_size.height()), paint);-- auto shadow_rect = geometry.toolbar.translated(0, Compositing::scaled_overlay_length(2, device_pixel_ratio));- paint.setColor(Gfx::to_skia_color(shadow_color));- canvas.drawRRect(SkRRect::MakeRectXY(Gfx::to_skia_rect(shadow_rect), radius, radius), paint);-- paint.setColor(Gfx::to_skia_color(toolbar_color));- canvas.drawRRect(SkRRect::MakeRectXY(Gfx::to_skia_rect(geometry.toolbar), radius, radius), paint);-- if (hovered_action.has_value()) {- auto const& hovered_button = *hovered_action == Compositing::PausedDebuggerOverlayAction::StepOver- ? geometry.step_over_button- : geometry.continue_button;- canvas.save();- canvas.clipRRect(SkRRect::MakeRectXY(Gfx::to_skia_rect(geometry.toolbar), radius, radius), true);- paint.setColor(Gfx::to_skia_color(button_hover_color));- canvas.drawRect(Gfx::to_skia_rect(hovered_button), paint);- canvas.restore();- }-- paint.setStyle(SkPaint::kStroke_Style);- paint.setStrokeWidth(max(1.0, device_pixel_ratio));- paint.setColor(Gfx::to_skia_color(toolbar_border_color));- canvas.drawRRect(SkRRect::MakeRectXY(Gfx::to_skia_rect(geometry.toolbar), radius, radius), paint);- paint.setStyle(SkPaint::kFill_Style);-- auto divider_inset = Compositing::scaled_overlay_length(10, device_pixel_ratio);- auto divider_x = geometry.step_over_button.left();- canvas.drawLine(- divider_x,- geometry.toolbar.top() + divider_inset,- divider_x,- geometry.toolbar.bottom() - divider_inset,- paint);-- RefPtr<Gfx::Font> font;- if (font_family.has_value())- font = Gfx::FontDatabase::the().get(FlyString { *font_family }, 12, 400, Gfx::FontWidth::Normal, 0);- if (!font)- font = Gfx::FontDatabase::the().get("SerenitySans"_fly_string, 12, 400, Gfx::FontWidth::Normal, 0);- paint.setColor(Gfx::to_skia_color(text_color));- Optional<SkFont> maybe_skia_font;- if (font)- maybe_skia_font = Compositor::skia_font(*font, static_cast<float>(device_pixel_ratio));- if (maybe_skia_font.has_value()) {- auto const& skia_font = *maybe_skia_font;- static constexpr auto label = "Paused in debugger"sv;- auto label_width = skia_font.measureText(label.characters_without_null_termination(), label.length(), SkTextEncoding::kUTF8);- SkFontMetrics font_metrics;- skia_font.getMetrics(&font_metrics);- auto label_x = geometry.message.x() + (geometry.message.width() - label_width) / 2;- auto label_y = geometry.message.center().y() - (font_metrics.fAscent + font_metrics.fDescent) / 2;- canvas.drawSimpleText(label.characters_without_null_termination(), label.length(), SkTextEncoding::kUTF8, label_x, label_y, skia_font, paint);- }-- auto icon_size = max(8.0, 16 * device_pixel_ratio);- auto line_thickness = max(1.0, device_pixel_ratio);-- auto paint_continue_icon = [&](Gfx::IntRect const& button_rect) {- auto icon_left = button_rect.center().x() - icon_size / 2;- auto icon_top = button_rect.center().y() - icon_size / 2;- SkPathBuilder path;- path.moveTo(icon_left + icon_size / 4, icon_top + icon_size / 8);- path.lineTo(icon_left + icon_size / 4, icon_top + icon_size - icon_size / 8);- path.lineTo(icon_left + icon_size - icon_size / 8, icon_top + icon_size / 2);- path.close();- canvas.drawPath(path.detach(), paint);- };-- auto paint_step_over_icon = [&](Gfx::IntRect const& button_rect) {- auto center = button_rect.center();- auto left = center.x() - icon_size / 2;- auto top = center.y() - icon_size / 2;- auto right = center.x() + icon_size / 2;-- SkPathBuilder arc;- arc.moveTo(left + icon_size / 8, top + icon_size * 0.55);- arc.cubicTo(- left + icon_size / 8, top + icon_size * 0.15,- right - icon_size / 5, top + icon_size * 0.15,- right - icon_size / 5, top + icon_size * 0.55);- paint.setStyle(SkPaint::kStroke_Style);- paint.setStrokeCap(SkPaint::kRound_Cap);- paint.setStrokeJoin(SkPaint::kRound_Join);- paint.setStrokeWidth(line_thickness);- canvas.drawPath(arc.detach(), paint);- paint.setStyle(SkPaint::kFill_Style);-- SkPathBuilder arrow;- auto arrow_width = icon_size / 2.5;- arrow.moveTo(right - arrow_width, top + icon_size * 0.55);- arrow.lineTo(right, top + icon_size * 0.55);- arrow.lineTo(right - arrow_width / 2, top + icon_size * 0.8);- arrow.close();- canvas.drawPath(arrow.detach(), paint);-- auto dot_size = max(2.0, line_thickness * 2);- canvas.drawCircle(center.x(), center.y() + icon_size / 3, dot_size / 2, paint);- };-- paint_step_over_icon(geometry.step_over_button);- paint_continue_icon(geometry.continue_button);-}--}diff --git a/Services/Compositor/PausedDebuggerOverlay.h b/Services/Compositor/PausedDebuggerOverlay.hdeleted file mode 100644index 3f8211e6da9..00000000000--- a/Services/Compositor/PausedDebuggerOverlay.h+++ /dev/null@@ -1,18 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <Compositor/Forward.h>-#include <LibCompositing/Forward.h>-#include <LibGfx/Forward.h>-#include <LibGfx/Size.h>--namespace Compositor {--void paint_paused_debugger_overlay(Gfx::PaintingSurface&, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::PausedDebuggerOverlayState const&);--}diff --git a/Services/Compositor/PictureInPictureControls.cpp b/Services/Compositor/PictureInPictureControls.cppdeleted file mode 100644index b3379e3e8d3..00000000000--- a/Services/Compositor/PictureInPictureControls.cpp+++ /dev/null@@ -1,78 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <Compositor/PaintingSurface.h>-#include <Compositor/PictureInPictureControls.h>-#include <Compositor/SkiaUtils.h>-#include <LibCompositing/UIOverlays.h>-#include <core/SkCanvas.h>-#include <core/SkPaint.h>-#include <core/SkPathBuilder.h>--namespace Compositor {--void paint_picture_in_picture_controls(Gfx::PaintingSurface& surface, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::PictureInPictureControlsState const& state, float opacity)-{- static constexpr auto button_color = Color(0, 0, 0, 115);- static constexpr auto icon_color = Color(0xff, 0xff, 0xff);- static constexpr auto hovered_icon_color = Color(0xe0, 0xd4, 0xff);-- auto& canvas = surface.canvas();- auto geometry = Compositing::picture_in_picture_controls_geometry(viewport_size, device_pixel_ratio);- auto bounds = Gfx::to_skia_rect(Compositing::overlay_buttons_bounds(geometry.buttons()));- canvas.saveLayerAlphaf(&bounds, opacity);-- SkPaint paint;- paint.setAntiAlias(true);-- // The icons are stroked on a grid of 16 units, and drawn at the given size in points.- auto paint_button = [&](Gfx::IntRect const& button, Compositing::PictureInPictureControl control, SkPathBuilder& icon, float icon_points, float stroke_units) {- auto center = button.to_type<float>().center();- paint.setStyle(SkPaint::kFill_Style);- paint.setColor(Gfx::to_skia_color(button_color));- canvas.drawCircle(center.x(), center.y(), button.width() / 2.0f, paint);-- auto icon_size = static_cast<float>(icon_points * device_pixel_ratio);- canvas.save();- canvas.translate(center.x() - icon_size / 2, center.y() - icon_size / 2);- canvas.scale(icon_size / 16, icon_size / 16);- paint.setStyle(SkPaint::kStroke_Style);- paint.setStrokeWidth(stroke_units);- paint.setStrokeCap(SkPaint::kRound_Cap);- paint.setStrokeJoin(SkPaint::kRound_Join);- paint.setColor(Gfx::to_skia_color(state.hovered_control == control ? hovered_icon_color : icon_color));- canvas.drawPath(icon.detach(), paint);- canvas.restore();- };-- // An arrow out of a box, toward its top right corner.- SkPathBuilder back_to_tab_icon;- back_to_tab_icon.moveTo(9.5f, 2.5f);- back_to_tab_icon.lineTo(13.5f, 2.5f);- back_to_tab_icon.lineTo(13.5f, 6.5f);- back_to_tab_icon.moveTo(13.5f, 2.5f);- back_to_tab_icon.lineTo(8, 8);- back_to_tab_icon.moveTo(12, 9.5f);- back_to_tab_icon.lineTo(12, 12.5f);- back_to_tab_icon.quadTo(12, 13.5f, 11, 13.5f);- back_to_tab_icon.lineTo(3.5f, 13.5f);- back_to_tab_icon.quadTo(2.5f, 13.5f, 2.5f, 12.5f);- back_to_tab_icon.lineTo(2.5f, 5);- back_to_tab_icon.quadTo(2.5f, 4, 3.5f, 4);- back_to_tab_icon.lineTo(6.5f, 4);- paint_button(geometry.back_to_tab_button, Compositing::PictureInPictureControl::BackToTab, back_to_tab_icon, 14, 1.6f);-- SkPathBuilder close_icon;- close_icon.moveTo(4, 4);- close_icon.lineTo(12, 12);- close_icon.moveTo(12, 4);- close_icon.lineTo(4, 12);- paint_button(geometry.close_button, Compositing::PictureInPictureControl::Close, close_icon, 11, 2);-- canvas.restore();-}--}diff --git a/Services/Compositor/PictureInPictureControls.h b/Services/Compositor/PictureInPictureControls.hdeleted file mode 100644index a4402b0cbf2..00000000000--- a/Services/Compositor/PictureInPictureControls.h+++ /dev/null@@ -1,18 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <Compositor/Forward.h>-#include <LibCompositing/Forward.h>-#include <LibGfx/Forward.h>-#include <LibGfx/Size.h>--namespace Compositor {--void paint_picture_in_picture_controls(Gfx::PaintingSurface&, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::PictureInPictureControlsState const&, float opacity);--}diff --git a/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs b/Services/Compositor/Rust/src/context_state/frames_and_viewport.rsindex d7113079942..57089566110 100644--- a/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs+++ b/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs@@ -212,19 +212,43 @@ impl ContextState {);}- pub fn viewport_size_updated(&mut self, viewport_size: IntSize) {+ // Returns whether the overlays have to repaint all of the viewport. The page's next frame repaints all of it when its+ // size changes, but the paused debugger's page does not paint again, and a new pixel ratio alone need not repaint+ // the page.+ pub fn viewport_size_updated(&mut self, viewport_size: IntSize, device_pixel_ratio: f64) -> bool {+ let only_the_pixel_ratio_changed =+ viewport_size == self.viewport_size && device_pixel_ratio != self.device_pixel_ratio;self.scene.forget_whether_animated_content_may_affect_viewport();if self.viewport_size != viewport_size {self.keyboard_scroll_controller.forget_target();}self.viewport_size = viewport_size;+ self.device_pixel_ratio = device_pixel_ratio;+ let ui_overlays = self.overlays.ui_overlays();+ ui_overlays.paused_debugger.is_some()+ || (only_the_pixel_ratio_changed && ui_overlays.picture_in_picture_controls.is_some())}- pub fn set_paused_debugger_overlay_is_shown(&mut self, is_shown: bool) {- if is_shown {+ // Returns false, changing nothing, for the overlays already shown.+ pub fn set_ui_overlays(&mut self, ui_overlays: UIOverlays, now: MonotonicTime) -> bool {+ let shows_paused_debugger = ui_overlays.paused_debugger.is_some();+ if !self.overlays.set_ui_overlays(ui_overlays, now) {+ return false;+ }+ if shows_paused_debugger {self.end_keyboard_scroll_gesture();}- self.paused_debugger_overlay_is_shown = is_shown;+ true+ }++ // What the fades of the overlays repaint of the viewport as they advance to the frame.+ pub fn advance_overlay_fades(&mut self, frame_time: MonotonicTime) -> Option<IntRect> {+ self.overlays+ .advance_fades(frame_time, self.viewport_size, self.device_pixel_ratio)+ }++ pub fn viewport_rect(&self) -> IntRect {+ IntRect::new(0, 0, self.viewport_size.width, self.viewport_size.height)}pub fn set_visibility(&mut self, visibility: ContextVisibility) -> bool {@@ -261,12 +285,19 @@ impl ContextState {let scrollbars = self.scrollbar_controller.scrollbars_of_frame(&presented_scroll_state_snapshot);+ let overlays = self.overlays.picture_of_frame(+ &scrollbars,+ self.viewport_size,+ self.device_pixel_ratio,+ &self.host.overlay_label_shaper(self.context_id),+ );FrameInputs {visual_context_tree: self.scene.visual_context_tree_for_compositing().clone(),presented_scroll_state_snapshot,scrollbars,viewport_scroll_node_index: self.async_scroll_tree.viewport_scroll_node_index(),painted_at: now,+ overlays,}}diff --git a/Services/Compositor/Rust/src/context_state/keys_and_pointer.rs b/Services/Compositor/Rust/src/context_state/keys_and_pointer.rsindex 8d32499ee1c..4d550ff4da4 100644--- a/Services/Compositor/Rust/src/context_state/keys_and_pointer.rs+++ b/Services/Compositor/Rust/src/context_state/keys_and_pointer.rs@@ -11,7 +11,7 @@ use super::*;impl ContextState {fn key_scroll_for(&self, event: &KeyEvent) -> Option<KeyScroll> {if !self.presents_to_client()- || self.paused_debugger_overlay_is_shown+ || self.overlays.ui_overlays().paused_debugger.is_some()|| self.visibility != ContextVisibility::Visible|| !is_keyboard_scroll_key(event.key, event.modifiers.0)|| !self.keyboard_scroll_controller.has_target()diff --git a/Services/Compositor/Rust/src/context_state/mod.rs b/Services/Compositor/Rust/src/context_state/mod.rsindex 3f58cf17e29..04e67a622f4 100644--- a/Services/Compositor/Rust/src/context_state/mod.rs+++ b/Services/Compositor/Rust/src/context_state/mod.rs@@ -19,6 +19,7 @@ use crate::frame_inputs::FrameInputs;use crate::host::{ContextTimer, Host, PendingFrame, PresentationId, WebContentClientId};use crate::input_event::is_keyboard_scroll_key;use crate::keyboard_scroll_controller::{KeyRelease, KeyStep, KeyboardScrollController};+use crate::overlays::{ContextOverlays, UIOverlays};use crate::scroll_fling_controller::ScrollFlingController;use crate::scroll_snap_controller::{ScrollSnapController, SnapScrollStart, StepDecision};use crate::scrollbar_controller::{Drag, ScrollbarController};@@ -300,7 +301,8 @@ pub struct ContextState {scene: ContextScene,presents_to_client: bool,viewport_size: IntSize,- paused_debugger_overlay_is_shown: bool,+ device_pixel_ratio: f64,+ overlays: ContextOverlays,scroll_state_snapshot: ScrollStateSnapshot,async_scroll_tree: AsyncScrollTree,@@ -399,7 +401,8 @@ impl ContextState {scene: Default::default(),presents_to_client: page_id.is_some(),viewport_size: Default::default(),- paused_debugger_overlay_is_shown: Default::default(),+ device_pixel_ratio: 1.0,+ overlays: Default::default(),scroll_state_snapshot: Default::default(),async_scroll_tree: Default::default(),scrollbar_controller: ScrollbarController::new(scrollbars_always_shown),@@ -538,6 +541,7 @@ impl ContextState {|| self.elastic_overscroll_controller.has_rebound()|| self.visual_animations_need_frame(now)|| self.scrollbar_controller.fades_need_frame(now)+ || self.overlays.fades_need_frame()}pub fn has_active_scroll_fling(&self) -> bool {self.scroll_fling_controller.is_active()diff --git a/Services/Compositor/Rust/src/core/mod.rs b/Services/Compositor/Rust/src/core/mod.rsindex 2c747d771d2..6dd71fc9494 100644--- a/Services/Compositor/Rust/src/core/mod.rs+++ b/Services/Compositor/Rust/src/core/mod.rs@@ -19,6 +19,7 @@ use crate::host::{ContextTimer, DisplayTickInputs, DisplayTickResult, Host, PendingFrame, PresentRequest, PresentScheduling,PresentationId, WebContentClientId,};+use crate::overlays::UIOverlays;use crate::wheel_gesture_routing::WheelGestureIdAllocator;use libcompositing_rust::ipc_types::Compositing_ContextVisibility as ContextVisibility;use libcompositing_rust::scrolling::{@@ -189,22 +190,44 @@ impl CompositorCore {context.borrow_mut().stop_presenting_to_client();}- pub fn viewport_size_updated(&self, context_id: CompositorContextId, viewport_size: IntSize) {+ pub fn viewport_size_updated(+ &self,+ context_id: CompositorContextId,+ viewport_size: IntSize,+ device_pixel_ratio: f64,+ ) {let _entered = self.enter();let Some(context) = self.context_if_present(context_id) else {return;};- context.borrow_mut().viewport_size_updated(viewport_size);+ let overlays_repaint_everything = context+ .borrow_mut()+ .viewport_size_updated(viewport_size, device_pixel_ratio);+ if overlays_repaint_everything {+ self.request_present_repainting_everything(context_id, context);+ }}- pub fn set_paused_debugger_overlay_is_shown(&self, context_id: CompositorContextId, is_shown: bool) {+ pub fn set_ui_overlays(&self, context_id: CompositorContextId, ui_overlays: UIOverlays, now: MonotonicTime) {let _entered = self.enter();let Some(context) = self.context_if_present(context_id) else {return;};- context.borrow_mut().set_paused_debugger_overlay_is_shown(is_shown);+ if context.borrow_mut().set_ui_overlays(ui_overlays, now) {+ self.request_present_repainting_everything(context_id, context);+ }+ }++ // A frame at the viewport rect the context is presented at, which repaints all of it.+ fn request_present_repainting_everything(&self, context_id: CompositorContextId, context: &RefCell<ContextState>) {+ self.present_requests.borrow_mut().push(PresentRequest {+ context_id,+ viewport_rect: None,+ forced_damage_rect: context.borrow().viewport_rect(),+ scheduling: PresentScheduling::OnNextDisplayTick,+ });}pub fn set_bound_presentation(&self, context_id: CompositorContextId, presentation_id: Option<PresentationId>) {@@ -387,9 +410,8 @@ impl CompositorCore {let context = self.context_if_present(context_id).expect("context exists");- let has_active_animation_on_display = (context.borrow_mut().needs_animation_frames(now)- || inputs.ui_overlay_fades_need_frame)- && inputs.context_is_on_tick_display;+ let has_active_animation_on_display =+ context.borrow_mut().needs_animation_frames(now) && inputs.context_is_on_tick_display;let presents_on_display = inputs.present_is_scheduled_on_tick_display || has_active_animation_on_display;if presents_on_display {if inputs.context_is_on_tick_display {@@ -445,6 +467,15 @@ impl CompositorCore {scheduling: PresentScheduling::WithDisplayTickInProgress,});}+ let overlay_fade_damage_rect = context.borrow_mut().advance_overlay_fades(frame_time);+ if let Some(overlay_fade_damage_rect) = overlay_fade_damage_rect {+ self.present_requests.borrow_mut().push(PresentRequest {+ context_id,+ viewport_rect: None,+ forced_damage_rect: overlay_fade_damage_rect,+ scheduling: PresentScheduling::WithDisplayTickInProgress,+ });+ }}DisplayTickResult {presents_on_display,diff --git a/Services/Compositor/Rust/src/ffi.rs b/Services/Compositor/Rust/src/ffi.rsindex 9d2e1f60436..fa2c47d7a15 100644--- a/Services/Compositor/Rust/src/ffi.rs+++ b/Services/Compositor/Rust/src/ffi.rs@@ -15,6 +15,10 @@ use crate::host::{WebContentClientId,};use crate::layers::ContextLayerPlan;+use crate::overlays::{+ PausedDebuggerOverlayAction, PausedDebuggerOverlayState, PictureInPictureControl, PictureInPictureControlsState,+ UIOverlays,+};use libcompositing_rust::display_list::commands::{CanvasId, CompositorContextId, ImageFrameResourceId, VideoSinkResourceId,};@@ -131,17 +135,90 @@ pub extern "C" fn compositor_core_viewport_size_updated(core: &CompositorCore,context_id: u64,viewport_size: IntSize,+ device_pixel_ratio: f64,) {- core.viewport_size_updated(CompositorContextId(context_id), viewport_size);+ core.viewport_size_updated(CompositorContextId(context_id), viewport_size, device_pixel_ratio);+}++/// What the browser draws over a context's page. An action or control is none where it is out of range.+#[repr(C)]+pub struct FfiUIOverlays<'a> {+ pub has_paused_debugger: bool,+ pub paused_debugger_has_font_family: bool,+ pub paused_debugger_font_family: ak::Span<'a, u8>,+ pub paused_debugger_has_hovered_action: bool,+ pub paused_debugger_hovered_action: u8,+ pub has_picture_in_picture_controls: bool,+ pub picture_in_picture_controls_shown: bool,+ pub picture_in_picture_controls_has_hovered_control: bool,+ pub picture_in_picture_controls_hovered_control: u8,}#[unsafe(no_mangle)]-pub extern "C" fn compositor_core_set_paused_debugger_overlay_is_shown(+pub extern "C" fn compositor_core_set_ui_overlays(core: &CompositorCore,context_id: u64,- is_shown: bool,+ ui_overlays: &FfiUIOverlays<'_>,+ now_nanoseconds: i64,+) {+ let paused_debugger = ui_overlays.has_paused_debugger.then(|| PausedDebuggerOverlayState {+ font_family: ui_overlays+ .paused_debugger_has_font_family+ .then(|| String::from_utf8_lossy(ui_overlays.paused_debugger_font_family.as_slice()).into_owned()),+ hovered_action: match (+ ui_overlays.paused_debugger_has_hovered_action,+ ui_overlays.paused_debugger_hovered_action,+ ) {+ (true, 0) => Some(PausedDebuggerOverlayAction::StepOver),+ (true, 1) => Some(PausedDebuggerOverlayAction::Continue),+ _ => None,+ },+ });+ let picture_in_picture_controls =+ ui_overlays+ .has_picture_in_picture_controls+ .then_some(PictureInPictureControlsState {+ shown: ui_overlays.picture_in_picture_controls_shown,+ hovered_control: match (+ ui_overlays.picture_in_picture_controls_has_hovered_control,+ ui_overlays.picture_in_picture_controls_hovered_control,+ ) {+ (true, 0) => Some(PictureInPictureControl::BackToTab),+ (true, 1) => Some(PictureInPictureControl::Close),+ _ => None,+ },+ });+ core.set_ui_overlays(+ CompositorContextId(context_id),+ UIOverlays {+ paused_debugger,+ picture_in_picture_controls,+ },+ MonotonicTime::from_nanoseconds(now_nanoseconds),+ );+}++/// Paints what the compositor draws over the page in the frame: its scrollbars and, unless they are left out, the+/// overlays of the browser.+///+/// # Safety+///+/// `painter` must be live. The painter callbacks run synchronously.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn compositor_frame_inputs_paint_overlays(+ frame_inputs: &FrameInputs,+ painter: *const FfiRasterPainter,+ paints_ui_overlays: bool,) {- core.set_paused_debugger_overlay_is_shown(CompositorContextId(context_id), is_shown);+ // SAFETY: The caller lends a live painter.+ let mut painter = unsafe { *painter };+ frame_inputs.overlays.paint(&mut painter, paints_ui_overlays);+}++/// The part of the viewport that what the compositor draws over the page covers in the frame.+#[unsafe(no_mangle)]+pub extern "C" fn compositor_frame_inputs_overlay_bounds(frame_inputs: &FrameInputs, bounds: &mut IntRect) {+ *bounds = frame_inputs.overlays.bounds;}#[unsafe(no_mangle)]@@ -459,7 +536,6 @@ pub unsafe extern "C" fn compositor_frame_inputs_damage_since(pub struct FfiDisplayTickInputs {pub context_is_on_tick_display: bool,pub present_is_scheduled_on_tick_display: bool,- pub ui_overlay_fades_need_frame: bool,/// Whether the render clock of the context is due a tick now, of the interval that follows.pub clock_tick_is_due: bool,pub clock_tick_interval_in_milliseconds: f64,@@ -480,7 +556,6 @@ pub extern "C" fn compositor_core_display_tick(&DisplayTickInputs {context_is_on_tick_display: inputs.context_is_on_tick_display,present_is_scheduled_on_tick_display: inputs.present_is_scheduled_on_tick_display,- ui_overlay_fades_need_frame: inputs.ui_overlay_fades_need_frame,clock_tick_interval_in_milliseconds: inputs.clock_tick_is_due.then_some(inputs.clock_tick_interval_in_milliseconds),diff --git a/Services/Compositor/Rust/src/frame_inputs.rs b/Services/Compositor/Rust/src/frame_inputs.rsindex 8c4756018b5..39b5a223b4e 100644--- a/Services/Compositor/Rust/src/frame_inputs.rs+++ b/Services/Compositor/Rust/src/frame_inputs.rs@@ -6,6 +6,7 @@//! What a frame is painted with besides the display list and its resources.+use crate::overlays::OverlayPicture;use libcompositing_rust::display_list::damage::{DisplayListDamage, DisplayListFrame, LayerPlans, LiveContentChanges, compute_display_list_damage,};@@ -59,6 +60,8 @@ pub struct FrameInputs {pub viewport_scroll_node_index: Option<SpatialNodeIndex>,// When the frame is painted, which is the time a blinking caret shows as of.pub painted_at: MonotonicTime,+ // What the compositor draws over the page in the frame.+ pub overlays: OverlayPicture,}impl FrameInputs {diff --git a/Services/Compositor/Rust/src/host.rs b/Services/Compositor/Rust/src/host.rsindex 1a501c55c4d..aeba1938bd5 100644--- a/Services/Compositor/Rust/src/host.rs+++ b/Services/Compositor/Rust/src/host.rs@@ -7,6 +7,7 @@//! What the scroll and input logic of the contexts asks of the process around it. None of these calls comes back into//! that logic before it returns.+use crate::overlays::{OverlayLabel, OverlayLabelShaper};use libcompositing_rust::scrolling::CompositorContextId;use libcompositing_rust::time::Duration;use libgfx_rust::IntRect;@@ -76,7 +77,6 @@ pub struct PresentRequest {pub struct DisplayTickInputs {pub context_is_on_tick_display: bool,pub present_is_scheduled_on_tick_display: bool,- pub ui_overlay_fades_need_frame: bool,/// Set when the render clock of the context is due a tick now.pub clock_tick_interval_in_milliseconds: Option<f64>,}@@ -85,10 +85,22 @@ pub struct DisplayTickInputs {#[repr(C)]pub struct DisplayTickResult {pub presents_on_display: bool,- /// As of the end of the tick, and without the fades of the UI overlays.+ /// As of the end of the tick.pub needs_animation_frames: bool,}+/// A label of an overlay as the host shaped it, lent for the call it is handed to.+#[repr(C)]+pub struct FfiOverlayLabel<'a> {+ pub font_id: u64,+ pub glyph_ids: ak::Span<'a, u32>,+ pub glyph_x_positions: ak::Span<'a, f32>,+ pub width: f32,+ pub ascent: f32,+ pub descent: f32,+ pub font_ascent: f32,+}+/// The entry points of the host and the object they are called on: `Compositor::RustFFI::FfiCompositorCoreHost`.#[repr(C)]#[derive(Clone, Copy)]@@ -103,6 +115,18 @@ pub struct FfiCompositorCoreHost {pub request_display_ticks: unsafe extern "C" fn(*mut c_void, u64),pub set_timer: unsafe extern "C" fn(*mut c_void, u64, ContextTimer, i64),pub cancel_timer: unsafe extern "C" fn(*mut c_void, u64, ContextTimer),+ /// Arguments: the context, whether a font family is given, the font family, the device pixel ratio, the text, and+ /// what receives the shaped label, which is not called where no font draws the label.+ pub shape_overlay_label: unsafe extern "C" fn(+ *mut c_void,+ u64,+ bool,+ ak::Span<'_, u8>,+ f64,+ ak::Span<'_, u8>,+ *mut c_void,+ unsafe extern "C" fn(*mut c_void, *const FfiOverlayLabel<'_>),+ ),}type PostEncodedMessage = unsafe extern "C" fn(*mut c_void, u64, ak::Span<'_, u8>, ak::Span<'_, RawAttachment>);@@ -164,4 +188,52 @@ impl Host {// SAFETY: The host outlives this.unsafe { (self.0.cancel_timer)(self.0.host, context_id.0, timer) };}++ /// Shapes the labels of the context's overlays, in fonts that the overlays' resources of the context then hold.+ pub fn overlay_label_shaper(&self, context_id: CompositorContextId) -> ContextOverlayLabelShaper<'_> {+ ContextOverlayLabelShaper { host: self, context_id }+ }+}++pub struct ContextOverlayLabelShaper<'a> {+ host: &'a Host,+ context_id: CompositorContextId,+}++impl OverlayLabelShaper for ContextOverlayLabelShaper<'_> {+ fn shape_overlay_label(+ &self,+ font_family: Option<&str>,+ device_pixel_ratio: f64,+ text: &str,+ ) -> Option<OverlayLabel> {+ unsafe extern "C" fn receive(receiver: *mut c_void, label: *const FfiOverlayLabel<'_>) {+ // SAFETY: The receiver is the label below, and the host lends the shaped label for the call.+ let (receiver, label) = unsafe { (&mut *receiver.cast::<Option<OverlayLabel>>(), &*label) };+ *receiver = Some(OverlayLabel {+ font_id: label.font_id,+ glyph_ids: label.glyph_ids.as_slice().to_vec(),+ glyph_x_positions: label.glyph_x_positions.as_slice().to_vec(),+ width: label.width,+ ascent: label.ascent,+ descent: label.descent,+ font_ascent: label.font_ascent,+ });+ }+ let mut label: Option<OverlayLabel> = None;+ // SAFETY: The host outlives this, shapes synchronously and never calls back into the core.+ unsafe {+ (self.host.0.shape_overlay_label)(+ self.host.0.host,+ self.context_id.0,+ font_family.is_some(),+ ak::Span::new(font_family.unwrap_or_default().as_bytes()),+ device_pixel_ratio,+ ak::Span::new(text.as_bytes()),+ (&raw mut label).cast(),+ receive,+ );+ }+ label+ }}diff --git a/Services/Compositor/Rust/src/lib.rs b/Services/Compositor/Rust/src/lib.rsindex 82a381ea729..f21635d3042 100644--- a/Services/Compositor/Rust/src/lib.rs+++ b/Services/Compositor/Rust/src/lib.rs@@ -26,6 +26,7 @@ pub mod host;pub mod input_event;pub mod keyboard_scroll_controller;pub mod layers;+pub mod overlays;pub mod scroll_fling_controller;pub mod scroll_snap_controller;pub mod scrollbar_controller;diff --git a/Services/Compositor/Rust/src/overlays.rs b/Services/Compositor/Rust/src/overlays.rsnew file mode 100644index 00000000000..595ca8e1982--- /dev/null+++ b/Services/Compositor/Rust/src/overlays.rs@@ -0,0 +1,849 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! What the compositor draws over the page of a context: the scrollbars it paints itself, and the overlays the browser+//! asks for. They are recorded as display list records and played through the same painter as the page.++use crate::frame_inputs::ScrollbarOfFrame;+use libcompositing_rust::display_list::builder::{DisplayListBuilder, HEADER_SIZE, PendingInlineClip};+use libcompositing_rust::display_list::commands::{+ ContextRef, DisplayListCommand, DisplayListDataSpan, DisplayListGlyph, DisplayListPaintStyle, DrawGlyphRun,+ FillPath, FillRect, FontResourceId, OptionalFloatRect, PathPaintKind, ReplayLayer, StrokePath,+};+use libcompositing_rust::display_list::ffi_bytes::FfiBytes;+use libcompositing_rust::display_list::replay::{+ ListReplay, NoNestedDisplayLists, RecordsContext, ReplayFrame, ReplayPainter, replay_records,+};+use libcompositing_rust::host::PresentedScrollbar;+use libcompositing_rust::overlays::{+ PausedDebuggerOverlayGeometry, paused_debugger_overlay_geometry, picture_in_picture_controls_geometry,+ scaled_overlay_length,+};+use libcompositing_rust::scrolling::overlay_fade::OverlayFade;+use libcompositing_rust::time::MonotonicTime;+use libcompositing_rust::visual_context::{TransformData, TransformDataRole, VisualContextTree};+use libgfx_rust::path::Path;+use libgfx_rust::{+ CapStyle, Color, CompositingAndBlendingOperator, FloatMatrix4x4, FloatPoint, FloatRect, IntRect, IntSize,+ JoinStyle, Orientation, ShouldAntiAlias, WindingRule, enclosing_int_rect,+};++#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum PausedDebuggerOverlayAction {+ StepOver,+ Continue,+}++#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum PictureInPictureControl {+ BackToTab,+ Close,+}++#[derive(Clone, Debug, Default, PartialEq)]+pub struct PausedDebuggerOverlayState {+ pub font_family: Option<String>,+ pub hovered_action: Option<PausedDebuggerOverlayAction>,+}++// The controls stay present while they are hidden, so that they fade out.+#[derive(Clone, Copy, Debug, Default, PartialEq)]+pub struct PictureInPictureControlsState {+ pub shown: bool,+ pub hovered_control: Option<PictureInPictureControl>,+}++// What the browser draws over a context's page, with each overlay the view has present.+#[derive(Clone, Debug, Default, PartialEq)]+pub struct UIOverlays {+ pub paused_debugger: Option<PausedDebuggerOverlayState>,+ pub picture_in_picture_controls: Option<PictureInPictureControlsState>,+}++/// A label of an overlay as the host shapes it: the font it resolved, in the overlays' resources, and where each glyph+/// goes along the line, in device pixels.+#[derive(Clone, Debug, PartialEq)]+pub struct OverlayLabel {+ pub font_id: u64,+ pub glyph_ids: Vec<u32>,+ pub glyph_x_positions: Vec<f32>,+ pub width: f32,+ // Of the font at the size the label is shaped at: the ascent above the baseline, which is negative, and the descent.+ pub ascent: f32,+ pub descent: f32,+ // The ascent the painter places glyphs below, at the font's own size.+ pub font_ascent: f32,+}++/// Shapes the label of an overlay, in the font family given or the default one, at a device pixel ratio.+pub trait OverlayLabelShaper {+ fn shape_overlay_label(+ &self,+ font_family: Option<&str>,+ device_pixel_ratio: f64,+ text: &str,+ ) -> Option<OverlayLabel>;+}++const PAUSED_DEBUGGER_LABEL: &str = "Paused in debugger";++#[derive(Default)]+pub struct ContextOverlays {+ ui_overlays: UIOverlays,+ picture_in_picture_controls_fade: OverlayFade,+ // The label of the paused debugger overlay, for the font family and device pixel ratio it was shaped for.+ paused_debugger_label: Option<(Option<String>, f64, Option<OverlayLabel>)>,+}++impl ContextOverlays {+ pub fn ui_overlays(&self) -> &UIOverlays {+ &self.ui_overlays+ }++ /// Returns false, changing nothing, for the overlays already shown.+ pub fn set_ui_overlays(&mut self, ui_overlays: UIOverlays, now: MonotonicTime) -> bool {+ if self.ui_overlays == ui_overlays {+ return false;+ }+ self.ui_overlays = ui_overlays;+ let shows_picture_in_picture_controls = self+ .ui_overlays+ .picture_in_picture_controls+ .is_some_and(|controls| controls.shown);+ self.picture_in_picture_controls_fade+ .fade_to(if shows_picture_in_picture_controls { 1.0 } else { 0.0 }, now);+ true+ }++ pub fn fades_need_frame(&self) -> bool {+ self.picture_in_picture_controls_fade.is_fading()+ }++ /// Advances the fades to a frame, answering what of the viewport they repaint.+ pub fn advance_fades(+ &mut self,+ frame_time: MonotonicTime,+ viewport_size: IntSize,+ device_pixel_ratio: f64,+ ) -> Option<IntRect> {+ if !self.picture_in_picture_controls_fade.advance_to(frame_time) {+ return None;+ }+ Some(picture_in_picture_controls_geometry(viewport_size, device_pixel_ratio).buttons_bounds())+ }++ /// What the overlays draw over a frame of the page, with the scrollbars the frame shows.+ pub fn picture_of_frame(+ &mut self,+ scrollbars: &[ScrollbarOfFrame],+ viewport_size: IntSize,+ device_pixel_ratio: f64,+ label_shaper: &dyn OverlayLabelShaper,+ ) -> OverlayPicture {+ let viewport_rect = IntRect::new(0, 0, viewport_size.width, viewport_size.height);+ let mut bounds = IntRect::default();+ let mut presented_scrollbars = Vec::new();+ for scrollbar in scrollbars.iter().filter(|scrollbar| scrollbar.is_painted_by_compositor) {+ presented_scrollbars.push(presented_compositor_scrollbar(scrollbar));+ if scrollbar.opacity <= 0.0 {+ continue;+ }+ // The thumb's outline is drawn around the gutter, which grows into the expanded gutter as it is hovered.+ bounds = bounds.united(+ enclosing_int_rect(scrollbar.gutter_rect)+ .united(scrollbar.thin_and_expanded_gutter_rect)+ .inflated(2, 2),+ );+ }++ let mut ui_overlay_records = DisplayListBuilder::new();+ if let Some(paused_debugger) = self.ui_overlays.paused_debugger.clone() {+ let label = self.paused_debugger_label(&paused_debugger, device_pixel_ratio, label_shaper);+ record_paused_debugger_overlay(+ &mut ui_overlay_records,+ viewport_size,+ device_pixel_ratio,+ &paused_debugger,+ label,+ );+ }++ let mut picture_in_picture_controls = None;+ let opacity = self.picture_in_picture_controls_fade.opacity();+ if let Some(controls) = &self.ui_overlays.picture_in_picture_controls+ && opacity > 0.0+ {+ let mut records = DisplayListBuilder::new();+ let controls_bounds =+ record_picture_in_picture_controls(&mut records, viewport_size, device_pixel_ratio, controls);+ picture_in_picture_controls = Some(PictureInPictureControlsPicture {+ opacity,+ bounds: controls_bounds,+ records: AlignedRecords::new(&records.finish().bytes),+ });+ }++ if self.ui_overlays.paused_debugger.is_some() || picture_in_picture_controls.is_some() {+ bounds = viewport_rect;+ }+ OverlayPicture {+ scrollbars: presented_scrollbars,+ ui_overlay_records: AlignedRecords::new(&ui_overlay_records.finish().bytes),+ picture_in_picture_controls,+ bounds: bounds.intersected(viewport_rect),+ }+ }++ fn paused_debugger_label(+ &mut self,+ paused_debugger: &PausedDebuggerOverlayState,+ device_pixel_ratio: f64,+ label_shaper: &dyn OverlayLabelShaper,+ ) -> Option<&OverlayLabel> {+ let is_cached = self+ .paused_debugger_label+ .as_ref()+ .is_some_and(|(font_family, ratio, _)| {+ *font_family == paused_debugger.font_family && *ratio == device_pixel_ratio+ });+ if !is_cached {+ let label = label_shaper.shape_overlay_label(+ paused_debugger.font_family.as_deref(),+ device_pixel_ratio,+ PAUSED_DEBUGGER_LABEL,+ );+ self.paused_debugger_label = Some((paused_debugger.font_family.clone(), device_pixel_ratio, label));+ }+ self.paused_debugger_label+ .as_ref()+ .and_then(|(_, _, label)| label.as_ref())+ }+}++// Records in memory aligned for every command and payload object they hold, which the painter checks and a Vec<u8>+// does not promise.+struct AlignedRecords {+ words: Vec<u64>,+ size: usize,+}++impl AlignedRecords {+ fn new(bytes: &[u8]) -> Self {+ let mut words = vec![0u64; bytes.len().div_ceil(8)];+ for (word, chunk) in words.iter_mut().zip(bytes.chunks(8)) {+ let mut word_bytes = [0u8; 8];+ word_bytes[..chunk.len()].copy_from_slice(chunk);+ *word = u64::from_ne_bytes(word_bytes);+ }+ Self {+ words,+ size: bytes.len(),+ }+ }++ fn as_bytes(&self) -> &[u8] {+ // SAFETY: The words hold `size` initialized bytes.+ unsafe { ak::slice_from_raw_parts(self.words.as_ptr().cast(), self.size) }+ }+}++struct PictureInPictureControlsPicture {+ opacity: f32,+ bounds: IntRect,+ records: AlignedRecords,+}++/// What the overlays draw over one frame, in the order they are drawn, and the part of the viewport they cover.+pub struct OverlayPicture {+ scrollbars: Vec<PresentedScrollbar>,+ ui_overlay_records: AlignedRecords,+ picture_in_picture_controls: Option<PictureInPictureControlsPicture>,+ pub bounds: IntRect,+}++thread_local! {+ // The overlays are recorded in the space of the viewport, which no node of a tree transforms.+ static OVERLAY_TREE: VisualContextTree = VisualContextTree::create(TransformData {+ matrix: FloatMatrix4x4::identity(),+ origin: FloatPoint::default(),+ sorting_context_root_index: None,+ flattens_inherited_transform: false,+ role: TransformDataRole::CssTransform,+ synthetic_plane: false,+ establishes_sorting_context: false,+ bounds: FloatRect::default(),+ });+}++impl OverlayPicture {+ /// Paints the overlays over a frame: the scrollbars the compositor paints, and unless they are left out, the+ /// overlays of the browser.+ pub fn paint(&self, painter: &mut impl ReplayPainter, paints_ui_overlays: bool) {+ for scrollbar in &self.scrollbars {+ painter.paint_scrollbar(scrollbar);+ }+ if !paints_ui_overlays {+ return;+ }+ OVERLAY_TREE.with(|tree| {+ let list = ListReplay::new(tree);+ let frame = ReplayFrame::unscrolled(0, &NoNestedDisplayLists);+ let context = RecordsContext {+ list: &list,+ frame: &frame,+ clip_space_matrix: &|_| None,+ };+ replay_records(self.ui_overlay_records.as_bytes(), &context, painter);+ if let Some(controls) = &self.picture_in_picture_controls {+ painter.push_layer(&ReplayLayer {+ opacity: controls.opacity,+ blend_mode: CompositingAndBlendingOperator::Normal,+ filter_bytes: std::ptr::null(),+ filter_bytes_size: 0,+ backdrop_filter_bytes: std::ptr::null(),+ backdrop_filter_bytes_size: 0,+ backdrop_region: IntRect::default(),+ backdrop_corner_radii: Default::default(),+ backdrop_base_color: Color::TRANSPARENT,+ backdrop_blur_edge: OptionalFloatRect::none(),+ filter_cache_key: 0,+ content_bounds: OptionalFloatRect::from(Some(controls.bounds.to_float())),+ });+ replay_records(controls.records.as_bytes(), &context, painter);+ painter.pop();+ }+ });+ }+}++fn presented_compositor_scrollbar(scrollbar: &ScrollbarOfFrame) -> PresentedScrollbar {+ libcompositing_rust::display_list::replay::presented_scrollbar_with_colors(+ scrollbar.gutter_rect,+ scrollbar.thumb_rect,+ scrollbar.expansion,+ scrollbar.opacity,+ scrollbar.thumb_color,+ scrollbar.thumb_outline_color,+ scrollbar.track_color,+ )+}++// The records of one overlay, with the payload of each command laid out after the command as the painter reads it.+struct OverlayRecorder<'a> {+ builder: &'a mut DisplayListBuilder,+}++impl OverlayRecorder<'_> {+ fn append<C: DisplayListCommand>(&mut self, command: &C, inline_data: &[u8]) {+ self.builder.append(command, inline_data, ContextRef::default());+ }++ // The span of `data` placed after a command of type `C`, at an offset aligned for the data, with the padding+ // that takes put in front of it.+ fn data_after_command<C: DisplayListCommand>(+ &self,+ data: &[u8],+ alignment: usize,+ ) -> (DisplayListDataSpan, Vec<u8>) {+ let payload_start = self.builder.byte_size() + HEADER_SIZE;+ let command_end = payload_start + std::mem::size_of::<C>();+ let padding = command_end.next_multiple_of(alignment) - command_end;+ let mut inline_data = vec![0u8; padding];+ inline_data.extend_from_slice(data);+ let span = DisplayListDataSpan {+ offset: (std::mem::size_of::<C>() + padding) as u32,+ size: data.len() as u32,+ };+ (span, inline_data)+ }++ fn fill_rect(&mut self, rect: IntRect, color: Color) {+ self.append(+ &FillRect {+ rect,+ color,+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,+ background_color_animation_effect: libcompositing_rust::display_list::commands::EffectNodeIndex::NONE,+ },+ &[],+ );+ }++ fn fill_rect_clipped_to(&mut self, rect: IntRect, color: Color, clip: &Path) {+ self.builder.append_with_inline_clips(+ &FillRect {+ rect,+ color,+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,+ background_color_animation_effect: libcompositing_rust::display_list::commands::EffectNodeIndex::NONE,+ },+ &[],+ ContextRef::default(),+ &[PendingInlineClip::intersecting_path(clip, WindingRule::Nonzero)],+ );+ }++ fn fill_path(&mut self, path: &Path, color: Color) {+ let path_bounding_rect = FloatRect::from_array(path.bounding_box());+ if path_bounding_rect.is_empty() {+ return;+ }+ let (path_data, inline_data) =+ self.data_after_command::<FillPath>(&path.serialize_to_bytes(), std::mem::align_of::<u32>());+ self.append(+ &FillPath {+ path_bounding_rect,+ path_data,+ opacity: 1.0,+ paint_kind: PathPaintKind::Color,+ color,+ paint_style: DisplayListPaintStyle::default(),+ winding_rule: WindingRule::Nonzero,+ should_anti_alias: ShouldAntiAlias::Yes,+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,+ },+ &inline_data,+ );+ }++ fn stroke_path(&mut self, path: &Path, color: Color, thickness: f32, cap_style: CapStyle, join_style: JoinStyle) {+ let path_bounding_rect = FloatRect::from_array(path.bounding_box()).inflated(thickness, thickness);+ if path_bounding_rect.is_empty() {+ return;+ }+ let (path_data, inline_data) =+ self.data_after_command::<StrokePath>(&path.serialize_to_bytes(), std::mem::align_of::<u32>());+ self.append(+ &StrokePath {+ cap_style,+ join_style,+ miter_limit: 4.0,+ dash_array: DisplayListDataSpan::default(),+ dash_offset: 0.0,+ path_bounding_rect,+ path_data,+ opacity: 1.0,+ paint_kind: PathPaintKind::Color,+ color,+ paint_style: DisplayListPaintStyle::default(),+ thickness,+ should_anti_alias: ShouldAntiAlias::Yes,+ },+ &inline_data,+ );+ }++ fn draw_label(&mut self, label: &OverlayLabel, baseline_origin: FloatPoint, color: Color, scale: f32) {+ if label.glyph_ids.is_empty() {+ return;+ }+ let glyphs: Vec<DisplayListGlyph> = label+ .glyph_ids+ .iter()+ .zip(&label.glyph_x_positions)+ .map(|(glyph_id, x)| DisplayListGlyph {+ position: FloatPoint {+ x: (baseline_origin.x + x) / scale,+ y: baseline_origin.y / scale - label.font_ascent,+ },+ glyph_id: *glyph_id,+ })+ .collect();+ let mut glyph_bytes = vec![0u8; glyphs.len() * std::mem::size_of::<DisplayListGlyph>()];+ for (index, glyph) in glyphs.iter().enumerate() {+ let start = index * std::mem::size_of::<DisplayListGlyph>();+ glyph.write_ffi_bytes(&mut glyph_bytes[start..start + std::mem::size_of::<DisplayListGlyph>()]);+ }+ let (glyph_span, inline_data) =+ self.data_after_command::<DrawGlyphRun>(&glyph_bytes, std::mem::align_of::<DisplayListGlyph>());+ let rect = enclosing_int_rect(FloatRect::new(+ baseline_origin.x,+ baseline_origin.y + label.ascent,+ label.width,+ label.descent - label.ascent,+ ))+ .inflated(2, 2);+ self.append(+ &DrawGlyphRun {+ stroke_width: 0.0,+ font_id: FontResourceId(label.font_id),+ glyphs: glyph_span,+ rect,+ glyph_bounding_rect: rect,+ translation: FloatPoint::default(),+ scale,+ color,+ orientation: Orientation::Horizontal,+ font_smoothing: 0,+ },+ &inline_data,+ );+ }+}++fn rounded_rect_path(rect: FloatRect, radius: f32) -> Path {+ let radius = radius.min(rect.width / 2.0).min(rect.height / 2.0);+ let (left, top, right, bottom) = (rect.x, rect.y, rect.right(), rect.bottom());+ let mut path = Path::new();+ path.move_to(FloatPoint {+ x: left + radius,+ y: top,+ });+ path.line_to(FloatPoint {+ x: right - radius,+ y: top,+ });+ path.arc_to(+ FloatPoint {+ x: right,+ y: top + radius,+ },+ radius,+ false,+ true,+ );+ path.line_to(FloatPoint {+ x: right,+ y: bottom - radius,+ });+ path.arc_to(+ FloatPoint {+ x: right - radius,+ y: bottom,+ },+ radius,+ false,+ true,+ );+ path.line_to(FloatPoint {+ x: left + radius,+ y: bottom,+ });+ path.arc_to(+ FloatPoint {+ x: left,+ y: bottom - radius,+ },+ radius,+ false,+ true,+ );+ path.line_to(FloatPoint {+ x: left,+ y: top + radius,+ });+ path.arc_to(+ FloatPoint {+ x: left + radius,+ y: top,+ },+ radius,+ false,+ true,+ );+ path.close();+ path+}++fn circle_path(center: FloatPoint, radius: f32) -> Path {+ let mut path = Path::new();+ path.move_to(FloatPoint {+ x: center.x + radius,+ y: center.y,+ });+ path.arc_to(+ FloatPoint {+ x: center.x - radius,+ y: center.y,+ },+ radius,+ false,+ true,+ );+ path.arc_to(+ FloatPoint {+ x: center.x + radius,+ y: center.y,+ },+ radius,+ false,+ true,+ );+ path.close();+ path+}++fn rect_center(rect: IntRect) -> FloatPoint {+ // An odd size centers on the pixel below and to the right of the middle, as the integer rects of the painter do.+ FloatPoint {+ x: (rect.x + rect.width / 2) as f32,+ y: (rect.y + rect.height / 2) as f32,+ }+}++// These colors are equivalent to those produced by UI/Qt/ChromeStyle.cpp in light mode. The compositor cannot use+// those colors directly because it does not depend on Qt, so their resolved values are copied here.+const DEBUGGER_OVERLAY_COLOR: Color = Color::from_rgba(0xee, 0xee, 0xef, 168);+const DEBUGGER_TOOLBAR_COLOR: Color = Color::from_rgba(0xff, 0xff, 0xff, 255);+const DEBUGGER_TOOLBAR_BORDER_COLOR: Color = Color::from_rgba(0xce, 0xce, 0xcf, 255);+const DEBUGGER_BUTTON_HOVER_COLOR: Color = Color::from_rgba(0xf1, 0xf1, 0xf2, 255);+const DEBUGGER_TEXT_COLOR: Color = Color::from_rgba(0x18, 0x1d, 0x24, 255);+const DEBUGGER_SHADOW_COLOR: Color = Color::from_rgba(0x18, 0x1d, 0x24, 66);++fn record_paused_debugger_overlay(+ builder: &mut DisplayListBuilder,+ viewport_size: IntSize,+ device_pixel_ratio: f64,+ state: &PausedDebuggerOverlayState,+ label: Option<&OverlayLabel>,+) {+ let mut recorder = OverlayRecorder { builder };+ let geometry: PausedDebuggerOverlayGeometry = paused_debugger_overlay_geometry(viewport_size, device_pixel_ratio);+ let radius = 1.0f32.max((4.0 * device_pixel_ratio) as f32);++ recorder.fill_rect(+ IntRect::new(0, 0, viewport_size.width, viewport_size.height),+ DEBUGGER_OVERLAY_COLOR,+ );++ let mut shadow_rect = geometry.toolbar;+ shadow_rect.y += scaled_overlay_length(2, device_pixel_ratio);+ recorder.fill_path(+ &rounded_rect_path(shadow_rect.to_float(), radius),+ DEBUGGER_SHADOW_COLOR,+ );++ let toolbar_path = rounded_rect_path(geometry.toolbar.to_float(), radius);+ recorder.fill_path(&toolbar_path, DEBUGGER_TOOLBAR_COLOR);++ if let Some(hovered_action) = state.hovered_action {+ let hovered_button = match hovered_action {+ PausedDebuggerOverlayAction::StepOver => geometry.step_over_button,+ PausedDebuggerOverlayAction::Continue => geometry.continue_button,+ };+ recorder.fill_rect_clipped_to(hovered_button, DEBUGGER_BUTTON_HOVER_COLOR, &toolbar_path);+ }++ let line_thickness = 1.0f64.max(device_pixel_ratio) as f32;+ recorder.stroke_path(+ &toolbar_path,+ DEBUGGER_TOOLBAR_BORDER_COLOR,+ line_thickness,+ CapStyle::Butt,+ JoinStyle::Miter,+ );++ let divider_inset = scaled_overlay_length(10, device_pixel_ratio) as f32;+ let divider_x = geometry.step_over_button.x as f32;+ let mut divider = Path::new();+ divider.move_to(FloatPoint {+ x: divider_x,+ y: geometry.toolbar.y as f32 + divider_inset,+ });+ divider.line_to(FloatPoint {+ x: divider_x,+ y: geometry.toolbar.bottom() as f32 - divider_inset,+ });+ recorder.stroke_path(+ ÷r,+ DEBUGGER_TOOLBAR_BORDER_COLOR,+ line_thickness,+ CapStyle::Butt,+ JoinStyle::Miter,+ );++ if let Some(label) = label {+ let message = geometry.message;+ let label_x = message.x as f32 + (message.width as f32 - label.width) / 2.0;+ let label_y = rect_center(message).y - (label.ascent + label.descent) / 2.0;+ recorder.draw_label(+ label,+ FloatPoint { x: label_x, y: label_y },+ DEBUGGER_TEXT_COLOR,+ device_pixel_ratio as f32,+ );+ }++ let icon_size = 8.0f64.max(16.0 * device_pixel_ratio) as f32;++ // Step over: an arc over a dot, with an arrow at its end.+ let center = rect_center(geometry.step_over_button);+ let left = center.x - icon_size / 2.0;+ let top = center.y - icon_size / 2.0;+ let right = center.x + icon_size / 2.0;+ let mut arc = Path::new();+ arc.move_to(FloatPoint {+ x: left + icon_size / 8.0,+ y: top + icon_size * 0.55,+ });+ arc.cubic_bezier_curve_to(+ FloatPoint {+ x: left + icon_size / 8.0,+ y: top + icon_size * 0.15,+ },+ FloatPoint {+ x: right - icon_size / 5.0,+ y: top + icon_size * 0.15,+ },+ FloatPoint {+ x: right - icon_size / 5.0,+ y: top + icon_size * 0.55,+ },+ );+ recorder.stroke_path(+ &arc,+ DEBUGGER_TEXT_COLOR,+ line_thickness,+ CapStyle::Round,+ JoinStyle::Round,+ );+ let arrow_width = icon_size / 2.5;+ let mut arrow = Path::new();+ arrow.move_to(FloatPoint {+ x: right - arrow_width,+ y: top + icon_size * 0.55,+ });+ arrow.line_to(FloatPoint {+ x: right,+ y: top + icon_size * 0.55,+ });+ arrow.line_to(FloatPoint {+ x: right - arrow_width / 2.0,+ y: top + icon_size * 0.8,+ });+ arrow.close();+ recorder.fill_path(&arrow, DEBUGGER_TEXT_COLOR);+ let dot_size = 2.0f32.max(line_thickness * 2.0);+ recorder.fill_path(+ &circle_path(+ FloatPoint {+ x: center.x,+ y: center.y + icon_size / 3.0,+ },+ dot_size / 2.0,+ ),+ DEBUGGER_TEXT_COLOR,+ );++ // Continue: a triangle pointing along the line.+ let center = rect_center(geometry.continue_button);+ let icon_left = center.x - icon_size / 2.0;+ let icon_top = center.y - icon_size / 2.0;+ let mut triangle = Path::new();+ triangle.move_to(FloatPoint {+ x: icon_left + icon_size / 4.0,+ y: icon_top + icon_size / 8.0,+ });+ triangle.line_to(FloatPoint {+ x: icon_left + icon_size / 4.0,+ y: icon_top + icon_size - icon_size / 8.0,+ });+ triangle.line_to(FloatPoint {+ x: icon_left + icon_size - icon_size / 8.0,+ y: icon_top + icon_size / 2.0,+ });+ triangle.close();+ recorder.fill_path(&triangle, DEBUGGER_TEXT_COLOR);+}++// A step of an icon's outline, on its grid of 16 units.+#[derive(Clone, Copy)]+enum IconStep {+ Move(f32, f32),+ Line(f32, f32),+ Quadratic(f32, f32, f32, f32),+}++const PICTURE_IN_PICTURE_BUTTON_COLOR: Color = Color::from_rgba(0, 0, 0, 115);+const PICTURE_IN_PICTURE_ICON_COLOR: Color = Color::from_rgba(0xff, 0xff, 0xff, 255);+const PICTURE_IN_PICTURE_HOVERED_ICON_COLOR: Color = Color::from_rgba(0xe0, 0xd4, 0xff, 255);++// Records the controls, answering the rect that holds them.+fn record_picture_in_picture_controls(+ builder: &mut DisplayListBuilder,+ viewport_size: IntSize,+ device_pixel_ratio: f64,+ state: &PictureInPictureControlsState,+) -> IntRect {+ let mut recorder = OverlayRecorder { builder };+ let geometry = picture_in_picture_controls_geometry(viewport_size, device_pixel_ratio);++ // The icons are stroked on a grid of 16 units, and drawn at the given size in points.+ let mut record_button =+ |button: IntRect, control: PictureInPictureControl, icon: &[IconStep], icon_points: f32, stroke_units: f32| {+ let center = FloatPoint {+ x: button.x as f32 + button.width as f32 / 2.0,+ y: button.y as f32 + button.height as f32 / 2.0,+ };+ recorder.fill_path(+ &circle_path(center, button.width as f32 / 2.0),+ PICTURE_IN_PICTURE_BUTTON_COLOR,+ );++ let icon_size = icon_points * device_pixel_ratio as f32;+ let unit = icon_size / 16.0;+ let at = |x: f32, y: f32| FloatPoint {+ x: center.x - icon_size / 2.0 + x * unit,+ y: center.y - icon_size / 2.0 + y * unit,+ };+ let mut path = Path::new();+ for step in icon {+ match *step {+ IconStep::Move(x, y) => path.move_to(at(x, y)),+ IconStep::Line(x, y) => path.line_to(at(x, y)),+ IconStep::Quadratic(control_x, control_y, x, y) => {+ path.quadratic_bezier_curve_to(at(control_x, control_y), at(x, y));+ }+ }+ }+ let color = if state.hovered_control == Some(control) {+ PICTURE_IN_PICTURE_HOVERED_ICON_COLOR+ } else {+ PICTURE_IN_PICTURE_ICON_COLOR+ };+ recorder.stroke_path(&path, color, stroke_units * unit, CapStyle::Round, JoinStyle::Round);+ };++ // An arrow out of a box, toward its top right corner.+ let back_to_tab_icon = [+ IconStep::Move(9.5, 2.5),+ IconStep::Line(13.5, 2.5),+ IconStep::Line(13.5, 6.5),+ IconStep::Move(13.5, 2.5),+ IconStep::Line(8.0, 8.0),+ IconStep::Move(12.0, 9.5),+ IconStep::Line(12.0, 12.5),+ IconStep::Quadratic(12.0, 13.5, 11.0, 13.5),+ IconStep::Line(3.5, 13.5),+ IconStep::Quadratic(2.5, 13.5, 2.5, 12.5),+ IconStep::Line(2.5, 5.0),+ IconStep::Quadratic(2.5, 4.0, 3.5, 4.0),+ IconStep::Line(6.5, 4.0),+ ];+ record_button(+ geometry.back_to_tab_button,+ PictureInPictureControl::BackToTab,+ &back_to_tab_icon,+ 14.0,+ 1.6,+ );++ let close_icon = [+ IconStep::Move(4.0, 4.0),+ IconStep::Line(12.0, 12.0),+ IconStep::Move(12.0, 4.0),+ IconStep::Line(4.0, 12.0),+ ];+ record_button(+ geometry.close_button,+ PictureInPictureControl::Close,+ &close_icon,+ 11.0,+ 2.0,+ );++ geometry.buttons_bounds()+}diff --git a/Tests/LibCompositing/CMakeLists.txt b/Tests/LibCompositing/CMakeLists.txtindex 8467077769d..cb95c2a5b82 100644--- a/Tests/LibCompositing/CMakeLists.txt+++ b/Tests/LibCompositing/CMakeLists.txt@@ -1,7 +1,6 @@ladybird_test_suite(LibCompositing)set(TEST_SOURCES- TestOverlayFade.cppTestOverlayGeometry.cppTestPausedDebuggerOverlay.cppTestPictureInPictureControls.cppdiff --git a/Tests/LibCompositing/TestOverlayFade.cpp b/Tests/LibCompositing/TestOverlayFade.cppdeleted file mode 100644index f7aae759307..00000000000--- a/Tests/LibCompositing/TestOverlayFade.cpp+++ /dev/null@@ -1,88 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibCompositing/OverlayFade.h>-#include <LibTest/TestCase.h>--using namespace Compositing;--static MonotonicTime after(MonotonicTime start, i64 milliseconds)-{- return start + AK::Duration::from_milliseconds(milliseconds);-}--TEST_CASE(a_fade_starts_transparent_and_at_rest)-{- OverlayFade fade;- EXPECT_EQ(fade.opacity(), 0.0f);- EXPECT(!fade.is_fading());-}--TEST_CASE(a_fade_eases_in_and_out_to_its_target)-{- auto start = MonotonicTime::now();- OverlayFade fade;- fade.fade_to(1, start);- EXPECT(fade.is_fading());-- EXPECT(!fade.advance_to(start));- EXPECT_EQ(fade.opacity(), 0.0f);-- EXPECT(fade.advance_to(after(start, 30)));- EXPECT_APPROXIMATE_WITH_ERROR(fade.opacity(), 0.104f, 0.0001f);-- fade.advance_to(after(start, 75));- EXPECT_APPROXIMATE(fade.opacity(), 0.5f);-- fade.advance_to(after(start, 150));- EXPECT_EQ(fade.opacity(), 1.0f);- EXPECT(!fade.is_fading());-- EXPECT(!fade.advance_to(after(start, 300)));- EXPECT_EQ(fade.opacity(), 1.0f);-}--TEST_CASE(a_fade_does_not_go_back_in_time)-{- auto start = MonotonicTime::now();- OverlayFade fade;- fade.fade_to(1, start);-- EXPECT(!fade.advance_to(after(start, -10)));- EXPECT_EQ(fade.opacity(), 0.0f);-}--TEST_CASE(a_fade_turns_back_from_where_it_has_reached)-{- auto start = MonotonicTime::now();- OverlayFade fade;- fade.fade_to(1, start);- fade.advance_to(after(start, 75));-- auto turned_at = after(start, 75);- fade.fade_to(0, turned_at);- EXPECT(!fade.advance_to(turned_at));- EXPECT_APPROXIMATE(fade.opacity(), 0.5f);-- fade.advance_to(after(turned_at, 75));- EXPECT_APPROXIMATE(fade.opacity(), 0.25f);-- fade.advance_to(after(turned_at, 150));- EXPECT_EQ(fade.opacity(), 0.0f);- EXPECT(!fade.is_fading());-}--TEST_CASE(fading_to_the_same_target_keeps_the_fade_going)-{- auto start = MonotonicTime::now();- OverlayFade fade;- fade.fade_to(1, start);- fade.advance_to(after(start, 75));-- fade.fade_to(1, after(start, 75));- fade.advance_to(after(start, 150));- EXPECT_EQ(fade.opacity(), 1.0f);-}