mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-01 06:48:01 +02:00
test: Add gl-surface-source
Exercise using GL sources.
This commit is contained in:
parent
75d8550891
commit
2e3acee410
6 changed files with 125 additions and 0 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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 = \
|
||||
|
|
|
|||
BIN
test/gl-surface-source.argb32.ref.png
Normal file
BIN
test/gl-surface-source.argb32.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 377 B |
115
test/gl-surface-source.c
Normal file
115
test/gl-surface-source.c
Normal file
|
|
@ -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)
|
||||
BIN
test/gl-surface-source.image16.ref.png
Normal file
BIN
test/gl-surface-source.image16.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 305 B |
BIN
test/gl-surface-source.rgb24.ref.png
Normal file
BIN
test/gl-surface-source.rgb24.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 301 B |
Loading…
Add table
Reference in a new issue