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 |
|
---|
26 | Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
---|
27 |
|
---|
28 | All Rights Reserved
|
---|
29 |
|
---|
30 | Permission to use, copy, modify, and distribute this software and its
|
---|
31 | documentation for any purpose and without fee is hereby granted,
|
---|
32 | provided that the above copyright notice appear in all copies and that
|
---|
33 | both that copyright notice and this permission notice appear in
|
---|
34 | supporting documentation, and that the name of Digital not be
|
---|
35 | used in advertising or publicity pertaining to distribution of the
|
---|
36 | software without specific, written prior permission.
|
---|
37 |
|
---|
38 | DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
---|
39 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
---|
40 | DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
---|
41 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
---|
42 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
---|
43 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
---|
44 | SOFTWARE.
|
---|
45 |
|
---|
46 | ******************************************************************/
|
---|
47 |
|
---|
48 | #ifndef REGIONSTRUCT_H
|
---|
49 | #define REGIONSTRUCT_H
|
---|
50 |
|
---|
51 | typedef struct pixman_region16 RegionRec, *RegionPtr;
|
---|
52 |
|
---|
53 | #include "miscstruct.h"
|
---|
54 |
|
---|
55 | /* Return values from RectIn() */
|
---|
56 |
|
---|
57 | #define rgnOUT 0
|
---|
58 | #define rgnIN 1
|
---|
59 | #define rgnPART 2
|
---|
60 |
|
---|
61 | #define NullRegion ((RegionPtr)0)
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * clip region
|
---|
65 | */
|
---|
66 |
|
---|
67 | typedef struct pixman_region16_data RegDataRec, *RegDataPtr;
|
---|
68 |
|
---|
69 | extern _X_EXPORT BoxRec RegionEmptyBox;
|
---|
70 | extern _X_EXPORT RegDataRec RegionEmptyData;
|
---|
71 | extern _X_EXPORT RegDataRec RegionBrokenData;
|
---|
72 | static inline Bool RegionNil(RegionPtr reg) {
|
---|
73 | return ((reg)->data && !(reg)->data->numRects);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /* not a region */
|
---|
77 |
|
---|
78 | static inline Bool RegionNar(RegionPtr reg) {
|
---|
79 | return ((reg)->data == &RegionBrokenData);
|
---|
80 | }
|
---|
81 |
|
---|
82 | static inline int RegionNumRects(RegionPtr reg) {
|
---|
83 | return ((reg)->data ? (reg)->data->numRects : 1);
|
---|
84 | }
|
---|
85 |
|
---|
86 | static inline int RegionSize(RegionPtr reg) {
|
---|
87 | return ((reg)->data ? (reg)->data->size : 0);
|
---|
88 | }
|
---|
89 |
|
---|
90 | static inline BoxPtr RegionRects(RegionPtr reg) {
|
---|
91 | return ((reg)->data ? (BoxPtr)((reg)->data + 1) : &(reg)->extents);
|
---|
92 | }
|
---|
93 |
|
---|
94 | static inline BoxPtr RegionBoxptr(RegionPtr reg) {
|
---|
95 | return ((BoxPtr)((reg)->data + 1));
|
---|
96 | }
|
---|
97 |
|
---|
98 | static inline BoxPtr RegionBox(RegionPtr reg, int i) {
|
---|
99 | return (&RegionBoxptr(reg)[i]);
|
---|
100 | }
|
---|
101 |
|
---|
102 | static inline BoxPtr RegionTop(RegionPtr reg) {
|
---|
103 | return RegionBox(reg, (reg)->data->numRects);
|
---|
104 | }
|
---|
105 |
|
---|
106 | static inline BoxPtr RegionEnd(RegionPtr reg) {
|
---|
107 | return RegionBox(reg, (reg)->data->numRects - 1);
|
---|
108 | }
|
---|
109 |
|
---|
110 | static inline size_t RegionSizeof(int n) {
|
---|
111 | return (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)));
|
---|
112 | }
|
---|
113 |
|
---|
114 | static inline void RegionInit(RegionPtr _pReg, BoxPtr _rect, int _size)
|
---|
115 | {
|
---|
116 | if ((_rect) != NULL)
|
---|
117 | {
|
---|
118 | (_pReg)->extents = *(_rect);
|
---|
119 | (_pReg)->data = (RegDataPtr)NULL;
|
---|
120 | }
|
---|
121 | else
|
---|
122 | {
|
---|
123 | (_pReg)->extents = RegionEmptyBox;
|
---|
124 | if (((_size) > 1) && ((_pReg)->data =
|
---|
125 | (RegDataPtr)malloc(RegionSizeof(_size))))
|
---|
126 | {
|
---|
127 | (_pReg)->data->size = (_size);
|
---|
128 | (_pReg)->data->numRects = 0;
|
---|
129 | }
|
---|
130 | else
|
---|
131 | (_pReg)->data = &RegionEmptyData;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | static inline void RegionUninit(RegionPtr _pReg)
|
---|
136 | {
|
---|
137 | if ((_pReg)->data && (_pReg)->data->size) {
|
---|
138 | free((_pReg)->data);
|
---|
139 | (_pReg)->data = NULL;
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | static inline void RegionReset(RegionPtr _pReg, BoxPtr _pBox)
|
---|
144 | {
|
---|
145 | (_pReg)->extents = *(_pBox);
|
---|
146 | RegionUninit(_pReg);
|
---|
147 | (_pReg)->data = (RegDataPtr)NULL;
|
---|
148 | }
|
---|
149 |
|
---|
150 | static inline Bool RegionNotEmpty(RegionPtr _pReg) {
|
---|
151 | return !RegionNil(_pReg);
|
---|
152 | }
|
---|
153 |
|
---|
154 | static inline Bool RegionBroken(RegionPtr _pReg) {
|
---|
155 | return RegionNar(_pReg);
|
---|
156 | }
|
---|
157 |
|
---|
158 | static inline void RegionEmpty(RegionPtr _pReg)
|
---|
159 | {
|
---|
160 | RegionUninit(_pReg);
|
---|
161 | (_pReg)->extents.x2 = (_pReg)->extents.x1;
|
---|
162 | (_pReg)->extents.y2 = (_pReg)->extents.y1;
|
---|
163 | (_pReg)->data = &RegionEmptyData;
|
---|
164 | }
|
---|
165 |
|
---|
166 | static inline BoxPtr RegionExtents(RegionPtr _pReg)
|
---|
167 | {
|
---|
168 | return (&(_pReg)->extents);
|
---|
169 | }
|
---|
170 |
|
---|
171 | static inline void RegionNull(RegionPtr _pReg)
|
---|
172 | {
|
---|
173 | (_pReg)->extents = RegionEmptyBox;
|
---|
174 | (_pReg)->data = &RegionEmptyData;
|
---|
175 | }
|
---|
176 |
|
---|
177 | extern _X_EXPORT void InitRegions(void);
|
---|
178 |
|
---|
179 | extern _X_EXPORT RegionPtr RegionCreate(
|
---|
180 | BoxPtr /*rect*/,
|
---|
181 | int /*size*/);
|
---|
182 |
|
---|
183 | extern _X_EXPORT void RegionDestroy(
|
---|
184 | RegionPtr /*pReg*/);
|
---|
185 |
|
---|
186 | static inline Bool
|
---|
187 | RegionCopy(RegionPtr dst, RegionPtr src)
|
---|
188 | {
|
---|
189 | return pixman_region_copy (dst, src);
|
---|
190 | }
|
---|
191 |
|
---|
192 | static inline Bool
|
---|
193 | RegionIntersect(
|
---|
194 | RegionPtr newReg, /* destination Region */
|
---|
195 | RegionPtr reg1,
|
---|
196 | RegionPtr reg2 /* source regions */
|
---|
197 | )
|
---|
198 | {
|
---|
199 | return pixman_region_intersect (newReg, reg1, reg2);
|
---|
200 | }
|
---|
201 |
|
---|
202 | static inline Bool
|
---|
203 | RegionUnion(
|
---|
204 | RegionPtr newReg, /* destination Region */
|
---|
205 | RegionPtr reg1,
|
---|
206 | RegionPtr reg2 /* source regions */
|
---|
207 | )
|
---|
208 | {
|
---|
209 | return pixman_region_union (newReg, reg1, reg2);
|
---|
210 | }
|
---|
211 |
|
---|
212 | extern _X_EXPORT Bool RegionAppend(
|
---|
213 | RegionPtr /*dstrgn*/,
|
---|
214 | RegionPtr /*rgn*/);
|
---|
215 |
|
---|
216 | extern _X_EXPORT Bool RegionValidate(
|
---|
217 | RegionPtr /*badreg*/,
|
---|
218 | Bool * /*pOverlap*/);
|
---|
219 |
|
---|
220 | extern _X_EXPORT RegionPtr RegionFromRects(
|
---|
221 | int /*nrects*/,
|
---|
222 | xRectanglePtr /*prect*/,
|
---|
223 | int /*ctype*/);
|
---|
224 |
|
---|
225 | /*-
|
---|
226 | *-----------------------------------------------------------------------
|
---|
227 | * Subtract --
|
---|
228 | * Subtract regS from regM and leave the result in regD.
|
---|
229 | * S stands for subtrahend, M for minuend and D for difference.
|
---|
230 | *
|
---|
231 | * Results:
|
---|
232 | * TRUE if successful.
|
---|
233 | *
|
---|
234 | * Side Effects:
|
---|
235 | * regD is overwritten.
|
---|
236 | *
|
---|
237 | *-----------------------------------------------------------------------
|
---|
238 | */
|
---|
239 | static inline Bool
|
---|
240 | RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
|
---|
241 | {
|
---|
242 | return pixman_region_subtract (regD, regM, regS);
|
---|
243 | }
|
---|
244 |
|
---|
245 | /*-
|
---|
246 | *-----------------------------------------------------------------------
|
---|
247 | * Inverse --
|
---|
248 | * Take a region and a box and return a region that is everything
|
---|
249 | * in the box but not in the region. The careful reader will note
|
---|
250 | * that this is the same as subtracting the region from the box...
|
---|
251 | *
|
---|
252 | * Results:
|
---|
253 | * TRUE.
|
---|
254 | *
|
---|
255 | * Side Effects:
|
---|
256 | * newReg is overwritten.
|
---|
257 | *
|
---|
258 | *-----------------------------------------------------------------------
|
---|
259 | */
|
---|
260 |
|
---|
261 | static inline Bool
|
---|
262 | RegionInverse(
|
---|
263 | RegionPtr newReg, /* Destination region */
|
---|
264 | RegionPtr reg1, /* Region to invert */
|
---|
265 | BoxPtr invRect /* Bounding box for inversion */
|
---|
266 | )
|
---|
267 | {
|
---|
268 | return pixman_region_inverse (newReg, reg1, invRect);
|
---|
269 | }
|
---|
270 |
|
---|
271 | static inline int
|
---|
272 | RegionContainsRect(RegionPtr region, BoxPtr prect)
|
---|
273 | {
|
---|
274 | return pixman_region_contains_rectangle (region, prect);
|
---|
275 | }
|
---|
276 |
|
---|
277 | /* TranslateRegion(pReg, x, y)
|
---|
278 | translates in place
|
---|
279 | */
|
---|
280 |
|
---|
281 | static inline void
|
---|
282 | RegionTranslate(RegionPtr pReg, int x, int y)
|
---|
283 | {
|
---|
284 | pixman_region_translate (pReg, x, y);
|
---|
285 | }
|
---|
286 |
|
---|
287 | extern _X_EXPORT Bool RegionBreak(
|
---|
288 | RegionPtr /*pReg*/);
|
---|
289 |
|
---|
290 | static inline Bool
|
---|
291 | RegionContainsPoint(
|
---|
292 | RegionPtr pReg,
|
---|
293 | int x,
|
---|
294 | int y,
|
---|
295 | BoxPtr box /* "return" value */
|
---|
296 | )
|
---|
297 | {
|
---|
298 | return pixman_region_contains_point (pReg, x, y, box);
|
---|
299 | }
|
---|
300 |
|
---|
301 | static inline Bool
|
---|
302 | RegionEqual(RegionPtr reg1, RegionPtr reg2)
|
---|
303 | {
|
---|
304 | return pixman_region_equal (reg1, reg2);
|
---|
305 | }
|
---|
306 |
|
---|
307 | extern _X_EXPORT Bool RegionRectAlloc(
|
---|
308 | RegionPtr /*pRgn*/,
|
---|
309 | int /*n*/
|
---|
310 | );
|
---|
311 |
|
---|
312 | #ifdef DEBUG
|
---|
313 | extern _X_EXPORT Bool RegionIsValid(
|
---|
314 | RegionPtr /*prgn*/
|
---|
315 | );
|
---|
316 | #endif
|
---|
317 |
|
---|
318 | extern _X_EXPORT void RegionPrint(
|
---|
319 | RegionPtr /*pReg*/);
|
---|
320 |
|
---|
321 | extern _X_EXPORT int RegionClipSpans(
|
---|
322 | RegionPtr /*prgnDst*/,
|
---|
323 | DDXPointPtr /*ppt*/,
|
---|
324 | int * /*pwidth*/,
|
---|
325 | int /*nspans*/,
|
---|
326 | DDXPointPtr /*pptNew*/,
|
---|
327 | int * /*pwidthNew*/,
|
---|
328 | int /*fSorted*/
|
---|
329 | );
|
---|
330 |
|
---|
331 | #define INCLUDE_LEGACY_REGION_DEFINES
|
---|
332 | #ifdef INCLUDE_LEGACY_REGION_DEFINES
|
---|
333 |
|
---|
334 | #define REGION_NIL RegionNil
|
---|
335 | #define REGION_NAR RegionNar
|
---|
336 | #define REGION_NUM_RECTS RegionNumRects
|
---|
337 | #define REGION_SIZE RegionSize
|
---|
338 | #define REGION_RECTS RegionRects
|
---|
339 | #define REGION_BOXPTR RegionBoxptr
|
---|
340 | #define REGION_BOX RegionBox
|
---|
341 | #define REGION_TOP RegionTop
|
---|
342 | #define REGION_END RegionEnd
|
---|
343 | #define REGION_SZOF RegionSizeof
|
---|
344 | #define BITMAP_TO_REGION BitmapToRegion
|
---|
345 | #define REGION_CREATE(pScreen, r, s) RegionCreate(r,s)
|
---|
346 | #define REGION_COPY(pScreen, d, r) RegionCopy(d, r)
|
---|
347 | #define REGION_DESTROY(pScreen, r) RegionDestroy(r)
|
---|
348 | #define REGION_INTERSECT(pScreen, res, r1, r2) RegionIntersect(res, r1, r2)
|
---|
349 | #define REGION_UNION(pScreen, res, r1, r2) RegionUnion(res, r1, r2)
|
---|
350 | #define REGION_SUBTRACT(pScreen, res, r1, r2) RegionSubtract(res, r1, r2)
|
---|
351 | #define REGION_INVERSE(pScreen, n, r, b) RegionInverse(n, r, b)
|
---|
352 | #define REGION_TRANSLATE(pScreen, r, x, y) RegionTranslate(r, x, y)
|
---|
353 | #define RECT_IN_REGION(pScreen, r, b) RegionContainsRect(r, b)
|
---|
354 | #define POINT_IN_REGION(pScreen, r, x, y, b) RegionContainsPoint(r, x, y, b)
|
---|
355 | #define REGION_EQUAL(pScreen, r1, r2) RegionEqual(r1, r2)
|
---|
356 | #define REGION_APPEND(pScreen, d, r) RegionAppend(d, r)
|
---|
357 | #define REGION_VALIDATE(pScreen, r, o) RegionValidate(r, o)
|
---|
358 | #define RECTS_TO_REGION(pScreen, n, r, c) RegionFromRects(n, r, c)
|
---|
359 | #define REGION_BREAK(pScreen, r) RegionBreak(r)
|
---|
360 | #define REGION_INIT(pScreen, r, b, s) RegionInit(r, b, s)
|
---|
361 | #define REGION_UNINIT(pScreen, r) RegionUninit(r)
|
---|
362 | #define REGION_RESET(pScreen, r, b) RegionReset(r, b)
|
---|
363 | #define REGION_NOTEMPTY(pScreen, r) RegionNotEmpty(r)
|
---|
364 | #define REGION_BROKEN(pScreen, r) RegionBroken(r)
|
---|
365 | #define REGION_EMPTY(pScreen, r) RegionEmpty(r)
|
---|
366 | #define REGION_EXTENTS(pScreen, r) RegionExtents(r)
|
---|
367 | #define REGION_NULL(pScreen, r) RegionNull(r)
|
---|
368 |
|
---|
369 | #endif /* INCLUDE_LEGACY_REGION_DEFINES */
|
---|
370 | #endif /* REGIONSTRUCT_H */
|
---|