Imported Upstream version 0.9.7
[platform/upstream/libXrender.git] / src / Tri.c
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
29 void
30 XRenderCompositeTriangles (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     xRenderTrianglesReq     *req;
42     int                     n;
43     long                    len;
44
45     RenderSimpleCheckExtension (dpy, info);
46     LockDisplay(dpy);
47     while (ntriangle)
48     {
49         GetReq(RenderTriangles, req);
50         req->reqType = info->codes->major_opcode;
51         req->renderReqType = X_RenderTriangles;
52         req->op = (CARD8) op;
53         req->src = src;
54         req->dst = dst;
55         req->maskFormat = maskFormat ? maskFormat->id : 0;
56         req->xSrc = xSrc;
57         req->ySrc = ySrc;
58         n = ntriangle;
59         len = ((long) n) * (SIZEOF (xTriangle) >> 2);
60         if (!dpy->bigreq_size && len > (dpy->max_request_size - req->length)) {
61             n = (dpy->max_request_size - req->length) / (SIZEOF (xTriangle) >> 2);
62             len = ((long)n) * (SIZEOF (xTriangle) >> 2);
63         }
64         SetReqLen (req, len, len);
65         len <<= 2;
66         DataInt32 (dpy, (int *) triangles, len);
67         ntriangle -= n;
68         triangles += n;
69     }
70     UnlockDisplay(dpy);
71     SyncHandle();
72 }
73
74 void
75 XRenderCompositeTriStrip (Display               *dpy,
76                           int                   op,
77                           Picture               src,
78                           Picture               dst,
79                           _Xconst XRenderPictFormat     *maskFormat,
80                           int                   xSrc,
81                           int                   ySrc,
82                           _Xconst XPointFixed   *points,
83                           int                   npoint)
84 {
85     XRenderExtDisplayInfo         *info = XRenderFindDisplay (dpy);
86     xRenderTriStripReq      *req;
87     int                     n;
88     long                    len;
89
90     RenderSimpleCheckExtension (dpy, info);
91     LockDisplay(dpy);
92     while (npoint > 2)
93     {
94         GetReq(RenderTriStrip, req);
95         req->reqType = info->codes->major_opcode;
96         req->renderReqType = X_RenderTriStrip;
97         req->op = (CARD8) op;
98         req->src = src;
99         req->dst = dst;
100         req->maskFormat = maskFormat ? maskFormat->id : 0;
101         req->xSrc = xSrc;
102         req->ySrc = ySrc;
103         n = npoint;
104         len = ((long) n) * (SIZEOF (xPointFixed) >> 2);
105         if (!dpy->bigreq_size && len > (dpy->max_request_size - req->length)) {
106             n = (dpy->max_request_size - req->length) / (SIZEOF (xPointFixed) >> 2);
107             len = ((long)n) * (SIZEOF (xPointFixed) >> 2);
108         }
109         SetReqLen (req, len, len);
110         len <<= 2;
111         DataInt32 (dpy, (int *) points, len);
112         npoint -= (n - 2);
113         points += (n - 2);
114     }
115     UnlockDisplay(dpy);
116     SyncHandle();
117 }
118
119 void
120 XRenderCompositeTriFan (Display                 *dpy,
121                         int                     op,
122                         Picture                 src,
123                         Picture                 dst,
124                         _Xconst XRenderPictFormat       *maskFormat,
125                         int                     xSrc,
126                         int                     ySrc,
127                         _Xconst XPointFixed     *points,
128                         int                     npoint)
129 {
130     XRenderExtDisplayInfo         *info = XRenderFindDisplay (dpy);
131     _Xconst XPointFixed     *first = points;
132     xPointFixed             *p;
133     xRenderTriFanReq        *req;
134     int                     n;
135     long                    len;
136
137     RenderSimpleCheckExtension (dpy, info);
138     LockDisplay(dpy);
139     points++;
140     npoint--;
141     while (npoint > 1)
142     {
143         GetReqExtra(RenderTriFan, SIZEOF (xPointFixed), req);
144         req->reqType = info->codes->major_opcode;
145         req->renderReqType = X_RenderTriFan;
146         req->op = (CARD8) op;
147         req->src = src;
148         req->dst = dst;
149         req->maskFormat = maskFormat ? maskFormat->id : 0;
150         req->xSrc = xSrc;
151         req->ySrc = ySrc;
152         p = (xPointFixed *) (req + 1);
153         p->x = first->x;
154         p->y = first->y;
155         n = npoint;
156         len = ((long) n) * (SIZEOF (xPointFixed) >> 2);
157         if (!dpy->bigreq_size && len > (dpy->max_request_size - req->length)) {
158             n = (dpy->max_request_size - req->length) / (SIZEOF (xPointFixed) >> 2);
159             len = ((long)n) * (SIZEOF (xPointFixed) >> 2);
160         }
161         SetReqLen (req, len, len);
162         len <<= 2;
163         DataInt32 (dpy, (int *) points, len);
164         npoint -= (n - 1);
165         points += (n - 1);
166     }
167     UnlockDisplay(dpy);
168     SyncHandle();
169 }