Update webrender, gleam and associated shaders.

This commit is contained in:
Glenn Watson 2016-09-15 09:07:27 +10:00
parent 1f1e92aca3
commit 9535c5ba5e
18 changed files with 142 additions and 85 deletions

View file

@ -567,7 +567,7 @@ float do_clip(vec2 pos, vec4 clip_rect, vec4 radius) {
// Apply a more gradual fade out to transparent.
//distance_from_border -= 0.5;
return smoothstep(1.0, 0, distance_from_border);
return smoothstep(1.0, 0.0, distance_from_border);
}
float squared_distance_from_rect(vec2 p, vec2 origin, vec2 size) {
@ -580,9 +580,9 @@ vec2 init_transform_fs(vec3 local_pos, vec4 local_rect, out float fragment_alpha
vec2 pos = local_pos.xy / local_pos.z;
float squared_distance = squared_distance_from_rect(pos, local_rect.xy, local_rect.zw);
if (squared_distance != 0) {
if (squared_distance != 0.0) {
float delta = length(fwidth(local_pos.xy));
fragment_alpha = smoothstep(1.0, 0.0, squared_distance / delta * 2);
fragment_alpha = smoothstep(1.0, 0.0, squared_distance / delta * 2.0);
}
return pos;

View file

@ -24,7 +24,7 @@ float alpha_for_solid_border(float distance_from_ref,
float outer_radius,
float pixels_per_fragment) {
// We want to start anti-aliasing one pixel in from the border.
float nudge = 1 * pixels_per_fragment;
float nudge = pixels_per_fragment;
inner_radius += nudge;
outer_radius -= nudge;
@ -41,7 +41,7 @@ float alpha_for_solid_border(float distance_from_ref,
// Apply a more gradual fade out to transparent.
distance_from_border -= 0.5;
return smoothstep(1.0, 0, distance_from_border);
return smoothstep(1.0, 0.0, distance_from_border);
}
float alpha_for_solid_border_corner(vec2 local_pos,
@ -56,22 +56,22 @@ vec4 draw_dotted_edge(vec2 local_pos, vec4 piece_rect, float pixels_per_fragment
// We don't use pixels_per_fragment here, since it can change along the edge
// of a transformed border edge. We want this calculation to be consistent
// across the entire edge so that the positioning of the dots stays the same.
float two_pixels = 2 * length(fwidth(vLocalPos.xy));
float two_pixels = 2.0 * length(fwidth(vLocalPos.xy));
// Circle diameter is stroke width, minus a couple pixels to account for anti-aliasing.
float circle_diameter = max(piece_rect.z - two_pixels, min(piece_rect.z, two_pixels));
// We want to spread the circles across the edge, but keep one circle diameter at the end
// reserved for two half-circles which connect to the corners.
float edge_available = piece_rect.w - (circle_diameter * 2);
float number_of_circles = floor(edge_available / (circle_diameter * 2));
float edge_available = piece_rect.w - (circle_diameter * 2.0);
float number_of_circles = floor(edge_available / (circle_diameter * 2.0));
// Here we are initializing the distance from the y coordinate of the center of the circle to
// the closest end half-circle.
vec2 relative_pos = local_pos - piece_rect.xy;
float y_distance = min(relative_pos.y, piece_rect.w - relative_pos.y);
if (number_of_circles > 0) {
if (number_of_circles > 0.0) {
// Spread the circles throughout the edge, to distribute the extra space evenly. We want
// to ensure that we have at last two pixels of space for each circle so that they aren't
// touching.
@ -80,41 +80,41 @@ vec4 draw_dotted_edge(vec2 local_pos, vec4 piece_rect, float pixels_per_fragment
float first_half_circle_space = circle_diameter;
float circle_index = (relative_pos.y - first_half_circle_space) / space_for_each_circle;
circle_index = floor(clamp(circle_index, 0, number_of_circles - 1));
circle_index = floor(clamp(circle_index, 0.0, number_of_circles - 1.0));
float circle_y_pos =
circle_index * space_for_each_circle + (space_for_each_circle / 2) + circle_diameter;
circle_index * space_for_each_circle + (space_for_each_circle / 2.0) + circle_diameter;
y_distance = min(abs(circle_y_pos - relative_pos.y), y_distance);
}
float distance_from_circle_center = length(vec2(relative_pos.x - (piece_rect.z / 2), y_distance));
float distance_from_circle_edge = distance_from_circle_center - (circle_diameter / 2);
float distance_from_circle_center = length(vec2(relative_pos.x - (piece_rect.z / 2.0), y_distance));
float distance_from_circle_edge = distance_from_circle_center - (circle_diameter / 2.0);
// Don't anti-alias if the circle diameter is small to avoid a blur of color.
if (circle_diameter < two_pixels && distance_from_circle_edge > 0)
return vec4(0, 0, 0, 0);
if (circle_diameter < two_pixels && distance_from_circle_edge > 0.0)
return vec4(0.0);
// Move the distance back into pixels.
distance_from_circle_edge /= pixels_per_fragment;
float alpha = smoothstep(1.0, 0.0, min(1.0, max(0, distance_from_circle_edge)));
return vHorizontalColor * vec4(1, 1, 1, alpha);
float alpha = smoothstep(1.0, 0.0, min(1.0, max(0.0, distance_from_circle_edge)));
return vHorizontalColor * vec4(1.0, 1.0, 1.0, alpha);
}
vec4 draw_dashed_edge(float position, float border_width, float pixels_per_fragment) {
// TODO: Investigate exactly what FF does.
float size = border_width * 3;
float size = border_width * 3.0;
float segment = floor(position / size);
float alpha = alpha_for_solid_border(position,
segment * size,
(segment + 1) * size,
(segment + 1.0) * size,
pixels_per_fragment);
if (mod(segment + 2, 2) == 0) {
return vHorizontalColor * vec4(1, 1, 1, 1 - alpha);
if (mod(segment + 2.0, 2.0) == 0.0) {
return vHorizontalColor * vec4(1.0, 1.0, 1.0, 1.0 - alpha);
} else {
return vHorizontalColor * vec4(1, 1, 1, alpha);
return vHorizontalColor * vec4(1.0, 1.0, 1.0, alpha);
}
}
@ -131,7 +131,7 @@ void draw_dashed_or_dotted_border(vec2 local_pos, float distance_from_mix_line)
{
oFragColor = get_fragment_color(distance_from_mix_line, pixels_per_fragment);
if (vRadii.x > 0.0) {
oFragColor *= vec4(1, 1, 1, alpha_for_solid_border_corner(local_pos,
oFragColor *= vec4(1.0, 1.0, 1.0, alpha_for_solid_border_corner(local_pos,
vRadii.z,
vRadii.x,
pixels_per_fragment));
@ -179,8 +179,8 @@ vec4 draw_double_edge(float pos,
pixels_per_fragment);
// Contribution of the inner border segment.
alpha += alpha_for_solid_border(pos, 0, one_third_width, pixels_per_fragment);
return get_fragment_color(distance_from_mix_line, pixels_per_fragment) * vec4(1, 1, 1, alpha);
alpha += alpha_for_solid_border(pos, 0.0, one_third_width, pixels_per_fragment);
return get_fragment_color(distance_from_mix_line, pixels_per_fragment) * vec4(1.0, 1.0, 1.0, alpha);
}
vec4 draw_double_edge_vertical(vec2 local_pos,
@ -216,20 +216,20 @@ vec4 draw_double_edge_corner_with_radius(vec2 local_pos,
vRadii.z,
vRadii.z + one_third_width,
pixels_per_fragment);
return get_fragment_color(distance_from_mix_line, pixels_per_fragment) * vec4(1, 1, 1, alpha);
return get_fragment_color(distance_from_mix_line, pixels_per_fragment) * vec4(1.0, 1.0, 1.0, alpha);
}
vec4 draw_double_edge_corner(vec2 local_pos,
float distance_from_mix_line,
float pixels_per_fragment) {
if (vRadii.x > 0) {
if (vRadii.x > 0.0) {
return draw_double_edge_corner_with_radius(local_pos,
distance_from_mix_line,
pixels_per_fragment);
}
bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? distance_from_mix_line < 0 :
distance_from_mix_line >= 0;
bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? distance_from_mix_line < 0.0 :
distance_from_mix_line >= 0.0;
if (is_vertical) {
return draw_double_edge_vertical(local_pos, distance_from_mix_line, pixels_per_fragment);
} else {
@ -280,7 +280,7 @@ void draw_solid_border(float distanceFromMixLine, vec2 localPos) {
if (vRadii.x > 0.0) {
float alpha = alpha_for_solid_border_corner(localPos, vRadii.z, vRadii.x, pixelsPerFragment);
oFragColor *= vec4(1, 1, 1, alpha);
oFragColor *= vec4(1.0, 1.0, 1.0, alpha);
}
break;
@ -295,7 +295,7 @@ void draw_solid_border(float distanceFromMixLine, vec2 localPos) {
// if it's worthwhile splitting it / removing branches etc.
void main(void) {
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0;
float alpha = 0.0;
vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
#else
vec2 local_pos = vLocalPos;
@ -330,6 +330,6 @@ void main(void) {
}
#ifdef WR_FEATURE_TRANSFORM
oFragColor *= vec4(1, 1, 1, alpha);
oFragColor *= vec4(1.0, 1.0, 1.0, alpha);
#endif
}

View file

@ -105,7 +105,7 @@ void main(void) {
// in the fragment shader itself. For non-transformed borders, we can use the
// interpolator.
#ifdef WR_FEATURE_TRANSFORM
vPieceRectHypotenuseLength = sqrt(pow(width, 2) + pow(height, 2));
vPieceRectHypotenuseLength = sqrt(pow(width, 2.0) + pow(height, 2.0));
#else
vDistanceFromMixLine = (vi.local_clamped_pos.x - x0) * height -
(vi.local_clamped_pos.y - y0) * width;

View file

@ -4,10 +4,10 @@
void main(void) {
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0;
float alpha = 0.0;
vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
#else
float alpha = 1;
float alpha = 1.0;
vec2 local_pos = vPos;
#endif

View file

@ -6,9 +6,14 @@
void main(void) {
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0;
float alpha = 0.0;
vec2 pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
vec2 uv = (pos - vLocalRect.xy) / vStretchSize;
// We clamp the texture coordinate calculation here to the local rectangle boundaries,
// which makes the edge of the texture stretch instead of repeat.
vec2 uv = clamp(pos, vLocalRect.xy, vLocalRect.xy + vLocalRect.zw);
uv = (uv - vLocalRect.xy) / vStretchSize;
#else
vec2 uv = vUv;
#endif

View file

@ -24,7 +24,7 @@ void main(void) {
case UV_NORMALIZED:
break;
case UV_PIXEL: {
vec2 texture_size = textureSize(sDiffuse, 0);
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
st0 /= texture_size;
st1 /= texture_size;
}

View file

@ -1,9 +1,27 @@
#line 1
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void main(void) {
float alpha = do_clip(vPos, vClipRect, vClipRadius);
vec2 st = vTextureOffset + vTextureSize * fract(vUv);
#ifdef WR_FEATURE_TRANSFORM
float alpha = 1;
vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
// We clamp the texture coordinate calculation here to the local rectangle boundaries,
// which makes the edge of the texture stretch instead of repeat.
vec2 uv = clamp(local_pos.xy, vLocalRect.xy, vLocalRect.xy + vLocalRect.zw);
uv = (uv - vLocalRect.xy) / vStretchSize;
#else
float alpha = 1;
vec2 local_pos = vLocalPos;
vec2 uv = vUv;
#endif
vec2 st = vTextureOffset + vTextureSize * fract(uv);
alpha = min(alpha, do_clip(local_pos, vClipRect, vClipRadius));
oFragColor = texture(sDiffuse, st) * vec4(1, 1, 1, alpha);
}

View file

@ -2,9 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
varying vec2 vUv; // Location within the CSS box to draw.
varying vec2 vPos;
flat varying vec2 vTextureOffset; // Offset of this image into the texture atlas.
flat varying vec2 vTextureSize; // Size of the image in the texture atlas.
flat varying vec4 vClipRect;
flat varying vec4 vClipRadius;
#ifdef WR_FEATURE_TRANSFORM
varying vec3 vLocalPos;
flat varying vec4 vLocalRect;
flat varying vec2 vStretchSize;
#else
varying vec2 vLocalPos;
varying vec2 vUv; // Location within the CSS box to draw.
#endif

View file

@ -5,17 +5,23 @@
void main(void) {
ImageClip image = fetch_image_clip(gl_InstanceID);
#ifdef WR_FEATURE_TRANSFORM
TransformVertexInfo vi = write_transform_vertex(image.info);
vLocalRect = vi.clipped_local_rect;
vLocalPos = vi.local_pos;
vStretchSize = image.stretch_size_uvkind.xy;
#else
VertexInfo vi = write_vertex(image.info);
vUv = (vi.local_clamped_pos - vi.local_rect.p0) / image.stretch_size_uvkind.xy;
vLocalPos = vi.local_clamped_pos;
#endif
vClipRect = vec4(image.clip.rect.xy, image.clip.rect.xy + image.clip.rect.zw);
vClipRadius = vec4(image.clip.top_left.outer_inner_radius.x,
image.clip.top_right.outer_inner_radius.x,
image.clip.bottom_right.outer_inner_radius.x,
image.clip.bottom_left.outer_inner_radius.x);
vPos = vi.local_clamped_pos;
// vUv will contain how many times this image has wrapped around the image size.
vUv = (vi.local_clamped_pos - image.info.local_rect.xy) / image.stretch_size_uvkind.xy;
vec2 st0 = image.st_rect.xy;
vec2 st1 = image.st_rect.zw;
@ -24,7 +30,7 @@ void main(void) {
case UV_NORMALIZED:
break;
case UV_PIXEL: {
vec2 texture_size = textureSize(sDiffuse, 0);
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
st0 /= texture_size;
st1 /= texture_size;
}

View file

@ -4,7 +4,7 @@
void main(void) {
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0;
float alpha = 0.0;
init_transform_fs(vLocalPos, vLocalRect, alpha);
oFragColor = vec4(1, 1, 1, alpha) * vColor;
#else

View file

@ -3,6 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void main(void) {
float alpha = do_clip(vPos, vClipRect, vClipRadius);
#ifdef WR_FEATURE_TRANSFORM
float alpha = 1;
vec2 local_pos = init_transform_fs(vPos, vLocalRect, alpha);
#else
float alpha = 1;
vec2 local_pos = vPos;
#endif
alpha = min(alpha, do_clip(local_pos, vClipRect, vClipRadius));
oFragColor = vColor * vec4(1, 1, 1, alpha);
}

View file

@ -5,6 +5,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
varying vec4 vColor;
varying vec2 vPos;
flat varying vec4 vClipRect;
flat varying vec4 vClipRadius;
#ifdef WR_FEATURE_TRANSFORM
varying vec3 vPos;
flat varying vec4 vLocalRect;
#else
varying vec2 vPos;
#endif

View file

@ -5,14 +5,21 @@
void main(void) {
RectangleClip rect = fetch_rectangle_clip(gl_InstanceID);
#ifdef WR_FEATURE_TRANSFORM
TransformVertexInfo vi = write_transform_vertex(rect.info);
vPos = vi.local_pos;
vLocalRect = vi.clipped_local_rect;
#else
VertexInfo vi = write_vertex(rect.info);
vPos = vi.local_clamped_pos;
#endif
vClipRect = vec4(rect.clip.rect.xy, rect.clip.rect.xy + rect.clip.rect.zw);
vClipRadius = vec4(rect.clip.top_left.outer_inner_radius.x,
rect.clip.top_right.outer_inner_radius.x,
rect.clip.bottom_right.outer_inner_radius.x,
rect.clip.bottom_left.outer_inner_radius.x);
vPos = vi.local_clamped_pos;
vColor = rect.color;
}

View file

@ -5,7 +5,7 @@
void main(void) {
float a = texture(sDiffuse, vUv).a;
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0;
float alpha = 0.0;
init_transform_fs(vLocalPos, vLocalRect, alpha);
a *= alpha;
#endif

View file

@ -16,7 +16,7 @@ void main(void) {
vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0);
#endif
vec2 texture_size = textureSize(sDiffuse, 0);
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
vec2 st0 = glyph.uv_rect.xy / texture_size;
vec2 st1 = glyph.uv_rect.zw / texture_size;

View file

@ -17,7 +17,7 @@ void main(void) {
vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0);
#endif
vec2 texture_size = textureSize(sDiffuse, 0);
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
vec2 st0 = uv_rect.xy / texture_size;
vec2 st1 = uv_rect.zw / texture_size;