From 1242a0df69d6d54c761b0e1bc9ba9cb81ba3887d Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 16 Aug 2016 08:58:51 +1000 Subject: [PATCH] Update webrender + shaders. --- components/servo/Cargo.lock | 2 +- ports/cef/Cargo.lock | 2 +- resources/shaders/ps_border.fs.glsl | 82 +++++++++++++++++++++++++++++ resources/shaders/ps_border.glsl | 1 + resources/shaders/ps_border.vs.glsl | 3 ++ resources/shaders/ps_text.vs.glsl | 10 ++-- resources/shaders/shared.glsl | 6 ++- 7 files changed, 99 insertions(+), 7 deletions(-) diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 6cc998d5fd3c..14629f2be50f 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "webrender" version = "0.2.0" -source = "git+https://github.com/servo/webrender#c84b6eb466dc6802b2b85cff481a5a08a9efadc1" +source = "git+https://github.com/servo/webrender#16e427ec2955f0a5f47b279a30b48eaa885d57fb" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index bb56b8534cf1..831fa5c8611f 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -2454,7 +2454,7 @@ dependencies = [ [[package]] name = "webrender" version = "0.2.0" -source = "git+https://github.com/servo/webrender#c84b6eb466dc6802b2b85cff481a5a08a9efadc1" +source = "git+https://github.com/servo/webrender#16e427ec2955f0a5f47b279a30b48eaa885d57fb" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/resources/shaders/ps_border.fs.glsl b/resources/shaders/ps_border.fs.glsl index 4661694aed3c..5ee736daf6ad 100644 --- a/resources/shaders/ps_border.fs.glsl +++ b/resources/shaders/ps_border.fs.glsl @@ -56,6 +56,57 @@ vec4 draw_dotted_edge() { return mix(white, circleColor, circleColor.a); } +vec4 draw_double_edge(float pos, float len) { + // Devided border to 3 parts, draw color on first and third part, + // leave second part blank. + float one_third_len = len / 3.0; + + float in_first_part = step(pos, one_third_len); + float in_third_part = step(len - one_third_len, pos); + + // The result of this should be 1.0 if we're in the 1st or 3rd part. + // And 0.0 for the blank part. + float should_fill = in_first_part + in_third_part; + + float color_weight = step(0.0, vF); + vec4 color = mix(vHorizontalColor, vVerticalColor, color_weight); + + vec4 white = vec4(1.0, 1.0, 1.0, 1.0); + return mix(white, color, should_fill); +} + +vec4 draw_double_edge_vertical() { + // Get our position within this specific segment + float position = vLocalPos.x - vLocalBorders.x; + return draw_double_edge(position, vLocalBorders.z); +} + +vec4 draw_double_edge_horizontal() { + // Get our position within this specific segment + float position = vLocalPos.y - vLocalBorders.y; + return draw_double_edge(position, vLocalBorders.w); +} + +vec4 draw_double_edge_with_radius() { + // Get our position within this specific segment + float position = distance(vRefPoint, vLocalPos) - vRadii.z; + float len = vRadii.x - vRadii.z; + return draw_double_edge(position, len); +} + +vec4 draw_double_edge_corner() { + if (vRadii.x > 0) { + return draw_double_edge_with_radius(); + } + + bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? vF < 0 : vF >= 0; + if (is_vertical) { + return draw_double_edge_vertical(); + } else { + return draw_double_edge_horizontal(); + } +} + // Our current edge calculation is based only on // the size of the border-size, but we need to draw // the dashes in the center of the segment we're drawing. @@ -144,6 +195,32 @@ void draw_dashed_border(void) { } } +void draw_double_border(void) { + switch (vBorderPart) { + // These are the layer tile part PrimitivePart as uploaded by the tiling.rs + case PST_TOP_LEFT: + case PST_TOP_RIGHT: + case PST_BOTTOM_LEFT: + case PST_BOTTOM_RIGHT: + { + oFragColor = draw_double_edge_corner(); + break; + } + case PST_BOTTOM: + case PST_TOP: + { + oFragColor = draw_double_edge_horizontal(); + break; + } + case PST_LEFT: + case PST_RIGHT: + { + oFragColor = draw_double_edge_vertical(); + break; + } + } +} + // TODO: Investigate performance of this shader and see // if it's worthwhile splitting it / removing branches etc. void main(void) { @@ -178,6 +255,11 @@ void main(void) { oFragColor = mix(vHorizontalColor, vVerticalColor, color); break; } + case BORDER_STYLE_DOUBLE: + { + draw_double_border(); + break; + } default: { discard; diff --git a/resources/shaders/ps_border.glsl b/resources/shaders/ps_border.glsl index 26a1a6601e9e..29a72371e747 100644 --- a/resources/shaders/ps_border.glsl +++ b/resources/shaders/ps_border.glsl @@ -16,6 +16,7 @@ flat varying vec4 vRadii; // The border radius from CSS border-radiu varying vec2 vLocalPos; // The clamped position in local 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 vLocalBorders; // The rect of the border (x, y, w, h) in local space. // for corners, this is the beginning of the corner. // For the lines, this is the top left of the line. diff --git a/resources/shaders/ps_border.vs.glsl b/resources/shaders/ps_border.vs.glsl index ad34c02737f2..65fae54f7029 100644 --- a/resources/shaders/ps_border.vs.glsl +++ b/resources/shaders/ps_border.vs.glsl @@ -103,6 +103,9 @@ void main(void) { // Local space vLocalPos = vi.local_clamped_pos.xy; + // Local space + vLocalBorders = border.info.local_rect; + // These are in device space vDevicePos = vi.global_clamped_pos; diff --git a/resources/shaders/ps_text.vs.glsl b/resources/shaders/ps_text.vs.glsl index 39e72bf86889..6c5ac29e9145 100644 --- a/resources/shaders/ps_text.vs.glsl +++ b/resources/shaders/ps_text.vs.glsl @@ -6,7 +6,7 @@ struct Glyph { PrimitiveInfo info; vec4 color; - vec4 st_rect; + ivec4 uv_rect; }; layout(std140) uniform Items { @@ -19,8 +19,10 @@ void main(void) { vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0); + vec2 texture_size = textureSize(sDiffuse, 0); + vec2 st0 = glyph.uv_rect.xy / texture_size; + vec2 st1 = glyph.uv_rect.zw / texture_size; + vColor = glyph.color; - vUv = mix(glyph.st_rect.xy, - glyph.st_rect.zw, - f); + vUv = mix(st0, st1, f); } diff --git a/resources/shaders/shared.glsl b/resources/shaders/shared.glsl index 2eb73d6b46d1..d5202d624841 100644 --- a/resources/shaders/shared.glsl +++ b/resources/shaders/shared.glsl @@ -25,13 +25,17 @@ #define varying in // Uniform inputs - uniform sampler2D sDiffuse; uniform sampler2D sMask; // Fragment shader outputs out vec4 oFragColor; #endif +//====================================================================================== +// Shared shader uniforms +//====================================================================================== +uniform sampler2D sDiffuse; + //====================================================================================== // Interpolator definitions //======================================================================================