servo: Merge #13808 - Update webrender to get clip_shared changes (from glennw:update-wr-clip); r=jdm
authorGlenn Watson <github@intuitionlibrary.com>
Mon, 17 Oct 2016 22:21:58 -0500
changeset 339940 685dfe58df3dd2e2e43d7013be9af89981d64852
parent 339939 2c5e94db60df33c1453b52ecb7eb060021d10282
child 339941 aa910509fa7ac92d6be502d61a711f2dc9fca8a9
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)
reviewersjdm
servo: Merge #13808 - Update webrender to get clip_shared changes (from glennw:update-wr-clip); r=jdm Source-Repo: https://github.com/servo/servo Source-Revision: fe78c346a35ce81cd602d1caf6e0ef188bf339ad
servo/components/servo/Cargo.lock
servo/ports/cef/Cargo.lock
servo/resources/shaders/clip_shared.glsl
servo/resources/shaders/prim_shared.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_gradient_clip.fs.glsl
servo/resources/shaders/ps_gradient_clip.glsl
servo/resources/shaders/ps_gradient_clip.vs.glsl
servo/resources/shaders/ps_image_clip.fs.glsl
servo/resources/shaders/ps_image_clip.glsl
servo/resources/shaders/ps_image_clip.vs.glsl
servo/resources/shaders/ps_rectangle_clip.fs.glsl
servo/resources/shaders/ps_rectangle_clip.glsl
servo/resources/shaders/ps_rectangle_clip.vs.glsl
--- a/servo/components/servo/Cargo.lock
+++ b/servo/components/servo/Cargo.lock
@@ -2653,17 +2653,17 @@ dependencies = [
  "util 0.0.1",
  "uuid 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "webdriver 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender"
 version = "0.6.0"
-source = "git+https://github.com/servo/webrender#b31b4cf76324bfbe82d27a059e1330ef5ae34c35"
+source = "git+https://github.com/servo/webrender#dff3e5dbcc3a40b3c5db37bf2e31422c61bf6dde"
 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.1 (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.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2678,17 +2678,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.6.0 (git+https://github.com/servo/webrender)",
 ]
 
 [[package]]
 name = "webrender_traits"
 version = "0.6.0"
-source = "git+https://github.com/servo/webrender#b31b4cf76324bfbe82d27a059e1330ef5ae34c35"
+source = "git+https://github.com/servo/webrender#dff3e5dbcc3a40b3c5db37bf2e31422c61bf6dde"
 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.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "heapsize 0.3.7 (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
@@ -2511,17 +2511,17 @@ dependencies = [
  "util 0.0.1",
  "uuid 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "webdriver 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender"
 version = "0.6.0"
-source = "git+https://github.com/servo/webrender#b31b4cf76324bfbe82d27a059e1330ef5ae34c35"
+source = "git+https://github.com/servo/webrender#dff3e5dbcc3a40b3c5db37bf2e31422c61bf6dde"
 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.1 (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.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2536,17 +2536,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.6.0 (git+https://github.com/servo/webrender)",
 ]
 
 [[package]]
 name = "webrender_traits"
 version = "0.6.0"
-source = "git+https://github.com/servo/webrender#b31b4cf76324bfbe82d27a059e1330ef5ae34c35"
+source = "git+https://github.com/servo/webrender#dff3e5dbcc3a40b3c5db37bf2e31422c61bf6dde"
 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.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
new file mode 100644
--- /dev/null
+++ b/servo/resources/shaders/clip_shared.glsl
@@ -0,0 +1,50 @@
+/* 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 vClipRect;
+flat varying vec4 vClipRadius;
+
+#ifdef WR_VERTEX_SHADER
+void write_clip(Clip clip) {
+    vClipRect = vec4(clip.rect.xy, clip.rect.xy + clip.rect.zw);
+    vClipRadius = vec4(clip.top_left.outer_inner_radius.x,
+                       clip.top_right.outer_inner_radius.x,
+                       clip.bottom_right.outer_inner_radius.x,
+                       clip.bottom_left.outer_inner_radius.x);
+}
+#endif
+
+#ifdef WR_FRAGMENT_SHADER
+float do_clip(vec2 pos) {
+    vec2 ref_tl = vClipRect.xy + vec2( vClipRadius.x,  vClipRadius.x);
+    vec2 ref_tr = vClipRect.zy + vec2(-vClipRadius.y,  vClipRadius.y);
+    vec2 ref_br = vClipRect.zw + vec2(-vClipRadius.z, -vClipRadius.z);
+    vec2 ref_bl = vClipRect.xw + vec2( vClipRadius.w, -vClipRadius.w);
+
+    float d_tl = distance(pos, ref_tl);
+    float d_tr = distance(pos, ref_tr);
+    float d_br = distance(pos, ref_br);
+    float d_bl = distance(pos, ref_bl);
+
+    float pixels_per_fragment = length(fwidth(pos.xy));
+    // TODO: compute the `nudge` separately for X and Y
+    float nudge = 0.5 * pixels_per_fragment;
+
+    bool out0 = pos.x < ref_tl.x && pos.y < ref_tl.y && d_tl > vClipRadius.x - nudge;
+    bool out1 = pos.x > ref_tr.x && pos.y < ref_tr.y && d_tr > vClipRadius.y - nudge;
+    bool out2 = pos.x > ref_br.x && pos.y > ref_br.y && d_br > vClipRadius.z - nudge;
+    bool out3 = pos.x < ref_bl.x && pos.y > ref_bl.y && d_bl > vClipRadius.w - nudge;
+
+    vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge;
+    float distance_from_border = dot(vec4(out0, out1, out2, out3), distances);
+
+    // Move the distance back into pixels.
+    distance_from_border /= pixels_per_fragment;
+
+    // Apply a more gradual fade out to transparent.
+    //distance_from_border -= 0.5;
+
+    return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
+}
+#endif
--- a/servo/resources/shaders/prim_shared.glsl
+++ b/servo/resources/shaders/prim_shared.glsl
@@ -540,49 +540,16 @@ Composite fetch_composite(int index) {
     composite.src0_src1_target_id = data[offset + 0];
     composite.info_amount = data[offset + 1];
 
     return composite;
 }
 #endif
 
 #ifdef WR_FRAGMENT_SHADER
-float 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);
-    vec2 ref_bl = clip_rect.xw + vec2( radius.w, -radius.w);
-
-    float d_tl = distance(pos, ref_tl);
-    float d_tr = distance(pos, ref_tr);
-    float d_br = distance(pos, ref_br);
-    float d_bl = distance(pos, ref_bl);
-
-    float pixels_per_fragment = length(fwidth(pos.xy));
-    float nudge = 0.5 * pixels_per_fragment;
-
-    bool out0 = pos.x < ref_tl.x && pos.y < ref_tl.y && d_tl > radius.x - nudge;
-    bool out1 = pos.x > ref_tr.x && pos.y < ref_tr.y && d_tr > radius.y - nudge;
-    bool out2 = pos.x > ref_br.x && pos.y > ref_br.y && d_br > radius.z - nudge;
-    bool out3 = pos.x < ref_bl.x && pos.y > ref_bl.y && d_bl > radius.w - nudge;
-
-    float distance_from_border = (float(out0) * (d_tl - radius.x + nudge)) +
-                                 (float(out1) * (d_tr - radius.y + nudge)) +
-                                 (float(out2) * (d_br - radius.z + nudge)) +
-                                 (float(out3) * (d_bl - radius.w + nudge));
-
-    // Move the distance back into pixels.
-    distance_from_border /= pixels_per_fragment;
-
-    // Apply a more gradual fade out to transparent.
-    //distance_from_border -= 0.5;
-
-    return smoothstep(1.0, 0.0, distance_from_border);
-}
-
 float squared_distance_from_rect(vec2 p, vec2 origin, vec2 size) {
     vec2 clamped = clamp(p, origin, origin + size);
     return distance(clamped, p);
 }
 
 vec2 init_transform_fs(vec3 local_pos, vec4 local_rect, out float fragment_alpha) {
     fragment_alpha = 1.0;
     vec2 pos = local_pos.xy / local_pos.z;
deleted file mode 100644
--- a/servo/resources/shaders/ps_gradient.vs.glsl
+++ /dev/null
@@ -1,40 +0,0 @@
-#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/. */
-
-#define DIR_HORIZONTAL      uint(0)
-#define DIR_VERTICAL        uint(1)
-
-void main(void) {
-    AlignedGradient gradient = fetch_aligned_gradient(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 (uint(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);
-
-    vColor0 = gradient.color0;
-    vColor1 = gradient.color1;
-}
rename from servo/resources/shaders/ps_gradient.fs.glsl
rename to servo/resources/shaders/ps_gradient_clip.fs.glsl
--- a/servo/resources/shaders/ps_gradient.fs.glsl
+++ b/servo/resources/shaders/ps_gradient_clip.fs.glsl
@@ -6,15 +6,15 @@ void main(void) {
 #ifdef WR_FEATURE_TRANSFORM
     float alpha = 0.0;
     vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
 #else
     float alpha = 1.0;
     vec2 local_pos = vPos;
 #endif
 
-    alpha = min(alpha, do_clip(local_pos, vClipRect, vClipRadius));
+    alpha = min(alpha, do_clip(local_pos));
     oFragColor = mix(vColor0, vColor1, vF) * vec4(1, 1, 1, alpha);
 
 #ifdef WR_FEATURE_TRANSFORM
     oFragColor.a *= alpha;
 #endif
 }
rename from servo/resources/shaders/ps_gradient.glsl
rename to servo/resources/shaders/ps_gradient_clip.glsl
--- a/servo/resources/shaders/ps_gradient.glsl
+++ b/servo/resources/shaders/ps_gradient_clip.glsl
@@ -1,16 +1,14 @@
 /* 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 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
new file mode 100644
--- /dev/null
+++ b/servo/resources/shaders/ps_gradient_clip.vs.glsl
@@ -0,0 +1,36 @@
+#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/. */
+
+#define DIR_HORIZONTAL      uint(0)
+#define DIR_VERTICAL        uint(1)
+
+void main(void) {
+    AlignedGradient gradient = fetch_aligned_gradient(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 (uint(gradient.dir.x)) {
+        case DIR_HORIZONTAL:
+            vF = f.x;
+            break;
+        case DIR_VERTICAL:
+            vF = f.y;
+            break;
+    }
+
+    write_clip(gradient.clip);
+
+    vColor0 = gradient.color0;
+    vColor1 = gradient.color1;
+}
--- a/servo/resources/shaders/ps_image_clip.fs.glsl
+++ b/servo/resources/shaders/ps_image_clip.fs.glsl
@@ -14,17 +14,17 @@ void main(void) {
     vec2 pos_for_texture =
          clamp(pos, vLocalRect.xy, vLocalRect.xy + vLocalRect.zw) - vLocalRect.xy;
 #else
     float alpha = 1.f;
     vec2 local_pos = vLocalPos;
     vec2 relative_pos_in_rect = vLocalPos - vLocalRect.xy;
 #endif
 
-    alpha = min(alpha, do_clip(local_pos, vClipRect, vClipRadius));
+    alpha = min(alpha, do_clip(local_pos));
 
     // We calculate the particular tile this fragment belongs to, taking into
     // account the spacing in between tiles. We only paint if our fragment does
     // not fall into that spacing.
     vec2 position_in_tile = mod(relative_pos_in_rect, vStretchSize + vTileSpacing);
     vec2 st = vTextureOffset + ((position_in_tile / vStretchSize) * vTextureSize);
     alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize))));
 
--- a/servo/resources/shaders/ps_image_clip.glsl
+++ b/servo/resources/shaders/ps_image_clip.glsl
@@ -1,18 +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/. */
 
 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 vec2 vTileSpacing;   // Amount of space between tiled instances of this image.
 flat varying vec2 vStretchSize;
-flat varying vec4 vClipRect;
-flat varying vec4 vClipRadius;
 flat varying vec4 vLocalRect;
 
 #ifdef WR_FEATURE_TRANSFORM
 varying vec3 vLocalPos;
 #else
 varying vec2 vLocalPos;
 varying vec2 vUv;                 // Location within the CSS box to draw.
 #endif
--- a/servo/resources/shaders/ps_image_clip.vs.glsl
+++ b/servo/resources/shaders/ps_image_clip.vs.glsl
@@ -10,21 +10,17 @@ void main(void) {
     TransformVertexInfo vi = write_transform_vertex(image.info);
     vLocalPos = vi.local_pos;
 #else
     VertexInfo vi = write_vertex(image.info);
     vLocalPos = vi.local_clamped_pos;
     vLocalRect = image.info.local_rect;
 #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);
+    write_clip(image.clip);
 
     vec2 st0 = image.st_rect.xy;
     vec2 st1 = image.st_rect.zw;
 
     switch (uint(image.uvkind.x)) {
         case UV_NORMALIZED:
             break;
         case UV_PIXEL: {
--- a/servo/resources/shaders/ps_rectangle_clip.fs.glsl
+++ b/servo/resources/shaders/ps_rectangle_clip.fs.glsl
@@ -6,11 +6,11 @@ void main(void) {
 #ifdef WR_FEATURE_TRANSFORM
     float alpha = 1.f;
     vec2 local_pos = init_transform_fs(vPos, vLocalRect, alpha);
 #else
     float alpha = 1.f;
     vec2 local_pos = vPos;
 #endif
 
-    alpha = min(alpha, do_clip(local_pos, vClipRect, vClipRadius));
+    alpha = min(alpha, do_clip(local_pos));
     oFragColor = vColor * vec4(1, 1, 1, alpha);
 }
--- a/servo/resources/shaders/ps_rectangle_clip.glsl
+++ b/servo/resources/shaders/ps_rectangle_clip.glsl
@@ -1,16 +1,14 @@
 #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/. */
 
 varying vec4 vColor;
-flat varying vec4 vClipRect;
-flat varying vec4 vClipRadius;
 
 #ifdef WR_FEATURE_TRANSFORM
 varying vec3 vPos;
 flat varying vec4 vLocalRect;
 #else
 varying vec2 vPos;
 #endif
--- a/servo/resources/shaders/ps_rectangle_clip.vs.glsl
+++ b/servo/resources/shaders/ps_rectangle_clip.vs.glsl
@@ -10,16 +10,12 @@ void main(void) {
     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);
+    write_clip(rect.clip);
 
     vColor = rect.color;
 }