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