summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2010-05-06 14:38:55 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2010-05-06 14:38:55 +0100
commit2e3acee410ff127d4557ca8191625338cd225313 (patch)
treeb9fd90f4d9b224db950e1da3b566eb14f175f853
parent75d8550891b8b2c09200aaaa812c6c9332161cd7 (diff)
test: Add gl-surface-source
Exercise using GL sources.
-rw-r--r--test/Makefile.am7
-rw-r--r--test/Makefile.sources3
-rw-r--r--test/gl-surface-source.argb32.ref.pngbin0 -> 377 bytes
-rw-r--r--test/gl-surface-source.c115
-rw-r--r--test/gl-surface-source.image16.ref.pngbin0 -> 305 bytes
-rw-r--r--test/gl-surface-source.rgb24.ref.pngbin0 -> 301 bytes
6 files changed, 125 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 72023a0c..0b9eb7ea 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -16,6 +16,10 @@ test_sources += $(ft_font_test_sources)
endif
endif
+if CAIRO_HAS_GL_SURFACE
+test_sources += $(gl_surface_test_sources)
+endif
+
# Need to add quartz-surface-source
if CAIRO_HAS_QUARTZ_SURFACE
test_sources += $(quartz_surface_test_sources)
@@ -591,6 +595,9 @@ REFERENCE_IMAGES = \
ft-text-vertical-layout-type3.svg.ref.png \
ft-text-vertical-layout-type3.xlib.ref.png \
get-group-target.ref.png \
+ gl-surface-source.rgb24.ref.png \
+ gl-surface-source.argb32.ref.png \
+ gl-surface-source.image16.ref.png \
glyph-cache-pressure.image16.ref.png \
glyph-cache-pressure.ps2.ref.png \
glyph-cache-pressure.ps3.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 01043c66..1464516c 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -286,6 +286,9 @@ ft_font_test_sources = \
ft-text-vertical-layout-type3.c \
ft-text-antialias-none.c
+gl_surface_test_sources = \
+ gl-surface-source.c
+
quartz_surface_test_sources = quartz-surface-source.c
pdf_surface_test_sources = \
diff --git a/test/gl-surface-source.argb32.ref.png b/test/gl-surface-source.argb32.ref.png
new file mode 100644
index 00000000..01829720
--- /dev/null
+++ b/test/gl-surface-source.argb32.ref.png
Binary files differ
diff --git a/test/gl-surface-source.c b/test/gl-surface-source.c
new file mode 100644
index 00000000..60f85914
--- /dev/null
+++ b/test/gl-surface-source.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2008 Chris Wilson
+ * Copyright © 2010 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
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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: Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+#include <cairo-gl.h>
+
+#include "surface-source.c"
+
+struct closure {
+ Display *dpy;
+ GLXContext ctx;
+
+ cairo_device_t *device;
+};
+
+static void
+cleanup (void *data)
+{
+ struct closure *arg = data;
+
+ cairo_device_finish (arg->device);
+ cairo_device_destroy (arg->device);
+
+ glXDestroyContext (arg->dpy, arg->ctx);
+ XCloseDisplay (arg->dpy);
+
+ free (arg);
+}
+
+static cairo_surface_t *
+create_source_surface (int size)
+{
+ int rgba_attribs[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_ALPHA_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None
+ };
+ XVisualInfo *visinfo;
+ GLXContext ctx;
+ struct closure *arg;
+ cairo_surface_t *surface;
+ Display *dpy;
+
+ dpy = XOpenDisplay (NULL);
+ if (dpy == NULL)
+ return NULL;
+
+ visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs);
+ if (visinfo == NULL) {
+ XCloseDisplay (dpy);
+ return NULL;
+ }
+
+ ctx = glXCreateContext (dpy, visinfo, NULL, True);
+ XFree (visinfo);
+
+ if (ctx == NULL) {
+ XCloseDisplay (dpy);
+ return NULL;
+ }
+
+ arg = xmalloc (sizeof (struct closure));
+ arg->dpy = dpy;
+ arg->ctx = ctx;
+ arg->device = cairo_glx_device_create (dpy, ctx);
+ surface = cairo_gl_surface_create (arg->device,
+ CAIRO_CONTENT_COLOR_ALPHA,
+ size, size);
+
+ if (cairo_surface_set_user_data (surface,
+ (cairo_user_data_key_t *) create_source_surface,
+ arg,
+ cleanup))
+ {
+ cairo_surface_destroy (surface);
+ cleanup (arg);
+ return NULL;
+ }
+
+ return surface;
+}
+
+CAIRO_TEST (gl_surface_source,
+ "Test using a GL surface as the source",
+ "source", /* keywords */
+ NULL, /* requirements */
+ SIZE, SIZE,
+ preamble, draw)
diff --git a/test/gl-surface-source.image16.ref.png b/test/gl-surface-source.image16.ref.png
new file mode 100644
index 00000000..2a7460e2
--- /dev/null
+++ b/test/gl-surface-source.image16.ref.png
Binary files differ
diff --git a/test/gl-surface-source.rgb24.ref.png b/test/gl-surface-source.rgb24.ref.png
new file mode 100644
index 00000000..0d68a82c
--- /dev/null
+++ b/test/gl-surface-source.rgb24.ref.png
Binary files differ