From 309c5e0a366882a10bb5baf8e9eb584f08846b44 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Fri, 24 May 2024 14:25:47 +0000 Subject: [PATCH] Bug 1898460 - Disambiguate some of the usage of 'surface' in coordinate spaces (Part 2). r=gw Differential Revision: https://phabricator.services.mozilla.com/D211389 --- gfx/wr/webrender/src/composite.rs | 20 ++++----- gfx/wr/webrender/src/picture.rs | 74 +++++++++++++++---------------- gfx/wr/webrender/src/quad.rs | 6 +-- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/gfx/wr/webrender/src/composite.rs b/gfx/wr/webrender/src/composite.rs index a9bae6628635..b68d2270d693 100644 --- a/gfx/wr/webrender/src/composite.rs +++ b/gfx/wr/webrender/src/composite.rs @@ -521,9 +521,9 @@ impl Default for CompositeStatePreallocator { #[cfg_attr(feature = "replay", derive(Deserialize))] pub struct CompositorTransform { // Map from local rect of a composite tile to the real backing surface coords - local_to_surface: ScaleOffset, + local_to_raster: ScaleOffset, // Map from surface coords to the final device space position - surface_to_device: ScaleOffset, + raster_to_device: ScaleOffset, // Combined local -> surface -> device transform local_to_device: ScaleOffset, } @@ -590,16 +590,16 @@ impl CompositeState { /// Register use of a transform for a picture cache tile or external surface pub fn register_transform( &mut self, - local_to_surface: ScaleOffset, - surface_to_device: ScaleOffset, + local_to_raster: ScaleOffset, + raster_to_device: ScaleOffset, ) -> CompositorTransformIndex { let index = CompositorTransformIndex(self.transforms.len()); - let local_to_device = local_to_surface.accumulate(&surface_to_device); + let local_to_device = local_to_raster.accumulate(&raster_to_device); self.transforms.push(CompositorTransform { - local_to_surface, - surface_to_device, + local_to_raster, + raster_to_device, local_to_device, }); @@ -626,8 +626,8 @@ impl CompositeState { ) -> DeviceRect { let transform = &self.transforms[transform_index.0]; - let surface_bounds = transform.local_to_surface.map_rect(&local_bounds); - let surface_rect = transform.local_to_surface.map_rect(&local_sub_rect); + let surface_bounds = transform.local_to_raster.map_rect(&local_bounds); + let surface_rect = transform.local_to_raster.map_rect(&local_sub_rect); surface_rect .round_out() @@ -652,7 +652,7 @@ impl CompositeState { transform_index: CompositorTransformIndex, ) -> ScaleOffset { let transform = &self.transforms[transform_index.0]; - transform.surface_to_device + transform.raster_to_device } /// Register an occluder during picture cache updates that can be diff --git a/gfx/wr/webrender/src/picture.rs b/gfx/wr/webrender/src/picture.rs index 9cff55236aa9..97551623844b 100644 --- a/gfx/wr/webrender/src/picture.rs +++ b/gfx/wr/webrender/src/picture.rs @@ -1829,12 +1829,12 @@ pub struct TileCacheInstance { frame_id: FrameId, /// Registered transform in CompositeState for this picture cache pub transform_index: CompositorTransformIndex, - /// Current transform mapping local picture space to compositor surface space - local_to_surface: ScaleOffset, + /// Current transform mapping local picture space to compositor surface raster space + local_to_raster: ScaleOffset, + /// Current transform mapping compositor surface raster space to final device space + raster_to_device: ScaleOffset, /// If true, we need to invalidate all tiles during `post_update` invalidate_all_tiles: bool, - /// Current transform mapping compositor surface space to final device space - surface_to_device: ScaleOffset, /// The current raster scale for tiles in this cache current_raster_scale: f32, /// Depth of off-screen surfaces that are currently pushed during dependency updates @@ -1903,8 +1903,8 @@ impl TileCacheInstance { external_native_surface_cache: FastHashMap::default(), frame_id: FrameId::INVALID, transform_index: CompositorTransformIndex::INVALID, - surface_to_device: ScaleOffset::identity(), - local_to_surface: ScaleOffset::identity(), + raster_to_device: ScaleOffset::identity(), + local_to_raster: ScaleOffset::identity(), invalidate_all_tiles: true, current_raster_scale: 1.0, current_surface_traversal_depth: 0, @@ -2189,29 +2189,29 @@ impl TileCacheInstance { ); // Get the compositor transform, which depends on pinch-zoom mode - let mut surface_to_device = local_to_device; + let mut raster_to_device = local_to_device; if frame_context.config.low_quality_pinch_zoom { - surface_to_device.scale.x /= self.current_raster_scale; - surface_to_device.scale.y /= self.current_raster_scale; + raster_to_device.scale.x /= self.current_raster_scale; + raster_to_device.scale.y /= self.current_raster_scale; } else { - surface_to_device.scale.x = 1.0; - surface_to_device.scale.y = 1.0; + raster_to_device.scale.x = 1.0; + raster_to_device.scale.y = 1.0; } // Use that compositor transform to calculate a relative local to surface - let local_to_surface = local_to_device.accumulate(&surface_to_device.inverse()); + let local_to_raster = local_to_device.accumulate(&raster_to_device.inverse()); const EPSILON: f32 = 0.001; let compositor_translation_changed = - !surface_to_device.offset.x.approx_eq_eps(&self.surface_to_device.offset.x, &EPSILON) || - !surface_to_device.offset.y.approx_eq_eps(&self.surface_to_device.offset.y, &EPSILON); + !raster_to_device.offset.x.approx_eq_eps(&self.raster_to_device.offset.x, &EPSILON) || + !raster_to_device.offset.y.approx_eq_eps(&self.raster_to_device.offset.y, &EPSILON); let compositor_scale_changed = - !surface_to_device.scale.x.approx_eq_eps(&self.surface_to_device.scale.x, &EPSILON) || - !surface_to_device.scale.y.approx_eq_eps(&self.surface_to_device.scale.y, &EPSILON); + !raster_to_device.scale.x.approx_eq_eps(&self.raster_to_device.scale.x, &EPSILON) || + !raster_to_device.scale.y.approx_eq_eps(&self.raster_to_device.scale.y, &EPSILON); let surface_scale_changed = - !local_to_surface.scale.x.approx_eq_eps(&self.local_to_surface.scale.x, &EPSILON) || - !local_to_surface.scale.y.approx_eq_eps(&self.local_to_surface.scale.y, &EPSILON); + !local_to_raster.scale.x.approx_eq_eps(&self.local_to_raster.scale.x, &EPSILON) || + !local_to_raster.scale.y.approx_eq_eps(&self.local_to_raster.scale.y, &EPSILON); if compositor_translation_changed || compositor_scale_changed || @@ -2220,8 +2220,8 @@ impl TileCacheInstance { frame_state.composite_state.dirty_rects_are_valid = false; } - self.surface_to_device = surface_to_device; - self.local_to_surface = local_to_surface; + self.raster_to_device = raster_to_device; + self.local_to_raster = local_to_raster; self.invalidate_all_tiles = surface_scale_changed || frame_context.config.force_invalidation; // Do a hacky diff of opacity binding values from the last frame. This is @@ -2264,8 +2264,8 @@ impl TileCacheInstance { ); self.tile_size = PictureSize::new( - world_tile_size.width / self.local_to_surface.scale.x, - world_tile_size.height / self.local_to_surface.scale.y, + world_tile_size.width / self.local_to_raster.scale.x, + world_tile_size.height / self.local_to_raster.scale.y, ); // Inflate the needed rect a bit, so that we retain tiles that we have drawn @@ -2698,8 +2698,8 @@ impl TileCacheInstance { let normalized_prim_to_device = prim_offset.accumulate(&local_prim_to_device); - let local_to_surface = ScaleOffset::identity(); - let surface_to_device = normalized_prim_to_device; + let local_to_raster = ScaleOffset::identity(); + let raster_to_device = normalized_prim_to_device; // If this primitive is an external image, and supports being used // directly by a native compositor, then lookup the external image id @@ -2717,14 +2717,14 @@ impl TileCacheInstance { if let CompositorKind::Native { capabilities, .. } = composite_state.compositor_kind { if external_image_id.is_some() && !capabilities.supports_external_compositor_surface_negative_scaling && - (surface_to_device.scale.x < 0.0 || surface_to_device.scale.y < 0.0) { + (raster_to_device.scale.x < 0.0 || raster_to_device.scale.y < 0.0) { external_image_id = None; } } let compositor_transform_index = composite_state.register_transform( - local_to_surface, - surface_to_device, + local_to_raster, + raster_to_device, ); let surface_size = composite_state.get_surface_rect( @@ -2957,17 +2957,17 @@ impl TileCacheInstance { // If the primitive is directly drawn onto this picture cache surface, then // the pic_coverage_rect is in the same space. If not, we need to map it from - // the surface space into the picture cache space. + // the intermediate picture space into the picture cache space. let on_picture_surface = prim_surface_index == self.surface_index; let pic_coverage_rect = if on_picture_surface { prim_clip_chain.pic_coverage_rect } else { - // We want to get the rect in the tile cache surface space that this primitive + // We want to get the rect in the tile cache picture space that this primitive // occupies, in order to enable correct invalidation regions. Each surface // that exists in the chain between this primitive and the tile cache surface // may have an arbitrary inflation factor (for example, in the case of a series // of nested blur elements). To account for this, step through the current - // surface stack, mapping the primitive rect into each surface space, including + // surface stack, mapping the primitive rect into each picture space, including // the inflation factor from each intermediate surface. let mut current_pic_coverage_rect = prim_clip_chain.pic_coverage_rect; let mut current_spatial_node_index = surfaces[prim_surface_index.0] @@ -2977,7 +2977,7 @@ impl TileCacheInstance { let surface = &surfaces[surface_index.0]; let pic = &pictures[pic_index.0]; - let map_local_to_picture = SpaceMapper::new_with_target( + let map_local_to_parent = SpaceMapper::new_with_target( surface.surface_spatial_node_index, current_spatial_node_index, surface.unclipped_local_rect, @@ -2987,7 +2987,7 @@ impl TileCacheInstance { // Map the rect into the parent surface, and inflate if this surface requires // it. If the rect can't be mapping (e.g. due to an invalid transform) then // just bail out from the dependencies and cull this primitive. - current_pic_coverage_rect = match map_local_to_picture.map(¤t_pic_coverage_rect) { + current_pic_coverage_rect = match map_local_to_parent.map(¤t_pic_coverage_rect) { Some(rect) => { // TODO(gw): The casts here are a hack. We have some interface inconsistencies // between layout/picture rects which don't really work with the @@ -3638,10 +3638,10 @@ impl TileCacheInstance { self.subpixel_mode = self.calculate_subpixel_mode(); self.transform_index = frame_state.composite_state.register_transform( - self.local_to_surface, + self.local_to_raster, // TODO(gw): Once we support scaling of picture cache tiles during compositing, // that transform gets plugged in here! - self.surface_to_device, + self.raster_to_device, ); let map_pic_to_world = SpaceMapper::new_with_target( @@ -3877,10 +3877,10 @@ pub struct SurfaceInfo { /// Helper structs for mapping local rects in different /// coordinate systems into the picture coordinates. pub map_local_to_picture: SpaceMapper, - /// Defines the positioning node for the surface itself, - /// and the rasterization root for this surface. - pub raster_spatial_node_index: SpatialNodeIndex, + /// The positioning node for the surface itself, pub surface_spatial_node_index: SpatialNodeIndex, + /// The rasterization root for this surface. + pub raster_spatial_node_index: SpatialNodeIndex, /// The device pixel ratio specific to this surface. pub device_pixel_scale: DevicePixelScale, /// The scale factors of the surface to world transform. diff --git a/gfx/wr/webrender/src/quad.rs b/gfx/wr/webrender/src/quad.rs index 35075f5d8daa..28dd32409747 100644 --- a/gfx/wr/webrender/src/quad.rs +++ b/gfx/wr/webrender/src/quad.rs @@ -195,12 +195,12 @@ pub fn push_quad( let clip_coverage_rect = surface .map_to_device_rect(&clip_chain.pic_coverage_rect, frame_context.spatial_tree); - surface.map_local_to_surface.set_target_spatial_node( + surface.map_local_to_picture.set_target_spatial_node( prim_spatial_node_index, frame_context.spatial_tree, ); - let Some(pic_rect) = surface.map_local_to_surface.map(local_rect) else { return }; + let Some(pic_rect) = surface.map_local_to_picture.map(local_rect) else { return }; let unclipped_surface_rect = surface.map_to_device_rect( &pic_rect, frame_context.spatial_tree @@ -321,7 +321,7 @@ pub fn push_quad( } if !scratch.quad_direct_segments.is_empty() { - let local_to_device = map_prim_to_surface.as_2d_scale_offset() + let local_to_device = map_prim_to_raster.as_2d_scale_offset() .expect("bug: nine-patch segments should be axis-aligned only") .scale(device_pixel_scale.0);