Skip to content

Sync changes from mozilla-central #3506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions webrender/res/ps_text_run.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ TextRun fetch_text_run(int address) {

VertexInfo write_text_vertex(RectWithSize local_clip_rect,
float z,
bool should_snap,
Transform transform,
PictureTask task,
vec2 text_offset,
Expand All @@ -73,13 +74,8 @@ VertexInfo write_text_vertex(RectWithSize local_clip_rect,
vec2 snap_offset = vec2(0.0);
mat2 local_transform;

#ifdef WR_FEATURE_GLYPH_TRANSFORM
bool remove_subpx_offset = true;
#else
bool remove_subpx_offset = transform.is_axis_aligned;
#endif
// Compute the snapping offset only if the scroll node transform is axis-aligned.
if (remove_subpx_offset) {
if (should_snap) {
// Transform from local space to device space.
float device_scale = task.common_data.device_pixel_scale / transform.m[3].w;
mat2 device_transform = mat2(transform.m) * device_scale;
Expand Down Expand Up @@ -178,13 +174,18 @@ void main(void) {
RectWithSize glyph_rect = RectWithSize(res.offset + glyph_transform * (text.offset + glyph.offset),
res.uv_rect.zw - res.uv_rect.xy);

// Since the glyph is pre-transformed, snapping is both forced and does not depend on the transform.
bool should_snap = true;
#else
// Scale from glyph space to local space.
float scale = res.scale / task.common_data.device_pixel_scale;

// Compute the glyph rect in local space.
RectWithSize glyph_rect = RectWithSize(scale * res.offset + text.offset + glyph.offset,
scale * (res.uv_rect.zw - res.uv_rect.xy));

// Check if the primitive is actually safe to snap.
bool should_snap = ph.user_data.x != 0;
#endif

vec2 snap_bias;
Expand Down Expand Up @@ -214,6 +215,7 @@ void main(void) {

VertexInfo vi = write_text_vertex(ph.local_clip_rect,
ph.z,
should_snap,
transform,
task,
text.offset,
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ impl AlphaBatchBuilder {
}
};

let prim_header_index = prim_headers.push(&prim_header, z_id, [0; 3]);
let prim_header_index = prim_headers.push(&prim_header, z_id, [run.should_snap as i32, 0, 0]);
let key = BatchKey::new(kind, blend_mode, textures);
let base_instance = GlyphInstance::new(
prim_header_index,
Expand Down
7 changes: 7 additions & 0 deletions webrender/src/prim_store/text_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl AsInstanceKind<TextRunDataHandle> for TextRunKey {
used_font: self.font.clone(),
glyph_keys_range: storage::Range::empty(),
shadow: self.shadow,
should_snap: true,
});

PrimitiveInstanceKind::TextRun{ data_handle, run_index }
Expand Down Expand Up @@ -227,6 +228,7 @@ pub struct TextRunPrimitive {
pub used_font: FontInstance,
pub glyph_keys_range: storage::Range<GlyphKey>,
pub shadow: bool,
pub should_snap: bool,
}

impl TextRunPrimitive {
Expand Down Expand Up @@ -262,6 +264,11 @@ impl TextRunPrimitive {
FontTransform::identity()
};

// We can snap only if the transform is axis-aligned and in screen-space.
self.should_snap =
transform.preserves_2d_axis_alignment() &&
raster_space == RasterSpace::Screen;

// If the transform or device size is different, then the caller of
// this method needs to know to rebuild the glyphs.
let cache_dirty =
Expand Down
Binary file modified wrench/reftests/text/blurred-shadow-local-clip-rect-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions wrench/reftests/text/raster-space-snap-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root:
items:
- type: stacking-context
bounds: [0, 0, 480, 80]
raster-space: screen
items:
- text: "a Bcd Efgh Ijklm Nopqrs Tuvwxyz"
origin: 20.5 50
size: 20
font: "FreeSans.ttf"
10 changes: 10 additions & 0 deletions wrench/reftests/text/raster-space-snap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root:
items:
- type: stacking-context
bounds: [0, 0, 480, 80]
raster-space: local(1.0)
items:
- text: "a Bcd Efgh Ijklm Nopqrs Tuvwxyz"
origin: 20.5 50
size: 20
font: "FreeSans.ttf"
1 change: 1 addition & 0 deletions wrench/reftests/text/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ fuzzy(1,113) platform(linux) == raster-space.yaml raster-space.png
== shadow-image.yaml shadow-solid-ref.yaml
options(disable-aa) == snap-clip.yaml snap-clip-ref.yaml
platform(linux) == perspective-clip.yaml perspective-clip.png
options(disable-subpixel) != raster-space-snap.yaml raster-space-snap-ref.yaml
Binary file modified wrench/reftests/text/two-shadows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.