Skip to content

Truly independent web browser

LibCompositing: Let live content changes leave out records

Aliaksandr Kalenikb782b68992d5
diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
index a4e00cd40b2..3e40492f66d 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
@@ -1435,6 +1435,7 @@ pub struct LiveContentChanges<'a> {
pub image_frames: &'a [ImageFrameResourceId],
/// What the compositor repaints whatever the lists hold, such as a blinking caret.
pub forced_damage_rect: IntRect,
+ pub offsets_of_records_composited_as_media_layers: &'a [u32],
}
impl LiveContentChanges<'_> {
@@ -1598,7 +1599,11 @@ pub fn compute_display_list_damage(
if damage.covers_viewport() {
break;
}
- if !live_content_changes.includes(live_content_record.content) {
+ if !live_content_changes.includes(live_content_record.content)
+ || live_content_changes
+ .offsets_of_records_composited_as_media_layers
+ .contains(&live_content_record.record.record_offset)
+ {
continue;
}
let offset = live_content_record.record.record_offset as usize;
@@ -2040,6 +2045,24 @@ mod tests {
compute_display_list_damage(frame, frame, IntRect::new(0, 0, 100, 100), live_content_changes)
}
+ #[test]
+ fn a_record_composited_as_a_media_layer_is_not_damaged_by_its_live_content() {
+ let tree = identity_tree();
+ let mut list = canvas_command_bytes(IntRect::new(10, 10, 20, 20));
+ let media_layer_record_offset = 0;
+ list.extend_from_slice(&fill_command_bytes(IntRect::new(50, 50, 10, 10), RED));
+ list.extend_from_slice(&canvas_command_bytes(IntRect::new(60, 60, 10, 10)));
+ let changed_canvas = LiveContentChanges {
+ canvases: &[CanvasId(1)],
+ offsets_of_records_composited_as_media_layers: &[media_layer_record_offset],
+ ..LiveContentChanges::default()
+ };
+ assert_eq!(
+ damage_for_live_content_changes(&list, &tree, changed_canvas),
+ Some(IntRect::new(59, 59, 12, 12))
+ );
+ }
+
#[test]
fn changed_live_content_damages_where_it_is_drawn() {
let tree = identity_tree();
diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cpp
index 9b741de7574..6dac6695451 100644
--- a/Services/Compositor/ContextPresenter.cpp
+++ b/Services/Compositor/ContextPresenter.cpp
@@ -538,7 +538,7 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
last_frame.frame_inputs,
*last_frame.display_list,
viewport_rect,
- { .canvases = canvases_with_new_content, .video_sinks = video_sinks_with_new_frames, .image_frames = image_frames_with_new_pixels, .forced_damage_rect = forced_damage_rect });
+ { .canvases = canvases_with_new_content, .video_sinks = video_sinks_with_new_frames, .image_frames = image_frames_with_new_pixels, .forced_damage_rect = forced_damage_rect, .offsets_of_records_composited_as_media_layers = {} });
if (!display_list_damage.has_value())
return viewport_rect;
return display_list_damage->intersected(viewport_rect);
diff --git a/Services/Compositor/FrameInputs.cpp b/Services/Compositor/FrameInputs.cpp
index d22a1b8bf8d..6743276cf19 100644
--- a/Services/Compositor/FrameInputs.cpp
+++ b/Services/Compositor/FrameInputs.cpp
@@ -73,6 +73,7 @@ Optional<Gfx::IntRect> FrameInputs::damage_since(Compositing::DisplayList const&
live_content_changes.video_sinks.data(), live_content_changes.video_sinks.size(),
live_content_changes.image_frames.data(), live_content_changes.image_frames.size(),
live_content_changes.forced_damage_rect,
+ live_content_changes.offsets_of_records_composited_as_media_layers.data(), live_content_changes.offsets_of_records_composited_as_media_layers.size(),
&damage_rect);
if (!damage_is_bounded)
return {};
diff --git a/Services/Compositor/FrameInputs.h b/Services/Compositor/FrameInputs.h
index 627f44b6b66..45d37478a5e 100644
--- a/Services/Compositor/FrameInputs.h
+++ b/Services/Compositor/FrameInputs.h
@@ -81,6 +81,7 @@ struct LiveContentChanges {
ReadonlySpan<Compositing::ImageFrameResourceId> image_frames;
// What the compositor repaints whatever the lists hold, such as a blinking caret.
Gfx::IntRect forced_damage_rect;
+ ReadonlySpan<u32> offsets_of_records_composited_as_media_layers;
};
// What a frame is painted with besides the display list and its resources, which the scroll and input logic holds:
diff --git a/Services/Compositor/Rust/src/ffi.rs b/Services/Compositor/Rust/src/ffi.rs
index 423d130cbf6..754ab298092 100644
--- a/Services/Compositor/Rust/src/ffi.rs
+++ b/Services/Compositor/Rust/src/ffi.rs
@@ -384,11 +384,13 @@ pub unsafe extern "C" fn compositor_frame_inputs_replay_records(
/// What a frame painted with `frame_inputs` repaints of the frame painted last, with `last_frame_inputs` and the list
/// `last_display_list_storage` holds. Writes the damage rect through `damage_rect` and returns whether the damage is
-/// bounded; unbounded damage means the whole viewport must repaint.
+/// bounded; unbounded damage means the whole viewport must repaint. Live content changes do not damage the records at
+/// `offsets_of_records_composited_as_media_layers`.
///
/// # Safety
///
-/// Both storages must be live storage handles, and the id pointers must address the stated number of ids for the call.
+/// Both storages must be live storage handles, and the id and offset pointers must address the stated number of
+/// values for the call.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn compositor_frame_inputs_damage_since(
frame_inputs: &FrameInputs,
@@ -403,6 +405,8 @@ pub unsafe extern "C" fn compositor_frame_inputs_damage_since(
image_frames_with_new_pixels: *const ImageFrameResourceId,
image_frames_with_new_pixels_len: usize,
forced_damage_rect: IntRect,
+ offsets_of_records_composited_as_media_layers: *const u32,
+ offsets_of_records_composited_as_media_layers_len: usize,
damage_rect: &mut IntRect,
) -> bool {
// SAFETY: The caller guarantees live handles and valid slices for the duration of the call.
@@ -415,6 +419,10 @@ pub unsafe extern "C" fn compositor_frame_inputs_damage_since(
video_sinks: ak::slice_from_raw_parts(video_sinks_with_new_frames, video_sinks_with_new_frames_len),
image_frames: ak::slice_from_raw_parts(image_frames_with_new_pixels, image_frames_with_new_pixels_len),
forced_damage_rect,
+ offsets_of_records_composited_as_media_layers: ak::slice_from_raw_parts(
+ offsets_of_records_composited_as_media_layers,
+ offsets_of_records_composited_as_media_layers_len,
+ ),
},
)
};