Skip to content

Truly independent web browser

LibCompositing+Compositor: Damage canvases where display lists draw them

Aliaksandr Kalenik8e3ccad15985
diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.cpp b/Libraries/LibCompositing/DisplayList/DisplayList.cpp
index 0bccb541c31..41832698bb9 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayList.cpp
+++ b/Libraries/LibCompositing/DisplayList/DisplayList.cpp
@@ -84,6 +84,7 @@ DisplayList::ReferencedResourceIds DisplayList::referenced_resource_ids() const
.image_frames = { ids.image_frame_ids, ids.image_frame_id_count },
.video_sinks = { ids.video_sink_ids, ids.video_sink_id_count },
.display_lists = { ids.display_list_ids, ids.display_list_id_count },
+ .canvases = { ids.canvas_ids, ids.canvas_id_count },
};
}
@@ -100,23 +101,12 @@ void DisplayList::for_each_compositor_metadata(Function<void(ContextRef, Display
});
}
-template<typename Command>
-static void for_each_indexed_record(void const* storage, RustFFI::FfiIndexedRecordKind kind, Function<void(ContextRef, Gfx::IntRect, Command const&)> const& callback)
-{
- RustFFI::display_list_storage_for_each_indexed_record(storage, kind, const_cast<void*>(static_cast<void const*>(&callback)), [](void* context, ContextRef run_context, Gfx::IntRect bounding_rect, u8 const* payload, size_t payload_size) {
- auto command = read_display_list_object<Command>({ payload, payload_size });
- (*static_cast<Function<void(ContextRef, Gfx::IntRect, Command const&)> const*>(context))(run_context, bounding_rect, command);
- });
-}
-
-void DisplayList::for_each_drawn_canvas(Function<void(ContextRef, Gfx::IntRect, DrawCanvas const&)> const& callback) const
-{
- for_each_indexed_record<DrawCanvas>(m_storage, RustFFI::FfiIndexedRecordKind::DrawnCanvas, callback);
-}
-
void DisplayList::for_each_caret(Function<void(ContextRef, Gfx::IntRect, PaintCaret const&)> const& callback) const
{
- for_each_indexed_record<PaintCaret>(m_storage, RustFFI::FfiIndexedRecordKind::Caret, callback);
+ RustFFI::display_list_storage_for_each_caret(m_storage, const_cast<void*>(static_cast<void const*>(&callback)), [](void* context, ContextRef run_context, Gfx::IntRect bounding_rect, u8 const* payload, size_t payload_size) {
+ auto command = read_display_list_object<PaintCaret>({ payload, payload_size });
+ (*static_cast<Function<void(ContextRef, Gfx::IntRect, PaintCaret const&)> const*>(context))(run_context, bounding_rect, command);
+ });
}
void DisplayList::replay(AccumulatedVisualContextTree const& visual_context_tree, ScrollStateSnapshot const& scroll_state, RustFFI::FfiDisplayListReplayCallbacks const& callbacks) const
diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.h b/Libraries/LibCompositing/DisplayList/DisplayList.h
index 8aef8b66a75..65ced79050a 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayList.h
+++ b/Libraries/LibCompositing/DisplayList/DisplayList.h
@@ -98,6 +98,7 @@ public:
ReadonlySpan<u64> image_frames;
ReadonlySpan<u64> video_sinks;
ReadonlySpan<u64> display_lists;
+ 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
@@ -105,9 +106,7 @@ public:
bool requires_direct_replay_without_nested_lists(AccumulatedVisualContextTree const&) const;
// Visits the compositor metadata commands with the context of their run and their payload, in tape order.
void for_each_compositor_metadata(Function<void(ContextRef, DisplayListCommandType, ReadonlyBytes payload)> const&) const;
- // Visits the canvases and carets the list draws outside of any group, with the context of their run and their
- // bounding rect.
- void for_each_drawn_canvas(Function<void(ContextRef, Gfx::IntRect, DrawCanvas const&)> const&) const;
+ // Visits the carets the list draws outside of any group, with the context of their run and their bounding rect.
void for_each_caret(Function<void(ContextRef, Gfx::IntRect, PaintCaret const&)> const&) const;
// Replays the list through a player's callbacks, against the visual context tree it was made for.
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListDamage.cpp b/Libraries/LibCompositing/DisplayList/DisplayListDamage.cpp
index 0e42c0cace8..400eddb3d17 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListDamage.cpp
+++ b/Libraries/LibCompositing/DisplayList/DisplayListDamage.cpp
@@ -19,7 +19,8 @@ Optional<Gfx::IntRect> compute_display_list_damage(
DisplayList const& new_display_list,
AccumulatedVisualContextTree const& new_visual_context_tree,
ScrollStateSnapshot const& new_scroll_state,
- Gfx::IntRect viewport_rect)
+ Gfx::IntRect viewport_rect,
+ LiveContentChanges live_content_changes)
{
auto old_scroll_offsets = old_scroll_state.device_offsets();
auto new_scroll_offsets = new_scroll_state.device_offsets();
@@ -27,7 +28,10 @@ Optional<Gfx::IntRect> compute_display_list_damage(
bool damage_is_bounded = Compositing::RustFFI::display_list_compute_damage(
old_display_list.rust_handle(), old_visual_context_tree.rust_handle(), old_scroll_offsets.data(), old_scroll_offsets.size(),
new_display_list.rust_handle(), new_visual_context_tree.rust_handle(), new_scroll_offsets.data(), new_scroll_offsets.size(),
- viewport_rect, &damage_rect);
+ viewport_rect,
+ live_content_changes.canvases.data(), live_content_changes.canvases.size(),
+ live_content_changes.video_sinks.data(), live_content_changes.video_sinks.size(),
+ &damage_rect);
if (!damage_is_bounded)
return {};
return damage_rect;
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListDamage.h b/Libraries/LibCompositing/DisplayList/DisplayListDamage.h
index 9605ce2f1b1..c9140e375fa 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListDamage.h
+++ b/Libraries/LibCompositing/DisplayList/DisplayListDamage.h
@@ -8,6 +8,7 @@
#include <AK/Optional.h>
#include <AK/Span.h>
+#include <LibCompositing/DisplayList/DisplayListResourceIds.h>
#include <LibCompositing/Export.h>
#include <LibCompositing/Forward.h>
#include <LibCompositing/Scrolling/ScrollState.h>
@@ -18,6 +19,13 @@ namespace Compositing {
class AccumulatedVisualContextTree;
class ScrollStateSnapshot;
+// The canvases and video sinks whose pixels changed since the old list was rasterized. The lists draw
+// them with commands that stay the same, so comparing the lists cannot see the change.
+struct LiveContentChanges {
+ ReadonlySpan<CanvasId> canvases;
+ ReadonlySpan<VideoSinkResourceId> video_sinks;
+};
+
COMPOSITING_API Optional<Gfx::IntRect> compute_display_list_damage(
DisplayList const& old_display_list,
AccumulatedVisualContextTree const& old_visual_context_tree,
@@ -25,7 +33,8 @@ COMPOSITING_API Optional<Gfx::IntRect> compute_display_list_damage(
DisplayList const& new_display_list,
AccumulatedVisualContextTree const& new_visual_context_tree,
ScrollStateSnapshot const& new_scroll_state,
- Gfx::IntRect viewport_rect);
+ Gfx::IntRect viewport_rect,
+ LiveContentChanges);
struct AnimatedContentViewportEffect {
bool may_affect_viewport { true };
diff --git a/Libraries/LibCompositing/Rust/build.rs b/Libraries/LibCompositing/Rust/build.rs
index 91e6df5805f..587dbaf50b1 100644
--- a/Libraries/LibCompositing/Rust/build.rs
+++ b/Libraries/LibCompositing/Rust/build.rs
@@ -102,6 +102,8 @@ fn expose_shared_abi_types_as_cpp_types(config: &mut cbindgen::Config) {
"ReplayLayer",
"ReplayMask",
"FfiVisualViewportTransform",
+ "CanvasId",
+ "VideoSinkResourceId",
]
.map(String::from),
);
@@ -147,6 +149,8 @@ fn expose_shared_abi_types_as_cpp_types(config: &mut cbindgen::Config) {
("ReplayLayer", "Compositing::ReplayLayer"),
("ReplayMask", "Compositing::ReplayMask"),
("FfiVisualViewportTransform", "Compositing::TransformWithOrigin"),
+ ("CanvasId", "Compositing::CanvasId"),
+ ("VideoSinkResourceId", "Compositing::VideoSinkResourceId"),
] {
config.export.rename.insert(rust_name.to_string(), cpp_name.to_string());
}
diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
index 1ee5708210e..f7871ec2dae 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
@@ -6,13 +6,16 @@
use super::effect_clip_plan::EffectClipPlan;
use super::effect_geometry::{Extent, SpaceMatrices, changed_extent_through_filters, nearest_spreading_effects};
-use crate::display_list::builder::{for_each_command, inline_transform_entry_offset, read_command};
+use super::summary::{DisplayListSummary, LiveContent};
+use crate::display_list::builder::{
+ HEADER_SIZE, for_each_command, inline_transform_entry_offset, read_command, read_header,
+};
use crate::display_list::commands::{
- ClipMode, ClipNodeIndex, CompositorScrollbar, ContextRef, DeclareMaskContent, DisplayListCommandHeader,
+ CanvasId, ClipMode, ClipNodeIndex, CompositorScrollbar, ContextRef, DeclareMaskContent, DisplayListCommandHeader,
DisplayListCommandRun, DisplayListCommandType, DisplayListDataSpan, DisplayListInlineClip,
DisplayListPaintStyleType, DrawGlyphRun, DrawScaledDecodedImageFrame, EffectNodeIndex, FillPath, FillRect,
INLINE_CLIP_ENTRY_SIZE, OptionalColor, OptionalFloatRect, PaintScrollBar, PaintTextShadow, PathPaintKind,
- SpatialNodeIndex, StrokePath, VISUAL_VIEWPORT_NODE_INDEX,
+ SpatialNodeIndex, StrokePath, VISUAL_VIEWPORT_NODE_INDEX, VideoSinkResourceId,
};
use crate::fast_hash::FastMap;
use crate::host::FfiAnimatedContentViewportEffect;
@@ -1368,10 +1371,32 @@ pub fn animated_content_may_affect_viewport(
pub struct DisplayListFrame<'a> {
pub command_bytes: &'a [u8],
pub command_runs: &'a [DisplayListCommandRun],
+ pub summary: &'a DisplayListSummary,
pub visual_context_tree: &'a VisualContextTree,
pub scroll_offsets: &'a [FloatPoint],
}
+// The canvases and video sinks whose pixels changed since the old frame. The lists draw them with
+// commands that stay the same, so the diff cannot see the change.
+#[derive(Clone, Copy, Default)]
+pub struct LiveContentChanges<'a> {
+ pub canvases: &'a [CanvasId],
+ pub video_sinks: &'a [VideoSinkResourceId],
+}
+
+impl LiveContentChanges<'_> {
+ fn is_empty(&self) -> bool {
+ self.canvases.is_empty() && self.video_sinks.is_empty()
+ }
+
+ fn includes(&self, content: LiveContent) -> bool {
+ match content {
+ LiveContent::Canvas(canvas_id) => self.canvases.contains(&canvas_id),
+ LiveContent::VideoFrame(video_sink_id) => self.video_sinks.contains(&video_sink_id),
+ }
+ }
+}
+
// The viewport-space damage between two frames, or None when a change without bounds needs a
// full repaint. The diff pairs the run tables first: runs that are byte-identical under chains of
// the same shape are never decoded unless their chains or scroll offsets changed. Only the runs
@@ -1381,6 +1406,7 @@ pub fn compute_display_list_damage(
old_frame: DisplayListFrame<'_>,
new_frame: DisplayListFrame<'_>,
viewport_rect: IntRect,
+ live_content_changes: LiveContentChanges<'_>,
) -> Option<IntRect> {
let old_tape = Tape {
bytes: old_frame.command_bytes,
@@ -1495,6 +1521,29 @@ pub fn compute_display_list_damage(
}
}
+ // A record that draws changed live content inside a group is damaged as the whole group.
+ if !live_content_changes.is_empty() {
+ for live_content_record in &new_frame.summary.live_content_records {
+ if damage.covers_viewport() {
+ break;
+ }
+ if !live_content_changes.includes(live_content_record.content) {
+ continue;
+ }
+ let offset = live_content_record.record.record_offset as usize;
+ let header = read_header(&new_frame.command_bytes[offset..]);
+ let payload_start = offset + HEADER_SIZE;
+ damage.add_new_command_damage(
+ &chains,
+ &CommandReference {
+ header,
+ payload: &new_frame.command_bytes[payload_start..payload_start + header.payload_size as usize],
+ context: new_command_runs[live_content_record.record.run_index as usize].context,
+ },
+ );
+ }
+ }
+
damage.add_backdrop_filter_damage(chains.new_side(), new_command_runs);
if damage.changed_unbounded_command {
@@ -1512,6 +1561,7 @@ pub fn compute_display_list_damage(
#[cfg(test)]
mod tests {
use super::*;
+ use crate::display_list::summary::summarize;
// Values of the CSS font-smoothing enum, as the recorder writes them.
const FONT_SMOOTHING_AUTO: u8 = 0;
@@ -1519,7 +1569,8 @@ mod tests {
use crate::display_list::builder::{HEADER_SIZE, note_command};
use crate::display_list::commands::{
BackdropFilterRegion, CanvasId, CompositorMainThreadWheelEventRegion, DisplayListCommand, DisplayListGlyph,
- DrawCanvas, FillRect, FontResourceId, ImageFrameResourceId, InlineClipKind, TextShadowLayer, UniqueNodeId,
+ DrawCanvas, DrawIsolatedGroup, DrawVideoFrame, FillRect, FontResourceId, ImageFrameResourceId, InlineClipKind,
+ TextShadowLayer, UniqueNodeId,
};
use crate::display_list::ffi_bytes::FfiBytes;
use crate::node_slot_id::NodeSlotId;
@@ -1870,16 +1921,19 @@ mod tests {
DisplayListFrame {
command_bytes: old_bytes,
command_runs: &old_bytes.runs,
+ summary: &summarize(old_bytes, &old_bytes.runs),
visual_context_tree: old_tree,
scroll_offsets: old_scroll_offsets,
},
DisplayListFrame {
command_bytes: new_bytes,
command_runs: &new_bytes.runs,
+ summary: &summarize(new_bytes, &new_bytes.runs),
visual_context_tree: new_tree,
scroll_offsets: new_scroll_offsets,
},
viewport_rect,
+ LiveContentChanges::default(),
)
}
@@ -1887,6 +1941,131 @@ mod tests {
ContextRef { spatial, ..context }
}
+ fn damage_for_live_content_changes(
+ bytes: &TestDisplayList,
+ tree: &VisualContextTree,
+ live_content_changes: LiveContentChanges<'_>,
+ ) -> Option<IntRect> {
+ let summary = summarize(bytes, &bytes.runs);
+ let frame = DisplayListFrame {
+ command_bytes: bytes,
+ command_runs: &bytes.runs,
+ summary: &summary,
+ visual_context_tree: tree,
+ scroll_offsets: &[],
+ };
+ compute_display_list_damage(frame, frame, IntRect::new(0, 0, 100, 100), live_content_changes)
+ }
+
+ #[test]
+ fn changed_live_content_damages_where_it_is_drawn() {
+ let tree = identity_tree();
+ let rect = IntRect::new(10, 10, 20, 20);
+ let canvas = canvas_command_bytes(rect, 0);
+ let changed_canvas = LiveContentChanges {
+ canvases: &[CanvasId(1)],
+ ..LiveContentChanges::default()
+ };
+ assert_eq!(
+ damage_for_live_content_changes(&canvas, &tree, changed_canvas),
+ Some(IntRect::new(9, 9, 22, 22))
+ );
+ let other_canvas = LiveContentChanges {
+ canvases: &[CanvasId(2)],
+ ..LiveContentChanges::default()
+ };
+ assert_eq!(
+ damage_for_live_content_changes(&canvas, &tree, other_canvas),
+ Some(IntRect::default())
+ );
+
+ let video = command_bytes(
+ &DrawVideoFrame {
+ dst_rect: rect,
+ video_sink_id: VideoSinkResourceId(1),
+ scaling_mode: ScalingMode::NearestNeighbor,
+ },
+ Some(rect),
+ ContextRef::default(),
+ );
+ let changed_video = LiveContentChanges {
+ video_sinks: &[VideoSinkResourceId(1)],
+ ..LiveContentChanges::default()
+ };
+ assert_eq!(
+ damage_for_live_content_changes(&video, &tree, changed_video),
+ Some(IntRect::new(9, 9, 22, 22))
+ );
+ assert_eq!(
+ damage_for_live_content_changes(&video, &tree, changed_canvas),
+ Some(IntRect::default())
+ );
+ }
+
+ #[test]
+ fn changed_live_content_under_a_blur_damages_its_blurred_footprint() {
+ let mut tree = identity_tree();
+ let context = context_in(
+ VISUAL_VIEWPORT_NODE_INDEX,
+ effect_context(&mut tree, effects(blur_filter(2.0))),
+ );
+ let rect = IntRect::new(10, 10, 20, 20);
+ let canvas = command_bytes(
+ &DrawCanvas {
+ dst_rect: rect,
+ canvas_id: CanvasId(1),
+ content_generation: 0,
+ scaling_mode: ScalingMode::NearestNeighbor,
+ },
+ Some(rect),
+ context,
+ );
+ let changed_canvas = LiveContentChanges {
+ canvases: &[CanvasId(1)],
+ ..LiveContentChanges::default()
+ };
+ assert_eq!(
+ damage_for_live_content_changes(&canvas, &tree, changed_canvas),
+ Some(IntRect::new(3, 3, 34, 34))
+ );
+ }
+
+ #[test]
+ fn changed_live_content_inside_a_group_damages_the_whole_group() {
+ let tree = identity_tree();
+ let group_rect = IntRect::new(5, 5, 40, 40);
+ let content = canvas_command_bytes(IntRect::new(10, 10, 20, 20), 0);
+ let no_data = DisplayListDataSpan { offset: 0, size: 0 };
+ let mut group = TestDisplayList::default();
+ append_record(
+ &mut group,
+ &DrawIsolatedGroup {
+ clip_rect: group_rect.to_float(),
+ content: DisplayListDataSpan {
+ offset: std::mem::size_of::<DrawIsolatedGroup>() as u32,
+ size: content.len() as u32,
+ },
+ mask: no_data,
+ filter: no_data,
+ opacity: 1.0,
+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,
+ mask_kind: MaskKind::Alpha,
+ },
+ &content,
+ Some(group_rect),
+ ContextRef::default(),
+ &[],
+ );
+ let changed_canvas = LiveContentChanges {
+ canvases: &[CanvasId(1)],
+ ..LiveContentChanges::default()
+ };
+ assert_eq!(
+ damage_for_live_content_changes(&group, &tree, changed_canvas),
+ Some(IntRect::new(4, 4, 42, 42))
+ );
+ }
+
#[test]
fn a_child_stored_below_its_parent_damages_like_the_in_order_tree() {
let mut in_order = identity_tree();
diff --git a/Libraries/LibCompositing/Rust/src/display_list/storage.rs b/Libraries/LibCompositing/Rust/src/display_list/storage.rs
index 7c0d2d57054..87d948decc4 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/storage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/storage.rs
@@ -362,6 +362,8 @@ pub struct FfiReferencedResourceIds {
pub video_sink_id_count: usize,
pub display_list_ids: *const u64,
pub display_list_id_count: usize,
+ pub canvas_ids: *const u64,
+ pub canvas_id_count: usize,
}
/// The ids of the resources the commands of the list reference, including the commands nested in
@@ -383,6 +385,8 @@ pub unsafe extern "C" fn display_list_storage_referenced_resource_ids(
video_sink_id_count: summary.video_sink_ids.len(),
display_list_ids: summary.display_list_ids.as_ptr(),
display_list_id_count: summary.display_list_ids.len(),
+ canvas_ids: summary.canvas_ids.as_ptr(),
+ canvas_id_count: summary.canvas_ids.len(),
}
}
@@ -420,35 +424,22 @@ pub unsafe extern "C" fn display_list_storage_for_each_compositor_metadata(
);
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-#[repr(u8)]
-pub enum FfiIndexedRecordKind {
- DrawnCanvas,
- Caret,
-}
-
-/// Calls `visit` with each top-level DrawCanvas or PaintCaret record of the list: its run's context,
-/// its bounding rect, and its payload.
+/// Calls `visit` with each top-level PaintCaret record of the list: its run's context, its bounding
+/// rect, and its payload.
///
/// # Safety
/// `storage` must be a live storage handle. `visit` runs synchronously.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn display_list_storage_for_each_indexed_record(
+pub unsafe extern "C" fn display_list_storage_for_each_caret(
storage: *const c_void,
- kind: FfiIndexedRecordKind,
context: *mut c_void,
visit: unsafe extern "C" fn(*mut c_void, ContextRef, libgfx_rust::IntRect, *const u8, usize),
) {
let storage = unsafe { storage_from_handle(storage) };
- let summary = storage.summary();
- let records = match kind {
- FfiIndexedRecordKind::DrawnCanvas => &summary.drawn_canvases,
- FfiIndexedRecordKind::Caret => &summary.carets,
- };
for_each_indexed_record(
storage.bytes(),
storage.command_runs(),
- records,
+ &storage.summary().carets,
|run_context, header, payload| {
// SAFETY: The caller reads the payload synchronously.
unsafe {
diff --git a/Libraries/LibCompositing/Rust/src/display_list/summary.rs b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
index b1b7ad75f53..c3096528105 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/summary.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! What C++ asks about a display list's tape: the resources its commands reference, whether reusing a raster of it
-//! can differ from replaying it, its compositor metadata, and where it draws canvases and carets.
+//! What C++ and damage ask about a display list's tape: the resources its commands reference, whether reusing a
+//! raster of it can differ from replaying it, its compositor metadata, its carets, and where it draws live content.
use super::builder::{HEADER_SIZE, for_each_command, read_command};
use super::commands::*;
@@ -22,14 +22,29 @@ pub struct IndexedRecord {
pub record_offset: u32,
}
+// Content that changes under the list's immutable commands.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum LiveContent {
+ Canvas(CanvasId),
+ VideoFrame(VideoSinkResourceId),
+}
+
+// A top-level record that draws live content, itself or in a record nested in it.
+#[derive(Clone, Copy, Debug)]
+pub struct LiveContentRecord {
+ pub record: IndexedRecord,
+ pub content: LiveContent,
+}
+
#[derive(Default)]
pub struct DisplayListSummary {
pub font_ids: Vec<u64>,
pub image_frame_ids: Vec<u64>,
pub video_sink_ids: Vec<u64>,
pub display_list_ids: Vec<u64>,
- pub drawn_canvases: Vec<IndexedRecord>,
+ pub canvas_ids: Vec<u64>,
pub carets: Vec<IndexedRecord>,
+ pub live_content_records: Vec<LiveContentRecord>,
}
#[derive(Default)]
@@ -38,6 +53,17 @@ struct ReferencedIds {
image_frames: HashSet<u64>,
video_sinks: HashSet<u64>,
display_lists: HashSet<u64>,
+ canvases: HashSet<u64>,
+}
+
+fn live_content_of(command_type: DisplayListCommandType, payload: &[u8]) -> Option<LiveContent> {
+ match command_type {
+ DisplayListCommandType::DrawCanvas => Some(LiveContent::Canvas(read_command::<DrawCanvas>(payload).canvas_id)),
+ DisplayListCommandType::DrawVideoFrame => Some(LiveContent::VideoFrame(
+ read_command::<DrawVideoFrame>(payload).video_sink_id,
+ )),
+ _ => None,
+ }
}
fn note_referenced_ids(command_type: DisplayListCommandType, payload: &[u8], ids: &mut ReferencedIds) {
@@ -65,6 +91,9 @@ fn note_referenced_ids(command_type: DisplayListCommandType, payload: &[u8], ids
ids.video_sinks
.insert(read_command::<DrawVideoFrame>(payload).video_sink_id.0);
}
+ T::DrawCanvas => {
+ ids.canvases.insert(read_command::<DrawCanvas>(payload).canvas_id.0);
+ }
T::PaintNestedDisplayList => {
ids.display_lists
.insert(read_command::<PaintNestedDisplayList>(payload).display_list_id.0);
@@ -83,7 +112,6 @@ fn note_referenced_ids(command_type: DisplayListCommandType, payload: &[u8], ids
| T::PaintCaret
| T::DrawRepeatedTile
| T::DrawCompositedContext
- | T::DrawCanvas
| T::PaintLinearGradient
| T::PaintRadialGradient
| T::PaintConicGradient
@@ -139,15 +167,23 @@ pub fn summarize(tape: &[u8], command_runs: &[DisplayListCommandRun]) -> Display
run_index: run_index as u32,
record_offset: (run_start + offset) as u32,
};
- match header.command_type {
- DisplayListCommandType::DrawCanvas => summary.drawn_canvases.push(indexed),
- DisplayListCommandType::PaintCaret => summary.carets.push(indexed),
- _ => {}
+ if header.command_type == DisplayListCommandType::PaintCaret {
+ summary.carets.push(indexed);
}
note_referenced_ids(header.command_type, payload, &mut ids);
+ let mut note_live_content = |command_type, payload: &[u8]| {
+ if let Some(content) = live_content_of(command_type, payload) {
+ summary.live_content_records.push(LiveContentRecord {
+ record: indexed,
+ content,
+ });
+ }
+ };
+ note_live_content(header.command_type, payload);
for_each_nested_record_span(header.command_type, payload, |_, span| {
for_each_record_including_nested(span_bytes(payload, span), &mut |command_type, payload| {
note_referenced_ids(command_type, payload, &mut ids);
+ note_live_content(command_type, payload);
});
});
});
@@ -156,6 +192,7 @@ pub fn summarize(tape: &[u8], command_runs: &[DisplayListCommandRun]) -> Display
summary.image_frame_ids = sorted(ids.image_frames);
summary.video_sink_ids = sorted(ids.video_sinks);
summary.display_list_ids = sorted(ids.display_lists);
+ summary.canvas_ids = sorted(ids.canvases);
summary
}
diff --git a/Libraries/LibCompositing/Rust/src/ffi.rs b/Libraries/LibCompositing/Rust/src/ffi.rs
index e540be4cad7..8235c3653ad 100644
--- a/Libraries/LibCompositing/Rust/src/ffi.rs
+++ b/Libraries/LibCompositing/Rust/src/ffi.rs
@@ -42,10 +42,10 @@ pub unsafe extern "C" fn ladybird_web_force_dark_should_filter_image(
/// # Safety
///
-/// Both storages must be live storage handles, both trees live retained tree handles, and both
-/// offset pointers must address the stated number of points for the call. Writes the damage rect
-/// through `out_damage_rect` and returns whether the damage is bounded; unbounded damage means the
-/// whole viewport must repaint.
+/// Both storages must be live storage handles, both trees live retained tree handles, and the
+/// offset and id pointers must address the stated number of items for the call. Writes the damage
+/// rect through `out_damage_rect` and returns whether the damage is bounded; unbounded damage means
+/// the whole viewport must repaint.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn display_list_compute_damage(
old_storage: *const c_void,
@@ -57,6 +57,10 @@ pub unsafe extern "C" fn display_list_compute_damage(
new_scroll_offsets: *const libgfx_rust::FloatPoint,
new_scroll_offsets_len: usize,
viewport_rect: libgfx_rust::IntRect,
+ canvases_with_new_content: *const crate::display_list::commands::CanvasId,
+ canvases_with_new_content_len: usize,
+ video_sinks_with_new_frames: *const crate::display_list::commands::VideoSinkResourceId,
+ video_sinks_with_new_frames_len: usize,
out_damage_rect: *mut libgfx_rust::IntRect,
) -> bool {
// SAFETY: The caller guarantees live handles and valid slices for the duration of the call.
@@ -70,20 +74,30 @@ pub unsafe extern "C" fn display_list_compute_damage(
ak::slice_from_raw_parts(new_scroll_offsets, new_scroll_offsets_len),
)
};
+ // SAFETY: As above.
+ let live_content_changes = unsafe {
+ crate::display_list::damage::LiveContentChanges {
+ canvases: ak::slice_from_raw_parts(canvases_with_new_content, canvases_with_new_content_len),
+ video_sinks: ak::slice_from_raw_parts(video_sinks_with_new_frames, video_sinks_with_new_frames_len),
+ }
+ };
let damage = crate::display_list::damage::compute_display_list_damage(
crate::display_list::damage::DisplayListFrame {
command_bytes: old_storage.bytes(),
command_runs: old_storage.command_runs(),
+ summary: old_storage.summary(),
visual_context_tree: old_tree,
scroll_offsets: old_scroll_offsets,
},
crate::display_list::damage::DisplayListFrame {
command_bytes: new_storage.bytes(),
command_runs: new_storage.command_runs(),
+ summary: new_storage.summary(),
visual_context_tree: new_tree,
scroll_offsets: new_scroll_offsets,
},
viewport_rect,
+ live_content_changes,
);
match damage {
Some(damage_rect) => {
diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cpp
index d6d60e31619..5f653bdaa10 100644
--- a/Services/Compositor/ContextPresenter.cpp
+++ b/Services/Compositor/ContextPresenter.cpp
@@ -441,15 +441,20 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
return viewport_rect;
}
- auto const& visual_context_tree = m_scene.visual_context_tree_for_compositing();
+ Vector<Compositing::CanvasId> canvases_with_new_content;
+ for (auto const& [canvas_id, content_generation] : last_frame.canvas_content_generations) {
+ if (m_canvas_surfaces.canvas_content_generation(canvas_id) != content_generation)
+ canvases_with_new_content.append(canvas_id);
+ }
auto display_list_damage = Compositing::compute_display_list_damage(
*last_frame.display_list,
last_frame.visual_context_tree,
last_frame.scroll_state_snapshot,
*m_scene.display_list(),
- visual_context_tree,
+ m_scene.visual_context_tree_for_compositing(),
presented_scroll_state_snapshot,
- viewport_rect);
+ viewport_rect,
+ { .canvases = canvases_with_new_content, .video_sinks = {} });
if (!display_list_damage.has_value())
return viewport_rect;
@@ -461,20 +466,6 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
continue;
damage_rect.unite(scrollbar.gutter_rect.united(scrollbar.expanded_gutter_rect));
}
- m_scene.display_list()->for_each_drawn_canvas([&](auto context, auto bounding_rect, auto const& draw_canvas) {
- auto last_content_generation = last_frame.canvas_content_generations.get(draw_canvas.canvas_id);
- if (last_content_generation.has_value() && *last_content_generation == m_canvas_surfaces.canvas_content_generation(draw_canvas.canvas_id))
- return;
- auto canvas_rect = visual_context_tree.transform_rect_to_viewport(context.spatial, bounding_rect.template to_type<float>(), presented_scroll_state_snapshot);
- if (!isfinite(canvas_rect.x()) || !isfinite(canvas_rect.y()) || !isfinite(canvas_rect.width()) || !isfinite(canvas_rect.height())) {
- damage_rect = viewport_rect;
- return;
- }
- canvas_rect.intersect(viewport_rect.to_type<float>());
- if (canvas_rect.is_empty())
- return;
- damage_rect.unite(Gfx::enclosing_int_rect(canvas_rect).inflated(1, 1, 1, 1));
- });
damage_rect.intersect(viewport_rect);
return damage_rect;
}
@@ -482,9 +473,10 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
void ContextPresenter::remember_rasterized_frame(Gfx::IntSize viewport_size, Compositing::ScrollStateSnapshot const& presented_scroll_state_snapshot)
{
HashMap<Compositing::CanvasId, u64> canvas_content_generations;
- m_scene.display_list()->for_each_drawn_canvas([&](auto, auto, auto const& draw_canvas) {
- canvas_content_generations.set(draw_canvas.canvas_id, m_canvas_surfaces.canvas_content_generation(draw_canvas.canvas_id));
- });
+ for (auto id : m_scene.display_list()->referenced_resource_ids().canvases) {
+ Compositing::CanvasId canvas_id { id };
+ canvas_content_generations.set(canvas_id, m_canvas_surfaces.canvas_content_generation(canvas_id));
+ }
m_last_rasterized_frame = RasterizedFrame {
.display_list = NonnullRefPtr { *m_scene.display_list() },
.visual_context_tree = m_scene.visual_context_tree_for_compositing(),