servo: Merge #13002 - Update wr + shaders for local clip rect changes (from glennw:wr2-update-local-clipping); r=pcwalton
authorGlenn Watson <github@intuitionlibrary.com>
Tue, 23 Aug 2016 16:41:11 -0500
changeset 339556 a30d30f734d7d70a0c14b51b6223117af72beb53
parent 339555 5ef403b9236e24a81392e00603f660f45f6d3a06
child 339557 42cc8b34d9bfc3c6800f1d647f2109251a25a2f8
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
servo: Merge #13002 - Update wr + shaders for local clip rect changes (from glennw:wr2-update-local-clipping); r=pcwalton Source-Repo: https://github.com/servo/servo Source-Revision: 400c7e032472255288599abce7c0309d3f802350
servo/components/servo/Cargo.lock
servo/ports/cef/Cargo.lock
servo/resources/shaders/prim_shared.glsl
servo/resources/shaders/ps_border.vs.glsl
servo/resources/shaders/ps_gradient.fs.glsl
servo/resources/shaders/ps_gradient.glsl
servo/resources/shaders/ps_gradient.vs.glsl
servo/resources/shaders/ps_image.vs.glsl
servo/resources/shaders/ps_rectangle.vs.glsl
servo/resources/shaders/ps_text.fs.glsl
servo/resources/shaders/ps_text.glsl
servo/resources/shaders/ps_text.vs.glsl
--- a/servo/components/servo/Cargo.lock
+++ b/servo/components/servo/Cargo.lock
@@ -2588,17 +2588,17 @@ dependencies = [
  "util 0.0.1",
  "uuid 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "webdriver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#2e9cba1c471b353babfb3bd80ec00207bc93f171"
+source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
 dependencies = [
  "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)",
  "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2613,17 +2613,17 @@ dependencies = [
  "rayon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
  "webrender_traits 0.5.1 (git+https://github.com/servo/webrender)",
 ]
 
 [[package]]
 name = "webrender_traits"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#2e9cba1c471b353babfb3bd80ec00207bc93f171"
+source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
 dependencies = [
  "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)",
  "core-graphics 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
  "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
--- a/servo/ports/cef/Cargo.lock
+++ b/servo/ports/cef/Cargo.lock
@@ -2448,17 +2448,17 @@ dependencies = [
  "util 0.0.1",
  "uuid 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "webdriver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#2e9cba1c471b353babfb3bd80ec00207bc93f171"
+source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
 dependencies = [
  "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)",
  "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2473,17 +2473,17 @@ dependencies = [
  "rayon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
  "webrender_traits 0.5.1 (git+https://github.com/servo/webrender)",
 ]
 
 [[package]]
 name = "webrender_traits"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#2e9cba1c471b353babfb3bd80ec00207bc93f171"
+source = "git+https://github.com/servo/webrender#5e4c18b22c6b441319959bd0e66b269a50d866be"
 dependencies = [
  "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)",
  "core-graphics 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
  "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
--- a/servo/resources/shaders/prim_shared.glsl
+++ b/servo/resources/shaders/prim_shared.glsl
@@ -24,17 +24,17 @@
 #define BORDER_STYLE_RIDGE        uint(7)
 #define BORDER_STYLE_INSET        uint(8)
 #define BORDER_STYLE_OUTSET       uint(9)
 
 #ifdef WR_VERTEX_SHADER
 struct Layer {
     mat4 transform;
     mat4 inv_transform;
-    ivec4 world_clip_rect;
+    vec4 local_clip_rect;
     vec4 screen_vertices[4];
 };
 
 layout(std140) uniform Layers {
     Layer layers[WR_MAX_PRIM_LAYERS];
 };
 
 struct Tile {
@@ -118,52 +118,65 @@ VertexInfo write_vertex(PrimitiveInfo in
     vec2 p1 = floor(0.5 + (info.local_rect.xy + info.local_rect.zw) * uDevicePixelRatio) / uDevicePixelRatio;
 
     vec2 local_pos = mix(p0, p1, aPosition.xy);
 
     vec2 cp0 = floor(0.5 + info.local_clip_rect.xy * uDevicePixelRatio) / uDevicePixelRatio;
     vec2 cp1 = floor(0.5 + (info.local_clip_rect.xy + info.local_clip_rect.zw) * uDevicePixelRatio) / uDevicePixelRatio;
     local_pos = clamp(local_pos, cp0, cp1);
 
+    local_pos = clamp(local_pos,
+                      vec2(layer.local_clip_rect.xy),
+                      vec2(layer.local_clip_rect.xy + layer.local_clip_rect.zw));
+
     vec4 world_pos = layer.transform * vec4(local_pos, 0, 1);
     world_pos.xyz /= world_pos.w;
 
     vec2 device_pos = world_pos.xy * uDevicePixelRatio;
 
     vec2 clamped_pos = clamp(device_pos,
                              vec2(tile.actual_rect.xy),
                              vec2(tile.actual_rect.xy + tile.actual_rect.zw));
 
-    clamped_pos = clamp(clamped_pos,
-                        vec2(layer.world_clip_rect.xy),
-                        vec2(layer.world_clip_rect.xy + layer.world_clip_rect.zw));
-
     vec4 local_clamped_pos = layer.inv_transform * vec4(clamped_pos / uDevicePixelRatio, world_pos.z, 1);
     local_clamped_pos.xyz /= local_clamped_pos.w;
 
     vec2 final_pos = clamped_pos + vec2(tile.target_rect.xy) - vec2(tile.actual_rect.xy);
 
     gl_Position = uTransform * vec4(final_pos, 0, 1);
 
     VertexInfo vi = VertexInfo(Rect(p0, p1), local_clamped_pos.xy, clamped_pos.xy);
     return vi;
 }
 
 struct TransformVertexInfo {
     vec3 local_pos;
+    vec4 clipped_local_rect;
 };
 
 TransformVertexInfo write_transform_vertex(PrimitiveInfo info) {
     Layer layer = layers[info.layer_tile_part.x];
     Tile tile = tiles[info.layer_tile_part.y];
 
-    vec2 p0 = info.local_rect.xy;
-    vec2 p1 = info.local_rect.xy + vec2(info.local_rect.z, 0.0);
-    vec2 p2 = info.local_rect.xy + vec2(0.0, info.local_rect.w);
-    vec2 p3 = info.local_rect.xy + info.local_rect.zw;
+    vec2 lp0 = info.local_rect.xy;
+    vec2 lp1 = info.local_rect.xy + info.local_rect.zw;
+
+    lp0 = clamp(lp0,
+                layer.local_clip_rect.xy,
+                layer.local_clip_rect.xy + layer.local_clip_rect.zw);
+    lp1 = clamp(lp1,
+                layer.local_clip_rect.xy,
+                layer.local_clip_rect.xy + layer.local_clip_rect.zw);
+
+    vec4 clipped_local_rect = vec4(lp0, lp1 - lp0);
+
+    vec2 p0 = lp0;
+    vec2 p1 = vec2(lp1.x, lp0.y);
+    vec2 p2 = vec2(lp0.x, lp1.y);
+    vec2 p3 = lp1;
 
     vec4 t0 = layer.transform * vec4(p0, 0, 1);
     vec4 t1 = layer.transform * vec4(p1, 0, 1);
     vec4 t2 = layer.transform * vec4(p2, 0, 1);
     vec4 t3 = layer.transform * vec4(p3, 0, 1);
 
     vec2 tp0 = t0.xy / t0.w;
     vec2 tp1 = t1.xy / t1.w;
@@ -186,17 +199,17 @@ TransformVertexInfo write_transform_vert
                            aPosition.xy);
 
     vec3 layer_pos = get_layer_pos(clamped_pos / uDevicePixelRatio, info.layer_tile_part.x);
 
     vec2 final_pos = clamped_pos + vec2(tile.target_rect.xy) - vec2(tile.actual_rect.xy);
 
     gl_Position = uTransform * vec4(final_pos, 0, 1);
 
-    return TransformVertexInfo(layer_pos);
+    return TransformVertexInfo(layer_pos, clipped_local_rect);
 }
 #endif
 
 #ifdef WR_FRAGMENT_SHADER
 void do_clip(vec2 pos, vec4 clip_rect, vec4 radius) {
     vec2 ref_tl = clip_rect.xy + vec2( radius.x,  radius.x);
     vec2 ref_tr = clip_rect.zy + vec2(-radius.y,  radius.y);
     vec2 ref_br = clip_rect.zw + vec2(-radius.z, -radius.z);
--- a/servo/resources/shaders/ps_border.vs.glsl
+++ b/servo/resources/shaders/ps_border.vs.glsl
@@ -32,28 +32,31 @@ uint get_border_style(Border a_border, u
   }
 }
 
 void main(void) {
     Border border = borders[gl_InstanceID];
 #ifdef WR_FEATURE_TRANSFORM
     TransformVertexInfo vi = write_transform_vertex(border.info);
     vLocalPos = vi.local_pos;
+
+    // Local space
+    vLocalRect = vi.clipped_local_rect;
 #else
     VertexInfo vi = write_vertex(border.info);
     vLocalPos = vi.local_clamped_pos.xy;
+
+    // Local space
+    vLocalRect = border.info.local_rect;
 #endif
 
     // This is what was currently sent.
     vVerticalColor = border.verticalColor;
     vHorizontalColor = border.horizontalColor;
 
-    // Local space
-    vLocalRect = border.info.local_rect;
-
     // Just our boring radius position.
     vRadii = border.radii;
 
     float x0, y0, x1, y1;
     vBorderPart = border.info.layer_tile_part.z;
     switch (vBorderPart) {
         // These are the layer tile part PrimitivePart as uploaded by the tiling.rs
         case PST_TOP_LEFT:
--- a/servo/resources/shaders/ps_gradient.fs.glsl
+++ b/servo/resources/shaders/ps_gradient.fs.glsl
@@ -1,8 +1,20 @@
 /* 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) {
-    do_clip(vPos, vClipRect, vClipRadius);
+#ifdef WR_FEATURE_TRANSFORM
+    float alpha = 0;
+    vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
+#else
+    vec2 local_pos = vPos;
+#endif
+
+    do_clip(local_pos, vClipRect, vClipRadius);
+
     oFragColor = mix(vColor0, vColor1, vF);
+
+#ifdef WR_FEATURE_TRANSFORM
+    oFragColor.a *= alpha;
+#endif
 }
--- a/servo/resources/shaders/ps_gradient.glsl
+++ b/servo/resources/shaders/ps_gradient.glsl
@@ -1,10 +1,16 @@
 /* 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/. */
 
-varying float vF;
-varying vec2 vPos;
 flat varying vec4 vColor0;
 flat varying vec4 vColor1;
 flat varying vec4 vClipRect;
 flat varying vec4 vClipRadius;
+varying float vF;
+
+#ifdef WR_FEATURE_TRANSFORM
+varying vec3 vLocalPos;
+flat varying vec4 vLocalRect;
+#else
+varying vec2 vPos;
+#endif
--- a/servo/resources/shaders/ps_gradient.vs.glsl
+++ b/servo/resources/shaders/ps_gradient.vs.glsl
@@ -15,31 +15,38 @@ struct Gradient {
 };
 
 layout(std140) uniform Items {
     Gradient gradients[WR_MAX_PRIM_ITEMS];
 };
 
 void main(void) {
     Gradient gradient = gradients[gl_InstanceID];
+
+#ifdef WR_FEATURE_TRANSFORM
+    TransformVertexInfo vi = write_transform_vertex(gradient.info);
+    vLocalRect = vi.clipped_local_rect;
+    vLocalPos = vi.local_pos;
+    vec2 f = (vi.local_pos.xy - gradient.info.local_rect.xy) / gradient.info.local_rect.zw;
+#else
     VertexInfo vi = write_vertex(gradient.info);
-
     vec2 f = (vi.local_clamped_pos - gradient.info.local_rect.xy) / gradient.info.local_rect.zw;
+    vPos = vi.local_clamped_pos;
+#endif
 
     switch (gradient.dir.x) {
         case DIR_HORIZONTAL:
             vF = f.x;
             break;
         case DIR_VERTICAL:
             vF = f.y;
             break;
     }
 
     vClipRect = vec4(gradient.clip.rect.xy, gradient.clip.rect.xy + gradient.clip.rect.zw);
     vClipRadius = vec4(gradient.clip.top_left.outer_inner_radius.x,
                        gradient.clip.top_right.outer_inner_radius.x,
                        gradient.clip.bottom_right.outer_inner_radius.x,
                        gradient.clip.bottom_left.outer_inner_radius.x);
-    vPos = vi.local_clamped_pos;
 
     vColor0 = gradient.color0;
     vColor1 = gradient.color1;
 }
--- a/servo/resources/shaders/ps_image.vs.glsl
+++ b/servo/resources/shaders/ps_image.vs.glsl
@@ -13,17 +13,17 @@ layout(std140) uniform Items {
     Image images[WR_MAX_PRIM_ITEMS];
 };
 
 void main(void) {
     Image image = images[gl_InstanceID];
 
 #ifdef WR_FEATURE_TRANSFORM
     TransformVertexInfo vi = write_transform_vertex(image.info);
-    vLocalRect = image.info.local_rect;
+    vLocalRect = vi.clipped_local_rect;
     vLocalPos = vi.local_pos;
     vStretchSize = image.stretch_size.xy;
 #else
     VertexInfo vi = write_vertex(image.info);
     vUv = (vi.local_clamped_pos - vi.local_rect.p0) / image.stretch_size.xy;
 #endif
 
     // vUv will contain how many times this image has wrapped around the image size.
--- a/servo/resources/shaders/ps_rectangle.vs.glsl
+++ b/servo/resources/shaders/ps_rectangle.vs.glsl
@@ -12,14 +12,14 @@ layout(std140) uniform Items {
     Rectangle rects[WR_MAX_PRIM_ITEMS];
 };
 
 void main(void) {
     Rectangle rect = rects[gl_InstanceID];
     vColor = rect.color;
 #ifdef WR_FEATURE_TRANSFORM
     TransformVertexInfo vi = write_transform_vertex(rect.info);
-    vLocalRect = rect.info.local_rect;
+    vLocalRect = vi.clipped_local_rect;
     vLocalPos = vi.local_pos;
 #else
     write_vertex(rect.info);
 #endif
 }
--- a/servo/resources/shaders/ps_text.fs.glsl
+++ b/servo/resources/shaders/ps_text.fs.glsl
@@ -1,8 +1,13 @@
 /* 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;
+#ifdef WR_FEATURE_TRANSFORM
+    float alpha = 0;
+    init_transform_fs(vLocalPos, vLocalRect, alpha);
+    a *= alpha;
+#endif
     oFragColor = vec4(vColor.rgb, vColor.a * a);
 }
--- a/servo/resources/shaders/ps_text.glsl
+++ b/servo/resources/shaders/ps_text.glsl
@@ -1,6 +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
--- a/servo/resources/shaders/ps_text.vs.glsl
+++ b/servo/resources/shaders/ps_text.vs.glsl
@@ -10,19 +10,26 @@ struct Glyph {
 };
 
 layout(std140) uniform Items {
     Glyph glyphs[WR_MAX_PRIM_ITEMS];
 };
 
 void main(void) {
     Glyph glyph = glyphs[gl_InstanceID];
+
+#ifdef WR_FEATURE_TRANSFORM
+    TransformVertexInfo vi = write_transform_vertex(glyph.info);
+    vLocalRect = vi.clipped_local_rect;
+    vLocalPos = vi.local_pos;
+    vec2 f = (vi.local_pos.xy - glyph.info.local_rect.xy) / glyph.info.local_rect.zw;
+#else
     VertexInfo vi = write_vertex(glyph.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 = glyph.uv_rect.xy / texture_size;
     vec2 st1 = glyph.uv_rect.zw / texture_size;
 
     vColor = glyph.color;
     vUv = mix(st0, st1, f);
 }