summaryrefslogtreecommitdiffstats
path: root/gfx/wr/webrender/res
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /gfx/wr/webrender/res
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/wr/webrender/res')
-rw-r--r--gfx/wr/webrender/res/ps_quad.glsl69
-rw-r--r--gfx/wr/webrender/res/ps_quad_mask.glsl48
-rw-r--r--gfx/wr/webrender/res/ps_quad_textured.glsl37
3 files changed, 97 insertions, 57 deletions
diff --git a/gfx/wr/webrender/res/ps_quad.glsl b/gfx/wr/webrender/res/ps_quad.glsl
index 94c80a93f7..3565c28afc 100644
--- a/gfx/wr/webrender/res/ps_quad.glsl
+++ b/gfx/wr/webrender/res/ps_quad.glsl
@@ -25,6 +25,11 @@
/// +-----------------------------+ | device pixel scale | +-----------+--------------+-+-+
/// | content origin |
/// +--------------------+
+///
+/// To use the quad infrastructure, a shader must define the following entry
+/// points in the corresponding shader stages:
+/// - void pattern_vertex(PrimitiveInfo prim)
+/// - vec4 pattern_fragment(vec4 base_color)
///```
#define WR_FEATURE_TEXTURE_2D
@@ -39,6 +44,10 @@ flat varying mediump vec4 v_uv_sample_bounds;
flat varying lowp ivec4 v_flags;
varying highp vec2 v_uv;
+#ifndef SWGL_ANTIALIAS
+varying highp vec2 vLocalPos;
+#endif
+
#ifdef WR_VERTEX_SHADER
#define EDGE_AA_LEFT 1
@@ -73,6 +82,7 @@ struct PrimitiveInfo {
int edge_flags;
int quad_flags;
+ ivec2 pattern_input;
};
struct QuadSegment {
@@ -112,6 +122,7 @@ QuadPrimitive fetch_primitive(int index) {
struct QuadHeader {
int transform_id;
int z_id;
+ ivec2 pattern_input;
};
QuadHeader fetch_header(int address) {
@@ -119,7 +130,8 @@ QuadHeader fetch_header(int address) {
QuadHeader qh = QuadHeader(
header.x,
- header.y
+ header.y,
+ header.zw
);
return qh;
@@ -204,7 +216,11 @@ float edge_aa_offset(int edge, int flags) {
return ((flags & edge) != 0) ? AA_PIXEL_RADIUS : 0.0;
}
-PrimitiveInfo ps_quad_main(void) {
+#ifdef WR_VERTEX_SHADER
+void pattern_vertex(PrimitiveInfo prim);
+#endif
+
+PrimitiveInfo quad_primive_info(void) {
QuadInstance qi = decode_instance();
QuadHeader qh = fetch_header(qi.prim_address_i);
@@ -339,7 +355,54 @@ PrimitiveInfo ps_quad_main(void) {
prim.bounds,
prim.clip,
qi.edge_flags,
- qi.quad_flags
+ qi.quad_flags,
+ qh.pattern_input
);
}
+
+void antialiasing_vertex(PrimitiveInfo prim) {
+#ifndef SWGL_ANTIALIAS
+ // This does the setup that is required for init_tranform_vs.
+ RectWithEndpoint xf_bounds = RectWithEndpoint(
+ max(prim.local_prim_rect.p0, prim.local_clip_rect.p0),
+ min(prim.local_prim_rect.p1, prim.local_clip_rect.p1)
+ );
+ vTransformBounds = vec4(xf_bounds.p0, xf_bounds.p1);
+
+ vLocalPos = prim.local_pos;
+
+ if (prim.edge_flags == 0) {
+ v_flags.x = 0;
+ } else {
+ v_flags.x = 1;
+ }
+#endif
+}
+
+void main() {
+ PrimitiveInfo prim = quad_primive_info();
+ antialiasing_vertex(prim);
+ pattern_vertex(prim);
+}
+#endif
+
+#ifdef WR_FRAGMENT_SHADER
+vec4 pattern_fragment(vec4 base_color);
+
+float antialiasing_fragment() {
+ float alpha = 1.0;
+#ifndef SWGL_ANTIALIAS
+ if (v_flags.x != 0) {
+ alpha = init_transform_fs(vLocalPos);
+ }
+#endif
+ return alpha;
+}
+
+void main() {
+ vec4 base_color = v_color;
+ base_color *= antialiasing_fragment();
+ oFragColor = pattern_fragment(base_color);
+}
+
#endif
diff --git a/gfx/wr/webrender/res/ps_quad_mask.glsl b/gfx/wr/webrender/res/ps_quad_mask.glsl
index 6b72714efb..0d700d32ec 100644
--- a/gfx/wr/webrender/res/ps_quad_mask.glsl
+++ b/gfx/wr/webrender/res/ps_quad_mask.glsl
@@ -15,10 +15,10 @@ flat varying highp vec4 vClipCenter_Radius_TL;
flat varying highp vec4 vClipCenter_Radius_TR;
flat varying highp vec4 vClipCenter_Radius_BR;
flat varying highp vec4 vClipCenter_Radius_BL;
-flat varying highp vec3 vClipPlane_TL;
-flat varying highp vec3 vClipPlane_TR;
-flat varying highp vec3 vClipPlane_BL;
-flat varying highp vec3 vClipPlane_BR;
+// We pack 4 vec3 clip planes into 3 vec4 to save a varying slot.
+flat varying highp vec4 vClipPlane_A;
+flat varying highp vec4 vClipPlane_B;
+flat varying highp vec4 vClipPlane_C;
#endif
flat varying highp vec2 vClipMode;
@@ -62,8 +62,7 @@ Clip fetch_clip(int index) {
return clip;
}
-void main(void) {
- PrimitiveInfo prim_info = ps_quad_main();
+void pattern_vertex(PrimitiveInfo prim_info) {
Clip clip = fetch_clip(aClipData.y);
Transform clip_transform = fetch_transform(aClipData.x);
@@ -121,14 +120,18 @@ void main(void) {
vec2 n_tr = vec2(r_tr.y, -r_tr.x);
vec2 n_br = r_br.yx;
vec2 n_bl = vec2(-r_bl.y, r_bl.x);
- vClipPlane_TL = vec3(n_tl,
- dot(n_tl, vec2(clip.rect.p0.x, clip.rect.p0.y + r_tl.y)));
- vClipPlane_TR = vec3(n_tr,
- dot(n_tr, vec2(clip.rect.p1.x - r_tr.x, clip.rect.p0.y)));
- vClipPlane_BR = vec3(n_br,
- dot(n_br, vec2(clip.rect.p1.x, clip.rect.p1.y - r_br.y)));
- vClipPlane_BL = vec3(n_bl,
- dot(n_bl, vec2(clip.rect.p0.x + r_bl.x, clip.rect.p1.y)));
+ vec3 tl = vec3(n_tl,
+ dot(n_tl, vec2(clip.rect.p0.x, clip.rect.p0.y + r_tl.y)));
+ vec3 tr = vec3(n_tr,
+ dot(n_tr, vec2(clip.rect.p1.x - r_tr.x, clip.rect.p0.y)));
+ vec3 br = vec3(n_br,
+ dot(n_br, vec2(clip.rect.p1.x, clip.rect.p1.y - r_br.y)));
+ vec3 bl = vec3(n_bl,
+ dot(n_bl, vec2(clip.rect.p0.x + r_bl.x, clip.rect.p1.y)));
+
+ vClipPlane_A = vec4(tl.x, tl.y, tl.z, tr.x);
+ vClipPlane_B = vec4(tr.y, tr.z, br.x, br.y);
+ vClipPlane_C = vec4(br.z, bl.x, bl.y, bl.z);
#endif
}
@@ -148,22 +151,27 @@ float sd_rounded_box(in vec2 pos, in vec2 box_size, in float radius) {
}
#endif
-void main(void) {
+vec4 pattern_fragment(vec4 _base_color) {
vec2 clip_local_pos = vClipLocalPos.xy / vClipLocalPos.w;
float aa_range = compute_aa_range(clip_local_pos);
#ifdef WR_FEATURE_FAST_PATH
float dist = sd_rounded_box(clip_local_pos, v_clip_params.xy, v_clip_params.z);
#else
+ vec3 plane_tl = vec3(vClipPlane_A.x, vClipPlane_A.y, vClipPlane_A.z);
+ vec3 plane_tr = vec3(vClipPlane_A.w, vClipPlane_B.x, vClipPlane_B.y);
+ vec3 plane_br = vec3(vClipPlane_B.z, vClipPlane_B.w, vClipPlane_C.x);
+ vec3 plane_bl = vec3(vClipPlane_C.y, vClipPlane_C.z, vClipPlane_C.w);
+
float dist = distance_to_rounded_rect(
clip_local_pos,
- vClipPlane_TL,
+ plane_tl,
vClipCenter_Radius_TL,
- vClipPlane_TR,
+ plane_tr,
vClipCenter_Radius_TR,
- vClipPlane_BR,
+ plane_br,
vClipCenter_Radius_BR,
- vClipPlane_BL,
+ plane_bl,
vClipCenter_Radius_BL,
vTransformBounds
);
@@ -175,6 +183,6 @@ void main(void) {
// Select alpha or inverse alpha depending on clip in/out.
float final_alpha = mix(alpha, 1.0 - alpha, vClipMode.x);
- oFragColor = vec4(final_alpha);
+ return vec4(final_alpha);
}
#endif
diff --git a/gfx/wr/webrender/res/ps_quad_textured.glsl b/gfx/wr/webrender/res/ps_quad_textured.glsl
index 2382623cdb..b405ccac2c 100644
--- a/gfx/wr/webrender/res/ps_quad_textured.glsl
+++ b/gfx/wr/webrender/res/ps_quad_textured.glsl
@@ -6,30 +6,8 @@
#include ps_quad
-#ifndef SWGL_ANTIALIAS
-varying highp vec2 vLocalPos;
-#endif
-
#ifdef WR_VERTEX_SHADER
-void main(void) {
- PrimitiveInfo info = ps_quad_main();
-
-#ifndef SWGL_ANTIALIAS
- RectWithEndpoint xf_bounds = RectWithEndpoint(
- max(info.local_prim_rect.p0, info.local_clip_rect.p0),
- min(info.local_prim_rect.p1, info.local_clip_rect.p1)
- );
- vTransformBounds = vec4(xf_bounds.p0, xf_bounds.p1);
-
- vLocalPos = info.local_pos;
-
- if (info.edge_flags == 0) {
- v_flags.x = 0;
- } else {
- v_flags.x = 1;
- }
-#endif
-
+void pattern_vertex(PrimitiveInfo info) {
if ((info.quad_flags & QF_SAMPLE_AS_MASK) != 0) {
v_flags.z = 1;
} else {
@@ -39,16 +17,7 @@ void main(void) {
#endif
#ifdef WR_FRAGMENT_SHADER
-void main(void) {
- vec4 color = v_color;
-
-#ifndef SWGL_ANTIALIAS
- if (v_flags.x != 0) {
- float alpha = init_transform_fs(vLocalPos);
- color *= alpha;
- }
-#endif
-
+vec4 pattern_fragment(vec4 color) {
if (v_flags.y != 0) {
vec2 uv = clamp(v_uv, v_uv_sample_bounds.xy, v_uv_sample_bounds.zw);
vec4 texel = TEX_SAMPLE(sColor0, uv);
@@ -58,7 +27,7 @@ void main(void) {
color *= texel;
}
- oFragColor = color;
+ return color;
}
#if defined(SWGL_DRAW_SPAN)