2
* $Id: fbtrap.c,v 1.5 2005/07/03 07:01:23 daniels Exp $
4
* Copyright © 2004 Keith Packard
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
#ifdef HAVE_DIX_CONFIG_H
26
#include <dix-config.h>
33
#include "picturestr.h"
35
#include "renderedge.h"
39
fbAddTraps (PicturePtr pPicture,
57
fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff);
59
width = pPicture->pDrawable->width;
60
height = pPicture->pDrawable->height;
64
x_off_fixed = IntToxFixed(y_off);
65
y_off_fixed = IntToxFixed(y_off);
69
t = traps->top.y + y_off_fixed;
72
t = RenderSampleCeilY (t, bpp);
74
b = traps->bot.y + y_off_fixed;
75
if (xFixedToInt (b) >= height)
76
b = IntToxFixed (height) - 1;
77
b = RenderSampleFloorY (b, bpp);
81
/* initialize edge walkers */
82
RenderEdgeInit (&l, bpp, t,
83
traps->top.l + x_off_fixed,
84
traps->top.y + y_off_fixed,
85
traps->bot.l + x_off_fixed,
86
traps->bot.y + y_off_fixed);
88
RenderEdgeInit (&r, bpp, t,
89
traps->top.r + x_off_fixed,
90
traps->top.y + y_off_fixed,
91
traps->bot.r + x_off_fixed,
92
traps->bot.y + y_off_fixed);
94
fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b);
101
fbRasterizeTrapezoid (PicturePtr pPicture,
118
fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff);
120
width = pPicture->pDrawable->width;
121
height = pPicture->pDrawable->height;
125
x_off_fixed = IntToxFixed(x_off);
126
y_off_fixed = IntToxFixed(y_off);
127
t = trap->top + y_off_fixed;
130
t = RenderSampleCeilY (t, bpp);
132
b = trap->bottom + y_off_fixed;
133
if (xFixedToInt (b) >= height)
134
b = IntToxFixed (height) - 1;
135
b = RenderSampleFloorY (b, bpp);
139
/* initialize edge walkers */
140
RenderLineFixedEdgeInit (&l, bpp, t, &trap->left, x_off, y_off);
141
RenderLineFixedEdgeInit (&r, bpp, t, &trap->right, x_off, y_off);
143
fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b);
148
_GreaterY (xPointFixed *a, xPointFixed *b)
156
* Note that the definition of this function is a bit odd because
157
* of the X coordinate space (y increasing downwards).
160
_Clockwise (xPointFixed *ref, xPointFixed *a, xPointFixed *b)
164
ad.x = a->x - ref->x;
165
ad.y = a->y - ref->y;
166
bd.x = b->x - ref->x;
167
bd.y = b->y - ref->y;
169
return ((xFixed_32_32) bd.y * ad.x - (xFixed_32_32) ad.y * bd.x) < 0;
172
/* FIXME -- this could be made more efficient */
174
fbAddTriangles (PicturePtr pPicture,
180
xPointFixed *top, *left, *right, *tmp;
183
for (; ntri; ntri--, tris++)
188
if (_GreaterY (top, left)) {
189
tmp = left; left = top; top = tmp;
191
if (_GreaterY (top, right)) {
192
tmp = right; right = top; top = tmp;
194
if (_Clockwise (top, right, left)) {
195
tmp = right; right = left; left = tmp;
213
trap.left.p2 = *left;
214
trap.right.p1 = *top;
215
trap.right.p2 = *right;
216
if (right->y < left->y)
217
trap.bottom = right->y;
219
trap.bottom = left->y;
220
fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off);
221
if (right->y < left->y)
224
trap.bottom = left->y;
225
trap.right.p1 = *right;
226
trap.right.p2 = *left;
231
trap.bottom = right->y;
232
trap.left.p1 = *left;
233
trap.left.p2 = *right;
235
fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off);