mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #13002 - glennw:wr2-update-local-clipping, r=pcwalton
Update wr + shaders for local clip rect changes. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13002) <!-- Reviewable:end -->
This commit is contained in:
commit
400c7e0324
12 changed files with 83 additions and 25 deletions
4
components/servo/Cargo.lock
generated
4
components/servo/Cargo.lock
generated
|
@ -2593,7 +2593,7 @@ dependencies = [
|
|||
[[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)",
|
||||
|
@ -2618,7 +2618,7 @@ dependencies = [
|
|||
[[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)",
|
||||
|
|
4
ports/cef/Cargo.lock
generated
4
ports/cef/Cargo.lock
generated
|
@ -2453,7 +2453,7 @@ dependencies = [
|
|||
[[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)",
|
||||
|
@ -2478,7 +2478,7 @@ dependencies = [
|
|||
[[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)",
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
struct Layer {
|
||||
mat4 transform;
|
||||
mat4 inv_transform;
|
||||
ivec4 world_clip_rect;
|
||||
vec4 local_clip_rect;
|
||||
vec4 screen_vertices[4];
|
||||
};
|
||||
|
||||
|
@ -123,6 +123,10 @@ VertexInfo write_vertex(PrimitiveInfo info) {
|
|||
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;
|
||||
|
||||
|
@ -132,10 +136,6 @@ VertexInfo write_vertex(PrimitiveInfo info) {
|
|||
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;
|
||||
|
||||
|
@ -149,16 +149,29 @@ VertexInfo write_vertex(PrimitiveInfo info) {
|
|||
|
||||
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);
|
||||
|
@ -191,7 +204,7 @@ TransformVertexInfo write_transform_vertex(PrimitiveInfo info) {
|
|||
|
||||
gl_Position = uTransform * vec4(final_pos, 0, 1);
|
||||
|
||||
return TransformVertexInfo(layer_pos);
|
||||
return TransformVertexInfo(layer_pos, clipped_local_rect);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -37,18 +37,21 @@ void main(void) {
|
|||
#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;
|
||||
|
||||
|
|
|
@ -3,6 +3,18 @@
|
|||
* 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
|
||||
}
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
* 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
|
||||
|
|
|
@ -20,9 +20,17 @@ layout(std140) uniform Items {
|
|||
|
||||
void main(void) {
|
||||
Gradient gradient = gradients[gl_InstanceID];
|
||||
VertexInfo vi = write_vertex(gradient.info);
|
||||
|
||||
#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:
|
||||
|
@ -38,7 +46,6 @@ void main(void) {
|
|||
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;
|
||||
|
|
|
@ -18,7 +18,7 @@ void main(void) {
|
|||
|
||||
#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
|
||||
|
|
|
@ -17,7 +17,7 @@ void main(void) {
|
|||
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);
|
||||
|
|
|
@ -4,5 +4,10 @@
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -4,3 +4,8 @@
|
|||
|
||||
flat varying vec4 vColor;
|
||||
varying vec2 vUv;
|
||||
|
||||
#ifdef WR_FEATURE_TRANSFORM
|
||||
varying vec3 vLocalPos;
|
||||
flat varying vec4 vLocalRect;
|
||||
#endif
|
||||
|
|
|
@ -15,9 +15,16 @@ layout(std140) uniform Items {
|
|||
|
||||
void main(void) {
|
||||
Glyph glyph = glyphs[gl_InstanceID];
|
||||
VertexInfo vi = write_vertex(glyph.info);
|
||||
|
||||
#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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue