2 * Copyright © 2008 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-test.h"
29 #include "cairo-xlib.h"
30 #include "cairo-xlib-xrender.h"
32 #include "cairo-boilerplate-xlib.h"
38 XRenderPictFormat
*orig_format
, *format
;
39 cairo_surface_t
*surface
;
43 cairo_test_init ("get-xrender-format");
45 dpy
= XOpenDisplay (NULL
);
47 cairo_test_log ("Error: Cannot open display: %s.\n",
50 return CAIRO_TEST_UNTESTED
;
53 screen
= DefaultScreen (dpy
);
55 cairo_test_log ("Testing with image surface.\n");
57 surface
= cairo_image_surface_create (CAIRO_FORMAT_ARGB32
, 1, 1);
59 format
= cairo_xlib_surface_get_xrender_format (surface
);
61 cairo_test_log ("Error: expected NULL for image surface\n");
62 return CAIRO_TEST_FAILURE
;
65 cairo_surface_destroy (surface
);
67 cairo_test_log ("Testing with non-xrender xlib surface.\n");
69 pixmap
= XCreatePixmap (dpy
, DefaultRootWindow (dpy
),
70 1, 1, DefaultDepth (dpy
, screen
));
71 surface
= cairo_xlib_surface_create (dpy
, pixmap
,
72 DefaultVisual (dpy
, screen
),
74 orig_format
= XRenderFindVisualFormat (dpy
, DefaultVisual (dpy
, screen
));
75 format
= cairo_xlib_surface_get_xrender_format (surface
);
76 if (format
!= orig_format
) {
77 cairo_test_log ("Error: did not receive the same format as XRenderFindVisualFormat\n");
78 return CAIRO_TEST_FAILURE
;
80 cairo_surface_destroy (surface
);
81 XFreePixmap (dpy
, pixmap
);
83 cairo_test_log ("Testing with xlib xrender surface.\n");
85 orig_format
= XRenderFindStandardFormat (dpy
, PictStandardARGB32
);
86 pixmap
= XCreatePixmap (dpy
, DefaultRootWindow (dpy
),
88 surface
= cairo_xlib_surface_create_with_xrender_format (dpy
,
90 DefaultScreenOfDisplay (dpy
),
93 format
= cairo_xlib_surface_get_xrender_format (surface
);
94 if (format
!= orig_format
) {
95 cairo_test_log ("Error: did not receive the same format originally set\n");
96 return CAIRO_TEST_FAILURE
;
99 cairo_test_log ("Testing without the X Render extension.\n");
101 cairo_boilerplate_xlib_surface_disable_render (surface
);
103 format
= cairo_xlib_surface_get_xrender_format (surface
);
104 if (format
!= NULL
) {
105 cairo_test_log ("Error: did not receive a NULL format as expected\n");
106 return CAIRO_TEST_FAILURE
;
109 cairo_surface_destroy (surface
);
113 cairo_debug_reset_static_data ();
117 return CAIRO_TEST_SUCCESS
;