[gtk/ngl-clip-classification] glsl: Make rounded rect clipping cheaper




commit 57e354c297e1703079c2bc6fb51211b24d884ac3
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Mar 8 10:03:21 2021 -0500

    glsl: Make rounded rect clipping cheaper
    
    Add early acceptance checks for non-corner cases.

 gsk/resources/glsl/preamble.fs.glsl | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/gsk/resources/glsl/preamble.fs.glsl b/gsk/resources/glsl/preamble.fs.glsl
index cd0af69958..3a2fe49240 100644
--- a/gsk/resources/glsl/preamble.fs.glsl
+++ b/gsk/resources/glsl/preamble.fs.glsl
@@ -50,16 +50,24 @@ gsk_rounded_rect_coverage (GskRoundedRect r, vec2 p)
       p.x >= r.bounds.z || p.y >= r.bounds.w)
     return 0.0;
 
-  vec2 rad_tl = r.corner_points1.xy - r.bounds.xy;
-  vec2 rad_tr = r.corner_points1.zw - r.bounds.zy;
-  vec2 rad_br = r.corner_points2.xy - r.bounds.zw;
-  vec2 rad_bl = r.corner_points2.zw - r.bounds.xw;
-
   vec2 ref_tl = r.corner_points1.xy;
   vec2 ref_tr = r.corner_points1.zw;
   vec2 ref_br = r.corner_points2.xy;
   vec2 ref_bl = r.corner_points2.zw;
 
+  if (p.x >= ref_tl.x && p.x >= ref_bl.x &&
+      p.x <= ref_tr.x && p.x <= ref_br.x)
+    return 1.0;
+
+  if (p.y >= ref_tl.y && p.y >= ref_tr.y &&
+      p.y <= ref_bl.y && p.y <= ref_br.y)
+    return 1.0;
+
+  vec2 rad_tl = r.corner_points1.xy - r.bounds.xy;
+  vec2 rad_tr = r.corner_points1.zw - r.bounds.zy;
+  vec2 rad_br = r.corner_points2.xy - r.bounds.zw;
+  vec2 rad_bl = r.corner_points2.zw - r.bounds.xw;
+
   float d_tl = gsk_ellipsis_coverage(p, ref_tl, rad_tl);
   float d_tr = gsk_ellipsis_coverage(p, ref_tr, rad_tr);
   float d_br = gsk_ellipsis_coverage(p, ref_br, rad_br);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]