1 /*
2  * Copyright © 2006 Eric Anholt
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of Eric Anholt not be used in
9  * advertising or publicity pertaining to distribution of the software without
10  * specific, written prior permission.  Eric Anholt makes no
11  * representations about the suitability of this software for any purpose.  It
12  * is provided "as is" without express or implied warranty.
13  *
14  * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL ERIC ANHOLT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "rendercheck.h"
28 
29 static int
expecting_error(Display * dpy,XErrorEvent * event)30 expecting_error(Display *dpy, XErrorEvent *event)
31 {
32     return TRUE;
33 }
34 
35 /**
36  * Check SetPictureTransform on a source picture causing a crash.
37  */
38 static Bool
bug7366_test_set_picture_transform(Display * dpy)39 bug7366_test_set_picture_transform(Display *dpy)
40 {
41     Picture source_pict;
42     XRenderColor color;
43     XTransform transform;
44 
45     memset(&color, 0, sizeof(color));
46     source_pict = XRenderCreateSolidFill(dpy, &color);
47 
48     memset(&transform, 0, sizeof(transform));
49     XRenderSetPictureTransform(dpy, source_pict, &transform);
50 
51     XSync(dpy, FALSE);
52 
53     XRenderFreePicture(dpy, source_pict);
54 
55     return TRUE;
56 }
57 
58 /**
59  * Check setting of AlphaMap to a source picture causing a crash.
60  */
61 static Bool
bug7366_test_set_alpha_map(Display * dpy)62 bug7366_test_set_alpha_map(Display *dpy)
63 {
64     Picture source_pict, pict;
65     XRenderColor color;
66     Drawable pixmap;
67     XRenderPictureAttributes pa;
68 
69     memset(&color, 0, sizeof(color));
70     source_pict = XRenderCreateSolidFill(dpy, &color);
71 
72     pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), 1, 1, 32);
73     pict = XRenderCreatePicture(dpy, pixmap,
74         XRenderFindStandardFormat(dpy, PictStandardARGB32), 0, NULL);
75 
76     XSetErrorHandler(expecting_error);
77     pa.alpha_map = source_pict;
78     XRenderChangePicture(dpy, pict, CPAlphaMap, &pa);
79     XSync(dpy, FALSE);
80     XSetErrorHandler(NULL);
81 
82     XFreePixmap(dpy, pixmap);
83     XRenderFreePicture(dpy, pict);
84     XRenderFreePicture(dpy, source_pict);
85 
86     return TRUE;
87 }
88 
89 /**
90  * Check SetPictureClipRectangles on a source potentially causing a crash.
91  */
92 static Bool
bug7366_test_set_picture_clip_rectangles(Display * dpy)93 bug7366_test_set_picture_clip_rectangles(Display *dpy)
94 {
95     Picture source_pict;
96     XRenderColor color;
97     XRectangle rectangle;
98 
99     memset(&color, 0, sizeof(color));
100     source_pict = XRenderCreateSolidFill(dpy, &color);
101 
102     memset(&rectangle, 0, sizeof(rectangle));
103     XSetErrorHandler(expecting_error);
104     XRenderSetPictureClipRectangles(dpy, source_pict, 0, 0, &rectangle, 1);
105     XSync(dpy, FALSE);
106     XSetErrorHandler(NULL);
107 
108     XRenderFreePicture(dpy, source_pict);
109 
110     return TRUE;
111 }
112 
113 /**
114  * Check SetPictureFilter on a source potentially causing a crash.
115  */
116 static Bool
bug7366_test_set_picture_filter(Display * dpy)117 bug7366_test_set_picture_filter(Display *dpy)
118 {
119     Picture source_pict;
120     XRenderColor color;
121 
122     memset(&color, 0, sizeof(color));
123     source_pict = XRenderCreateSolidFill(dpy, &color);
124 
125     XRenderSetPictureFilter(dpy, source_pict, "bilinear", NULL, 0);
126     XSync(dpy, FALSE);
127     XSetErrorHandler(NULL);
128 
129     XRenderFreePicture(dpy, source_pict);
130 
131     return TRUE;
132 }
133 
134 Bool
bug7366_test(Display * dpy)135 bug7366_test(Display *dpy)
136 {
137     int maj, min;
138 
139     /* Make sure we actually have gradients available */
140     XRenderQueryVersion(dpy, &maj, &min);
141     if (maj != 0 || min < 10)
142 	return TRUE;
143 
144     bug7366_test_set_picture_transform(dpy);
145     bug7366_test_set_alpha_map(dpy);
146     bug7366_test_set_picture_clip_rectangles(dpy);
147     bug7366_test_set_picture_filter(dpy);
148 
149     /* If the server isn't gone, then we've succeeded. */
150     return TRUE;
151 }
152