Skip to content

Commit 6bf1f89

Browse files
author
Glenn Watson
committed
Bug 1759647 - Fix segments on snapped picture surface with clips + scale transform r=gfx-reviewers,nical
Differential Revision: https://phabricator.services.mozilla.com/D141182 [ghsync] From https://hg.mozilla.org/mozilla-central/rev/3bfcf747cccfdebd6da85c316b2448dfb17a0323
1 parent c361aa9 commit 6bf1f89

File tree

5 files changed

+49
-47
lines changed

5 files changed

+49
-47
lines changed

webrender/src/batch.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::space::SpaceMapper;
3131
use crate::visibility::{PrimitiveVisibilityFlags, VisibilityState};
3232
use smallvec::SmallVec;
3333
use std::{f32, i32, usize, mem};
34-
use crate::util::{project_rect, MaxRect, MatrixHelpers, TransformedRectKind};
34+
use crate::util::{project_rect, MaxRect, MatrixHelpers, TransformedRectKind, ScaleOffset};
3535
use crate::segment::EdgeAaSegmentMask;
3636

3737
// Special sentinel value recognized by the shader. It is considered to be
@@ -1353,43 +1353,39 @@ impl BatchBuilder {
13531353

13541354
let surface = &ctx.surfaces[raster_config.surface_index.0];
13551355

1356-
// If we are drawing with snapping enabled, the local rect of the prim must be in the raster
1357-
// space, to avoid situations where there is a 180deg rotation in between the root and primitive
1358-
// space not being correctly applied.
1359-
let prim_header = if surface.surface_spatial_node_index == surface.raster_spatial_node_index {
1360-
PrimitiveHeader {
1361-
local_rect: prim_rect,
1362-
local_clip_rect: prim_info.combined_local_clip_rect,
1363-
specific_prim_address: prim_cache_address,
1364-
transform_id,
1365-
}
1356+
// If we are drawing with snapping enabled, form a simple transform that just applies
1357+
// the scale / translation from the raster transform. Otherwise, in edge cases where the
1358+
// intermediate surface has a non-identity but axis-aligned transform (e.g. a 180 degree
1359+
// rotation) it can be applied twice.
1360+
let transform_id = if surface.surface_spatial_node_index == surface.raster_spatial_node_index {
1361+
transform_id
13661362
} else {
13671363
let map_local_to_raster = SpaceMapper::new_with_target(
1368-
surface.raster_spatial_node_index,
1364+
root_spatial_node_index,
13691365
surface.surface_spatial_node_index,
13701366
LayoutRect::max_rect(),
13711367
ctx.spatial_tree,
13721368
);
13731369

1374-
let prim_rect = map_local_to_raster
1370+
let raster_rect = map_local_to_raster
13751371
.map(&prim_rect)
13761372
.unwrap();
1377-
let local_clip_rect = map_local_to_raster
1378-
.map(&prim_info.combined_local_clip_rect)
1379-
.unwrap();
1380-
let transform_id = transforms
1381-
.get_id(
1382-
surface.raster_spatial_node_index,
1383-
root_spatial_node_index,
1384-
ctx.spatial_tree,
1385-
);
13861373

1387-
PrimitiveHeader {
1388-
local_rect: prim_rect,
1389-
local_clip_rect,
1390-
specific_prim_address: prim_cache_address,
1391-
transform_id,
1392-
}
1374+
let sx = (raster_rect.max.x - raster_rect.min.x) / (prim_rect.max.x - prim_rect.min.x);
1375+
let sy = (raster_rect.max.y - raster_rect.min.y) / (prim_rect.max.y - prim_rect.min.y);
1376+
1377+
let tx = raster_rect.min.x - sx * prim_rect.min.x;
1378+
let ty = raster_rect.min.y - sy * prim_rect.min.y;
1379+
1380+
let transform = ScaleOffset::new(sx, sy, tx, ty);
1381+
transforms.get_custom(transform.to_transform())
1382+
};
1383+
1384+
let prim_header = PrimitiveHeader {
1385+
local_rect: prim_rect,
1386+
local_clip_rect: prim_info.combined_local_clip_rect,
1387+
specific_prim_address: prim_cache_address,
1388+
transform_id,
13931389
};
13941390

13951391
let mut is_opaque = prim_info.clip_task_index == ClipTaskIndex::INVALID

webrender/src/gpu_types.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,23 @@ impl TransformPalette {
788788
(transform_kind << 24)
789789
)
790790
}
791+
792+
pub fn get_custom(
793+
&mut self,
794+
transform: LayoutToPictureTransform,
795+
) -> TransformPaletteId {
796+
let index = register_transform(
797+
&mut self.metadata,
798+
&mut self.transforms,
799+
transform,
800+
);
801+
802+
let transform_kind = self.metadata[index].transform_kind as u32;
803+
TransformPaletteId(
804+
(index as u32) |
805+
(transform_kind << 24)
806+
)
807+
}
791808
}
792809

793810
// Texture cache resources can be either a simple rect, or define

webrender/src/picture.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5948,7 +5948,6 @@ impl PicturePrimitive {
59485948

59495949
pub fn prepare_for_render(
59505950
&mut self,
5951-
frame_context: &FrameBuildingContext,
59525951
frame_state: &mut FrameBuildingState,
59535952
data_stores: &mut DataStores,
59545953
) -> bool {
@@ -5984,27 +5983,11 @@ impl PicturePrimitive {
59845983
shadow.blur_radius,
59855984
);
59865985

5987-
let mut shadow_rect = prim_rect.inflate(
5986+
let shadow_rect = prim_rect.inflate(
59885987
blur_inflation_x * BLUR_SAMPLE_SCALE,
59895988
blur_inflation_y * BLUR_SAMPLE_SCALE,
59905989
).translate(shadow.offset);
59915990

5992-
// If we are drawing with snapping enabled, the local rect of the prim must be in the raster
5993-
// space, to avoid situations where there is a 180deg rotation in between the root and primitive
5994-
// space not being correctly applied.
5995-
if surface.surface_spatial_node_index != surface.raster_spatial_node_index {
5996-
let map_local_to_raster = SpaceMapper::new_with_target(
5997-
surface.raster_spatial_node_index,
5998-
surface.surface_spatial_node_index,
5999-
LayoutRect::max_rect(),
6000-
frame_context.spatial_tree,
6001-
);
6002-
6003-
shadow_rect = map_local_to_raster
6004-
.map(&shadow_rect)
6005-
.unwrap();
6006-
}
6007-
60085991
// ImageBrush colors
60095992
request.push(shadow.color.premultiplied());
60105993
request.push(PremultipliedColorF::WHITE);

webrender/src/prepare.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ fn prepare_interned_prim_for_render(
763763
let pic = &mut store.pictures[pic_index.0];
764764

765765
if pic.prepare_for_render(
766-
frame_context,
767766
frame_state,
768767
data_stores,
769768
) {

webrender/src/util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ pub struct ScaleOffset {
135135
}
136136

137137
impl ScaleOffset {
138+
pub fn new(sx: f32, sy: f32, tx: f32, ty: f32) -> Self {
139+
ScaleOffset {
140+
scale: Vector2D::new(sx, sy),
141+
offset: Vector2D::new(tx, ty),
142+
}
143+
}
144+
138145
pub fn identity() -> Self {
139146
ScaleOffset {
140147
scale: Vector2D::new(1.0, 1.0),

0 commit comments

Comments
 (0)