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>
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>
47 struct closure
*closure
= data
;
52 XDestroyWindow (closure
->dpy
, closure
->win
);
54 XCloseDisplay (closure
->dpy
);
59 static glitz_surface_t
*
60 _glitz_glx_create_surface (glitz_format_name_t formatname
,
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
;
70 glitz_drawable_t
* drawable
= NULL
;
71 glitz_format_t
* format
;
75 XSetWindowAttributes xswa
;
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
;
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);
103 drawable
= glitz_glx_create_pbuffer_drawable (dpy
, scr
, dformat
,
108 /* No pbuffer, try window */
109 dformat
= glitz_glx_find_window_format (dpy
, scr
, mask
, &templ
, 0);
114 vinfo
= glitz_glx_get_visual_info_from_format(dpy
,
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
);
136 glitz_glx_create_drawable_for_window (dpy
, scr
,
137 dformat
, closure
->win
,
144 format
= glitz_find_standard_format (drawable
, formatname
);
146 goto DESTROY_DRAWABLE
;
148 sr
= glitz_surface_create (drawable
, format
, width
, height
, 0, NULL
);
150 goto DESTROY_DRAWABLE
;
152 if (closure
->win
== None
|| dformat
->doublebuffer
) {
153 glitz_surface_attach (sr
, drawable
, GLITZ_DRAWABLE_BUFFER_BACK_COLOR
);
155 XMapWindow (closure
->dpy
, closure
->win
);
156 glitz_surface_attach (sr
, drawable
, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR
);
159 glitz_drawable_destroy (drawable
);
163 glitz_drawable_destroy (drawable
);
166 XDestroyWindow (dpy
, closure
->win
);
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
) {
186 glitz_surface
= _glitz_glx_create_surface (GLITZ_STANDARD_ARGB32
,
189 if (glitz_surface
== NULL
) {
190 XCloseDisplay (closure
->dpy
);
195 surface
= cairo_glitz_surface_create (glitz_surface
);
197 cairo_surface_set_user_data (surface
, &closure_key
, closure
, cleanup
);