Skip to content

Commit cbdd312

Browse files
author
bors-servo
authored
Auto merge of #502 - kvark:prim_transform, r=glennw
Local rectangle clipping for transformed primitives Finishes #427 implementation, now the text is cut evenly and not aligned to tile borders. Also refactored `build_bounding_rect()` as well as a bit of `assign_prims_to_screen_tiles()`. ![textrun-comparison3](https://cloud.githubusercontent.com/assets/107301/19860234/5ce0c85a-9f5e-11e6-82f2-d72f19e4641a.png) <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/502) <!-- Reviewable:end -->
2 parents 97e5a6e + b2b6079 commit cbdd312

File tree

3 files changed

+29
-44
lines changed

3 files changed

+29
-44
lines changed

webrender/res/prim_shared.glsl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ vec4 get_layer_pos(vec2 pos, Layer layer) {
439439
return untransform(pos, n, a, layer.inv_transform);
440440
}
441441

442+
vec2 clamp_rect(vec2 point, vec4 rect) {
443+
return clamp(point, rect.xy, rect.xy + rect.zw);
444+
}
445+
442446
struct Rect {
443447
vec2 p0;
444448
vec2 p1;
@@ -463,9 +467,7 @@ VertexInfo write_vertex(vec4 instance_rect,
463467
vec2 cp1 = floor(0.5 + (local_clip_rect.xy + local_clip_rect.zw) * uDevicePixelRatio) / uDevicePixelRatio;
464468
local_pos = clamp(local_pos, cp0, cp1);
465469

466-
local_pos = clamp(local_pos,
467-
layer.local_clip_rect.xy,
468-
layer.local_clip_rect.xy + layer.local_clip_rect.zw);
470+
local_pos = clamp_rect(local_pos, layer.local_clip_rect);
469471

470472
vec4 world_pos = layer.transform * vec4(local_pos, 0, 1);
471473
world_pos.xyz /= world_pos.w;
@@ -495,15 +497,16 @@ struct TransformVertexInfo {
495497
};
496498

497499
TransformVertexInfo write_transform_vertex(vec4 instance_rect,
498-
vec4 local_clip_rect, //unused
500+
vec4 local_clip_rect,
499501
Layer layer,
500502
Tile tile) {
501-
vec2 lp0 = clamp(instance_rect.xy,
502-
layer.local_clip_rect.xy,
503-
layer.local_clip_rect.xy + layer.local_clip_rect.zw);
504-
vec2 lp1 = clamp(instance_rect.xy + instance_rect.zw,
505-
layer.local_clip_rect.xy,
506-
layer.local_clip_rect.xy + layer.local_clip_rect.zw);
503+
vec2 lp0_base = instance_rect.xy;
504+
vec2 lp1_base = instance_rect.xy + instance_rect.zw;
505+
506+
vec2 lp0 = clamp_rect(clamp_rect(lp0_base, local_clip_rect),
507+
layer.local_clip_rect);
508+
vec2 lp1 = clamp_rect(clamp_rect(lp1_base, local_clip_rect),
509+
layer.local_clip_rect);
507510

508511
vec4 clipped_local_rect = vec4(lp0, lp1 - lp0);
509512

webrender/src/prim_store.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -656,28 +656,20 @@ impl PrimitiveStore {
656656
layer_transform: &Matrix4D<f32>,
657657
layer_combined_local_clip_rect: &Rect<f32>,
658658
device_pixel_ratio: f32) -> bool {
659-
let mut bounding_rect = None;
660-
let mut visible = false;
661659
let geom = &self.gpu_geometry.get(GpuStoreAddress(prim_index.0 as i32));
662660

663-
match geom.local_rect
664-
.intersection(&geom.local_clip_rect)
665-
.and_then(|rect| rect.intersection(layer_combined_local_clip_rect)) {
666-
Some(local_rect) => {
667-
let xf_rect = TransformedRect::new(&local_rect,
668-
layer_transform,
669-
device_pixel_ratio);
670-
if xf_rect.bounding_rect
671-
.intersects(screen_rect) {
672-
bounding_rect = Some(xf_rect.bounding_rect);
673-
visible = true;
674-
}
675-
}
676-
None => {}
677-
};
661+
let bounding_rect = geom.local_rect
662+
.intersection(&geom.local_clip_rect)
663+
.and_then(|rect| rect.intersection(layer_combined_local_clip_rect))
664+
.and_then(|ref local_rect| {
665+
let xf_rect = TransformedRect::new(local_rect,
666+
layer_transform,
667+
device_pixel_ratio);
668+
xf_rect.bounding_rect.intersection(screen_rect)
669+
});
678670

679671
self.cpu_bounding_rects[prim_index.0] = bounding_rect;
680-
visible
672+
bounding_rect.is_some()
681673
}
682674

683675
pub fn prepare_prim_for_render(&mut self,

webrender/src/tiling.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,26 +1991,16 @@ impl FrameBuilder {
19911991
let p_tile_x1 = (p_rect.origin.x + p_rect.size.width + SCREEN_TILE_SIZE - 1) / SCREEN_TILE_SIZE;
19921992
let p_tile_y1 = (p_rect.origin.y + p_rect.size.height + SCREEN_TILE_SIZE - 1) / SCREEN_TILE_SIZE;
19931993

1994-
let p_tile_x0 = cmp::min(p_tile_x0, tile_range.x1);
1995-
let p_tile_x0 = cmp::max(p_tile_x0, tile_range.x0);
1996-
let p_tile_x1 = cmp::min(p_tile_x1, tile_range.x1);
1997-
let p_tile_x1 = cmp::max(p_tile_x1, tile_range.x0);
1998-
1999-
let p_tile_y0 = cmp::min(p_tile_y0, tile_range.y1);
2000-
let p_tile_y0 = cmp::max(p_tile_y0, tile_range.y0);
2001-
let p_tile_y1 = cmp::min(p_tile_y1, tile_range.y1);
2002-
let p_tile_y1 = cmp::max(p_tile_y1, tile_range.y0);
2003-
2004-
for py in p_tile_y0..p_tile_y1 {
2005-
for px in p_tile_x0..p_tile_x1 {
1994+
for py in cmp::max(p_tile_y0, tile_range.y0) .. cmp::min(p_tile_y1, tile_range.y1) {
1995+
for px in cmp::max(p_tile_x0, tile_range.x0) .. cmp::min(p_tile_x1, tile_range.x1) {
20061996
let tile = &mut screen_tiles[(py * x_tile_count + px) as usize];
20071997

20081998
// TODO(gw): Support narrow phase for 3d transform elements!
20091999
if xf_rect.kind == TransformedRectKind::Complex ||
2010-
self.prim_store.prim_affects_tile(prim_index,
2011-
&tile.rect,
2012-
&packed_layer.transform,
2013-
self.device_pixel_ratio) {
2000+
self.prim_store.prim_affects_tile(prim_index,
2001+
&tile.rect,
2002+
&packed_layer.transform,
2003+
self.device_pixel_ratio) {
20142004
tile.push_primitive(prim_index);
20152005
}
20162006
}

0 commit comments

Comments
 (0)