First import
[xorg_rtime.git] / xorg-server-1.4 / render / render.c
blobcaaa2781c753711f4264bd01f44462af6161b9cf
1 /*
3 * Copyright © 2000 SuSE, Inc.
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.
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.
22 * Author: Keith Packard, SuSE, Inc.
25 #define NEED_REPLIES
26 #define NEED_EVENTS
27 #ifdef HAVE_DIX_CONFIG_H
28 #include <dix-config.h>
29 #endif
31 #include <X11/X.h>
32 #include <X11/Xproto.h>
33 #include "misc.h"
34 #include "os.h"
35 #include "dixstruct.h"
36 #include "resource.h"
37 #include "scrnintstr.h"
38 #include "windowstr.h"
39 #include "pixmapstr.h"
40 #include "colormapst.h"
41 #include "extnsionst.h"
42 #include "servermd.h"
43 #include <X11/extensions/render.h>
44 #include <X11/extensions/renderproto.h>
45 #include "picturestr.h"
46 #include "glyphstr.h"
47 #include <X11/Xfuncproto.h>
48 #include "cursorstr.h"
50 #if HAVE_STDINT_H
51 #include <stdint.h>
52 #elif !defined(UINT32_MAX)
53 #define UINT32_MAX 0xffffffffU
54 #endif
56 static int ProcRenderQueryVersion (ClientPtr pClient);
57 static int ProcRenderQueryPictFormats (ClientPtr pClient);
58 static int ProcRenderQueryPictIndexValues (ClientPtr pClient);
59 static int ProcRenderQueryDithers (ClientPtr pClient);
60 static int ProcRenderCreatePicture (ClientPtr pClient);
61 static int ProcRenderChangePicture (ClientPtr pClient);
62 static int ProcRenderSetPictureClipRectangles (ClientPtr pClient);
63 static int ProcRenderFreePicture (ClientPtr pClient);
64 static int ProcRenderComposite (ClientPtr pClient);
65 static int ProcRenderScale (ClientPtr pClient);
66 static int ProcRenderTrapezoids (ClientPtr pClient);
67 static int ProcRenderTriangles (ClientPtr pClient);
68 static int ProcRenderTriStrip (ClientPtr pClient);
69 static int ProcRenderTriFan (ClientPtr pClient);
70 static int ProcRenderColorTrapezoids (ClientPtr pClient);
71 static int ProcRenderColorTriangles (ClientPtr pClient);
72 static int ProcRenderTransform (ClientPtr pClient);
73 static int ProcRenderCreateGlyphSet (ClientPtr pClient);
74 static int ProcRenderReferenceGlyphSet (ClientPtr pClient);
75 static int ProcRenderFreeGlyphSet (ClientPtr pClient);
76 static int ProcRenderAddGlyphs (ClientPtr pClient);
77 static int ProcRenderAddGlyphsFromPicture (ClientPtr pClient);
78 static int ProcRenderFreeGlyphs (ClientPtr pClient);
79 static int ProcRenderCompositeGlyphs (ClientPtr pClient);
80 static int ProcRenderFillRectangles (ClientPtr pClient);
81 static int ProcRenderCreateCursor (ClientPtr pClient);
82 static int ProcRenderSetPictureTransform (ClientPtr pClient);
83 static int ProcRenderQueryFilters (ClientPtr pClient);
84 static int ProcRenderSetPictureFilter (ClientPtr pClient);
85 static int ProcRenderCreateAnimCursor (ClientPtr pClient);
86 static int ProcRenderAddTraps (ClientPtr pClient);
87 static int ProcRenderCreateSolidFill (ClientPtr pClient);
88 static int ProcRenderCreateLinearGradient (ClientPtr pClient);
89 static int ProcRenderCreateRadialGradient (ClientPtr pClient);
90 static int ProcRenderCreateConicalGradient (ClientPtr pClient);
92 static int ProcRenderDispatch (ClientPtr pClient);
94 static int SProcRenderQueryVersion (ClientPtr pClient);
95 static int SProcRenderQueryPictFormats (ClientPtr pClient);
96 static int SProcRenderQueryPictIndexValues (ClientPtr pClient);
97 static int SProcRenderQueryDithers (ClientPtr pClient);
98 static int SProcRenderCreatePicture (ClientPtr pClient);
99 static int SProcRenderChangePicture (ClientPtr pClient);
100 static int SProcRenderSetPictureClipRectangles (ClientPtr pClient);
101 static int SProcRenderFreePicture (ClientPtr pClient);
102 static int SProcRenderComposite (ClientPtr pClient);
103 static int SProcRenderScale (ClientPtr pClient);
104 static int SProcRenderTrapezoids (ClientPtr pClient);
105 static int SProcRenderTriangles (ClientPtr pClient);
106 static int SProcRenderTriStrip (ClientPtr pClient);
107 static int SProcRenderTriFan (ClientPtr pClient);
108 static int SProcRenderColorTrapezoids (ClientPtr pClient);
109 static int SProcRenderColorTriangles (ClientPtr pClient);
110 static int SProcRenderTransform (ClientPtr pClient);
111 static int SProcRenderCreateGlyphSet (ClientPtr pClient);
112 static int SProcRenderReferenceGlyphSet (ClientPtr pClient);
113 static int SProcRenderFreeGlyphSet (ClientPtr pClient);
114 static int SProcRenderAddGlyphs (ClientPtr pClient);
115 static int SProcRenderAddGlyphsFromPicture (ClientPtr pClient);
116 static int SProcRenderFreeGlyphs (ClientPtr pClient);
117 static int SProcRenderCompositeGlyphs (ClientPtr pClient);
118 static int SProcRenderFillRectangles (ClientPtr pClient);
119 static int SProcRenderCreateCursor (ClientPtr pClient);
120 static int SProcRenderSetPictureTransform (ClientPtr pClient);
121 static int SProcRenderQueryFilters (ClientPtr pClient);
122 static int SProcRenderSetPictureFilter (ClientPtr pClient);
123 static int SProcRenderCreateAnimCursor (ClientPtr pClient);
124 static int SProcRenderAddTraps (ClientPtr pClient);
125 static int SProcRenderCreateSolidFill (ClientPtr pClient);
126 static int SProcRenderCreateLinearGradient (ClientPtr pClient);
127 static int SProcRenderCreateRadialGradient (ClientPtr pClient);
128 static int SProcRenderCreateConicalGradient (ClientPtr pClient);
130 static int SProcRenderDispatch (ClientPtr pClient);
132 int (*ProcRenderVector[RenderNumberRequests])(ClientPtr) = {
133 ProcRenderQueryVersion,
134 ProcRenderQueryPictFormats,
135 ProcRenderQueryPictIndexValues,
136 ProcRenderQueryDithers,
137 ProcRenderCreatePicture,
138 ProcRenderChangePicture,
139 ProcRenderSetPictureClipRectangles,
140 ProcRenderFreePicture,
141 ProcRenderComposite,
142 ProcRenderScale,
143 ProcRenderTrapezoids,
144 ProcRenderTriangles,
145 ProcRenderTriStrip,
146 ProcRenderTriFan,
147 ProcRenderColorTrapezoids,
148 ProcRenderColorTriangles,
149 ProcRenderTransform,
150 ProcRenderCreateGlyphSet,
151 ProcRenderReferenceGlyphSet,
152 ProcRenderFreeGlyphSet,
153 ProcRenderAddGlyphs,
154 ProcRenderAddGlyphsFromPicture,
155 ProcRenderFreeGlyphs,
156 ProcRenderCompositeGlyphs,
157 ProcRenderCompositeGlyphs,
158 ProcRenderCompositeGlyphs,
159 ProcRenderFillRectangles,
160 ProcRenderCreateCursor,
161 ProcRenderSetPictureTransform,
162 ProcRenderQueryFilters,
163 ProcRenderSetPictureFilter,
164 ProcRenderCreateAnimCursor,
165 ProcRenderAddTraps,
166 ProcRenderCreateSolidFill,
167 ProcRenderCreateLinearGradient,
168 ProcRenderCreateRadialGradient,
169 ProcRenderCreateConicalGradient
172 int (*SProcRenderVector[RenderNumberRequests])(ClientPtr) = {
173 SProcRenderQueryVersion,
174 SProcRenderQueryPictFormats,
175 SProcRenderQueryPictIndexValues,
176 SProcRenderQueryDithers,
177 SProcRenderCreatePicture,
178 SProcRenderChangePicture,
179 SProcRenderSetPictureClipRectangles,
180 SProcRenderFreePicture,
181 SProcRenderComposite,
182 SProcRenderScale,
183 SProcRenderTrapezoids,
184 SProcRenderTriangles,
185 SProcRenderTriStrip,
186 SProcRenderTriFan,
187 SProcRenderColorTrapezoids,
188 SProcRenderColorTriangles,
189 SProcRenderTransform,
190 SProcRenderCreateGlyphSet,
191 SProcRenderReferenceGlyphSet,
192 SProcRenderFreeGlyphSet,
193 SProcRenderAddGlyphs,
194 SProcRenderAddGlyphsFromPicture,
195 SProcRenderFreeGlyphs,
196 SProcRenderCompositeGlyphs,
197 SProcRenderCompositeGlyphs,
198 SProcRenderCompositeGlyphs,
199 SProcRenderFillRectangles,
200 SProcRenderCreateCursor,
201 SProcRenderSetPictureTransform,
202 SProcRenderQueryFilters,
203 SProcRenderSetPictureFilter,
204 SProcRenderCreateAnimCursor,
205 SProcRenderAddTraps,
206 SProcRenderCreateSolidFill,
207 SProcRenderCreateLinearGradient,
208 SProcRenderCreateRadialGradient,
209 SProcRenderCreateConicalGradient
212 static void
213 RenderResetProc (ExtensionEntry *extEntry);
215 #if 0
216 static CARD8 RenderReqCode;
217 #endif
218 int RenderErrBase;
219 int RenderClientPrivateIndex;
221 typedef struct _RenderClient {
222 int major_version;
223 int minor_version;
224 } RenderClientRec, *RenderClientPtr;
226 #define GetRenderClient(pClient) ((RenderClientPtr) (pClient)->devPrivates[RenderClientPrivateIndex].ptr)
228 static void
229 RenderClientCallback (CallbackListPtr *list,
230 pointer closure,
231 pointer data)
233 NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
234 ClientPtr pClient = clientinfo->client;
235 RenderClientPtr pRenderClient = GetRenderClient (pClient);
237 pRenderClient->major_version = 0;
238 pRenderClient->minor_version = 0;
241 void
242 RenderExtensionInit (void)
244 ExtensionEntry *extEntry;
246 if (!PictureType)
247 return;
248 if (!PictureFinishInit ())
249 return;
250 RenderClientPrivateIndex = AllocateClientPrivateIndex ();
251 if (!AllocateClientPrivate (RenderClientPrivateIndex,
252 sizeof (RenderClientRec)))
253 return;
254 if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0))
255 return;
257 extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors,
258 ProcRenderDispatch, SProcRenderDispatch,
259 RenderResetProc, StandardMinorOpcode);
260 if (!extEntry)
261 return;
262 #if 0
263 RenderReqCode = (CARD8) extEntry->base;
264 #endif
265 RenderErrBase = extEntry->errorBase;
268 static void
269 RenderResetProc (ExtensionEntry *extEntry)
271 ResetPicturePrivateIndex();
272 ResetGlyphSetPrivateIndex();
275 static int
276 ProcRenderQueryVersion (ClientPtr client)
278 RenderClientPtr pRenderClient = GetRenderClient (client);
279 xRenderQueryVersionReply rep;
280 register int n;
281 REQUEST(xRenderQueryVersionReq);
283 pRenderClient->major_version = stuff->majorVersion;
284 pRenderClient->minor_version = stuff->minorVersion;
286 REQUEST_SIZE_MATCH(xRenderQueryVersionReq);
287 rep.type = X_Reply;
288 rep.length = 0;
289 rep.sequenceNumber = client->sequence;
290 rep.majorVersion = RENDER_MAJOR;
291 rep.minorVersion = RENDER_MINOR;
292 if (client->swapped) {
293 swaps(&rep.sequenceNumber, n);
294 swapl(&rep.length, n);
295 swapl(&rep.majorVersion, n);
296 swapl(&rep.minorVersion, n);
298 WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *)&rep);
299 return (client->noClientException);
302 #if 0
303 static int
304 VisualDepth (ScreenPtr pScreen, VisualPtr pVisual)
306 DepthPtr pDepth;
307 int d, v;
309 for (d = 0; d < pScreen->numDepths; d++)
311 pDepth = pScreen->allowedDepths + d;
312 for (v = 0; v < pDepth->numVids; v++)
314 if (pDepth->vids[v] == pVisual->vid)
315 return pDepth->depth;
318 return 0;
320 #endif
322 static VisualPtr
323 findVisual (ScreenPtr pScreen, VisualID vid)
325 VisualPtr pVisual;
326 int v;
328 for (v = 0; v < pScreen->numVisuals; v++)
330 pVisual = pScreen->visuals + v;
331 if (pVisual->vid == vid)
332 return pVisual;
334 return 0;
337 extern char *ConnectionInfo;
339 static int
340 ProcRenderQueryPictFormats (ClientPtr client)
342 RenderClientPtr pRenderClient = GetRenderClient (client);
343 xRenderQueryPictFormatsReply *reply;
344 xPictScreen *pictScreen;
345 xPictDepth *pictDepth;
346 xPictVisual *pictVisual;
347 xPictFormInfo *pictForm;
348 CARD32 *pictSubpixel;
349 ScreenPtr pScreen;
350 VisualPtr pVisual;
351 DepthPtr pDepth;
352 int v, d;
353 PictureScreenPtr ps;
354 PictFormatPtr pFormat;
355 int nformat;
356 int ndepth;
357 int nvisual;
358 int rlength;
359 int s;
360 int n;
361 int numScreens;
362 int numSubpixel;
363 /* REQUEST(xRenderQueryPictFormatsReq); */
365 REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq);
367 #ifdef PANORAMIX
368 if (noPanoramiXExtension)
369 numScreens = screenInfo.numScreens;
370 else
371 numScreens = ((xConnSetup *)ConnectionInfo)->numRoots;
372 #else
373 numScreens = screenInfo.numScreens;
374 #endif
375 ndepth = nformat = nvisual = 0;
376 for (s = 0; s < numScreens; s++)
378 pScreen = screenInfo.screens[s];
379 for (d = 0; d < pScreen->numDepths; d++)
381 pDepth = pScreen->allowedDepths + d;
382 ++ndepth;
384 for (v = 0; v < pDepth->numVids; v++)
386 pVisual = findVisual (pScreen, pDepth->vids[v]);
387 if (pVisual && PictureMatchVisual (pScreen, pDepth->depth, pVisual))
388 ++nvisual;
391 ps = GetPictureScreenIfSet(pScreen);
392 if (ps)
393 nformat += ps->nformats;
395 if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6)
396 numSubpixel = 0;
397 else
398 numSubpixel = numScreens;
400 rlength = (sizeof (xRenderQueryPictFormatsReply) +
401 nformat * sizeof (xPictFormInfo) +
402 numScreens * sizeof (xPictScreen) +
403 ndepth * sizeof (xPictDepth) +
404 nvisual * sizeof (xPictVisual) +
405 numSubpixel * sizeof (CARD32));
406 reply = (xRenderQueryPictFormatsReply *) xalloc (rlength);
407 if (!reply)
408 return BadAlloc;
409 reply->type = X_Reply;
410 reply->sequenceNumber = client->sequence;
411 reply->length = (rlength - sizeof(xGenericReply)) >> 2;
412 reply->numFormats = nformat;
413 reply->numScreens = numScreens;
414 reply->numDepths = ndepth;
415 reply->numVisuals = nvisual;
416 reply->numSubpixel = numSubpixel;
418 pictForm = (xPictFormInfo *) (reply + 1);
420 for (s = 0; s < numScreens; s++)
422 pScreen = screenInfo.screens[s];
423 ps = GetPictureScreenIfSet(pScreen);
424 if (ps)
426 for (nformat = 0, pFormat = ps->formats;
427 nformat < ps->nformats;
428 nformat++, pFormat++)
430 pictForm->id = pFormat->id;
431 pictForm->type = pFormat->type;
432 pictForm->depth = pFormat->depth;
433 pictForm->direct.red = pFormat->direct.red;
434 pictForm->direct.redMask = pFormat->direct.redMask;
435 pictForm->direct.green = pFormat->direct.green;
436 pictForm->direct.greenMask = pFormat->direct.greenMask;
437 pictForm->direct.blue = pFormat->direct.blue;
438 pictForm->direct.blueMask = pFormat->direct.blueMask;
439 pictForm->direct.alpha = pFormat->direct.alpha;
440 pictForm->direct.alphaMask = pFormat->direct.alphaMask;
441 if (pFormat->type == PictTypeIndexed && pFormat->index.pColormap)
442 pictForm->colormap = pFormat->index.pColormap->mid;
443 else
444 pictForm->colormap = None;
445 if (client->swapped)
447 swapl (&pictForm->id, n);
448 swaps (&pictForm->direct.red, n);
449 swaps (&pictForm->direct.redMask, n);
450 swaps (&pictForm->direct.green, n);
451 swaps (&pictForm->direct.greenMask, n);
452 swaps (&pictForm->direct.blue, n);
453 swaps (&pictForm->direct.blueMask, n);
454 swaps (&pictForm->direct.alpha, n);
455 swaps (&pictForm->direct.alphaMask, n);
456 swapl (&pictForm->colormap, n);
458 pictForm++;
463 pictScreen = (xPictScreen *) pictForm;
464 for (s = 0; s < numScreens; s++)
466 pScreen = screenInfo.screens[s];
467 pictDepth = (xPictDepth *) (pictScreen + 1);
468 ndepth = 0;
469 for (d = 0; d < pScreen->numDepths; d++)
471 pictVisual = (xPictVisual *) (pictDepth + 1);
472 pDepth = pScreen->allowedDepths + d;
474 nvisual = 0;
475 for (v = 0; v < pDepth->numVids; v++)
477 pVisual = findVisual (pScreen, pDepth->vids[v]);
478 if (pVisual && (pFormat = PictureMatchVisual (pScreen,
479 pDepth->depth,
480 pVisual)))
482 pictVisual->visual = pVisual->vid;
483 pictVisual->format = pFormat->id;
484 if (client->swapped)
486 swapl (&pictVisual->visual, n);
487 swapl (&pictVisual->format, n);
489 pictVisual++;
490 nvisual++;
493 pictDepth->depth = pDepth->depth;
494 pictDepth->nPictVisuals = nvisual;
495 if (client->swapped)
497 swaps (&pictDepth->nPictVisuals, n);
499 ndepth++;
500 pictDepth = (xPictDepth *) pictVisual;
502 pictScreen->nDepth = ndepth;
503 ps = GetPictureScreenIfSet(pScreen);
504 if (ps)
505 pictScreen->fallback = ps->fallback->id;
506 else
507 pictScreen->fallback = 0;
508 if (client->swapped)
510 swapl (&pictScreen->nDepth, n);
511 swapl (&pictScreen->fallback, n);
513 pictScreen = (xPictScreen *) pictDepth;
515 pictSubpixel = (CARD32 *) pictScreen;
517 for (s = 0; s < numSubpixel; s++)
519 pScreen = screenInfo.screens[s];
520 ps = GetPictureScreenIfSet(pScreen);
521 if (ps)
522 *pictSubpixel = ps->subpixel;
523 else
524 *pictSubpixel = SubPixelUnknown;
525 if (client->swapped)
527 swapl (pictSubpixel, n);
529 ++pictSubpixel;
532 if (client->swapped)
534 swaps (&reply->sequenceNumber, n);
535 swapl (&reply->length, n);
536 swapl (&reply->numFormats, n);
537 swapl (&reply->numScreens, n);
538 swapl (&reply->numDepths, n);
539 swapl (&reply->numVisuals, n);
540 swapl (&reply->numSubpixel, n);
542 WriteToClient(client, rlength, (char *) reply);
543 xfree (reply);
544 return client->noClientException;
547 static int
548 ProcRenderQueryPictIndexValues (ClientPtr client)
550 PictFormatPtr pFormat;
551 int num;
552 int rlength;
553 int i, n;
554 REQUEST(xRenderQueryPictIndexValuesReq);
555 xRenderQueryPictIndexValuesReply *reply;
556 xIndexValue *values;
558 REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq);
560 pFormat = (PictFormatPtr) SecurityLookupIDByType (client,
561 stuff->format,
562 PictFormatType,
563 DixReadAccess);
565 if (!pFormat)
567 client->errorValue = stuff->format;
568 return RenderErrBase + BadPictFormat;
570 if (pFormat->type != PictTypeIndexed)
572 client->errorValue = stuff->format;
573 return BadMatch;
575 num = pFormat->index.nvalues;
576 rlength = (sizeof (xRenderQueryPictIndexValuesReply) +
577 num * sizeof(xIndexValue));
578 reply = (xRenderQueryPictIndexValuesReply *) xalloc (rlength);
579 if (!reply)
580 return BadAlloc;
582 reply->type = X_Reply;
583 reply->sequenceNumber = client->sequence;
584 reply->length = (rlength - sizeof(xGenericReply)) >> 2;
585 reply->numIndexValues = num;
587 values = (xIndexValue *) (reply + 1);
589 memcpy (reply + 1, pFormat->index.pValues, num * sizeof (xIndexValue));
591 if (client->swapped)
593 for (i = 0; i < num; i++)
595 swapl (&values[i].pixel, n);
596 swaps (&values[i].red, n);
597 swaps (&values[i].green, n);
598 swaps (&values[i].blue, n);
599 swaps (&values[i].alpha, n);
601 swaps (&reply->sequenceNumber, n);
602 swapl (&reply->length, n);
603 swapl (&reply->numIndexValues, n);
606 WriteToClient(client, rlength, (char *) reply);
607 xfree(reply);
608 return (client->noClientException);
611 static int
612 ProcRenderQueryDithers (ClientPtr client)
614 return BadImplementation;
617 static int
618 ProcRenderCreatePicture (ClientPtr client)
620 PicturePtr pPicture;
621 DrawablePtr pDrawable;
622 PictFormatPtr pFormat;
623 int len, error, rc;
624 REQUEST(xRenderCreatePictureReq);
626 REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq);
628 LEGAL_NEW_RESOURCE(stuff->pid, client);
629 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
630 DixWriteAccess);
631 if (rc != Success)
632 return rc;
634 pFormat = (PictFormatPtr) SecurityLookupIDByType (client,
635 stuff->format,
636 PictFormatType,
637 DixReadAccess);
638 if (!pFormat)
640 client->errorValue = stuff->format;
641 return RenderErrBase + BadPictFormat;
643 if (pFormat->depth != pDrawable->depth)
644 return BadMatch;
645 len = client->req_len - (sizeof(xRenderCreatePictureReq) >> 2);
646 if (Ones(stuff->mask) != len)
647 return BadLength;
649 pPicture = CreatePicture (stuff->pid,
650 pDrawable,
651 pFormat,
652 stuff->mask,
653 (XID *) (stuff + 1),
654 client,
655 &error);
656 if (!pPicture)
657 return error;
658 if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
659 return BadAlloc;
660 return Success;
663 static int
664 ProcRenderChangePicture (ClientPtr client)
666 PicturePtr pPicture;
667 REQUEST(xRenderChangePictureReq);
668 int len;
670 REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq);
671 VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
672 RenderErrBase + BadPicture);
674 len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2);
675 if (Ones(stuff->mask) != len)
676 return BadLength;
678 return ChangePicture (pPicture, stuff->mask, (XID *) (stuff + 1),
679 (DevUnion *) 0, client);
682 static int
683 ProcRenderSetPictureClipRectangles (ClientPtr client)
685 REQUEST(xRenderSetPictureClipRectanglesReq);
686 PicturePtr pPicture;
687 int nr;
688 int result;
690 REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq);
691 VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
692 RenderErrBase + BadPicture);
693 if (!pPicture->pDrawable)
694 return BadDrawable;
696 nr = (client->req_len << 2) - sizeof(xRenderChangePictureReq);
697 if (nr & 4)
698 return BadLength;
699 nr >>= 3;
700 result = SetPictureClipRects (pPicture,
701 stuff->xOrigin, stuff->yOrigin,
702 nr, (xRectangle *) &stuff[1]);
703 if (client->noClientException != Success)
704 return(client->noClientException);
705 else
706 return(result);
709 static int
710 ProcRenderFreePicture (ClientPtr client)
712 PicturePtr pPicture;
713 REQUEST(xRenderFreePictureReq);
715 REQUEST_SIZE_MATCH(xRenderFreePictureReq);
717 VERIFY_PICTURE (pPicture, stuff->picture, client, DixDestroyAccess,
718 RenderErrBase + BadPicture);
719 FreeResource (stuff->picture, RT_NONE);
720 return(client->noClientException);
723 static Bool
724 PictOpValid (CARD8 op)
726 if (/*PictOpMinimum <= op && */ op <= PictOpMaximum)
727 return TRUE;
728 if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum)
729 return TRUE;
730 if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum)
731 return TRUE;
732 return FALSE;
735 static int
736 ProcRenderComposite (ClientPtr client)
738 PicturePtr pSrc, pMask, pDst;
739 REQUEST(xRenderCompositeReq);
741 REQUEST_SIZE_MATCH(xRenderCompositeReq);
742 if (!PictOpValid (stuff->op))
744 client->errorValue = stuff->op;
745 return BadValue;
747 VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess,
748 RenderErrBase + BadPicture);
749 if (!pDst->pDrawable)
750 return BadDrawable;
751 VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess,
752 RenderErrBase + BadPicture);
753 VERIFY_ALPHA (pMask, stuff->mask, client, DixReadAccess,
754 RenderErrBase + BadPicture);
755 if ((pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) ||
756 (pMask && pMask->pDrawable && pDst->pDrawable->pScreen != pMask->pDrawable->pScreen))
757 return BadMatch;
758 CompositePicture (stuff->op,
759 pSrc,
760 pMask,
761 pDst,
762 stuff->xSrc,
763 stuff->ySrc,
764 stuff->xMask,
765 stuff->yMask,
766 stuff->xDst,
767 stuff->yDst,
768 stuff->width,
769 stuff->height);
770 return Success;
773 static int
774 ProcRenderScale (ClientPtr client)
776 return BadImplementation;
779 static int
780 ProcRenderTrapezoids (ClientPtr client)
782 int ntraps;
783 PicturePtr pSrc, pDst;
784 PictFormatPtr pFormat;
785 REQUEST(xRenderTrapezoidsReq);
787 REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq);
788 if (!PictOpValid (stuff->op))
790 client->errorValue = stuff->op;
791 return BadValue;
793 VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess,
794 RenderErrBase + BadPicture);
795 VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess,
796 RenderErrBase + BadPicture);
797 if (!pDst->pDrawable)
798 return BadDrawable;
799 if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
800 return BadMatch;
801 if (stuff->maskFormat)
803 pFormat = (PictFormatPtr) SecurityLookupIDByType (client,
804 stuff->maskFormat,
805 PictFormatType,
806 DixReadAccess);
807 if (!pFormat)
809 client->errorValue = stuff->maskFormat;
810 return RenderErrBase + BadPictFormat;
813 else
814 pFormat = 0;
815 ntraps = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq);
816 if (ntraps % sizeof (xTrapezoid))
817 return BadLength;
818 ntraps /= sizeof (xTrapezoid);
819 if (ntraps)
820 CompositeTrapezoids (stuff->op, pSrc, pDst, pFormat,
821 stuff->xSrc, stuff->ySrc,
822 ntraps, (xTrapezoid *) &stuff[1]);
823 return client->noClientException;
826 static int
827 ProcRenderTriangles (ClientPtr client)
829 int ntris;
830 PicturePtr pSrc, pDst;
831 PictFormatPtr pFormat;
832 REQUEST(xRenderTrianglesReq);
834 REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
835 if (!PictOpValid (stuff->op))
837 client->errorValue = stuff->op;
838 return BadValue;
840 VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess,
841 RenderErrBase + BadPicture);
842 VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess,
843 RenderErrBase + BadPicture);
844 if (!pDst->pDrawable)
845 return BadDrawable;
846 if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
847 return BadMatch;
848 if (stuff->maskFormat)
850 pFormat = (PictFormatPtr) SecurityLookupIDByType (client,
851 stuff->maskFormat,
852 PictFormatType,
853 DixReadAccess);
854 if (!pFormat)
856 client->errorValue = stuff->maskFormat;
857 return RenderErrBase + BadPictFormat;
860 else
861 pFormat = 0;
862 ntris = (client->req_len << 2) - sizeof (xRenderTrianglesReq);
863 if (ntris % sizeof (xTriangle))
864 return BadLength;
865 ntris /= sizeof (xTriangle);
866 if (ntris)
867 CompositeTriangles (stuff->op, pSrc, pDst, pFormat,
868 stuff->xSrc, stuff->ySrc,
869 ntris, (xTriangle *) &stuff[1]);
870 return client->noClientException;
873 static int
874 ProcRenderTriStrip (ClientPtr client)
876 int npoints;
877 PicturePtr pSrc, pDst;
878 PictFormatPtr pFormat;
879 REQUEST(xRenderTrianglesReq);
881 REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
882 if (!PictOpValid (stuff->op))
884 client->errorValue = stuff->op;
885 return BadValue;
887 VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess,
888 RenderErrBase + BadPicture);
889 VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess,
890 RenderErrBase + BadPicture);
891 if (!pDst->pDrawable)
892 return BadDrawable;
893 if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
894 return BadMatch;
895 if (stuff->maskFormat)
897 pFormat = (PictFormatPtr) SecurityLookupIDByType (client,
898 stuff->maskFormat,
899 PictFormatType,
900 DixReadAccess);
901 if (!pFormat)
903 client->errorValue = stuff->maskFormat;
904 return RenderErrBase + BadPictFormat;
907 else
908 pFormat = 0;
909 npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq));
910 if (npoints & 4)
911 return(BadLength);
912 npoints >>= 3;
913 if (npoints >= 3)
914 CompositeTriStrip (stuff->op, pSrc, pDst, pFormat,
915 stuff->xSrc, stuff->ySrc,
916 npoints, (xPointFixed *) &stuff[1]);
917 return client->noClientException;
920 static int
921 ProcRenderTriFan (ClientPtr client)
923 int npoints;
924 PicturePtr pSrc, pDst;
925 PictFormatPtr pFormat;
926 REQUEST(xRenderTrianglesReq);
928 REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
929 if (!PictOpValid (stuff->op))
931 client->errorValue = stuff->op;
932 return BadValue;
934 VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess,
935 RenderErrBase + BadPicture);
936 VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess,
937 RenderErrBase + BadPicture);
938 if (!pDst->pDrawable)
939 return BadDrawable;
940 if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
941 return BadMatch;
942 if (stuff->maskFormat)
944 pFormat = (PictFormatPtr) SecurityLookupIDByType (client,
945 stuff->maskFormat,
946 PictFormatType,
947 DixReadAccess);
948 if (!pFormat)
950 client->errorValue = stuff->maskFormat;
951 return RenderErrBase + BadPictFormat;
954 else
955 pFormat = 0;
956 npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq));
957 if (npoints & 4)
958 return(BadLength);
959 npoints >>= 3;
960 if (npoints >= 3)
961 CompositeTriFan (stuff->op, pSrc, pDst, pFormat,
962 stuff->xSrc, stuff->ySrc,
963 npoints, (xPointFixed *) &stuff[1]);
964 return client->noClientException;
967 static int
968 ProcRenderColorTrapezoids (ClientPtr client)
970 return BadImplementation;
973 static int
974 ProcRenderColorTriangles (ClientPtr client)
976 return BadImplementation;
979 static int
980 ProcRenderTransform (ClientPtr client)
982 return BadImplementation;
985 static int
986 ProcRenderCreateGlyphSet (ClientPtr client)
988 GlyphSetPtr glyphSet;
989 PictFormatPtr format;
990 int f;
991 REQUEST(xRenderCreateGlyphSetReq);
993 REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq);
995 LEGAL_NEW_RESOURCE(stuff->gsid, client);
996 format = (PictFormatPtr) SecurityLookupIDByType (client,
997 stuff->format,
998 PictFormatType,
999 DixReadAccess);
1000 if (!format)
1002 client->errorValue = stuff->format;
1003 return RenderErrBase + BadPictFormat;
1005 switch (format->depth) {
1006 case 1:
1007 f = GlyphFormat1;
1008 break;
1009 case 4:
1010 f = GlyphFormat4;
1011 break;
1012 case 8:
1013 f = GlyphFormat8;
1014 break;
1015 case 16:
1016 f = GlyphFormat16;
1017 break;
1018 case 32:
1019 f = GlyphFormat32;
1020 break;
1021 default:
1022 return BadMatch;
1024 if (format->type != PictTypeDirect)
1025 return BadMatch;
1026 glyphSet = AllocateGlyphSet (f, format);
1027 if (!glyphSet)
1028 return BadAlloc;
1029 if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet))
1030 return BadAlloc;
1031 return Success;
1034 static int
1035 ProcRenderReferenceGlyphSet (ClientPtr client)
1037 GlyphSetPtr glyphSet;
1038 REQUEST(xRenderReferenceGlyphSetReq);
1040 REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq);
1042 LEGAL_NEW_RESOURCE(stuff->gsid, client);
1044 glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
1045 stuff->existing,
1046 GlyphSetType,
1047 DixWriteAccess);
1048 if (!glyphSet)
1050 client->errorValue = stuff->existing;
1051 return RenderErrBase + BadGlyphSet;
1053 glyphSet->refcnt++;
1054 if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet))
1055 return BadAlloc;
1056 return client->noClientException;
1059 #define NLOCALDELTA 64
1060 #define NLOCALGLYPH 256
1062 static int
1063 ProcRenderFreeGlyphSet (ClientPtr client)
1065 GlyphSetPtr glyphSet;
1066 REQUEST(xRenderFreeGlyphSetReq);
1068 REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq);
1069 glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
1070 stuff->glyphset,
1071 GlyphSetType,
1072 DixDestroyAccess);
1073 if (!glyphSet)
1075 client->errorValue = stuff->glyphset;
1076 return RenderErrBase + BadGlyphSet;
1078 FreeResource (stuff->glyphset, RT_NONE);
1079 return client->noClientException;
1082 typedef struct _GlyphNew {
1083 Glyph id;
1084 GlyphPtr glyph;
1085 } GlyphNewRec, *GlyphNewPtr;
1087 static int
1088 ProcRenderAddGlyphs (ClientPtr client)
1090 GlyphSetPtr glyphSet;
1091 REQUEST(xRenderAddGlyphsReq);
1092 GlyphNewRec glyphsLocal[NLOCALGLYPH];
1093 GlyphNewPtr glyphsBase, glyphs;
1094 GlyphPtr glyph;
1095 int remain, nglyphs;
1096 CARD32 *gids;
1097 xGlyphInfo *gi;
1098 CARD8 *bits;
1099 int size;
1100 int err = BadAlloc;
1102 REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq);
1103 glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
1104 stuff->glyphset,
1105 GlyphSetType,
1106 DixWriteAccess);
1107 if (!glyphSet)
1109 client->errorValue = stuff->glyphset;
1110 return RenderErrBase + BadGlyphSet;
1113 nglyphs = stuff->nglyphs;
1114 if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec))
1115 return BadAlloc;
1117 if (nglyphs <= NLOCALGLYPH)
1118 glyphsBase = glyphsLocal;
1119 else
1121 glyphsBase = (GlyphNewPtr) Xalloc (nglyphs * sizeof (GlyphNewRec));
1122 if (!glyphsBase)
1123 return BadAlloc;
1126 remain = (client->req_len << 2) - sizeof (xRenderAddGlyphsReq);
1128 glyphs = glyphsBase;
1130 gids = (CARD32 *) (stuff + 1);
1131 gi = (xGlyphInfo *) (gids + nglyphs);
1132 bits = (CARD8 *) (gi + nglyphs);
1133 remain -= (sizeof (CARD32) + sizeof (xGlyphInfo)) * nglyphs;
1134 while (remain >= 0 && nglyphs)
1136 glyph = AllocateGlyph (gi, glyphSet->fdepth);
1137 if (!glyph)
1139 err = BadAlloc;
1140 goto bail;
1143 glyphs->glyph = glyph;
1144 glyphs->id = *gids;
1146 size = glyph->size - sizeof (xGlyphInfo);
1147 if (remain < size)
1148 break;
1149 memcpy ((CARD8 *) (glyph + 1), bits, size);
1151 if (size & 3)
1152 size += 4 - (size & 3);
1153 bits += size;
1154 remain -= size;
1155 gi++;
1156 gids++;
1157 glyphs++;
1158 nglyphs--;
1160 if (nglyphs || remain)
1162 err = BadLength;
1163 goto bail;
1165 nglyphs = stuff->nglyphs;
1166 if (!ResizeGlyphSet (glyphSet, nglyphs))
1168 err = BadAlloc;
1169 goto bail;
1171 glyphs = glyphsBase;
1172 while (nglyphs--) {
1173 AddGlyph (glyphSet, glyphs->glyph, glyphs->id);
1174 glyphs++;
1177 if (glyphsBase != glyphsLocal)
1178 Xfree (glyphsBase);
1179 return client->noClientException;
1180 bail:
1181 while (glyphs != glyphsBase)
1183 --glyphs;
1184 xfree (glyphs->glyph);
1186 if (glyphsBase != glyphsLocal)
1187 Xfree (glyphsBase);
1188 return err;
1191 static int
1192 ProcRenderAddGlyphsFromPicture (ClientPtr client)
1194 return BadImplementation;
1197 static int
1198 ProcRenderFreeGlyphs (ClientPtr client)
1200 REQUEST(xRenderFreeGlyphsReq);
1201 GlyphSetPtr glyphSet;
1202 int nglyph;
1203 CARD32 *gids;
1204 CARD32 glyph;
1206 REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq);
1207 glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
1208 stuff->glyphset,
1209 GlyphSetType,
1210 DixWriteAccess);
1211 if (!glyphSet)
1213 client->errorValue = stuff->glyphset;
1214 return RenderErrBase + BadGlyphSet;
1216 nglyph = ((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)) >> 2;
1217 gids = (CARD32 *) (stuff + 1);
1218 while (nglyph-- > 0)
1220 glyph = *gids++;
1221 if (!DeleteGlyph (glyphSet, glyph))
1223 client->errorValue = glyph;
1224 return RenderErrBase + BadGlyph;
1227 return client->noClientException;
1230 static int
1231 ProcRenderCompositeGlyphs (ClientPtr client)
1233 GlyphSetPtr glyphSet;
1234 GlyphSet gs;
1235 PicturePtr pSrc, pDst;
1236 PictFormatPtr pFormat;
1237 GlyphListRec listsLocal[NLOCALDELTA];
1238 GlyphListPtr lists, listsBase;
1239 GlyphPtr glyphsLocal[NLOCALGLYPH];
1240 Glyph glyph;
1241 GlyphPtr *glyphs, *glyphsBase;
1242 xGlyphElt *elt;
1243 CARD8 *buffer, *end;
1244 int nglyph;
1245 int nlist;
1246 int space;
1247 int size;
1248 int n;
1250 REQUEST(xRenderCompositeGlyphsReq);
1252 REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq);
1254 switch (stuff->renderReqType) {
1255 default: size = 1; break;
1256 case X_RenderCompositeGlyphs16: size = 2; break;
1257 case X_RenderCompositeGlyphs32: size = 4; break;
1260 if (!PictOpValid (stuff->op))
1262 client->errorValue = stuff->op;
1263 return BadValue;
1265 VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess,
1266 RenderErrBase + BadPicture);
1267 VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess,
1268 RenderErrBase + BadPicture);
1269 if (!pDst->pDrawable)
1270 return BadDrawable;
1271 if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
1272 return BadMatch;
1273 if (stuff->maskFormat)
1275 pFormat = (PictFormatPtr) SecurityLookupIDByType (client,
1276 stuff->maskFormat,
1277 PictFormatType,
1278 DixReadAccess);
1279 if (!pFormat)
1281 client->errorValue = stuff->maskFormat;
1282 return RenderErrBase + BadPictFormat;
1285 else
1286 pFormat = 0;
1288 glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
1289 stuff->glyphset,
1290 GlyphSetType,
1291 DixReadAccess);
1292 if (!glyphSet)
1294 client->errorValue = stuff->glyphset;
1295 return RenderErrBase + BadGlyphSet;
1298 buffer = (CARD8 *) (stuff + 1);
1299 end = (CARD8 *) stuff + (client->req_len << 2);
1300 nglyph = 0;
1301 nlist = 0;
1302 while (buffer + sizeof (xGlyphElt) < end)
1304 elt = (xGlyphElt *) buffer;
1305 buffer += sizeof (xGlyphElt);
1307 if (elt->len == 0xff)
1309 buffer += 4;
1311 else
1313 nlist++;
1314 nglyph += elt->len;
1315 space = size * elt->len;
1316 if (space & 3)
1317 space += 4 - (space & 3);
1318 buffer += space;
1321 if (nglyph <= NLOCALGLYPH)
1322 glyphsBase = glyphsLocal;
1323 else
1325 glyphsBase = (GlyphPtr *) ALLOCATE_LOCAL (nglyph * sizeof (GlyphPtr));
1326 if (!glyphsBase)
1327 return BadAlloc;
1329 if (nlist <= NLOCALDELTA)
1330 listsBase = listsLocal;
1331 else
1333 listsBase = (GlyphListPtr) ALLOCATE_LOCAL (nlist * sizeof (GlyphListRec));
1334 if (!listsBase)
1335 return BadAlloc;
1337 buffer = (CARD8 *) (stuff + 1);
1338 glyphs = glyphsBase;
1339 lists = listsBase;
1340 while (buffer + sizeof (xGlyphElt) < end)
1342 elt = (xGlyphElt *) buffer;
1343 buffer += sizeof (xGlyphElt);
1345 if (elt->len == 0xff)
1347 if (buffer + sizeof (GlyphSet) < end)
1349 memcpy(&gs, buffer, sizeof(GlyphSet));
1350 glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
1352 GlyphSetType,
1353 DixReadAccess);
1354 if (!glyphSet)
1356 client->errorValue = gs;
1357 if (glyphsBase != glyphsLocal)
1358 DEALLOCATE_LOCAL (glyphsBase);
1359 if (listsBase != listsLocal)
1360 DEALLOCATE_LOCAL (listsBase);
1361 return RenderErrBase + BadGlyphSet;
1364 buffer += 4;
1366 else
1368 lists->xOff = elt->deltax;
1369 lists->yOff = elt->deltay;
1370 lists->format = glyphSet->format;
1371 lists->len = 0;
1372 n = elt->len;
1373 while (n--)
1375 if (buffer + size <= end)
1377 switch (size) {
1378 case 1:
1379 glyph = *((CARD8 *)buffer); break;
1380 case 2:
1381 glyph = *((CARD16 *)buffer); break;
1382 case 4:
1383 default:
1384 glyph = *((CARD32 *)buffer); break;
1386 if ((*glyphs = FindGlyph (glyphSet, glyph)))
1388 lists->len++;
1389 glyphs++;
1392 buffer += size;
1394 space = size * elt->len;
1395 if (space & 3)
1396 buffer += 4 - (space & 3);
1397 lists++;
1400 if (buffer > end)
1401 return BadLength;
1403 CompositeGlyphs (stuff->op,
1404 pSrc,
1405 pDst,
1406 pFormat,
1407 stuff->xSrc,
1408 stuff->ySrc,
1409 nlist,
1410 listsBase,
1411 glyphsBase);
1413 if (glyphsBase != glyphsLocal)
1414 DEALLOCATE_LOCAL (glyphsBase);
1415 if (listsBase != listsLocal)
1416 DEALLOCATE_LOCAL (listsBase);
1418 return client->noClientException;
1421 static int
1422 ProcRenderFillRectangles (ClientPtr client)
1424 PicturePtr pDst;
1425 int things;
1426 REQUEST(xRenderFillRectanglesReq);
1428 REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq);
1429 if (!PictOpValid (stuff->op))
1431 client->errorValue = stuff->op;
1432 return BadValue;
1434 VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess,
1435 RenderErrBase + BadPicture);
1436 if (!pDst->pDrawable)
1437 return BadDrawable;
1439 things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq);
1440 if (things & 4)
1441 return(BadLength);
1442 things >>= 3;
1444 CompositeRects (stuff->op,
1445 pDst,
1446 &stuff->color,
1447 things,
1448 (xRectangle *) &stuff[1]);
1450 return client->noClientException;
1453 static void
1454 SetBit (unsigned char *line, int x, int bit)
1456 unsigned char mask;
1458 if (screenInfo.bitmapBitOrder == LSBFirst)
1459 mask = (1 << (x & 7));
1460 else
1461 mask = (0x80 >> (x & 7));
1462 /* XXX assumes byte order is host byte order */
1463 line += (x >> 3);
1464 if (bit)
1465 *line |= mask;
1466 else
1467 *line &= ~mask;
1470 #define DITHER_DIM 2
1472 static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = {
1473 { 1, 3, },
1474 { 4, 2, },
1477 #define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1)
1479 static int
1480 ProcRenderCreateCursor (ClientPtr client)
1482 REQUEST(xRenderCreateCursorReq);
1483 PicturePtr pSrc;
1484 ScreenPtr pScreen;
1485 unsigned short width, height;
1486 CARD32 *argbbits, *argb;
1487 unsigned char *srcbits, *srcline;
1488 unsigned char *mskbits, *mskline;
1489 int stride;
1490 int x, y;
1491 int nbytes_mono;
1492 CursorMetricRec cm;
1493 CursorPtr pCursor;
1494 CARD32 twocolor[3];
1495 int ncolor;
1497 REQUEST_SIZE_MATCH (xRenderCreateCursorReq);
1498 LEGAL_NEW_RESOURCE(stuff->cid, client);
1500 VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess,
1501 RenderErrBase + BadPicture);
1502 if (!pSrc->pDrawable)
1503 return BadDrawable;
1504 pScreen = pSrc->pDrawable->pScreen;
1505 width = pSrc->pDrawable->width;
1506 height = pSrc->pDrawable->height;
1507 if ( stuff->x > width
1508 || stuff->y > height )
1509 return (BadMatch);
1510 argbbits = xalloc (width * height * sizeof (CARD32));
1511 if (!argbbits)
1512 return (BadAlloc);
1514 stride = BitmapBytePad(width);
1515 nbytes_mono = stride*height;
1516 srcbits = (unsigned char *)xalloc(nbytes_mono);
1517 if (!srcbits)
1519 xfree (argbbits);
1520 return (BadAlloc);
1522 mskbits = (unsigned char *)xalloc(nbytes_mono);
1523 if (!mskbits)
1525 xfree(argbbits);
1526 xfree(srcbits);
1527 return (BadAlloc);
1529 bzero ((char *) mskbits, nbytes_mono);
1530 bzero ((char *) srcbits, nbytes_mono);
1532 if (pSrc->format == PICT_a8r8g8b8)
1534 (*pScreen->GetImage) (pSrc->pDrawable,
1535 0, 0, width, height, ZPixmap,
1536 0xffffffff, (pointer) argbbits);
1538 else
1540 PixmapPtr pPixmap;
1541 PicturePtr pPicture;
1542 PictFormatPtr pFormat;
1543 int error;
1545 pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
1546 if (!pFormat)
1548 xfree (argbbits);
1549 xfree (srcbits);
1550 xfree (mskbits);
1551 return (BadImplementation);
1553 pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32);
1554 if (!pPixmap)
1556 xfree (argbbits);
1557 xfree (srcbits);
1558 xfree (mskbits);
1559 return (BadAlloc);
1561 pPicture = CreatePicture (0, &pPixmap->drawable, pFormat, 0, 0,
1562 client, &error);
1563 if (!pPicture)
1565 xfree (argbbits);
1566 xfree (srcbits);
1567 xfree (mskbits);
1568 return error;
1570 (*pScreen->DestroyPixmap) (pPixmap);
1571 CompositePicture (PictOpSrc,
1572 pSrc, 0, pPicture,
1573 0, 0, 0, 0, 0, 0, width, height);
1574 (*pScreen->GetImage) (pPicture->pDrawable,
1575 0, 0, width, height, ZPixmap,
1576 0xffffffff, (pointer) argbbits);
1577 FreePicture (pPicture, 0);
1580 * Check whether the cursor can be directly supported by
1581 * the core cursor code
1583 ncolor = 0;
1584 argb = argbbits;
1585 for (y = 0; ncolor <= 2 && y < height; y++)
1587 for (x = 0; ncolor <= 2 && x < width; x++)
1589 CARD32 p = *argb++;
1590 CARD32 a = (p >> 24);
1592 if (a == 0) /* transparent */
1593 continue;
1594 if (a == 0xff) /* opaque */
1596 int n;
1597 for (n = 0; n < ncolor; n++)
1598 if (p == twocolor[n])
1599 break;
1600 if (n == ncolor)
1601 twocolor[ncolor++] = p;
1603 else
1604 ncolor = 3;
1609 * Convert argb image to two plane cursor
1611 srcline = srcbits;
1612 mskline = mskbits;
1613 argb = argbbits;
1614 for (y = 0; y < height; y++)
1616 for (x = 0; x < width; x++)
1618 CARD32 p = *argb++;
1620 if (ncolor <= 2)
1622 CARD32 a = ((p >> 24));
1624 SetBit (mskline, x, a != 0);
1625 SetBit (srcline, x, a != 0 && p == twocolor[0]);
1627 else
1629 CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255;
1630 CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255;
1631 CARD32 d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)];
1632 /* Set mask from dithered alpha value */
1633 SetBit(mskline, x, a > d);
1634 /* Set src from dithered intensity value */
1635 SetBit(srcline, x, a > d && i <= d);
1638 srcline += stride;
1639 mskline += stride;
1642 * Dither to white and black if the cursor has more than two colors
1644 if (ncolor > 2)
1646 twocolor[0] = 0xff000000;
1647 twocolor[1] = 0xffffffff;
1649 else
1651 xfree (argbbits);
1652 argbbits = 0;
1655 #define GetByte(p,s) (((p) >> (s)) & 0xff)
1656 #define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8))
1658 cm.width = width;
1659 cm.height = height;
1660 cm.xhot = stuff->x;
1661 cm.yhot = stuff->y;
1662 pCursor = AllocCursorARGB (srcbits, mskbits, argbbits, &cm,
1663 GetColor(twocolor[0], 16),
1664 GetColor(twocolor[0], 8),
1665 GetColor(twocolor[0], 0),
1666 GetColor(twocolor[1], 16),
1667 GetColor(twocolor[1], 8),
1668 GetColor(twocolor[1], 0));
1669 if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
1670 return (client->noClientException);
1671 return BadAlloc;
1674 static int
1675 ProcRenderSetPictureTransform (ClientPtr client)
1677 REQUEST(xRenderSetPictureTransformReq);
1678 PicturePtr pPicture;
1679 int result;
1681 REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq);
1682 VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
1683 RenderErrBase + BadPicture);
1684 result = SetPictureTransform (pPicture, (PictTransform *) &stuff->transform);
1685 if (client->noClientException != Success)
1686 return(client->noClientException);
1687 else
1688 return(result);
1691 static int
1692 ProcRenderQueryFilters (ClientPtr client)
1694 REQUEST (xRenderQueryFiltersReq);
1695 DrawablePtr pDrawable;
1696 xRenderQueryFiltersReply *reply;
1697 int nbytesName;
1698 int nnames;
1699 ScreenPtr pScreen;
1700 PictureScreenPtr ps;
1701 int i, j, len, total_bytes, rc;
1702 INT16 *aliases;
1703 char *names;
1705 REQUEST_SIZE_MATCH(xRenderQueryFiltersReq);
1706 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
1707 DixReadAccess);
1708 if (rc != Success)
1709 return rc;
1711 pScreen = pDrawable->pScreen;
1712 nbytesName = 0;
1713 nnames = 0;
1714 ps = GetPictureScreenIfSet(pScreen);
1715 if (ps)
1717 for (i = 0; i < ps->nfilters; i++)
1718 nbytesName += 1 + strlen (ps->filters[i].name);
1719 for (i = 0; i < ps->nfilterAliases; i++)
1720 nbytesName += 1 + strlen (ps->filterAliases[i].alias);
1721 nnames = ps->nfilters + ps->nfilterAliases;
1723 len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2);
1724 total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2);
1725 reply = (xRenderQueryFiltersReply *) xalloc (total_bytes);
1726 if (!reply)
1727 return BadAlloc;
1728 aliases = (INT16 *) (reply + 1);
1729 names = (char *) (aliases + ((nnames + 1) & ~1));
1731 reply->type = X_Reply;
1732 reply->sequenceNumber = client->sequence;
1733 reply->length = len;
1734 reply->numAliases = nnames;
1735 reply->numFilters = nnames;
1736 if (ps)
1739 /* fill in alias values */
1740 for (i = 0; i < ps->nfilters; i++)
1741 aliases[i] = FilterAliasNone;
1742 for (i = 0; i < ps->nfilterAliases; i++)
1744 for (j = 0; j < ps->nfilters; j++)
1745 if (ps->filterAliases[i].filter_id == ps->filters[j].id)
1746 break;
1747 if (j == ps->nfilters)
1749 for (j = 0; j < ps->nfilterAliases; j++)
1750 if (ps->filterAliases[i].filter_id ==
1751 ps->filterAliases[j].alias_id)
1753 break;
1755 if (j == ps->nfilterAliases)
1756 j = FilterAliasNone;
1757 else
1758 j = j + ps->nfilters;
1760 aliases[i + ps->nfilters] = j;
1763 /* fill in filter names */
1764 for (i = 0; i < ps->nfilters; i++)
1766 j = strlen (ps->filters[i].name);
1767 *names++ = j;
1768 strncpy (names, ps->filters[i].name, j);
1769 names += j;
1772 /* fill in filter alias names */
1773 for (i = 0; i < ps->nfilterAliases; i++)
1775 j = strlen (ps->filterAliases[i].alias);
1776 *names++ = j;
1777 strncpy (names, ps->filterAliases[i].alias, j);
1778 names += j;
1782 if (client->swapped)
1784 register int n;
1786 for (i = 0; i < reply->numAliases; i++)
1788 swaps (&aliases[i], n);
1790 swaps(&reply->sequenceNumber, n);
1791 swapl(&reply->length, n);
1792 swapl(&reply->numAliases, n);
1793 swapl(&reply->numFilters, n);
1795 WriteToClient(client, total_bytes, (char *) reply);
1796 xfree (reply);
1798 return(client->noClientException);
1801 static int
1802 ProcRenderSetPictureFilter (ClientPtr client)
1804 REQUEST (xRenderSetPictureFilterReq);
1805 PicturePtr pPicture;
1806 int result;
1807 xFixed *params;
1808 int nparams;
1809 char *name;
1811 REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq);
1812 VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
1813 RenderErrBase + BadPicture);
1814 name = (char *) (stuff + 1);
1815 params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3));
1816 nparams = ((xFixed *) stuff + client->req_len) - params;
1817 result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams);
1818 return result;
1821 static int
1822 ProcRenderCreateAnimCursor (ClientPtr client)
1824 REQUEST(xRenderCreateAnimCursorReq);
1825 CursorPtr *cursors;
1826 CARD32 *deltas;
1827 CursorPtr pCursor;
1828 int ncursor;
1829 xAnimCursorElt *elt;
1830 int i;
1831 int ret;
1833 REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq);
1834 LEGAL_NEW_RESOURCE(stuff->cid, client);
1835 if (client->req_len & 1)
1836 return BadLength;
1837 ncursor = (client->req_len - (SIZEOF(xRenderCreateAnimCursorReq) >> 2)) >> 1;
1838 cursors = xalloc (ncursor * (sizeof (CursorPtr) + sizeof (CARD32)));
1839 if (!cursors)
1840 return BadAlloc;
1841 deltas = (CARD32 *) (cursors + ncursor);
1842 elt = (xAnimCursorElt *) (stuff + 1);
1843 for (i = 0; i < ncursor; i++)
1845 cursors[i] = (CursorPtr)SecurityLookupIDByType(client, elt->cursor,
1846 RT_CURSOR, DixReadAccess);
1847 if (!cursors[i])
1849 xfree (cursors);
1850 client->errorValue = elt->cursor;
1851 return BadCursor;
1853 deltas[i] = elt->delay;
1854 elt++;
1856 ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor);
1857 xfree (cursors);
1858 if (ret != Success)
1859 return ret;
1861 if (AddResource (stuff->cid, RT_CURSOR, (pointer)pCursor))
1862 return client->noClientException;
1863 return BadAlloc;
1866 static int
1867 ProcRenderAddTraps (ClientPtr client)
1869 int ntraps;
1870 PicturePtr pPicture;
1871 REQUEST(xRenderAddTrapsReq);
1873 REQUEST_AT_LEAST_SIZE(xRenderAddTrapsReq);
1874 VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
1875 RenderErrBase + BadPicture);
1876 if (!pPicture->pDrawable)
1877 return BadDrawable;
1878 ntraps = (client->req_len << 2) - sizeof (xRenderAddTrapsReq);
1879 if (ntraps % sizeof (xTrap))
1880 return BadLength;
1881 ntraps /= sizeof (xTrap);
1882 if (ntraps)
1883 AddTraps (pPicture,
1884 stuff->xOff, stuff->yOff,
1885 ntraps, (xTrap *) &stuff[1]);
1886 return client->noClientException;
1889 static int ProcRenderCreateSolidFill(ClientPtr client)
1891 PicturePtr pPicture;
1892 int error = 0;
1893 REQUEST(xRenderCreateSolidFillReq);
1895 REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq);
1897 LEGAL_NEW_RESOURCE(stuff->pid, client);
1899 pPicture = CreateSolidPicture(stuff->pid, &stuff->color, &error);
1900 if (!pPicture)
1901 return error;
1902 if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
1903 return BadAlloc;
1904 return Success;
1907 static int ProcRenderCreateLinearGradient (ClientPtr client)
1909 PicturePtr pPicture;
1910 int len;
1911 int error = 0;
1912 xFixed *stops;
1913 xRenderColor *colors;
1914 REQUEST(xRenderCreateLinearGradientReq);
1916 REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq);
1918 LEGAL_NEW_RESOURCE(stuff->pid, client);
1920 len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq);
1921 if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
1922 return BadLength;
1924 stops = (xFixed *)(stuff + 1);
1925 colors = (xRenderColor *)(stops + stuff->nStops);
1927 pPicture = CreateLinearGradientPicture (stuff->pid, &stuff->p1, &stuff->p2,
1928 stuff->nStops, stops, colors, &error);
1929 if (!pPicture)
1930 return error;
1931 if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
1932 return BadAlloc;
1933 return Success;
1936 static int ProcRenderCreateRadialGradient (ClientPtr client)
1938 PicturePtr pPicture;
1939 int len;
1940 int error = 0;
1941 xFixed *stops;
1942 xRenderColor *colors;
1943 REQUEST(xRenderCreateRadialGradientReq);
1945 REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq);
1947 LEGAL_NEW_RESOURCE(stuff->pid, client);
1949 len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq);
1950 if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
1951 return BadLength;
1953 stops = (xFixed *)(stuff + 1);
1954 colors = (xRenderColor *)(stops + stuff->nStops);
1956 pPicture = CreateRadialGradientPicture (stuff->pid, &stuff->inner, &stuff->outer,
1957 stuff->inner_radius, stuff->outer_radius,
1958 stuff->nStops, stops, colors, &error);
1959 if (!pPicture)
1960 return error;
1961 if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
1962 return BadAlloc;
1963 return Success;
1966 static int ProcRenderCreateConicalGradient (ClientPtr client)
1968 PicturePtr pPicture;
1969 int len;
1970 int error = 0;
1971 xFixed *stops;
1972 xRenderColor *colors;
1973 REQUEST(xRenderCreateConicalGradientReq);
1975 REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq);
1977 LEGAL_NEW_RESOURCE(stuff->pid, client);
1979 len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq);
1980 if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
1981 return BadLength;
1983 stops = (xFixed *)(stuff + 1);
1984 colors = (xRenderColor *)(stops + stuff->nStops);
1986 pPicture = CreateConicalGradientPicture (stuff->pid, &stuff->center, stuff->angle,
1987 stuff->nStops, stops, colors, &error);
1988 if (!pPicture)
1989 return error;
1990 if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
1991 return BadAlloc;
1992 return Success;
1996 static int
1997 ProcRenderDispatch (ClientPtr client)
1999 REQUEST(xReq);
2001 if (stuff->data < RenderNumberRequests)
2002 return (*ProcRenderVector[stuff->data]) (client);
2003 else
2004 return BadRequest;
2007 static int
2008 SProcRenderQueryVersion (ClientPtr client)
2010 register int n;
2011 REQUEST(xRenderQueryVersionReq);
2013 swaps(&stuff->length, n);
2014 swapl(&stuff->majorVersion, n);
2015 swapl(&stuff->minorVersion, n);
2016 return (*ProcRenderVector[stuff->renderReqType])(client);
2019 static int
2020 SProcRenderQueryPictFormats (ClientPtr client)
2022 register int n;
2023 REQUEST(xRenderQueryPictFormatsReq);
2024 swaps(&stuff->length, n);
2025 return (*ProcRenderVector[stuff->renderReqType]) (client);
2028 static int
2029 SProcRenderQueryPictIndexValues (ClientPtr client)
2031 register int n;
2032 REQUEST(xRenderQueryPictIndexValuesReq);
2033 swaps(&stuff->length, n);
2034 swapl(&stuff->format, n);
2035 return (*ProcRenderVector[stuff->renderReqType]) (client);
2038 static int
2039 SProcRenderQueryDithers (ClientPtr client)
2041 return BadImplementation;
2044 static int
2045 SProcRenderCreatePicture (ClientPtr client)
2047 register int n;
2048 REQUEST(xRenderCreatePictureReq);
2049 swaps(&stuff->length, n);
2050 swapl(&stuff->pid, n);
2051 swapl(&stuff->drawable, n);
2052 swapl(&stuff->format, n);
2053 swapl(&stuff->mask, n);
2054 SwapRestL(stuff);
2055 return (*ProcRenderVector[stuff->renderReqType]) (client);
2058 static int
2059 SProcRenderChangePicture (ClientPtr client)
2061 register int n;
2062 REQUEST(xRenderChangePictureReq);
2063 swaps(&stuff->length, n);
2064 swapl(&stuff->picture, n);
2065 swapl(&stuff->mask, n);
2066 SwapRestL(stuff);
2067 return (*ProcRenderVector[stuff->renderReqType]) (client);
2070 static int
2071 SProcRenderSetPictureClipRectangles (ClientPtr client)
2073 register int n;
2074 REQUEST(xRenderSetPictureClipRectanglesReq);
2075 swaps(&stuff->length, n);
2076 swapl(&stuff->picture, n);
2077 swaps(&stuff->xOrigin, n);
2078 swaps(&stuff->yOrigin, n);
2079 SwapRestS(stuff);
2080 return (*ProcRenderVector[stuff->renderReqType]) (client);
2083 static int
2084 SProcRenderFreePicture (ClientPtr client)
2086 register int n;
2087 REQUEST(xRenderFreePictureReq);
2088 swaps(&stuff->length, n);
2089 swapl(&stuff->picture, n);
2090 return (*ProcRenderVector[stuff->renderReqType]) (client);
2093 static int
2094 SProcRenderComposite (ClientPtr client)
2096 register int n;
2097 REQUEST(xRenderCompositeReq);
2098 swaps(&stuff->length, n);
2099 swapl(&stuff->src, n);
2100 swapl(&stuff->mask, n);
2101 swapl(&stuff->dst, n);
2102 swaps(&stuff->xSrc, n);
2103 swaps(&stuff->ySrc, n);
2104 swaps(&stuff->xMask, n);
2105 swaps(&stuff->yMask, n);
2106 swaps(&stuff->xDst, n);
2107 swaps(&stuff->yDst, n);
2108 swaps(&stuff->width, n);
2109 swaps(&stuff->height, n);
2110 return (*ProcRenderVector[stuff->renderReqType]) (client);
2113 static int
2114 SProcRenderScale (ClientPtr client)
2116 register int n;
2117 REQUEST(xRenderScaleReq);
2118 swaps(&stuff->length, n);
2119 swapl(&stuff->src, n);
2120 swapl(&stuff->dst, n);
2121 swapl(&stuff->colorScale, n);
2122 swapl(&stuff->alphaScale, n);
2123 swaps(&stuff->xSrc, n);
2124 swaps(&stuff->ySrc, n);
2125 swaps(&stuff->xDst, n);
2126 swaps(&stuff->yDst, n);
2127 swaps(&stuff->width, n);
2128 swaps(&stuff->height, n);
2129 return (*ProcRenderVector[stuff->renderReqType]) (client);
2132 static int
2133 SProcRenderTrapezoids (ClientPtr client)
2135 register int n;
2136 REQUEST(xRenderTrapezoidsReq);
2138 REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq);
2139 swaps (&stuff->length, n);
2140 swapl (&stuff->src, n);
2141 swapl (&stuff->dst, n);
2142 swapl (&stuff->maskFormat, n);
2143 swaps (&stuff->xSrc, n);
2144 swaps (&stuff->ySrc, n);
2145 SwapRestL(stuff);
2146 return (*ProcRenderVector[stuff->renderReqType]) (client);
2149 static int
2150 SProcRenderTriangles (ClientPtr client)
2152 register int n;
2153 REQUEST(xRenderTrianglesReq);
2155 REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
2156 swaps (&stuff->length, n);
2157 swapl (&stuff->src, n);
2158 swapl (&stuff->dst, n);
2159 swapl (&stuff->maskFormat, n);
2160 swaps (&stuff->xSrc, n);
2161 swaps (&stuff->ySrc, n);
2162 SwapRestL(stuff);
2163 return (*ProcRenderVector[stuff->renderReqType]) (client);
2166 static int
2167 SProcRenderTriStrip (ClientPtr client)
2169 register int n;
2170 REQUEST(xRenderTriStripReq);
2172 REQUEST_AT_LEAST_SIZE(xRenderTriStripReq);
2173 swaps (&stuff->length, n);
2174 swapl (&stuff->src, n);
2175 swapl (&stuff->dst, n);
2176 swapl (&stuff->maskFormat, n);
2177 swaps (&stuff->xSrc, n);
2178 swaps (&stuff->ySrc, n);
2179 SwapRestL(stuff);
2180 return (*ProcRenderVector[stuff->renderReqType]) (client);
2183 static int
2184 SProcRenderTriFan (ClientPtr client)
2186 register int n;
2187 REQUEST(xRenderTriFanReq);
2189 REQUEST_AT_LEAST_SIZE(xRenderTriFanReq);
2190 swaps (&stuff->length, n);
2191 swapl (&stuff->src, n);
2192 swapl (&stuff->dst, n);
2193 swapl (&stuff->maskFormat, n);
2194 swaps (&stuff->xSrc, n);
2195 swaps (&stuff->ySrc, n);
2196 SwapRestL(stuff);
2197 return (*ProcRenderVector[stuff->renderReqType]) (client);
2200 static int
2201 SProcRenderColorTrapezoids (ClientPtr client)
2203 return BadImplementation;
2206 static int
2207 SProcRenderColorTriangles (ClientPtr client)
2209 return BadImplementation;
2212 static int
2213 SProcRenderTransform (ClientPtr client)
2215 return BadImplementation;
2218 static int
2219 SProcRenderCreateGlyphSet (ClientPtr client)
2221 register int n;
2222 REQUEST(xRenderCreateGlyphSetReq);
2223 swaps(&stuff->length, n);
2224 swapl(&stuff->gsid, n);
2225 swapl(&stuff->format, n);
2226 return (*ProcRenderVector[stuff->renderReqType]) (client);
2229 static int
2230 SProcRenderReferenceGlyphSet (ClientPtr client)
2232 register int n;
2233 REQUEST(xRenderReferenceGlyphSetReq);
2234 swaps(&stuff->length, n);
2235 swapl(&stuff->gsid, n);
2236 swapl(&stuff->existing, n);
2237 return (*ProcRenderVector[stuff->renderReqType]) (client);
2240 static int
2241 SProcRenderFreeGlyphSet (ClientPtr client)
2243 register int n;
2244 REQUEST(xRenderFreeGlyphSetReq);
2245 swaps(&stuff->length, n);
2246 swapl(&stuff->glyphset, n);
2247 return (*ProcRenderVector[stuff->renderReqType]) (client);
2250 static int
2251 SProcRenderAddGlyphs (ClientPtr client)
2253 register int n;
2254 register int i;
2255 CARD32 *gids;
2256 void *end;
2257 xGlyphInfo *gi;
2258 REQUEST(xRenderAddGlyphsReq);
2259 swaps(&stuff->length, n);
2260 swapl(&stuff->glyphset, n);
2261 swapl(&stuff->nglyphs, n);
2262 if (stuff->nglyphs & 0xe0000000)
2263 return BadLength;
2264 end = (CARD8 *) stuff + (client->req_len << 2);
2265 gids = (CARD32 *) (stuff + 1);
2266 gi = (xGlyphInfo *) (gids + stuff->nglyphs);
2267 if ((char *) end - (char *) (gids + stuff->nglyphs) < 0)
2268 return BadLength;
2269 if ((char *) end - (char *) (gi + stuff->nglyphs) < 0)
2270 return BadLength;
2271 for (i = 0; i < stuff->nglyphs; i++)
2273 swapl (&gids[i], n);
2274 swaps (&gi[i].width, n);
2275 swaps (&gi[i].height, n);
2276 swaps (&gi[i].x, n);
2277 swaps (&gi[i].y, n);
2278 swaps (&gi[i].xOff, n);
2279 swaps (&gi[i].yOff, n);
2281 return (*ProcRenderVector[stuff->renderReqType]) (client);
2284 static int
2285 SProcRenderAddGlyphsFromPicture (ClientPtr client)
2287 return BadImplementation;
2290 static int
2291 SProcRenderFreeGlyphs (ClientPtr client)
2293 register int n;
2294 REQUEST(xRenderFreeGlyphsReq);
2295 swaps(&stuff->length, n);
2296 swapl(&stuff->glyphset, n);
2297 SwapRestL(stuff);
2298 return (*ProcRenderVector[stuff->renderReqType]) (client);
2301 static int
2302 SProcRenderCompositeGlyphs (ClientPtr client)
2304 register int n;
2305 xGlyphElt *elt;
2306 CARD8 *buffer;
2307 CARD8 *end;
2308 int space;
2309 int i;
2310 int size;
2312 REQUEST(xRenderCompositeGlyphsReq);
2314 switch (stuff->renderReqType) {
2315 default: size = 1; break;
2316 case X_RenderCompositeGlyphs16: size = 2; break;
2317 case X_RenderCompositeGlyphs32: size = 4; break;
2320 swaps(&stuff->length, n);
2321 swapl(&stuff->src, n);
2322 swapl(&stuff->dst, n);
2323 swapl(&stuff->maskFormat, n);
2324 swapl(&stuff->glyphset, n);
2325 swaps(&stuff->xSrc, n);
2326 swaps(&stuff->ySrc, n);
2327 buffer = (CARD8 *) (stuff + 1);
2328 end = (CARD8 *) stuff + (client->req_len << 2);
2329 while (buffer + sizeof (xGlyphElt) < end)
2331 elt = (xGlyphElt *) buffer;
2332 buffer += sizeof (xGlyphElt);
2334 swaps (&elt->deltax, n);
2335 swaps (&elt->deltay, n);
2337 i = elt->len;
2338 if (i == 0xff)
2340 swapl (buffer, n);
2341 buffer += 4;
2343 else
2345 space = size * i;
2346 switch (size) {
2347 case 1:
2348 buffer += i;
2349 break;
2350 case 2:
2351 while (i--)
2353 swaps (buffer, n);
2354 buffer += 2;
2356 break;
2357 case 4:
2358 while (i--)
2360 swapl (buffer, n);
2361 buffer += 4;
2363 break;
2365 if (space & 3)
2366 buffer += 4 - (space & 3);
2369 return (*ProcRenderVector[stuff->renderReqType]) (client);
2372 static int
2373 SProcRenderFillRectangles (ClientPtr client)
2375 register int n;
2376 REQUEST(xRenderFillRectanglesReq);
2378 REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq);
2379 swaps(&stuff->length, n);
2380 swapl(&stuff->dst, n);
2381 swaps(&stuff->color.red, n);
2382 swaps(&stuff->color.green, n);
2383 swaps(&stuff->color.blue, n);
2384 swaps(&stuff->color.alpha, n);
2385 SwapRestS(stuff);
2386 return (*ProcRenderVector[stuff->renderReqType]) (client);
2389 static int
2390 SProcRenderCreateCursor (ClientPtr client)
2392 register int n;
2393 REQUEST(xRenderCreateCursorReq);
2394 REQUEST_SIZE_MATCH (xRenderCreateCursorReq);
2396 swaps(&stuff->length, n);
2397 swapl(&stuff->cid, n);
2398 swapl(&stuff->src, n);
2399 swaps(&stuff->x, n);
2400 swaps(&stuff->y, n);
2401 return (*ProcRenderVector[stuff->renderReqType]) (client);
2404 static int
2405 SProcRenderSetPictureTransform (ClientPtr client)
2407 register int n;
2408 REQUEST(xRenderSetPictureTransformReq);
2409 REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq);
2411 swaps(&stuff->length, n);
2412 swapl(&stuff->picture, n);
2413 swapl(&stuff->transform.matrix11, n);
2414 swapl(&stuff->transform.matrix12, n);
2415 swapl(&stuff->transform.matrix13, n);
2416 swapl(&stuff->transform.matrix21, n);
2417 swapl(&stuff->transform.matrix22, n);
2418 swapl(&stuff->transform.matrix23, n);
2419 swapl(&stuff->transform.matrix31, n);
2420 swapl(&stuff->transform.matrix32, n);
2421 swapl(&stuff->transform.matrix33, n);
2422 return (*ProcRenderVector[stuff->renderReqType]) (client);
2425 static int
2426 SProcRenderQueryFilters (ClientPtr client)
2428 register int n;
2429 REQUEST (xRenderQueryFiltersReq);
2430 REQUEST_SIZE_MATCH (xRenderQueryFiltersReq);
2432 swaps(&stuff->length, n);
2433 swapl(&stuff->drawable, n);
2434 return (*ProcRenderVector[stuff->renderReqType]) (client);
2437 static int
2438 SProcRenderSetPictureFilter (ClientPtr client)
2440 register int n;
2441 REQUEST (xRenderSetPictureFilterReq);
2442 REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq);
2444 swaps(&stuff->length, n);
2445 swapl(&stuff->picture, n);
2446 swaps(&stuff->nbytes, n);
2447 return (*ProcRenderVector[stuff->renderReqType]) (client);
2450 static int
2451 SProcRenderCreateAnimCursor (ClientPtr client)
2453 register int n;
2454 REQUEST (xRenderCreateAnimCursorReq);
2455 REQUEST_AT_LEAST_SIZE (xRenderCreateAnimCursorReq);
2457 swaps(&stuff->length, n);
2458 swapl(&stuff->cid, n);
2459 SwapRestL(stuff);
2460 return (*ProcRenderVector[stuff->renderReqType]) (client);
2463 static int
2464 SProcRenderAddTraps (ClientPtr client)
2466 register int n;
2467 REQUEST (xRenderAddTrapsReq);
2468 REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq);
2470 swaps(&stuff->length, n);
2471 swapl(&stuff->picture, n);
2472 swaps(&stuff->xOff, n);
2473 swaps(&stuff->yOff, n);
2474 SwapRestL(stuff);
2475 return (*ProcRenderVector[stuff->renderReqType]) (client);
2478 static int
2479 SProcRenderCreateSolidFill(ClientPtr client)
2481 register int n;
2482 REQUEST (xRenderCreateSolidFillReq);
2483 REQUEST_AT_LEAST_SIZE (xRenderCreateSolidFillReq);
2485 swaps(&stuff->length, n);
2486 swapl(&stuff->pid, n);
2487 swaps(&stuff->color.alpha, n);
2488 swaps(&stuff->color.red, n);
2489 swaps(&stuff->color.green, n);
2490 swaps(&stuff->color.blue, n);
2491 return (*ProcRenderVector[stuff->renderReqType]) (client);
2494 static void swapStops(void *stuff, int n)
2496 int i;
2497 CARD32 *stops;
2498 CARD16 *colors;
2499 stops = (CARD32 *)(stuff);
2500 for (i = 0; i < n; ++i) {
2501 swapl(stops, n);
2502 ++stops;
2504 colors = (CARD16 *)(stops);
2505 for (i = 0; i < 4*n; ++i) {
2506 swaps(stops, n);
2507 ++stops;
2511 static int
2512 SProcRenderCreateLinearGradient (ClientPtr client)
2514 register int n;
2515 int len;
2516 REQUEST (xRenderCreateLinearGradientReq);
2517 REQUEST_AT_LEAST_SIZE (xRenderCreateLinearGradientReq);
2519 swaps(&stuff->length, n);
2520 swapl(&stuff->pid, n);
2521 swapl(&stuff->p1.x, n);
2522 swapl(&stuff->p1.y, n);
2523 swapl(&stuff->p2.x, n);
2524 swapl(&stuff->p2.y, n);
2525 swapl(&stuff->nStops, n);
2527 len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq);
2528 if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
2529 return BadLength;
2531 swapStops(stuff+1, stuff->nStops);
2533 return (*ProcRenderVector[stuff->renderReqType]) (client);
2536 static int
2537 SProcRenderCreateRadialGradient (ClientPtr client)
2539 register int n;
2540 int len;
2541 REQUEST (xRenderCreateRadialGradientReq);
2542 REQUEST_AT_LEAST_SIZE (xRenderCreateRadialGradientReq);
2544 swaps(&stuff->length, n);
2545 swapl(&stuff->pid, n);
2546 swapl(&stuff->inner.x, n);
2547 swapl(&stuff->inner.y, n);
2548 swapl(&stuff->outer.x, n);
2549 swapl(&stuff->outer.y, n);
2550 swapl(&stuff->inner_radius, n);
2551 swapl(&stuff->outer_radius, n);
2552 swapl(&stuff->nStops, n);
2554 len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq);
2555 if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
2556 return BadLength;
2558 swapStops(stuff+1, stuff->nStops);
2560 return (*ProcRenderVector[stuff->renderReqType]) (client);
2563 static int
2564 SProcRenderCreateConicalGradient (ClientPtr client)
2566 register int n;
2567 int len;
2568 REQUEST (xRenderCreateConicalGradientReq);
2569 REQUEST_AT_LEAST_SIZE (xRenderCreateConicalGradientReq);
2571 swaps(&stuff->length, n);
2572 swapl(&stuff->pid, n);
2573 swapl(&stuff->center.x, n);
2574 swapl(&stuff->center.y, n);
2575 swapl(&stuff->angle, n);
2576 swapl(&stuff->nStops, n);
2578 len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq);
2579 if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
2580 return BadLength;
2582 swapStops(stuff+1, stuff->nStops);
2584 return (*ProcRenderVector[stuff->renderReqType]) (client);
2587 static int
2588 SProcRenderDispatch (ClientPtr client)
2590 REQUEST(xReq);
2592 if (stuff->data < RenderNumberRequests)
2593 return (*SProcRenderVector[stuff->data]) (client);
2594 else
2595 return BadRequest;
2598 #ifdef PANORAMIX
2599 #include "panoramiX.h"
2600 #include "panoramiXsrv.h"
2602 #define VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err) {\
2603 pPicture = SecurityLookupIDByType(client, pid, XRT_PICTURE, mode);\
2604 if (!pPicture) { \
2605 client->errorValue = pid; \
2606 return err; \
2610 #define VERIFY_XIN_ALPHA(pPicture, pid, client, mode, err) {\
2611 if (pid == None) \
2612 pPicture = 0; \
2613 else { \
2614 VERIFY_XIN_PICTURE(pPicture, pid, client, mode, err); \
2618 int (*PanoramiXSaveRenderVector[RenderNumberRequests])(ClientPtr);
2620 unsigned long XRT_PICTURE;
2622 static int
2623 PanoramiXRenderCreatePicture (ClientPtr client)
2625 REQUEST(xRenderCreatePictureReq);
2626 PanoramiXRes *refDraw, *newPict;
2627 int result = Success, j;
2629 REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq);
2630 if(!(refDraw = (PanoramiXRes *)SecurityLookupIDByClass(
2631 client, stuff->drawable, XRC_DRAWABLE, DixWriteAccess)))
2632 return BadDrawable;
2633 if(!(newPict = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes))))
2634 return BadAlloc;
2635 newPict->type = XRT_PICTURE;
2636 newPict->info[0].id = stuff->pid;
2638 if (refDraw->type == XRT_WINDOW &&
2639 stuff->drawable == WindowTable[0]->drawable.id)
2641 newPict->u.pict.root = TRUE;
2643 else
2644 newPict->u.pict.root = FALSE;
2646 for(j = 1; j < PanoramiXNumScreens; j++)
2647 newPict->info[j].id = FakeClientID(client->index);
2649 FOR_NSCREENS_BACKWARD(j) {
2650 stuff->pid = newPict->info[j].id;
2651 stuff->drawable = refDraw->info[j].id;
2652 result = (*PanoramiXSaveRenderVector[X_RenderCreatePicture]) (client);
2653 if(result != Success) break;
2656 if (result == Success)
2657 AddResource(newPict->info[0].id, XRT_PICTURE, newPict);
2658 else
2659 xfree(newPict);
2661 return (result);
2664 static int
2665 PanoramiXRenderChangePicture (ClientPtr client)
2667 PanoramiXRes *pict;
2668 int result = Success, j;
2669 REQUEST(xRenderChangePictureReq);
2671 REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
2673 VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess,
2674 RenderErrBase + BadPicture);
2676 FOR_NSCREENS_BACKWARD(j) {
2677 stuff->picture = pict->info[j].id;
2678 result = (*PanoramiXSaveRenderVector[X_RenderChangePicture]) (client);
2679 if(result != Success) break;
2682 return (result);
2685 static int
2686 PanoramiXRenderSetPictureClipRectangles (ClientPtr client)
2688 REQUEST(xRenderSetPictureClipRectanglesReq);
2689 int result = Success, j;
2690 PanoramiXRes *pict;
2692 REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq);
2694 VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess,
2695 RenderErrBase + BadPicture);
2697 FOR_NSCREENS_BACKWARD(j) {
2698 stuff->picture = pict->info[j].id;
2699 result = (*PanoramiXSaveRenderVector[X_RenderSetPictureClipRectangles]) (client);
2700 if(result != Success) break;
2703 return (result);
2706 static int
2707 PanoramiXRenderSetPictureTransform (ClientPtr client)
2709 REQUEST(xRenderSetPictureTransformReq);
2710 int result = Success, j;
2711 PanoramiXRes *pict;
2713 REQUEST_AT_LEAST_SIZE(xRenderSetPictureTransformReq);
2715 VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess,
2716 RenderErrBase + BadPicture);
2718 FOR_NSCREENS_BACKWARD(j) {
2719 stuff->picture = pict->info[j].id;
2720 result = (*PanoramiXSaveRenderVector[X_RenderSetPictureTransform]) (client);
2721 if(result != Success) break;
2724 return (result);
2727 static int
2728 PanoramiXRenderSetPictureFilter (ClientPtr client)
2730 REQUEST(xRenderSetPictureFilterReq);
2731 int result = Success, j;
2732 PanoramiXRes *pict;
2734 REQUEST_AT_LEAST_SIZE(xRenderSetPictureFilterReq);
2736 VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess,
2737 RenderErrBase + BadPicture);
2739 FOR_NSCREENS_BACKWARD(j) {
2740 stuff->picture = pict->info[j].id;
2741 result = (*PanoramiXSaveRenderVector[X_RenderSetPictureFilter]) (client);
2742 if(result != Success) break;
2745 return (result);
2748 static int
2749 PanoramiXRenderFreePicture (ClientPtr client)
2751 PanoramiXRes *pict;
2752 int result = Success, j;
2753 REQUEST(xRenderFreePictureReq);
2755 REQUEST_SIZE_MATCH(xRenderFreePictureReq);
2757 client->errorValue = stuff->picture;
2759 VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixDestroyAccess,
2760 RenderErrBase + BadPicture);
2763 FOR_NSCREENS_BACKWARD(j) {
2764 stuff->picture = pict->info[j].id;
2765 result = (*PanoramiXSaveRenderVector[X_RenderFreePicture]) (client);
2766 if(result != Success) break;
2769 /* Since ProcRenderFreePicture is using FreeResource, it will free
2770 our resource for us on the last pass through the loop above */
2772 return (result);
2775 static int
2776 PanoramiXRenderComposite (ClientPtr client)
2778 PanoramiXRes *src, *msk, *dst;
2779 int result = Success, j;
2780 xRenderCompositeReq orig;
2781 REQUEST(xRenderCompositeReq);
2783 REQUEST_SIZE_MATCH(xRenderCompositeReq);
2785 VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess,
2786 RenderErrBase + BadPicture);
2787 VERIFY_XIN_ALPHA (msk, stuff->mask, client, DixReadAccess,
2788 RenderErrBase + BadPicture);
2789 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
2790 RenderErrBase + BadPicture);
2792 orig = *stuff;
2794 FOR_NSCREENS_FORWARD(j) {
2795 stuff->src = src->info[j].id;
2796 if (src->u.pict.root)
2798 stuff->xSrc = orig.xSrc - panoramiXdataPtr[j].x;
2799 stuff->ySrc = orig.ySrc - panoramiXdataPtr[j].y;
2801 stuff->dst = dst->info[j].id;
2802 if (dst->u.pict.root)
2804 stuff->xDst = orig.xDst - panoramiXdataPtr[j].x;
2805 stuff->yDst = orig.yDst - panoramiXdataPtr[j].y;
2807 if (msk)
2809 stuff->mask = msk->info[j].id;
2810 if (msk->u.pict.root)
2812 stuff->xMask = orig.xMask - panoramiXdataPtr[j].x;
2813 stuff->yMask = orig.yMask - panoramiXdataPtr[j].y;
2816 result = (*PanoramiXSaveRenderVector[X_RenderComposite]) (client);
2817 if(result != Success) break;
2820 return result;
2823 static int
2824 PanoramiXRenderCompositeGlyphs (ClientPtr client)
2826 PanoramiXRes *src, *dst;
2827 int result = Success, j;
2828 REQUEST(xRenderCompositeGlyphsReq);
2829 xGlyphElt origElt, *elt;
2830 INT16 xSrc, ySrc;
2832 REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq);
2833 VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess,
2834 RenderErrBase + BadPicture);
2835 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
2836 RenderErrBase + BadPicture);
2838 if (client->req_len << 2 >= (sizeof (xRenderCompositeGlyphsReq) +
2839 sizeof (xGlyphElt)))
2841 elt = (xGlyphElt *) (stuff + 1);
2842 origElt = *elt;
2843 xSrc = stuff->xSrc;
2844 ySrc = stuff->ySrc;
2845 FOR_NSCREENS_FORWARD(j) {
2846 stuff->src = src->info[j].id;
2847 if (src->u.pict.root)
2849 stuff->xSrc = xSrc - panoramiXdataPtr[j].x;
2850 stuff->ySrc = ySrc - panoramiXdataPtr[j].y;
2852 stuff->dst = dst->info[j].id;
2853 if (dst->u.pict.root)
2855 elt->deltax = origElt.deltax - panoramiXdataPtr[j].x;
2856 elt->deltay = origElt.deltay - panoramiXdataPtr[j].y;
2858 result = (*PanoramiXSaveRenderVector[stuff->renderReqType]) (client);
2859 if(result != Success) break;
2863 return result;
2866 static int
2867 PanoramiXRenderFillRectangles (ClientPtr client)
2869 PanoramiXRes *dst;
2870 int result = Success, j;
2871 REQUEST(xRenderFillRectanglesReq);
2872 char *extra;
2873 int extra_len;
2875 REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq);
2876 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
2877 RenderErrBase + BadPicture);
2878 extra_len = (client->req_len << 2) - sizeof (xRenderFillRectanglesReq);
2879 if (extra_len &&
2880 (extra = (char *) ALLOCATE_LOCAL (extra_len)))
2882 memcpy (extra, stuff + 1, extra_len);
2883 FOR_NSCREENS_FORWARD(j) {
2884 if (j) memcpy (stuff + 1, extra, extra_len);
2885 if (dst->u.pict.root)
2887 int x_off = panoramiXdataPtr[j].x;
2888 int y_off = panoramiXdataPtr[j].y;
2890 if(x_off || y_off) {
2891 xRectangle *rects = (xRectangle *) (stuff + 1);
2892 int i = extra_len / sizeof (xRectangle);
2894 while (i--)
2896 rects->x -= x_off;
2897 rects->y -= y_off;
2898 rects++;
2902 stuff->dst = dst->info[j].id;
2903 result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client);
2904 if(result != Success) break;
2906 DEALLOCATE_LOCAL(extra);
2909 return result;
2912 static int
2913 PanoramiXRenderTrapezoids(ClientPtr client)
2915 PanoramiXRes *src, *dst;
2916 int result = Success, j;
2917 REQUEST(xRenderTrapezoidsReq);
2918 char *extra;
2919 int extra_len;
2921 REQUEST_AT_LEAST_SIZE (xRenderTrapezoidsReq);
2923 VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess,
2924 RenderErrBase + BadPicture);
2925 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
2926 RenderErrBase + BadPicture);
2928 extra_len = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq);
2930 if (extra_len &&
2931 (extra = (char *) ALLOCATE_LOCAL (extra_len))) {
2932 memcpy (extra, stuff + 1, extra_len);
2934 FOR_NSCREENS_FORWARD(j) {
2935 if (j) memcpy (stuff + 1, extra, extra_len);
2936 if (dst->u.pict.root) {
2937 int x_off = panoramiXdataPtr[j].x;
2938 int y_off = panoramiXdataPtr[j].y;
2940 if(x_off || y_off) {
2941 xTrapezoid *trap = (xTrapezoid *) (stuff + 1);
2942 int i = extra_len / sizeof (xTrapezoid);
2944 while (i--) {
2945 trap->top -= y_off;
2946 trap->bottom -= y_off;
2947 trap->left.p1.x -= x_off;
2948 trap->left.p1.y -= y_off;
2949 trap->left.p2.x -= x_off;
2950 trap->left.p2.y -= y_off;
2951 trap->right.p1.x -= x_off;
2952 trap->right.p1.y -= y_off;
2953 trap->right.p2.x -= x_off;
2954 trap->right.p2.y -= y_off;
2955 trap++;
2960 stuff->src = src->info[j].id;
2961 stuff->dst = dst->info[j].id;
2962 result =
2963 (*PanoramiXSaveRenderVector[X_RenderTrapezoids]) (client);
2965 if(result != Success) break;
2968 DEALLOCATE_LOCAL(extra);
2971 return result;
2974 static int
2975 PanoramiXRenderTriangles(ClientPtr client)
2977 PanoramiXRes *src, *dst;
2978 int result = Success, j;
2979 REQUEST(xRenderTrianglesReq);
2980 char *extra;
2981 int extra_len;
2983 REQUEST_AT_LEAST_SIZE (xRenderTrianglesReq);
2985 VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess,
2986 RenderErrBase + BadPicture);
2987 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
2988 RenderErrBase + BadPicture);
2990 extra_len = (client->req_len << 2) - sizeof (xRenderTrianglesReq);
2992 if (extra_len &&
2993 (extra = (char *) ALLOCATE_LOCAL (extra_len))) {
2994 memcpy (extra, stuff + 1, extra_len);
2996 FOR_NSCREENS_FORWARD(j) {
2997 if (j) memcpy (stuff + 1, extra, extra_len);
2998 if (dst->u.pict.root) {
2999 int x_off = panoramiXdataPtr[j].x;
3000 int y_off = panoramiXdataPtr[j].y;
3002 if(x_off || y_off) {
3003 xTriangle *tri = (xTriangle *) (stuff + 1);
3004 int i = extra_len / sizeof (xTriangle);
3006 while (i--) {
3007 tri->p1.x -= x_off;
3008 tri->p1.y -= y_off;
3009 tri->p2.x -= x_off;
3010 tri->p2.y -= y_off;
3011 tri->p3.x -= x_off;
3012 tri->p3.y -= y_off;
3013 tri++;
3018 stuff->src = src->info[j].id;
3019 stuff->dst = dst->info[j].id;
3020 result =
3021 (*PanoramiXSaveRenderVector[X_RenderTriangles]) (client);
3023 if(result != Success) break;
3026 DEALLOCATE_LOCAL(extra);
3029 return result;
3032 static int
3033 PanoramiXRenderTriStrip(ClientPtr client)
3035 PanoramiXRes *src, *dst;
3036 int result = Success, j;
3037 REQUEST(xRenderTriStripReq);
3038 char *extra;
3039 int extra_len;
3041 REQUEST_AT_LEAST_SIZE (xRenderTriStripReq);
3043 VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess,
3044 RenderErrBase + BadPicture);
3045 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
3046 RenderErrBase + BadPicture);
3048 extra_len = (client->req_len << 2) - sizeof (xRenderTriStripReq);
3050 if (extra_len &&
3051 (extra = (char *) ALLOCATE_LOCAL (extra_len))) {
3052 memcpy (extra, stuff + 1, extra_len);
3054 FOR_NSCREENS_FORWARD(j) {
3055 if (j) memcpy (stuff + 1, extra, extra_len);
3056 if (dst->u.pict.root) {
3057 int x_off = panoramiXdataPtr[j].x;
3058 int y_off = panoramiXdataPtr[j].y;
3060 if(x_off || y_off) {
3061 xPointFixed *fixed = (xPointFixed *) (stuff + 1);
3062 int i = extra_len / sizeof (xPointFixed);
3064 while (i--) {
3065 fixed->x -= x_off;
3066 fixed->y -= y_off;
3067 fixed++;
3072 stuff->src = src->info[j].id;
3073 stuff->dst = dst->info[j].id;
3074 result =
3075 (*PanoramiXSaveRenderVector[X_RenderTriStrip]) (client);
3077 if(result != Success) break;
3080 DEALLOCATE_LOCAL(extra);
3083 return result;
3086 static int
3087 PanoramiXRenderTriFan(ClientPtr client)
3089 PanoramiXRes *src, *dst;
3090 int result = Success, j;
3091 REQUEST(xRenderTriFanReq);
3092 char *extra;
3093 int extra_len;
3095 REQUEST_AT_LEAST_SIZE (xRenderTriFanReq);
3097 VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess,
3098 RenderErrBase + BadPicture);
3099 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
3100 RenderErrBase + BadPicture);
3102 extra_len = (client->req_len << 2) - sizeof (xRenderTriFanReq);
3104 if (extra_len &&
3105 (extra = (char *) ALLOCATE_LOCAL (extra_len))) {
3106 memcpy (extra, stuff + 1, extra_len);
3108 FOR_NSCREENS_FORWARD(j) {
3109 if (j) memcpy (stuff + 1, extra, extra_len);
3110 if (dst->u.pict.root) {
3111 int x_off = panoramiXdataPtr[j].x;
3112 int y_off = panoramiXdataPtr[j].y;
3114 if(x_off || y_off) {
3115 xPointFixed *fixed = (xPointFixed *) (stuff + 1);
3116 int i = extra_len / sizeof (xPointFixed);
3118 while (i--) {
3119 fixed->x -= x_off;
3120 fixed->y -= y_off;
3121 fixed++;
3126 stuff->src = src->info[j].id;
3127 stuff->dst = dst->info[j].id;
3128 result =
3129 (*PanoramiXSaveRenderVector[X_RenderTriFan]) (client);
3131 if(result != Success) break;
3134 DEALLOCATE_LOCAL(extra);
3137 return result;
3140 #if 0 /* Not implemented yet */
3142 static int
3143 PanoramiXRenderColorTrapezoids(ClientPtr client)
3145 PanoramiXRes *src, *dst;
3146 int result = Success, j;
3147 REQUEST(xRenderColorTrapezoidsReq);
3148 char *extra;
3149 int extra_len;
3151 REQUEST_AT_LEAST_SIZE (xRenderColorTrapezoidsReq);
3153 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
3154 RenderErrBase + BadPicture);
3156 extra_len = (client->req_len << 2) - sizeof (xRenderColorTrapezoidsReq);
3158 if (extra_len &&
3159 (extra = (char *) ALLOCATE_LOCAL (extra_len))) {
3160 memcpy (extra, stuff + 1, extra_len);
3162 FOR_NSCREENS_FORWARD(j) {
3163 if (j) memcpy (stuff + 1, extra, extra_len);
3164 if (dst->u.pict.root) {
3165 int x_off = panoramiXdataPtr[j].x;
3166 int y_off = panoramiXdataPtr[j].y;
3168 if(x_off || y_off) {
3169 ....;
3173 stuff->dst = dst->info[j].id;
3174 result =
3175 (*PanoramiXSaveRenderVector[X_RenderColorTrapezoids]) (client);
3177 if(result != Success) break;
3180 DEALLOCATE_LOCAL(extra);
3183 return result;
3186 static int
3187 PanoramiXRenderColorTriangles(ClientPtr client)
3189 PanoramiXRes *src, *dst;
3190 int result = Success, j;
3191 REQUEST(xRenderColorTrianglesReq);
3192 char *extra;
3193 int extra_len;
3195 REQUEST_AT_LEAST_SIZE (xRenderColorTrianglesReq);
3197 VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess,
3198 RenderErrBase + BadPicture);
3200 extra_len = (client->req_len << 2) - sizeof (xRenderColorTrianglesReq);
3202 if (extra_len &&
3203 (extra = (char *) ALLOCATE_LOCAL (extra_len))) {
3204 memcpy (extra, stuff + 1, extra_len);
3206 FOR_NSCREENS_FORWARD(j) {
3207 if (j) memcpy (stuff + 1, extra, extra_len);
3208 if (dst->u.pict.root) {
3209 int x_off = panoramiXdataPtr[j].x;
3210 int y_off = panoramiXdataPtr[j].y;
3212 if(x_off || y_off) {
3213 ....;
3217 stuff->dst = dst->info[j].id;
3218 result =
3219 (*PanoramiXSaveRenderVector[X_RenderColorTriangles]) (client);
3221 if(result != Success) break;
3224 DEALLOCATE_LOCAL(extra);
3227 return result;
3230 #endif
3232 static int
3233 PanoramiXRenderAddTraps (ClientPtr client)
3235 PanoramiXRes *picture;
3236 int result = Success, j;
3237 REQUEST(xRenderAddTrapsReq);
3238 char *extra;
3239 int extra_len;
3240 INT16 x_off, y_off;
3242 REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq);
3243 VERIFY_XIN_PICTURE (picture, stuff->picture, client, DixWriteAccess,
3244 RenderErrBase + BadPicture);
3245 extra_len = (client->req_len << 2) - sizeof (xRenderAddTrapsReq);
3246 if (extra_len &&
3247 (extra = (char *) ALLOCATE_LOCAL (extra_len)))
3249 memcpy (extra, stuff + 1, extra_len);
3250 x_off = stuff->xOff;
3251 y_off = stuff->yOff;
3252 FOR_NSCREENS_FORWARD(j) {
3253 if (j) memcpy (stuff + 1, extra, extra_len);
3254 stuff->picture = picture->info[j].id;
3256 if (picture->u.pict.root)
3258 stuff->xOff = x_off + panoramiXdataPtr[j].x;
3259 stuff->yOff = y_off + panoramiXdataPtr[j].y;
3261 result = (*PanoramiXSaveRenderVector[X_RenderAddTraps]) (client);
3262 if(result != Success) break;
3264 DEALLOCATE_LOCAL(extra);
3267 return result;
3270 void
3271 PanoramiXRenderInit (void)
3273 int i;
3275 XRT_PICTURE = CreateNewResourceType (XineramaDeleteResource);
3276 for (i = 0; i < RenderNumberRequests; i++)
3277 PanoramiXSaveRenderVector[i] = ProcRenderVector[i];
3279 * Stuff in Xinerama aware request processing hooks
3281 ProcRenderVector[X_RenderCreatePicture] = PanoramiXRenderCreatePicture;
3282 ProcRenderVector[X_RenderChangePicture] = PanoramiXRenderChangePicture;
3283 ProcRenderVector[X_RenderSetPictureTransform] = PanoramiXRenderSetPictureTransform;
3284 ProcRenderVector[X_RenderSetPictureFilter] = PanoramiXRenderSetPictureFilter;
3285 ProcRenderVector[X_RenderSetPictureClipRectangles] = PanoramiXRenderSetPictureClipRectangles;
3286 ProcRenderVector[X_RenderFreePicture] = PanoramiXRenderFreePicture;
3287 ProcRenderVector[X_RenderComposite] = PanoramiXRenderComposite;
3288 ProcRenderVector[X_RenderCompositeGlyphs8] = PanoramiXRenderCompositeGlyphs;
3289 ProcRenderVector[X_RenderCompositeGlyphs16] = PanoramiXRenderCompositeGlyphs;
3290 ProcRenderVector[X_RenderCompositeGlyphs32] = PanoramiXRenderCompositeGlyphs;
3291 ProcRenderVector[X_RenderFillRectangles] = PanoramiXRenderFillRectangles;
3293 ProcRenderVector[X_RenderTrapezoids] = PanoramiXRenderTrapezoids;
3294 ProcRenderVector[X_RenderTriangles] = PanoramiXRenderTriangles;
3295 ProcRenderVector[X_RenderTriStrip] = PanoramiXRenderTriStrip;
3296 ProcRenderVector[X_RenderTriFan] = PanoramiXRenderTriFan;
3297 ProcRenderVector[X_RenderAddTraps] = PanoramiXRenderAddTraps;
3300 void
3301 PanoramiXRenderReset (void)
3303 int i;
3304 for (i = 0; i < RenderNumberRequests; i++)
3305 ProcRenderVector[i] = PanoramiXSaveRenderVector[i];
3308 #endif /* PANORAMIX */