Truly independent web browser
LibCompositing+LibWeb: Keep a display list's tree in its Rust storage
Aliaksandr Kalenik4e7690a9f4a7
diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.cpp b/Libraries/LibCompositing/DisplayList/DisplayList.cppindex b77197039b7..54c99a22758 100644--- a/Libraries/LibCompositing/DisplayList/DisplayList.cpp+++ b/Libraries/LibCompositing/DisplayList/DisplayList.cpp@@ -37,21 +37,29 @@ DisplayList::~DisplayList()RustFFI::display_list_storage_release(m_storage);}-NonnullRefPtr<DisplayList> DisplayList::create(AccumulatedVisualContextTree const& visual_context_tree)+NonnullRefPtr<DisplayList> DisplayList::adopt_rust_storage(void const* retained_storage){- return adopt_ref(*new DisplayList(visual_context_tree.structural_epoch(), next_id(), RustFFI::display_list_storage_create_empty(), {}, Gfx::Color::Transparent, {}));+ 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::adopt_rust_command_storage(AccumulatedVisualContextTree const& visual_context_tree, void const* recorded)+NonnullRefPtr<DisplayList> DisplayList::create_empty(){- VERIFY(recorded);- return adopt_ref(*new DisplayList(visual_context_tree.structural_epoch(), next_id(), RustFFI::display_list_storage_adopt_recorded(recorded), {}, Gfx::Color::Transparent, {}));+ return adopt_rust_storage(RustFFI::display_list_storage_create_empty());}-NonnullRefPtr<DisplayList> DisplayList::share_rust_command_storage(AccumulatedVisualContextTree const& visual_context_tree, void const* recorded)+NonnullRefPtr<DisplayList> DisplayList::adopt_rust_recording(void const* retained_commands, void const* retained_visual_context_tree){- VERIFY(recorded);- return adopt_rust_command_storage(visual_context_tree, RustFFI::display_list_retain_command_storage(recorded));+ 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(Properties properties, void const* storage)@@ -89,16 +97,33 @@ DisplayList::ReferencedResourceIds DisplayList::referenced_resource_ids() const};}-bool DisplayList::requires_direct_replay_without_nested_lists(AccumulatedVisualContextTree const& visual_context_tree) const+bool DisplayList::was_recorded_against(void const* lent_visual_context_tree) const{- VERIFY(m_compatible_visual_context_tree_structural_epoch == visual_context_tree.structural_epoch());- return RustFFI::display_list_storage_requires_direct_replay_without_nested_lists(m_storage, visual_context_tree.rust_handle());+ return RustFFI::display_list_storage_was_recorded_against(m_storage, lent_visual_context_tree);}-void DisplayList::replay(AccumulatedVisualContextTree const& visual_context_tree, RustFFI::FfiRasterPainter const& painter, i64 time_nanoseconds) const+ByteBuffer DisplayList::serialized_visual_context_tree() const{- VERIFY(m_compatible_visual_context_tree_structural_epoch == visual_context_tree.structural_epoch());- RustFFI::display_list_replay(visual_context_tree.rust_handle(), m_storage, m_root_group_color, time_nanoseconds, &painter);+ 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@@ -160,13 +185,6 @@ RustFFI::FfiDisplayList DisplayList::for_scroll_logic(ReadonlyBytes encoded_asyn};}-ErrorOr<void> validate_display_list_references_live_visual_context_nodes(DisplayList const& display_list, AccumulatedVisualContextTree const& visual_context_tree)-{- if (!RustFFI::display_list_references_only_live_visual_context_nodes(visual_context_tree.rust_handle(), display_list.rust_handle()))- return Error::from_string_literal("Display list references a visual context node that is not live");- return {};-}-}namespace IPC {diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.h b/Libraries/LibCompositing/DisplayList/DisplayList.hindex 82b23228dcf..f4324a04997 100644--- a/Libraries/LibCompositing/DisplayList/DisplayList.h+++ b/Libraries/LibCompositing/DisplayList/DisplayList.h@@ -8,12 +8,12 @@#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/AccumulatedVisualContext.h>#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibCompositing/Export.h>#include <LibCompositing/Forward.h>@@ -60,12 +60,17 @@ public:Gfx::Color root_group_color { Gfx::Color::Transparent };};- // An empty list.- static NonnullRefPtr<DisplayList> create(AccumulatedVisualContextTree const&);- // Adopts a strong reference to an immutable Rust recording, including its run table.- static NonnullRefPtr<DisplayList> adopt_rust_command_storage(AccumulatedVisualContextTree const&, void const*);- // Shares an immutable Rust recording that someone else holds, taking a strong reference of its own.- static NonnullRefPtr<DisplayList> share_rust_command_storage(AccumulatedVisualContextTree const&, void const*);+ // 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.@@ -105,13 +110,17 @@ public:ReadonlySpan<u64> canvases;};ReferencedResourceIds referenced_resource_ids() const;- // Whether reusing a raster of the list can produce different pixels than replaying it in place, leaving out the- // display lists it nests.- bool requires_direct_replay_without_nested_lists(AccumulatedVisualContextTree const&) const;- // Replays the list through a painter, against the visual context tree it was made for, with nothing scrolled and- // a blinking caret as it shows at the time given.- void replay(AccumulatedVisualContextTree const&, RustFFI::FfiRasterPainter const&, i64 time_nanoseconds) 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.@@ -133,8 +142,6 @@ private:friend ErrorOr<T> IPC::decode(IPC::Decoder&);};-COMPOSITING_API ErrorOr<void> validate_display_list_references_live_visual_context_nodes(DisplayList const&, AccumulatedVisualContextTree const&);-}namespace IPC {diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cppindex 85c32947415..93bc0369ee4 100644--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp@@ -55,21 +55,18 @@ void DisplayListResourceSet::include(DisplayListResourceSet const& other)display_lists.set(id, AK::HashSetExistingEntryBehavior::Keep);}-DisplayListResource::DisplayListResource(NonnullRefPtr<DisplayList> display_list, AccumulatedVisualContextTree visual_context_tree)+DisplayListResource::DisplayListResource(NonnullRefPtr<DisplayList> display_list): display_list(move(display_list))- , visual_context_tree(move(visual_context_tree)){}-DisplayListResource::DisplayListResource(NonnullRefPtr<DisplayList const> display_list, AccumulatedVisualContextTree visual_context_tree)+DisplayListResource::DisplayListResource(NonnullRefPtr<DisplayList const> display_list): display_list(move(display_list))- , visual_context_tree(move(visual_context_tree)){}-DisplayListResource::DisplayListResource(DisplayList const& display_list, AccumulatedVisualContextTree visual_context_tree)+DisplayListResource::DisplayListResource(DisplayList const& display_list): display_list(display_list)- , visual_context_tree(move(visual_context_tree)){}@@ -149,16 +146,6 @@ VideoSinkResourceId DisplayListResourceStorage::add_video_sink(VideoSinkResourcereturn id;}-DisplayListResourceId DisplayListResourceStorage::add_display_list(NonnullRefPtr<DisplayList const> display_list, AccumulatedVisualContextTree const& visual_context_tree)-{- m_has_resources_added_since_last_retain = true;- auto id = display_list->id();- m_display_lists.ensure(id, [&] {- return DisplayListResource { move(display_list), visual_context_tree };- });- return { id };-}-DisplayListResourceId DisplayListResourceStorage::add_display_list(DisplayListResource&& resource){m_has_resources_added_since_last_retain = true;@@ -194,45 +181,6 @@ Gfx::DecodedImageFrame const& DisplayListResourceStorage::image_frame(ImageFramereturn m_image_frames.get(id.value()).value()->frame;}-bool DisplayListResourceStorage::display_list_requires_direct_replay(DisplayListResourceId id) const-{- HashTable<u64> visited_display_lists;- return nested_display_list_requires_direct_replay(id, visited_display_lists);-}--// Determines whether reusing a rasterization of the display list can produce different pixels than replaying it-// in place on every frame. That is the case when a destination-reading operation (a non-normal blend mode on a-// command or a visual context effect, or a backdrop filter carried by a visual context effect) can see canvas-// content painted before the display list began, or when the list draws live-// content that changes underneath its immutable command stream (video frames are updated in place under a stable-// resource id, canvas surfaces and composited child contexts are resolved at replay time). Destination-reading-// operations enclosed in a save layer recorded within the list only ever read within-list content, so they do-// not require direct replay. The verdict is intrinsic to the list and memoized until the list is removed.-bool DisplayListResourceStorage::nested_display_list_requires_direct_replay(DisplayListResourceId id, HashTable<u64>& visited_display_lists) const-{- if (auto memoized = m_display_list_requires_direct_replay.get(id.value()); memoized.has_value())- return *memoized;-- visited_display_lists.set(id.value());- auto const& list_resource = display_list_resource(id);-- bool requires_direct_replay = list_resource.display_list->requires_direct_replay_without_nested_lists(list_resource.visual_context_tree);- // NB: A nested list's live content matters at any depth, and its unisolated destination reads matter when its- // command is not enclosed in a layer; recursing unconditionally is slightly conservative for the latter.- for (auto nested_id : list_resource.display_list->referenced_resource_ids().display_lists) {- if (requires_direct_replay)- break;- DisplayListResourceId nested_display_list_id { nested_id };- if (visited_display_lists.set(nested_display_list_id.value()) != HashSetResult::InsertedNewEntry)- continue;- if (has_display_list(nested_display_list_id))- requires_direct_replay = nested_display_list_requires_direct_replay(nested_display_list_id, visited_display_lists);- }-- m_display_list_requires_direct_replay.set(id.value(), requires_direct_replay);- return requires_direct_replay;-}-void DisplayListResourceStorage::collect_referenced_resources(DisplayList const& display_list,DisplayListResourceSet& referenced_resources) const@@ -255,7 +203,23 @@ void DisplayListResourceStorage::add_referenced_display_list(DisplayListResourceif (!has_display_list(id))return;collect_referenced_resources(display_list(id), referenced_resources);- collect_referenced_resources(display_list_visual_context_tree(id), referenced_resources);+ collect_resources_referenced_by_visual_context_tree(display_list(id), referenced_resources);+}++void DisplayListResourceStorage::collect_resources_referenced_by_visual_context_tree(+ DisplayList const& display_list,+ DisplayListResourceSet& referenced_resources) const+{+ display_list.for_each_visual_context_tree_filter_image_frame_id([&](u64 image_id) {+ referenced_resources.image_frames.set(ImageFrameResourceId { image_id }, AK::HashSetExistingEntryBehavior::Keep);+ });+}++DisplayListResourceSet DisplayListResourceStorage::collect_resources_referenced_by_visual_context_tree(DisplayList const& display_list) const+{+ DisplayListResourceSet referenced_resources;+ collect_resources_referenced_by_visual_context_tree(display_list, referenced_resources);+ return referenced_resources;}void DisplayListResourceStorage::collect_referenced_resources(@@ -281,13 +245,6 @@ DisplayListResourceSet DisplayListResourceStorage::collect_referenced_resources(return referenced_resources;}-static ErrorOr<void> validate_display_list_against_visual_context_tree(DisplayList const& display_list, AccumulatedVisualContextTree const& visual_context_tree)-{- if (display_list.compatible_visual_context_tree_structural_epoch() != visual_context_tree.structural_epoch())- return Error::from_string_literal("Display list was recorded against another visual context tree");- return validate_display_list_references_live_visual_context_nodes(display_list, visual_context_tree);-}-static ErrorOr<void> validate_resources_are_present(DisplayListResourceStorage const& storage, DisplayListResourceSet const& resources){for (auto id : resources.fonts) {@@ -305,30 +262,14 @@ static ErrorOr<void> validate_resources_are_present(DisplayListResourceStorage creturn {};}-ErrorOr<DisplayListResourceTransaction> DisplayListResourceStorage::create_self_contained_transaction(DisplayList const& display_list, AccumulatedVisualContextTree const& visual_context_tree) const+ErrorOr<DisplayListResourceTransaction> DisplayListResourceStorage::create_self_contained_transaction(DisplayList const& display_list) const{auto resources = collect_referenced_resources(display_list);- resources.include(collect_referenced_resources(visual_context_tree));+ resources.include(collect_resources_referenced_by_visual_context_tree(display_list));TRY(validate_resources_are_present(*this, resources));return create_transaction({}, resources);}-ErrorOr<void> DisplayListResourceStorage::validate_for_replay(DisplayList const& display_list, AccumulatedVisualContextTree const& visual_context_tree) const-{- TRY(validate_display_list_against_visual_context_tree(display_list, visual_context_tree));- auto resources = collect_referenced_resources(display_list);- resources.include(collect_referenced_resources(visual_context_tree));- TRY(validate_resources_are_present(*this, resources));- for (auto id : resources.display_lists) {- auto const& nested_display_list = this->display_list(id);- TRY(validate_display_list_against_visual_context_tree(nested_display_list, display_list_visual_context_tree(id)));- // Replay follows nested lists with no depth limit, so a list must not reach itself.- if (collect_referenced_resources(nested_display_list).display_lists.contains(id))- return Error::from_string_literal("Nested display list refers to itself");- }- return {};-}-DisplayListResourceTransaction DisplayListResourceStorage::create_transaction(DisplayListResourceSet const& previous,DisplayListResourceSet const& current) const@@ -351,7 +292,7 @@ DisplayListResourceTransaction DisplayListResourceStorage::create_transaction(}for (auto id : current.display_lists) {if (!previous.display_lists.contains(id))- transaction.display_lists.append({ display_list_resource(id).display_list, display_list_visual_context_tree(id) });+ transaction.display_lists.append({ display_list_resource(id).display_list });}for (auto id : previous.fonts) {@@ -407,7 +348,6 @@ DisplayListResourceSet DisplayListResourceStorage::apply_transaction(DisplayListfor (auto id : transaction.display_list_ids_to_remove) {if (m_display_lists.remove(id.value()))removed_resources.display_lists.set(id);- m_display_list_requires_direct_replay.remove(id.value());}return removed_resources;}@@ -442,9 +382,6 @@ DisplayListResourceSet DisplayListResourceStorage::retain_only(DisplayListResourremoved_resources.display_lists.set(DisplayListResourceId { id });return true;});- m_display_list_requires_direct_replay.remove_all_matching([&](auto id, auto const&) {- return !resource_set.display_lists.contains(DisplayListResourceId { id });- });m_has_resources_added_since_last_retain = false;return removed_resources;}diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.h b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.hindex 82c00911c65..42fb20e1c6e 100644--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.h+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.h@@ -70,13 +70,13 @@ enum class FontSmoothing : u8 {struct DisplayListStoredImageFrameResource;struct DisplayListStoredVideoSinkResource;+// A display list recorded in this process, which goes with the visual context tree it was recorded against.struct COMPOSITING_API DisplayListResource {- DisplayListResource(NonnullRefPtr<DisplayList>, AccumulatedVisualContextTree);- DisplayListResource(NonnullRefPtr<DisplayList const>, AccumulatedVisualContextTree);- DisplayListResource(DisplayList const&, AccumulatedVisualContextTree);+ DisplayListResource(NonnullRefPtr<DisplayList>);+ DisplayListResource(NonnullRefPtr<DisplayList const>);+ DisplayListResource(DisplayList const&);NonnullRefPtr<DisplayList const> display_list;- AccumulatedVisualContextTree visual_context_tree;};struct DisplayListResourceTransaction {@@ -103,20 +103,21 @@ public:FontResourceId add_font(Gfx::Font const&);ImageFrameResourceId add_image_frame(Gfx::DecodedImageFrame const&);VideoSinkResourceId add_video_sink(VideoSinkResourceId, Media::VideoSinkHandle);- DisplayListResourceId add_display_list(NonnullRefPtr<DisplayList const>, AccumulatedVisualContextTree const&);DisplayListResourceId add_display_list(DisplayListResource&&);bool has_display_list(DisplayListResourceId id) const { return m_display_lists.contains(id.value()); }void set_font(FontResourceId, NonnullRefPtr<Gfx::Font const>);// Returns the resources that the transaction removed or replaced, so whatever was made from them can be dropped.DisplayListResourceSet apply_transaction(DisplayListResourceTransaction&&);DisplayListResourceTransaction create_transaction(DisplayListResourceSet const& previous, DisplayListResourceSet const& current) const;+ // What the list's commands refer to, with what the display lists they nest, and the trees those were recorded+ // against, refer to.DisplayListResourceSet collect_referenced_resources(DisplayList const&) const;+ // What the visual context tree a list recorded in this process was recorded against refers to.+ DisplayListResourceSet collect_resources_referenced_by_visual_context_tree(DisplayList const&) const;DisplayListResourceSet collect_referenced_resources(AccumulatedVisualContextTree const&) const;- // Carries everything the list and its tree refer to, for a receiver that holds none of it yet.- ErrorOr<DisplayListResourceTransaction> create_self_contained_transaction(DisplayList const&, AccumulatedVisualContextTree const&) const;- // Checks that the list, and each list nested in it, can replay against what this storage holds, and that no nested- // list reaches itself.- ErrorOr<void> validate_for_replay(DisplayList const&, AccumulatedVisualContextTree const&) const;+ // Carries everything a list recorded in this process and its tree refer to, for a receiver that holds none of it+ // yet.+ ErrorOr<DisplayListResourceTransaction> create_self_contained_transaction(DisplayList const&) const;// Returns the resources that were removed.DisplayListResourceSet retain_only(DisplayListResourceSet const&);bool has_resources_added_since_last_retain() const { return m_has_resources_added_since_last_retain; }@@ -133,22 +134,18 @@ public:Gfx::DecodedImageFrame const& image_frame(ImageFrameResourceId) const;// Whether force-dark should invert this image, worked out once and cached.bool image_frame_should_force_dark(ImageFrameResourceId) const;- // Whether reusing a raster of the display list could show other pixels than a replay in place, worked out once- // and cached.- bool display_list_requires_direct_replay(DisplayListResourceId) const;RefPtr<Media::DisplayingVideoSink const> video_sink(VideoSinkResourceId id) const;Optional<Media::VideoSinkHandle> video_sink_handle(VideoSinkResourceId id) const { return m_video_sink_handles.get(id.value()); }HashMap<u64, Media::VideoSinkHandle> const& video_sink_handles() const { return m_video_sink_handles; }DisplayListResource const& display_list_resource(DisplayListResourceId id) const { return m_display_lists.get(id.value()).value(); }DisplayList const& display_list(DisplayListResourceId id) const { return *display_list_resource(id).display_list; }- AccumulatedVisualContextTree const& display_list_visual_context_tree(DisplayListResourceId id) const { return display_list_resource(id).visual_context_tree; }private:void set_image_frame(ImageFrameResourceId, Gfx::DecodedImageFrame);void collect_referenced_resources(DisplayList const&, DisplayListResourceSet&) const;+ void collect_resources_referenced_by_visual_context_tree(DisplayList const&, DisplayListResourceSet&) const;void collect_referenced_resources(AccumulatedVisualContextTree const&, DisplayListResourceSet&) const;void add_referenced_display_list(DisplayListResourceId, DisplayListResourceSet&) const;- bool nested_display_list_requires_direct_replay(DisplayListResourceId, HashTable<u64>& visited_display_lists) const;bool m_has_resources_added_since_last_retain { false };HashMap<u64, NonnullRefPtr<Gfx::Font const>> m_fonts;@@ -158,7 +155,6 @@ private:HashMap<u64, Media::VideoSinkHandle> m_video_sink_handles;HashMap<u64, NonnullOwnPtr<DisplayListStoredVideoSinkResource>> m_video_sinks;HashMap<u64, DisplayListResource> m_display_lists;- mutable HashMap<u64, bool> m_display_list_requires_direct_replay;};}diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cpp b/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cppindex 05b145f1502..de92264b909 100644--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cpp+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cpp@@ -96,7 +96,7 @@ ErrorOr<void> encode(Encoder& encoder, Compositing::DisplayListResourceTransactiTRY(encoder.encode_size(transaction.display_lists.size()));for (auto const& display_list : transaction.display_lists) {TRY(encoder.encode(*display_list.display_list));- TRY(encoder.encode(display_list.visual_context_tree));+ TRY(encoder.encode(display_list.display_list->serialized_visual_context_tree()));}TRY(encoder.encode(transaction.font_ids_to_remove));TRY(encoder.encode(transaction.image_frame_ids_to_remove));@@ -112,23 +112,16 @@ ErrorOr<Compositing::DisplayListResourceTransaction> decode(Decoder& decoder)auto image_frames = TRY(decoder.decode<Vector<Compositing::DisplayListImageFrameResource>>());auto video_sinks = TRY(decoder.decode<Vector<Compositing::DisplayListVideoSinkResource>>());- auto display_list_count = TRY(decoder.decode_size());- Vector<Compositing::DisplayListResource> display_lists;- TRY(display_lists.try_ensure_capacity(display_list_count));- for (size_t i = 0; i < display_list_count; ++i) {- auto display_list = TRY(decoder.decode<NonnullRefPtr<Compositing::DisplayList>>());- auto visual_context_tree = TRY(decoder.decode<Compositing::AccumulatedVisualContextTree>());- if (display_list->compatible_visual_context_tree_structural_epoch() != visual_context_tree.structural_epoch())- return Error::from_string_literal("Display list resource does not match its visual context tree");- TRY(Compositing::validate_display_list_references_live_visual_context_nodes(*display_list, visual_context_tree));- display_lists.unchecked_append({ move(display_list), move(visual_context_tree) });- }+ // Only the compositor's Rust receives nested display lists, with the visual context trees they were recorded+ // against.+ if (TRY(decoder.decode_size()) != 0)+ return Error::from_string_literal("Display list resources only go to the compositor's Rust");return Compositing::DisplayListResourceTransaction {.fonts = move(fonts),.image_frames = move(image_frames),.video_sinks = move(video_sinks),- .display_lists = move(display_lists),+ .display_lists = {},.font_ids_to_remove = TRY(decoder.decode<Vector<Compositing::FontResourceId>>()),.image_frame_ids_to_remove = TRY(decoder.decode<Vector<Compositing::ImageFrameResourceId>>()),.video_sink_ids_to_remove = TRY(decoder.decode<Vector<Compositing::VideoSinkResourceId>>()),diff --git a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cpp b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cppindex 9b16b2e109e..55419a844bd 100644--- a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cpp+++ b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.cpp@@ -26,21 +26,19 @@ EffectNodeIndex VisualContextTreeTestBuilder::append_image_filter(u64 image_id,return EffectNodeIndex { RustFFI::visual_context_tree_test_builder_append_image_filter(m_builder, image_id, rect) };}-NonnullRefPtr<DisplayList> VisualContextTreeTestBuilder::filled_rect_display_list(AccumulatedVisualContextTree const& tree, ContextRef context, Gfx::IntRect rect, Gfx::Color color)+void VisualContextTreeTestBuilder::finish(){- return DisplayList::adopt_rust_command_storage(tree, RustFFI::visual_context_tree_test_builder_filled_rect(rect, color, context));+ RustFFI::visual_context_tree_test_builder_finish(m_builder);}-NonnullRefPtr<DisplayList> VisualContextTreeTestBuilder::rounded_rect_ring_display_list(AccumulatedVisualContextTree const& tree, ContextRef context, FillRoundedRectRing const& ring)+NonnullRefPtr<DisplayList> VisualContextTreeTestBuilder::filled_rect_display_list(ContextRef context, Gfx::IntRect rect, Gfx::Color color) const{- return DisplayList::adopt_rust_command_storage(tree, RustFFI::visual_context_tree_test_builder_rounded_rect_ring(ring, context));+ return DisplayList::adopt_rust_storage(RustFFI::visual_context_tree_test_builder_filled_rect(m_builder, rect, color, context));}-AccumulatedVisualContextTree VisualContextTreeTestBuilder::finish()+NonnullRefPtr<DisplayList> VisualContextTreeTestBuilder::rounded_rect_ring_display_list(ContextRef context, FillRoundedRectRing const& ring) const{- VERIFY(m_builder);- auto const* retained_tree = Compositing::RustFFI::visual_context_tree_test_builder_finish(exchange(m_builder, nullptr));- return AccumulatedVisualContextTree::adopt_rust_handle(retained_tree);+ return DisplayList::adopt_rust_storage(RustFFI::visual_context_tree_test_builder_rounded_rect_ring(m_builder, ring, context));}}diff --git a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.h b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.hindex 3a5d01b169d..ee949b08843 100644--- a/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.h+++ b/Libraries/LibCompositing/DisplayList/VisualContextTreeTestBuilder.h@@ -6,11 +6,12 @@#pragma once+#include <AK/NonnullRefPtr.h>#include <AK/Optional.h>-#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>#include <LibCompositing/DisplayList/ContextRef.h>#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibCompositing/Export.h>+#include <LibCompositing/Forward.h>#include <LibGfx/Color.h>#include <LibGfx/CornerRadii.h>#include <LibGfx/Forward.h>@@ -32,10 +33,11 @@ public:~VisualContextTreeTestBuilder();EffectNodeIndex append_image_filter(u64 image_id, Gfx::IntRect);- static NonnullRefPtr<DisplayList> filled_rect_display_list(AccumulatedVisualContextTree const&, ContextRef, Gfx::IntRect, Gfx::Color);- static NonnullRefPtr<DisplayList> rounded_rect_ring_display_list(AccumulatedVisualContextTree const&, ContextRef, FillRoundedRectRing const&);+ // Ends adding nodes. The lists below are recorded against the tree as it is then.+ void finish();- AccumulatedVisualContextTree finish();+ NonnullRefPtr<DisplayList> filled_rect_display_list(ContextRef, Gfx::IntRect, Gfx::Color) const;+ NonnullRefPtr<DisplayList> rounded_rect_ring_display_list(ContextRef, FillRoundedRectRing const&) const;private:void* m_builder { nullptr };diff --git a/Libraries/LibCompositing/Rust/src/display_list/storage.rs b/Libraries/LibCompositing/Rust/src/display_list/storage.rsindex cca2fb8b9e3..9b18d88e174 100644--- a/Libraries/LibCompositing/Rust/src/display_list/storage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/storage.rs@@ -4,14 +4,15 @@* SPDX-License-Identifier: BSD-2-Clause*/-//! The tape of one display list as C++ holds it: a recording this process made, 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 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.use super::builder::RecordedDisplayList;use super::commands::{ContextRef, DisplayListCommandRun};use super::effect_clip_plan::EffectClipPlan;-use super::summary::{DisplayListSummary, requires_direct_replay_without_nested_lists, summarize};+use super::summary::{DisplayListSummary, summarize};use super::validate::validate_tape;use crate::visual_context::VisualContextTree;use std::ffi::c_void;@@ -88,6 +89,9 @@ pub struct DisplayListStorage {// 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.effect_clip_plan: OnceLock<EffectClipPlan>,@@ -100,7 +104,7 @@ unsafe impl Send for DisplayListStorage {}unsafe impl Sync for DisplayListStorage {}impl DisplayListStorage {- fn new(tape: Tape) -> Arc<Self> {+ 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),@@ -109,6 +113,7 @@ impl DisplayListStorage {Arc::new(Self {view,tape,+ visual_context_tree,effect_clip_plan: OnceLock::new(),summary: OnceLock::new(),})@@ -130,6 +135,16 @@ impl DisplayListStorage {}}+ pub fn visual_context_tree(&self) -> Option<&Arc<VisualContextTree>> {+ 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()))@@ -155,29 +170,121 @@ 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::new(+ Tape::Recorded(recorded),+ Some(visual_context_tree),+ ))+}++/// 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))+ 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-/// `recorded` must point to a live RecordedDisplayList held by an Arc. Returns `recorded` with one-/// more Arc reference to it, which the caller passes to `display_list_storage_adopt_recorded`.+/// `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_retain_command_storage(recorded: *const c_void) -> *const c_void {- assert!(!recorded.is_null());- unsafe { Arc::increment_strong_count(recorded.cast::<RecordedDisplayList>()) };- recorded+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-/// `recorded` must be one unconsumed Arc reference to a RecordedDisplayList, which the returned-/// storage takes over.+/// `storage` must be a live storage handle of a list this process recorded.#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_adopt_recorded(recorded: *const c_void) -> *const c_void {- assert!(!recorded.is_null());- let recorded = unsafe { Arc::from_raw(recorded.cast::<RecordedDisplayList>()) };- into_handle(DisplayListStorage::new(Tape::Recorded(recorded)))+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@@ -306,7 +413,7 @@ pub fn receive_packed(let mut bytes = AlignedBytes::try_zeroed(tape_size).ok_or("Display list is too large to receive")?;bytes.as_mut_slice().copy_from_slice(&packed[..tape_size]);let command_runs = validate_tape(bytes.as_slice(), &packed[tape_size..size])?;- Ok(DisplayListStorage::new(Tape::Received { bytes, command_runs }))+ Ok(DisplayListStorage::new(Tape::Received { bytes, command_runs }, None))}/// The size of the storage's tape and run table packed for transport.@@ -405,7 +512,7 @@ pub unsafe fn receive_packed_from_shared_memory(}}let command_runs = validate_tape(bytes.as_slice(), &run_bytes)?;- Ok(DisplayListStorage::new(Tape::Received { bytes, command_runs }))+ Ok(DisplayListStorage::new(Tape::Received { bytes, command_runs }, None))}#[derive(Clone, Copy, Debug)]@@ -447,19 +554,6 @@ pub unsafe extern "C" fn display_list_storage_referenced_resource_ids(}}-/// # Safety-/// `storage` must be a live storage handle and `tree` a live retained tree handle whose nodes the-/// list's runs name.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn display_list_storage_requires_direct_replay_without_nested_lists(- storage: *const c_void,- tree: *const c_void,-) -> bool {- let storage = unsafe { storage_from_handle(storage) };- let tree = unsafe { crate::ffi::tree_from_handle(tree) };- requires_direct_replay_without_nested_lists(storage.bytes(), storage.command_runs(), tree)-}-// A tape and run table that C++ writes into before they are checked.pub struct PendingDisplayListStorage {bytes: AlignedBytes,@@ -522,10 +616,13 @@ pub unsafe extern "C" fn display_list_storage_finish(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,- })),+ 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 {@@ -559,7 +656,8 @@ mod tests {..Default::default()});let published = Arc::into_raw(recorded.clone());- let storage = unsafe { display_list_storage_adopt_recorded(published.cast()) };+ let tree = Arc::into_raw(Arc::new(VisualContextTree::create_identity()));+ let storage = unsafe { display_list_storage_adopt_recorded(published.cast(), tree.cast()) };Arc::make_mut(&mut recorded).bytes[0] = 9;assert_eq!(unsafe { tape_of(storage) }.0, &[1, 2, 3]);drop(recorded);diff --git a/Libraries/LibCompositing/Rust/src/ffi.rs b/Libraries/LibCompositing/Rust/src/ffi.rsindex 1400b0e168d..9fb84a6385b 100644--- a/Libraries/LibCompositing/Rust/src/ffi.rs+++ b/Libraries/LibCompositing/Rust/src/ffi.rs@@ -78,16 +78,15 @@ pub unsafe fn replay_display_list_storage();}-/// Replays a list with nothing scrolled, showing a blinking caret as it is at `time_nanoseconds`. The display lists it-/// nests are looked up through the 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///-/// `tree` must be a live retained tree handle of the structural epoch the storage was recorded-/// against, `storage` a live storage handle, and `painter` must be live. The painter callbacks run synchronously.+/// `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(- tree: *const c_void,storage: *const c_void,root_group_color: libgfx_rust::Color,time_nanoseconds: i64,@@ -98,16 +97,12 @@ pub unsafe extern "C" fn display_list_replay(time_nanoseconds,&crate::display_list::replay::NoNestedDisplayLists,);- // SAFETY: The caller guarantees live handles and a live painter for the duration of the call.+ // SAFETY: The caller guarantees a live handle and a live painter for the duration of the call.unsafe {- replay_display_list_storage(- tree_from_handle(tree),- storage,- root_group_color,- &frame,- Default::default(),- painter,- );+ 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);};}@@ -262,43 +257,47 @@ pub unsafe extern "C" fn visual_context_tree_for_each_effects_filter_image_frametree.for_each_effects_filter_image_frame_id(&mut |id| unsafe { visit(context, id) });}+/// 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>),+}+/// # Safety////// Returns a builder handle for hand-built test trees rooted at an identity visual viewport-/// transform; every builder call must receive it until `visual_context_tree_test_builder_finish`-/// or `visual_context_tree_test_builder_destroy` consumes it.+/// transform; every builder call must receive it until `visual_context_tree_test_builder_destroy`+/// consumes it.#[unsafe(no_mangle)]pub unsafe extern "C" fn visual_context_tree_test_builder_create() -> *mut c_void {- let tree = crate::visual_context::VisualContextTree::create(crate::visual_context::TransformData {- matrix: libgfx_rust::FloatMatrix4x4::identity(),- origin: libgfx_rust::FloatPoint::default(),- sorting_context_root_index: None,- flattens_inherited_transform: false,- role: crate::visual_context::TransformDataRole::CssTransform,- synthetic_plane: false,- establishes_sorting_context: false,- bounds: libgfx_rust::FloatRect::default(),- });+ let tree = TestBuilderTree::Building(Box::new(crate::visual_context::VisualContextTree::create_identity()));Box::into_raw(Box::new(tree)).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 crate::visual_context::VisualContextTree {+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::<crate::visual_context::VisualContextTree>() }+ unsafe { &mut *builder.cast::<TestBuilderTree>() }}+/// Ends adding nodes: the lists recorded from here on are recorded against the tree as it is.+////// # Safety///-/// `builder` must be a live handle from `visual_context_tree_test_builder_create`, consumed by this-/// call. Returns a retained tree handle the caller owns.+/// `builder` must be a live handle from `visual_context_tree_test_builder_create` that was not finished yet.#[unsafe(no_mangle)]-pub unsafe extern "C" fn visual_context_tree_test_builder_finish(builder: *mut c_void) -> *const c_void {- // SAFETY: The caller hands over the boxed tree the create call returned.- let tree = unsafe { Box::from_raw(builder.cast::<crate::visual_context::VisualContextTree>()) };- std::sync::Arc::into_raw(std::sync::Arc::new(*tree)).cast()+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 TestBuilderTree::Building(building) = std::mem::replace(+ tree,+ TestBuilderTree::Finished(Arc::new(crate::visual_context::VisualContextTree::create_identity())),+ ) else {+ panic!("a test tree is finished once");+ };+ *tree = TestBuilderTree::Finished(Arc::new(*building));}/// # Safety@@ -311,7 +310,7 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_destroy(builder: *mutreturn;}// SAFETY: The caller hands over the boxed tree the create call returned.- drop(unsafe { Box::from_raw(builder.cast::<crate::visual_context::VisualContextTree>()) });+ drop(unsafe { Box::from_raw(builder.cast::<TestBuilderTree>()) });}#[unsafe(no_mangle)]@@ -416,29 +415,41 @@ pub unsafe fn tree_sharing_handle(visual_context_tree: *const c_void) -> Accumulconst ENCODED_IN_THIS_PROCESS: &str = "a value this process encoded for itself decodes";+/// The list a document of this process recorded, which C++ lends, and the tree it was recorded against.+///+/// # Safety+///+/// The storage of `display_list` must be a live storage handle of a list this process recorded.+unsafe fn recorded_display_list_and_tree(+ display_list: &FfiDisplayList<'_>,+) -> (DisplayList, AccumulatedVisualContextTree) {+ // SAFETY: The caller lends a live storage handle.+ let tree = unsafe { storage_from_handle(display_list.storage) }+ .visual_context_tree()+ .cloned()+ .expect("a list this process recorded holds the tree it was recorded against");+ // SAFETY: As above.+ let display_list = unsafe { display_list.share() }.expect(ENCODED_IN_THIS_PROCESS);+ (display_list, AccumulatedVisualContextTree::from_arc(tree))+}+/// The scrolling state of no display list is the empty one.////// # Safety///-/// The storage of `display_list` must be a live display list storage handle, and `visual_context_tree` a live tree-/// handle where there is a display list. `receive` must copy the UTF-8 bytes it keeps synchronously.+/// The storage of `display_list` must be a live storage handle of a list this process recorded, where there is a+/// display list. `receive` must copy the UTF-8 bytes it keeps synchronously.#[unsafe(no_mangle)]pub unsafe extern "C" fn recorded_display_list_async_scrolling_state_json(display_list: Option<&FfiDisplayList<'_>>,- visual_context_tree: *const c_void,receiver: *mut c_void,receive: unsafe extern "C" fn(*mut c_void, ak::Span<'_, u8>),) {let state = match display_list {None => crate::scrolling::AsyncScrollingState::default(),Some(display_list) => {- // SAFETY: The caller lends live storage and tree handles.- let (display_list, visual_context_tree) = unsafe {- (- display_list.share().expect(ENCODED_IN_THIS_PROCESS),- tree_sharing_handle(visual_context_tree),- )- };+ // SAFETY: The caller lends a live storage handle.+ let (display_list, visual_context_tree) = unsafe { recorded_display_list_and_tree(display_list) };crate::scrolling::async_scrolling_state_from(&display_list, visual_context_tree.as_arc())}};@@ -452,10 +463,9 @@ pub unsafe extern "C" fn recorded_display_list_async_scrolling_state_json(////// # Safety///-/// The storage of `display_list` and `visual_context_tree` must be live handles.+/// The storage of `display_list` must be a live storage handle of a list this process recorded.unsafe fn recorded_scroll_tree_of(display_list: &FfiDisplayList<'_>,- visual_context_tree: *const c_void,scroll_state_snapshot: EncodedValue<'_>,newest_wheel_event_listener_state_generation: u64,) -> (@@ -463,13 +473,8 @@ unsafe fn recorded_scroll_tree_of(AccumulatedVisualContextTree,crate::scrolling::WheelRoutingAdmission,) {- // SAFETY: The caller lends live storage and tree handles.- let (display_list, visual_context_tree) = unsafe {- (- display_list.share().expect(ENCODED_IN_THIS_PROCESS),- tree_sharing_handle(visual_context_tree),- )- };+ // SAFETY: The caller lends a live storage handle.+ let (display_list, visual_context_tree) = unsafe { recorded_display_list_and_tree(display_list) };let mut snapshot = scroll_state_snapshot.decode::<crate::scrolling::ScrollStateSnapshot>().expect(ENCODED_IN_THIS_PROCESS);@@ -500,11 +505,10 @@ pub struct FfiFirstWheelStepRouteForTesting {/// # Safety///-/// The storage of `display_list` and `visual_context_tree` must be live handles.+/// The storage of `display_list` must be a live storage handle of a list this process recorded.#[unsafe(no_mangle)]pub unsafe extern "C" fn recorded_display_list_route_first_wheel_step(display_list: &FfiDisplayList<'_>,- visual_context_tree: *const c_void,scroll_state_snapshot: EncodedValue<'_>,newest_wheel_event_listener_state_generation: u64,position: FloatPoint,@@ -514,7 +518,6 @@ pub unsafe extern "C" fn recorded_display_list_route_first_wheel_step(let (scroll_tree, visual_context_tree, admission) = unsafe {recorded_scroll_tree_of(display_list,- visual_context_tree,scroll_state_snapshot,newest_wheel_event_listener_state_generation,)@@ -543,16 +546,15 @@ pub unsafe extern "C" fn recorded_display_list_route_first_wheel_step(/// # Safety///-/// The storage of `display_list` and `visual_context_tree` must be live handles.+/// The storage of `display_list` must be a live storage handle of a list this process recorded.#[unsafe(no_mangle)]pub unsafe extern "C" fn recorded_display_list_blocks_wheel_event_at(display_list: &FfiDisplayList<'_>,- visual_context_tree: *const c_void,scroll_state_snapshot: EncodedValue<'_>,position: FloatPoint,) -> bool {- // SAFETY: The caller lends live handles.+ // SAFETY: The caller lends a live handle.let (scroll_tree, visual_context_tree, _) =- unsafe { recorded_scroll_tree_of(display_list, visual_context_tree, scroll_state_snapshot, 0) };+ unsafe { recorded_scroll_tree_of(display_list, scroll_state_snapshot, 0) };scroll_tree.blocks_wheel_event_at_position(&visual_context_tree, position)}diff --git a/Libraries/LibCompositing/Rust/src/test_builder.rs b/Libraries/LibCompositing/Rust/src/test_builder.rsindex 2b302709806..e236f89e759 100644--- a/Libraries/LibCompositing/Rust/src/test_builder.rs+++ b/Libraries/LibCompositing/Rust/src/test_builder.rs@@ -4,20 +4,38 @@* SPDX-License-Identifier: BSD-2-Clause*/+use crate::display_list::builder::DisplayListBuilder;use crate::display_list::commands::{ClipNodeIndex, ContextRef, EffectNodeIndex, FillRoundedRectRing};-use crate::ffi::test_builder_tree;+use crate::display_list::storage::recorded_storage_handle;+use crate::ffi::{TestBuilderTree, test_builder_tree};use std::ffi::c_void;+use std::sync::Arc;+/// A storage handle for what `builder` recorded, against the finished tree of `test_builder`.+////// # Safety///-/// `builder` must be a live handle from `visual_context_tree_test_builder_create`.+/// `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 {+ // SAFETY: Guaranteed by the caller.+ let TestBuilderTree::Finished(tree) = (unsafe { test_builder_tree(test_builder) }) else {+ panic!("lists are recorded against a finished test tree");+ };+ recorded_storage_handle(Arc::new(builder.finish()), tree.clone())+}++/// # Safety+///+/// `builder` must be a live handle from `visual_context_tree_test_builder_create` that was not finished yet.#[unsafe(no_mangle)]pub unsafe extern "C" fn visual_context_tree_test_builder_append_image_filter(builder: *mut c_void,image_id: u64,rect: libgfx_rust::IntRect,) -> u32 {- let tree = unsafe { test_builder_tree(builder) };+ let TestBuilderTree::Building(tree) = (unsafe { test_builder_tree(builder) }) else {+ panic!("nodes are added to a test tree before it is finished");+ };let filter = libgfx_rust::filter::Filter::Image {frame_id: image_id,src_rect: rect,@@ -39,15 +57,20 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_append_image_filter(.0}-/// Records a rectangle with the same canonical builder as production recordings. Returns one-/// owned Arc reference consumed by `display_list_storage_adopt_recorded`.+/// 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.+///+/// # Safety+///+/// `test_builder` must be a live, finished handle from `visual_context_tree_test_builder_create`.#[unsafe(no_mangle)]-pub extern "C" fn visual_context_tree_test_builder_filled_rect(+pub unsafe extern "C" fn visual_context_tree_test_builder_filled_rect(+ test_builder: *mut c_void,rect: libgfx_rust::IntRect,color: libgfx_rust::Color,context: ContextRef,) -> *const c_void {- let mut builder = crate::display_list::builder::DisplayListBuilder::new();+ let mut builder = DisplayListBuilder::new();builder.append(&crate::display_list::commands::FillRect {rect,@@ -58,17 +81,24 @@ pub extern "C" fn visual_context_tree_test_builder_filled_rect(&[],context,);- std::sync::Arc::into_raw(std::sync::Arc::new(builder.finish())).cast()+ // SAFETY: Guaranteed by the caller.+ unsafe { recorded_against_finished_tree(test_builder, builder) }}-/// Records a rounded rectangle ring. Returns one owned Arc reference consumed by-/// `display_list_storage_adopt_recorded`.+/// Records a rounded rectangle ring against the finished tree of `test_builder`. Returns a storage handle the caller+/// owns.+///+/// # Safety+///+/// `test_builder` must be a live, finished handle from `visual_context_tree_test_builder_create`.#[unsafe(no_mangle)]-pub extern "C" fn visual_context_tree_test_builder_rounded_rect_ring(+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 = crate::display_list::builder::DisplayListBuilder::new();+ let mut builder = DisplayListBuilder::new();builder.append(&ring, &[], context);- std::sync::Arc::into_raw(std::sync::Arc::new(builder.finish())).cast()+ // SAFETY: Guaranteed by the caller.+ unsafe { recorded_against_finished_tree(test_builder, builder) }}diff --git a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs b/Libraries/LibCompositing/Rust/src/visual_context/mod.rsindex a9b9d34902c..377755fa75f 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/mod.rs@@ -741,7 +741,7 @@ pub struct VisualContextTree {compositor_scroll_table: CompositorScrollTable,}-// A tree is shared by the arena and by the handles C++ retains; any thread may come to hold it.+// A tree is shared by the arena, recordings, display list storages and presentations; any thread may come to hold it.const _: () = {const fn assert_send_and_sync<T: Send + Sync>() {}assert_send_and_sync::<VisualContextTree>();@@ -900,6 +900,20 @@ impl VisualContextTree {}}+ // A tree with no node but an identity visual viewport transform, for a list that names no other node.+ pub fn create_identity() -> Self {+ Self::create(TransformData {+ matrix: libgfx_rust::FloatMatrix4x4::identity(),+ origin: libgfx_rust::FloatPoint::default(),+ sorting_context_root_index: None,+ flattens_inherited_transform: false,+ role: TransformDataRole::CssTransform,+ synthetic_plane: false,+ establishes_sorting_context: false,+ bounds: libgfx_rust::FloatRect::default(),+ })+ }+// A tree over decoded arrays: no slot is free or quarantined, the live counts are recounted.pub fn from_nodes(spatial_nodes: Vec<SpatialNode>,diff --git a/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.cpp b/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.cppindex a8633b2f972..71f652f96c5 100644--- a/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.cpp+++ b/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.cpp@@ -4,7 +4,6 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/RustFFI.h>#include <LibCompositing/Scrolling/RecordedDisplayListScrolling.h>@@ -19,27 +18,27 @@ static void receive_json(void* receiver, ReadonlyBytes bytes)*static_cast<String*>(receiver) = MUST(String::from_utf8(bytes));}-String async_scrolling_state_as_json(DisplayList const& display_list, AccumulatedVisualContextTree const& visual_context_tree)+String async_scrolling_state_as_json(DisplayList const& display_list){String json;EncodedAsyncScrollingMetadata async_scrolling_metadata { display_list.async_scrolling_metadata() };auto display_list_for_scroll_logic = display_list.for_scroll_logic(async_scrolling_metadata.bytes());- RustFFI::recorded_display_list_async_scrolling_state_json(&display_list_for_scroll_logic, visual_context_tree.rust_handle(), &json, receive_json);+ RustFFI::recorded_display_list_async_scrolling_state_json(&display_list_for_scroll_logic, &json, receive_json);return json;}String empty_async_scrolling_state_as_json(){String json;- RustFFI::recorded_display_list_async_scrolling_state_json(nullptr, nullptr, &json, receive_json);+ RustFFI::recorded_display_list_async_scrolling_state_json(nullptr, &json, receive_json);return json;}-FirstWheelStepRouteForTesting route_first_wheel_step_through_recorded_display_list(DisplayList const& display_list, AccumulatedVisualContextTree const& visual_context_tree, ReadonlyBytes encoded_scroll_state, u64 newest_wheel_event_listener_state_generation, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)+FirstWheelStepRouteForTesting route_first_wheel_step_through_recorded_display_list(DisplayList const& display_list, ReadonlyBytes encoded_scroll_state, u64 newest_wheel_event_listener_state_generation, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels){EncodedAsyncScrollingMetadata async_scrolling_metadata { display_list.async_scrolling_metadata() };auto display_list_for_scroll_logic = display_list.for_scroll_logic(async_scrolling_metadata.bytes());- auto route = RustFFI::recorded_display_list_route_first_wheel_step(&display_list_for_scroll_logic, visual_context_tree.rust_handle(), encoded_scroll_state, newest_wheel_event_listener_state_generation, position, delta_in_css_pixels);+ auto route = RustFFI::recorded_display_list_route_first_wheel_step(&display_list_for_scroll_logic, encoded_scroll_state, newest_wheel_event_listener_state_generation, position, delta_in_css_pixels);FirstWheelStepRouteForTesting result { .route = { route.decision }, .document_id = {} };if (route.has_scroller) {@@ -54,11 +53,11 @@ FirstWheelStepRouteForTesting route_first_wheel_step_through_recorded_display_lireturn result;}-bool recorded_display_list_blocks_wheel_event_at(DisplayList const& display_list, AccumulatedVisualContextTree const& visual_context_tree, ReadonlyBytes encoded_scroll_state, Gfx::FloatPoint position)+bool recorded_display_list_blocks_wheel_event_at(DisplayList const& display_list, ReadonlyBytes encoded_scroll_state, Gfx::FloatPoint position){EncodedAsyncScrollingMetadata async_scrolling_metadata { display_list.async_scrolling_metadata() };auto display_list_for_scroll_logic = display_list.for_scroll_logic(async_scrolling_metadata.bytes());- return RustFFI::recorded_display_list_blocks_wheel_event_at(&display_list_for_scroll_logic, visual_context_tree.rust_handle(), encoded_scroll_state, position);+ return RustFFI::recorded_display_list_blocks_wheel_event_at(&display_list_for_scroll_logic, encoded_scroll_state, position);}}diff --git a/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.h b/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.hindex 38a67e350de..b1a4e12233a 100644--- a/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.h+++ b/Libraries/LibCompositing/Scrolling/RecordedDisplayListScrolling.h@@ -14,10 +14,11 @@namespace Compositing {-COMPOSITING_API String async_scrolling_state_as_json(DisplayList const&, AccumulatedVisualContextTree const&);+// The display lists are ones this process recorded, which go with the visual context trees they were recorded against.+COMPOSITING_API String async_scrolling_state_as_json(DisplayList const&);COMPOSITING_API String empty_async_scrolling_state_as_json();// The scroll state is the document's, as the scroll logic, which is Rust, encoded it.-COMPOSITING_API FirstWheelStepRouteForTesting route_first_wheel_step_through_recorded_display_list(DisplayList const&, AccumulatedVisualContextTree const&, ReadonlyBytes encoded_scroll_state, u64 newest_wheel_event_listener_state_generation, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);-COMPOSITING_API bool recorded_display_list_blocks_wheel_event_at(DisplayList const&, AccumulatedVisualContextTree const&, ReadonlyBytes encoded_scroll_state, Gfx::FloatPoint position);+COMPOSITING_API FirstWheelStepRouteForTesting route_first_wheel_step_through_recorded_display_list(DisplayList const&, ReadonlyBytes encoded_scroll_state, u64 newest_wheel_event_listener_state_generation, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);+COMPOSITING_API bool recorded_display_list_blocks_wheel_event_at(DisplayList const&, ReadonlyBytes encoded_scroll_state, Gfx::FloatPoint position);}diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cppindex 0b3778ae9e8..ecaa4f95a1f 100644--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp@@ -498,7 +498,7 @@ Web::Compositor::PlaceholderCanvasPixels CompositorConnection::get_placeholder_creturn { pixels.is_valid() ? pixels.bitmap() : nullptr, response->origin_clean() };}-bool CompositorConnection::rasterize_display_list(Compositing::DisplayList const& display_list, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Compositing::DisplayListResourceTransaction resource_transaction, NonnullRefPtr<Gfx::Bitmap> target)+bool CompositorConnection::rasterize_display_list(Compositing::DisplayList const& display_list, Compositing::DisplayListResourceTransaction resource_transaction, NonnullRefPtr<Gfx::Bitmap> target){if (!can_send_message_to_compositor())return false;@@ -523,7 +523,7 @@ bool CompositorConnection::rasterize_display_list(Compositing::DisplayList constdisplay_list.tape_size(),display_list.run_count(),display_list.properties(),- visual_context_tree,+ display_list.serialized_visual_context_tree(),move(resource_transaction));return response && response->success();}diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.hindex 212f04d8682..f323676d34c 100644--- a/Libraries/LibWeb/Compositor/CompositorConnection.h+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h@@ -67,7 +67,7 @@ public:void release_placeholder_canvas(Compositing::CanvasId);void commit_placeholder_canvas(Web::Compositor::PlaceholderCanvasLink, Optional<Compositing::CanvasId> source_canvas_id, Gfx::IntSize, bool origin_clean);Web::Compositor::PlaceholderCanvasPixels get_placeholder_canvas_pixels(Compositing::CanvasId, Gfx::IntRect);- bool rasterize_display_list(Compositing::DisplayList const&, Compositing::AccumulatedVisualContextTree const&, Compositing::DisplayListResourceTransaction, NonnullRefPtr<Gfx::Bitmap> target);+ bool rasterize_display_list(Compositing::DisplayList const&, Compositing::DisplayListResourceTransaction, NonnullRefPtr<Gfx::Bitmap> target);void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventRouting);diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cppindex f79ca211ea4..2073bf3cf76 100644--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp@@ -408,12 +408,12 @@ bool CompositorHost::rasterize_display_list(Compositing::DisplayListResource conauto* connection = compositor_connection();if (!connection)return false;- auto resource_transaction = resource_storage.create_self_contained_transaction(*display_list.display_list, display_list.visual_context_tree);+ auto resource_transaction = resource_storage.create_self_contained_transaction(*display_list.display_list);if (resource_transaction.is_error()) {dbgln("WebContent: Not rasterizing a display list: {}", resource_transaction.error());return false;}- return connection->rasterize_display_list(*display_list.display_list, display_list.visual_context_tree, resource_transaction.release_value(), move(target));+ return connection->rasterize_display_list(*display_list.display_list, resource_transaction.release_value(), move(target));}void CompositorHost::destroy_context(Web::CompositorContextId context_id)diff --git a/Libraries/LibWeb/Compositor/NavigablePresenter.cpp b/Libraries/LibWeb/Compositor/NavigablePresenter.cppindex 5fd482634cd..4f0a72b7084 100644--- a/Libraries/LibWeb/Compositor/NavigablePresenter.cpp+++ b/Libraries/LibWeb/Compositor/NavigablePresenter.cpp@@ -257,7 +257,7 @@ extern "C" WEB_API void web_navigable_presenter_take_vector_image_resources(voidCompositing::DisplayListResourceId id { raw_id };resources.display_lists.set(id);resources.include(storage.collect_referenced_resources(storage.display_list(id)));- resources.include(storage.collect_referenced_resources(storage.display_list_visual_context_tree(id)));+ resources.include(storage.collect_resources_referenced_by_visual_context_tree(storage.display_list(id)));}static_cast<Web::Compositor::NavigablePresenter*>(presenter)->display_list_resource_storage().apply_transaction(storage.create_transaction({}, resources));}diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex d4b23d52319..4ad7d7414df 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -12193,7 +12193,7 @@ Painting::HitTestListAdoption Document::adopt_published_recording(Optional<Layou}if (recording.cache_mode == Painting::PaintCommandCacheMode::ReadWrite && !recording_returned_the_paint_command_cache_source)- document_paint_state.set_display_list_used_as_paint_command_cache_source(display_list, referenced_resources(), recording.visual_context_tree);+ document_paint_state.set_display_list_used_as_paint_command_cache_source(display_list, referenced_resources());return adoption;}diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex fc72d8f0eba..b43aa50b82d 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -7274,7 +7274,7 @@ bool LocalNavigable::take_recording_in_flight_in(TakeIn take_in)while (landing == Layout::RustFFI::FfiRecordingLanding::NeedsVectorImages) {{Layout::ForcedReadScope read { *document };- Painting::render_vector_images(read, *document, *m_recording_in_flight->recording);+ Painting::render_vector_images(read, *document);}landing = take_landing();}diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex e0dc8498538..bd47a62702c 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -1710,10 +1710,9 @@ GC::Ref<JS::Object> Internals::recorded_display_list_wheel_target_at(double x, dauto* display_list = document.paint_state().display_list_used_as_paint_command_cache_source();if (!display_list)return first_wheel_step_route_to_object({ .route = { InputRoutingDecision::NoAsyncScrollingState }, .document_id = {} });- auto const& visual_context_tree = document.paint_state().paint_command_cache_source_visual_context_tree().value();auto position = device_position_as_float_point(page().css_to_device_point({ x, y }));auto encoded_scroll_state = document.paint_state().encoded_scroll_state();- return first_wheel_step_route_to_object(Compositing::route_first_wheel_step_through_recorded_display_list(*display_list, visual_context_tree, encoded_scroll_state, document.wheel_event_listener_state_generation(), position, { static_cast<float>(delta_x), static_cast<float>(delta_y) }));+ return first_wheel_step_route_to_object(Compositing::route_first_wheel_step_through_recorded_display_list(*display_list, encoded_scroll_state, document.wheel_event_listener_state_generation(), position, { static_cast<float>(delta_x), static_cast<float>(delta_y) }));}bool Internals::recorded_display_list_blocks_wheel_event_at(double x, double y)@@ -1724,10 +1723,9 @@ bool Internals::recorded_display_list_blocks_wheel_event_at(double x, double y)auto* display_list = document.paint_state().display_list_used_as_paint_command_cache_source();if (!display_list)return false;- auto const& visual_context_tree = document.paint_state().paint_command_cache_source_visual_context_tree().value();auto position = device_position_as_float_point(page().css_to_device_point({ x, y }));auto encoded_scroll_state = document.paint_state().encoded_scroll_state();- return Compositing::recorded_display_list_blocks_wheel_event_at(*display_list, visual_context_tree, encoded_scroll_state, position);+ return Compositing::recorded_display_list_blocks_wheel_event_at(*display_list, encoded_scroll_state, position);}void Internals::record_display_list_for_testing(bool paint_overlay, bool cold)@@ -3917,7 +3915,7 @@ GC::Ref<JS::Object> Internals::recorded_async_scrolling_state_object()auto& document = window().associated_document();auto* display_list = document.paint_state().display_list_used_as_paint_command_cache_source();auto json = display_list- ? Compositing::async_scrolling_state_as_json(*display_list, document.paint_state().paint_command_cache_source_visual_context_tree().value())+ ? Compositing::async_scrolling_state_as_json(*display_list): Compositing::empty_async_scrolling_state_as_json();auto report = MUST(JsonValue::from_string(json));return scrolling_state_report_to_object(window(), report.as_object());diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.h b/Libraries/LibWeb/Painting/DocumentPaintState.hindex 72414647657..b6b4eb6252c 100644--- a/Libraries/LibWeb/Painting/DocumentPaintState.h+++ b/Libraries/LibWeb/Painting/DocumentPaintState.h@@ -72,17 +72,14 @@ public:Compositing::AccumulatedVisualContextTree visual_context_tree(DOM::Document const&) const;u64 visual_context_tree_structural_epoch(Layout::BegunRead const& read) const;- void set_display_list_used_as_paint_command_cache_source(RefPtr<Compositing::DisplayList> display_list, Compositing::DisplayListResourceSet referenced_resources, Compositing::AccumulatedVisualContextTree visual_context_tree)+ void set_display_list_used_as_paint_command_cache_source(RefPtr<Compositing::DisplayList> display_list, Compositing::DisplayListResourceSet referenced_resources){m_display_list_used_as_paint_command_cache_source = move(display_list);- m_paint_command_cache_source_visual_context_tree = move(visual_context_tree);m_paint_command_cache_source_referenced_resources = move(referenced_resources);}Compositing::DisplayList* display_list_used_as_paint_command_cache_source() const { return m_display_list_used_as_paint_command_cache_source.ptr(); }Compositing::DisplayListResourceSet const& paint_command_cache_source_referenced_resources() const { return m_paint_command_cache_source_referenced_resources; }- Optional<Compositing::AccumulatedVisualContextTree> const& paint_command_cache_source_visual_context_tree() const { return m_paint_command_cache_source_visual_context_tree; }-void append_paint_command_cache_source_resources(Compositing::DisplayListResourceSet&) const;private:@@ -93,7 +90,6 @@ private:Vector<Compositing::RustFFI::NodeSlotId> m_boxes_with_auto_content_visibility;RefPtr<Compositing::DisplayList> m_display_list_used_as_paint_command_cache_source;- Optional<Compositing::AccumulatedVisualContextTree> m_paint_command_cache_source_visual_context_tree;Compositing::DisplayListResourceSet m_paint_command_cache_source_referenced_resources;};diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cppindex d55288ded7a..6476ed596cb 100644--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp@@ -360,13 +360,12 @@ void dump_layout_tree(StringBuilder& builder, Layout::Node const& root, bool intnamespace {-// What a recording's publication adds its resources to, and what an SVG-as-image render is found and cut from: the-// document's host, through which a layout node of the recording is reached, and the tree the recording was cut from.+// What a recording's publication adds its resources to, and what an SVG-as-image render is found from: the document's+// host, through which a layout node of the recording is reached.struct RecordingPublishContext {Compositing::DisplayListResourceStorage& resource_storage;Layout::RustFFI::DocumentHost* host;Layout::BegunRead const& read;- Compositing::AccumulatedVisualContextTree const& visual_context_tree;};static Layout::RustFFI::FfiRecordingPublishCallbacks recording_publish_callbacks(RecordingPublishContext& context)@@ -382,7 +381,7 @@ static Layout::RustFFI::FfiRecordingPublishCallbacks recording_publish_callbacks.resolve_vector_image_display_list = [](void* context_pointer, Layout::RustFFI::FfiVectorImageRenderRequest const* request) -> u64 {auto& context = *static_cast<RecordingPublishContext*>(context_pointer);auto empty_display_list = [&] {- return context.resource_storage.add_display_list(Compositing::DisplayList::create(context.visual_context_tree), context.visual_context_tree).value();+ return context.resource_storage.add_display_list(Compositing::DisplayListResource { Compositing::DisplayList::create_empty() }).value();};auto const* layout_node = static_cast<Layout::NodeWithStyle const*>(Layout::RustFFI::render_state_node_shell_if_live(context.host, &context.read, request->owner));if (!layout_node)@@ -672,16 +671,16 @@ Optional<DisplayListRecording> start_rust_display_list_recording(Layout::BegunRereturn recording;}-void render_vector_images(Layout::BegunRead const& read, DOM::Document& document, DisplayListRecording const& recording)+void render_vector_images(Layout::BegunRead const& read, DOM::Document& document){auto resources = make<Compositor::VectorImageResources>();- RecordingPublishContext publish_context { resources->storage, document_host(document), read, recording.visual_context_tree };+ RecordingPublishContext publish_context { resources->storage, document_host(document), read };Layout::RustFFI::render_state_render_vector_images(publish_context.host, recording_publish_callbacks(publish_context), resources.leak_ptr());}RefPtr<Compositing::DisplayList> finish_rust_display_list_recording(Layout::BegunRead const& read, DOM::Document& document, DisplayListRecording const& recording, Compositing::DisplayListResourceStorage& resource_storage){- RecordingPublishContext publish_context { resource_storage, document_host(document), read, recording.visual_context_tree };+ RecordingPublishContext publish_context { resource_storage, document_host(document), read };auto rust_timer = Core::ElapsedTimer::start_new(Core::TimerType::Precise);Layout::RustFFI::FfiPresentedRecording presented {};Layout::RustFFI::render_state_publish_recording(publish_context.host, &read, recording_publish_callbacks(publish_context), &presented);@@ -709,7 +708,7 @@ NonnullRefPtr<Compositing::DisplayList> display_list_of_published_recording(Disp}}- auto display_list = Compositing::DisplayList::share_rust_command_storage(recording.visual_context_tree, presented.display_list);+ auto display_list = Compositing::DisplayList::share_rust_recording(presented.display_list, presented.visual_context_tree);if (recording.surface_clear_color.has_value())display_list->set_surface_clear_color(*recording.surface_clear_color);display_list->set_root_group_color(presented.root_group_color);@@ -717,14 +716,26 @@ NonnullRefPtr<Compositing::DisplayList> display_list_of_published_recording(Dispreturn display_list;}+NonnullRefPtr<Compositing::DisplayList> nestable_display_list_of_last_recording(Layout::BegunRead const& read, DOM::Document const& document, NonnullRefPtr<Compositing::DisplayList> published)+{+ Layout::RustFFI::FfiPresentedRecording last {};+ Layout::RustFFI::render_state_last_recording(document_host(document), &read, &last);+ if (published->was_recorded_against(last.visual_context_tree))+ return published;+ auto display_list = Compositing::DisplayList::share_rust_recording(last.display_list, last.visual_context_tree);+ if (auto surface_clear_color = published->surface_clear_color(); surface_clear_color.has_value())+ display_list->set_surface_clear_color(*surface_clear_color);+ display_list->set_root_group_color(published->root_group_color());+ return display_list;+}+static Compositing::DisplayListResource record_image_paint(Layout::RustFFI::FfiImagePaintRecordInputs const& inputs){Optional<Compositing::DisplayListResource> recorded_display_list;Layout::RustFFI::ladybird_web_record_image_paint_display_list(&inputs, &recorded_display_list,[](void* context, void const* retained_commands, void const* retained_tree) {- auto visual_context_tree = Compositing::AccumulatedVisualContextTree::adopt_rust_handle(retained_tree);- auto display_list = Compositing::DisplayList::adopt_rust_command_storage(visual_context_tree, retained_commands);- *static_cast<Optional<Compositing::DisplayListResource>*>(context) = Compositing::DisplayListResource { move(display_list), move(visual_context_tree) };+ auto display_list = Compositing::DisplayList::adopt_rust_recording(retained_commands, retained_tree);+ *static_cast<Optional<Compositing::DisplayListResource>*>(context) = Compositing::DisplayListResource { move(display_list) };});return recorded_display_list.release_value();}@@ -743,7 +754,7 @@ Compositing::DisplayListResource record_image_paint_display_list(ImagePaint cons},[&](ImagePaint::NestedDisplayList const& nested) {inputs.kind = Layout::RustFFI::FfiImagePaintRecordKind::NestedDisplayList;- inputs.nested_display_list_id = request.resource_storage.add_display_list(nested.resource.display_list, nested.resource.visual_context_tree).value();+ inputs.nested_display_list_id = request.resource_storage.add_display_list(Compositing::DisplayListResource { nested.resource }).value();inputs.nested_display_list_size = nested.list_size;},[&](ImagePaint::Gradient const& gradient) {diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.h b/Libraries/LibWeb/Painting/PaintingRustBridge.hindex f19607d71b3..4958d64ef7c 100644--- a/Libraries/LibWeb/Painting/PaintingRustBridge.h+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.h@@ -67,9 +67,9 @@ WEB_API Optional<DisplayListRecording> start_rust_display_list_recording(Layout:// Commits the navigable's next frame, which keeps the display list the compositor has, to the render owner, which// presents it with `presentation` beside the event loop.WEB_API void commit_unrecorded_frame(Layout::BegunRead const&, DOM::Document&, Compositor::FlightPresentation presentation);-// Renders the SVG images of the committed frame of `recording` that waits for them, which only the main thread renders,-// into a resource storage of their own, and hands the frame back to the Paint thread, which presents it with them.-WEB_API void render_vector_images(Layout::BegunRead const&, DOM::Document&, DisplayListRecording const& recording);+// Renders the SVG images of the document's committed frame that waits for them, which only the main thread renders, into+// a resource storage of their own, and hands the frame back to the Paint thread, which presents it with them.+WEB_API void render_vector_images(Layout::BegunRead const&, DOM::Document&);// Publishes the recording, which has landed and stands, and makes its display list from what was sealed where it began.WEB_API RefPtr<Compositing::DisplayList> finish_rust_display_list_recording(Layout::BegunRead const&, DOM::Document&, DisplayListRecording const&, Compositing::DisplayListResourceStorage&);// Hands the document the trace the recording it took in last left, if it left one.@@ -77,6 +77,10 @@ WEB_API void take_recording_trace_if_pending(Layout::BegunRead const&, DOM::Docu// Makes the display list of `recording`, published as `presented` says, from what the recording sealed where it began.// Reads no document, so it runs wherever the recording is published.WEB_API NonnullRefPtr<Compositing::DisplayList> display_list_of_published_recording(DisplayListRecording const&, Layout::RustFFI::FfiPresentedRecording const&);+// `published`, the display list the document's last recording published, as another display list nests it: with the+// visual context tree that recording was recorded against. A recording that repeats the list it published before+// publishes that list again, which holds the tree of the recording before.+WEB_API NonnullRefPtr<Compositing::DisplayList> nestable_display_list_of_last_recording(Layout::BegunRead const&, DOM::Document const&, NonnullRefPtr<Compositing::DisplayList> published);WEB_API Utf16String serialize_painting_dump(Layout::BegunRead const&, DOM::Document const&, Compositing::AccumulatedVisualContextTree const&, Compositing::DisplayList const&, Compositing::DisplayListResourceStorage const&);WEB_API Compositing::DisplayListResource record_image_paint_display_list(ImagePaint const&, ImagePaintRequest const&, double device_pixels_per_css_pixel);diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 6d159d16cb0..437b25bdc6b 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -482,6 +482,8 @@ pub struct FfiPresentedRecording {/// The recorded display list, which the document's last recording holds until the next/// recording replaces it. The host takes a reference of its own to keep it longer.pub display_list: *const c_void,+ /// The visual context tree the display list was recorded against, held as the list is.+ pub visual_context_tree: *const c_void,/// The color the canvas holds below the recording's layers.pub root_group_color: libgfx_rust::Color,}@@ -494,6 +496,10 @@ impl FfiPresentedRecording {is_identical_to_published_recording: output.is_identical_to_published_recording,has_blocking_wheel_event_listeners: output.has_blocking_wheel_event_listeners,display_list: std::sync::Arc::as_ptr(&output.display_list).cast(),+ visual_context_tree: output+ .visual_context_tree+ .as_ref()+ .map_or(std::ptr::null(), |tree| std::sync::Arc::as_ptr(tree).cast()),root_group_color: output.root_group_color,}}@@ -510,6 +516,9 @@ impl FfiPresentedRecording {display_list: recording.map_or(std::ptr::null(), |recording| {std::sync::Arc::as_ptr(&recording.display_list).cast()}),+ visual_context_tree: recording+ .and_then(|recording| recording.visual_context_tree.as_ref())+ .map_or(std::ptr::null(), |tree| std::sync::Arc::as_ptr(tree).cast()),root_group_color: recording.map_or(libgfx_rust::Color::TRANSPARENT, |recording| recording.root_group_color),}}@@ -623,18 +632,9 @@ pub unsafe extern "C" fn ladybird_web_record_image_paint_display_list(use crate::painting::record::paint::gradient_resolution::{record_resolved_gradient_fill, resolve_gradient_paint_with_input,};- use crate::painting::visual_context::{TransformData, TransformDataRole, VisualContextTree};- use libgfx_rust::{CompositingAndBlendingOperator, FloatMatrix4x4, FloatPoint};- let tree = 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: libgfx_rust::FloatRect::default(),- });+ use crate::painting::visual_context::VisualContextTree;+ use libgfx_rust::CompositingAndBlendingOperator;+ let tree = VisualContextTree::create_identity();// Force-dark never reaches here: an image is darkened by classifying the image itself — not by inverting the// fills that raster it.let mut recorder = DisplayListRecorder::new(None);diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 9330cdd0fa9..b4a866b409d 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -616,6 +616,22 @@ pub unsafe extern "C" fn render_state_publish_recording(*out = presented;}+/// What the host reads of the recording `host`'s document took in last.+///+/// # Safety+///+/// `host` must be a live document host, on its document's thread.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn render_state_last_recording(+ host: &crate::render_state::DocumentHost,+ read: &crate::render_state::BegunRead,+ out: &mut crate::painting::ffi::FfiPresentedRecording,+) {+ *out = read_arena(host, read, (), |arena, ()| {+ crate::painting::ffi::FfiPresentedRecording::of_last_recording(arena)+ });+}+/// # Safety////// `host` must be a live document host, on its document's thread; `describe_node` and `append_text` are calleddiff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rsindex f1617d60851..9e1a24fb9db 100644--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs@@ -48,6 +48,8 @@ pub(crate) use inputs::RecordingInputs;#[derive(Default)]pub struct RecordingOutput {pub recorded_structural_epoch: u64,+ /// The visual context tree the recording was recorded against: the frozen frame's.+ pub visual_context_tree: Option<Arc<crate::painting::visual_context::VisualContextTree>>,pub(crate) frame_inputs: FrameInputs,// The area the root background painted: the viewport united with the root's overflow. Only// the root's background reads it, so a change pushes that producer instead of a new frame.diff --git a/Libraries/LibWeb/Rust/src/painting/record/traversal.rs b/Libraries/LibWeb/Rust/src/painting/record/traversal.rsindex 9b73dc6f972..bfc81b33a88 100644--- a/Libraries/LibWeb/Rust/src/painting/record/traversal.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/traversal.rs@@ -180,6 +180,7 @@ fn record_display_list_impl<O: Observer>(hit_test_list.recorded_structural_epoch = structural_epoch;let output = RecordingOutput {recorded_structural_epoch: structural_epoch,+ visual_context_tree: paint_state.visual_context_tree.clone(),frame_inputs,root_background_canvas_rect,prologue_bytes,diff --git a/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Libraries/LibWeb/SVG/SVGDecodedImageData.cppindex 80b2759a8b5..6f5ab6e3f5c 100644--- a/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp+++ b/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp@@ -25,6 +25,7 @@#include <LibWeb/Page/Page.h>#include <LibWeb/Painting/DocumentPaintState.h>#include <LibWeb/Painting/PaintableTypes.h>+#include <LibWeb/Painting/PaintingRustBridge.h>#include <LibWeb/Platform/EventLoopPlugin.h>#include <LibWeb/SVG/SVGDecodedImageData.h>#include <LibWeb/SVG/SVGSVGElement.h>@@ -268,7 +269,7 @@ Optional<Compositing::DisplayListResource> SVGDecodedImageData::record_display_lRenderKey const key { css_size, raster_scale, color_scheme, paint_config };if (auto it = m_cached_display_lists.find(key); it != m_cached_display_lists.end()) {copy_referenced_resources_to(destination_resource_storage, resource_storage, it->value.referenced_resources);- return Compositing::DisplayListResource { *it->value.display_list, it->value.visual_context_tree };+ return Compositing::DisplayListResource { *it->value.display_list };}// FIXME: Evict least used entries.@@ -319,12 +320,12 @@ Optional<Compositing::DisplayListResource> SVGDecodedImageData::record_display_lVERIFY(m_document->has_committed_viewport_box());auto& document_paint_state = m_document->paint_state();VERIFY(document_paint_state.display_list_used_as_paint_command_cache_source() == display_list.ptr());+ auto nestable_display_list = Painting::nestable_display_list_of_last_recording(read, *m_document, display_list.release_nonnull());auto referenced_resources = document_paint_state.paint_command_cache_source_referenced_resources();- auto visual_context_tree = document_paint_state.visual_context_tree(*m_document);- referenced_resources.include(resource_storage.collect_referenced_resources(visual_context_tree));+ referenced_resources.include(resource_storage.collect_resources_referenced_by_visual_context_tree(*nestable_display_list));copy_referenced_resources_to(destination_resource_storage, resource_storage, referenced_resources);- auto display_list_resource = Compositing::DisplayListResource { *display_list, visual_context_tree };- m_cached_display_lists.set(key, CachedDisplayList { NonnullRefPtr<Compositing::DisplayList> { *display_list }, move(visual_context_tree), move(referenced_resources) });+ auto display_list_resource = Compositing::DisplayListResource { nestable_display_list };+ m_cached_display_lists.set(key, CachedDisplayList { move(nestable_display_list), move(referenced_resources) });prune_cached_display_list_resources();return display_list_resource;}diff --git a/Libraries/LibWeb/SVG/SVGDecodedImageData.h b/Libraries/LibWeb/SVG/SVGDecodedImageData.hindex b46ed6c80bd..7b8fc398a2a 100644--- a/Libraries/LibWeb/SVG/SVGDecodedImageData.h+++ b/Libraries/LibWeb/SVG/SVGDecodedImageData.h@@ -78,7 +78,6 @@ private:struct CachedDisplayList {NonnullRefPtr<Compositing::DisplayList> display_list;- Compositing::AccumulatedVisualContextTree visual_context_tree;// Precomputed by collect_referenced_resources(); the display list is immutable, so this never changes.Compositing::DisplayListResourceSet referenced_resources;};diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipcindex 8625b7df54b..c6b246ee38c 100644--- a/Services/Compositor/CompositorWebContentServer.ipc+++ b/Services/Compositor/CompositorWebContentServer.ipc@@ -68,7 +68,7 @@ endpoint CompositorWebContentServer// A display list is rasterized into the target bitmap with the fonts, image frames and video sinks staged for it under// a token that the next rasterize_display_list names, and with the display lists it nests, which come with it.stage_rasterization(u64 token, Compositing::DisplayListResourceTransaction resources, Gfx::ShareableBitmap target_bitmap) =|- [RustReceiver] rasterize_display_list(u64 token, Core::AnonymousBuffer display_list_buffer, u64 tape_size, u64 run_count, Compositing::DisplayList::Properties display_list_properties, Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction nested_display_lists) => (bool success)+ [RustReceiver] rasterize_display_list(u64 token, Core::AnonymousBuffer display_list_buffer, u64 tape_size, u64 run_count, Compositing::DisplayList::Properties display_list_properties, ByteBuffer visual_context_tree, Compositing::DisplayListResourceTransaction nested_display_lists) => (bool success)create_webgl_context(Compositing::WebGL::WebGLVersion webgl_version, Gfx::IntSize size, bool depth, bool stencil, bool antialias) => (bool success, Compositing::CanvasId canvas_id, Vector<String> supported_extensions)webgl_set_command_buffer(Compositing::CanvasId canvas_id, Core::AnonymousBuffer command_buffer) =|diff --git a/Services/Compositor/Rust/src/core/messages.rs b/Services/Compositor/Rust/src/core/messages.rsindex 1833418f0b7..df8f6e55b00 100644--- a/Services/Compositor/Rust/src/core/messages.rs+++ b/Services/Compositor/Rust/src/core/messages.rs@@ -36,6 +36,7 @@ use libcompositing_rust::scrolling::{PinchEvent, ScrollRequest, ScrollStateSnapshot,};use libcompositing_rust::time::MonotonicTime;+use libcompositing_rust::visual_context::VisualContextTree;use libgfx_rust::FloatPoint;use libipc_rust::Misbehavior;use std::io::Write;@@ -50,6 +51,13 @@ fn display_list_timing_enabled() -> bool {}const NESTED_DISPLAY_LISTS_THAT_NEST_THEMSELVES: &str = "WebContent published display lists that nest themselves";+const MALFORMED_VISUAL_CONTEXT_TREE: &str = "WebContent sent a visual context tree that does not decode";++fn decode_visual_context_tree(bytes: &[u8]) -> Result<std::sync::Arc<VisualContextTree>, Misbehavior> {+ VisualContextTree::from_bytes(bytes)+ .map(std::sync::Arc::new)+ .map_err(|_| Misbehavior(MALFORMED_VISUAL_CONTEXT_TREE))+}const DISPLAY_LIST_WITH_UNUSABLE_SCROLLING_STATE: &str ="WebContent published a display list with scrolling state the compositor cannot use";@@ -348,8 +356,14 @@ impl compositor_web_content_server::Stub for MessagesFromWebContent<'_> {for display_list in transaction.display_lists {nested_display_lists.add(display_list);}+ let tree = match decode_visual_context_tree(&message.visual_context_tree) {+ Ok(tree) => tree,+ Err(misbehavior) => {+ raster.discard_staged_rasterization(client, token);+ return Err(misbehavior);+ }+ };let properties = message.display_list_properties;- let tree = message.visual_context_tree.0;if properties.compatible_visual_context_tree_structural_epoch != tree.structural_epoch|| !tree.display_list_references_only_live_nodes(storage.command_runs()){diff --git a/Tests/Compositor/TestDisplayListImageFilters.cpp b/Tests/Compositor/TestDisplayListImageFilters.cppindex be8a90ad394..edf260b6dd5 100644--- a/Tests/Compositor/TestDisplayListImageFilters.cpp+++ b/Tests/Compositor/TestDisplayListImageFilters.cpp@@ -27,12 +27,12 @@ static NonnullRefPtr<Gfx::Bitmap> replace_image(Compositing::DisplayListResourcereturn bitmap;}-static Gfx::Color render(Compositor::DisplayListPlayerSkia& player, Compositing::DisplayList const& list, Compositing::AccumulatedVisualContextTree const& tree, Compositing::DisplayListResourceStorage const& storage, Compositor::DisplayListRasterCache& cache)+static Gfx::Color render(Compositor::DisplayListPlayerSkia& player, Compositing::DisplayList const& list, 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(tree, painter, 0);+ list.replay(painter, 0);player.end_painting();player.flush(*surface);return bitmap->get_pixel(0, 0);@@ -42,8 +42,8 @@ TEST_CASE(image_filters_use_the_current_resource_storage){Compositing::VisualContextTreeTestBuilder builder;auto effect = builder.append_image_filter(image_id.value(), rect);- auto tree = builder.finish();- auto list = Compositing::VisualContextTreeTestBuilder::filled_rect_display_list(tree, { .effect = effect }, rect, Gfx::Color::White);+ builder.finish();+ auto list = builder.filled_rect_display_list({ .effect = effect }, rect, Gfx::Color::White);Compositor::DisplayListPlayerSkia player { nullptr };Compositing::DisplayListResourceStorage blue_storage;Compositing::DisplayListResourceStorage green_storage;@@ -52,24 +52,24 @@ 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, tree, blue_storage, blue_cache), Gfx::Color::Blue);- EXPECT_EQ(render(player, *list, tree, green_storage, green_cache), Gfx::Color::Green);- EXPECT_EQ(render(player, *list, tree, blue_storage, blue_cache), Gfx::Color::Blue);+ 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);}TEST_CASE(image_filters_drop_replaced_image_resources){Compositing::VisualContextTreeTestBuilder builder;auto effect = builder.append_image_filter(image_id.value(), rect);- auto tree = builder.finish();- auto list = Compositing::VisualContextTreeTestBuilder::filled_rect_display_list(tree, { .effect = effect }, rect, Gfx::Color::White);+ builder.finish();+ auto list = builder.filled_rect_display_list({ .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, tree, storage, cache), Gfx::Color::Blue);+ EXPECT_EQ(render(player, *list, storage, cache), Gfx::Color::Blue);(void)replace_image(storage, cache, Gfx::Color::Green);- EXPECT_EQ(render(player, *list, tree, storage, cache), Gfx::Color::Green);+ EXPECT_EQ(render(player, *list, storage, cache), Gfx::Color::Green);EXPECT_EQ(original_bitmap->get_pixel(0, 0), Gfx::Color::Blue);}@@ -77,8 +77,8 @@ TEST_CASE(image_filters_do_not_keep_destroyed_resource_namespaces){Compositing::VisualContextTreeTestBuilder builder;auto effect = builder.append_image_filter(image_id.value(), rect);- auto tree = builder.finish();- auto list = Compositing::VisualContextTreeTestBuilder::filled_rect_display_list(tree, { .effect = effect }, rect, Gfx::Color::White);+ builder.finish();+ auto list = builder.filled_rect_display_list({ .effect = effect }, rect, Gfx::Color::White);Compositor::DisplayListPlayerSkia player { nullptr };struct ResourceNamespace {Compositing::DisplayListResourceStorage storage;@@ -89,7 +89,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, tree, resources->storage, resources->cache), color);+ EXPECT_EQ(render(player, *list, resources->storage, resources->cache), color);resources->~ResourceNamespace();}}diff --git a/Tests/Compositor/TestPaintingSurface.cpp b/Tests/Compositor/TestPaintingSurface.cppindex 1ee961608b1..a64ab56484f 100644--- a/Tests/Compositor/TestPaintingSurface.cpp+++ b/Tests/Compositor/TestPaintingSurface.cpp@@ -30,7 +30,8 @@ TEST_CASE(zero_width_border_sides_do_not_paint_on_gpu_surface)Gfx::IntSize size { 10, 10 };auto surface = Gfx::PaintingSurface::create_with_size(size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, context);- auto tree = Compositing::VisualContextTreeTestBuilder {}.finish();+ Compositing::VisualContextTreeTestBuilder builder;+ builder.finish();Compositor::DisplayListPlayerSkia player { context };Compositing::DisplayListResourceStorage storage;Compositor::DisplayListRasterCache cache;@@ -50,9 +51,9 @@ TEST_CASE(zero_width_border_sides_do_not_paint_on_gpu_surface).left_width = 0,.color = Gfx::Color::Black,};- auto list = Compositing::VisualContextTreeTestBuilder::rounded_rect_ring_display_list(tree, {}, ring);+ auto list = builder.rounded_rect_ring_display_list({}, ring);auto painter = player.begin_painting(*surface, storage, cache, nullptr);- list->replay(tree, painter, 0);+ list->replay(painter, 0);player.end_painting();surface->read_into_bitmap(*bitmap);