[cairo-commit] 2 commits - src/cairo-gl-surface.c src/cairo-glx-context.c test/Makefile.am test/Makefile.sources test/push-group-color.c test/push-group-color.ref.png test/push-group-color.xlib.ref.png
Chris Wilson
ickle at kemper.freedesktop.org
Tue Sep 22 07:48:32 PDT 2009
src/cairo-gl-surface.c | 8 ++
src/cairo-glx-context.c | 7 +
test/Makefile.am | 2
test/Makefile.sources | 1
test/push-group-color.c | 141 +++++++++++++++++++++++++++++++++++++
test/push-group-color.ref.png |binary
test/push-group-color.xlib.ref.png |binary
7 files changed, 156 insertions(+), 3 deletions(-)
New commits:
commit 941d3693fac831c4ce8c61cbac7c77b566b97611
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Sep 22 14:43:45 2009 +0100
[test] Exercise push-group-color.
Hunting for a known bug in the xlib backend where it invalidly converts
an argb32 source to rgb24. However, this does not appear to be that bug,
but still a useful exercise nevertheless.
diff --git a/test/Makefile.am b/test/Makefile.am
index 2a01270..0428052 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -759,6 +759,8 @@ REFERENCE_IMAGES = \
push-group.rgb24.ref.png \
push-group.xlib.ref.png \
push-group.xlib.rgb24.ref.png \
+ push-group-color.ref.png \
+ push-group-color.xlib.ref.png \
quartz-surface-source.ps2.ref.png \
quartz-surface-source.ps3.ref.png \
quartz-surface-source.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 04a0110..4f3ecea 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -156,6 +156,7 @@ test_sources = \
pixman-rotate.c \
png.c \
push-group.c \
+ push-group-color.c \
radial-gradient.c \
random-intersections-eo.c \
random-intersections-nonzero.c \
diff --git a/test/push-group-color.c b/test/push-group-color.c
new file mode 100644
index 0000000..1bc5bca
--- /dev/null
+++ b/test/push-group-color.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright © 2005 Mozilla Corporation
+ * Copyright © 2009 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Mozilla Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Mozilla Corporation makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Vladimir Vukicevic <vladimir at pobox.com>
+ * Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+#define UNIT_SIZE 100
+#define PAD 5
+#define INNER_PAD 10
+
+#define WIDTH (UNIT_SIZE + PAD) + PAD
+#define HEIGHT (UNIT_SIZE + PAD) + PAD
+
+static cairo_pattern_t *
+argb32_source (void)
+{
+ cairo_surface_t *surface;
+ cairo_pattern_t *pattern;
+ cairo_t *cr;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 16, 16);
+ cr = cairo_create (surface);
+ cairo_surface_destroy (surface);
+
+ cairo_set_source_rgb (cr, 1, 0, 0);
+ cairo_rectangle (cr, 8, 0, 8, 8);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 0, 1, 0);
+ cairo_rectangle (cr, 0, 8, 8, 8);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 0, 0, 1);
+ cairo_rectangle (cr, 8, 8, 8, 8);
+ cairo_fill (cr);
+
+ pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
+ cairo_destroy (cr);
+
+ return pattern;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ cairo_pattern_t *gradient, *image;
+
+ cairo_set_source_rgb (cr, 1,1,1);
+ cairo_paint (cr);
+
+ cairo_translate (cr, PAD, PAD);
+
+ /* clip to the unit size */
+ cairo_rectangle (cr, 0, 0,
+ UNIT_SIZE, UNIT_SIZE);
+ cairo_clip (cr);
+
+ cairo_rectangle (cr, 0, 0,
+ UNIT_SIZE, UNIT_SIZE);
+ cairo_set_source_rgba (cr, 0, 0, 0, 1);
+ cairo_set_line_width (cr, 2);
+ cairo_stroke (cr);
+
+ /* start a group */
+ cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR);
+
+ /* draw a gradient background */
+ cairo_save (cr);
+ cairo_translate (cr, INNER_PAD, INNER_PAD);
+ cairo_new_path (cr);
+ cairo_rectangle (cr, 0, 0,
+ UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
+ gradient = cairo_pattern_create_linear (UNIT_SIZE - (INNER_PAD*2), 0,
+ UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
+ cairo_pattern_add_color_stop_rgba (gradient, 0.0, 0.3, 0.3, 0.3, 1.0);
+ cairo_pattern_add_color_stop_rgba (gradient, 1.0, 1.0, 1.0, 1.0, 1.0);
+ cairo_set_source (cr, gradient);
+ cairo_pattern_destroy (gradient);
+ cairo_fill (cr);
+ cairo_restore (cr);
+
+ /* draw diamond */
+ cairo_move_to (cr, UNIT_SIZE / 2, 0);
+ cairo_line_to (cr, UNIT_SIZE , UNIT_SIZE / 2);
+ cairo_line_to (cr, UNIT_SIZE / 2, UNIT_SIZE);
+ cairo_line_to (cr, 0 , UNIT_SIZE / 2);
+ cairo_close_path (cr);
+ cairo_set_source_rgba (cr, 0, 0, 1, 1);
+ cairo_fill (cr);
+
+ /* draw circle */
+ cairo_arc (cr,
+ UNIT_SIZE / 2, UNIT_SIZE / 2,
+ UNIT_SIZE / 3.5,
+ 0, M_PI * 2);
+ cairo_set_source_rgba (cr, 1, 0, 0, 1);
+ cairo_fill (cr);
+
+ /* and put the image on top */
+ cairo_translate (cr, UNIT_SIZE/2 - 8, UNIT_SIZE/2 - 8);
+ image = argb32_source ();
+ cairo_set_source (cr, image);
+ cairo_pattern_destroy (image);
+ cairo_paint (cr);
+
+ cairo_pop_group_to_source (cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (cr);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (push_group_color,
+ "Verify that cairo_push_group_with_content works.",
+ "group", /* keywords */
+ NULL, /* requirements */
+ WIDTH, HEIGHT,
+ NULL, draw)
diff --git a/test/push-group-color.ref.png b/test/push-group-color.ref.png
new file mode 100644
index 0000000..c270bde
Binary files /dev/null and b/test/push-group-color.ref.png differ
diff --git a/test/push-group-color.xlib.ref.png b/test/push-group-color.xlib.ref.png
new file mode 100644
index 0000000..e245e4d
Binary files /dev/null and b/test/push-group-color.xlib.ref.png differ
commit 30f45ce5f7d639dd5a0b60f544b3535e3bc2105d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Sep 22 15:15:47 2009 +0100
[gl] Handle an absent visual.
If we cannot find the correct visual for the fbconfig, return an error
instead of crashing. The difference is subtle, granted.
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index e73646a..17bf4bc 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -61,6 +61,11 @@ static const cairo_gl_context_t _nil_context = {
CAIRO_STATUS_NO_MEMORY
};
+static const cairo_gl_context_t _nil_context__invalid_format = {
+ CAIRO_REFERENCE_COUNT_INVALID,
+ CAIRO_STATUS_INVALID_FORMAT
+};
+
static cairo_bool_t _cairo_surface_is_gl (cairo_surface_t *surface)
{
return surface->backend == &_cairo_gl_surface_backend;
@@ -72,6 +77,9 @@ _cairo_gl_context_create_in_error (cairo_status_t status)
if (status == CAIRO_STATUS_NO_MEMORY)
return (cairo_gl_context_t *) &_nil_context;
+ if (status == CAIRO_STATUS_INVALID_FORMAT)
+ return (cairo_gl_context_t *) &_nil_context__invalid_format;
+
ASSERT_NOT_REACHED;
return NULL;
}
diff --git a/src/cairo-glx-context.c b/src/cairo-glx-context.c
index 18fe229..b442a1f 100644
--- a/src/cairo-glx-context.c
+++ b/src/cairo-glx-context.c
@@ -99,8 +99,6 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy)
Window win = None;
int cnt;
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
-
/* Create a dummy window created for the target GLX context that we can
* use to query the available GL/GLX extensions.
*/
@@ -114,6 +112,9 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy)
vi = glXGetVisualFromFBConfig (dpy, config[0]);
XFree (config);
+ if (unlikely (vi == NULL))
+ return _cairo_error (CAIRO_STATUS_INVALID_FORMAT);
+
cmap = XCreateColormap (dpy,
RootWindow (dpy, vi->screen),
vi->visual,
@@ -136,7 +137,7 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy)
}
*dummy = win;
- return status;
+ return CAIRO_STATUS_SUCCESS;
}
cairo_gl_context_t *
More information about the cairo-commit
mailing list