[PATCH 02/10] glamor: Use glsl "fract/mod" instead of "while" in gradient shaders.

Markus Wick markus at selfnet.de
Tue Mar 18 01:42:48 PDT 2014


This fixes gtkperf. It seemed to hang forever.
---
 glamor/glamor_gradient.c | 48 ++++--------------------------------------------
 1 file changed, 4 insertions(+), 44 deletions(-)

diff --git a/glamor/glamor_gradient.c b/glamor/glamor_gradient.c
index f77d6a8..38dac68 100644
--- a/glamor/glamor_gradient.c
+++ b/glamor/glamor_gradient.c
@@ -247,7 +247,6 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count,
 	    "{\n"\
 	    "    float t = 0.0;\n"\
 	    "    float sqrt_value;\n"\
-	    "    int revserse = 0;\n"\
 	    "    t_invalid = 0;\n"\
 	    "    \n"\
 	    "    vec3 tmp = vec3(source_texture.x, source_texture.y, 1.0);\n"\
@@ -295,30 +294,11 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count,
 	    "    }\n"\
 	    "    \n"\
 	    "    if(repeat_type == %d){\n" /* repeat normal*/\
-	    "        while(t > 1.0) \n"\
-	    "            t = t - 1.0; \n"\
-	    "        while(t < 0.0) \n"\
-	    "            t = t + 1.0; \n"\
+	    "        t = fract(t);\n"\
 	    "    }\n"\
 	    "    \n"\
 	    "    if(repeat_type == %d) {\n" /* repeat reflect*/\
-	    "        while(t > 1.0) {\n"\
-	    "            t = t - 1.0; \n"\
-	    "            if(revserse == 0)\n"\
-	    "                revserse = 1;\n"\
-	    "            else\n"\
-	    "                revserse = 0;\n"\
-	    "        }\n"\
-	    "        while(t < 0.0) {\n"\
-	    "            t = t + 1.0; \n"\
-	    "            if(revserse == 0)\n"\
-	    "                revserse = 1;\n"\
-	    "            else\n"\
-	    "                revserse = 0;\n"\
-	    "        }\n"\
-	    "        if(revserse == 1) {\n"\
-	    "            t = 1.0 - t; \n"\
-	    "        }\n"\
+	    "        t = abs(fract(t * 0.5 + 0.5) * 2.0 - 1.0);\n"\
 	    "    }\n"\
 	    "    \n"\
 	    "    return t;\n"\
@@ -492,7 +472,6 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count,
 	    "    vec4 stop_color_before;\n"\
 	    "    vec4 stop_color_after;\n"\
 	    "    float new_alpha; \n"\
-	    "    int revserse = 0;\n"\
 	    "    vec4 gradient_color;\n"\
 	    "    float percentage; \n"\
 	    "    vec3 source_texture_trans = transform_mat * tmp;\n"\
@@ -512,30 +491,11 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count,
 	    "    distance = distance - _p1_distance; \n"\
 	    "    \n"\
 	    "    if(repeat_type == %d){\n" /* repeat normal*/\
-	    "        while(distance > _pt_distance) \n"\
-	    "            distance = distance - (_pt_distance); \n"\
-	    "        while(distance < 0.0) \n"\
-	    "            distance = distance + (_pt_distance); \n"\
+	    "        distance = mod(distance, _pt_distance);\n"\
 	    "    }\n"\
 	    "    \n"\
 	    "    if(repeat_type == %d) {\n" /* repeat reflect*/\
-	    "        while(distance > _pt_distance) {\n"\
-	    "            distance = distance - (_pt_distance); \n"\
-	    "            if(revserse == 0)\n"\
-	    "                revserse = 1;\n"\
-	    "            else\n"\
-	    "                revserse = 0;\n"\
-	    "        }\n"\
-	    "        while(distance < 0.0) {\n"\
-	    "            distance = distance + (_pt_distance); \n"\
-	    "            if(revserse == 0)\n"\
-	    "                revserse = 1;\n"\
-	    "            else\n"\
-	    "                revserse = 0;\n"\
-	    "        }\n"\
-	    "        if(revserse == 1) {\n"\
-	    "            distance = (_pt_distance) - distance; \n"\
-	    "        }\n"\
+	    "        distance = abs(mod(distance + _pt_distance, 2.0 * _pt_distance) - _pt_distance);\n"\
 	    "    }\n"\
 	    "    \n"\
 	    "    len_percentage = distance/(_pt_distance);\n"\
-- 
1.9.0



More information about the xorg-devel mailing list