commit d47a5157712c408dc3c1deea61ceabe6ac0b53e1
parent e2f89177a368a81792e1016fa43dbd1e77eb4796
Author: Glenn Watson <git@chillybin.org>
Date: Fri, 19 Dec 2025 04:28:32 +0000
Bug 2004303 - Ensure should_snap is respected for nested reference frames r=gfx-reviewers,lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D277124
Diffstat:
7 files changed, 95 insertions(+), 3 deletions(-)
diff --git a/gfx/wr/webrender/src/scene_building.rs b/gfx/wr/webrender/src/scene_building.rs
@@ -1200,6 +1200,17 @@ impl<'a> SceneBuilder<'a> {
},
};
+ let snap_origin = match info.reference_frame.kind {
+ ReferenceFrameKind::Transform { should_snap, .. } => should_snap,
+ ReferenceFrameKind::Perspective { .. } => false,
+ };
+
+ let origin = if snap_origin {
+ info.origin.round()
+ } else {
+ info.origin
+ };
+
let external_scroll_offset = self.current_external_scroll_offset(parent_space);
self.push_reference_frame(
@@ -1209,7 +1220,7 @@ impl<'a> SceneBuilder<'a> {
info.reference_frame.transform_style,
transform,
info.reference_frame.kind,
- (info.origin + external_scroll_offset).to_vector(),
+ (origin + external_scroll_offset).to_vector(),
SpatialNodeUid::external(info.reference_frame.key, pipeline_id, instance_id),
);
}
diff --git a/gfx/wr/wrench/reftests/snap/Ahem.ttf b/gfx/wr/wrench/reftests/snap/Ahem.ttf
Binary files differ.
diff --git a/gfx/wr/wrench/reftests/snap/fractional-root-frame-ref.yaml b/gfx/wr/wrench/reftests/snap/fractional-root-frame-ref.yaml
@@ -0,0 +1,35 @@
+---
+root:
+ items:
+ - type: clip
+ id: 35
+ complex:
+ - rect: [53.366665, 85.0, 3746.633335, 2075.0]
+ radius:
+ top-left: [8.0, 8.0]
+
+ - type: clip-chain
+ id: 20
+ clips: [35]
+
+ - type: stacking-context
+ bounds: [53, 85.0, 3746.633335, 2075.0]
+ transform: identity()
+ items:
+ - type: stacking-context
+ bounds: [0.0, 0.0, 3746.633335, 2075.0]
+ clip-chain: 20
+ items:
+ - type: scroll-frame
+ id: 2
+ bounds: [0, 0, 3747.0, 14087.066]
+ content-size: [3747.0, 2075.0]
+ items:
+ - type: text
+ bounds: [47.0, 55.083332, 342.3, 35.0]
+ clip-rect: [46.0, 54.083332, 344.3, 36.999998000000005]
+ font: Ahem.ttf
+ size: 18
+ color: [21, 20, 26, 1]
+ glyphs: [55]
+ offsets: [48.0, 82.083336]
diff --git a/gfx/wr/wrench/reftests/snap/fractional-root-frame.yaml b/gfx/wr/wrench/reftests/snap/fractional-root-frame.yaml
@@ -0,0 +1,39 @@
+# verify that a fractional bounds in a reference frame is correctly snapped
+# if the should_snap field is set by caller
+---
+root:
+ items:
+ - type: clip
+ id: 35
+ complex:
+ - rect: [53.366665, 85.0, 3746.633335, 2075.0]
+ radius:
+ top-left: [8.0, 8.0]
+
+ - type: clip-chain
+ id: 20
+ clips: [35]
+
+ - type: stacking-context
+ bounds: [53.366665, 85.0, 3746.633335, 2075.0]
+ transform: identity()
+ is-2d: true
+ should-snap: true
+ items:
+ - type: stacking-context
+ bounds: [0.0, 0.0, 3746.633335, 2075.0]
+ clip-chain: 20
+ items:
+ - type: scroll-frame
+ id: 2
+ bounds: [0, 0, 3747.0, 14087.066]
+ content-size: [3747.0, 2075.0]
+ items:
+ - type: text
+ bounds: [47.0, 55.083332, 342.3, 35.0]
+ clip-rect: [46.0, 54.083332, 344.3, 36.999998000000005]
+ font: Ahem.ttf
+ size: 18
+ color: [21, 20, 26, 1]
+ glyphs: [55]
+ offsets: [48.0, 82.083336]
diff --git a/gfx/wr/wrench/reftests/snap/reftest.list b/gfx/wr/wrench/reftests/snap/reftest.list
@@ -5,3 +5,4 @@ fuzzy(128,200) == subpixel-raster-root.yaml subpixel-raster-root-ref.yaml
platform(linux,mac) == fractional-filter.yaml fractional-filter-ref.yaml
max_surface_size(256) == 1761299.yaml 1761299.yaml
== content-offset.yaml content-offset-ref.yaml
+== fractional-root-frame.yaml fractional-root-frame-ref.yaml
diff --git a/gfx/wr/wrench/src/yaml_frame_reader.rs b/gfx/wr/wrench/src/yaml_frame_reader.rs
@@ -1894,12 +1894,15 @@ impl YamlFrameReader {
.as_point()
.unwrap_or(default_transform_origin);
+ let is_2d = yaml["is-2d"].as_bool().unwrap_or(false);
+ let should_snap = yaml["should-snap"].as_bool().unwrap_or(false);
+
let reference_frame_kind = if !yaml["perspective"].is_badvalue() {
ReferenceFrameKind::Perspective { scrolling_relative_to: None }
} else {
ReferenceFrameKind::Transform {
- is_2d_scale_translation: false,
- should_snap: false,
+ is_2d_scale_translation: is_2d,
+ should_snap,
paired_with_perspective: yaml["paired-with-perspective"].as_bool().unwrap_or(false),
}
};
diff --git a/gfx/wr/wrench/src/yaml_helper.rs b/gfx/wr/wrench/src/yaml_helper.rs
@@ -333,6 +333,9 @@ impl YamlHelper for Yaml {
let (function, ref args, reminder) = parse_function(slice);
slice = reminder;
let mx = match function {
+ "identity" => {
+ LayoutTransform::identity()
+ }
"translate" if args.len() >= 2 => {
let z = args.get(2).and_then(|a| a.parse().ok()).unwrap_or(0.);
LayoutTransform::translation(