mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Update webrender (various optimizations, layer fixes and antialiasing shaders).
This commit is contained in:
parent
7345905c8b
commit
ba90540352
8 changed files with 127 additions and 45 deletions
4
components/servo/Cargo.lock
generated
4
components/servo/Cargo.lock
generated
|
@ -2593,7 +2593,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webrender"
|
name = "webrender"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
|
source = "git+https://github.com/servo/webrender#4171ab07f36d9dff12cc4fc31b23c037851cd747"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2618,7 +2618,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webrender_traits"
|
name = "webrender_traits"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
|
source = "git+https://github.com/servo/webrender#4171ab07f36d9dff12cc4fc31b23c037851cd747"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
4
ports/cef/Cargo.lock
generated
4
ports/cef/Cargo.lock
generated
|
@ -2453,7 +2453,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webrender"
|
name = "webrender"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
|
source = "git+https://github.com/servo/webrender#4171ab07f36d9dff12cc4fc31b23c037851cd747"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2478,7 +2478,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webrender_traits"
|
name = "webrender_traits"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
|
source = "git+https://github.com/servo/webrender#4171ab07f36d9dff12cc4fc31b23c037851cd747"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -4,6 +4,21 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
void discard_pixels_in_rounded_borders(vec2 local_pos) {
|
||||||
|
float distanceFromRef = distance(vRefPoint, local_pos);
|
||||||
|
if (vRadii.x > 0.0 && (distanceFromRef > vRadii.x || distanceFromRef < vRadii.z)) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 get_fragment_color(float distanceFromMixLine, float pixelsPerFragment) {
|
||||||
|
// Here we are mixing between the two border colors. We need to convert
|
||||||
|
// distanceFromMixLine it to pixel space to properly anti-alias and then push
|
||||||
|
// it between the limits accepted by `mix`.
|
||||||
|
float colorMix = min(max(distanceFromMixLine / pixelsPerFragment, -0.5), 0.5) + 0.5;
|
||||||
|
return mix(vHorizontalColor, vVerticalColor, colorMix);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WR_FEATURE_TRANSFORM
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -73,11 +88,10 @@ vec4 draw_double_edge(float pos, float len) {
|
||||||
// And 0.0 for the blank part.
|
// And 0.0 for the blank part.
|
||||||
float should_fill = in_first_part + in_third_part;
|
float should_fill = in_first_part + in_third_part;
|
||||||
|
|
||||||
float color_weight = step(0.0, vF);
|
// This is the conversion factor for transformations and device pixel scaling.
|
||||||
vec4 color = mix(vHorizontalColor, vVerticalColor, color_weight);
|
float pixels_per_fragment = length(fwidth(vLocalPos.xy));
|
||||||
|
|
||||||
vec4 white = vec4(1.0, 1.0, 1.0, 1.0);
|
vec4 white = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
return mix(white, color, should_fill);
|
return mix(white, get_fragment_color(vDistanceFromMixLine, pixels_per_fragment), should_fill);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 draw_double_edge_vertical() {
|
vec4 draw_double_edge_vertical() {
|
||||||
|
@ -104,7 +118,8 @@ vec4 draw_double_edge_corner() {
|
||||||
return draw_double_edge_with_radius();
|
return draw_double_edge_with_radius();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? vF < 0 : vF >= 0;
|
bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? vDistanceFromMixLine < 0 :
|
||||||
|
vDistanceFromMixLine >= 0;
|
||||||
if (is_vertical) {
|
if (is_vertical) {
|
||||||
return draw_double_edge_vertical();
|
return draw_double_edge_vertical();
|
||||||
} else {
|
} else {
|
||||||
|
@ -225,23 +240,14 @@ void draw_double_border(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void discard_pixels_in_rounded_borders(vec2 local_pos) {
|
void draw_antialiased_solid_border_corner(vec2 local_pos, float pixelsPerFragment) {
|
||||||
float distanceFromRef = distance(vRefPoint, local_pos);
|
|
||||||
if (vRadii.x > 0.0 && (distanceFromRef > vRadii.x || distanceFromRef < vRadii.z)) {
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_antialiased_solid_border_corner(vec2 local_pos) {
|
|
||||||
if (vRadii.x <= 0.0) {
|
if (vRadii.x <= 0.0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the conversion factor for transformations and device pixel scaling.
|
|
||||||
float pixelsPerFragment = length(fwidth(local_pos.xy));
|
|
||||||
|
|
||||||
float distanceFromRef = distance(vRefPoint, local_pos);
|
float distanceFromRef = distance(vRefPoint, local_pos);
|
||||||
|
|
||||||
// We want to start anti-aliasing one pixel in from the border.
|
// We want to start anti-aliasing one pixel in from the border.
|
||||||
|
@ -262,6 +268,25 @@ void draw_antialiased_solid_border_corner(vec2 local_pos) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_solid_border(float distanceFromMixLine, vec2 localPos) {
|
||||||
|
switch (vBorderPart) {
|
||||||
|
case PST_TOP_LEFT:
|
||||||
|
case PST_TOP_RIGHT:
|
||||||
|
case PST_BOTTOM_LEFT:
|
||||||
|
case PST_BOTTOM_RIGHT: {
|
||||||
|
// This is the conversion factor for transformations and device pixel scaling.
|
||||||
|
float pixelsPerFragment = length(fwidth(localPos.xy));
|
||||||
|
oFragColor = get_fragment_color(distanceFromMixLine, pixelsPerFragment);
|
||||||
|
draw_antialiased_solid_border_corner(localPos, pixelsPerFragment);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
oFragColor = vHorizontalColor;
|
||||||
|
discard_pixels_in_rounded_borders(localPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Investigate performance of this shader and see
|
// TODO: Investigate performance of this shader and see
|
||||||
// if it's worthwhile splitting it / removing branches etc.
|
// if it's worthwhile splitting it / removing branches etc.
|
||||||
void main(void) {
|
void main(void) {
|
||||||
|
@ -274,9 +299,12 @@ void main(void) {
|
||||||
|
|
||||||
#ifdef WR_FEATURE_TRANSFORM
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
// TODO(gw): Support other border styles for transformed elements.
|
// TODO(gw): Support other border styles for transformed elements.
|
||||||
discard_pixels_in_rounded_borders(local_pos);
|
float distance_from_mix_line = (local_pos.x - vPieceRect.x) * vPieceRect.w -
|
||||||
float f = (local_pos.x - vSizeInfo.x) * vSizeInfo.w - (local_pos.y - vSizeInfo.y) * vSizeInfo.z;
|
(local_pos.y - vPieceRect.y) * vPieceRect.z;
|
||||||
oFragColor = vec4(1, 1, 1, alpha) * mix(vHorizontalColor, vVerticalColor, step(0.0, f));
|
distance_from_mix_line /= vPieceRectHypotenuseLength;
|
||||||
|
draw_solid_border(distance_from_mix_line, local_pos);
|
||||||
|
oFragColor *= vec4(1, 1, 1, alpha);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
switch (vBorderStyle) {
|
switch (vBorderStyle) {
|
||||||
case BORDER_STYLE_DASHED:
|
case BORDER_STYLE_DASHED:
|
||||||
|
@ -289,25 +317,9 @@ void main(void) {
|
||||||
break;
|
break;
|
||||||
case BORDER_STYLE_OUTSET:
|
case BORDER_STYLE_OUTSET:
|
||||||
case BORDER_STYLE_INSET:
|
case BORDER_STYLE_INSET:
|
||||||
discard_pixels_in_rounded_borders(local_pos);
|
|
||||||
oFragColor = mix(vVerticalColor, vHorizontalColor, step(0.0, vF));
|
|
||||||
break;
|
|
||||||
case BORDER_STYLE_SOLID:
|
case BORDER_STYLE_SOLID:
|
||||||
oFragColor = mix(vHorizontalColor, vVerticalColor, step(0.0, vF));
|
|
||||||
switch (vBorderPart) {
|
|
||||||
case PST_TOP_LEFT:
|
|
||||||
case PST_TOP_RIGHT:
|
|
||||||
case PST_BOTTOM_LEFT:
|
|
||||||
case PST_BOTTOM_RIGHT:
|
|
||||||
draw_antialiased_solid_border_corner(local_pos);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
discard_pixels_in_rounded_borders(local_pos);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BORDER_STYLE_NONE:
|
case BORDER_STYLE_NONE:
|
||||||
discard_pixels_in_rounded_borders(local_pos);
|
draw_solid_border(vDistanceFromMixLine, local_pos);
|
||||||
oFragColor = mix(vHorizontalColor, vVerticalColor, step(0.0, vF));
|
|
||||||
break;
|
break;
|
||||||
case BORDER_STYLE_DOUBLE:
|
case BORDER_STYLE_DOUBLE:
|
||||||
discard_pixels_in_rounded_borders(local_pos);
|
discard_pixels_in_rounded_borders(local_pos);
|
||||||
|
|
|
@ -19,12 +19,14 @@ flat varying uint vBorderPart; // Which part of the border we're drawing.
|
||||||
// These are in device space
|
// These are in device space
|
||||||
#ifdef WR_FEATURE_TRANSFORM
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
varying vec3 vLocalPos; // The clamped position in local space.
|
varying vec3 vLocalPos; // The clamped position in local space.
|
||||||
flat varying vec4 vSizeInfo;
|
flat varying vec4 vPieceRect;
|
||||||
|
flat varying float vPieceRectHypotenuseLength;
|
||||||
#else
|
#else
|
||||||
varying vec2 vLocalPos; // The clamped position in local space.
|
varying vec2 vLocalPos; // The clamped position in local space.
|
||||||
|
|
||||||
// These two are interpolated
|
// These two are interpolated
|
||||||
varying float vF; // This is a weighting as we get closer to the bottom right corner?
|
varying float vDistanceFromMixLine; // This is the distance from the line where two colors
|
||||||
|
// meet in border corners.
|
||||||
varying vec2 vDevicePos; // The clamped position in device space.
|
varying vec2 vDevicePos; // The clamped position in device space.
|
||||||
flat varying vec4 vBorders; // the rect of the border in (x, y, width, height) form
|
flat varying vec4 vBorders; // the rect of the border in (x, y, width, height) form
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -109,11 +109,17 @@ void main(void) {
|
||||||
// x1 - x0 is the width of the corner / line.
|
// x1 - x0 is the width of the corner / line.
|
||||||
float width = x1 - x0;
|
float width = x1 - x0;
|
||||||
float height = y1 - y0;
|
float height = y1 - y0;
|
||||||
|
|
||||||
|
// The fragment shader needs to calculate the distance from the bisecting line
|
||||||
|
// to properly mix border colors. For transformed borders, we calculate this distance
|
||||||
|
// in the fragment shader itself. For non-transformed borders, we can use the
|
||||||
|
// interpolator.
|
||||||
#ifdef WR_FEATURE_TRANSFORM
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
vSizeInfo = vec4(x0, y0, width, height);
|
vPieceRect = vec4(x0, y0, width, height);
|
||||||
|
vPieceRectHypotenuseLength = sqrt(pow(width, 2) + pow(height, 2));
|
||||||
#else
|
#else
|
||||||
// This is just a weighting of the pixel colors it seems?
|
vDistanceFromMixLine = (vi.local_clamped_pos.x - x0) * height -
|
||||||
vF = (vi.local_clamped_pos.x - x0) * height - (vi.local_clamped_pos.y - y0) * width;
|
(vi.local_clamped_pos.y - y0) * width;
|
||||||
|
|
||||||
// These are in device space
|
// These are in device space
|
||||||
vDevicePos = vi.global_clamped_pos;
|
vDevicePos = vi.global_clamped_pos;
|
||||||
|
|
8
resources/shaders/ps_text_run.fs.glsl
Normal file
8
resources/shaders/ps_text_run.fs.glsl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/* 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 a = texture(sDiffuse, vUv).a;
|
||||||
|
oFragColor = vec4(vColor.rgb, vColor.a * a);
|
||||||
|
}
|
11
resources/shaders/ps_text_run.glsl
Normal file
11
resources/shaders/ps_text_run.glsl
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
flat varying vec4 vColor;
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
varying vec3 vLocalPos;
|
||||||
|
flat varying vec4 vLocalRect;
|
||||||
|
#endif
|
43
resources/shaders/ps_text_run.vs.glsl
Normal file
43
resources/shaders/ps_text_run.vs.glsl
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#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/. */
|
||||||
|
|
||||||
|
struct TextRunGlyph {
|
||||||
|
vec4 local_rect;
|
||||||
|
ivec4 uv_rect;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TextRun {
|
||||||
|
PrimitiveInfo info;
|
||||||
|
TextRunGlyph glyphs[WR_GLYPHS_PER_TEXT_RUN];
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(std140) uniform Items {
|
||||||
|
TextRun text_runs[WR_MAX_PRIM_ITEMS];
|
||||||
|
};
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
TextRun text_run = text_runs[gl_InstanceID / WR_GLYPHS_PER_TEXT_RUN];
|
||||||
|
TextRunGlyph glyph = text_run.glyphs[gl_InstanceID % WR_GLYPHS_PER_TEXT_RUN];
|
||||||
|
text_run.info.local_rect = glyph.local_rect;
|
||||||
|
ivec4 uv_rect = glyph.uv_rect;
|
||||||
|
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
TransformVertexInfo vi = write_transform_vertex(text_run.info);
|
||||||
|
vLocalRect = vi.clipped_local_rect;
|
||||||
|
vLocalPos = vi.local_pos;
|
||||||
|
vec2 f = (vi.local_pos.xy - text_run.info.local_rect.xy) / text_run.info.local_rect.zw;
|
||||||
|
#else
|
||||||
|
VertexInfo vi = write_vertex(text_run.info);
|
||||||
|
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 st0 = uv_rect.xy / texture_size;
|
||||||
|
vec2 st1 = uv_rect.zw / texture_size;
|
||||||
|
|
||||||
|
vColor = text_run.color;
|
||||||
|
vUv = mix(st0, st1, f);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue