Skip to content
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

Sync changes from mozilla-central gfx/wr #3859

Merged
merged 4 commits into from Feb 14, 2020
Merged

Bug 1529260 - Match shader and CPU glyph rasterization logic for glyp…

…hs in local space. r=lsalzman

This patch makes the CPU side incorporate the raster scale when
calculating the subpixel position of a glyph. It also makes the shader
side not include the glyph scale factor when recalculating the glyph
position (since it was not known/used when determining the subpixel
position in the first place). This makes the subpixel position stable
when we transition between Screen and Local(raster_scale) spaces.

Differential Revision: https://phabricator.services.mozilla.com/D62812

[ghsync] From https://hg.mozilla.org/mozilla-central/rev/9bd4120bc9779fe1c42fb45246044a23f2e95d25
  • Loading branch information
aosmond authored and moz-gfx committed Feb 14, 2020
commit 6a3732c9d4f7199ddee6a052dd261ee826b03ffc
@@ -186,9 +186,11 @@ void main(void) {
#else
float raster_scale = float(ph.user_data.z) / 65535.0;

// Scale in which the glyph is snapped when rasterized.
float glyph_raster_scale = raster_scale * task.device_pixel_scale;

// Scale from glyph space to local space.
float glyph_scale_inv = res.scale / (raster_scale * task.device_pixel_scale);
float glyph_scale = 1.0 / glyph_scale_inv;
float glyph_scale_inv = res.scale / glyph_raster_scale;

// Glyph raster pixels do not include the impact of the transform. Instead it was
// replaced with an identity transform during glyph rasterization. As such only the
@@ -204,7 +206,7 @@ void main(void) {
// - The transform has perspective or does not have a 2d inverse (Screen or local space).
// - The transform's scale will result in result in very large rasterized glyphs and
// we clamped the size. This will imply local raster space.
vec2 raster_glyph_offset = floor(glyph.offset * glyph_scale + snap_bias);
vec2 raster_glyph_offset = floor(glyph.offset * glyph_raster_scale + snap_bias) / res.scale;

// Compute the glyph rect in local space.
//
@@ -361,10 +361,15 @@ impl TextRunPrimitive {
if self.glyph_keys_range.is_empty() || cache_dirty {
let subpx_dir = self.used_font.get_subpx_dir();

let transform = match self.raster_space {
RasterSpace::Local(scale) => FontTransform::new(scale, 0.0, 0.0, scale),
RasterSpace::Screen => self.used_font.transform,
};

self.glyph_keys_range = scratch.glyph_keys.extend(
glyphs.iter().map(|src| {
let src_point = src.point + prim_offset;
let world_offset = self.used_font.transform.transform(&src_point);
let world_offset = transform.transform(&src_point);
let device_offset = surface.device_pixel_scale.transform_point(world_offset);
GlyphKey::new(src.index, device_offset, subpx_dir)
}));
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.