regionstr.h 10.6 KB
Newer Older
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
/***********************************************************

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

29 30
Permission to use, copy, modify, and distribute this software and its
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 34
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
35
software without specific, written prior permission.
36 37 38 39 40 41 42 43 44 45

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.

******************************************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
46

47 48 49
#ifndef REGIONSTRUCT_H
#define REGIONSTRUCT_H

50
typedef struct pixman_region16 RegionRec, *RegionPtr;
51

52 53 54 55 56 57 58 59 60 61
#include "miscstruct.h"

/* Return values from RectIn() */

#define rgnOUT 0
#define rgnIN  1
#define rgnPART 2

#define NullRegion ((RegionPtr)0)

62
/*
63 64 65
 *   clip region
 */

66
typedef struct pixman_region16_data RegDataRec, *RegDataPtr;
67

68 69 70
extern _X_EXPORT BoxRec RegionEmptyBox;
extern _X_EXPORT RegDataRec RegionEmptyData;
extern _X_EXPORT RegDataRec RegionBrokenData;
71 72 73
static inline Bool
RegionNil(RegionPtr reg)
{
74 75
    return ((reg)->data && !(reg)->data->numRects);
}
76

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
77
/* not a region */
78

79 80 81
static inline Bool
RegionNar(RegionPtr reg)
{
82 83 84
    return ((reg)->data == &RegionBrokenData);
}

85 86 87
static inline int
RegionNumRects(RegionPtr reg)
{
88 89 90
    return ((reg)->data ? (reg)->data->numRects : 1);
}

91 92 93
static inline int
RegionSize(RegionPtr reg)
{
94
    return ((reg)->data ? (reg)->data->size : 0);
95 96
}

97 98 99 100
static inline BoxPtr
RegionRects(RegionPtr reg)
{
    return ((reg)->data ? (BoxPtr) ((reg)->data + 1) : &(reg)->extents);
101 102
}

103 104 105 106
static inline BoxPtr
RegionBoxptr(RegionPtr reg)
{
    return ((BoxPtr) ((reg)->data + 1));
107
}
108

109 110 111
static inline BoxPtr
RegionBox(RegionPtr reg, int i)
{
112 113
    return (&RegionBoxptr(reg)[i]);
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
114

115 116 117
static inline BoxPtr
RegionTop(RegionPtr reg)
{
118
    return RegionBox(reg, (reg)->data->numRects);
119 120
}

121 122 123
static inline BoxPtr
RegionEnd(RegionPtr reg)
{
124 125
    return RegionBox(reg, (reg)->data->numRects - 1);
}
126

127
static inline size_t
128
RegionSizeof(size_t n)
129
{
130 131 132 133
    if (n < ((INT_MAX - sizeof(RegDataRec)) / sizeof(BoxRec)))
        return (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)));
    else
        return 0;
134
}
135

136 137
static inline void
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) &&
Adam Jackson's avatar
Adam Jackson committed
147
            (((_pReg)->data = (RegDataPtr) malloc(rgnSize)) != NULL)) {
148 149 150 151 152 153 154
            (_pReg)->data->size = (_size);
            (_pReg)->data->numRects = 0;
        }
        else
            (_pReg)->data = &RegionEmptyData;
    }
}
155

156 157
static inline Bool
RegionInitBoxes(RegionPtr pReg, BoxPtr boxes, int nBoxes)
158
{
159
    return pixman_region_init_rects(pReg, boxes, nBoxes);
160 161
}

162 163
static inline void
RegionUninit(RegionPtr _pReg)
164 165
{
    if ((_pReg)->data && (_pReg)->data->size) {
166 167
        free((_pReg)->data);
        (_pReg)->data = NULL;
168 169 170
    }
}

171 172
static inline void
RegionReset(RegionPtr _pReg, BoxPtr _pBox)
173 174 175
{
    (_pReg)->extents = *(_pBox);
    RegionUninit(_pReg);
176
    (_pReg)->data = (RegDataPtr) NULL;
177 178
}

179 180 181
static inline Bool
RegionNotEmpty(RegionPtr _pReg)
{
182 183 184
    return !RegionNil(_pReg);
}

185 186 187
static inline Bool
RegionBroken(RegionPtr _pReg)
{
188 189 190
    return RegionNar(_pReg);
}

191 192
static inline void
RegionEmpty(RegionPtr _pReg)
193 194 195 196 197 198 199
{
    RegionUninit(_pReg);
    (_pReg)->extents.x2 = (_pReg)->extents.x1;
    (_pReg)->extents.y2 = (_pReg)->extents.y1;
    (_pReg)->data = &RegionEmptyData;
}

200 201
static inline BoxPtr
RegionExtents(RegionPtr _pReg)
202 203 204 205
{
    return (&(_pReg)->extents);
}

206 207
static inline void
RegionNull(RegionPtr _pReg)
208 209 210 211 212 213
{
    (_pReg)->extents = RegionEmptyBox;
    (_pReg)->data = &RegionEmptyData;
}

extern _X_EXPORT void InitRegions(void);
214

215 216
extern _X_EXPORT RegionPtr RegionCreate(BoxPtr /*rect */ ,
                                        int /*size */ );
217

218
extern _X_EXPORT void RegionDestroy(RegionPtr /*pReg */ );
219

Keith Packard's avatar
Keith Packard committed
220 221
extern _X_EXPORT RegionPtr RegionDuplicate(RegionPtr /* pOld */);

222 223 224
static inline Bool
RegionCopy(RegionPtr dst, RegionPtr src)
{
225
    return pixman_region_copy(dst, src);
226
}
227

228
static inline Bool
229 230
RegionIntersect(RegionPtr newReg,       /* destination Region */
                RegionPtr reg1, RegionPtr reg2  /* source regions     */
231 232
    )
{
233
    return pixman_region_intersect(newReg, reg1, reg2);
234
}
235

236
static inline Bool
237 238
RegionUnion(RegionPtr newReg,   /* destination Region */
            RegionPtr reg1, RegionPtr reg2      /* source regions     */
239 240
    )
{
241
    return pixman_region_union(newReg, reg1, reg2);
242
}
243

244 245
extern _X_EXPORT Bool RegionAppend(RegionPtr /*dstrgn */ ,
                                   RegionPtr /*rgn */ );
246

247 248
extern _X_EXPORT Bool RegionValidate(RegionPtr /*badreg */ ,
                                     Bool * /*pOverlap */ );
249

250 251 252
extern _X_EXPORT RegionPtr RegionFromRects(int /*nrects */ ,
                                           xRectanglePtr /*prect */ ,
                                           int /*ctype */ );
253

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
/*-
 *-----------------------------------------------------------------------
 * Subtract --
 *	Subtract regS from regM and leave the result in regD.
 *	S stands for subtrahend, M for minuend and D for difference.
 *
 * Results:
 *	TRUE if successful.
 *
 * Side Effects:
 *	regD is overwritten.
 *
 *-----------------------------------------------------------------------
 */
static inline Bool
RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
{
271
    return pixman_region_subtract(regD, regM, regS);
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
}

/*-
 *-----------------------------------------------------------------------
 * Inverse --
 *	Take a region and a box and return a region that is everything
 *	in the box but not in the region. The careful reader will note
 *	that this is the same as subtracting the region from the box...
 *
 * Results:
 *	TRUE.
 *
 * Side Effects:
 *	newReg is overwritten.
 *
 *-----------------------------------------------------------------------
 */
289

290
static inline Bool
291 292 293
RegionInverse(RegionPtr newReg, /* Destination region */
              RegionPtr reg1,   /* Region to invert */
              BoxPtr invRect    /* Bounding box for inversion */
294 295
    )
{
296
    return pixman_region_inverse(newReg, reg1, invRect);
297
}
298

299 300 301
static inline int
RegionContainsRect(RegionPtr region, BoxPtr prect)
{
302
    return pixman_region_contains_rectangle(region, prect);
303
}
304

305 306 307 308 309 310 311
/* TranslateRegion(pReg, x, y)
   translates in place
*/

static inline void
RegionTranslate(RegionPtr pReg, int x, int y)
{
312
    pixman_region_translate(pReg, x, y);
313
}
314

315
extern _X_EXPORT Bool RegionBreak(RegionPtr /*pReg */ );
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
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 325 326
static inline Bool
RegionEqual(RegionPtr reg1, RegionPtr reg2)
{
327
    return pixman_region_equal(reg1, reg2);
328
}
329

330 331 332
extern _X_EXPORT Bool RegionRectAlloc(RegionPtr /*pRgn */ ,
                                      int       /*n */
    );
333

334
#ifdef DEBUG
335 336
extern _X_EXPORT Bool RegionIsValid(RegionPtr   /*prgn */
    );
337
#endif
338

339
extern _X_EXPORT void RegionPrint(RegionPtr /*pReg */ );
340

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
#define INCLUDE_LEGACY_REGION_DEFINES
#ifdef INCLUDE_LEGACY_REGION_DEFINES

#define REGION_NIL				RegionNil
#define REGION_NAR				RegionNar
#define REGION_NUM_RECTS			RegionNumRects
#define REGION_SIZE				RegionSize
#define REGION_RECTS				RegionRects
#define REGION_BOXPTR				RegionBoxptr
#define REGION_BOX				RegionBox
#define REGION_TOP				RegionTop
#define REGION_END				RegionEnd
#define REGION_SZOF				RegionSizeof
#define BITMAP_TO_REGION			BitmapToRegion
#define REGION_CREATE(pScreen, r, s)		RegionCreate(r,s)
#define REGION_COPY(pScreen, d, r)		RegionCopy(d, r)
#define REGION_DESTROY(pScreen, r)		RegionDestroy(r)
#define REGION_INTERSECT(pScreen, res, r1, r2)	RegionIntersect(res, r1, r2)
#define REGION_UNION(pScreen, res, r1, r2)	RegionUnion(res, r1, r2)
#define REGION_SUBTRACT(pScreen, res, r1, r2)	RegionSubtract(res, r1, r2)
#define REGION_INVERSE(pScreen, n, r, b)	RegionInverse(n, r, b)
#define REGION_TRANSLATE(pScreen, r, x, y)	RegionTranslate(r, x, y)
#define RECT_IN_REGION(pScreen, r, b) 		RegionContainsRect(r, b)
#define POINT_IN_REGION(pScreen, r, x, y, b) 	RegionContainsPoint(r, x, y, b)
#define REGION_EQUAL(pScreen, r1, r2)		RegionEqual(r1, r2)
#define REGION_APPEND(pScreen, d, r)		RegionAppend(d, r)
#define REGION_VALIDATE(pScreen, r, o)		RegionValidate(r, o)
#define RECTS_TO_REGION(pScreen, n, r, c)	RegionFromRects(n, r, c)
#define REGION_BREAK(pScreen, r)		RegionBreak(r)
#define REGION_INIT(pScreen, r, b, s)		RegionInit(r, b, s)
#define REGION_UNINIT(pScreen, r)		RegionUninit(r)
#define REGION_RESET(pScreen, r, b)		RegionReset(r, b)
#define REGION_NOTEMPTY(pScreen, r)		RegionNotEmpty(r)
#define REGION_BROKEN(pScreen, r)		RegionBroken(r)
#define REGION_EMPTY(pScreen, r)		RegionEmpty(r)
#define REGION_EXTENTS(pScreen, r)		RegionExtents(r)
#define REGION_NULL(pScreen, r)			RegionNull(r)

379 380
#endif                          /* INCLUDE_LEGACY_REGION_DEFINES */
#endif                          /* REGIONSTRUCT_H */