2
* $XFree86: xc/programs/Xserver/render/mitri.c,v 1.6 2002/08/12 04:03:21 keithp Exp $
4
* Copyright � 2002 Keith Packard, member of The XFree86 Project, Inc.
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
25
#include "scrnintstr.h"
27
#include "pixmapstr.h"
28
#include "windowstr.h"
30
#include "picturestr.h"
34
miPointFixedBounds (int npoint, xPointFixed *points, BoxPtr bounds)
36
bounds->x1 = xFixedToInt (points->x);
37
bounds->x2 = xFixedToInt (xFixedCeil (points->x));
38
bounds->y1 = xFixedToInt (points->y);
39
bounds->y2 = xFixedToInt (xFixedCeil (points->y));
44
INT16 x1 = xFixedToInt (points->x);
45
INT16 x2 = xFixedToInt (xFixedCeil (points->x));
46
INT16 y1 = xFixedToInt (points->y);
47
INT16 y2 = xFixedToInt (xFixedCeil (points->y));
51
else if (x2 > bounds->x2)
55
else if (y2 > bounds->y2)
62
miTriangleBounds (int ntri, xTriangle *tris, BoxPtr bounds)
64
miPointFixedBounds (ntri * 3, (xPointFixed *) tris, bounds);
68
miRasterizeTriangle (PicturePtr pPicture,
73
ScreenPtr pScreen = pPicture->pDrawable->pScreen;
74
PictureScreenPtr ps = GetPictureScreen(pScreen);
75
xPointFixed *top, *left, *right, *t;
81
if (left->y < top->y) {
82
t = left; left = top; top = t;
84
if (right->y < top->y) {
85
t = right; right = top; top = t;
87
if (right->x < left->x) {
88
t = right; right = left; left = t;
104
trap[0].top = top->y;
106
trap[0].left.p1.x = top->x;
107
trap[0].left.p1.y = trap[0].top;
108
trap[0].left.p2.x = left->x;
109
trap[0].left.p2.y = left->y;
111
trap[0].right.p1 = trap[0].left.p1;
112
trap[0].right.p2.x = right->x;
113
trap[0].right.p2.y = right->y;
115
if (right->y < left->y)
117
trap[0].bottom = trap[0].right.p2.y;
119
trap[1].top = trap[0].bottom;
120
trap[1].bottom = trap[0].left.p2.y;
122
trap[1].left = trap[0].left;
123
trap[1].right.p1 = trap[0].right.p2;
124
trap[1].right.p2 = trap[0].left.p2;
128
trap[0].bottom = trap[0].left.p2.y;
130
trap[1].top = trap[0].bottom;
131
trap[1].bottom = trap[0].right.p2.y;
133
trap[1].right = trap[0].right;
134
trap[1].left.p1 = trap[0].left.p2;
135
trap[1].left.p2 = trap[0].right.p2;
137
if (trap[0].top != trap[0].bottom)
138
(*ps->RasterizeTrapezoid) (pPicture, &trap[0], x_off, y_off);
139
if (trap[1].top != trap[1].bottom)
140
(*ps->RasterizeTrapezoid) (pPicture, &trap[1], x_off, y_off);
144
miTriangles (CARD8 op,
147
PictFormatPtr maskFormat,
153
ScreenPtr pScreen = pDst->pDrawable->pScreen;
155
PicturePtr pPicture = 0;
159
xDst = tris[0].p1.x >> 16;
160
yDst = tris[0].p1.y >> 16;
164
miTriangleBounds (ntri, tris, &bounds);
165
if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
167
pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
168
bounds.x2 - bounds.x1,
169
bounds.y2 - bounds.y1);
173
for (; ntri; ntri--, tris++)
177
miTriangleBounds (1, tris, &bounds);
178
if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
180
pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
181
bounds.x2 - bounds.x1,
182
bounds.y2 - bounds.y1);
186
miRasterizeTriangle (pPicture, tris, -bounds.x1, -bounds.y1);
189
xRel = bounds.x1 + xSrc - xDst;
190
yRel = bounds.y1 + ySrc - yDst;
191
CompositePicture (op, pSrc, pPicture, pDst,
192
xRel, yRel, 0, 0, bounds.x1, bounds.y1,
193
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
194
FreePicture (pPicture, 0);
196
/* XXX adjust xSrc and ySrc */
200
xRel = bounds.x1 + xSrc - xDst;
201
yRel = bounds.y1 + ySrc - yDst;
202
CompositePicture (op, pSrc, pPicture, pDst,
203
xRel, yRel, 0, 0, bounds.x1, bounds.y1,
204
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
205
FreePicture (pPicture, 0);
210
miTriStrip (CARD8 op,
213
PictFormatPtr maskFormat,
219
ScreenPtr pScreen = pDst->pDrawable->pScreen;
222
PicturePtr pPicture = 0;
226
xDst = points[0].x >> 16;
227
yDst = points[0].y >> 16;
233
miPointFixedBounds (npoint, points, &bounds);
234
if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
236
pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
237
bounds.x2 - bounds.x1,
238
bounds.y2 - bounds.y1);
242
for (; npoint >= 3; npoint--, points++)
249
miTriangleBounds (1, &tri, &bounds);
250
if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
252
pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
253
bounds.x2 - bounds.x1,
254
bounds.y2 - bounds.y1);
258
miRasterizeTriangle (pPicture, &tri, -bounds.x1, -bounds.y1);
261
xRel = bounds.x1 + xSrc - xDst;
262
yRel = bounds.y1 + ySrc - yDst;
263
CompositePicture (op, pSrc, pPicture, pDst,
264
xRel, yRel, 0, 0, bounds.x1, bounds.y1,
265
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
266
FreePicture (pPicture, 0);
271
xRel = bounds.x1 + xSrc - xDst;
272
yRel = bounds.y1 + ySrc - yDst;
273
CompositePicture (op, pSrc, pPicture, pDst,
274
xRel, yRel, 0, 0, bounds.x1, bounds.y1,
275
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
276
FreePicture (pPicture, 0);
284
PictFormatPtr maskFormat,
290
ScreenPtr pScreen = pDst->pDrawable->pScreen;
293
PicturePtr pPicture = 0;
298
xDst = points[0].x >> 16;
299
yDst = points[0].y >> 16;
305
miPointFixedBounds (npoint, points, &bounds);
306
if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
308
pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
309
bounds.x2 - bounds.x1,
310
bounds.y2 - bounds.y1);
316
for (; npoint >= 2; npoint--, points++)
323
miTriangleBounds (1, &tri, &bounds);
324
if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
326
pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
327
bounds.x2 - bounds.x1,
328
bounds.y2 - bounds.y1);
332
miRasterizeTriangle (pPicture, &tri, -bounds.x1, -bounds.y1);
335
xRel = bounds.x1 + xSrc - xDst;
336
yRel = bounds.y1 + ySrc - yDst;
337
CompositePicture (op, pSrc, pPicture, pDst,
338
xRel, yRel, 0, 0, bounds.x1, bounds.y1,
339
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
340
FreePicture (pPicture, 0);
345
xRel = bounds.x1 + xSrc - xDst;
346
yRel = bounds.y1 + ySrc - yDst;
347
CompositePicture (op, pSrc, pPicture, pDst,
348
xRel, yRel, 0, 0, bounds.x1, bounds.y1,
349
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
350
FreePicture (pPicture, 0);