Skip to content

Commit

Permalink
Auto merge of #3868 - moz-gfx:github-sync, r=auto
Browse files Browse the repository at this point in the history
Sync changes from mozilla-central gfx/wr

 Fixes #3864,
  • Loading branch information
bors-servo authored Feb 19, 2020
2 parents 308740b + 0d042e8 commit f78c01d
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 133 deletions.
6 changes: 5 additions & 1 deletion webrender/res/brush.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ void main(void) {

// Write the normal vertex information out.
if (transform.is_axis_aligned) {

// Select the corner of the local rect that we are processing.
vec2 local_pos = segment_rect.p0 + segment_rect.size * aPosition.xy;

vi = write_vertex(
segment_rect,
local_pos,
ph.local_clip_rect,
ph.z,
transform,
Expand Down
6 changes: 1 addition & 5 deletions webrender/res/prim_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,11 @@ struct VertexInfo {
vec4 world_pos;
};

VertexInfo write_vertex(RectWithSize instance_rect,
VertexInfo write_vertex(vec2 local_pos,
RectWithSize local_clip_rect,
float z,
Transform transform,
PictureTask task) {

// Select the corner of the local rect that we are processing.
vec2 local_pos = instance_rect.p0 + instance_rect.size * aPosition.xy;

// Clamp to the two local clip rects.
vec2 clamped_local_pos = clamp_rect(local_pos, local_clip_rect);

Expand Down
71 changes: 33 additions & 38 deletions 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 Expand Up @@ -220,26 +219,22 @@ void main(void) {
vec2 local_pos = glyph_rect.p0 + glyph_rect.size * aPosition.xy;
#endif

// Clamp to the local clip rect.
local_pos = clamp_rect(local_pos, ph.local_clip_rect);

// Map the clamped local space corner into device space.
vec4 world_pos = transform.m * vec4(local_pos, 0.0, 1.0);
vec2 device_pos = world_pos.xy * task.device_pixel_scale;

// Apply offsets for the render task to get correct screen location.
vec2 final_offset = -task.content_origin + task.common_data.task_rect.p0;

gl_Position = uTransform * vec4(device_pos + final_offset * world_pos.w, ph.z * world_pos.w, world_pos.w);
VertexInfo vi = write_vertex(
local_pos,
ph.local_clip_rect,
ph.z,
transform,
task
);

#ifdef WR_FEATURE_GLYPH_TRANSFORM
vec2 f = (glyph_transform * local_pos - glyph_rect.p0) / glyph_rect.size;
vec2 f = (glyph_transform * vi.local_pos - glyph_rect.p0) / glyph_rect.size;
V_UV_CLIP = vec4(f, 1.0 - f);
#else
vec2 f = (local_pos - glyph_rect.p0) / glyph_rect.size;
vec2 f = (vi.local_pos - glyph_rect.p0) / glyph_rect.size;
#endif

write_clip(world_pos, clip_area);
write_clip(vi.world_pos, clip_area);

switch (color_mode) {
case COLOR_MODE_ALPHA:
Expand Down
Loading

0 comments on commit f78c01d

Please sign in to comment.