Debian Codegraph @

src/Picture.c

raw
1 /*
2 *
3 * Copyright © 2000 SuSE, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of SuSE not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. SuSE makes no representations about the
12 * suitability of this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
14 *
15 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
17 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Author: Keith Packard, SuSE, Inc.
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 #include "Xrenderint.h"
29 #include <X11/Xregion.h>
30
31 static void
32 _XRenderProcessPictureAttributes (Display *dpy,
33 xRenderChangePictureReq *req,
34 unsigned long valuemask,
35 _Xconst XRenderPictureAttributes *attributes)
36 {
37 unsigned long values[32];
38 register unsigned long *value = values;
39 unsigned int nvalues;
40
41 if (valuemask & CPRepeat)
42 *value++ = (unsigned long) attributes->repeat;
43 if (valuemask & CPAlphaMap)
44 *value++ = attributes->alpha_map;
45 if (valuemask & CPAlphaXOrigin)
46 *value++ = (unsigned long) attributes->alpha_x_origin;
47 if (valuemask & CPAlphaYOrigin)
48 *value++ = (unsigned long) attributes->alpha_y_origin;
49 if (valuemask & CPClipXOrigin)
50 *value++ = (unsigned long) attributes->clip_x_origin;
51 if (valuemask & CPClipYOrigin)
52 *value++ = (unsigned long) attributes->clip_y_origin;
53 if (valuemask & CPClipMask)
54 *value++ = attributes->clip_mask;
55 if (valuemask & CPGraphicsExposure)
56 *value++ = (unsigned long) attributes->graphics_exposures;
57 if (valuemask & CPSubwindowMode)
58 *value++ = (unsigned long) attributes->subwindow_mode;
59 if (valuemask & CPPolyEdge)
60 *value++ = (unsigned long) attributes->poly_edge;
61 if (valuemask & CPPolyMode)
62 *value++ = (unsigned long) attributes->poly_mode;
63 if (valuemask & CPDither)
64 *value++ = attributes->dither;
65 if (valuemask & CPComponentAlpha)
66 *value++ = (unsigned long) attributes->component_alpha;
67
68 req->length += (nvalues = (unsigned) (value - values));
69
70 nvalues <<= 2; /* watch out for macros... */
71 Data32 (dpy, (long *) values, (long)nvalues);
72 }
73
74 Picture
75 XRenderCreatePicture (Display *dpy,
76 Drawable drawable,
77 _Xconst XRenderPictFormat *format,
78 unsigned long valuemask,
79 _Xconst XRenderPictureAttributes *attributes)
80 {
81 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
82 Picture pid;
83 xRenderCreatePictureReq *req;
84
85 RenderCheckExtension (dpy, info, 0);
86 LockDisplay(dpy);
87 GetReq(RenderCreatePicture, req);
88 req->reqType = (CARD8) info->codes->major_opcode;
89 req->renderReqType = X_RenderCreatePicture;
90 req->pid = (CARD32) (pid = XAllocID(dpy));
91 req->drawable = (CARD32) drawable;
92 req->format = (CARD32) format->id;
93 if ((req->mask = (CARD32) valuemask))
94 _XRenderProcessPictureAttributes (dpy,
95 (xRenderChangePictureReq *) req,
96 valuemask,
97 attributes);
98 UnlockDisplay(dpy);
99 SyncHandle();
100 return pid;
101 }
102
103 void
104 XRenderChangePicture (Display *dpy,
105 Picture picture,
106 unsigned long valuemask,
107 _Xconst XRenderPictureAttributes *attributes)
108 {
109 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
110 xRenderChangePictureReq *req;
111
112 RenderSimpleCheckExtension (dpy, info);
113 LockDisplay(dpy);
114 GetReq(RenderChangePicture, req);
115 req->reqType = (CARD8) info->codes->major_opcode;
116 req->renderReqType = X_RenderChangePicture;
117 req->picture = (CARD32) picture;
118 req->mask = (CARD32) valuemask;
119 _XRenderProcessPictureAttributes (dpy,
120 req,
121 valuemask,
122 attributes);
123 UnlockDisplay(dpy);
124 SyncHandle();
125 }
126
127 static void
128 _XRenderSetPictureClipRectangles (Display *dpy,
129 XRenderExtDisplayInfo *info,
130 Picture picture,
131 int xOrigin,
132 int yOrigin,
133 _Xconst XRectangle *rects,
134 int n)
135 {
136 xRenderSetPictureClipRectanglesReq *req;
137 long len;
138
139 GetReq (RenderSetPictureClipRectangles, req);
140 req->reqType = (CARD8) info->codes->major_opcode;
141 req->renderReqType = X_RenderSetPictureClipRectangles;
142 req->picture = (CARD32) picture;
143 req->xOrigin = (INT16) xOrigin;
144 req->yOrigin = (INT16) yOrigin;
145 len = ((long) n) << 1;
146 SetReqLen (req, len, 1);
147 len <<= 2;
148 Data16 (dpy, (_Xconst short *) rects, len);
149 }
150
151 void
152 XRenderSetPictureClipRectangles (Display *dpy,
153 Picture picture,
154 int xOrigin,
155 int yOrigin,
156 _Xconst XRectangle *rects,
157 int n)
158 {
159 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
160
161 RenderSimpleCheckExtension (dpy, info);
162 LockDisplay(dpy);
163 _XRenderSetPictureClipRectangles (dpy, info, picture,
164 xOrigin, yOrigin, rects, n);
165 UnlockDisplay (dpy);
166 SyncHandle ();
167 }
168
169 void
170 XRenderSetPictureClipRegion (Display *dpy,
171 Picture picture,
172 Region r)
173 {
174 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
175 XRectangle *xr;
176 unsigned long total;
177
178 RenderSimpleCheckExtension (dpy, info);
179 LockDisplay(dpy);
180 total = (unsigned long) ((size_t) r->numRects * sizeof (XRectangle));
181 if ((xr = (XRectangle *) _XAllocTemp(dpy, total))) {
182 int i;
183 XRectangle *pr;
184 BOX *pb;
185
186 for (pr = xr, pb = r->rects, i = (int) r->numRects; --i >= 0; pr++, pb++) {
187 pr->x = pb->x1;
188 pr->y = pb->y1;
189 pr->width = (unsigned short) (pb->x2 - pb->x1);
190 pr->height = (unsigned short) (pb->y2 - pb->y1);
191 }
192 }
193 if (xr || !r->numRects)
194 _XRenderSetPictureClipRectangles (dpy, info, picture, 0, 0,
195 xr, (int) r->numRects);
196 if (xr)
197 _XFreeTemp(dpy, (char *)xr, total);
198 UnlockDisplay(dpy);
199 SyncHandle();
200 }
201
202 void
203 XRenderSetPictureTransform (Display *dpy,
204 Picture picture,
205 XTransform *transform)
206 {
207 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
208 xRenderSetPictureTransformReq *req;
209
210 RenderSimpleCheckExtension (dpy, info);
211 LockDisplay (dpy);
212 GetReq(RenderSetPictureTransform, req);
213 req->reqType = (CARD8) info->codes->major_opcode;
214 req->renderReqType = X_RenderSetPictureTransform;
215 req->picture = (CARD32) picture;
216 req->transform.matrix11 = transform->matrix[0][0];
217 req->transform.matrix12 = transform->matrix[0][1];
218 req->transform.matrix13 = transform->matrix[0][2];
219 req->transform.matrix21 = transform->matrix[1][0];
220 req->transform.matrix22 = transform->matrix[1][1];
221 req->transform.matrix23 = transform->matrix[1][2];
222 req->transform.matrix31 = transform->matrix[2][0];
223 req->transform.matrix32 = transform->matrix[2][1];
224 req->transform.matrix33 = transform->matrix[2][2];
225 UnlockDisplay(dpy);
226 SyncHandle();
227
228 }
229
230 void
231 XRenderFreePicture (Display *dpy,
232 Picture picture)
233 {
234 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
235 xRenderFreePictureReq *req;
236
237 RenderSimpleCheckExtension (dpy, info);
238 LockDisplay(dpy);
239 GetReq(RenderFreePicture, req);
240 req->reqType = (CARD8) info->codes->major_opcode;
241 req->renderReqType = X_RenderFreePicture;
242 req->picture = (CARD32) picture;
243 UnlockDisplay(dpy);
244 SyncHandle();
245 }
246
247
248 Picture XRenderCreateSolidFill(Display *dpy,
249 const XRenderColor *color)
250 {
251 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
252 Picture pid;
253 xRenderCreateSolidFillReq *req;
254
255 RenderCheckExtension (dpy, info, 0);
256 LockDisplay(dpy);
257 GetReq(RenderCreateSolidFill, req);
258 req->reqType = (CARD8) info->codes->major_opcode;
259 req->renderReqType = X_RenderCreateSolidFill;
260
261 req->pid = (CARD32) (pid = XAllocID(dpy));
262 req->color.red = color->red;
263 req->color.green = color->green;
264 req->color.blue = color->blue;
265 req->color.alpha = color->alpha;
266
267 UnlockDisplay(dpy);
268 SyncHandle();
269 return pid;
270 }
271
272
273 Picture XRenderCreateLinearGradient(Display *dpy,
274 const XLinearGradient *gradient,
275 const XFixed *stops,
276 const XRenderColor *colors,
277 int nStops)
278 {
279 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
280 Picture pid;
281 xRenderCreateLinearGradientReq *req;
282 long len;
283
284 RenderCheckExtension (dpy, info, 0);
285 LockDisplay(dpy);
286 GetReq(RenderCreateLinearGradient, req);
287 req->reqType = (CARD8) info->codes->major_opcode;
288 req->renderReqType = X_RenderCreateLinearGradient;
289
290 req->pid = (CARD32) (pid = XAllocID(dpy));
291 req->p1.x = gradient->p1.x;
292 req->p1.y = gradient->p1.y;
293 req->p2.x = gradient->p2.x;
294 req->p2.y = gradient->p2.y;
295
296 req->nStops = (CARD32) nStops;
297 len = (long) nStops * 3;
298 SetReqLen (req, len, 6);
299 DataInt32(dpy, stops, nStops * 4);
300 Data16(dpy, colors, nStops * 8);
301
302 UnlockDisplay(dpy);
303 SyncHandle();
304 return pid;
305 }
306
307 Picture XRenderCreateRadialGradient(Display *dpy,
308 const XRadialGradient *gradient,
309 const XFixed *stops,
310 const XRenderColor *colors,
311 int nStops)
312 {
313 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
314 Picture pid;
315 xRenderCreateRadialGradientReq *req;
316 long len;
317
318 RenderCheckExtension (dpy, info, 0);
319 LockDisplay(dpy);
320 GetReq(RenderCreateRadialGradient, req);
321 req->reqType = (CARD8) info->codes->major_opcode;
322 req->renderReqType = X_RenderCreateRadialGradient;
323
324 req->pid = (CARD32) (pid = XAllocID(dpy));
325 req->inner.x = gradient->inner.x;
326 req->inner.y = gradient->inner.y;
327 req->outer.x = gradient->outer.x;
328 req->outer.y = gradient->outer.y;
329 req->inner_radius = gradient->inner.radius;
330 req->outer_radius = gradient->outer.radius;
331
332 req->nStops = (CARD32) nStops;
333 len = (long) nStops * 3;
334 SetReqLen (req, len, 6);
335 DataInt32(dpy, stops, nStops * 4);
336 Data16(dpy, colors, nStops * 8);
337
338 UnlockDisplay(dpy);
339 SyncHandle();
340 return pid;
341 }
342
343 Picture XRenderCreateConicalGradient(Display *dpy,
344 const XConicalGradient *gradient,
345 const XFixed *stops,
346 const XRenderColor *colors,
347 int nStops)
348 {
349 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
350 Picture pid;
351 xRenderCreateConicalGradientReq *req;
352 long len;
353
354 RenderCheckExtension (dpy, info, 0);
355 LockDisplay(dpy);
356 GetReq(RenderCreateConicalGradient, req);
357 req->reqType = (CARD8) info->codes->major_opcode;
358 req->renderReqType = X_RenderCreateConicalGradient;
359
360 req->pid = (CARD32) (pid = XAllocID(dpy));
361 req->center.x = gradient->center.x;
362 req->center.y = gradient->center.y;
363 req->angle = gradient->angle;
364
365 req->nStops = (CARD32) nStops;
366 len = (long) nStops * 3;
367 SetReqLen (req, len, 6);
368 DataInt32(dpy, stops, nStops * 4);
369 Data16(dpy, colors, nStops * 8);
370
371 UnlockDisplay(dpy);
372 SyncHandle();
373 return pid;
374 }