diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index b326b7a1444a..4f9bc40b6c31 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -2658,7 +2658,7 @@ dependencies = [ [[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)", @@ -2683,7 +2683,7 @@ dependencies = [ [[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)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 0e1ef872a280..06a19b61f5f2 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -2516,7 +2516,7 @@ dependencies = [ [[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)", @@ -2541,7 +2541,7 @@ dependencies = [ [[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)", diff --git a/resources/shaders/clip_shared.glsl b/resources/shaders/clip_shared.glsl new file mode 100644 index 000000000000..772ff050e06b --- /dev/null +++ b/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 diff --git a/resources/shaders/prim_shared.glsl b/resources/shaders/prim_shared.glsl index 2220a7de34d7..df62c0fe77ae 100644 --- a/resources/shaders/prim_shared.glsl +++ b/resources/shaders/prim_shared.glsl @@ -545,39 +545,6 @@ Composite fetch_composite(int index) { #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); diff --git a/resources/shaders/ps_gradient.fs.glsl b/resources/shaders/ps_gradient_clip.fs.glsl similarity index 88% rename from resources/shaders/ps_gradient.fs.glsl rename to resources/shaders/ps_gradient_clip.fs.glsl index 96b262395fc8..f22194261cbd 100644 --- a/resources/shaders/ps_gradient.fs.glsl +++ b/resources/shaders/ps_gradient_clip.fs.glsl @@ -11,7 +11,7 @@ void main(void) { 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 diff --git a/resources/shaders/ps_gradient.glsl b/resources/shaders/ps_gradient_clip.glsl similarity index 86% rename from resources/shaders/ps_gradient.glsl rename to resources/shaders/ps_gradient_clip.glsl index 01a43b339ab1..160d506ce99b 100644 --- a/resources/shaders/ps_gradient.glsl +++ b/resources/shaders/ps_gradient_clip.glsl @@ -4,8 +4,6 @@ flat varying vec4 vColor0; flat varying vec4 vColor1; -flat varying vec4 vClipRect; -flat varying vec4 vClipRadius; varying float vF; #ifdef WR_FEATURE_TRANSFORM diff --git a/resources/shaders/ps_gradient.vs.glsl b/resources/shaders/ps_gradient_clip.vs.glsl similarity index 74% rename from resources/shaders/ps_gradient.vs.glsl rename to resources/shaders/ps_gradient_clip.vs.glsl index 6697e3a08c15..e4bbeaf84361 100644 --- a/resources/shaders/ps_gradient.vs.glsl +++ b/resources/shaders/ps_gradient_clip.vs.glsl @@ -29,11 +29,7 @@ void main(void) { 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); + write_clip(gradient.clip); vColor0 = gradient.color0; vColor1 = gradient.color1; diff --git a/resources/shaders/ps_image_clip.fs.glsl b/resources/shaders/ps_image_clip.fs.glsl index 3cc2ba3d6322..f3c03c8095c9 100644 --- a/resources/shaders/ps_image_clip.fs.glsl +++ b/resources/shaders/ps_image_clip.fs.glsl @@ -19,7 +19,7 @@ void main(void) { 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 diff --git a/resources/shaders/ps_image_clip.glsl b/resources/shaders/ps_image_clip.glsl index fe4333271d9b..02c4ff785048 100644 --- a/resources/shaders/ps_image_clip.glsl +++ b/resources/shaders/ps_image_clip.glsl @@ -6,8 +6,6 @@ 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 diff --git a/resources/shaders/ps_image_clip.vs.glsl b/resources/shaders/ps_image_clip.vs.glsl index 3ba4bc3b49f5..6a12546ee1a3 100644 --- a/resources/shaders/ps_image_clip.vs.glsl +++ b/resources/shaders/ps_image_clip.vs.glsl @@ -15,11 +15,7 @@ void main(void) { 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; diff --git a/resources/shaders/ps_rectangle_clip.fs.glsl b/resources/shaders/ps_rectangle_clip.fs.glsl index 61b2b026b7c6..9e0e0a95aba7 100644 --- a/resources/shaders/ps_rectangle_clip.fs.glsl +++ b/resources/shaders/ps_rectangle_clip.fs.glsl @@ -11,6 +11,6 @@ void main(void) { 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); } diff --git a/resources/shaders/ps_rectangle_clip.glsl b/resources/shaders/ps_rectangle_clip.glsl index 4880668eadaa..abd4a6cc5e8d 100644 --- a/resources/shaders/ps_rectangle_clip.glsl +++ b/resources/shaders/ps_rectangle_clip.glsl @@ -5,8 +5,6 @@ * 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; diff --git a/resources/shaders/ps_rectangle_clip.vs.glsl b/resources/shaders/ps_rectangle_clip.vs.glsl index f62ecbbb2ef3..90bb0ee4f508 100644 --- a/resources/shaders/ps_rectangle_clip.vs.glsl +++ b/resources/shaders/ps_rectangle_clip.vs.glsl @@ -15,11 +15,7 @@ void main(void) { 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; }