1
/* **********************************************************
2
* Copyright (C) 2002 VMware, Inc.
4
* **********************************************************/
6
/* $Xorg: regionstr.h,v 1.4 2001/02/09 02:05:15 xorgcvs Exp $ */
7
/***********************************************************
9
Copyright 1987, 1998 The Open Group
11
Permission to use, copy, modify, distribute, and sell this software and its
12
documentation for any purpose is hereby granted without fee, provided that
13
the above copyright notice appear in all copies and that both that
14
copyright notice and this permission notice appear in supporting
17
The above copyright notice and this permission notice shall be included in
18
all copies or substantial portions of the Software.
20
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
Except as contained in this notice, the name of The Open Group shall not be
28
used in advertising or otherwise to promote the sale, use or other dealings
29
in this Software without prior written authorization from The Open Group.
32
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
36
Permission to use, copy, modify, and distribute this software and its
37
documentation for any purpose and without fee is hereby granted,
38
provided that the above copyright notice appear in all copies and that
39
both that copyright notice and this permission notice appear in
40
supporting documentation, and that the name of Digital not be
41
used in advertising or publicity pertaining to distribution of the
42
software without specific, written prior permission.
44
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
45
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
46
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
47
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
48
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
49
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
52
******************************************************************/
53
/* $XFree86: xc/programs/Xserver/include/regionstr.h,v 1.7 2001/12/14 19:59:56 dawes Exp $ */
58
* Interface definition for miRegion operations. Originally from X11
59
* source distribution. This version includes modifications made for the
60
* VNC Reflector package.
64
* 07/21/2003 rrdharan - added miRegionArea function prototype
65
* - added REGION_AREA wrapper macro
66
* - added this header, removed whitespace
67
* 08/02/2005 akan - fixed conflicting definition of MINSHORT
68
* and MAXSHORT with winnt.h
69
* 04/03/2007 shelleygong - use int instead of short for data
71
* 02/12/2010 michael - Since coordinates are kept as ints, coordinate values
72
* shouldn't be clamped to the range of short. I removed R_{MIN,MAX}SHORT
73
* and changed clamping to be in the range R_MININT..R_MAXINT instead.
74
* Since some code does "n < R_MININT" and "n > R_MAXINT", R_MININT must be
75
* greater than INT_MIN and R_MAXINT must be less than INT_MAX.
76
* 03/08/2010 amarp - Move xalloc macro outside the header because of
77
* boost conflict with macro
85
/* Return values from RectIn() */
90
#define NullBox ((BoxPtr)0)
91
#define NullRegion ((RegionPtr)0)
93
#define R_MAXINT 0x0FFFFFFF /* Must be less than INT_MAX */
94
#define R_MININT 0x8FFFFFFF /* Must be greater than INT_MIN */
96
#define CT_YXBANDED 18
98
#define xrealloc(ptr, n) realloc((ptr), (n))
99
#define xfree(ptr) free(ptr)
110
typedef struct RectInfo {
124
/* add more here, then update miRectInfosEqual and miPrintRegion. */
126
} RectInfo, *RectInfoPtr;
128
#define RECTINFO_ISVALID(info) \
129
((info).type >= UpdateRect && (info).type < MaxRect)
135
typedef struct _Box {
140
typedef struct _xPoint {
142
} xPoint, *xPointPtr;
144
typedef xPoint DDXPointRec, *DDXPointPtr;
146
typedef struct _xRectangle {
148
unsigned short width, height;
150
} xRectangle, *xRectanglePtr;
156
typedef struct _RegData {
159
/* BoxRec rects[size]; in memory but not explicitly declared */
160
} RegDataRec, *RegDataPtr;
162
typedef struct _Region {
165
} RegionRec, *RegionPtr;
167
extern BoxRec miEmptyBox;
168
extern RegDataRec miEmptyData;
169
extern RegDataRec miBrokenData;
171
#define REGION_EXTENTS(reg) (&(reg)->extents)
172
#define REGION_NIL(reg) ((reg)->data && !(reg)->data->numRects)
173
#define REGION_NAR(reg) ((reg)->data == &miBrokenData)
174
#define REGION_NUM_RECTS(reg) ((reg)->data ? (reg)->data->numRects : 1)
175
#define REGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0)
176
#define REGION_RECTS(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
178
#define REGION_BOXPTR(reg) ((BoxPtr)((reg)->data + 1))
179
#define REGION_BOX(reg,i) (®ION_BOXPTR(reg)[i])
180
#define REGION_TOP(reg) REGION_BOX(reg, (reg)->data->numRects)
181
#define REGION_END(reg) REGION_BOX(reg, (reg)->data->numRects - 1)
182
#define REGION_SZOF(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))
184
#define REGION_VALIDINDEX(reg, i) (i >= 0 && i < REGION_NUM_RECTS((reg)))
186
#define BOX_X(ptr) (ptr->x1)
187
#define BOX_Y(ptr) (ptr->y1)
188
#define BOX_WIDTH(ptr) (ptr->x2 - ptr->x1)
189
#define BOX_HEIGHT(ptr) (ptr->y2 - ptr->y1)
190
#define BOX_XY(ptr) BOX_X(ptr), BOX_Y(ptr)
191
#define BOX_WH(ptr) BOX_WIDTH(ptr), BOX_HEIGHT(ptr)
192
#define BOX_XYWH(ptr) BOX_XY(ptr), BOX_WH(ptr)
194
#define RECT_SETBOX(r, rx, ry, rw, rh) do { \
196
(r)->x2 = (rx) + (rw); \
198
(r)->y2 = (ry) + (rh); \
199
(r)->info.type = UpdateRect; \
202
#define RECT_SETRECT(r, rx1, ry1, rx2, ry2) do { \
203
RECT_SETBOX((r), (rx1), (ry1), ((rx2) - (rx1)), ((ry2) - (ry1))); \
206
#define RECT_SETVMRECT(r, vmr) \
207
RECT_SETRECT((r), (vmr)->left, (vmr)->top, (vmr)->right, (vmr)->bottom)
210
* This will only work if the intersection is not empty.
212
#define RECT_INTERSECT(r, r1, r2) \
214
(r)->x1 = MAX((r1)->x1, (r2)->x1); \
215
(r)->x2 = MIN((r1)->x2, (r2)->x2); \
216
(r)->y1 = MAX((r1)->y1, (r2)->y1); \
217
(r)->y2 = MIN((r1)->y2, (r2)->y2); \
221
* True iff the two boxes overlap.
223
#define RECT_EXTENTCHECK(r1, r2) \
224
(!( ((r1)->x2 <= (r2)->x1) || \
225
((r1)->x1 >= (r2)->x2) || \
226
((r1)->y2 <= (r2)->y1) || \
227
((r1)->y1 >= (r2)->y2) ) )
230
* True iff both the BoxRecs are identical.
232
#define RECT_IDENTICAL(r1, r2) \
233
(( ((r1)->x1 == (r2)->x1) && \
234
((r1)->x2 == (r2)->x2) && \
235
((r1)->y1 == (r2)->y1) && \
236
((r1)->y2 == (r2)->y2) ) )
239
extern RegionPtr miRegionCreate(BoxPtr rect, int size);
240
extern void miRegionInit(RegionPtr pReg, BoxPtr rect, int size);
241
extern void miRegionDestroy(RegionPtr pReg);
242
extern void miRegionUninit(RegionPtr pReg);
243
extern Bool miRegionCopy(RegionPtr dst, RegionPtr src);
244
extern Bool miIntersect(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2);
245
extern Bool miUnion(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2);
246
extern Bool miRegionAppend(RegionPtr dstrgn, RegionPtr rgn);
247
extern Bool miRegionValidate(RegionPtr badreg, Bool *pOverlap);
248
extern RegionPtr miRectsToRegion(int nrects, xRectanglePtr prect, int ctype);
249
extern RegionPtr miRectsToRegionbyBoundary(int nrects, xRectanglePtr prect, int ctype,
250
int minValue, int maxValue);
251
extern Bool miSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS);
252
extern Bool miInverse(RegionPtr newReg, RegionPtr reg1, BoxPtr invRect);
253
extern int miRectIn(RegionPtr region, BoxPtr prect);
254
extern void miTranslateRegion(RegionPtr pReg, int x, int y);
255
extern void miTranslateRegionByBoundary(RegionPtr pReg, int x, int y,
256
int minValue, int maxValue);
257
extern void miRegionReset(RegionPtr pReg, BoxPtr pBox);
258
extern Bool miRegionBreak(RegionPtr pReg);
259
extern Bool miPointInRegion(RegionPtr pReg, int x, int y, BoxPtr box);
260
extern Bool miRegionNotEmpty(RegionPtr pReg);
261
extern void miRegionEmpty(RegionPtr pReg);
262
extern Bool miRegionsEqual(RegionPtr reg1, RegionPtr reg2);
263
extern BoxPtr miRegionExtents(RegionPtr pReg);
264
extern int miRegionArea(RegionPtr pReg);
265
extern void miRegionPack(RegionPtr pReg, int threshold);
267
extern Bool miApplyRect(RegionPtr newReg, RegionPtr reg, BoxPtr rect,
268
Bool (*op) (RegionPtr, RegionPtr, RegionPtr));
269
extern int miPrintRegion(RegionPtr rgn);
271
typedef Bool (*miRegionMatchFunc)(BoxPtr box, uintptr_t userData);
272
extern Bool miRegionMatch(RegionPtr newReg, RegionPtr reg,
273
miRegionMatchFunc match, uintptr_t userData);
275
// Extension to REGION_NIL that also checks for a 0 x 0 bounding rect.
276
extern Bool miIsRegionVoid(RegionPtr pReg);
278
#endif /* __REGION_H__ */