Truly independent web browser
LibCompositing: Remove DisplayList
Aliaksandr Kalenik36d6e4da3fae
diff --git a/Libraries/LibCompositing/CMakeLists.txt b/Libraries/LibCompositing/CMakeLists.txtindex 703ce35e440..4d93d759ad6 100644--- a/Libraries/LibCompositing/CMakeLists.txt+++ b/Libraries/LibCompositing/CMakeLists.txt@@ -3,7 +3,6 @@ include(libcompositing_generators)set(SOURCESDisplayList/Canvas2DCommandStream.cppDisplayList/Canvas2DTape.cpp- DisplayList/DisplayList.cppDisplayList/DisplayListResourceStorage.cppDisplayList/DisplayListResourceTransaction.cppDisplayList/RustFFIAssertions.cpp@@ -102,7 +101,7 @@ if(NOT BUILD_SHARED_LIBS)# POST_BUILD steps don't track inputs, so the bridge files depend on the Rust archive: when it# changes, LibCompositing re-archives and the merge picks up the fresh objects.- foreach(bridge IN ITEMS DisplayList/DisplayList.cpp DisplayList/DisplayListResourceStorage.cpp DisplayList/VisualContextTreeTestBuilder.cpp Scrolling/SmoothScrollAnimation.cpp)+ foreach(bridge IN ITEMS DisplayList/DisplayListResourceStorage.cpp DisplayList/VisualContextTreeTestBuilder.cpp Scrolling/SmoothScrollAnimation.cpp)set_property(SOURCE ${bridge} APPEND PROPERTY OBJECT_DEPENDS ${_libcompositing_rust_lib})endforeach()endif()diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.cpp b/Libraries/LibCompositing/DisplayList/DisplayList.cppdeleted file mode 100644index 33e21ff1a02..00000000000--- a/Libraries/LibCompositing/DisplayList/DisplayList.cpp+++ /dev/null@@ -1,211 +0,0 @@-/*- * Copyright (c) 2024-2026, Aliaksandr Kalenik <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <AK/Atomic.h>-#include <AK/Function.h>-#include <AK/ScopeGuard.h>-#include <LibCompositing/DisplayList/DisplayList.h>-#include <LibCompositing/RustFFI.h>-#include <LibIPC/Decoder.h>-#include <LibIPC/Encoder.h>--namespace Compositing {--static Atomic<u64> s_next_id { 1 };--static u64 next_id()-{- return s_next_id.fetch_add(1, AK::MemoryOrder::memory_order_relaxed);-}--DisplayList::DisplayList(u64 compatible_visual_context_tree_structural_epoch, u64 id, void const* storage, Optional<Gfx::Color> surface_clear_color, Gfx::Color root_group_color, Optional<AsyncScrollingMetadata> async_scrolling_metadata)- : m_compatible_visual_context_tree_structural_epoch(compatible_visual_context_tree_structural_epoch)- , m_id(id)- , m_storage(storage)- , m_surface_clear_color(surface_clear_color)- , m_root_group_color(root_group_color)- , m_async_scrolling_metadata(move(async_scrolling_metadata))-{- VERIFY(m_storage);-}--DisplayList::~DisplayList()-{- RustFFI::display_list_storage_release(m_storage);-}--NonnullRefPtr<DisplayList> DisplayList::adopt_rust_storage(void const* retained_storage)-{- VERIFY(retained_storage);- return adopt_ref(*new DisplayList(RustFFI::display_list_storage_visual_context_tree_structural_epoch(retained_storage), next_id(), retained_storage, {}, Gfx::Color::Transparent, {}));-}--NonnullRefPtr<DisplayList> DisplayList::create_empty()-{- return adopt_rust_storage(RustFFI::display_list_storage_create_empty());-}--NonnullRefPtr<DisplayList> DisplayList::adopt_rust_recording(void const* retained_commands, void const* retained_visual_context_tree)-{- VERIFY(retained_commands);- VERIFY(retained_visual_context_tree);- return adopt_rust_storage(RustFFI::display_list_storage_adopt_recorded(retained_commands, retained_visual_context_tree));-}--NonnullRefPtr<DisplayList> DisplayList::share_rust_recording(void const* lent_commands, void const* lent_visual_context_tree)-{- VERIFY(lent_commands);- VERIFY(lent_visual_context_tree);- return adopt_rust_storage(RustFFI::display_list_storage_share_recorded(lent_commands, lent_visual_context_tree));-}--NonnullRefPtr<DisplayList> DisplayList::adopt_received_storage(DisplayListProperties properties, void const* storage)-{- return adopt_ref(*new DisplayList(properties.compatible_visual_context_tree_structural_epoch, properties.id, storage, properties.surface_clear_color, properties.root_group_color, {}));-}--// Copies a tape and run table that came from another process into Rust memory through `fill`, then checks them and-// returns the storage that holds them. Every later read of the tape is then sound.-static ErrorOr<void const*> receive_display_list_tape(u64 tape_size, u64 run_count, Function<ErrorOr<void>(Bytes tape, Bytes run_bytes)> const& fill)-{- auto pending = RustFFI::display_list_storage_begin(tape_size, run_count);- if (!pending.pending)- return Error::from_string_literal("Display list is too large to receive");- ArmedScopeGuard abandon_pending = [&] { RustFFI::display_list_storage_abandon(pending.pending); };- TRY(fill(Bytes { pending.tape, tape_size }, Bytes { pending.run_bytes, pending.run_bytes_size }));- abandon_pending.disarm();- u8 const* error = nullptr;- size_t error_size = 0;- auto const* storage = RustFFI::display_list_storage_finish(pending.pending, &error, &error_size);- if (!storage)- return Error::from_string_view({ error, error_size });- return storage;-}--DisplayList::ReferencedResourceIds DisplayList::referenced_resource_ids() const-{- auto ids = RustFFI::display_list_storage_referenced_resource_ids(m_storage);- return {- .fonts = { ids.font_ids, ids.font_id_count },- .image_frames = { ids.image_frame_ids, ids.image_frame_id_count },- .video_sinks = { ids.video_sink_ids, ids.video_sink_id_count },- .display_lists = { ids.display_list_ids, ids.display_list_id_count },- .canvases = { ids.canvas_ids, ids.canvas_id_count },- };-}--bool DisplayList::was_recorded_against(void const* lent_visual_context_tree) const-{- return RustFFI::display_list_storage_was_recorded_against(m_storage, lent_visual_context_tree);-}--ByteBuffer DisplayList::serialized_visual_context_tree() const-{- ByteBuffer bytes;- RustFFI::display_list_storage_serialize_visual_context_tree(m_storage, &bytes, [](void* sink, u8 const* data, size_t size) {- MUST(static_cast<ByteBuffer*>(sink)->try_append(data, size));- });- return bytes;-}--void DisplayList::for_each_visual_context_tree_filter_image_frame_id(Function<void(u64)> const& visit) const-{- struct ImageFrameIdVisitor {- Function<void(u64)> const& visit;- } visitor { visit };- RustFFI::display_list_storage_for_each_visual_context_tree_filter_image_frame_id(m_storage, &visitor, [](void* context, u64 image_frame_id) {- static_cast<ImageFrameIdVisitor*>(context)->visit(image_frame_id);- });-}--void DisplayList::replay(RustFFI::FfiRasterPainter const& painter, i64 time_nanoseconds) const-{- RustFFI::display_list_replay(m_storage, m_root_group_color, time_nanoseconds, &painter);-}--u64 DisplayList::tape_size() const-{- return RustFFI::display_list_storage_tape_size(m_storage);-}--u64 DisplayList::run_count() const-{- return RustFFI::display_list_storage_run_count(m_storage);-}--ErrorOr<Core::AnonymousBuffer> DisplayList::copy_to_shared_buffer() const-{- auto size = RustFFI::display_list_storage_packed_size(m_storage);- if (size == 0)- return Core::AnonymousBuffer {};- // Sealed where the platform supports it, so the receiver cannot be faulted by the file shrinking.- auto buffer = TRY(Core::AnonymousBuffer::create_with_size(size));- RustFFI::display_list_storage_write_packed(m_storage, buffer.data<u8>());- return buffer;-}--ErrorOr<NonnullRefPtr<DisplayList>> DisplayList::create_from_shared_buffer(DisplayListProperties properties, Core::AnonymousBuffer shared_tape_buffer, u64 tape_size, u64 run_count)-{- ReadonlyBytes packed;- if (shared_tape_buffer.is_valid()) {- TRY(shared_tape_buffer.validate_backing_size());- packed = shared_tape_buffer.bytes();- }- u8 const* error = nullptr;- size_t error_size = 0;- auto const* storage = RustFFI::display_list_storage_receive_packed(packed.data(), packed.size(), tape_size, run_count, &error, &error_size);- if (!storage)- return Error::from_string_view({ error, error_size });- return adopt_received_storage(move(properties), storage);-}--DisplayListProperties DisplayList::properties() const-{- return {- .id = m_id,- .compatible_visual_context_tree_structural_epoch = m_compatible_visual_context_tree_structural_epoch,- .surface_clear_color = m_surface_clear_color,- .root_group_color = m_root_group_color,- };-}--}--namespace IPC {--template<>-ErrorOr<void> encode(Encoder& encoder, Compositing::DisplayList const& display_list)-{- TRY(encoder.encode(display_list.properties()));- TRY(encoder.encode_size(display_list.tape_size()));- TRY(encoder.encode_size(display_list.run_count()));- auto packed = TRY(ByteBuffer::create_uninitialized(Compositing::RustFFI::display_list_storage_packed_size(display_list.rust_handle())));- Compositing::RustFFI::display_list_storage_write_packed(display_list.rust_handle(), packed.data());- TRY(encoder.append(packed.data(), packed.size()));- return {};-}--template<>-ErrorOr<void> encode(Encoder& encoder, NonnullRefPtr<Compositing::DisplayList> const& display_list)-{- return encoder.encode(*display_list);-}--template<>-ErrorOr<NonnullRefPtr<Compositing::DisplayList>> decode(Decoder& decoder)-{- auto properties = TRY(decoder.decode<Compositing::DisplayListProperties>());- auto tape_size = TRY(decoder.decode_size());- auto run_count = TRY(decoder.decode_size());- auto const* storage = TRY(Compositing::receive_display_list_tape(tape_size, run_count, [&](Bytes tape, Bytes run_bytes) -> ErrorOr<void> {- TRY(decoder.decode_into(tape));- TRY(decoder.decode_into(run_bytes));- return {};- }));- return Compositing::DisplayList::adopt_received_storage(move(properties), storage);-}--}diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.h b/Libraries/LibCompositing/DisplayList/DisplayList.hdeleted file mode 100644index b0dee725648..00000000000--- a/Libraries/LibCompositing/DisplayList/DisplayList.h+++ /dev/null@@ -1,131 +0,0 @@-/*- * Copyright (c) 2024-2026, Aliaksandr Kalenik <[email protected]>- * Copyright (c) 2025, Jelle Raaijmakers <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/AtomicRefCounted.h>-#include <AK/ByteBuffer.h>-#include <AK/Error.h>-#include <AK/Forward.h>-#include <AK/Function.h>-#include <AK/NonnullRefPtr.h>-#include <AK/Span.h>-#include <LibCompositing/DisplayList/DisplayListCommand.h>-#include <LibCompositing/DisplayList/DisplayListProperties.h>-#include <LibCompositing/Export.h>-#include <LibCompositing/Forward.h>-#include <LibCompositing/Types.h>-#include <LibCore/AnonymousBuffer.h>-#include <LibGfx/Color.h>-#include <LibGfx/Forward.h>-#include <LibIPC/Forward.h>--namespace Compositing {--namespace RustFFI {--struct FfiRasterPainter;--}--class COMPOSITING_API DisplayList : public AtomicRefCounted<DisplayList> {-public:- ~DisplayList();-- // An empty list, recorded against a visual context tree with no node but the visual viewport.- static NonnullRefPtr<DisplayList> create_empty();- // Adopts a strong reference to the Rust storage of a list recorded in this process, which holds the visual context- // tree the list was recorded against.- static NonnullRefPtr<DisplayList> adopt_rust_storage(void const* retained_storage);- // Adopts a strong reference to an immutable Rust recording, including its run table, and one to the visual context- // tree it was recorded against. Rust hands both over, and only Rust reads the tree.- static NonnullRefPtr<DisplayList> adopt_rust_recording(void const* retained_commands, void const* retained_visual_context_tree);- // Shares an immutable Rust recording, and the visual context tree it was recorded against, that Rust holds and- // lends for the call, taking a strong reference of its own to each.- static NonnullRefPtr<DisplayList> share_rust_recording(void const* lent_commands, void const* lent_visual_context_tree);-- // The producer's side of sending a list: a fresh shared buffer holding the tape and the run table. The- // buffer is handed to the receiver whole; the producer keeps nothing.- ErrorOr<Core::AnonymousBuffer> copy_to_shared_buffer() const;- // The receiver's side: copies the tape and the run table out of the buffer, which the sender can still- // write to, and checks the copies. Fails when the sizes do not fit the buffer or the tape is malformed.- static ErrorOr<NonnullRefPtr<DisplayList>> create_from_shared_buffer(DisplayListProperties, Core::AnonymousBuffer, u64 tape_size, u64 run_count);-- DisplayListProperties properties() const;-- u64 compatible_visual_context_tree_structural_epoch() const { return m_compatible_visual_context_tree_structural_epoch; }- u64 id() const { return m_id; }-- // The Rust storage that holds the list's tape.- void const* rust_handle() const { return m_storage; }- // The list as the scroll logic takes it, with the async scrolling metadata it goes with as IPC encodes an- // Optional of it.-- // The sizes a receiver needs to unpack the list from its shared buffer.- u64 tape_size() const;- u64 run_count() const;-- void set_surface_clear_color(Gfx::Color color) { m_surface_clear_color = color; }- Optional<Gfx::Color> surface_clear_color() const { return m_surface_clear_color; }- void set_root_group_color(Gfx::Color color) { m_root_group_color = color; }- Gfx::Color root_group_color() const { return m_root_group_color; }- void set_async_scrolling_metadata(AsyncScrollingMetadata metadata) { m_async_scrolling_metadata = metadata; }- Optional<AsyncScrollingMetadata> const& async_scrolling_metadata() const { return m_async_scrolling_metadata; }-- // The ids of the resources the list's commands reference, including the commands nested in others, each once.- struct ReferencedResourceIds {- ReadonlySpan<u64> fonts;- ReadonlySpan<u64> image_frames;- ReadonlySpan<u64> video_sinks;- ReadonlySpan<u64> display_lists;- ReadonlySpan<u64> canvases;- };- ReferencedResourceIds referenced_resource_ids() const;-- // Whether the list was recorded against the visual context tree Rust lends for the call, not a copy of it.- bool was_recorded_against(void const* lent_visual_context_tree) const;- // The visual context tree a list recorded in this process was recorded against, serialized for the compositor.- ByteBuffer serialized_visual_context_tree() const;- // The ids of the image frames that the filters and backdrop filters of the effects of that tree draw.- void for_each_visual_context_tree_filter_image_frame_id(Function<void(u64)> const&) const;-- // Replays a list recorded in this process through a painter, against the visual context tree it was recorded- // against, with nothing scrolled and a blinking caret as it shows at the time given.- void replay(RustFFI::FfiRasterPainter const&, i64 time_nanoseconds) const;--private:- // Takes over the storage of a tape that came from another process and passed its checks.- static NonnullRefPtr<DisplayList> adopt_received_storage(DisplayListProperties, void const* storage);-- DisplayList(u64 compatible_visual_context_tree_structural_epoch, u64 id, void const* storage, Optional<Gfx::Color> surface_clear_color, Gfx::Color root_group_color, Optional<AsyncScrollingMetadata>);-- u64 m_compatible_visual_context_tree_structural_epoch { 0 };- u64 m_id { 0 };- // One strong reference to the Rust storage, which owns the tape.- void const* m_storage { nullptr };- Optional<Gfx::Color> m_surface_clear_color;- Gfx::Color m_root_group_color { Gfx::Color::Transparent };- Optional<AsyncScrollingMetadata> m_async_scrolling_metadata;-- template<typename T>- friend ErrorOr<void> IPC::encode(IPC::Encoder&, T const&);- template<typename T>- friend ErrorOr<T> IPC::decode(IPC::Decoder&);-};--}--namespace IPC {--template<>-COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::DisplayList const&);-template<>-COMPOSITING_API ErrorOr<void> encode(Encoder&, NonnullRefPtr<Compositing::DisplayList> const&);-template<>-COMPOSITING_API ErrorOr<NonnullRefPtr<Compositing::DisplayList>> decode(Decoder&);--}diff --git a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cpp b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cppindex 55419a844bd..533ffc8a6dd 100644--- a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cpp+++ b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cpp@@ -4,7 +4,6 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/DisplayList/VisualContextTreeTestBuilder.h>#include <LibCompositing/RustFFI.h>#include <LibCompositing/TestBuilderRustFFI.h>@@ -31,14 +30,19 @@ void VisualContextTreeTestBuilder::finish()RustFFI::visual_context_tree_test_builder_finish(m_builder);}-NonnullRefPtr<DisplayList> VisualContextTreeTestBuilder::filled_rect_display_list(ContextRef context, Gfx::IntRect rect, Gfx::Color color) const+void VisualContextTreeTestBuilder::record_filled_rect(ContextRef context, Gfx::IntRect rect, Gfx::Color color){- return DisplayList::adopt_rust_storage(RustFFI::visual_context_tree_test_builder_filled_rect(m_builder, rect, color, context));+ RustFFI::visual_context_tree_test_builder_filled_rect(m_builder, rect, color, context);}-NonnullRefPtr<DisplayList> VisualContextTreeTestBuilder::rounded_rect_ring_display_list(ContextRef context, FillRoundedRectRing const& ring) const+void VisualContextTreeTestBuilder::record_rounded_rect_ring(ContextRef context, FillRoundedRectRing const& ring){- return DisplayList::adopt_rust_storage(RustFFI::visual_context_tree_test_builder_rounded_rect_ring(m_builder, ring, context));+ RustFFI::visual_context_tree_test_builder_rounded_rect_ring(m_builder, ring, context);+}++void VisualContextTreeTestBuilder::replay(RustFFI::FfiRasterPainter const& painter, i64 time_nanoseconds) const+{+ RustFFI::visual_context_tree_test_builder_replay(m_builder, time_nanoseconds, &painter);}}diff --git a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.h b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.hindex ee949b08843..4aa9f5e0dec 100644--- a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.h+++ b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.h@@ -6,7 +6,6 @@#pragma once-#include <AK/NonnullRefPtr.h>#include <AK/Optional.h>#include <LibCompositing/DisplayList/ContextRef.h>#include <LibCompositing/DisplayList/DisplayListCommand.h>@@ -22,6 +21,12 @@namespace Compositing {+namespace RustFFI {++struct FfiRasterPainter;++}+// Builds a visual context tree node by node in Rust for unit tests, which otherwise only ever// receive trees the layout arena built.class COMPOSITING_API VisualContextTreeTestBuilder {@@ -36,8 +41,12 @@ public:// Ends adding nodes. The lists below are recorded against the tree as it is then.void finish();- NonnullRefPtr<DisplayList> filled_rect_display_list(ContextRef, Gfx::IntRect, Gfx::Color) const;- NonnullRefPtr<DisplayList> rounded_rect_ring_display_list(ContextRef, FillRoundedRectRing const&) const;+ // Records a list against the tree, which the builder replays from then on.+ void record_filled_rect(ContextRef, Gfx::IntRect, Gfx::Color);+ void record_rounded_rect_ring(ContextRef, FillRoundedRectRing const&);++ // Replays the list recorded last, with nothing scrolled, as it shows at `time_nanoseconds`.+ void replay(RustFFI::FfiRasterPainter const&, i64 time_nanoseconds) const;private:void* m_builder { nullptr };diff --git a/Libraries/LibCompositing/Forward.h b/Libraries/LibCompositing/Forward.hindex b6de7200570..09b2fdd61c5 100644--- a/Libraries/LibCompositing/Forward.h+++ b/Libraries/LibCompositing/Forward.h@@ -21,7 +21,6 @@ struct UIOverlays;class Canvas2DCommandStream;struct Canvas2DCommandStreamSegment;-class DisplayList;struct DisplayListGlyph;class DisplayListResourceStorage;struct DisplayListResourceSet;diff --git a/Libraries/LibCompositing/Rust/src/display_list/storage.rs b/Libraries/LibCompositing/Rust/src/display_list/storage.rsindex 87cb7c4d9a3..4144550d071 100644--- a/Libraries/LibCompositing/Rust/src/display_list/storage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/storage.rs@@ -4,10 +4,8 @@* SPDX-License-Identifier: BSD-2-Clause*/-//! The tape of one display list as C++ holds it: a recording this process made, with the visual-//! context tree it was recorded against, or a tape that came from another process and passed-//! validation. C++ keeps the storage as an opaque handle and passes it back to the entry points of-//! this crate.+//! The tape of one display list: a recording this process made, with the visual context tree it was recorded against,+//! or a tape that came from another process and passed validation.use super::builder::RecordedDisplayList;use super::commands::{ContextRef, DisplayListCommandRun};@@ -15,40 +13,8 @@ use super::effect_clip_plan::EffectClipPlan;use super::summary::{DisplayListSummary, summarize};use super::validate::validate_tape;use crate::visual_context::VisualContextTree;-use std::ffi::c_void;use std::sync::{Arc, OnceLock};-// A read-only view into a storage's tape. An empty Vec's pointer is dangling, so a reader never-// dereferences a pointer whose count is zero.-#[derive(Clone, Copy, Debug)]-#[repr(C)]-struct TapeView {- bytes: *const u8,- byte_count: usize,- command_runs: *const DisplayListCommandRun,- command_run_count: usize,-}--impl TapeView {- const fn empty() -> Self {- Self {- bytes: std::ptr::null(),- byte_count: 0,- command_runs: std::ptr::null(),- command_run_count: 0,- }- }-- fn of(bytes: &[u8], command_runs: &[DisplayListCommandRun]) -> Self {- Self {- bytes: bytes.as_ptr(),- byte_count: bytes.len(),- command_runs: command_runs.as_ptr(),- command_run_count: command_runs.len(),- }- }-}-// Tape bytes in memory aligned for every command struct, which a Vec<u8> does not promise.struct AlignedBytes {words: Vec<u64>,@@ -83,35 +49,20 @@ enum Tape {},}-#[repr(C)]pub struct DisplayListStorage {- // The view comes first and keeps its layout, as code from another copy of this crate in the- // process reads it.- view: TapeView,tape: Tape,// The tree a list this process recorded was recorded against, which it replays against and goes// to the compositor with. A tape from another process comes without one.visual_context_tree: Option<Arc<VisualContextTree>>,- // The placement of the runs' clips and effects. The C++ list that owns this storage replays it- // against trees of one structural epoch only, so one plan serves every replay.+ // The placement of the runs' clips and effects. The list is replayed against trees of one structural epoch only, so+ // one plan serves every replay.effect_clip_plan: OnceLock<EffectClipPlan>,summary: OnceLock<DisplayListSummary>,}-// SAFETY: The view's pointers address the tape the storage owns, and nothing changes the tape.-unsafe impl Send for DisplayListStorage {}-// SAFETY: As above; the plan is published through a OnceLock.-unsafe impl Sync for DisplayListStorage {}-impl DisplayListStorage {fn new(tape: Tape, visual_context_tree: Option<Arc<VisualContextTree>>) -> Arc<Self> {- let view = match &tape {- Tape::Empty => TapeView::empty(),- Tape::Recorded(recorded) => TapeView::of(&recorded.bytes, &recorded.command_runs),- Tape::Received { bytes, command_runs } => TapeView::of(bytes.as_slice(), command_runs),- };Arc::new(Self {- view,tape,visual_context_tree,effect_clip_plan: OnceLock::new(),@@ -139,12 +90,6 @@ impl DisplayListStorage {self.visual_context_tree.as_ref()}- fn recorded_visual_context_tree(&self) -> &VisualContextTree {- self.visual_context_tree- .as_deref()- .expect("a list this process recorded holds the tree it was recorded against")- }-pub fn summary(&self) -> &DisplayListSummary {self.summary.get_or_init(|| summarize(self.bytes(), self.command_runs()))@@ -157,27 +102,6 @@ impl DisplayListStorage {}}-/// # Safety-///-/// `storage` must be a live storage handle for the duration of the borrow.-pub unsafe fn storage_from_handle<'a>(storage: *const c_void) -> &'a DisplayListStorage {- assert!(!storage.is_null());- // SAFETY: The caller guarantees a live handle.- unsafe { &*storage.cast::<DisplayListStorage>() }-}--fn into_handle(storage: Arc<DisplayListStorage>) -> *const c_void {- Arc::into_raw(storage).cast()-}--/// A storage handle for a list recorded against `visual_context_tree`, which the caller owns.-pub fn recorded_storage_handle(- recorded: Arc<RecordedDisplayList>,- visual_context_tree: Arc<VisualContextTree>,-) -> *const c_void {- into_handle(DisplayListStorage::recorded(recorded, visual_context_tree))-}-impl DisplayListStorage {/// A list this process recorded against `visual_context_tree`.pub fn recorded(recorded: Arc<RecordedDisplayList>, visual_context_tree: Arc<VisualContextTree>) -> Arc<Self> {@@ -190,153 +114,6 @@ impl DisplayListStorage {}}-/// An empty list, recorded against a tree with no node but the visual viewport.-#[unsafe(no_mangle)]-pub extern "C" fn display_list_storage_create_empty() -> *const c_void {- into_handle(DisplayListStorage::new(- Tape::Empty,- Some(Arc::new(VisualContextTree::create_identity())),- ))-}--/// # Safety-/// `recorded` and `visual_context_tree` must each be one unconsumed Arc reference, to a-/// RecordedDisplayList and to the tree it was recorded against, which the returned storage takes-/// over.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_adopt_recorded(- recorded: *const c_void,- visual_context_tree: *const c_void,-) -> *const c_void {- assert!(!recorded.is_null() && !visual_context_tree.is_null());- // SAFETY: The caller hands over one reference to each.- let (recorded, visual_context_tree) = unsafe {- (- Arc::from_raw(recorded.cast::<RecordedDisplayList>()),- Arc::from_raw(visual_context_tree.cast::<VisualContextTree>()),- )- };- recorded_storage_handle(recorded, visual_context_tree)-}--/// # Safety-/// `recorded` and `visual_context_tree` must point to a live RecordedDisplayList and the tree it was-/// recorded against, each held by an Arc for the call. The returned storage takes a reference of its-/// own to each.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_share_recorded(- recorded: *const c_void,- visual_context_tree: *const c_void,-) -> *const c_void {- assert!(!recorded.is_null() && !visual_context_tree.is_null());- // SAFETY: The caller lends a reference to each, of which this takes one more.- unsafe {- Arc::increment_strong_count(recorded.cast::<RecordedDisplayList>());- Arc::increment_strong_count(visual_context_tree.cast::<VisualContextTree>());- display_list_storage_adopt_recorded(recorded, visual_context_tree)- }-}--/// Whether the list was recorded against `visual_context_tree` itself, not a copy of it.-///-/// # Safety-/// `storage` must be a live storage handle, and `visual_context_tree` a tree held by an Arc or null.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_was_recorded_against(- storage: *const c_void,- visual_context_tree: *const c_void,-) -> bool {- unsafe { storage_from_handle(storage) }- .visual_context_tree- .as_ref()- .is_some_and(|tree| std::ptr::eq(Arc::as_ptr(tree).cast(), visual_context_tree))-}--/// # Safety-/// `storage` must be a live storage handle of a list this process recorded.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_visual_context_tree_structural_epoch(storage: *const c_void) -> u64 {- unsafe { storage_from_handle(storage) }- .recorded_visual_context_tree()- .structural_epoch-}--/// The tree a list this process recorded was recorded against, serialized for the compositor.-///-/// # Safety-/// `storage` must be a live storage handle of a list this process recorded; `append` is called-/// synchronously with `sink`.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_serialize_visual_context_tree(- storage: *const c_void,- sink: *mut c_void,- append: unsafe extern "C" fn(*mut c_void, *const u8, usize),-) {- let bytes = unsafe { storage_from_handle(storage) }- .recorded_visual_context_tree()- .to_bytes();- // SAFETY: The C++ sink copies the bytes synchronously.- unsafe { append(sink, bytes.as_ptr(), bytes.len()) };-}--/// Calls `visit` with `context` for the id of every image frame that a filter or backdrop filter of-/// an effect node of the list's tree draws.-///-/// # Safety-/// `storage` must be a live storage handle of a list this process recorded; `visit` is called-/// synchronously.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_for_each_visual_context_tree_filter_image_frame_id(- storage: *const c_void,- context: *mut c_void,- visit: unsafe extern "C" fn(*mut c_void, u64),-) {- let tree = unsafe { storage_from_handle(storage) }.recorded_visual_context_tree();- // SAFETY: The caller guarantees `visit` accepts `context`.- tree.for_each_effects_filter_image_frame_id(&mut |id| unsafe { visit(context, id) });-}--/// # Safety-/// `storage` is null or one unconsumed storage reference. It may be released from any thread.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_release(storage: *const c_void) {- if !storage.is_null() {- drop(unsafe { Arc::from_raw(storage.cast::<DisplayListStorage>()) });- }-}--/// The tape and run table of a storage. This reads only the view at the start of the storage, so-/// code from any copy of this crate in the process can call it.-///-/// # Safety-/// `storage` must be a live storage handle for the duration of the borrow.-pub unsafe fn tape_of<'a>(storage: *const c_void) -> (&'a [u8], &'a [DisplayListCommandRun]) {- assert!(!storage.is_null());- // SAFETY: The view is the first field of the #[repr(C)] storage, and its spans address the tape- // the storage owns.- unsafe {- let view = *storage.cast::<TapeView>();- (- ak::slice_from_raw_parts(view.bytes, view.byte_count),- ak::slice_from_raw_parts(view.command_runs, view.command_run_count),- )- }-}--/// # Safety-/// `storage` must be a live storage handle.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_tape_size(storage: *const c_void) -> usize {- unsafe { storage_from_handle(storage) }.bytes().len()-}--/// # Safety-/// `storage` must be a live storage handle.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_run_count(storage: *const c_void) -> usize {- unsafe { storage_from_handle(storage) }.command_runs().len()-}-// The tape and its run table packed together for transport: the tape first, then the runs./// The size of a tape and run table packed for transport.pub fn packed_size(tape_size: usize, run_count: usize) -> Option<usize> {@@ -435,69 +212,6 @@ pub fn receive_packed(Ok(DisplayListStorage::new(Tape::Received { bytes, command_runs }, None))}-/// The size of the storage's tape and run table packed for transport.-///-/// # Safety-/// `storage` must be a live storage handle.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_packed_size(storage: *const c_void) -> usize {- let storage = unsafe { storage_from_handle(storage) };- packed_size(storage.bytes().len(), storage.command_runs().len()).expect("a stored tape fits in memory")-}--/// Writes the storage's tape and run table packed for transport.-///-/// # Safety-/// `storage` must be a live storage handle and `destination` must address-/// `display_list_storage_packed_size(storage)` writable bytes.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_write_packed(storage: *const c_void, destination: *mut u8) {- let storage = unsafe { storage_from_handle(storage) };- let (tape, runs) = (storage.bytes(), storage.command_runs());- let size = packed_size(tape.len(), runs.len()).expect("a stored tape fits in memory");- if size == 0 {- return;- }- // SAFETY: The caller guarantees `destination` addresses `size` writable bytes.- let destination = unsafe { ak::slice_from_raw_parts_mut(destination, size) };- let (tape_destination, runs_destination) = destination.split_at_mut(tape.len());- tape_destination.copy_from_slice(tape);- let (run_destinations, _) = runs_destination.as_chunks_mut::<{ std::mem::size_of::<DisplayListCommandRun>() }>();- for (run, out) in runs.iter().zip(run_destinations) {- write_run(run, out);- }-}--/// Copies a packed tape and run table out of memory that another process can still write to, and-/// checks the copy. Returns the new storage, or null with a static error message whose address and-/// size it writes.-///-/// # Safety-/// `packed` must address `packed_size` readable bytes, or be null with a size of zero; `error` and-/// `error_size` must be writable.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_receive_packed(- packed: *const u8,- packed_size_in_bytes: usize,- tape_size: usize,- run_count: usize,- error: *mut *const u8,- error_size: *mut usize,-) -> *const c_void {- // SAFETY: The caller guarantees `packed` addresses `packed_size_in_bytes` readable bytes.- match unsafe { receive_packed_from_shared_memory(packed, packed_size_in_bytes, tape_size, run_count) } {- Ok(storage) => into_handle(storage),- Err(message) => {- // SAFETY: The caller guarantees both are writable.- unsafe {- *error = message.as_ptr();- *error_size = message.len();- }- std::ptr::null()- }- }-}-/// Copies a packed tape and run table out of memory that another process can still write to, and checks the copy.////// # Safety@@ -534,134 +248,6 @@ pub unsafe fn receive_packed_from_shared_memory(Ok(DisplayListStorage::new(Tape::Received { bytes, command_runs }, None))}-#[derive(Clone, Copy, Debug)]-#[repr(C)]-pub struct FfiReferencedResourceIds {- pub font_ids: *const u64,- pub font_id_count: usize,- pub image_frame_ids: *const u64,- pub image_frame_id_count: usize,- pub video_sink_ids: *const u64,- pub video_sink_id_count: usize,- pub display_list_ids: *const u64,- pub display_list_id_count: usize,- pub canvas_ids: *const u64,- pub canvas_id_count: usize,-}--/// The ids of the resources the commands of the list reference, including the commands nested in-/// others, each once. The spans remain valid while the storage lives.-///-/// # Safety-/// `storage` must be a live storage handle.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_referenced_resource_ids(- storage: *const c_void,-) -> FfiReferencedResourceIds {- let summary = unsafe { storage_from_handle(storage) }.summary();- FfiReferencedResourceIds {- font_ids: summary.font_ids.as_ptr(),- font_id_count: summary.font_ids.len(),- image_frame_ids: summary.image_frame_ids.as_ptr(),- image_frame_id_count: summary.image_frame_ids.len(),- video_sink_ids: summary.video_sink_ids.as_ptr(),- video_sink_id_count: summary.video_sink_ids.len(),- display_list_ids: summary.display_list_ids.as_ptr(),- display_list_id_count: summary.display_list_ids.len(),- canvas_ids: summary.canvas_ids.as_ptr(),- canvas_id_count: summary.canvas_ids.len(),- }-}--// A tape and run table that C++ writes into before they are checked.-pub struct PendingDisplayListStorage {- bytes: AlignedBytes,- run_bytes: Vec<u8>,-}--#[derive(Clone, Copy, Debug)]-#[repr(C)]-pub struct FfiPendingDisplayListStorage {- pub pending: *mut c_void,- pub tape: *mut u8,- pub run_bytes: *mut u8,- pub run_bytes_size: usize,-}--/// Allocates room for a tape of `tape_size` bytes and a table of `run_count` runs that arrive from-/// another process. Returns a null `pending` when that much memory is not available. The caller-/// fills both and passes `pending` to `display_list_storage_finish` or-/// `display_list_storage_abandon`.-#[unsafe(no_mangle)]-pub extern "C" fn display_list_storage_begin(tape_size: usize, run_count: usize) -> FfiPendingDisplayListStorage {- let failed = FfiPendingDisplayListStorage {- pending: std::ptr::null_mut(),- tape: std::ptr::null_mut(),- run_bytes: std::ptr::null_mut(),- run_bytes_size: 0,- };- let Some(run_bytes_size) = run_count.checked_mul(std::mem::size_of::<DisplayListCommandRun>()) else {- return failed;- };- let Some(bytes) = AlignedBytes::try_zeroed(tape_size) else {- return failed;- };- let mut run_bytes = Vec::new();- if run_bytes.try_reserve_exact(run_bytes_size).is_err() {- return failed;- }- run_bytes.resize(run_bytes_size, 0);- let mut pending = Box::new(PendingDisplayListStorage { bytes, run_bytes });- FfiPendingDisplayListStorage {- tape: pending.bytes.words.as_mut_ptr().cast(),- run_bytes: pending.run_bytes.as_mut_ptr(),- run_bytes_size,- pending: Box::into_raw(pending).cast(),- }-}--/// Checks a filled tape and run table. Returns the new storage, or null with a static error message-/// whose address and size it writes.-///-/// # Safety-/// `pending` must come from `display_list_storage_begin` and is consumed; `error` and `error_size`-/// must be writable.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_finish(- pending: *mut c_void,- error: *mut *const u8,- error_size: *mut usize,-) -> *const c_void {- assert!(!pending.is_null());- let pending = unsafe { Box::from_raw(pending.cast::<PendingDisplayListStorage>()) };- match validate_tape(pending.bytes.as_slice(), &pending.run_bytes) {- Ok(command_runs) => into_handle(DisplayListStorage::new(- Tape::Received {- bytes: pending.bytes,- command_runs,- },- None,- )),- Err(message) => {- // SAFETY: The caller guarantees both are writable.- unsafe {- *error = message.as_ptr();- *error_size = message.len();- }- std::ptr::null()- }- }-}--/// # Safety-/// `pending` must come from `display_list_storage_begin` and is consumed.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_abandon(pending: *mut c_void) {- if !pending.is_null() {- drop(unsafe { Box::from_raw(pending.cast::<PendingDisplayListStorage>()) });- }-}-#[cfg(test)]mod tests {use super::*;@@ -670,22 +256,18 @@ mod tests {fn published_bytes_survive_the_recorder_and_can_be_released_on_another_thread() {fn assert_send_sync<T: Send + Sync>() {}assert_send_sync::<RecordedDisplayList>();+ assert_send_sync::<DisplayListStorage>();let mut recorded = Arc::new(RecordedDisplayList {bytes: vec![1, 2, 3],..Default::default()});- let published = Arc::into_raw(recorded.clone());- let tree = Arc::into_raw(Arc::new(VisualContextTree::create_identity()));- let storage = unsafe { display_list_storage_adopt_recorded(published.cast(), tree.cast()) };+ let storage = DisplayListStorage::recorded(recorded.clone(), Arc::new(VisualContextTree::create_identity()));Arc::make_mut(&mut recorded).bytes[0] = 9;- assert_eq!(unsafe { tape_of(storage) }.0, &[1, 2, 3]);+ assert_eq!(storage.bytes(), &[1, 2, 3]);drop(recorded);- // An FFI consumer transfers the opaque owner without lending any arena state.- let transferred = storage as usize;std::thread::spawn(move || {- let storage = transferred as *const c_void;- assert_eq!(unsafe { tape_of(storage) }.0, &[1, 2, 3]);- unsafe { display_list_storage_release(storage) };+ assert_eq!(storage.bytes(), &[1, 2, 3]);+ drop(storage);}).join().unwrap();diff --git a/Libraries/LibCompositing/Rust/src/ffi.rs b/Libraries/LibCompositing/Rust/src/ffi.rsindex 75c2bd227f5..47fb04ccdf8 100644--- a/Libraries/LibCompositing/Rust/src/ffi.rs+++ b/Libraries/LibCompositing/Rust/src/ffi.rs@@ -7,7 +7,6 @@//! The entry points the compositor process shares with WebContent: replaying display lists, computing//! their damage, the scroll queries of recorded display lists, and the tree builder tests use.-use crate::display_list::storage::storage_from_handle;use crate::scrolling::smooth_scroll_animation::SmoothScrollAnimation;use crate::scrolling::{AccumulatedVisualContextTree, AsyncScrollNodeKind, DisplayList, InputRoutingDecision, ScrollAnimationKind,@@ -37,70 +36,18 @@ pub unsafe extern "C" fn ladybird_web_force_dark_should_filter_image(crate::force_dark::should_filter(&features)}-/// Replays the list `storage` holds against `tree`, as `frame` presents it.-///-/// # Safety-///-/// `storage` must be a live storage handle of a list recorded against the structural epoch of `tree`, and `painter`-/// must be live. The painter callbacks run synchronously.-pub unsafe fn replay_display_list_storage(- tree: &crate::visual_context::VisualContextTree,- storage: *const c_void,- root_group_color: libgfx_rust::Color,- frame: &crate::display_list::replay::ReplayFrame<'_>,- selection: crate::display_list::replay::ReplaySelection<'_>,- painter: *const crate::host::FfiRasterPainter,-) {- // SAFETY: The caller guarantees a live handle for the duration of the call.- let storage = unsafe { storage_from_handle(storage) };- // SAFETY: The caller guarantees `painter` is live for the call.- let mut painter = unsafe { *painter };- crate::display_list::replay::replay_display_list(- tree,- storage.bytes(),- storage.command_runs(),- storage.effect_clip_plan(tree),- root_group_color,- frame,- selection,- &mut painter,- );-}--/// Replays a list this process recorded against the tree it was recorded against, with nothing scrolled, showing a-/// blinking caret as it is at `time_nanoseconds`. The display lists it nests are looked up through the painter.-///-/// # Safety-///-/// `storage` must be a live storage handle of a list this process recorded, and `painter` must be live. The painter-/// callbacks run synchronously.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_replay(- storage: *const c_void,- root_group_color: libgfx_rust::Color,- time_nanoseconds: i64,- painter: *const crate::host::FfiRasterPainter,-) {- // NB: The compositor replays the display lists that nest others itself, with the lists they nest.- let frame = crate::display_list::replay::ReplayFrame::unscrolled(- time_nanoseconds,- &crate::display_list::replay::NoNestedDisplayLists,- );- // SAFETY: The caller guarantees a live handle and a live painter for the duration of the call.- unsafe {- let tree = storage_from_handle(storage)- .visual_context_tree()- .expect("a list this process recorded holds the tree it was recorded against");- replay_display_list_storage(tree, storage, root_group_color, &frame, Default::default(), painter);- };-}-/// A hand-built test tree: nodes are added until it is finished, and lists are recorded against it after.pub(super) enum TestBuilderTree {Building(Box<crate::visual_context::VisualContextTree>),Finished(Arc<crate::visual_context::VisualContextTree>),}+/// A hand-built test tree, and the list recorded against it last, which a test replays.+pub(super) struct TestBuilder {+ pub(super) tree: TestBuilderTree,+ pub(super) recorded: Option<Arc<crate::display_list::storage::DisplayListStorage>>,+}+/// # Safety////// Returns a builder handle for hand-built test trees rooted at an identity visual viewport@@ -108,16 +55,19 @@ pub(super) enum TestBuilderTree {/// consumes it.#[unsafe(no_mangle)]pub unsafe extern "C" fn visual_context_tree_test_builder_create() -> *mut c_void {- let tree = TestBuilderTree::Building(Box::new(crate::visual_context::VisualContextTree::create_identity()));- Box::into_raw(Box::new(tree)).cast()+ let builder = TestBuilder {+ tree: TestBuilderTree::Building(Box::new(crate::visual_context::VisualContextTree::create_identity())),+ recorded: None,+ };+ Box::into_raw(Box::new(builder)).cast()}/// # Safety////// `builder` must be a live handle from `visual_context_tree_test_builder_create`.-pub(super) unsafe fn test_builder_tree<'a>(builder: *mut c_void) -> &'a mut TestBuilderTree {- // SAFETY: The caller guarantees `builder` is the live boxed tree the create call returned.- unsafe { &mut *builder.cast::<TestBuilderTree>() }+pub(super) unsafe fn test_builder<'a>(builder: *mut c_void) -> &'a mut TestBuilder {+ // SAFETY: The caller guarantees `builder` is the live boxed builder the create call returned.+ unsafe { &mut *builder.cast::<TestBuilder>() }}/// Ends adding nodes: the lists recorded from here on are recorded against the tree as it is.@@ -128,7 +78,7 @@ pub(super) unsafe fn test_builder_tree<'a>(builder: *mut c_void) -> &'a mut Test#[unsafe(no_mangle)]pub unsafe extern "C" fn visual_context_tree_test_builder_finish(builder: *mut c_void) {// SAFETY: Guaranteed by the caller.- let tree = unsafe { test_builder_tree(builder) };+ let tree = &mut unsafe { test_builder(builder) }.tree;let TestBuilderTree::Building(building) = std::mem::replace(tree,TestBuilderTree::Finished(Arc::new(crate::visual_context::VisualContextTree::create_identity())),@@ -147,8 +97,45 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_destroy(builder: *mutif builder.is_null() {return;}- // SAFETY: The caller hands over the boxed tree the create call returned.- drop(unsafe { Box::from_raw(builder.cast::<TestBuilderTree>()) });+ // SAFETY: The caller hands over the boxed builder the create call returned.+ drop(unsafe { Box::from_raw(builder.cast::<TestBuilder>()) });+}++/// Replays the list recorded last against the finished tree of `builder`, with nothing scrolled, showing a blinking caret+/// as it is at `time_nanoseconds`.+///+/// # Safety+///+/// `builder` must be a live handle from `visual_context_tree_test_builder_create` that recorded a list, and `painter`+/// must be live. The painter callbacks run synchronously.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn visual_context_tree_test_builder_replay(+ builder: *mut c_void,+ time_nanoseconds: i64,+ painter: *const crate::host::FfiRasterPainter,+) {+ // SAFETY: Guaranteed by the caller.+ let builder = unsafe { test_builder(builder) };+ let storage = builder.recorded.as_ref().expect("a test replays a list it recorded");+ let tree = storage+ .visual_context_tree()+ .expect("a test list holds the tree it was recorded against");+ let frame = crate::display_list::replay::ReplayFrame::unscrolled(+ time_nanoseconds,+ &crate::display_list::replay::NoNestedDisplayLists,+ );+ // SAFETY: The caller guarantees `painter` is live for the call.+ let mut painter = unsafe { *painter };+ crate::display_list::replay::replay_display_list(+ tree,+ storage.bytes(),+ storage.command_runs(),+ storage.effect_clip_plan(tree),+ libgfx_rust::Color::TRANSPARENT,+ &frame,+ Default::default(),+ &mut painter,+ );}#[unsafe(no_mangle)]diff --git a/Libraries/LibCompositing/Rust/src/test_builder.rs b/Libraries/LibCompositing/Rust/src/test_builder.rsindex e236f89e759..e4796f73262 100644--- a/Libraries/LibCompositing/Rust/src/test_builder.rs+++ b/Libraries/LibCompositing/Rust/src/test_builder.rs@@ -6,22 +6,23 @@use crate::display_list::builder::DisplayListBuilder;use crate::display_list::commands::{ClipNodeIndex, ContextRef, EffectNodeIndex, FillRoundedRectRing};-use crate::display_list::storage::recorded_storage_handle;-use crate::ffi::{TestBuilderTree, test_builder_tree};+use crate::display_list::storage::DisplayListStorage;+use crate::ffi::{TestBuilderTree, test_builder};use std::ffi::c_void;use std::sync::Arc;-/// A storage handle for what `builder` recorded, against the finished tree of `test_builder`.+/// Has `test_builder` keep what `builder` recorded, against its finished tree, as the list it replays.////// # Safety////// `test_builder` must be a live, finished handle from `visual_context_tree_test_builder_create`.-unsafe fn recorded_against_finished_tree(test_builder: *mut c_void, builder: DisplayListBuilder) -> *const c_void {+unsafe fn record_against_finished_tree(test_builder: *mut c_void, builder: DisplayListBuilder) {// SAFETY: Guaranteed by the caller.- let TestBuilderTree::Finished(tree) = (unsafe { test_builder_tree(test_builder) }) else {+ let test_builder = unsafe { self::test_builder(test_builder) };+ let TestBuilderTree::Finished(tree) = &test_builder.tree else {panic!("lists are recorded against a finished test tree");};- recorded_storage_handle(Arc::new(builder.finish()), tree.clone())+ test_builder.recorded = Some(DisplayListStorage::recorded(Arc::new(builder.finish()), tree.clone()));}/// # Safety@@ -33,7 +34,7 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_append_image_filter(image_id: u64,rect: libgfx_rust::IntRect,) -> u32 {- let TestBuilderTree::Building(tree) = (unsafe { test_builder_tree(builder) }) else {+ let TestBuilderTree::Building(tree) = &mut (unsafe { test_builder(builder) }).tree else {panic!("nodes are added to a test tree before it is finished");};let filter = libgfx_rust::filter::Filter::Image {@@ -58,7 +59,7 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_append_image_filter(}/// Records a rectangle with the same canonical builder as production recordings, against the finished tree of-/// `test_builder`. Returns a storage handle the caller owns.+/// `test_builder`, which keeps it as the list it replays.////// # Safety///@@ -69,7 +70,7 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_filled_rect(rect: libgfx_rust::IntRect,color: libgfx_rust::Color,context: ContextRef,-) -> *const c_void {+) {let mut builder = DisplayListBuilder::new();builder.append(&crate::display_list::commands::FillRect {@@ -82,11 +83,10 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_filled_rect(context,);// SAFETY: Guaranteed by the caller.- unsafe { recorded_against_finished_tree(test_builder, builder) }+ unsafe { record_against_finished_tree(test_builder, builder) };}-/// Records a rounded rectangle ring against the finished tree of `test_builder`. Returns a storage handle the caller-/// owns.+/// Records a rounded rectangle ring against the finished tree of `test_builder`, which keeps it as the list it replays.////// # Safety///@@ -96,9 +96,9 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_rounded_rect_ring(test_builder: *mut c_void,ring: FillRoundedRectRing,context: ContextRef,-) -> *const c_void {+) {let mut builder = DisplayListBuilder::new();builder.append(&ring, &[], context);// SAFETY: Guaranteed by the caller.- unsafe { recorded_against_finished_tree(test_builder, builder) }+ unsafe { record_against_finished_tree(test_builder, builder) };}diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex bfc375d37ce..018fa9f51fb 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -11,7 +11,7 @@#include <Compositor/CanvasHost.h>#include <Compositor/CompositorState.h>#include <Compositor/SkiaUtils.h>-#include <LibCompositing/DisplayList/DisplayList.h>+#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibCore/AnonymousBuffer.h>#include <LibCore/EventLoop.h>#include <LibCore/StatsLog.h>diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.hindex 01c9cbbb0b9..3b1b5b6d8b9 100644--- a/Services/Compositor/ConnectionFromWebContent.h+++ b/Services/Compositor/ConnectionFromWebContent.h@@ -14,7 +14,7 @@#include <Compositor/CompositorWebContentServerEndpoint.h>#include <Compositor/RenderClockConnection.h>#include <Compositor/VideoFrameHolds.h>-#include <LibCompositing/DisplayList/DisplayList.h>+#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>#include <LibCompositing/WebGL/Types.h>#include <LibCore/AnonymousBuffer.h>diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cppindex 46e03e6db78..45506c73427 100644--- a/Services/Compositor/DisplayListPlayerSkia.cpp+++ b/Services/Compositor/DisplayListPlayerSkia.cpp@@ -39,7 +39,7 @@#include <Compositor/DisplayListRasterCache.h>#include <Compositor/SkiaBackendContext.h>#include <Compositor/SkiaUtils.h>-#include <LibCompositing/DisplayList/DisplayList.h>+#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibGfx/Bitmap.h>#include <LibGfx/ColorSpace.h>#include <LibGfx/DecodedImageFrame.h>diff --git a/Services/Compositor/DisplayListRasterCache.cpp b/Services/Compositor/DisplayListRasterCache.cppindex 0b79f5a738e..3f1cf1d5590 100644--- a/Services/Compositor/DisplayListRasterCache.cpp+++ b/Services/Compositor/DisplayListRasterCache.cpp@@ -12,7 +12,7 @@#include <Compositor/SkiaBackendContext.h>#include <Compositor/SkiaUtils.h>#include <Compositor/VideoFrameSkia.h>-#include <LibCompositing/DisplayList/DisplayList.h>+#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>#include <LibGfx/Bitmap.h>#include <LibGfx/ColorSpace.h>diff --git a/Tests/Compositor/TestDisplayListImageFilters.cpp b/Tests/Compositor/TestDisplayListImageFilters.cppindex edf260b6dd5..8cfe3992b82 100644--- a/Tests/Compositor/TestDisplayListImageFilters.cpp+++ b/Tests/Compositor/TestDisplayListImageFilters.cpp@@ -7,7 +7,6 @@#include <Compositor/DisplayListPlayerSkia.h>#include <Compositor/DisplayListRasterCache.h>#include <Compositor/PaintingSurface.h>-#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>#include <LibCompositing/DisplayList/VisualContextTreeTestBuilder.h>#include <LibGfx/Bitmap.h>@@ -27,12 +26,12 @@ static NonnullRefPtr<Gfx::Bitmap> replace_image(Compositing::DisplayListResourcereturn bitmap;}-static Gfx::Color render(Compositor::DisplayListPlayerSkia& player, Compositing::DisplayList const& list, Compositing::DisplayListResourceStorage const& storage, Compositor::DisplayListRasterCache& cache)+static Gfx::Color render(Compositor::DisplayListPlayerSkia& player, Compositing::VisualContextTreeTestBuilder const& builder, Compositing::DisplayListResourceStorage const& storage, Compositor::DisplayListRasterCache& cache){auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, rect.size()));auto surface = Gfx::PaintingSurface::wrap_bitmap(*bitmap);auto painter = player.begin_painting(*surface, storage, cache, nullptr);- list.replay(painter, 0);+ builder.replay(painter, 0);player.end_painting();player.flush(*surface);return bitmap->get_pixel(0, 0);@@ -43,7 +42,7 @@ TEST_CASE(image_filters_use_the_current_resource_storage)Compositing::VisualContextTreeTestBuilder builder;auto effect = builder.append_image_filter(image_id.value(), rect);builder.finish();- auto list = builder.filled_rect_display_list({ .effect = effect }, rect, Gfx::Color::White);+ builder.record_filled_rect({ .effect = effect }, rect, Gfx::Color::White);Compositor::DisplayListPlayerSkia player { nullptr };Compositing::DisplayListResourceStorage blue_storage;Compositing::DisplayListResourceStorage green_storage;@@ -52,9 +51,9 @@ TEST_CASE(image_filters_use_the_current_resource_storage)(void)replace_image(blue_storage, blue_cache, Gfx::Color::Blue);(void)replace_image(green_storage, green_cache, Gfx::Color::Green);- EXPECT_EQ(render(player, *list, blue_storage, blue_cache), Gfx::Color::Blue);- EXPECT_EQ(render(player, *list, green_storage, green_cache), Gfx::Color::Green);- EXPECT_EQ(render(player, *list, blue_storage, blue_cache), Gfx::Color::Blue);+ EXPECT_EQ(render(player, builder, blue_storage, blue_cache), Gfx::Color::Blue);+ EXPECT_EQ(render(player, builder, green_storage, green_cache), Gfx::Color::Green);+ EXPECT_EQ(render(player, builder, blue_storage, blue_cache), Gfx::Color::Blue);}TEST_CASE(image_filters_drop_replaced_image_resources)@@ -62,14 +61,14 @@ TEST_CASE(image_filters_drop_replaced_image_resources)Compositing::VisualContextTreeTestBuilder builder;auto effect = builder.append_image_filter(image_id.value(), rect);builder.finish();- auto list = builder.filled_rect_display_list({ .effect = effect }, rect, Gfx::Color::White);+ builder.record_filled_rect({ .effect = effect }, rect, Gfx::Color::White);Compositor::DisplayListPlayerSkia player { nullptr };Compositing::DisplayListResourceStorage storage;Compositor::DisplayListRasterCache cache;auto original_bitmap = replace_image(storage, cache, Gfx::Color::Blue);- EXPECT_EQ(render(player, *list, storage, cache), Gfx::Color::Blue);+ EXPECT_EQ(render(player, builder, storage, cache), Gfx::Color::Blue);(void)replace_image(storage, cache, Gfx::Color::Green);- EXPECT_EQ(render(player, *list, storage, cache), Gfx::Color::Green);+ EXPECT_EQ(render(player, builder, storage, cache), Gfx::Color::Green);EXPECT_EQ(original_bitmap->get_pixel(0, 0), Gfx::Color::Blue);}@@ -78,7 +77,7 @@ TEST_CASE(image_filters_do_not_keep_destroyed_resource_namespaces)Compositing::VisualContextTreeTestBuilder builder;auto effect = builder.append_image_filter(image_id.value(), rect);builder.finish();- auto list = builder.filled_rect_display_list({ .effect = effect }, rect, Gfx::Color::White);+ builder.record_filled_rect({ .effect = effect }, rect, Gfx::Color::White);Compositor::DisplayListPlayerSkia player { nullptr };struct ResourceNamespace {Compositing::DisplayListResourceStorage storage;@@ -89,7 +88,7 @@ TEST_CASE(image_filters_do_not_keep_destroyed_resource_namespaces)for (auto color : { Gfx::Color::Blue, Gfx::Color::Green }) {auto* resources = new (memory) ResourceNamespace;kept_images.append(replace_image(resources->storage, resources->cache, color));- EXPECT_EQ(render(player, *list, resources->storage, resources->cache), color);+ EXPECT_EQ(render(player, builder, resources->storage, resources->cache), color);resources->~ResourceNamespace();}}diff --git a/Tests/Compositor/TestPaintingSurface.cpp b/Tests/Compositor/TestPaintingSurface.cppindex a64ab56484f..c1f332dcd9c 100644--- a/Tests/Compositor/TestPaintingSurface.cpp+++ b/Tests/Compositor/TestPaintingSurface.cpp@@ -9,7 +9,6 @@#include <Compositor/PaintingSurface.h>#include <Compositor/SkiaBackendContext.h>#include <Compositor/SkiaUtils.h>-#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/DisplayList/VisualContextTreeTestBuilder.h>#include <LibGfx/Bitmap.h>#include <LibTest/TestCase.h>@@ -51,9 +50,9 @@ TEST_CASE(zero_width_border_sides_do_not_paint_on_gpu_surface).left_width = 0,.color = Gfx::Color::Black,};- auto list = builder.rounded_rect_ring_display_list({}, ring);+ builder.record_rounded_rect_ring({}, ring);auto painter = player.begin_painting(*surface, storage, cache, nullptr);- list->replay(painter, 0);+ builder.replay(painter, 0);player.end_painting();surface->read_into_bitmap(*bitmap);