1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Copyright © 2008 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Author: Carl D. Worth <cworth@cworth.org>
*/
#include "cairo-test.h"
#include "cairo-xlib.h"
#include "cairo-xlib-xrender.h"
#include "cairo-boilerplate-xlib.h"
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
Display *dpy;
XRenderPictFormat *orig_format, *format;
cairo_surface_t *surface;
Pixmap pixmap;
int screen;
cairo_test_status_t result;
result = CAIRO_TEST_UNTESTED;
if (! cairo_test_is_target_enabled (ctx, "xlib"))
goto CLEANUP_TEST;
dpy = XOpenDisplay (NULL);
if (! dpy) {
cairo_test_log (ctx, "Error: Cannot open display: %s, skipping.\n",
XDisplayName (NULL));
goto CLEANUP_TEST;
}
result = CAIRO_TEST_FAILURE;
screen = DefaultScreen (dpy);
cairo_test_log (ctx, "Testing with image surface.\n");
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
format = cairo_xlib_surface_get_xrender_format (surface);
if (format != NULL) {
cairo_test_log (ctx, "Error: expected NULL for image surface\n");
goto CLEANUP_SURFACE;
}
cairo_surface_destroy (surface);
cairo_test_log (ctx, "Testing with non-xrender xlib surface.\n");
pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
1, 1, DefaultDepth (dpy, screen));
surface = cairo_xlib_surface_create (dpy, pixmap,
DefaultVisual (dpy, screen),
1, 1);
orig_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
format = cairo_xlib_surface_get_xrender_format (surface);
if (format != orig_format) {
cairo_test_log (ctx, "Error: did not receive the same format as XRenderFindVisualFormat\n");
goto CLEANUP_PIXMAP;
}
cairo_surface_destroy (surface);
XFreePixmap (dpy, pixmap);
cairo_test_log (ctx, "Testing with xlib xrender surface.\n");
orig_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
1, 1, 32);
surface = cairo_xlib_surface_create_with_xrender_format (dpy,
pixmap,
DefaultScreenOfDisplay (dpy),
orig_format,
1, 1);
format = cairo_xlib_surface_get_xrender_format (surface);
if (format != orig_format) {
cairo_test_log (ctx, "Error: did not receive the same format originally set\n");
goto CLEANUP_PIXMAP;
}
cairo_test_log (ctx, "Testing without the X Render extension.\n");
cairo_boilerplate_xlib_surface_disable_render (surface);
format = cairo_xlib_surface_get_xrender_format (surface);
if (format != NULL) {
cairo_test_log (ctx, "Error: did not receive a NULL format as expected\n");
goto CLEANUP_PIXMAP;
}
result = CAIRO_TEST_SUCCESS;
CLEANUP_PIXMAP:
XFreePixmap (dpy, pixmap);
CLEANUP_SURFACE:
cairo_surface_destroy (surface);
XCloseDisplay (dpy);
CLEANUP_TEST:
return result;
}
CAIRO_TEST (get_xrender_format,
"Check XRender specific API",
"xrender, api", /* keywords */
NULL, /* requirements */
0, 0,
preamble, NULL)
|