Skip to content

Commit

Permalink
Bug 1615613 - Move text snap bias in its own function. r=gw
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D62926

--HG--
extra : moz-landing-system : lando
  • Loading branch information
nical committed Feb 19, 2020
1 parent 2d252c6 commit 4942c75
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions gfx/wr/webrender/res/ps_text_run.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ TextRun fetch_text_run(int address) {
return TextRun(data[0], data[1]);
}

vec2 get_snap_bias(int subpx_dir) {
// In subpixel mode, the subpixel offset has already been
// accounted for while rasterizing the glyph. However, we
// must still round with a subpixel bias rather than rounding
// to the nearest whole pixel, depending on subpixel direciton.
switch (subpx_dir) {
case SUBPX_DIR_NONE:
default:
return vec2(0.5);
case SUBPX_DIR_HORIZONTAL:
// Glyphs positioned [-0.125, 0.125] get a
// subpx position of zero. So include that
// offset in the glyph position to ensure
// we round to the correct whole position.
return vec2(0.125, 0.5);
case SUBPX_DIR_VERTICAL:
return vec2(0.5, 0.125);
case SUBPX_DIR_MIXED:
return vec2(0.125);
}
}

void main(void) {
Instance instance = decode_instance_attributes();

Expand Down Expand Up @@ -118,30 +140,7 @@ void main(void) {

GlyphResource res = fetch_glyph_resource(instance.resource_address);

vec2 snap_bias;
// In subpixel mode, the subpixel offset has already been
// accounted for while rasterizing the glyph. However, we
// must still round with a subpixel bias rather than rounding
// to the nearest whole pixel, depending on subpixel direciton.
switch (subpx_dir) {
case SUBPX_DIR_NONE:
default:
snap_bias = vec2(0.5);
break;
case SUBPX_DIR_HORIZONTAL:
// Glyphs positioned [-0.125, 0.125] get a
// subpx position of zero. So include that
// offset in the glyph position to ensure
// we round to the correct whole position.
snap_bias = vec2(0.125, 0.5);
break;
case SUBPX_DIR_VERTICAL:
snap_bias = vec2(0.5, 0.125);
break;
case SUBPX_DIR_MIXED:
snap_bias = vec2(0.125);
break;
}
vec2 snap_bias = get_snap_bias(subpx_dir);

// Glyph space refers to the pixel space used by glyph rasterization during frame
// building. If a non-identity transform was used, WR_FEATURE_GLYPH_TRANSFORM will
Expand Down

0 comments on commit 4942c75

Please sign in to comment.