1
/*
2
 * Copyright © 2008 Red Hat, Inc.
3
 *
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:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
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
22
 * SOFTWARE.
23
 *
24
 * Author: Carl D. Worth <cworth@cworth.org>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
#include "cairo-xlib.h"
30
#include "cairo-xlib-xrender.h"
31

            
32
#include "cairo-boilerplate-xlib.h"
33

            
34
static cairo_test_status_t
35
1
preamble (cairo_test_context_t *ctx)
36
{
37
    Display *dpy;
38
    XRenderPictFormat *orig_format, *format;
39
    cairo_surface_t *surface;
40
    Pixmap pixmap;
41
    int screen;
42
    cairo_test_status_t result;
43

            
44
1
    result = CAIRO_TEST_UNTESTED;
45

            
46
1
    if (! cairo_test_is_target_enabled (ctx, "xlib"))
47
1
	goto CLEANUP_TEST;
48

            
49
    dpy = XOpenDisplay (NULL);
50
    if (! dpy) {
51
	cairo_test_log (ctx, "Error: Cannot open display: %s, skipping.\n",
52
			XDisplayName (NULL));
53
	goto CLEANUP_TEST;
54
    }
55

            
56
    result = CAIRO_TEST_FAILURE;
57

            
58
    screen = DefaultScreen (dpy);
59

            
60
    cairo_test_log (ctx, "Testing with image surface.\n");
61

            
62
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
63

            
64
    format = cairo_xlib_surface_get_xrender_format (surface);
65
    if (format != NULL) {
66
	cairo_test_log (ctx, "Error: expected NULL for image surface\n");
67
	goto CLEANUP_SURFACE;
68
    }
69

            
70
    cairo_surface_destroy (surface);
71

            
72
    cairo_test_log (ctx, "Testing with non-xrender xlib surface.\n");
73

            
74
    pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
75
			    1, 1, DefaultDepth (dpy, screen));
76
    surface = cairo_xlib_surface_create (dpy, pixmap,
77
					 DefaultVisual (dpy, screen),
78
					 1, 1);
79
    orig_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
80
    format = cairo_xlib_surface_get_xrender_format (surface);
81
    if (format != orig_format) {
82
	cairo_test_log (ctx, "Error: did not receive the same format as XRenderFindVisualFormat\n");
83
	goto CLEANUP_PIXMAP;
84
    }
85
    cairo_surface_destroy (surface);
86
    XFreePixmap (dpy, pixmap);
87

            
88
    cairo_test_log (ctx, "Testing with xlib xrender surface.\n");
89

            
90
    orig_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
91
    pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
92
			    1, 1, 32);
93
    surface = cairo_xlib_surface_create_with_xrender_format (dpy,
94
							     pixmap,
95
							     DefaultScreenOfDisplay (dpy),
96
							     orig_format,
97
							     1, 1);
98
    format = cairo_xlib_surface_get_xrender_format (surface);
99
    if (format != orig_format) {
100
	cairo_test_log (ctx, "Error: did not receive the same format originally set\n");
101
	goto CLEANUP_PIXMAP;
102
    }
103

            
104
    result = CAIRO_TEST_SUCCESS;
105

            
106
  CLEANUP_PIXMAP:
107
    XFreePixmap (dpy, pixmap);
108
  CLEANUP_SURFACE:
109
    cairo_surface_destroy (surface);
110

            
111
    XCloseDisplay (dpy);
112

            
113
1
  CLEANUP_TEST:
114
1
    return result;
115
}
116

            
117
1
CAIRO_TEST (get_xrender_format,
118
	    "Check XRender specific API",
119
	    "xrender, api", /* keywords */
120
	    NULL, /* requirements */
121
	    0, 0,
122
	    preamble, NULL)