commit 30f39fabcdce08e5507fb18637a03fb46aff8cd2
parent 800255b55030980cba9b32f08c0e0b3a648fd341
Author: Nicolas Silva <nical@fastmail.com>
Date: Mon, 15 Dec 2025 10:53:23 +0000
Bug 1998913 - Part 15 - Move PrimitiveDescriptor and TileDescriptor from tile_cache to cached_surface. r=gfx-reviewers,gw
Also rename TileDescriptor into CachedSurfaceDescriptor.
Differential Revision: https://phabricator.services.mozilla.com/D276379
Diffstat:
5 files changed, 126 insertions(+), 130 deletions(-)
diff --git a/gfx/wr/webrender/src/invalidation/cached_surface.rs b/gfx/wr/webrender/src/invalidation/cached_surface.rs
@@ -23,14 +23,13 @@ use crate::print_tree::PrintTreePrinter;
use crate::resource_cache::ResourceCache;
use crate::space::SpaceMapper;
use crate::spatial_tree::SpatialNodeIndex;
-use crate::tile_cache::{TileDescriptor, PrimitiveDescriptor, PrimitiveDependencyIndex};
use crate::visibility::FrameVisibilityContext;
use peek_poke::poke_into_vec;
use std::mem;
pub struct CachedSurface {
- pub current_descriptor: TileDescriptor,
- pub prev_descriptor: TileDescriptor,
+ pub current_descriptor: CachedSurfaceDescriptor,
+ pub prev_descriptor: CachedSurfaceDescriptor,
pub is_valid: bool,
pub local_valid_rect: PictureBox2D,
pub local_dirty_rect: PictureRect,
@@ -44,8 +43,8 @@ pub struct CachedSurface {
impl CachedSurface {
pub fn new() -> Self {
CachedSurface {
- current_descriptor: TileDescriptor::new(),
- prev_descriptor: TileDescriptor::new(),
+ current_descriptor: CachedSurfaceDescriptor::new(),
+ prev_descriptor: CachedSurfaceDescriptor::new(),
is_valid: false,
local_valid_rect: PictureBox2D::zero(),
local_dirty_rect: PictureRect::zero(),
@@ -380,3 +379,118 @@ impl PrimitiveDependencyInfo {
}
}
}
+
+/// Information about a primitive that is a dependency for a cached surface.
+#[derive(Debug, Clone)]
+#[cfg_attr(feature = "capture", derive(Serialize))]
+#[cfg_attr(feature = "replay", derive(Deserialize))]
+pub struct PrimitiveDescriptor {
+ pub prim_uid: ItemUid,
+ pub prim_clip_box: PictureBox2D,
+ // TODO(gw): These two fields could be packed as a u24/u8
+ pub dep_offset: u32,
+ pub dep_count: u32,
+}
+
+impl PartialEq for PrimitiveDescriptor {
+ fn eq(&self, other: &Self) -> bool {
+ const EPSILON: f32 = 0.001;
+
+ if self.prim_uid != other.prim_uid {
+ return false;
+ }
+
+ use euclid::approxeq::ApproxEq;
+ if !self.prim_clip_box.min.x.approx_eq_eps(&other.prim_clip_box.min.x, &EPSILON) {
+ return false;
+ }
+ if !self.prim_clip_box.min.y.approx_eq_eps(&other.prim_clip_box.min.y, &EPSILON) {
+ return false;
+ }
+ if !self.prim_clip_box.max.x.approx_eq_eps(&other.prim_clip_box.max.x, &EPSILON) {
+ return false;
+ }
+ if !self.prim_clip_box.max.y.approx_eq_eps(&other.prim_clip_box.max.y, &EPSILON) {
+ return false;
+ }
+
+ if self.dep_count != other.dep_count {
+ return false;
+ }
+
+ true
+ }
+}
+
+impl PartialEq<PrimitiveDescriptor> for (&ItemUid, &PictureBox2D) {
+ fn eq(&self, other: &PrimitiveDescriptor) -> bool {
+ self.0 == &other.prim_uid && self.1 == &other.prim_clip_box
+ }
+}
+
+/// An index into the prims array in a TileDescriptor.
+#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[cfg_attr(feature = "capture", derive(Serialize))]
+#[cfg_attr(feature = "replay", derive(Deserialize))]
+pub struct PrimitiveDependencyIndex(pub u32);
+
+/// Uniquely describes the content of this cached surface, in a way that can be
+/// (reasonably) efficiently hashed and compared.
+#[cfg_attr(any(feature="capture",feature="replay"), derive(Clone))]
+#[cfg_attr(feature = "capture", derive(Serialize))]
+#[cfg_attr(feature = "replay", derive(Deserialize))]
+pub struct CachedSurfaceDescriptor {
+ /// List of primitive instance unique identifiers. The uid is guaranteed
+ /// to uniquely describe the content of the primitive template, while
+ /// the other parameters describe the clip chain and instance params.
+ pub prims: Vec<PrimitiveDescriptor>,
+
+ /// Picture space rect that contains valid pixels region of this tile.
+ pub local_valid_rect: PictureRect,
+
+ /// The last frame this tile had its dependencies updated (dependency updating is
+ /// skipped if a tile is off-screen).
+ pub last_updated_frame_id: FrameId,
+
+ /// Packed per-prim dependency information
+ pub dep_data: Vec<u8>,
+}
+
+impl CachedSurfaceDescriptor {
+ pub fn new() -> Self {
+ CachedSurfaceDescriptor {
+ local_valid_rect: PictureRect::zero(),
+ dep_data: Vec::new(),
+ prims: Vec::new(),
+ last_updated_frame_id: FrameId::INVALID,
+ }
+ }
+
+ /// Print debug information about this tile descriptor to a tree printer.
+ pub fn print(&self, pt: &mut dyn crate::print_tree::PrintTreePrinter) {
+ pt.new_level("current_descriptor".to_string());
+
+ pt.new_level("prims".to_string());
+ for prim in &self.prims {
+ pt.new_level(format!("prim uid={}", prim.prim_uid.get_uid()));
+ pt.add_item(format!("clip: p0={},{} p1={},{}",
+ prim.prim_clip_box.min.x,
+ prim.prim_clip_box.min.y,
+ prim.prim_clip_box.max.x,
+ prim.prim_clip_box.max.y,
+ ));
+ pt.end_level();
+ }
+ pt.end_level();
+
+ pt.end_level();
+ }
+
+ /// Clear the dependency information for a tile, when the dependencies
+ /// are being rebuilt.
+ pub fn clear(&mut self) {
+ self.local_valid_rect = PictureRect::zero();
+ self.prims.clear();
+ self.dep_data.clear();
+ }
+}
diff --git a/gfx/wr/webrender/src/invalidation/dependency.rs b/gfx/wr/webrender/src/invalidation/dependency.rs
@@ -15,7 +15,7 @@ use crate::spatial_tree::{SpatialTree, SpatialNodeIndex, CoordinateSpaceMapping}
use crate::internal_types::{FastHashMap, FastHashSet, FrameId};
use crate::intern::ItemUid;
use crate::resource_cache::{ResourceCache, ImageGeneration};
-use crate::tile_cache::{TileDescriptor, PrimitiveDescriptor, PrimitiveDependencyIndex};
+use crate::invalidation::cached_surface::{PrimitiveDependencyIndex, PrimitiveDescriptor, CachedSurfaceDescriptor};
use peek_poke::{PeekPoke, peek_from_slice};
use std::collections::hash_map::Entry;
@@ -290,7 +290,6 @@ impl SpatialNodeComparer {
}
}
-
/// A key for storing primitive comparison results during tile dependency tests.
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
pub struct PrimitiveComparisonKey {
@@ -312,8 +311,8 @@ pub struct PrimitiveComparer<'a> {
impl<'a> PrimitiveComparer<'a> {
pub fn new(
- prev: &'a TileDescriptor,
- curr: &'a TileDescriptor,
+ prev: &'a CachedSurfaceDescriptor,
+ curr: &'a CachedSurfaceDescriptor,
resource_cache: &'a ResourceCache,
spatial_node_comparer: &'a mut SpatialNodeComparer,
opacity_bindings: &'a FastHashMap<PropertyBindingId, OpacityBindingInfo>,
diff --git a/gfx/wr/webrender/src/invalidation/quadtree.rs b/gfx/wr/webrender/src/invalidation/quadtree.rs
@@ -13,8 +13,8 @@ use crate::debug_colors;
use crate::internal_types::FastHashMap;
use crate::prim_store::PrimitiveScratchBuffer;
use crate::space::SpaceMapper;
-use crate::tile_cache::{PrimitiveDescriptor, PrimitiveDependencyIndex};
use crate::invalidation::{InvalidationReason, PrimitiveCompareResult};
+use crate::invalidation::cached_surface::{PrimitiveDescriptor, PrimitiveDependencyIndex};
use crate::invalidation::dependency::PrimitiveComparer;
use crate::visibility::FrameVisibilityContext;
use std::mem;
diff --git a/gfx/wr/webrender/src/lib.rs b/gfx/wr/webrender/src/lib.rs
@@ -194,7 +194,8 @@ pub use crate::screen_capture::{AsyncScreenshotHandle, RecordedFrameHandle};
pub use crate::texture_cache::TextureCacheConfig;
pub use api as webrender_api;
pub use webrender_build::shader::{ProgramSourceDigest, ShaderKind};
-pub use crate::tile_cache::{TileDescriptor, TileId};
+pub use crate::tile_cache::TileId;
+pub use crate::invalidation::cached_surface::CachedSurfaceDescriptor;
pub use crate::invalidation::InvalidationReason;
pub use crate::invalidation::{PrimitiveCompareResult, CompareHelperResult};
pub use crate::picture::{TileNode, TileNodeKind};
diff --git a/gfx/wr/webrender/src/tile_cache/mod.rs b/gfx/wr/webrender/src/tile_cache/mod.rs
@@ -21,7 +21,6 @@ use crate::composite::{ExternalSurfaceDependency, NativeSurfaceId, NativeTileId}
use crate::composite::{CompositorClipIndex, CompositorTransformIndex};
use crate::composite::{CompositeTileDescriptor, CompositeTile};
use crate::gpu_types::ZBufferId;
-use crate::intern::ItemUid;
use crate::internal_types::{FastHashMap, FrameId, Filter};
use crate::invalidation::{InvalidationReason, DirtyRegion, PrimitiveCompareResult};
use crate::invalidation::cached_surface::{CachedSurface, TileUpdateDirtyContext, TileUpdateDirtyState, PrimitiveDependencyInfo};
@@ -48,7 +47,7 @@ use euclid::approxeq::ApproxEq;
use euclid::Box2D;
use peek_poke::{PeekPoke, ensure_red_zone};
use std::fmt::{Display, Error, Formatter};
-use std::{marker, mem, u32};
+use std::{marker, mem};
use std::sync::atomic::{AtomicUsize, Ordering};
pub use self::slice_builder::{
@@ -124,12 +123,6 @@ pub struct TileKey {
pub sub_slice_index: SubSliceIndex,
}
-/// An index into the prims array in a TileDescriptor.
-#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
-#[cfg_attr(feature = "capture", derive(Serialize))]
-#[cfg_attr(feature = "replay", derive(Deserialize))]
-pub struct PrimitiveDependencyIndex(pub u32);
-
/// Defines which sub-slice (effectively a z-index) a primitive exists on within
/// a picture cache instance.
#[cfg_attr(feature = "capture", derive(Serialize))]
@@ -156,117 +149,6 @@ impl SubSliceIndex {
}
}
-
-/// Information about a primitive that is a dependency for a tile.
-#[derive(Debug, Clone)]
-#[cfg_attr(feature = "capture", derive(Serialize))]
-#[cfg_attr(feature = "replay", derive(Deserialize))]
-pub struct PrimitiveDescriptor {
- pub prim_uid: ItemUid,
- pub prim_clip_box: PictureBox2D,
- // TODO(gw): These two fields could be packed as a u24/u8
- pub dep_offset: u32,
- pub dep_count: u32,
-}
-
-impl PartialEq for PrimitiveDescriptor {
- fn eq(&self, other: &Self) -> bool {
- const EPSILON: f32 = 0.001;
-
- if self.prim_uid != other.prim_uid {
- return false;
- }
-
- use euclid::approxeq::ApproxEq;
- if !self.prim_clip_box.min.x.approx_eq_eps(&other.prim_clip_box.min.x, &EPSILON) {
- return false;
- }
- if !self.prim_clip_box.min.y.approx_eq_eps(&other.prim_clip_box.min.y, &EPSILON) {
- return false;
- }
- if !self.prim_clip_box.max.x.approx_eq_eps(&other.prim_clip_box.max.x, &EPSILON) {
- return false;
- }
- if !self.prim_clip_box.max.y.approx_eq_eps(&other.prim_clip_box.max.y, &EPSILON) {
- return false;
- }
-
- if self.dep_count != other.dep_count {
- return false;
- }
-
- true
- }
-}
-
-impl PartialEq<PrimitiveDescriptor> for (&ItemUid, &PictureBox2D) {
- fn eq(&self, other: &PrimitiveDescriptor) -> bool {
- self.0 == &other.prim_uid && self.1 == &other.prim_clip_box
- }
-}
-
-/// Uniquely describes the content of this tile, in a way that can be
-/// (reasonably) efficiently hashed and compared.
-#[cfg_attr(any(feature="capture",feature="replay"), derive(Clone))]
-#[cfg_attr(feature = "capture", derive(Serialize))]
-#[cfg_attr(feature = "replay", derive(Deserialize))]
-pub struct TileDescriptor {
- /// List of primitive instance unique identifiers. The uid is guaranteed
- /// to uniquely describe the content of the primitive template, while
- /// the other parameters describe the clip chain and instance params.
- pub prims: Vec<PrimitiveDescriptor>,
-
- /// Picture space rect that contains valid pixels region of this tile.
- pub local_valid_rect: PictureRect,
-
- /// The last frame this tile had its dependencies updated (dependency updating is
- /// skipped if a tile is off-screen).
- pub last_updated_frame_id: FrameId,
-
- /// Packed per-prim dependency information
- pub dep_data: Vec<u8>,
-}
-
-impl TileDescriptor {
- pub fn new() -> Self {
- TileDescriptor {
- local_valid_rect: PictureRect::zero(),
- dep_data: Vec::new(),
- prims: Vec::new(),
- last_updated_frame_id: FrameId::INVALID,
- }
- }
-
- /// Print debug information about this tile descriptor to a tree printer.
- pub fn print(&self, pt: &mut dyn crate::print_tree::PrintTreePrinter) {
- pt.new_level("current_descriptor".to_string());
-
- pt.new_level("prims".to_string());
- for prim in &self.prims {
- pt.new_level(format!("prim uid={}", prim.prim_uid.get_uid()));
- pt.add_item(format!("clip: p0={},{} p1={},{}",
- prim.prim_clip_box.min.x,
- prim.prim_clip_box.min.y,
- prim.prim_clip_box.max.x,
- prim.prim_clip_box.max.y,
- ));
- pt.end_level();
- }
- pt.end_level();
-
- pt.end_level();
- }
-
- /// Clear the dependency information for a tile, when the dependencies
- /// are being rebuilt.
- pub fn clear(&mut self) {
- self.local_valid_rect = PictureRect::zero();
- self.prims.clear();
- self.dep_data.clear();
- }
-}
-
-
/// The key that identifies a tile cache instance. For now, it's simple the index of
/// the slice as it was created during scene building.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]