Add patch that contain Mali fixes.
[deb_xorg-server.git] / mi / mipolyrect.c
1 /***********************************************************
2
3 Copyright 1987, 1998 The Open Group
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.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27 All Rights Reserved
28
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
36
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43 SOFTWARE.
44
45 ******************************************************************/
46 #ifdef HAVE_DIX_CONFIG_H
47 #include <dix-config.h>
48 #endif
49
50 #include <X11/X.h>
51 #include <X11/Xprotostr.h>
52 #include "regionstr.h"
53 #include "gcstruct.h"
54 #include "pixmap.h"
55 #include "mi.h"
56
57 void
58 miPolyRectangle(DrawablePtr pDraw, GCPtr pGC, int nrects, xRectangle *pRects)
59 {
60 int i;
61 xRectangle *pR = pRects;
62 DDXPointRec rect[5];
63 int bound_tmp;
64
65 #define MINBOUND(dst,eqn) bound_tmp = eqn; \
66 if (bound_tmp < -32768) \
67 bound_tmp = -32768; \
68 dst = bound_tmp;
69
70 #define MAXBOUND(dst,eqn) bound_tmp = eqn; \
71 if (bound_tmp > 32767) \
72 bound_tmp = 32767; \
73 dst = bound_tmp;
74
75 #define MAXUBOUND(dst,eqn) bound_tmp = eqn; \
76 if (bound_tmp > 65535) \
77 bound_tmp = 65535; \
78 dst = bound_tmp;
79
80 if (pGC->lineStyle == LineSolid && pGC->joinStyle == JoinMiter &&
81 pGC->lineWidth != 0) {
82 xRectangle *tmp, *t;
83 int ntmp;
84 int offset1, offset2, offset3;
85 int x, y, width, height;
86
87 ntmp = (nrects << 2);
88 offset2 = pGC->lineWidth;
89 offset1 = offset2 >> 1;
90 offset3 = offset2 - offset1;
91 tmp = malloc(ntmp * sizeof(xRectangle));
92 if (!tmp)
93 return;
94 t = tmp;
95 for (i = 0; i < nrects; i++) {
96 x = pR->x;
97 y = pR->y;
98 width = pR->width;
99 height = pR->height;
100 pR++;
101 if (width == 0 && height == 0) {
102 rect[0].x = x;
103 rect[0].y = y;
104 rect[1].x = x;
105 rect[1].y = y;
106 (*pGC->ops->Polylines) (pDraw, pGC, CoordModeOrigin, 2, rect);
107 }
108 else if (height < offset2 || width < offset1) {
109 if (height == 0) {
110 t->x = x;
111 t->width = width;
112 }
113 else {
114 MINBOUND(t->x, x - offset1)
115 MAXUBOUND(t->width, width + offset2)
116 }
117 if (width == 0) {
118 t->y = y;
119 t->height = height;
120 }
121 else {
122 MINBOUND(t->y, y - offset1)
123 MAXUBOUND(t->height, height + offset2)
124 }
125 t++;
126 }
127 else {
128 MINBOUND(t->x, x - offset1)
129 MINBOUND(t->y, y - offset1)
130 MAXUBOUND(t->width, width + offset2)
131 t->height = offset2;
132 t++;
133 MINBOUND(t->x, x - offset1)
134 MAXBOUND(t->y, y + offset3);
135 t->width = offset2;
136 t->height = height - offset2;
137 t++;
138 MAXBOUND(t->x, x + width - offset1);
139 MAXBOUND(t->y, y + offset3)
140 t->width = offset2;
141 t->height = height - offset2;
142 t++;
143 MINBOUND(t->x, x - offset1)
144 MAXBOUND(t->y, y + height - offset1)
145 MAXUBOUND(t->width, width + offset2)
146 t->height = offset2;
147 t++;
148 }
149 }
150 (*pGC->ops->PolyFillRect) (pDraw, pGC, t - tmp, tmp);
151 free((pointer) tmp);
152 }
153 else {
154
155 for (i = 0; i < nrects; i++) {
156 rect[0].x = pR->x;
157 rect[0].y = pR->y;
158
159 MAXBOUND(rect[1].x, pR->x + (int) pR->width)
160 rect[1].y = rect[0].y;
161
162 rect[2].x = rect[1].x;
163 MAXBOUND(rect[2].y, pR->y + (int) pR->height);
164
165 rect[3].x = rect[0].x;
166 rect[3].y = rect[2].y;
167
168 rect[4].x = rect[0].x;
169 rect[4].y = rect[0].y;
170
171 (*pGC->ops->Polylines) (pDraw, pGC, CoordModeOrigin, 5, rect);
172 pR++;
173 }
174 }
175 }