Truly independent web browser
Compositor: Keep what a frame is painted with in a header of its own
Aliaksandr Kalenikefe7ba7051be
diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cppindex ffb6eee83ff..8a6cfab730d 100644--- a/Services/Compositor/ContextPresenter.cpp+++ b/Services/Compositor/ContextPresenter.cpp@@ -10,7 +10,6 @@#include <Compositor/DisplayListPlayerSkia.h>#include <Compositor/PausedDebuggerOverlay.h>#include <Compositor/PictureInPictureControls.h>-#include <Compositor/ScrollbarController.h>#include <Compositor/SkiaUtils.h>#include <LibCompositing/DisplayList/DisplayListDamage.h>#include <LibCore/Timer.h>diff --git a/Services/Compositor/ContextPresenter.h b/Services/Compositor/ContextPresenter.hindex d1178ca7f60..0e0b5e12941 100644--- a/Services/Compositor/ContextPresenter.h+++ b/Services/Compositor/ContextPresenter.h@@ -19,8 +19,8 @@#include <Compositor/CompositorCoreHost.h>#include <Compositor/DisplayListRasterCache.h>#include <Compositor/Forward.h>+#include <Compositor/FrameInputs.h>#include <Compositor/PaintingSurface.h>-#include <Compositor/ScrollbarController.h>#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>@@ -50,14 +50,6 @@ struct PreparedFrame {double device_pixel_ratio { 1.0 };};-// What a frame is painted with besides the display list and its resources.-struct FrameInputs {- Compositing::AccumulatedVisualContextTree visual_context_tree;- Compositing::ScrollStateSnapshot presented_scroll_state_snapshot;- Vector<ScrollbarController::ScrollbarOfFrame> scrollbars;- Optional<Compositing::SpatialNodeIndex> viewport_scroll_node_index;-};-// Rasterizes the scene of a context into its backing stores and keeps track of the frames it presents.class ContextPresenter {AK_MAKE_NONCOPYABLE(ContextPresenter);diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cppindex 05b19e5463a..d161bd42e61 100644--- a/Services/Compositor/DisplayListPlayerSkia.cpp+++ b/Services/Compositor/DisplayListPlayerSkia.cpp@@ -72,7 +72,7 @@ void DisplayListPlayerSkia::execute(RefPtr<Gfx::PaintingSurface> surface,OwnedCanvasSurfaces const* canvas_surfaces,CompositedContextResolver const* composited_context_resolver,- ReadonlySpan<ScrollbarController::ScrollbarOfFrame> scrollbars_of_frame)+ ReadonlySpan<ScrollbarOfFrame> scrollbars_of_frame){TemporaryChange composited_context_resolver_change { m_composited_context_resolver, composited_context_resolver };TemporaryChange scrollbars_of_frame_change { m_scrollbars_of_frame, scrollbars_of_frame };@@ -159,7 +159,7 @@ static bool rect_is_pixel_aligned(SkRect const& rect)return rect.left() == roundf(rect.left()) && rect.top() == roundf(rect.top()) && rect.right() == roundf(rect.right()) && rect.bottom() == roundf(rect.bottom());}-static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, ScrollbarController::PresentedScrollbar const& scrollbar)+static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, PresentedScrollbar const& scrollbar){auto opacity = scrollbar.opacity;if (opacity <= 0)@@ -199,12 +199,12 @@ static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, Scrollbacanvas.drawRRect(thumb_rrect, stroke_paint);}-void DisplayListPlayerSkia::paint_scrollbars_painted_by_compositor(Gfx::PaintingSurface& surface, ReadonlySpan<ScrollbarController::ScrollbarOfFrame> scrollbars_of_frame)+void DisplayListPlayerSkia::paint_scrollbars_painted_by_compositor(Gfx::PaintingSurface& surface, ReadonlySpan<ScrollbarOfFrame> scrollbars_of_frame){for (auto const& scrollbar : scrollbars_of_frame) {if (!scrollbar.is_painted_by_compositor)continue;- paint_scrollbar_into_surface(surface, scrollbar.presented_with_colors(scrollbar.thumb_color, scrollbar.thumb_outline_color, scrollbar.track_color));+ paint_scrollbar_into_surface(surface, presented_scrollbar_with_colors(scrollbar, scrollbar.thumb_color, scrollbar.thumb_outline_color, scrollbar.track_color));}}@@ -1333,7 +1333,7 @@ void DisplayListPlayerSkia::play_command(PaintNestedDisplayList const& command)auto& canvas = surface().canvas();auto const& nested_display_list = resource_storage().display_list_resource(command.display_list_id);// The scrollbars of this context do not belong to the scroll nodes of a nested display list.- TemporaryChange<ReadonlySpan<ScrollbarController::ScrollbarOfFrame>> scrollbars_of_frame_change { m_scrollbars_of_frame, {} };+ TemporaryChange<ReadonlySpan<ScrollbarOfFrame>> scrollbars_of_frame_change { m_scrollbars_of_frame, {} };// Rasterize immutable nested lists (SVG images and masks) at list resolution and reuse their snapshots.// The first paint of a list rasterizes only the visible portion, so lists replaced every frame do not paint@@ -1479,13 +1479,13 @@ void DisplayListPlayerSkia::play_command(PaintScrollBar const& command)// colors are the ones the display list resolved for the page, which it may have darkened.for (auto const& scrollbar_of_frame : m_scrollbars_of_frame) {if (!scrollbar_of_frame.is_painted_by_compositor && scrollbar_of_frame.scroll_node_index == command.scroll_node_index && scrollbar_of_frame.vertical == command.vertical) {- paint_scrollbar_into_surface(surface(), scrollbar_of_frame.presented_with_colors(command.thumb_color, command.thumb_outline_color, command.track_color));+ paint_scrollbar_into_surface(surface(), presented_scrollbar_with_colors(scrollbar_of_frame, command.thumb_color, command.thumb_outline_color, command.track_color));return;}}- ScrollbarController::PresentedScrollbar scrollbar {+ PresentedScrollbar scrollbar {.gutter_rect = command.gutter_rect.to_type<float>(),- .thumb_rect = ScrollbarController::thumb_rect_kept_inside_track(command.thumb_rect, command.track_rect, command.vertical).to_type<float>(),+ .thumb_rect = thumb_rect_kept_inside_track(command.thumb_rect, command.track_rect, command.vertical).to_type<float>(),.thumb_color = command.thumb_color,.thumb_outline_color = command.thumb_outline_color,.track_color = command.track_color,diff --git a/Services/Compositor/DisplayListPlayerSkia.h b/Services/Compositor/DisplayListPlayerSkia.hindex 34dae681e51..21decaf2ee4 100644--- a/Services/Compositor/DisplayListPlayerSkia.h+++ b/Services/Compositor/DisplayListPlayerSkia.h@@ -14,7 +14,7 @@#include <Compositor/CompositedContext.h>#include <Compositor/DisplayListPlayer.h>#include <Compositor/Forward.h>-#include <Compositor/ScrollbarController.h>+#include <Compositor/FrameInputs.h>#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibGfx/Forward.h>@@ -52,11 +52,11 @@ public:RefPtr<Gfx::PaintingSurface>,OwnedCanvasSurfaces const*,CompositedContextResolver const*,- ReadonlySpan<ScrollbarController::ScrollbarOfFrame> = {});+ ReadonlySpan<ScrollbarOfFrame> = {});void flush(Gfx::PaintingSurface&) override;void flush_async(Gfx::PaintingSurface&, Function<void()>&&);- void paint_scrollbars_painted_by_compositor(Gfx::PaintingSurface&, ReadonlySpan<ScrollbarController::ScrollbarOfFrame>);+ void paint_scrollbars_painted_by_compositor(Gfx::PaintingSurface&, ReadonlySpan<ScrollbarOfFrame>);private:#define DECLARE_PLAY_COMMAND(command_type) \@@ -91,7 +91,7 @@ private:RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;CompositedContextResolver const* m_composited_context_resolver { nullptr };// Says how opaque the scrollbars that the display list paints are.- ReadonlySpan<ScrollbarController::ScrollbarOfFrame> m_scrollbars_of_frame;+ ReadonlySpan<ScrollbarOfFrame> m_scrollbars_of_frame;DisplayListRasterCache* m_raster_cache { nullptr };DisplayListRasterCache& raster_cache() const { return *m_raster_cache; }};diff --git a/Services/Compositor/FrameInputs.h b/Services/Compositor/FrameInputs.hnew file mode 100644index 00000000000..1bb34cd7d5d--- /dev/null+++ b/Services/Compositor/FrameInputs.h@@ -0,0 +1,82 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/Optional.h>+#include <AK/Vector.h>+#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>+#include <LibCompositing/Scrolling/ScrollState.h>+#include <LibGfx/Color.h>+#include <LibGfx/Rect.h>+#include <math.h>++namespace Compositor {++// A scrollbar as it is painted, somewhere between its thin and its expanded geometry.+struct PresentedScrollbar {+ Gfx::FloatRect gutter_rect;+ Gfx::FloatRect thumb_rect;+ Color thumb_color;+ Color thumb_outline_color;+ Color track_color;+ float opacity { 1 };+};++struct ScrollbarOfFrame {+ Compositing::SpatialNodeIndex scroll_node_index;+ bool vertical { false };+ bool is_painted_by_compositor { false };+ Gfx::FloatRect gutter_rect;+ Gfx::FloatRect thumb_rect;+ float expansion { 0 };+ float opacity { 1 };+ Color thumb_color;+ Color thumb_outline_color;+ Color track_color;+ Gfx::IntRect thin_and_expanded_gutter_rect;+};++// A scroll offset outside the scroll range moves the thumb past an end of its track, where it is cut short instead.+inline Gfx::IntRect thumb_rect_kept_inside_track(Gfx::IntRect thumb_rect, Gfx::IntRect const& track_rect, bool vertical)+{+ if (vertical) {+ auto top = max(thumb_rect.top(), track_rect.top());+ auto bottom = min(thumb_rect.bottom(), track_rect.bottom());+ thumb_rect.set_y(top);+ thumb_rect.set_height(max(0, bottom - top));+ } else {+ auto left = max(thumb_rect.left(), track_rect.left());+ auto right = min(thumb_rect.right(), track_rect.right());+ thumb_rect.set_x(left);+ thumb_rect.set_width(max(0, right - left));+ }+ return thumb_rect;+}++inline PresentedScrollbar presented_scrollbar_with_colors(ScrollbarOfFrame const& scrollbar, Color thumb_color, Color thumb_outline_color, Color track_color)+{+ // 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>(track_color.alpha()) * scrollbar.expansion);+ return PresentedScrollbar {+ .gutter_rect = scrollbar.gutter_rect,+ .thumb_rect = scrollbar.thumb_rect,+ .thumb_color = thumb_color,+ .thumb_outline_color = thumb_outline_color,+ .track_color = track_color.with_alpha(static_cast<u8>(track_alpha)),+ .opacity = scrollbar.opacity,+ };+}++// What a frame is painted with besides the display list and its resources.+struct FrameInputs {+ Compositing::AccumulatedVisualContextTree visual_context_tree;+ Compositing::ScrollStateSnapshot presented_scroll_state_snapshot;+ Vector<ScrollbarOfFrame> scrollbars;+ Optional<Compositing::SpatialNodeIndex> viewport_scroll_node_index;+};++}diff --git a/Services/Compositor/ScrollbarController.cpp b/Services/Compositor/ScrollbarController.cppindex ebfb1acb242..bf8cf42c61d 100644--- a/Services/Compositor/ScrollbarController.cpp+++ b/Services/Compositor/ScrollbarController.cpp@@ -416,22 +416,6 @@ Optional<Gfx::IntRect> ScrollbarController::rect_in_viewport(size_t scrollbar_inreturn Gfx::enclosing_int_rect(rect_in_viewport).inflated(2, 2);}-Gfx::IntRect ScrollbarController::thumb_rect_kept_inside_track(Gfx::IntRect thumb_rect, Gfx::IntRect const& track_rect, bool vertical)-{- if (vertical) {- auto top = max(thumb_rect.top(), track_rect.top());- auto bottom = min(thumb_rect.bottom(), track_rect.bottom());- thumb_rect.set_y(top);- thumb_rect.set_height(max(0, bottom - top));- } else {- auto left = max(thumb_rect.left(), track_rect.left());- auto right = min(thumb_rect.right(), track_rect.right());- thumb_rect.set_x(left);- thumb_rect.set_width(max(0, right - left));- }- return thumb_rect;-}-static Gfx::FloatRect interpolated_rect(Gfx::IntRect const& from, Gfx::IntRect const& to, float progress){auto interpolate = [progress](int from, int to) {@@ -445,7 +429,7 @@ static Gfx::FloatRect interpolated_rect(Gfx::IntRect const& from, Gfx::IntRect c};}-Vector<ScrollbarController::ScrollbarOfFrame> ScrollbarController::scrollbars_of_frame(Compositing::ScrollStateSnapshot const& scroll_state_snapshot) const+Vector<ScrollbarOfFrame> ScrollbarController::scrollbars_of_frame(Compositing::ScrollStateSnapshot const& scroll_state_snapshot) const{Vector<ScrollbarOfFrame> scrollbars_of_frame;scrollbars_of_frame.ensure_capacity(m_scrollbars.size());@@ -478,20 +462,6 @@ Vector<ScrollbarController::ScrollbarOfFrame> ScrollbarController::scrollbars_ofreturn scrollbars_of_frame;}-ScrollbarController::PresentedScrollbar ScrollbarController::ScrollbarOfFrame::presented_with_colors(Color thumb_color, Color thumb_outline_color, Color track_color) const-{- // 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>(track_color.alpha()) * expansion);- return PresentedScrollbar {- .gutter_rect = gutter_rect,- .thumb_rect = thumb_rect,- .thumb_color = thumb_color,- .thumb_outline_color = thumb_outline_color,- .track_color = track_color.with_alpha(static_cast<u8>(track_alpha)),- .opacity = opacity,- };-}-bool ScrollbarController::is_expanded(size_t scrollbar_index) const{return m_hovered_scrollbar_index == scrollbar_index || m_captured_scrollbar_index == scrollbar_index;diff --git a/Services/Compositor/ScrollbarController.h b/Services/Compositor/ScrollbarController.hindex bb62d15b380..00317d27d6a 100644--- a/Services/Compositor/ScrollbarController.h+++ b/Services/Compositor/ScrollbarController.h@@ -10,6 +10,7 @@#include <AK/Time.h>#include <AK/Vector.h>#include <Compositor/Forward.h>+#include <Compositor/FrameInputs.h>#include <LibCompositing/OverlayFade.h>#include <LibCompositing/Scrolling/AsyncScrollingState.h>#include <LibGfx/Color.h>@@ -47,35 +48,6 @@ public:Gfx::FloatPoint scroll_offset;};- // A scrollbar as it is painted, somewhere between its thin and its expanded geometry.- struct PresentedScrollbar {- Gfx::FloatRect gutter_rect;- Gfx::FloatRect thumb_rect;- Color thumb_color;- Color thumb_outline_color;- Color track_color;- float opacity { 1 };- };-- struct ScrollbarOfFrame {- Compositing::SpatialNodeIndex scroll_node_index;- bool vertical { false };- bool is_painted_by_compositor { false };- Gfx::FloatRect gutter_rect;- Gfx::FloatRect thumb_rect;- float expansion { 0 };- float opacity { 1 };- Color thumb_color;- Color thumb_outline_color;- Color track_color;- Gfx::IntRect thin_and_expanded_gutter_rect;-- PresentedScrollbar presented_with_colors(Color thumb_color, Color thumb_outline_color, Color track_color) const;- };-- // A scroll offset outside the scroll range moves the thumb past an end of its track, where it is cut short instead.- static Gfx::IntRect thumb_rect_kept_inside_track(Gfx::IntRect thumb_rect, Gfx::IntRect const& track_rect, bool vertical);-// Overlay scrollbars are hidden until their scroller scrolls. A scrollbar stays shown for this long after its// scroller last scrolled or the pointer left it, and then fades out.static constexpr auto shown_duration_after_activity = AK::Duration::from_milliseconds(1000);diff --git a/Tests/Compositor/TestScrollbarController.cpp b/Tests/Compositor/TestScrollbarController.cppindex 139e37013f8..b0ec7308aa3 100644--- a/Tests/Compositor/TestScrollbarController.cpp+++ b/Tests/Compositor/TestScrollbarController.cpp@@ -141,11 +141,11 @@ static Compositing::AsyncScrollbar scrollbar_painted_by_display_list()};}-static Compositor::ScrollbarController::PresentedScrollbar presented_scrollbar(Compositor::ScrollbarController const& controller, Compositing::ScrollStateSnapshot const& scroll_state_snapshot = {})+static Compositor::PresentedScrollbar presented_scrollbar(Compositor::ScrollbarController const& controller, Compositing::ScrollStateSnapshot const& scroll_state_snapshot = {}){for (auto const& scrollbar : controller.scrollbars_of_frame(scroll_state_snapshot)) {if (!scrollbar.is_painted_by_compositor && scrollbar.scroll_node_index == Compositing::SpatialNodeIndex { 1 } && scrollbar.vertical)- return scrollbar.presented_with_colors(Gfx::Color(0, 0, 0, 100), Gfx::Color(255, 255, 255, 64), Gfx::Color(0, 0, 0, 20));+ return Compositor::presented_scrollbar_with_colors(scrollbar, Gfx::Color(0, 0, 0, 100), Gfx::Color(255, 255, 255, 64), Gfx::Color(0, 0, 0, 20));}VERIFY_NOT_REACHED();}