Skip to content

Truly independent web browser

Compositor: Track the canvases that nested display lists draw

Aliaksandr Kalenik6a9f87d587c1
diff --git a/Services/Compositor/Rust/src/nested_display_lists.rs b/Services/Compositor/Rust/src/nested_display_lists.rs
index 082c3f25949..2849a93173a 100644
--- a/Services/Compositor/Rust/src/nested_display_lists.rs
+++ b/Services/Compositor/Rust/src/nested_display_lists.rs
@@ -129,6 +129,24 @@ impl NestedDisplayListStore {
})
}
+ /// The canvases that the lists a list nests draw, at any depth.
+ pub fn canvas_ids_of_nested_display_lists(&self, storage: &DisplayListStorage) -> HashSet<u64> {
+ let mut canvas_ids = HashSet::new();
+ let mut visited = HashSet::new();
+ let mut pending: Vec<u64> = storage.summary().display_list_ids.clone();
+ while let Some(display_list_id) = pending.pop() {
+ if !visited.insert(display_list_id) {
+ continue;
+ }
+ if let Some(nested) = self.display_lists.get(&display_list_id) {
+ let summary = nested.storage.summary();
+ canvas_ids.extend(&summary.canvas_ids);
+ pending.extend(&summary.display_list_ids);
+ }
+ }
+ canvas_ids
+ }
+
// A raster of a list can differ from replaying it in place when a destination-reading operation can see what was
// painted before the list began, or when the list draws live content that changes under its immutable commands.
// A nested list's live content matters at any depth, and its unisolated destination reads matter when its command
diff --git a/Services/Compositor/Rust/src/presenting/damage.rs b/Services/Compositor/Rust/src/presenting/damage.rs
index 028689a5196..1a23bd895a2 100644
--- a/Services/Compositor/Rust/src/presenting/damage.rs
+++ b/Services/Compositor/Rust/src/presenting/damage.rs
@@ -90,10 +90,29 @@ pub struct FrameDamage {
pub live_media_changed: bool,
}
+// The canvases that the list draws, and those that the lists it nests draw.
+fn canvases_drawn_by(display_list: &DisplayList, nested_display_lists: &NestedDisplayListStore) -> Vec<u64> {
+ let mut canvas_ids = display_list.storage().summary().canvas_ids.clone();
+ let canvas_ids_of_list: HashSet<u64> = canvas_ids.iter().copied().collect();
+ canvas_ids.extend(
+ nested_display_lists
+ .canvas_ids_of_nested_display_lists(display_list.storage())
+ .into_iter()
+ .filter(|id| !canvas_ids_of_list.contains(id)),
+ );
+ canvas_ids
+}
+
impl ContextPresenting {
- /// The live content of the context as it is now, with the canvases of the list and of the frame painted last.
- pub(super) fn live_content(&self, env: &PresentingEnvironment<'_>, display_list: &DisplayList) -> LiveContent {
- let mut canvas_ids = display_list.storage().summary().canvas_ids.clone();
+ /// The live content of the context as it is now, with the canvases that the list, the lists it nests and the frame
+ /// painted last draw.
+ pub(super) fn live_content(
+ &self,
+ env: &PresentingEnvironment<'_>,
+ display_list: &DisplayList,
+ nested_display_lists: &NestedDisplayListStore,
+ ) -> LiveContent {
+ let mut canvas_ids = canvases_drawn_by(display_list, nested_display_lists);
if let Some(painted_frame) = &self.painted_frame {
let canvas_ids_of_list: HashSet<u64> = canvas_ids.iter().copied().collect();
canvas_ids.extend(
@@ -120,12 +139,9 @@ impl ContextPresenting {
.get(&id)
.map_or(0, |canvas| canvas.content_generation)
};
- let canvas_content_generations = display_list
- .storage()
- .summary()
- .canvas_ids
- .iter()
- .map(|id| (*id, canvas_generation(*id)))
+ let canvas_content_generations = canvases_drawn_by(display_list, nested_display_lists)
+ .into_iter()
+ .map(|id| (id, canvas_generation(id)))
.collect();
// Every video the context holds is drawn by the list or by a display list it nests.
let video_frame_ids = live_content
@@ -165,6 +181,7 @@ impl ContextPresenting {
changes.repaints_everything = true;
}
+ let canvas_ids_of_list: HashSet<u64> = display_list.storage().summary().canvas_ids.iter().copied().collect();
for (canvas_id, content_generation) in &painted_frame.canvas_content_generations {
let current_content_generation = live_content
.canvases
@@ -173,6 +190,10 @@ impl ContextPresenting {
if current_content_generation == *content_generation {
continue;
}
+ // A canvas drawn only by a nested display list has no command in this list to damage.
+ if !canvas_ids_of_list.contains(canvas_id) {
+ changes.repaints_everything = true;
+ }
changes.canvases.push(CanvasId(*canvas_id));
changes.media_updates.push(MediaUpdate {
media: LiveMedia::Canvas(CanvasId(*canvas_id)),
diff --git a/Services/Compositor/Rust/src/presenting/mod.rs b/Services/Compositor/Rust/src/presenting/mod.rs
index feffd4a349e..dd7aa26d5f8 100644
--- a/Services/Compositor/Rust/src/presenting/mod.rs
+++ b/Services/Compositor/Rust/src/presenting/mod.rs
@@ -530,7 +530,7 @@ impl ContextPresenting {
}
let display_list = display_list.expect("a frame that can render has a display list");
let frame_inputs = frame_inputs.expect("a context with a display list has frame inputs");
- let live_content = self.live_content(env, display_list);
+ let live_content = self.live_content(env, display_list, nested_display_lists);
let frame = FrameToPaint {
display_list,
nested_display_lists,
@@ -617,7 +617,7 @@ impl ContextPresenting {
None => return false,
},
};
- let live_content = self.live_content(env, display_list);
+ let live_content = self.live_content(env, display_list, nested_display_lists);
let frame = FrameToPaint {
display_list,
nested_display_lists,