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
80
* lib/region has terrible short/long confusion problems. For MSFT,
81
* disable the warning. See PR142264.
83
#pragma warning( disable: 4242 )
86
/* Return values from RectIn() */
91
#define NullBox ((BoxPtr)0)
92
#define NullRegion ((RegionPtr)0)
94
#define R_MAXSHORT 32767
95
#define R_MINSHORT (-R_MAXSHORT)
97
#define R_MAXINT 0x7FFFFFFF
98
#define R_MININT 0x8FFFFFFF
100
#define CT_YXBANDED 18
102
#define xalloc(n) malloc(n)
103
#define xrealloc(ptr, n) realloc((ptr), (n))
104
#define xfree(ptr) free(ptr)
113
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 RECT_SETBOX(r, rx, ry, rw, rh) do { \
188
(r)->x2 = (rx) + (rw); \
190
(r)->y2 = (ry) + (rh); \
191
(r)->info.type = UpdateRect; \
194
#define RECT_SETRECT(r, rx1, ry1, rx2, ry2) do { \
195
RECT_SETBOX((r), (rx1), (ry1), ((rx2) - (rx1)), ((ry2) - (ry1))); \
199
* This will only work if the intersection is not empty.
201
#define RECT_INTERSECT(r, r1, r2) \
203
(r)->x1 = MAX((r1)->x1, (r2)->x1); \
204
(r)->x2 = MIN((r1)->x2, (r2)->x2); \
205
(r)->y1 = MAX((r1)->y1, (r2)->y1); \
206
(r)->y2 = MIN((r1)->y2, (r2)->y2); \
210
* True iff the two boxes overlap.
212
#define RECT_EXTENTCHECK(r1, r2) \
213
(!( ((r1)->x2 <= (r2)->x1) || \
214
((r1)->x1 >= (r2)->x2) || \
215
((r1)->y2 <= (r2)->y1) || \
216
((r1)->y1 >= (r2)->y2) ) )
219
* True iff both the BoxRecs are identical.
221
#define RECT_IDENTICAL(r1, r2) \
222
(( ((r1)->x1 == (r2)->x1) && \
223
((r1)->x2 == (r2)->x2) && \
224
((r1)->y1 == (r2)->y1) && \
225
((r1)->y2 == (r2)->y2) ) )
228
extern RegionPtr miRegionCreate(BoxPtr rect, int size);
229
extern void miRegionInit(RegionPtr pReg, BoxPtr rect, int size);
230
extern void miRegionDestroy(RegionPtr pReg);
231
extern void miRegionUninit(RegionPtr pReg);
232
extern Bool miRegionCopy(RegionPtr dst, RegionPtr src);
233
extern Bool miIntersect(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2);
234
extern Bool miUnion(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2);
235
extern Bool miRegionAppend(RegionPtr dstrgn, RegionPtr rgn);
236
extern Bool miRegionValidate(RegionPtr badreg, Bool *pOverlap);
237
extern RegionPtr miRectsToRegion(int nrects, xRectanglePtr prect, int ctype);
238
extern RegionPtr miRectsToRegionbyBoundary(int nrects, xRectanglePtr prect, int ctype,
239
int minValue, int maxValue);
240
extern Bool miSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS);
241
extern Bool miInverse(RegionPtr newReg, RegionPtr reg1, BoxPtr invRect);
242
extern int miRectIn(RegionPtr region, BoxPtr prect);
243
extern void miTranslateRegion(RegionPtr pReg, int x, int y);
244
extern void miTranslateRegionByBoundary(RegionPtr pReg, int x, int y,
245
int minValue, int maxValue);
246
extern void miRegionReset(RegionPtr pReg, BoxPtr pBox);
247
extern Bool miRegionBreak(RegionPtr pReg);
248
extern Bool miPointInRegion(RegionPtr pReg, int x, int y, BoxPtr box);
249
extern Bool miRegionNotEmpty(RegionPtr pReg);
250
extern void miRegionEmpty(RegionPtr pReg);
251
extern Bool miRegionsEqual(RegionPtr reg1, RegionPtr reg2);
252
extern BoxPtr miRegionExtents(RegionPtr pReg);
253
extern int miRegionArea(RegionPtr pReg);
254
extern void miRegionPack(RegionPtr pReg, int threshold);
256
extern Bool miApplyRect(RegionPtr newReg, RegionPtr reg, BoxPtr rect,
257
Bool (*op) (RegionPtr, RegionPtr, RegionPtr));
258
extern int miPrintRegion(RegionPtr rgn);
260
typedef Bool (*miRegionMatchFunc)(BoxPtr box, uintptr_t userData);
261
extern Bool miRegionMatch(RegionPtr newReg, RegionPtr reg,
262
miRegionMatchFunc match, uintptr_t userData);
264
// Extension to REGION_NIL that also checks for a 0 x 0 bounding rect.
265
extern Bool miIsRegionVoid(RegionPtr pReg);
267
#endif /* __REGION_H__ */