Skip to content

Truly independent web browser

LibCompositing+Compositor: Find caret and scroll bar changes by hash

Aliaksandr Kalenik3ba82e80a5f8
diff --git a/Libraries/LibCompositing/Rust/src/display_list/storage.rs b/Libraries/LibCompositing/Rust/src/display_list/storage.rs
index 96d17bd801c..e9ff1bb6d03 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/storage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/storage.rs
@@ -15,7 +15,7 @@ use super::chunks::{
use super::commands::{ContextRef, DisplayListCommandHeader, DisplayListCommandRun, DisplayListCommandType};
use super::effect_clip_plan::EffectClipPlan;
use super::placement::RunGroups;
-use super::summary::{DisplayListSummary, IndexedRecord, summarize, summary_of_pieces};
+use super::summary::{DisplayListSummary, summarize, summary_of_pieces};
use super::tile_keys::{ChunkPlacedInRasterSpace, ContentHash, RecordTable};
use super::validate::validate_tape;
use crate::visual_context::VisualContextTree;
@@ -500,18 +500,6 @@ impl DisplayListStorage {
}
}
}
-
- /// Visits indexed top-level records with their run's context, their header and their payload.
- pub fn for_each_indexed_record(
- &self,
- records: &[IndexedRecord],
- mut visit: impl FnMut(ContextRef, &DisplayListCommandHeader, &[u8]),
- ) {
- for record in records {
- let (header, payload) = self.record_at(record.position);
- visit(self.run(record.run_index as usize).context, &header, payload);
- }
- }
}
/// The chunks of a recorded tape, which `chunks` cuts it into, each a copy. What the tape holds past its last chunk is a
diff --git a/Libraries/LibCompositing/Rust/src/display_list/summary.rs b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
index fde115a6e06..1b2fbe24fb6 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/summary.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
@@ -80,7 +80,6 @@ pub struct DisplayListSummary {
pub vector_image_ids: Vec<u64>,
pub canvas_ids: Vec<u64>,
pub composited_context_ids: Vec<u64>,
- pub carets: Vec<IndexedRecord>,
pub live_content_records: Vec<LiveContentRecord>,
pub destination_blending_records: Vec<IndexedRecord>,
pub mask_declarations: Vec<MaskDeclarationRecord>,
@@ -242,13 +241,11 @@ pub fn summarize(tape: &[u8], command_runs: &[DisplayListCommandRun]) -> Display
run_index: run_index as u32,
position: ListPosition::new(ChunkIndexInList(0), (run_start + offset_in_run) as u32),
};
- match header.command_type {
- DisplayListCommandType::PaintCaret => summary.carets.push(indexed_record),
- DisplayListCommandType::DeclareMaskContent => summary.mask_declarations.push(MaskDeclarationRecord {
+ if header.command_type == DisplayListCommandType::DeclareMaskContent {
+ summary.mask_declarations.push(MaskDeclarationRecord {
record: indexed_record,
mask_effect: read_command::<DeclareMaskContent>(payload).effect,
- }),
- _ => {}
+ });
}
if let Some((blend, blends_with_isolated_backdrop_color)) = command_blend(header.command_type, payload)
&& blend != CompositingAndBlendingOperator::Normal
@@ -291,7 +288,6 @@ pub fn summary_of_pieces<'a>(
let mut summary = DisplayListSummary::default();
for (chunk_summary, first_run_index_of_chunk, chunk_index) in pieces {
let shift_into_list = |record: &IndexedRecord| record.shifted_into_list(first_run_index_of_chunk, chunk_index);
- summary.carets.extend(chunk_summary.carets.iter().map(shift_into_list));
summary
.live_content_records
.extend(
diff --git a/Libraries/LibCompositing/Rust/src/display_list/tile_keys.rs b/Libraries/LibCompositing/Rust/src/display_list/tile_keys.rs
index 06ee4585f54..6e59c067b4e 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/tile_keys.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/tile_keys.rs
@@ -12,7 +12,7 @@
//! band bound to another list or geometry bins its tiles again, and a tile that holds what it held before gets the
//! content hash it had before.
-use super::builder::{inline_clips_of, read_command};
+use super::builder::{HEADER_SIZE, inline_clips_of, read_command};
use super::commands::{
ClipNodeIndex, ContextRef, DisplayListCommandRun, DrawCompositedContext, EffectNodeIndex, PaintCaret,
PaintScrollBar, SpatialNodeIndex,
@@ -22,7 +22,9 @@ use super::effect_geometry::{
FiltersOfEffects, LARGEST_FILTER_READ_REACH_IN_DEVICE_PIXELS, backdrop_filter_read_reach,
filter_read_reach_in_device_pixels, nearest_effects_at_or_above_where, spreading_filter_of,
};
-use super::layers::{BandIndex, BarrierCutsOfCell, CutsOfCell, LayerIndex, LayerStack, PlacementNodeBand};
+use super::layers::{
+ BandIndex, BarrierCutsOfCell, CutsOfCell, LayerContent, LayerIndex, LayerStack, PlacementNodeBand,
+};
use super::nested_records::for_each_command_including_nested;
use super::placement::{
ANTIALIASING_MARGIN_IN_DEVICE_PIXELS, FiltersAndClipsOfList, RasterSpaceGeometry, RunGroupIndex, RunGroups,
@@ -51,9 +53,8 @@ mod coverage;
pub(crate) use chunk_placement::ChunkRecord;
pub use chunk_placement::{ChunkPlacedInRasterSpace, PlacedRecordRangeIndex, RecordIndexInChunk, RecordTable};
use chunk_placement::{
- FRAME_STATE_CARET_BLINK_PHASE, FRAME_STATE_LIVE_CONTENT, FRAME_STATE_SAMPLED_BACKGROUND_COLOR,
- FRAME_STATE_SCROLL_BAR, FRAME_STATE_SPACES_OF_INLINE_CLIPS, PlacedRecordRange,
- background_color_animation_effect_of,
+ FRAME_STATE_LIVE_CONTENT, FRAME_STATE_SAMPLED_BACKGROUND_COLOR, FRAME_STATE_SPACES_OF_INLINE_CLIPS,
+ PlacedRecordRange, background_color_animation_effect_of,
};
pub use coverage::TileCoverage;
@@ -237,7 +238,7 @@ impl<'a> TileKeyingOfList<'a> {
replays_every_record_into_every_tile: layering_obstacles.every_tile_replays_every_record()
|| stack.one_layer_list_cannot_tell_which_records_show_in_tile(),
tree_sorts_planes_by_depth: layering_obstacles.sorts_planes_by_depth,
- frame_state_hash: frame_state_hash_of(display_list, &frame_state),
+ frame_state_hash: frame_state_hash_of(display_list, stack, &frame_state),
innermost_composited_effect_by_effect_index,
nearest_composited_or_not_plain_effect_by_effect_index: OnceCell::new(),
nearest_composited_or_alpha_lowering_effect_by_effect_index: OnceCell::new(),
@@ -268,18 +269,44 @@ impl<'a> TileKeyingOfList<'a> {
}
}
-fn version_of_live_content(live_content: &dyn LiveContentVersions, content: LiveContent) -> u64 {
+// Hashes what the frame shows of `content`, which the command of `payload` draws: the version of a canvas, video, image
+// or nested context, whether a caret shows, and where the thumb of a scroll bar is, how far it grows and how much it
+// fades.
+fn write_live_content_shown_by_frame(
+ hasher: &mut ContentHasher,
+ frame_state: &FrameStateReadByReplay<'_>,
+ content: LiveContent,
+ payload: &[u8],
+) {
+ let live_content = frame_state.live_content;
match content {
- LiveContent::Canvas(canvas) => live_content.canvas_content_generation(canvas),
- LiveContent::VideoFrame(video_sink) => live_content.video_frame_id(video_sink).unwrap_or(u64::MAX),
- LiveContent::ImageFrame(image_frame) => live_content
- .image_frame_pixel_generation(image_frame)
- .unwrap_or(u64::MAX),
- LiveContent::CompositedContext(nested_context) => live_content
- .nested_context_frame_generation(nested_context)
- .unwrap_or(u64::MAX),
- // What a caret or a scroll bar shows in the frame is hashed from its record.
- LiveContent::Caret | LiveContent::ScrollBar { .. } => 0,
+ LiveContent::Canvas(canvas) => hasher.write_u64(live_content.canvas_content_generation(canvas)),
+ LiveContent::VideoFrame(video_sink) => {
+ hasher.write_u64(live_content.video_frame_id(video_sink).unwrap_or(u64::MAX));
+ }
+ LiveContent::ImageFrame(image_frame) => hasher.write_u64(
+ live_content
+ .image_frame_pixel_generation(image_frame)
+ .unwrap_or(u64::MAX),
+ ),
+ LiveContent::CompositedContext(nested_context) => hasher.write_u64(
+ live_content
+ .nested_context_frame_generation(nested_context)
+ .unwrap_or(u64::MAX),
+ ),
+ LiveContent::Caret => hasher.write_bool(caret_is_visible_at_time(
+ &read_command::<PaintCaret>(payload),
+ frame_state.time_ns,
+ )),
+ LiveContent::ScrollBar { .. } => {
+ match scrollbar_shown_by_frame(frame_state.scrollbars, &read_command::<PaintScrollBar>(payload)) {
+ Some(scrollbar) => {
+ hasher.write_u32(1);
+ write_scrollbar_shown_by_frame(hasher, scrollbar);
+ }
+ None => hasher.write_u32(2),
+ }
+ }
}
}
@@ -290,26 +317,41 @@ fn write_scrollbar_shown_by_frame(hasher: &mut ContentHasher, scrollbar: &Scroll
hasher.write_f32(scrollbar.opacity);
}
-fn frame_state_hash_of(display_list: &DisplayListStorage, frame_state: &FrameStateReadByReplay<'_>) -> ContentHash {
- let summary = display_list.summary();
+// The hash of what the frame shows of the live content that the records of bands draw, which the tiles of a band that
+// holds such records read. Live content with a layer of its own is in no band, so a blinking caret or a moving thumb
+// with a layer keys no tile anew.
+fn frame_state_hash_of(
+ display_list: &DisplayListStorage,
+ stack: &LayerStack,
+ frame_state: &FrameStateReadByReplay<'_>,
+) -> ContentHash {
+ let mut positions_of_layers_of_their_own: Vec<ListPosition> = stack
+ .layers
+ .iter()
+ .filter_map(|layer| match layer.content {
+ LayerContent::Media { record_span } | LayerContent::OwnSurface { record_span } => Some(record_span.begin),
+ LayerContent::Painted => None,
+ })
+ .collect();
+ positions_of_layers_of_their_own.sort_unstable();
let mut hasher = ContentHasher::new();
- for caret in &summary.carets {
- let (_, payload) = display_list.record_at(caret.position);
- hasher.write_bool(caret_is_visible_at_time(
- &read_command::<PaintCaret>(payload),
- frame_state.time_ns,
- ));
- }
- for scrollbar in frame_state.scrollbars {
- hasher.write_u32(scrollbar.scroll_node_index.0);
- hasher.write_bool(scrollbar.vertical);
- write_scrollbar_shown_by_frame(&mut hasher, scrollbar);
- }
- for live_content_record in &summary.live_content_records {
- hasher.write_u64(version_of_live_content(
- frame_state.live_content,
- live_content_record.content,
- ));
+ let mut position_hashed_last = None;
+ // A record that draws live content in records nested in it is noted once for each.
+ for live_content_record in &display_list.summary().live_content_records {
+ let position = live_content_record.record.position;
+ if position_hashed_last == Some(position) || positions_of_layers_of_their_own.binary_search(&position).is_ok() {
+ continue;
+ }
+ position_hashed_last = Some(position);
+ let (header, _) = display_list.record_at(position);
+ let record_start = position.offset as usize;
+ let record_bytes = &display_list.chunk(position.chunk_index).records()
+ [record_start..record_start + HEADER_SIZE + header.payload_size as usize];
+ for_each_command_including_nested(record_bytes, &mut |command_type, _, payload| {
+ if let Some(content) = live_content_of(command_type, payload) {
+ write_live_content_shown_by_frame(&mut hasher, frame_state, content, payload);
+ }
+ });
}
hasher.finish()
}
@@ -1523,28 +1565,6 @@ impl<'a> TileKeyingOfRasterSpace<'a> {
let frame_state = &list.frame_state;
let record_bytes = &chunk.records()[record.offset as usize..record.end_offset as usize];
let (header, payload) = chunk.record_at(record.offset);
- if record.frame_state_read_flags & FRAME_STATE_CARET_BLINK_PHASE != 0 {
- hasher.write_bool(caret_is_visible_at_time(
- &read_command::<PaintCaret>(payload),
- frame_state.time_ns,
- ));
- }
- if record.frame_state_read_flags & FRAME_STATE_SCROLL_BAR != 0 {
- let command = read_command::<PaintScrollBar>(payload);
- match scrollbar_shown_by_frame(frame_state.scrollbars, &command) {
- Some(scrollbar) => {
- hasher.write_u32(1);
- write_scrollbar_shown_by_frame(hasher, scrollbar);
- }
- None => {
- hasher.write_u32(2);
- hasher.write_float_point(device_offset_for_index(
- &self.geometry.raster_scroll_offsets,
- command.scroll_node_index,
- ));
- }
- }
- }
if record.frame_state_read_flags & FRAME_STATE_SPACES_OF_INLINE_CLIPS != 0 {
for clip in inline_clips_of(&header, payload).filter(|clip| clip.has_own_space) {
match self.geometry.world.draw_matrix_if_known(clip.space) {
@@ -1567,10 +1587,19 @@ impl<'a> TileKeyingOfRasterSpace<'a> {
LiveContent::Caret => 5,
LiveContent::ScrollBar { .. } => 6,
});
- hasher.write_u64(version_of_live_content(frame_state.live_content, content));
- if matches!(content, LiveContent::CompositedContext(_)) {
- let command = read_command::<DrawCompositedContext>(payload);
- hasher.write_bool(tree.translations_snap_to_device_pixels(command.spatial_node_index));
+ write_live_content_shown_by_frame(hasher, frame_state, content, payload);
+ match content {
+ LiveContent::CompositedContext(_) => {
+ let command = read_command::<DrawCompositedContext>(payload);
+ hasher.write_bool(tree.translations_snap_to_device_pixels(command.spatial_node_index));
+ }
+ // A scroll bar that the frame does not show is drawn where the scroll offset its tiles are
+ // rastered at puts it.
+ LiveContent::ScrollBar { scroll_node, .. } => hasher.write_float_point(device_offset_for_index(
+ &self.geometry.raster_scroll_offsets,
+ scroll_node,
+ )),
+ _ => {}
}
}
let background_color_animation_effect = background_color_animation_effect_of(command_type, payload);
@@ -2338,8 +2367,8 @@ mod tests {
use crate::display_list::layers::{LayerIdentity, LayerStack, LayeringObstacles, SpaceToFrame, WhyListIsOneLayer};
use crate::display_list::placement::{RasterSpaceIndex, RasterSpaces, WhatEverySpaceOfTreeShares};
use crate::display_list::test_fixtures::{
- GREEN, ListOfOneChunk, NO_FRAME_STATE, VIEWPORT, animation_of, canvas, chunk_of, effects, fill, frosted_glass,
- opacity_animation_of, raster_settings_hash_by_layer, transform, transform_animation_of,
+ GREEN, ListOfOneChunk, NO_FRAME_STATE, VIEWPORT, animation_of, canvas, caret, chunk_of, effects, fill,
+ frosted_glass, opacity_animation_of, raster_settings_hash_by_layer, transform, transform_animation_of,
tree_with_document_scroll, tree_with_root_isolation_effect,
};
use crate::display_list::tiles::TILE_SIZE_IN_DEVICE_PIXELS;
@@ -2693,6 +2722,73 @@ mod tests {
.collect()
}
+ // A caret with a layer of its own is in no band, so its blinking keys no tile anew, even of a band that holds other
+ // live content and so reads the frame state of the list.
+ #[test]
+ fn a_caret_with_a_layer_keys_no_tile_anew_as_it_blinks() {
+ let (mut tree, root) = tree_with_root_isolation_effect(1.0);
+ let moved_by_filter = tree.append_effect_node_under(
+ root,
+ EffectNodeData::Effects(EffectsData {
+ isolation: false,
+ opacity: 1.0,
+ blend_mode: CompositingAndBlendingOperator::Normal,
+ filter: Some(Arc::new(
+ libgfx_rust::filter::Filter::Offset {
+ dx: 40.0,
+ dy: 0.0,
+ input: None,
+ }
+ .serialize(),
+ )),
+ backdrop_filter: None,
+ }),
+ );
+ let list = ListOfOneChunk::default()
+ .with(fill(VIEWPORT, GREEN), root)
+ .with(canvas(IntRect::new(100, 100, 200, 100), 1), moved_by_filter)
+ .with(caret(IntRect::new(20, 20, 2, 16)), root);
+ let display_list = DisplayListStorage::of_builder(&list.builder);
+ let stack = stack_of(&display_list, &tree);
+ let has_layer_of = |content: LiveContent| {
+ stack
+ .layers
+ .iter()
+ .any(|layer| layer.identity == LayerIdentity::Media { content, ordinal: 0 })
+ };
+ assert!(has_layer_of(LiveContent::Caret) && !has_layer_of(LiveContent::Canvas(CanvasId(1))));
+ let canvas_position = display_list.span_of_run(1).begin;
+ let band_index = BandIndex(
+ stack
+ .bands
+ .iter()
+ .position(|band| band.record_spans.iter().any(|span| span.contains(canvas_position)))
+ .expect("a band holds the canvas"),
+ );
+ let raster_space_index = stack.nodes[stack.bands[band_index.0].placement_node_index.0].raster_space_index;
+ let geometry = geometry_of_space(&tree, &stack, raster_space_index);
+ let live_content = CanvasesAtGeneration(0);
+ let mut band_tile_keys_bound_in_first_frame = None;
+ // The caret shows, hides and shows again.
+ let tiles_keyed: Vec<usize> = [0, 600_000_000, 1_200_000_000]
+ .into_iter()
+ .map(|time_ns| {
+ let frame_state = FrameStateReadByReplay {
+ live_content: &live_content,
+ time_ns,
+ ..NO_FRAME_STATE
+ };
+ let list_keying = TileKeyingOfList::new(&display_list, &tree, &stack, frame_state);
+ let raster_space = TileKeyingOfRasterSpace::new(&list_keying, &geometry);
+ let band_tile_keys = band_tile_keys_bound_in_first_frame
+ .get_or_insert_with(|| raster_space.bind_band(&stack, band_index));
+ key_band(&raster_space, band_tile_keys, &stack, band_index, VIEWPORT).tiles_keyed
+ })
+ .collect();
+ assert!(tiles_keyed[0] > 0);
+ assert_eq!(tiles_keyed[1..], [0, 0]);
+ }
+
#[test]
fn a_new_canvas_frame_keys_again_only_the_bands_whose_records_draw_the_canvas() {
let canvas_rect = IntRect::new(100, 100, 200, 100);
diff --git a/Libraries/LibCompositing/Rust/src/display_list/tile_keys/chunk_placement.rs b/Libraries/LibCompositing/Rust/src/display_list/tile_keys/chunk_placement.rs
index 5e195c18f14..86f62f5ddf6 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/tile_keys/chunk_placement.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/tile_keys/chunk_placement.rs
@@ -25,13 +25,11 @@ use crate::display_list::window_server_placement::RoundedRect;
use libgfx_rust::{Color, CompositingAndBlendingOperator, CornerRadii, IntRect};
use std::sync::Arc;
-pub(super) const FRAME_STATE_CARET_BLINK_PHASE: u8 = 1 << 0;
-pub(super) const FRAME_STATE_SCROLL_BAR: u8 = 1 << 1;
-pub(super) const FRAME_STATE_LIVE_CONTENT: u8 = 1 << 2;
-pub(super) const FRAME_STATE_SPACES_OF_INLINE_CLIPS: u8 = 1 << 3;
-pub(super) const FRAME_STATE_SAMPLED_BACKGROUND_COLOR: u8 = 1 << 4;
-const FRAME_STATE_HASHED_FOR_THE_LIST: u8 =
- FRAME_STATE_CARET_BLINK_PHASE | FRAME_STATE_SCROLL_BAR | FRAME_STATE_LIVE_CONTENT;
+/// The record draws live content, such as a caret or a scroll bar, itself or in a record nested in it, whose look the
+/// frame decides. The frame state of the list hashes that of every such record that is in a band.
+pub(super) const FRAME_STATE_LIVE_CONTENT: u8 = 1 << 0;
+pub(super) const FRAME_STATE_SPACES_OF_INLINE_CLIPS: u8 = 1 << 1;
+pub(super) const FRAME_STATE_SAMPLED_BACKGROUND_COLOR: u8 = 1 << 2;
/// A top-level record of a chunk, with what placing it and hashing tile content read of it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -49,7 +47,7 @@ pub(crate) struct ChunkRecord {
impl ChunkRecord {
pub(super) fn reads_frame_state_hashed_for_the_list(&self) -> bool {
- self.frame_state_read_flags & FRAME_STATE_HASHED_FOR_THE_LIST != 0
+ self.frame_state_read_flags & FRAME_STATE_LIVE_CONTENT != 0
}
}
@@ -70,11 +68,7 @@ fn frame_state_read_flags_of_record(
payload: &[u8],
record_bytes: &[u8],
) -> u8 {
- let mut flags = match header.command_type {
- DisplayListCommandType::PaintCaret => FRAME_STATE_CARET_BLINK_PHASE,
- DisplayListCommandType::PaintScrollBar => FRAME_STATE_SCROLL_BAR,
- _ => 0,
- };
+ let mut flags = 0;
if header.inline_clip_count != 0 && has_inline_clip_in_its_own_space(header, payload) {
flags |= FRAME_STATE_SPACES_OF_INLINE_CLIPS;
}
diff --git a/Libraries/LibCompositing/Rust/src/scrolling/display_list.rs b/Libraries/LibCompositing/Rust/src/scrolling/display_list.rs
index 2c3271f798e..086e148c40d 100644
--- a/Libraries/LibCompositing/Rust/src/scrolling/display_list.rs
+++ b/Libraries/LibCompositing/Rust/src/scrolling/display_list.rs
@@ -7,11 +7,12 @@
//! Everything about a list that travels alongside its chunks when it is sent to the Compositor.
use super::ContextRef;
-use crate::display_list::builder::{bounding_rect_computed_from_payload, read_command};
+use crate::display_list::builder::read_command;
use crate::display_list::commands::{DisplayListCommandType, PaintCaret};
use crate::display_list::storage::DisplayListStorage;
+use crate::display_list::summary::LiveContent;
use crate::display_list::window::RecordedWindow;
-use libgfx_rust::{Color, IntRect};
+use libgfx_rust::Color;
use std::sync::Arc;
pub use crate::ipc_types::Compositing_AsyncScrollingMetadata as AsyncScrollingMetadata;
@@ -86,16 +87,16 @@ impl DisplayList {
self.storage.for_each_compositor_metadata(visit);
}
- // Visits the carets the list draws outside of any group, with the context of their run and their bounding rect.
- pub fn for_each_caret(&self, mut visit: impl FnMut(ContextRef, IntRect, &PaintCaret)) {
- self.storage
- .for_each_indexed_record(&self.storage.summary().carets, |context, header, payload| {
- let command = read_command::<PaintCaret>(payload);
- visit(
- context,
- bounding_rect_computed_from_payload(header, payload).unwrap_or_default(),
- &command,
- );
- });
+ // Visits the carets the list draws outside of any group.
+ pub fn for_each_caret(&self, mut visit: impl FnMut(&PaintCaret)) {
+ for live_content_record in &self.storage.summary().live_content_records {
+ if live_content_record.content != LiveContent::Caret {
+ continue;
+ }
+ let (header, payload) = self.storage.record_at(live_content_record.record.position);
+ if header.command_type == DisplayListCommandType::PaintCaret {
+ visit(&read_command::<PaintCaret>(payload));
+ }
+ }
}
}
diff --git a/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs b/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs
index e989d1d840e..2ebc09f8fb3 100644
--- a/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs
+++ b/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs
@@ -345,19 +345,11 @@ impl ContextState {
}
}
- pub fn advance_scrollbar_fades_and_return_damage_rect(&mut self, frame_time: MonotonicTime) -> IntRect {
- if self.scene.visual_context_tree().is_none() {
- return Default::default();
- }
- let stretched_scroll_state_snapshot = self.scroll_state_snapshot_stretched_by_elastic_overscrolls();
- let presented_scroll_state_snapshot = stretched_scroll_state_snapshot
- .as_ref()
- .unwrap_or(&self.scroll_state_snapshot);
- let damage_rect = self.scrollbar_controller.advance_fades(
- self.scene.visual_context_tree_for_compositing(),
- presented_scroll_state_snapshot,
- frame_time,
- );
+ /// Advances the fades of the scrollbars to a frame. Answers None where none changed, and otherwise what of the viewport
+ /// the frame repaints for them besides what it finds changed.
+ pub fn advance_scrollbar_fades(&mut self, frame_time: MonotonicTime) -> Option<IntRect> {
+ self.scene.visual_context_tree().as_ref()?;
+ let damage_rect = self.scrollbar_controller.advance_fades(frame_time);
self.report_scrollbar_visibility_changes();
damage_rect
}
@@ -410,7 +402,7 @@ impl ContextState {
let capture_time = now;
self.advance_visual_animations(capture_time);
self.update_scrollbar_visibility(now);
- let scrollbar_fade_damage_rect = self.advance_scrollbar_fades_and_return_damage_rect(capture_time);
+ let scrollbar_fade_damage_rect = self.advance_scrollbar_fades(capture_time);
ScreenshotInputs {
frame_inputs: self.frame_inputs_as_presented_now(capture_time),
scrollbar_fade_damage_rect,
diff --git a/Services/Compositor/Rust/src/context_state/keys_and_pointer.rs b/Services/Compositor/Rust/src/context_state/keys_and_pointer.rs
index e5b2fb01c22..63595d738d4 100644
--- a/Services/Compositor/Rust/src/context_state/keys_and_pointer.rs
+++ b/Services/Compositor/Rust/src/context_state/keys_and_pointer.rs
@@ -305,12 +305,16 @@ impl ContextState {
self.pointer_position = position;
}
- // The compositor presents how scrollbars expand, outside of what damage tracking sees.
+ // A frame that shows how the scrollbars grow. The scrollbars the compositor paints itself are outside of what damage
+ // tracking sees, so the frame repaints where they are; it finds what changed of the others in their records.
fn frame_repainting_scrollbars(&self) -> Option<PendingFrame> {
if self.async_scrolling_viewport_rect.is_empty() {
return None;
}
- Some(PendingFrame::repainting_everything(self.async_scrolling_viewport_rect))
+ Some(PendingFrame {
+ viewport_rect: self.async_scrolling_viewport_rect,
+ forced_damage_rect: self.scrollbar_controller.rect_of_scrollbars_painted_by_compositor(),
+ })
}
/// The pointer left the scrollbar it was over here for a context nested in this one, or for the one around it.
diff --git a/Services/Compositor/Rust/src/context_state/mod.rs b/Services/Compositor/Rust/src/context_state/mod.rs
index 3a0cc7a0074..481fedb6679 100644
--- a/Services/Compositor/Rust/src/context_state/mod.rs
+++ b/Services/Compositor/Rust/src/context_state/mod.rs
@@ -36,7 +36,7 @@ use libcompositing_rust::scrolling::smooth_scroll_animation::SmoothScrollAnimati
use libcompositing_rust::scrolling::wheel_gesture_identity::TouchpadGestureEnd;
use libcompositing_rust::scrolling::*;
use libcompositing_rust::time::{Duration, MonotonicTime};
-use libgfx_rust::{FloatPoint, IntRect, IntSize, Orientation, enclosing_int_rect};
+use libgfx_rust::{FloatPoint, IntRect, IntSize, Orientation};
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
@@ -204,8 +204,8 @@ impl Default for ScrollCapabilities {
pub struct ScreenshotInputs {
pub frame_inputs: FrameInputs,
- /// The scrollbar fade damage that the screenshot does not present on screen.
- pub scrollbar_fade_damage_rect: IntRect,
+ /// The scrollbar fade damage that the screenshot does not present on screen, where a fade changed.
+ pub scrollbar_fade_damage_rect: Option<IntRect>,
}
struct ActiveSmoothScrollAnimation {
@@ -613,17 +613,20 @@ impl ContextState {
}
}
- pub fn timer_fired(&mut self, timer: ContextTimer, now: MonotonicTime) -> Option<IntRect> {
+ /// Answers whether the timer asks for a frame, as each blink of a caret does.
+ pub fn timer_fired(&mut self, timer: ContextTimer, now: MonotonicTime) -> bool {
match timer {
ContextTimer::ScrollStepGestureInput => self.end_scroll_step_gestures_whose_input_ran_out(now),
ContextTimer::ScrollbarPaging => {
self.scrollbar_paging_timer_is_armed = false;
if self.scrollbar_paging.is_none() || !self.scrollbar_controller.has_captured_scrollbar() {
self.stop_scrollbar_paging();
- return None;
+ return false;
}
// Once the thumb reaches the pointer, paging waits for the pointer to move.
- self.page_captured_scrollbar(now)?;
+ if self.page_captured_scrollbar(now).is_none() {
+ return false;
+ }
self.request_rendering_update();
self.request_display_ticks_if_needed(now);
self.host.set_timer(
@@ -635,11 +638,9 @@ impl ContextState {
}
ContextTimer::ScrollbarFadeOut => self.request_display_ticks_if_needed(now),
ContextTimer::CaretBlink => {
- let damage_rect = self.damage_rect_of_blinking_carets();
self.schedule_next_caret_blink(now);
- if !damage_rect.is_empty() {
- return Some(damage_rect);
- }
+ // The frame finds what the blink changes in the content hashes of what draws each caret.
+ return true;
}
// The core handles the timers of presenting.
ContextTimer::BackingStoreShrink
@@ -648,7 +649,7 @@ impl ContextState {
| ContextTimer::SpareTileEviction
| ContextTimer::TileRasterScratchSurfaceRelease => {}
}
- None
+ false
}
pub fn request_rendering_update(&mut self) {
@@ -837,7 +838,7 @@ impl ContextState {
fn restart_caret_blink_for(&mut self, display_list: &DisplayList, now: MonotonicTime) {
let mut blink_cycle_start_time_ns = None;
- display_list.for_each_caret(|_, _, caret| {
+ display_list.for_each_caret(|caret| {
if caret.should_blink {
blink_cycle_start_time_ns = Some(caret.blink_cycle_start_time_ns);
}
@@ -867,41 +868,6 @@ impl ContextState {
);
}
- fn damage_rect_of_blinking_carets(&mut self) -> IntRect {
- if self.scene.display_list().is_none() || self.scene.visual_context_tree().is_none() {
- return Default::default();
- }
- let display_list = self.scene.display_list().as_ref().unwrap().clone();
- let visual_context_tree = self.scene.visual_context_tree_for_compositing().clone();
- let stretched_scroll_state_snapshot = self.scroll_state_snapshot_stretched_by_elastic_overscrolls();
- let presented_scroll_state_snapshot = stretched_scroll_state_snapshot
- .as_ref()
- .unwrap_or(&self.scroll_state_snapshot);
- let mut damage_rect = IntRect::default();
- let viewport_rect = IntRect::new(0, 0, self.viewport_size.width, self.viewport_size.height);
- display_list.for_each_caret(|context, bounding_rect, caret| {
- if !caret.should_blink {
- return;
- }
- let mut rect = visual_context_tree.transform_rect_to_viewport(
- context.spatial,
- bounding_rect.to_float(),
- presented_scroll_state_snapshot,
- IncludeVisualViewportTransform::Yes,
- );
- if !rect.x.is_finite() || !rect.y.is_finite() || !rect.width.is_finite() || !rect.height.is_finite() {
- damage_rect = viewport_rect;
- return;
- }
- rect = rect.intersected(viewport_rect.to_float());
- if !rect.is_empty() {
- damage_rect = damage_rect.united(enclosing_int_rect(rect).inflated_edges(1, 1, 1, 1));
- }
- });
- damage_rect = damage_rect.intersected(viewport_rect);
- damage_rect
- }
-
pub fn forget_layer_plan(&mut self) {
self.scene.forget_layer_plan();
}
diff --git a/Services/Compositor/Rust/src/core/mod.rs b/Services/Compositor/Rust/src/core/mod.rs
index b66e0c99123..be2081f369c 100644
--- a/Services/Compositor/Rust/src/core/mod.rs
+++ b/Services/Compositor/Rust/src/core/mod.rs
@@ -909,12 +909,11 @@ impl CompositorCore {
}
}
_ => {
- let caret_damage_rect = context.borrow_mut().timer_fired(timer, now);
- if let Some(caret_damage_rect) = caret_damage_rect {
+ if context.borrow_mut().timer_fired(timer, now) {
self.present_requests.borrow_mut().push(PresentRequest {
context_id,
viewport_rect: None,
- forced_damage_rect: caret_damage_rect,
+ forced_damage_rect: Default::default(),
scheduling: PresentScheduling::OnNextDisplayTick,
});
}
@@ -1016,10 +1015,8 @@ impl CompositorCore {
scheduling: PresentScheduling::WithDisplayTickInProgress,
});
}
- let damage_rect = context
- .borrow_mut()
- .advance_scrollbar_fades_and_return_damage_rect(frame_time);
- if !damage_rect.is_empty() {
+ let damage_rect = context.borrow_mut().advance_scrollbar_fades(frame_time);
+ if let Some(damage_rect) = damage_rect {
self.present_requests.borrow_mut().push(PresentRequest {
context_id,
viewport_rect: None,
diff --git a/Services/Compositor/Rust/src/core/presenting.rs b/Services/Compositor/Rust/src/core/presenting.rs
index cb0d7c491cd..fb029558f75 100644
--- a/Services/Compositor/Rust/src/core/presenting.rs
+++ b/Services/Compositor/Rust/src/core/presenting.rs
@@ -1291,14 +1291,14 @@ impl CompositorCore {
presenting
.borrow_mut()
.paint_screenshot(&environment, target, &display_list, &screenshot_inputs.frame_inputs);
- if !screenshot_inputs.scrollbar_fade_damage_rect.is_empty() {
+ if let Some(forced_damage_rect) = screenshot_inputs.scrollbar_fade_damage_rect {
let viewport_rect = presenting.borrow().viewport_rect_of_current_frame();
if let Some(viewport_rect) = viewport_rect {
self.schedule_present_frame(
context_id,
PendingFrame {
viewport_rect,
- forced_damage_rect: screenshot_inputs.scrollbar_fade_damage_rect,
+ forced_damage_rect,
},
now,
);
diff --git a/Services/Compositor/Rust/src/scrollbar_controller.rs b/Services/Compositor/Rust/src/scrollbar_controller.rs
index 72e4a06ab0a..1e49cf6e265 100644
--- a/Services/Compositor/Rust/src/scrollbar_controller.rs
+++ b/Services/Compositor/Rust/src/scrollbar_controller.rs
@@ -8,11 +8,11 @@ use crate::frame_inputs::{ScrollbarOfFrame, thumb_rect_kept_inside_track};
use libcompositing_rust::scrolling::overlay_fade::OverlayFade;
use libcompositing_rust::scrolling::{
AccumulatedVisualContextTree, AsyncScrollNodeStableID, AsyncScrollTree, AsyncScrollbar, ClipBehavior,
- CompositorContextId, IncludeVisualViewportTransform, OverlayScrollbarVisibility, ScrollStateSnapshot,
- ScrollbarDraggedByCompositor, SpatialNodeIndex,
+ CompositorContextId, OverlayScrollbarVisibility, ScrollStateSnapshot, ScrollbarDraggedByCompositor,
+ SpatialNodeIndex,
};
use libcompositing_rust::time::{Duration, MonotonicTime};
-use libgfx_rust::{FloatPoint, FloatRect, IntRect, Orientation, enclosing_int_rect};
+use libgfx_rust::{FloatPoint, FloatRect, IntRect, Orientation};
#[derive(Default)]
pub struct ScrollbarController {
@@ -644,16 +644,13 @@ impl ScrollbarController {
false
}
- // Returns the rect in the viewport of the scrollbars whose opacity or geometry changed.
- pub fn advance_fades(
- &mut self,
- visual_context_tree: &AccumulatedVisualContextTree,
- scroll_state_snapshot: &ScrollStateSnapshot,
- frame_time: MonotonicTime,
- ) -> IntRect {
+ // Advances the fades to a frame. Answers None where no scrollbar changed, and otherwise the rect in the viewport of the
+ // scrollbars the compositor paints that changed: the frame finds what changed of the others, which the display list
+ // draws, in the content hashes of their records.
+ pub fn advance_fades(&mut self, frame_time: MonotonicTime) -> Option<IntRect> {
+ let mut some_scrollbar_changed = false;
let mut damage_rect = IntRect::default();
- for i in 0..self.scrollbars.len() {
- let visibility = &mut self.visibilities[i];
+ for (scrollbar, visibility) in self.scrollbars.iter().zip(&mut self.visibilities) {
if visibility.fade_out_time.is_some_and(|time| time <= frame_time) {
visibility.fade_out_time = None;
visibility.fade.fade_to(0.0, frame_time);
@@ -664,50 +661,34 @@ impl ScrollbarController {
visibility.expansion.jump_to(0.0);
}
changed |= visibility.expansion.advance_to(frame_time);
- if !changed {
- continue;
- }
- if let Some(rect) = self.rect_in_viewport(i, visual_context_tree, scroll_state_snapshot) {
- damage_rect = damage_rect.united(rect);
+ some_scrollbar_changed |= changed;
+ if changed && scrollbar.is_painted_by_compositor {
+ damage_rect = damage_rect.united(rect_painted_by_compositor(scrollbar));
}
}
- damage_rect
+ some_scrollbar_changed.then_some(damage_rect)
}
- fn rect_in_viewport(
- &self,
- scrollbar_index: usize,
- visual_context_tree: &AccumulatedVisualContextTree,
- scroll_state_snapshot: &ScrollStateSnapshot,
- ) -> Option<IntRect> {
- let scrollbar = self.scrollbars.get(scrollbar_index)?;
- let rect = scrollbar
- .gutter_rect
- .united(scrollbar.track_rect)
- .united(scrollbar.expanded_gutter_rect);
- if scrollbar.is_painted_by_compositor {
- return Some(rect.inflated(2, 2));
- }
- if !visual_context_tree.context_is_valid(scrollbar.context) {
- return None;
- }
- let rect_in_viewport = visual_context_tree.transform_rect_to_viewport(
- scrollbar.context.spatial,
- rect.to_float(),
- scroll_state_snapshot,
- IncludeVisualViewportTransform::Yes,
- );
- if !rect_in_viewport.x.is_finite()
- || !rect_in_viewport.y.is_finite()
- || !rect_in_viewport.width.is_finite()
- || !rect_in_viewport.height.is_finite()
- {
- return None;
- }
- Some(enclosing_int_rect(rect_in_viewport).inflated(2, 2))
+ /// The rect in the viewport of the scrollbars the compositor paints, where they can draw as they grow.
+ pub fn rect_of_scrollbars_painted_by_compositor(&self) -> IntRect {
+ self.scrollbars
+ .iter()
+ .filter(|scrollbar| scrollbar.is_painted_by_compositor)
+ .fold(IntRect::default(), |rect, scrollbar| {
+ rect.united(rect_painted_by_compositor(scrollbar))
+ })
}
}
+// Where the compositor paints a scrollbar of its own over the viewport, with the outline around its thumb.
+fn rect_painted_by_compositor(scrollbar: &AsyncScrollbar) -> IntRect {
+ scrollbar
+ .gutter_rect
+ .united(scrollbar.track_rect)
+ .united(scrollbar.expanded_gutter_rect)
+ .inflated(2, 2)
+}
+
fn interpolated_rect(from: IntRect, to: IntRect, progress: f32) -> FloatRect {
let interpolate = |from: i32, to: i32| from as f32 + (to - from) as f32 * progress;
FloatRect::new(