[cairo-commit] 5 commits - src/cairo-gl-private.h src/cairo-gl-shaders.c src/cairo-gl-surface.c test/cairo-test-runner.c

Eric Anholt anholt at kemper.freedesktop.org
Wed Feb 17 12:56:51 PST 2010


 src/cairo-gl-private.h   |   10 ---
 src/cairo-gl-shaders.c   |  139 -----------------------------------------------
 src/cairo-gl-surface.c   |   55 ++----------------
 test/cairo-test-runner.c |   14 +++-
 4 files changed, 19 insertions(+), 199 deletions(-)

New commits:
commit 9057c4b6be5f5cc6f8905e017dde534402ddedda
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Feb 17 12:37:07 2010 -0800

    test: Add an option to explicitly specify a test name to the runner.

diff --git a/test/cairo-test-runner.c b/test/cairo-test-runner.c
index af2991a..2b83b88 100644
--- a/test/cairo-test-runner.c
+++ b/test/cairo-test-runner.c
@@ -93,6 +93,7 @@ typedef struct _cairo_test_runner {
     cairo_bool_t exit_on_failure;
     cairo_bool_t list_only;
     cairo_bool_t full_test;
+    cairo_bool_t exact_test_names;
 } cairo_test_runner_t;
 
 typedef enum {
@@ -315,7 +316,7 @@ static void
 usage (const char *argv0)
 {
     fprintf (stderr,
-	     "Usage: %s [-afx] [test-names|keywords ...]\n"
+	     "Usage: %s [-afxlt] [test-names|keywords ...]\n"
 	     "       %s -l\n"
 	     "\n"
 	     "Run the cairo conformance test suite over the given tests (all by default)\n"
@@ -324,10 +325,11 @@ usage (const char *argv0)
 	     "  -a	all; run the full set of tests. By default the test suite\n"
 	     "          skips similar surface and device offset testing.\n"
 	     "  -f	foreground; do not fork\n"
+	     "  -t	exact test names, no keyword matching\n"
 	     "  -x	exit on first failure\n"
 	     "  -l	list only; just list selected test case names without executing\n"
 	     "\n"
-	     "If test names are given they are used as exact matches either to a specific\n"
+	     "If test names are given they are used as matches either to a specific\n"
 	     "test case or to a keyword, so a command such as\n"
 	     "\"cairo-test-suite text\" can be used to run all text test cases.\n",
 	     argv0, argv0);
@@ -339,7 +341,7 @@ _parse_cmdline (cairo_test_runner_t *runner, int *argc, char **argv[])
     int c;
 
     while (1) {
-	c = _cairo_getopt (*argc, *argv, ":aflx");
+	c = _cairo_getopt (*argc, *argv, ":aflxt");
 	if (c == -1)
 	    break;
 
@@ -356,6 +358,9 @@ _parse_cmdline (cairo_test_runner_t *runner, int *argc, char **argv[])
 	case 'x':
 	    runner->exit_on_failure = TRUE;
 	    break;
+	case 't':
+	    runner->exact_test_names = TRUE;
+	    break;
 	default:
 	    fprintf (stderr, "Internal error: unhandled option: %c\n", c);
 	    /* fall-through */
@@ -709,6 +714,9 @@ main (int argc, char **argv)
 		    found = TRUE;
 		}
 
+		if (runner.exact_test_names)
+		    continue;
+
 		/* XXX keyword match */
 		if (keywords != NULL && strstr (keywords, match) != NULL) {
 		    found = ! invert;
commit e0a948bd2ff3504f5d8b3b3f2136cd9b86cf8ec6
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Feb 17 11:48:41 2010 -0800

    gl: Be sure to do linear interpolation on gradients.

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 8b13e39..e9a2061 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1166,6 +1166,8 @@ _render_gradient (const cairo_gl_context_t *ctx,
     if (unlikely (gradient == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
+    pixman_image_set_filter (gradient, PIXMAN_FILTER_BILINEAR, NULL, 0);
+
     image = pixman_image_create_bits (PIXMAN_a8r8g8b8, width, 1,
 				      bytes, sizeof(uint32_t)*width);
     if (unlikely (image == NULL)) {
@@ -1213,7 +1215,7 @@ _cairo_gl_create_gradient_texture (const cairo_gl_context_t *ctx,
 
     glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, 0);
 
-    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
     switch (pattern->base.extend) {
commit f1e794956f60a935bfc38ae1c2c2d51d37aadee3
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Feb 17 11:03:52 2010 -0800

    gl: Stop trying to handle first/last stop offset in the gradient shaders.
    
    Since moving to pixman for the gradient textures, first=0 and last=1,
    so there's no need to rescale to 0,1 any more.  Shaves 6 Gen4 ISA
    instructions, including 2 inverses, in the radial fragment shader.

diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index b02fad4..1c5429a 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -168,8 +168,6 @@ typedef struct cairo_gl_composite_operand {
 	    cairo_matrix_t m;
 	    float segment_x;
 	    float segment_y;
-	    float first_stop_offset;
-	    float last_stop_offset;
 	} linear;
 	struct {
 	    GLuint tex;
@@ -178,8 +176,6 @@ typedef struct cairo_gl_composite_operand {
 	    float circle_1_y;
 	    float radius_0;
 	    float radius_1;
-	    float first_stop_offset;
-	    float last_stop_offset;
 	} radial;
     } operand;
 
diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c
index fb99efa..b2f3a3f 100644
--- a/src/cairo-gl-shaders.c
+++ b/src/cairo-gl-shaders.c
@@ -625,14 +625,11 @@ static const char *fs_source_linear_gradient =
     "uniform sampler1D source_sampler;\n"
     "uniform mat4 source_matrix;\n"
     "uniform vec2 source_segment;\n"
-    "uniform float source_first_offset;\n"
-    "uniform float source_last_offset;\n"
     "\n"
     "vec4 get_source()\n"
     "{\n"
     "    vec2 pos = (source_matrix * vec4 (gl_FragCoord.xy, 0.0, 1.0)).xy;\n"
     "    float t = dot (pos, source_segment) / dot (source_segment, source_segment);\n"
-    "    t = (t - source_first_offset) / (source_last_offset - source_first_offset);\n"
     "    return texture1D (source_sampler, t);\n"
     "}\n";
 static const char *fs_source_radial_gradient =
@@ -641,8 +638,6 @@ static const char *fs_source_radial_gradient =
     "uniform vec2 source_circle_1;\n"
     "uniform float source_radius_0;\n"
     "uniform float source_radius_1;\n"
-    "uniform float source_first_offset;\n"
-    "uniform float source_last_offset;\n"
     "\n"
     "vec4 get_source()\n"
     "{\n"
@@ -662,7 +657,6 @@ static const char *fs_source_radial_gradient =
     "    sqrt_det *= sign(A);\n"
     "    \n"
     "    float t = (-B + sqrt_det) / (2.0 * A);\n"
-    "    t = (t - source_first_offset) / (source_last_offset - source_first_offset);\n"
     "    return texture1D (source_sampler, t);\n"
     "}\n";
 static const char *fs_mask_constant =
@@ -703,14 +697,11 @@ static const char *fs_mask_linear_gradient =
     "uniform sampler1D mask_sampler;\n"
     "uniform mat4 mask_matrix;\n"
     "uniform vec2 mask_segment;\n"
-    "uniform float mask_first_offset;\n"
-    "uniform float mask_last_offset;\n"
     "\n"
     "vec4 get_mask()\n"
     "{\n"
     "    vec2 pos = (mask_matrix * vec4 (gl_FragCoord.xy, 0.0, 1.0)).xy;\n"
     "    float t = dot (pos, mask_segment) / dot (mask_segment, mask_segment);\n"
-    "    t = (t - mask_first_offset) / (mask_last_offset - mask_first_offset);\n"
     "    return texture1D (mask_sampler, t);\n"
     "}\n";
 static const char *fs_mask_radial_gradient =
@@ -719,8 +710,6 @@ static const char *fs_mask_radial_gradient =
     "uniform vec2 mask_circle_1;\n"
     "uniform float mask_radius_0;\n"
     "uniform float mask_radius_1;\n"
-    "uniform float mask_first_offset;\n"
-    "uniform float mask_last_offset;\n"
     "\n"
     "vec4 get_mask()\n"
     "{\n"
@@ -740,7 +729,6 @@ static const char *fs_mask_radial_gradient =
     "    sqrt_det *= sign(A);\n"
     "    \n"
     "    float t = (-B + sqrt_det) / (2.0 * A);\n"
-    "    t = (t - mask_first_offset) / (mask_last_offset - mask_first_offset);\n"
     "    return texture1D (mask_sampler, t);\n"
     "}\n";
 static const char *fs_mask_none =
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 84c8d88..8b13e39 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1189,9 +1189,7 @@ static void
 _cairo_gl_create_gradient_texture (const cairo_gl_context_t *ctx,
 				   cairo_gl_surface_t *surface,
 				   cairo_gradient_pattern_t *pattern,
-				   GLuint *tex,
-				   float *first_offset,
-				   float *last_offset)
+				   GLuint *tex)
 {
     int tex_width;
     GLubyte *data;
@@ -1205,8 +1203,6 @@ _cairo_gl_create_gradient_texture (const cairo_gl_context_t *ctx,
     data = glMapBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
 
     _render_gradient (ctx, pattern, data, tex_width);
-    *first_offset = 0.;
-    *last_offset  = 1.;
 
     glUnmapBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB);
 
@@ -1389,9 +1385,7 @@ _cairo_gl_gradient_operand_init(cairo_gl_composite_operand_t *operand,
         _cairo_gl_create_gradient_texture (ctx,
 					   dst,
 					   gradient,
-					   &operand->operand.linear.tex,
-					   &operand->operand.linear.first_stop_offset,
-					   &operand->operand.linear.last_stop_offset);
+					   &operand->operand.linear.tex);
 
 	/* Translation matrix from the destination fragment coordinates
 	 * (pixels from lower left = 0,0) to the coordinates in the
@@ -1427,9 +1421,7 @@ _cairo_gl_gradient_operand_init(cairo_gl_composite_operand_t *operand,
         _cairo_gl_create_gradient_texture (ctx,
 					   dst,
 					   gradient,
-					   &operand->operand.radial.tex,
-					   &operand->operand.radial.first_stop_offset,
-					   &operand->operand.radial.last_stop_offset);
+					   &operand->operand.radial.tex);
 
 	/* Translation matrix from the destination fragment coordinates
 	 * (pixels from lower left = 0,0) to the coordinates in the
@@ -1624,16 +1616,6 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
 				      setup->src.operand.linear.segment_x,
 				      setup->src.operand.linear.segment_y);
 	assert (!_cairo_status_is_error (status));
-
-	status = bind_float_to_shader (setup->shader->program,
-				       "source_first_offset",
-				       setup->src.operand.linear.first_stop_offset);
-	assert (!_cairo_status_is_error (status));
-	status = bind_float_to_shader (setup->shader->program,
-				       "source_last_offset",
-				       setup->src.operand.linear.last_stop_offset);
-	assert (!_cairo_status_is_error (status));
-
 	break;
 
     case OPERAND_RADIAL_GRADIENT:
@@ -1661,15 +1643,6 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
 				       "source_radius_1",
 				       setup->src.operand.radial.radius_1);
 	assert (!_cairo_status_is_error (status));
-
-        status = bind_float_to_shader (setup->shader->program,
-				       "source_first_offset",
-				       setup->src.operand.radial.first_stop_offset);
-	assert (!_cairo_status_is_error (status));
-
-        status = bind_float_to_shader (setup->shader->program,
-				       "source_last_offset",
-				       setup->src.operand.radial.last_stop_offset);
 	break;
     }
 }
@@ -1737,15 +1710,6 @@ _cairo_gl_set_linear_gradient_mask_operand (cairo_gl_composite_setup_t *setup)
 			 setup->mask.operand.linear.segment_x,
 			 setup->mask.operand.linear.segment_y);
     assert (!_cairo_status_is_error (status));
-
-    status = bind_float_to_shader (setup->shader->program,
-			  "mask_first_offset",
-			  setup->mask.operand.linear.first_stop_offset);
-    assert (!_cairo_status_is_error (status));
-    status = bind_float_to_shader (setup->shader->program,
-			  "mask_last_offset",
-			  setup->mask.operand.linear.last_stop_offset);
-    assert (!_cairo_status_is_error (status));
 }
 
 static void
@@ -1779,15 +1743,6 @@ _cairo_gl_set_radial_gradient_mask_operand (cairo_gl_composite_setup_t *setup)
 				   "mask_radius_1",
 				   setup->mask.operand.radial.radius_1);
     assert (!_cairo_status_is_error (status));
-
-    status = bind_float_to_shader (setup->shader->program,
-				   "mask_first_offset",
-				   setup->mask.operand.radial.first_stop_offset);
-    assert (!_cairo_status_is_error (status));
-
-    status = bind_float_to_shader (setup->shader->program,
-				   "mask_last_offset",
-				   setup->mask.operand.radial.last_stop_offset);
 }
 
 /* This is like _cairo_gl_set_src_alpha_operand, for component alpha setup
commit f813a0243b90ea4151f60f3d13bb6c84d21270df
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Feb 17 10:58:16 2010 -0800

    gl: Remove the old unused radial/linear gradients shaders.
    
    They're dynamically generated now for source/mask.

diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 6faaffa..b02fad4 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -314,12 +314,6 @@ create_shader_program (cairo_gl_shader_program_t *program,
                        const char *fragment_text);
 
 cairo_status_t
-create_linear_gradient_shader_program (cairo_gl_shader_program_t *program);
-
-cairo_status_t
-create_radial_gradient_shader_program (cairo_gl_shader_program_t *program);
-
-cairo_status_t
 bind_float_to_shader (GLuint program, const char *name,
                       float value);
 
diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c
index 741e235..fb99efa 100644
--- a/src/cairo-gl-shaders.c
+++ b/src/cairo-gl-shaders.c
@@ -46,12 +46,6 @@ typedef struct _shader_impl {
     (*destroy_shader_program) (cairo_gl_shader_program_t *program);
 
     cairo_status_t
-    (*create_linear_gradient_shader_program) (cairo_gl_shader_program_t *program);
-
-    cairo_status_t
-    (*create_radial_gradient_shader_program) (cairo_gl_shader_program_t *program);
-
-    cairo_status_t
     (*bind_float_to_shader) (GLuint program, const char *name,
                              float value);
 
@@ -82,69 +76,6 @@ typedef struct _shader_impl {
 static const shader_impl_t*
 get_impl (void);
 
-static const char * const minimal_vert_text_110 =
-    "#version 110\n"
-    "\n"
-    "void main ()\n"
-    "{ gl_Position = ftransform(); }\n";
-
-/* This fragment shader was adapted from Argiris Kirtzidis' cairo-gral
- * library, found at git://github.com/akyrtzi/cairo-gral.git.  Argiris' shader
- * was adapted from the original algorithm in pixman.
- */
-static const char * const radial_gradient_frag_text_110 =
-    "#version 110\n"
-    "\n"
-    "uniform sampler1D tex;\n"
-    "uniform mat4 matrix;\n"
-    "uniform vec2 circle_1;\n"
-    "uniform float radius_0;\n"
-    "uniform float radius_1;\n"
-    "uniform float first_offset;\n"
-    "uniform float last_offset;\n"
-    "\n"
-    "void main ()\n"
-    "{\n"
-    "    vec2 pos = (matrix * vec4 (gl_FragCoord.xy, 0.0, 1.0)).xy;\n"
-    "    \n"
-    "    float dr = radius_1 - radius_0;\n"
-    "    float dot_circle_1 = dot (circle_1, circle_1);\n"
-    "    float dot_pos_circle_1 = dot (pos, circle_1);\n"
-    "    \n"
-    "    float A = dot_circle_1 - dr * dr;\n"
-    "    float B = -2.0 * (dot_pos_circle_1 + radius_0 * dr);\n"
-    "    float C = dot (pos, pos) - radius_0 * radius_0;\n"
-    "    float det = B * B - 4.0 * A * C;\n"
-    "    det = max (det, 0.0);\n"
-    "    \n"
-    "    float sqrt_det = sqrt (det);\n"
-    "    /* This complicated bit of logic acts as\n"
-    "     * \"if (A < 0.0) sqrt_det = -sqrt_det\", without the branch.\n"
-    "     */\n"
-    "    sqrt_det *= 1.0 + 2.0 * sign (min (A, 0.0));\n"
-    "    \n"
-    "    float t = (-B + sqrt_det) / (2.0 * A);\n"
-    "    t = (t - first_offset) / (last_offset - first_offset);\n"
-    "    gl_FragColor = texture1D (tex, t);\n"
-    "}\n";
-
-static const char * const linear_gradient_frag_text_110 =
-    "#version 110\n"
-    "\n"
-    "uniform sampler1D tex;\n"
-    "uniform mat4 matrix;\n"
-    "uniform vec2 segment;\n"
-    "uniform float first_offset;\n"
-    "uniform float last_offset;\n"
-    "\n"
-    "void main ()\n"
-    "{\n"
-    "    vec2 pos = (matrix * vec4 (gl_FragCoord.xy, 0.0, 1.0)).xy;\n"
-    "    float t = dot (pos, segment) / dot (segment, segment);\n"
-    "    t = (t - first_offset) / (last_offset - first_offset);\n"
-    "    gl_FragColor = texture1D (tex, t);\n"
-    "}\n";
-
 /* ARB_shader_objects / ARB_vertex_shader / ARB_fragment_shader extensions
    API. */
 static cairo_status_t
@@ -227,22 +158,6 @@ destroy_shader_program_arb (cairo_gl_shader_program_t *program)
 }
 
 static cairo_status_t
-create_linear_gradient_shader_program_arb (cairo_gl_shader_program_t *program)
-{
-    return create_shader_program (program,
-                                  minimal_vert_text_110,
-                                  linear_gradient_frag_text_110);
-}
-
-static cairo_status_t
-create_radial_gradient_shader_program_arb (cairo_gl_shader_program_t *program)
-{
-    return create_shader_program (program,
-                                  minimal_vert_text_110,
-                                  radial_gradient_frag_text_110);
-}
-
-static cairo_status_t
 bind_float_to_shader_arb (GLuint program, const char *name,
                                float value)
 {
@@ -401,22 +316,6 @@ destroy_shader_program_core_2_0 (cairo_gl_shader_program_t *program)
 }
 
 static cairo_status_t
-create_linear_gradient_shader_program_core_2_0 (cairo_gl_shader_program_t *program)
-{
-    return create_shader_program (program,
-                                  minimal_vert_text_110,
-                                  linear_gradient_frag_text_110);
-}
-
-static cairo_status_t
-create_radial_gradient_shader_program_core_2_0 (cairo_gl_shader_program_t *program)
-{
-    return create_shader_program (program,
-                                  minimal_vert_text_110,
-                                  radial_gradient_frag_text_110);
-}
-
-static cairo_status_t
 bind_float_to_shader_core_2_0 (GLuint program, const char *name,
                                float value)
 {
@@ -501,8 +400,6 @@ static const shader_impl_t shader_impl_core_2_0 = {
     compile_shader_core_2_0,
     link_shader_core_2_0,
     destroy_shader_program_core_2_0,
-    create_linear_gradient_shader_program_core_2_0,
-    create_radial_gradient_shader_program_core_2_0,
     bind_float_to_shader_core_2_0,
     bind_vec2_to_shader_core_2_0,
     bind_vec3_to_shader_core_2_0,
@@ -516,8 +413,6 @@ static const shader_impl_t shader_impl_arb = {
     compile_shader_arb,
     link_shader_arb,
     destroy_shader_program_arb,
-    create_linear_gradient_shader_program_arb,
-    create_radial_gradient_shader_program_arb,
     bind_float_to_shader_arb,
     bind_vec2_to_shader_arb,
     bind_vec3_to_shader_arb,
@@ -601,18 +496,6 @@ create_shader_program (cairo_gl_shader_program_t *program,
 }
 
 cairo_status_t
-create_linear_gradient_shader_program (cairo_gl_shader_program_t *program)
-{
-    return get_impl()->create_linear_gradient_shader_program(program);
-}
-
-cairo_status_t
-create_radial_gradient_shader_program (cairo_gl_shader_program_t *program)
-{
-    return get_impl()->create_radial_gradient_shader_program(program);
-}
-
-cairo_status_t
 bind_float_to_shader (GLuint program, const char *name,
                       float value)
 {
commit 8da843e996bda7152abb217b3f461a8091dbc880
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Feb 17 10:54:39 2010 -0800

    gl: Reduce complexity of radial fragment shaders.
    
    This shaves 1 Mesa IR instruction, and 6 Gen4 ISA instructions.

diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c
index 70a8c75..741e235 100644
--- a/src/cairo-gl-shaders.c
+++ b/src/cairo-gl-shaders.c
@@ -776,10 +776,7 @@ static const char *fs_source_radial_gradient =
     "    det = max (det, 0.0);\n"
     "    \n"
     "    float sqrt_det = sqrt (det);\n"
-    "    /* This complicated bit of logic acts as\n"
-    "     * \"if (A < 0.0) sqrt_det = -sqrt_det\", without the branch.\n"
-    "     */\n"
-    "    sqrt_det *= 1.0 + 2.0 * sign (min (A, 0.0));\n"
+    "    sqrt_det *= sign(A);\n"
     "    \n"
     "    float t = (-B + sqrt_det) / (2.0 * A);\n"
     "    t = (t - source_first_offset) / (source_last_offset - source_first_offset);\n"
@@ -857,10 +854,7 @@ static const char *fs_mask_radial_gradient =
     "    det = max (det, 0.0);\n"
     "    \n"
     "    float sqrt_det = sqrt (det);\n"
-    "    /* This complicated bit of logic acts as\n"
-    "     * \"if (A < 0.0) sqrt_det = -sqrt_det\", without the branch.\n"
-    "     */\n"
-    "    sqrt_det *= 1.0 + 2.0 * sign (min (A, 0.0));\n"
+    "    sqrt_det *= sign(A);\n"
     "    \n"
     "    float t = (-B + sqrt_det) / (2.0 * A);\n"
     "    t = (t - mask_first_offset) / (mask_last_offset - mask_first_offset);\n"


More information about the cairo-commit mailing list