xref: /OK3568_Linux_fs/external/xserver/render/mitrap.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Permission to use, copy, modify, distribute, and sell this software and its
6*4882a593Smuzhiyun  * documentation for any purpose is hereby granted without fee, provided that
7*4882a593Smuzhiyun  * the above copyright notice appear in all copies and that both that
8*4882a593Smuzhiyun  * copyright notice and this permission notice appear in supporting
9*4882a593Smuzhiyun  * documentation, and that the name of Keith Packard not be used in
10*4882a593Smuzhiyun  * advertising or publicity pertaining to distribution of the software without
11*4882a593Smuzhiyun  * specific, written prior permission.  Keith Packard makes no
12*4882a593Smuzhiyun  * representations about the suitability of this software for any purpose.  It
13*4882a593Smuzhiyun  * is provided "as is" without express or implied warranty.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16*4882a593Smuzhiyun  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17*4882a593Smuzhiyun  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19*4882a593Smuzhiyun  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20*4882a593Smuzhiyun  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21*4882a593Smuzhiyun  * PERFORMANCE OF THIS SOFTWARE.
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
25*4882a593Smuzhiyun #include <dix-config.h>
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include "scrnintstr.h"
29*4882a593Smuzhiyun #include "gcstruct.h"
30*4882a593Smuzhiyun #include "pixmapstr.h"
31*4882a593Smuzhiyun #include "windowstr.h"
32*4882a593Smuzhiyun #include "servermd.h"
33*4882a593Smuzhiyun #include "mi.h"
34*4882a593Smuzhiyun #include "picturestr.h"
35*4882a593Smuzhiyun #include "mipict.h"
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun static xFixed
miLineFixedX(xLineFixed * l,xFixed y,Bool ceil)38*4882a593Smuzhiyun miLineFixedX(xLineFixed * l, xFixed y, Bool ceil)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun     xFixed dx = l->p2.x - l->p1.x;
41*4882a593Smuzhiyun     xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx;
42*4882a593Smuzhiyun     xFixed dy = l->p2.y - l->p1.y;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun     if (ceil)
45*4882a593Smuzhiyun         ex += (dy - 1);
46*4882a593Smuzhiyun     return l->p1.x + (xFixed) (ex / dy);
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun void
miTrapezoidBounds(int ntrap,xTrapezoid * traps,BoxPtr box)50*4882a593Smuzhiyun miTrapezoidBounds(int ntrap, xTrapezoid * traps, BoxPtr box)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun     box->y1 = MAXSHORT;
53*4882a593Smuzhiyun     box->y2 = MINSHORT;
54*4882a593Smuzhiyun     box->x1 = MAXSHORT;
55*4882a593Smuzhiyun     box->x2 = MINSHORT;
56*4882a593Smuzhiyun     for (; ntrap; ntrap--, traps++) {
57*4882a593Smuzhiyun         INT16 x1, y1, x2, y2;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun         if (!xTrapezoidValid(traps))
60*4882a593Smuzhiyun             continue;
61*4882a593Smuzhiyun         y1 = xFixedToInt(traps->top);
62*4882a593Smuzhiyun         if (y1 < box->y1)
63*4882a593Smuzhiyun             box->y1 = y1;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun         y2 = xFixedToInt(xFixedCeil(traps->bottom));
66*4882a593Smuzhiyun         if (y2 > box->y2)
67*4882a593Smuzhiyun             box->y2 = y2;
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun         x1 = xFixedToInt(min(miLineFixedX(&traps->left, traps->top, FALSE),
70*4882a593Smuzhiyun                              miLineFixedX(&traps->left, traps->bottom, FALSE)));
71*4882a593Smuzhiyun         if (x1 < box->x1)
72*4882a593Smuzhiyun             box->x1 = x1;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun         x2 = xFixedToInt(xFixedCeil
75*4882a593Smuzhiyun                          (max
76*4882a593Smuzhiyun                           (miLineFixedX(&traps->right, traps->top, TRUE),
77*4882a593Smuzhiyun                            miLineFixedX(&traps->right, traps->bottom, TRUE))));
78*4882a593Smuzhiyun         if (x2 > box->x2)
79*4882a593Smuzhiyun             box->x2 = x2;
80*4882a593Smuzhiyun     }
81*4882a593Smuzhiyun }
82