First import
[xorg_rtime.git] / xorg-server-1.4 / fb / fbtrap.c
blob830603ae730ef5b4fff10fa6ac23667f74e02680
1 /*
2 * Copyright © 2004 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_DIX_CONFIG_H
24 #include <dix-config.h>
25 #endif
27 #include "fb.h"
29 #ifdef RENDER
31 #include "picturestr.h"
32 #include "mipict.h"
33 #include "renderedge.h"
34 #include "fbpict.h"
36 void
37 fbAddTraps (PicturePtr pPicture,
38 INT16 x_off,
39 INT16 y_off,
40 int ntrap,
41 xTrap *traps)
43 pixman_image_t *image = image_from_pict (pPicture, FALSE);
45 if (!image)
46 return;
48 pixman_add_traps (image, x_off, y_off, ntrap, (pixman_trap_t *)traps);
50 free_pixman_pict (pPicture, image);
53 void
54 fbRasterizeTrapezoid (PicturePtr pPicture,
55 xTrapezoid *trap,
56 int x_off,
57 int y_off)
59 pixman_image_t *image = image_from_pict (pPicture, FALSE);
61 if (!image)
62 return;
64 pixman_rasterize_trapezoid (image, (pixman_trapezoid_t *)trap, x_off, y_off);
66 free_pixman_pict (pPicture, image);
69 static int
70 _GreaterY (xPointFixed *a, xPointFixed *b)
72 if (a->y == b->y)
73 return a->x > b->x;
74 return a->y > b->y;
78 * Note that the definition of this function is a bit odd because
79 * of the X coordinate space (y increasing downwards).
81 static int
82 _Clockwise (xPointFixed *ref, xPointFixed *a, xPointFixed *b)
84 xPointFixed ad, bd;
86 ad.x = a->x - ref->x;
87 ad.y = a->y - ref->y;
88 bd.x = b->x - ref->x;
89 bd.y = b->y - ref->y;
91 return ((xFixed_32_32) bd.y * ad.x - (xFixed_32_32) ad.y * bd.x) < 0;
94 /* FIXME -- this could be made more efficient */
95 void
96 fbAddTriangles (PicturePtr pPicture,
97 INT16 x_off,
98 INT16 y_off,
99 int ntri,
100 xTriangle *tris)
102 xPointFixed *top, *left, *right, *tmp;
103 xTrapezoid trap;
105 for (; ntri; ntri--, tris++)
107 top = &tris->p1;
108 left = &tris->p2;
109 right = &tris->p3;
110 if (_GreaterY (top, left)) {
111 tmp = left; left = top; top = tmp;
113 if (_GreaterY (top, right)) {
114 tmp = right; right = top; top = tmp;
116 if (_Clockwise (top, right, left)) {
117 tmp = right; right = left; left = tmp;
121 * Two cases:
123 * + +
124 * / \ / \
125 * / \ / \
126 * / + + \
127 * / -- -- \
128 * / -- -- \
129 * / --- --- \
130 * +-- --+
133 trap.top = top->y;
134 trap.left.p1 = *top;
135 trap.left.p2 = *left;
136 trap.right.p1 = *top;
137 trap.right.p2 = *right;
138 if (right->y < left->y)
139 trap.bottom = right->y;
140 else
141 trap.bottom = left->y;
142 fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off);
143 if (right->y < left->y)
145 trap.top = right->y;
146 trap.bottom = left->y;
147 trap.right.p1 = *right;
148 trap.right.p2 = *left;
150 else
152 trap.top = left->y;
153 trap.bottom = right->y;
154 trap.left.p1 = *left;
155 trap.left.p2 = *right;
157 fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off);
161 #endif /* RENDER */