[test] Add test case for a leaky dashed rectangle.
[cairo/haiku.git] / test / glitz-surface-source.c
blob2dfa7355a6551073436f80f0688c662865239a82
1 /*
2 * Copyright © 2008 Chris Wilson
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Chris Wilson not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Chris Wilson makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Chris Wilson <chris@chris-wilson.co.uk>
26 #include "cairo-test.h"
27 #include <cairo-glitz.h>
28 #include <cairo-xlib.h>
29 #include <cairo-xlib-xrender.h>
31 #define NAME "glitz"
32 #include "surface-source.c"
34 static cairo_user_data_key_t closure_key;
36 #if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
37 #include <glitz-glx.h>
39 struct closure {
40 Display *dpy;
41 Window win;
44 static void
45 cleanup (void *data)
47 struct closure *closure = data;
49 glitz_glx_fini ();
51 if (closure->win)
52 XDestroyWindow (closure->dpy, closure->win);
54 XCloseDisplay (closure->dpy);
56 free (closure);
59 static glitz_surface_t *
60 _glitz_glx_create_surface (glitz_format_name_t formatname,
61 int width,
62 int height,
63 struct closure *closure)
65 Display * dpy = closure->dpy;
66 int scr = DefaultScreen(dpy);
67 glitz_drawable_format_t templ;
68 glitz_drawable_format_t * dformat = NULL;
69 unsigned long mask;
70 glitz_drawable_t * drawable = NULL;
71 glitz_format_t * format;
72 glitz_surface_t * sr;
74 XSizeHints xsh;
75 XSetWindowAttributes xswa;
76 XVisualInfo * vinfo;
78 memset(&templ, 0, sizeof(templ));
79 templ.color.red_size = 8;
80 templ.color.green_size = 8;
81 templ.color.blue_size = 8;
82 templ.color.alpha_size = 8;
83 templ.color.fourcc = GLITZ_FOURCC_RGB;
84 templ.samples = 1;
86 glitz_glx_init (NULL);
88 mask = GLITZ_FORMAT_SAMPLES_MASK |
89 GLITZ_FORMAT_FOURCC_MASK |
90 GLITZ_FORMAT_RED_SIZE_MASK |
91 GLITZ_FORMAT_GREEN_SIZE_MASK |
92 GLITZ_FORMAT_BLUE_SIZE_MASK;
93 if (formatname == GLITZ_STANDARD_ARGB32)
94 mask |= GLITZ_FORMAT_ALPHA_SIZE_MASK;
96 /* Try for a pbuffer first */
97 if (!getenv("CAIRO_TEST_FORCE_GLITZ_WINDOW"))
98 dformat = glitz_glx_find_pbuffer_format (dpy, scr, mask, &templ, 0);
100 if (dformat) {
101 closure->win = None;
103 drawable = glitz_glx_create_pbuffer_drawable (dpy, scr, dformat,
104 width, height);
105 if (!drawable)
106 goto FAIL;
107 } else {
108 /* No pbuffer, try window */
109 dformat = glitz_glx_find_window_format (dpy, scr, mask, &templ, 0);
111 if (!dformat)
112 goto FAIL;
114 vinfo = glitz_glx_get_visual_info_from_format(dpy,
115 DefaultScreen(dpy),
116 dformat);
118 if (!vinfo)
119 goto FAIL;
121 xsh.flags = PSize;
122 xsh.x = 0;
123 xsh.y = 0;
124 xsh.width = width;
125 xsh.height = height;
127 xswa.colormap = XCreateColormap (dpy, RootWindow(dpy, scr),
128 vinfo->visual, AllocNone);
129 closure->win = XCreateWindow (dpy, RootWindow(dpy, scr),
130 xsh.x, xsh.y, xsh.width, xsh.height,
131 0, vinfo->depth, CopyFromParent,
132 vinfo->visual, CWColormap, &xswa);
133 XFree (vinfo);
135 drawable =
136 glitz_glx_create_drawable_for_window (dpy, scr,
137 dformat, closure->win,
138 width, height);
140 if (!drawable)
141 goto DESTROY_WINDOW;
144 format = glitz_find_standard_format (drawable, formatname);
145 if (!format)
146 goto DESTROY_DRAWABLE;
148 sr = glitz_surface_create (drawable, format, width, height, 0, NULL);
149 if (!sr)
150 goto DESTROY_DRAWABLE;
152 if (closure->win == None || dformat->doublebuffer) {
153 glitz_surface_attach (sr, drawable, GLITZ_DRAWABLE_BUFFER_BACK_COLOR);
154 } else {
155 XMapWindow (closure->dpy, closure->win);
156 glitz_surface_attach (sr, drawable, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
159 glitz_drawable_destroy (drawable);
161 return sr;
162 DESTROY_DRAWABLE:
163 glitz_drawable_destroy (drawable);
164 DESTROY_WINDOW:
165 if (closure->win)
166 XDestroyWindow (dpy, closure->win);
167 FAIL:
168 return NULL;
171 static cairo_surface_t *
172 create_source_surface (int size)
174 struct closure *closure;
175 glitz_surface_t *glitz_surface;
176 cairo_surface_t *surface;
178 closure = xcalloc (1, sizeof (struct closure));
180 closure->dpy = XOpenDisplay (getenv("CAIRO_TEST_GLITZ_DISPLAY"));
181 if (closure->dpy == NULL) {
182 free (closure);
183 return NULL;
186 glitz_surface = _glitz_glx_create_surface (GLITZ_STANDARD_ARGB32,
187 size, size,
188 closure);
189 if (glitz_surface == NULL) {
190 XCloseDisplay (closure->dpy);
191 free (closure);
192 return NULL;
195 surface = cairo_glitz_surface_create (glitz_surface);
197 cairo_surface_set_user_data (surface, &closure_key, closure, cleanup);
199 return surface;
201 #endif