File: region.h

package info (click to toggle)
open-vm-tools 1%3A8.4.2-261024-1%2Bbuild1
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze-lts
  • size: 20,376 kB
  • ctags: 30,043
  • sloc: ansic: 164,785; sh: 10,713; cpp: 6,525; makefile: 3,386
file content (277 lines) | stat: -rw-r--r-- 9,678 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* **********************************************************
 * Copyright (C) 2002 VMware, Inc.
 * All Rights Reserved
 * **********************************************************/

/* $Xorg: regionstr.h,v 1.4 2001/02/09 02:05:15 xorgcvs Exp $ */
/***********************************************************

Copyright 1987, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/
/* $XFree86: xc/programs/Xserver/include/regionstr.h,v 1.7 2001/12/14 19:59:56 dawes Exp $ */

/*
 * region.h --
 *
 *      Interface definition for miRegion operations. Originally from X11
 *      source distribution. This version includes modifications made for the
 *      VNC Reflector package.
 *
 * ChangeLog:
 *
 *	07/21/2003 rrdharan     - added miRegionArea function prototype
 *	                        - added REGION_AREA wrapper macro
 *	                        - added this header, removed whitespace
 *	08/02/2005 akan		- fixed conflicting definition of MINSHORT
 *				  and MAXSHORT with winnt.h
 *      04/03/2007 shelleygong  - use int instead of short for data
 *                                inside the region
 * 02/12/2010 michael - Since coordinates are kept as ints, coordinate values
 *    shouldn't be clamped to the range of short. I removed R_{MIN,MAX}SHORT
 *    and changed clamping to be in the range R_MININT..R_MAXINT instead.
 *    Since some code does "n < R_MININT" and "n > R_MAXINT", R_MININT must be
 *    greater than INT_MIN and R_MAXINT must be less than INT_MAX.
 */

#ifndef __REGION_H__
#define __REGION_H__

#include "vmware.h"

#ifdef _WIN32
/*
 * lib/region has terrible short/long confusion problems.  For MSFT,
 * disable the warning.  See PR142264.
 */
#pragma warning( disable: 4242 )
#endif

/* Return values from RectIn() */
#define rgnOUT 0
#define rgnIN  1
#define rgnPART 2

#define NullBox ((BoxPtr)0)
#define NullRegion ((RegionPtr)0)

#define R_MAXINT 0x0FFFFFFF   /* Must be less than INT_MAX */
#define R_MININT 0x8FFFFFFF   /* Must be greater than INT_MIN */

#define CT_YXBANDED 18

#define xalloc(n)        malloc(n)
#define xrealloc(ptr, n) realloc((ptr), (n))
#define xfree(ptr)       free(ptr)

typedef enum {
   UpdateRect,
   ROPFillRect,
   Present3dRect,
   LockRect,
   FenceRect,
   MaxRect
} RectInfoType;

typedef struct RectInfo {
   RectInfoType type;
   union {
      struct {
         uint32 rop;
         uint32 color;
      } ROPFill;
      struct {
         uint32 sid;
         uint32 srcx, srcy;
      } Present3d;
      struct {
         uint32 fenceId;
      } Fence;
      /* add more here, then update miRectInfosEqual and miPrintRegion. */
   };
} RectInfo, *RectInfoPtr;

#define RECTINFO_ISVALID(info) \
   ((info).type >= UpdateRect && (info).type < MaxRect)

/*
 * X data types
 */

typedef struct _Box {
   int x1, y1, x2, y2;
   RectInfo info;
} BoxRec, *BoxPtr;

typedef struct _xPoint {
    int x, y;
} xPoint, *xPointPtr;

typedef xPoint DDXPointRec, *DDXPointPtr;

typedef struct _xRectangle {
    int x, y;
    unsigned short width, height;
    RectInfo info;
} xRectangle, *xRectanglePtr;

/*
 *   clip region
 */

typedef struct _RegData {
    int		size;
    int		numRects;
/*  BoxRec	rects[size];   in memory but not explicitly declared */
} RegDataRec, *RegDataPtr;

typedef struct _Region {
    BoxRec	extents;
    RegDataPtr	data;
} RegionRec, *RegionPtr;

extern BoxRec miEmptyBox;
extern RegDataRec miEmptyData;
extern RegDataRec miBrokenData;

#define REGION_EXTENTS(reg) (&(reg)->extents)
#define REGION_NIL(reg) ((reg)->data && !(reg)->data->numRects)
#define REGION_NAR(reg)	((reg)->data == &miBrokenData)
#define REGION_NUM_RECTS(reg) ((reg)->data ? (reg)->data->numRects : 1)
#define REGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0)
#define REGION_RECTS(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
			               : &(reg)->extents)
#define REGION_BOXPTR(reg) ((BoxPtr)((reg)->data + 1))
#define REGION_BOX(reg,i) (&REGION_BOXPTR(reg)[i])
#define REGION_TOP(reg) REGION_BOX(reg, (reg)->data->numRects)
#define REGION_END(reg) REGION_BOX(reg, (reg)->data->numRects - 1)
#define REGION_SZOF(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))

#define REGION_VALIDINDEX(reg, i) (i >= 0 && i < REGION_NUM_RECTS((reg)))

#define RECT_SETBOX(r, rx, ry, rw, rh) do { \
  (r)->x1 = (rx); \
  (r)->x2 = (rx) + (rw); \
  (r)->y1 = (ry); \
  (r)->y2 = (ry) + (rh); \
  (r)->info.type = UpdateRect; \
} while (FALSE)

#define RECT_SETRECT(r, rx1, ry1, rx2, ry2) do { \
  RECT_SETBOX((r), (rx1), (ry1), ((rx2) - (rx1)), ((ry2) - (ry1))); \
} while (FALSE)

#define RECT_SETVMRECT(r, vmr) \
  RECT_SETRECT((r), (vmr)->left,  (vmr)->top,  (vmr)->right,  (vmr)->bottom)

/*
 * This will only work if the intersection is not empty.
 */
#define RECT_INTERSECT(r, r1, r2) \
{ \
   (r)->x1 = MAX((r1)->x1, (r2)->x1); \
   (r)->x2 = MIN((r1)->x2, (r2)->x2); \
   (r)->y1 = MAX((r1)->y1, (r2)->y1); \
   (r)->y2 = MIN((r1)->y2, (r2)->y2); \
}

/*
 *  True iff the two boxes overlap.
 */
#define RECT_EXTENTCHECK(r1, r2) \
   (!( ((r1)->x2 <= (r2)->x1)  || \
       ((r1)->x1 >= (r2)->x2)  || \
       ((r1)->y2 <= (r2)->y1)  || \
       ((r1)->y1 >= (r2)->y2) ) )

/*
 * True iff both the BoxRecs are identical.
 */
#define RECT_IDENTICAL(r1, r2) \
   (( ((r1)->x1 == (r2)->x1)  && \
      ((r1)->x2 == (r2)->x2)  && \
      ((r1)->y1 == (r2)->y1)  && \
      ((r1)->y2 == (r2)->y2) ) )


extern RegionPtr miRegionCreate(BoxPtr rect, int size);
extern void miRegionInit(RegionPtr pReg, BoxPtr rect, int size);
extern void miRegionDestroy(RegionPtr pReg);
extern void miRegionUninit(RegionPtr pReg);
extern Bool miRegionCopy(RegionPtr dst, RegionPtr src);
extern Bool miIntersect(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2);
extern Bool miUnion(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2);
extern Bool miRegionAppend(RegionPtr dstrgn, RegionPtr rgn);
extern Bool miRegionValidate(RegionPtr badreg, Bool *pOverlap);
extern RegionPtr miRectsToRegion(int nrects, xRectanglePtr prect, int ctype);
extern RegionPtr miRectsToRegionbyBoundary(int nrects, xRectanglePtr prect, int ctype,
                                           int minValue, int maxValue);
extern Bool miSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS);
extern Bool miInverse(RegionPtr newReg, RegionPtr reg1, BoxPtr invRect);
extern int miRectIn(RegionPtr region, BoxPtr prect);
extern void miTranslateRegion(RegionPtr pReg, int x, int y);
extern void miTranslateRegionByBoundary(RegionPtr pReg, int x, int y,
                                        int minValue, int maxValue);
extern void miRegionReset(RegionPtr pReg, BoxPtr pBox);
extern Bool miRegionBreak(RegionPtr pReg);
extern Bool miPointInRegion(RegionPtr pReg, int x, int y, BoxPtr box);
extern Bool miRegionNotEmpty(RegionPtr pReg);
extern void miRegionEmpty(RegionPtr pReg);
extern Bool miRegionsEqual(RegionPtr reg1, RegionPtr reg2);
extern BoxPtr miRegionExtents(RegionPtr pReg);
extern int miRegionArea(RegionPtr pReg);
extern void miRegionPack(RegionPtr pReg, int threshold);

extern Bool miApplyRect(RegionPtr newReg, RegionPtr reg, BoxPtr rect,
                        Bool (*op) (RegionPtr, RegionPtr, RegionPtr));
extern int miPrintRegion(RegionPtr rgn);

typedef Bool (*miRegionMatchFunc)(BoxPtr box, uintptr_t userData);
extern Bool miRegionMatch(RegionPtr newReg, RegionPtr reg,
                          miRegionMatchFunc match, uintptr_t userData);

// Extension to REGION_NIL that also checks for a 0 x 0 bounding rect.
extern Bool miIsRegionVoid(RegionPtr pReg);

#endif /* __REGION_H__ */