Bug 1594128 - Add brush_linear_gradient to the multi-brush infrastructure. r=gw
authorNicolas Silva <nsilva@mozilla.com>
Mon, 25 Nov 2019 20:01:49 +0000
changeset 503858 54efcc9976cf17987c5b3bbfaf120ea76f9b395e
parent 503857 5768997fb3919368e763df2c7cb9198b6d3995ff
child 503859 84e767a3763735eab3fefadaf99de5cf85a1c806
push id36849
push userdvarga@mozilla.com
push dateTue, 26 Nov 2019 21:27:08 +0000
treeherdermozilla-central@bcbb45f7d4f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw
bugs1594128
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594128 - Add brush_linear_gradient to the multi-brush infrastructure. r=gw Differential Revision: https://phabricator.services.mozilla.com/D53995
gfx/wr/webrender/res/brush.glsl
gfx/wr/webrender/res/brush_linear_gradient.glsl
gfx/wr/webrender/res/brush_multi.glsl
--- a/gfx/wr/webrender/res/brush.glsl
+++ b/gfx/wr/webrender/res/brush.glsl
@@ -70,16 +70,18 @@ flat varying vec4 flat_varying_vec4_2;
 flat varying vec4 flat_varying_vec4_3;
 flat varying vec4 flat_varying_vec4_4;
 
 flat varying ivec4 flat_varying_ivec4_0;
 
 varying vec4 varying_vec4_0;
 varying vec4 varying_vec4_1;
 
+flat varying HIGHP_FS_ADDRESS int flat_varying_highp_int_address_0;
+
 #ifdef WR_VERTEX_SHADER
 
 #define FWD_DECLARE_VS_FUNCTION(name)   \
 void name(                              \
     VertexInfo vi,                      \
     int prim_address,                   \
     RectWithSize local_rect,            \
     RectWithSize segment_rect,          \
@@ -226,16 +228,22 @@ void main(void) {
             break;
         #endif
 
         #ifdef WR_FEATURE_MIX_BLEND_BRUSH
         case BRUSH_KIND_MIX_BLEND:
             mix_blend_brush_vs(BRUSH_VS_PARAMS);
             break;
         #endif
+
+        #ifdef WR_FEATURE_LINEAR_GRADIENT_BRUSH
+        case BRUSH_KIND_LINEAR_GRADIENT:
+            linear_gradient_brush_vs(BRUSH_VS_PARAMS);
+            break;
+        #endif
     }
 
 #else
     WR_BRUSH_VS_FUNCTION(BRUSH_VS_PARAMS);
 #endif
 
 }
 
@@ -287,16 +295,22 @@ void main(void) {
         }
 #endif
 #ifdef WR_FEATURE_MIX_BLEND_BRUSH
         case BRUSH_KIND_MIX_BLEND: {
             frag = mix_blend_brush_fs();
             break;
         }
 #endif
+#ifdef WR_FEATURE_LINEAR_GRADIENT_BRUSH
+        case BRUSH_KIND_LINEAR_GRADIENT: {
+            frag = linear_gradient_brush_fs();
+            break;
+        }
+#endif
     }
 #else
     frag = WR_BRUSH_FS_FUNCTION();
 #endif
 
 
 #ifdef WR_FEATURE_ALPHA_PASS
     // Apply the clip mask
--- a/gfx/wr/webrender/res/brush_linear_gradient.glsl
+++ b/gfx/wr/webrender/res/brush_linear_gradient.glsl
@@ -5,31 +5,32 @@
 #define VECS_PER_LINEAR_GRADIENT_BRUSH 2
 #define VECS_PER_SPECIFIC_BRUSH VECS_PER_LINEAR_GRADIENT_BRUSH
 
 #define WR_BRUSH_VS_FUNCTION linear_gradient_brush_vs
 #define WR_BRUSH_FS_FUNCTION linear_gradient_brush_fs
 
 #include shared,prim_shared,brush
 
-flat varying HIGHP_FS_ADDRESS int vGradientAddress;
-flat varying float vGradientRepeat;
+#define V_GRADIENT_ADDRESS  flat_varying_highp_int_address_0
 
-flat varying vec2 vScaledDir;
-flat varying vec2 vStartPoint;
+#define V_START_POINT       flat_varying_vec4_0.xy
+#define V_SCALE_DIR         flat_varying_vec4_0.zw
 // Size of the gradient pattern's rectangle, used to compute horizontal and vertical
 // repetitions. Not to be confused with another kind of repetition of the pattern
 // which happens along the gradient stops.
-flat varying vec2 vRepeatedSize;
+#define V_REPEATED_SIZE     flat_varying_vec4_1.xy
+// Repetition along the gradient stops.
+#define V_GRADIENT_REPEAT   flat_varying_vec4_1.z
 
-varying vec2 vPos;
+#define V_POS               varying_vec4_0.zw
 
 #ifdef WR_FEATURE_ALPHA_PASS
-varying vec2 vLocalPos;
-flat varying vec2 vTileRepeat;
+#define V_LOCAL_POS         varying_vec4_0.xy
+#define V_TILE_REPEAT       flat_varying_vec4_2.xy
 #endif
 
 #ifdef WR_VERTEX_SHADER
 
 struct Gradient {
     vec4 start_end_point;
     int extend_mode;
     vec2 stretch_size;
@@ -54,73 +55,83 @@ void linear_gradient_brush_vs(
     mat4 transform,
     PictureTask pic_task,
     int brush_flags,
     vec4 texel_rect
 ) {
     Gradient gradient = fetch_gradient(prim_address);
 
     if ((brush_flags & BRUSH_FLAG_SEGMENT_RELATIVE) != 0) {
-        vPos = (vi.local_pos - segment_rect.p0) / segment_rect.size;
-        vPos = vPos * (texel_rect.zw - texel_rect.xy) + texel_rect.xy;
-        vPos = vPos * local_rect.size;
+        V_POS = (vi.local_pos - segment_rect.p0) / segment_rect.size;
+        V_POS = V_POS * (texel_rect.zw - texel_rect.xy) + texel_rect.xy;
+        V_POS = V_POS * local_rect.size;
     } else {
-        vPos = vi.local_pos - local_rect.p0;
+        V_POS = vi.local_pos - local_rect.p0;
     }
 
     vec2 start_point = gradient.start_end_point.xy;
     vec2 end_point = gradient.start_end_point.zw;
     vec2 dir = end_point - start_point;
 
-    vStartPoint = start_point;
-    vScaledDir = dir / dot(dir, dir);
+    V_START_POINT = start_point;
+    V_SCALE_DIR = dir / dot(dir, dir);
 
     vec2 tile_repeat = local_rect.size / gradient.stretch_size;
-    vRepeatedSize = gradient.stretch_size;
+    V_REPEATED_SIZE = gradient.stretch_size;
 
-    vGradientAddress = prim_user_data.x;
+    V_GRADIENT_ADDRESS = prim_user_data.x;
 
     // Whether to repeat the gradient along the line instead of clamping.
-    vGradientRepeat = float(gradient.extend_mode != EXTEND_MODE_CLAMP);
+    V_GRADIENT_REPEAT = float(gradient.extend_mode != EXTEND_MODE_CLAMP);
 
 #ifdef WR_FEATURE_ALPHA_PASS
-    vTileRepeat = tile_repeat;
-    vLocalPos = vi.local_pos;
+    V_TILE_REPEAT = tile_repeat;
+    V_LOCAL_POS = vi.local_pos;
 #endif
 }
 #endif
 
 #ifdef WR_FRAGMENT_SHADER
 Fragment linear_gradient_brush_fs() {
 
 #ifdef WR_FEATURE_ALPHA_PASS
     // Handle top and left inflated edges (see brush_image).
-    vec2 local_pos = max(vPos, vec2(0.0));
+    vec2 local_pos = max(V_POS, vec2(0.0));
 
     // Apply potential horizontal and vertical repetitions.
-    vec2 pos = mod(local_pos, vRepeatedSize);
+    vec2 pos = mod(local_pos, V_REPEATED_SIZE);
 
-    vec2 prim_size = vRepeatedSize * vTileRepeat;
+    vec2 prim_size = V_REPEATED_SIZE * V_TILE_REPEAT;
     // Handle bottom and right inflated edges (see brush_image).
     if (local_pos.x >= prim_size.x) {
-        pos.x = vRepeatedSize.x;
+        pos.x = V_REPEATED_SIZE.x;
     }
     if (local_pos.y >= prim_size.y) {
-        pos.y = vRepeatedSize.y;
+        pos.y = V_REPEATED_SIZE.y;
     }
 #else
     // Apply potential horizontal and vertical repetitions.
-    vec2 pos = mod(vPos, vRepeatedSize);
+    vec2 pos = mod(V_POS, V_REPEATED_SIZE);
 #endif
 
-    float offset = dot(pos - vStartPoint, vScaledDir);
+    float offset = dot(pos - V_START_POINT, V_SCALE_DIR);
 
-    vec4 color = sample_gradient(vGradientAddress,
+    vec4 color = sample_gradient(V_GRADIENT_ADDRESS,
                                  offset,
-                                 vGradientRepeat);
+                                 V_GRADIENT_REPEAT);
 
 #ifdef WR_FEATURE_ALPHA_PASS
-    color *= init_transform_fs(vLocalPos);
+    color *= init_transform_fs(V_LOCAL_POS);
 #endif
 
     return Fragment(color);
 }
 #endif
+
+// Undef macro names that could be re-defined by other shaders.
+#undef V_GRADIENT_ADDRESS
+#undef V_START_POINT
+#undef V_SCALE_DIR
+#undef V_REPEATED_SIZE
+#undef V_GRADIENT_REPEAT
+#undef V_POS
+#undef V_LOCAL_POS
+#undef V_TILE_REPEAT
--- a/gfx/wr/webrender/res/brush_multi.glsl
+++ b/gfx/wr/webrender/res/brush_multi.glsl
@@ -31,16 +31,24 @@ int vecs_per_brush(int brush_kind);
 #undef VECS_PER_SPECIFIC_BRUSH
 #undef WR_BRUSH_VS_FUNCTION
 #undef WR_BRUSH_FS_FUNCTION
 
 #ifdef WR_FEATURE_MIX_BLEND_BRUSH
 #include brush_mix_blend
 #endif
 
+#undef VECS_PER_SPECIFIC_BRUSH
+#undef WR_BRUSH_VS_FUNCTION
+#undef WR_BRUSH_FS_FUNCTION
+
+#ifdef WR_FEATURE_LINEAR_GRADIENT_BRUSH
+#include brush_linear_gradient
+#endif
+
 int vecs_per_brush(int brush_kind) {
     int result;
     switch (brush_kind) {
         #ifdef WR_FEATURE_IMAGE_BRUSH
         case BRUSH_KIND_IMAGE:
             result = VECS_PER_IMAGE_BRUSH;
             break;
         #endif
@@ -57,12 +65,18 @@ int vecs_per_brush(int brush_kind) {
             break;
         #endif
 
         #ifdef WR_FEATURE_MIX_BLEND_BRUSH
         case BRUSH_KIND_MIX_BLEND:
             result = VECS_PER_MIX_BLEND_BRUSH;
             break;
         #endif
+
+        #ifdef WR_FEATURE_LINEAR_GRADIENT_BRUSH
+        case BRUSH_KIND_LINEAR_GRADIENT:
+            result = VECS_PER_LINEAR_GRADIENT_BRUSH;
+            break;
+        #endif
     }
 
     return result;
 }