Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * | |
3 | * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. | |
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_DIX_CONFIG_H | |
25 | #include <dix-config.h> | |
26 | #endif | |
27 | ||
28 | #include "scrnintstr.h" | |
29 | #include "gcstruct.h" | |
30 | #include "pixmapstr.h" | |
31 | #include "windowstr.h" | |
32 | #include "servermd.h" | |
33 | #include "mi.h" | |
34 | #include "picturestr.h" | |
35 | #include "mipict.h" | |
36 | ||
37 | static xFixed | |
38 | miLineFixedX(xLineFixed * l, xFixed y, Bool ceil) | |
39 | { | |
40 | xFixed dx = l->p2.x - l->p1.x; | |
41 | xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx; | |
42 | xFixed dy = l->p2.y - l->p1.y; | |
43 | ||
44 | if (ceil) | |
45 | ex += (dy - 1); | |
46 | return l->p1.x + (xFixed) (ex / dy); | |
47 | } | |
48 | ||
49 | void | |
50 | miTrapezoidBounds(int ntrap, xTrapezoid * traps, BoxPtr box) | |
51 | { | |
52 | box->y1 = MAXSHORT; | |
53 | box->y2 = MINSHORT; | |
54 | box->x1 = MAXSHORT; | |
55 | box->x2 = MINSHORT; | |
56 | for (; ntrap; ntrap--, traps++) { | |
57 | INT16 x1, y1, x2, y2; | |
58 | ||
59 | if (!xTrapezoidValid(traps)) | |
60 | continue; | |
61 | y1 = xFixedToInt(traps->top); | |
62 | if (y1 < box->y1) | |
63 | box->y1 = y1; | |
64 | ||
65 | y2 = xFixedToInt(xFixedCeil(traps->bottom)); | |
66 | if (y2 > box->y2) | |
67 | box->y2 = y2; | |
68 | ||
69 | x1 = xFixedToInt(min(miLineFixedX(&traps->left, traps->top, FALSE), | |
70 | miLineFixedX(&traps->left, traps->bottom, FALSE))); | |
71 | if (x1 < box->x1) | |
72 | box->x1 = x1; | |
73 | ||
74 | x2 = xFixedToInt(xFixedCeil | |
75 | (max | |
76 | (miLineFixedX(&traps->right, traps->top, TRUE), | |
77 | miLineFixedX(&traps->right, traps->bottom, TRUE)))); | |
78 | if (x2 > box->x2) | |
79 | box->x2 = x2; | |
80 | } | |
81 | } |