1/*
2 *
3 * Copyright © 2002 Keith Packard
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 Keith Packard not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission.  Keith Packard makes no
12 * representations about the suitability of this software for any purpose.  It
13 * is provided "as is" without express or implied warranty.
14 *
15 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27#include "Xrenderint.h"
28
29void
30XRenderCompositeTriangles (Display		*dpy,
31			   int			op,
32			   Picture		src,
33			   Picture		dst,
34			    _Xconst XRenderPictFormat	*maskFormat,
35			   int			xSrc,
36			   int			ySrc,
37			   _Xconst XTriangle	*triangles,
38			   int			ntriangle)
39{
40    XRenderExtDisplayInfo	*info = XRenderFindDisplay (dpy);
41
42    RenderSimpleCheckExtension (dpy, info);
43    LockDisplay(dpy);
44    while (ntriangle)
45    {
46	xRenderTrianglesReq	*req;
47	int			n;
48	long			len;
49
50	GetReq(RenderTriangles, req);
51	req->reqType = (CARD8) info->codes->major_opcode;
52	req->renderReqType = X_RenderTriangles;
53	req->op = (CARD8) op;
54	req->src = (CARD32) src;
55	req->dst = (CARD32) dst;
56	req->maskFormat = (CARD32) (maskFormat ? maskFormat->id : 0);
57	req->xSrc = (INT16) xSrc;
58	req->ySrc = (INT16) ySrc;
59	n = ntriangle;
60	len = ((long) n) * (SIZEOF (xTriangle) >> 2);
61	if (!dpy->bigreq_size && len > (dpy->max_request_size - req->length)) {
62	    n = (int) ((dpy->max_request_size - req->length) / (SIZEOF (xTriangle) >> 2));
63	    len = ((long)n) * (SIZEOF (xTriangle) >> 2);
64	}
65	SetReqLen (req, len, len);
66	len <<= 2;
67	DataInt32 (dpy, (_Xconst int *) triangles, len);
68	ntriangle -= n;
69	triangles += n;
70    }
71    UnlockDisplay(dpy);
72    SyncHandle();
73}
74
75void
76XRenderCompositeTriStrip (Display		*dpy,
77			  int			op,
78			  Picture		src,
79			  Picture		dst,
80			  _Xconst XRenderPictFormat	*maskFormat,
81			  int			xSrc,
82			  int			ySrc,
83			  _Xconst XPointFixed	*points,
84			  int			npoint)
85{
86    XRenderExtDisplayInfo	*info = XRenderFindDisplay (dpy);
87
88    RenderSimpleCheckExtension (dpy, info);
89    LockDisplay(dpy);
90    while (npoint > 2)
91    {
92	xRenderTriStripReq	*req;
93	int			n;
94	long			len;
95
96	GetReq(RenderTriStrip, req);
97	req->reqType = (CARD8) info->codes->major_opcode;
98	req->renderReqType = X_RenderTriStrip;
99	req->op = (CARD8) op;
100	req->src = (CARD32) src;
101	req->dst = (CARD32) dst;
102	req->maskFormat = (CARD32) (maskFormat ? maskFormat->id : 0);
103	req->xSrc = (INT16) xSrc;
104	req->ySrc = (INT16) ySrc;
105	n = npoint;
106	len = ((long) n) * (SIZEOF (xPointFixed) >> 2);
107	if (!dpy->bigreq_size && len > (dpy->max_request_size - req->length)) {
108	    n = (int) ((dpy->max_request_size - req->length) / (SIZEOF (xPointFixed) >> 2));
109	    len = ((long)n) * (SIZEOF (xPointFixed) >> 2);
110	}
111	SetReqLen (req, len, len);
112	len <<= 2;
113	DataInt32 (dpy, (_Xconst int *) points, len);
114	npoint -= (n - 2);
115	points += (n - 2);
116    }
117    UnlockDisplay(dpy);
118    SyncHandle();
119}
120
121void
122XRenderCompositeTriFan (Display			*dpy,
123			int			op,
124			Picture			src,
125			Picture			dst,
126			_Xconst XRenderPictFormat	*maskFormat,
127			int			xSrc,
128			int			ySrc,
129			_Xconst XPointFixed	*points,
130			int			npoint)
131{
132    XRenderExtDisplayInfo   *info = XRenderFindDisplay (dpy);
133    _Xconst XPointFixed	    *first = points;
134
135    RenderSimpleCheckExtension (dpy, info);
136    LockDisplay(dpy);
137    points++;
138    npoint--;
139    while (npoint > 1)
140    {
141	xRenderTriFanReq	*req;
142	xPointFixed		*p;
143	int			n;
144	long			len;
145
146	GetReqExtra(RenderTriFan, SIZEOF (xPointFixed), req);
147	req->reqType = (CARD8) info->codes->major_opcode;
148	req->renderReqType = X_RenderTriFan;
149	req->op = (CARD8) op;
150	req->src = (CARD32) src;
151	req->dst = (CARD32) dst;
152	req->maskFormat = (CARD32) (maskFormat ? maskFormat->id : 0);
153	req->xSrc = (INT16) xSrc;
154	req->ySrc = (INT16) ySrc;
155	p = (xPointFixed *) (req + 1);
156	p->x = first->x;
157	p->y = first->y;
158	n = npoint;
159	len = ((long) n) * (SIZEOF (xPointFixed) >> 2);
160	if (!dpy->bigreq_size && len > (dpy->max_request_size - req->length)) {
161	    n = (int) ((dpy->max_request_size - req->length) / (SIZEOF (xPointFixed) >> 2));
162	    len = ((long)n) * (SIZEOF (xPointFixed) >> 2);
163	}
164	SetReqLen (req, len, len);
165	len <<= 2;
166	DataInt32 (dpy, (_Xconst int *) points, len);
167	npoint -= (n - 1);
168	points += (n - 1);
169    }
170    UnlockDisplay(dpy);
171    SyncHandle();
172}
173