Picture.c revision 1f0ac6a5
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
31static 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++ = attributes->repeat;
43    if (valuemask & CPAlphaMap)
44	*value++ = attributes->alpha_map;
45    if (valuemask & CPAlphaXOrigin)
46	*value++ = attributes->alpha_x_origin;
47    if (valuemask & CPAlphaYOrigin)
48	*value++ = attributes->alpha_y_origin;
49    if (valuemask & CPClipXOrigin)
50	*value++ = attributes->clip_x_origin;
51    if (valuemask & CPClipYOrigin)
52	*value++ = attributes->clip_y_origin;
53    if (valuemask & CPClipMask)
54	*value++ = attributes->clip_mask;
55    if (valuemask & CPGraphicsExposure)
56	*value++ = attributes->graphics_exposures;
57    if (valuemask & CPSubwindowMode)
58	*value++ = attributes->subwindow_mode;
59    if (valuemask & CPPolyEdge)
60	*value++ = attributes->poly_edge;
61    if (valuemask & CPPolyMode)
62	*value++ = attributes->poly_mode;
63    if (valuemask & CPDither)
64	*value++ = attributes->dither;
65    if (valuemask & CPComponentAlpha)
66	*value++ = attributes->component_alpha;
67
68    req->length += (nvalues = value - values);
69
70    nvalues <<= 2;			    /* watch out for macros... */
71    Data32 (dpy, (long *) values, (long)nvalues);
72}
73
74Picture
75XRenderCreatePicture (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 = info->codes->major_opcode;
89    req->renderReqType = X_RenderCreatePicture;
90    req->pid = pid = XAllocID(dpy);
91    req->drawable = drawable;
92    req->format = format->id;
93    if ((req->mask = valuemask))
94	_XRenderProcessPictureAttributes (dpy,
95					  (xRenderChangePictureReq *) req,
96					  valuemask,
97					  attributes);
98    UnlockDisplay(dpy);
99    SyncHandle();
100    return pid;
101}
102
103void
104XRenderChangePicture (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 = info->codes->major_opcode;
116    req->renderReqType = X_RenderChangePicture;
117    req->picture = picture;
118    req->mask = valuemask;
119    _XRenderProcessPictureAttributes (dpy,
120				      req,
121				      valuemask,
122				      attributes);
123    UnlockDisplay(dpy);
124    SyncHandle();
125}
126
127static 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 = info->codes->major_opcode;
141    req->renderReqType = X_RenderSetPictureClipRectangles;
142    req->picture = picture;
143    req->xOrigin = xOrigin;
144    req->yOrigin = yOrigin;
145    len = ((long) n) << 1;
146    SetReqLen (req, len, 1);
147    len <<= 2;
148    Data16 (dpy, (short *) rects, len);
149}
150
151void
152XRenderSetPictureClipRectangles (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
169void
170XRenderSetPictureClipRegion (Display	    *dpy,
171			     Picture	    picture,
172			     Region	    r)
173{
174    XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
175    int		    i;
176    XRectangle	    *xr, *pr;
177    BOX		    *pb;
178    unsigned long   total;
179
180    RenderSimpleCheckExtension (dpy, info);
181    LockDisplay(dpy);
182    total = r->numRects * sizeof (XRectangle);
183    if ((xr = (XRectangle *) _XAllocTemp(dpy, total))) {
184	for (pr = xr, pb = r->rects, i = r->numRects; --i >= 0; pr++, pb++) {
185	    pr->x = pb->x1;
186	    pr->y = pb->y1;
187	    pr->width = pb->x2 - pb->x1;
188	    pr->height = pb->y2 - pb->y1;
189	}
190    }
191    if (xr || !r->numRects)
192	_XRenderSetPictureClipRectangles (dpy, info, picture, 0, 0,
193					  xr, r->numRects);
194    if (xr)
195	_XFreeTemp(dpy, (char *)xr, total);
196    UnlockDisplay(dpy);
197    SyncHandle();
198}
199
200void
201XRenderSetPictureTransform (Display	*dpy,
202			    Picture	picture,
203			    XTransform	*transform)
204{
205    XRenderExtDisplayInfo		    *info = XRenderFindDisplay (dpy);
206    xRenderSetPictureTransformReq   *req;
207
208    RenderSimpleCheckExtension (dpy, info);
209    LockDisplay (dpy);
210    GetReq(RenderSetPictureTransform, req);
211    req->reqType = info->codes->major_opcode;
212    req->renderReqType = X_RenderSetPictureTransform;
213    req->picture = picture;
214    req->transform.matrix11 = transform->matrix[0][0];
215    req->transform.matrix12 = transform->matrix[0][1];
216    req->transform.matrix13 = transform->matrix[0][2];
217    req->transform.matrix21 = transform->matrix[1][0];
218    req->transform.matrix22 = transform->matrix[1][1];
219    req->transform.matrix23 = transform->matrix[1][2];
220    req->transform.matrix31 = transform->matrix[2][0];
221    req->transform.matrix32 = transform->matrix[2][1];
222    req->transform.matrix33 = transform->matrix[2][2];
223    UnlockDisplay(dpy);
224    SyncHandle();
225
226}
227
228void
229XRenderFreePicture (Display                   *dpy,
230		    Picture                   picture)
231{
232    XRenderExtDisplayInfo         *info = XRenderFindDisplay (dpy);
233    xRenderFreePictureReq   *req;
234
235    RenderSimpleCheckExtension (dpy, info);
236    LockDisplay(dpy);
237    GetReq(RenderFreePicture, req);
238    req->reqType = info->codes->major_opcode;
239    req->renderReqType = X_RenderFreePicture;
240    req->picture = picture;
241    UnlockDisplay(dpy);
242    SyncHandle();
243}
244
245
246Picture XRenderCreateSolidFill(Display *dpy,
247                               const XRenderColor *color)
248{
249    XRenderExtDisplayInfo	    *info = XRenderFindDisplay (dpy);
250    Picture		    pid;
251    xRenderCreateSolidFillReq *req;
252
253    RenderCheckExtension (dpy, info, 0);
254    LockDisplay(dpy);
255    GetReq(RenderCreateSolidFill, req);
256    req->reqType = info->codes->major_opcode;
257    req->renderReqType = X_RenderCreateSolidFill;
258
259    req->pid = pid = XAllocID(dpy);
260    req->color.red = color->red;
261    req->color.green = color->green;
262    req->color.blue = color->blue;
263    req->color.alpha = color->alpha;
264
265    UnlockDisplay(dpy);
266    SyncHandle();
267    return pid;
268}
269
270
271Picture XRenderCreateLinearGradient(Display *dpy,
272                                    const XLinearGradient *gradient,
273                                    const XFixed *stops,
274                                    const XRenderColor *colors,
275                                    int nStops)
276{
277    XRenderExtDisplayInfo	    *info = XRenderFindDisplay (dpy);
278    Picture		    pid;
279    xRenderCreateLinearGradientReq *req;
280    long			   len;
281
282    RenderCheckExtension (dpy, info, 0);
283    LockDisplay(dpy);
284    GetReq(RenderCreateLinearGradient, req);
285    req->reqType = info->codes->major_opcode;
286    req->renderReqType = X_RenderCreateLinearGradient;
287
288    req->pid = pid = XAllocID(dpy);
289    req->p1.x = gradient->p1.x;
290    req->p1.y = gradient->p1.y;
291    req->p2.x = gradient->p2.x;
292    req->p2.y = gradient->p2.y;
293
294    req->nStops = nStops;
295    len = (long) nStops * 3;
296    SetReqLen (req, len, 6);
297    DataInt32(dpy, stops, nStops * 4);
298    Data16(dpy, colors, nStops * 8);
299
300    UnlockDisplay(dpy);
301    SyncHandle();
302    return pid;
303}
304
305Picture XRenderCreateRadialGradient(Display *dpy,
306                                    const XRadialGradient *gradient,
307                                    const XFixed *stops,
308                                    const XRenderColor *colors,
309                                    int nStops)
310{
311    XRenderExtDisplayInfo	    *info = XRenderFindDisplay (dpy);
312    Picture		    pid;
313    xRenderCreateRadialGradientReq *req;
314    long			   len;
315
316    RenderCheckExtension (dpy, info, 0);
317    LockDisplay(dpy);
318    GetReq(RenderCreateRadialGradient, req);
319    req->reqType = info->codes->major_opcode;
320    req->renderReqType = X_RenderCreateRadialGradient;
321
322    req->pid = pid = XAllocID(dpy);
323    req->inner.x = gradient->inner.x;
324    req->inner.y = gradient->inner.y;
325    req->outer.x = gradient->outer.x;
326    req->outer.y = gradient->outer.y;
327    req->inner_radius = gradient->inner.radius;
328    req->outer_radius = gradient->outer.radius;
329
330    req->nStops = nStops;
331    len = (long) nStops * 3;
332    SetReqLen (req, len, 6);
333    DataInt32(dpy, stops, nStops * 4);
334    Data16(dpy, colors, nStops * 8);
335
336    UnlockDisplay(dpy);
337    SyncHandle();
338    return pid;
339}
340
341Picture XRenderCreateConicalGradient(Display *dpy,
342                                     const XConicalGradient *gradient,
343                                     const XFixed *stops,
344                                     const XRenderColor *colors,
345                                     int nStops)
346{
347    XRenderExtDisplayInfo	    *info = XRenderFindDisplay (dpy);
348    Picture		    pid;
349    xRenderCreateConicalGradientReq *req;
350    long			    len;
351
352    RenderCheckExtension (dpy, info, 0);
353    LockDisplay(dpy);
354    GetReq(RenderCreateConicalGradient, req);
355    req->reqType = info->codes->major_opcode;
356    req->renderReqType = X_RenderCreateConicalGradient;
357
358    req->pid = pid = XAllocID(dpy);
359    req->center.x = gradient->center.x;
360    req->center.y = gradient->center.y;
361    req->angle = gradient->angle;
362
363    req->nStops = nStops;
364    len = (long) nStops * 3;
365    SetReqLen (req, len, 6);
366    DataInt32(dpy, stops, nStops * 4);
367    Data16(dpy, colors, nStops * 8);
368
369    UnlockDisplay(dpy);
370    SyncHandle();
371    return pid;
372}
373