regionstr.h revision 05b261ec
1/*********************************************************** 2 3Copyright 1987, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25 26Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 27 28 All Rights Reserved 29 30Permission to use, copy, modify, and distribute this software and its 31documentation for any purpose and without fee is hereby granted, 32provided that the above copyright notice appear in all copies and that 33both that copyright notice and this permission notice appear in 34supporting documentation, and that the name of Digital not be 35used in advertising or publicity pertaining to distribution of the 36software without specific, written prior permission. 37 38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 44SOFTWARE. 45 46******************************************************************/ 47 48#ifndef REGIONSTRUCT_H 49#define REGIONSTRUCT_H 50 51typedef struct pixman_region16 RegionRec, *RegionPtr; 52 53#include "miscstruct.h" 54 55/* Return values from RectIn() */ 56 57#define rgnOUT 0 58#define rgnIN 1 59#define rgnPART 2 60 61#define NullRegion ((RegionPtr)0) 62 63/* 64 * clip region 65 */ 66 67typedef struct pixman_region16_data RegDataRec, *RegDataPtr; 68 69extern BoxRec miEmptyBox; 70extern RegDataRec miEmptyData; 71extern RegDataRec miBrokenData; 72 73#define REGION_NIL(reg) ((reg)->data && !(reg)->data->numRects) 74/* not a region */ 75#define REGION_NAR(reg) ((reg)->data == &miBrokenData) 76#define REGION_NUM_RECTS(reg) ((reg)->data ? (reg)->data->numRects : 1) 77#define REGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0) 78#define REGION_RECTS(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \ 79 : &(reg)->extents) 80#define REGION_BOXPTR(reg) ((BoxPtr)((reg)->data + 1)) 81#define REGION_BOX(reg,i) (®ION_BOXPTR(reg)[i]) 82#define REGION_TOP(reg) REGION_BOX(reg, (reg)->data->numRects) 83#define REGION_END(reg) REGION_BOX(reg, (reg)->data->numRects - 1) 84#define REGION_SZOF(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec))) 85 86#define REGION_CREATE(_pScreen, _rect, _size) \ 87 miRegionCreate(_rect, _size) 88 89#define REGION_COPY(_pScreen, dst, src) \ 90 miRegionCopy(dst, src) 91 92#define REGION_DESTROY(_pScreen, _pReg) \ 93 miRegionDestroy(_pReg) 94 95#define REGION_INTERSECT(_pScreen, newReg, reg1, reg2) \ 96 miIntersect(newReg, reg1, reg2) 97 98#define REGION_UNION(_pScreen, newReg, reg1, reg2) \ 99 miUnion(newReg, reg1, reg2) 100 101#define REGION_SUBTRACT(_pScreen, newReg, reg1, reg2) \ 102 miSubtract(newReg, reg1, reg2) 103 104#define REGION_INVERSE(_pScreen, newReg, reg1, invRect) \ 105 miInverse(newReg, reg1, invRect) 106 107#define REGION_TRANSLATE(_pScreen, _pReg, _x, _y) \ 108 miTranslateRegion(_pReg, _x, _y) 109 110#define RECT_IN_REGION(_pScreen, _pReg, prect) \ 111 miRectIn(_pReg, prect) 112 113#define POINT_IN_REGION(_pScreen, _pReg, _x, _y, prect) \ 114 miPointInRegion(_pReg, _x, _y, prect) 115 116#define REGION_APPEND(_pScreen, dstrgn, rgn) \ 117 miRegionAppend(dstrgn, rgn) 118 119#define REGION_VALIDATE(_pScreen, badreg, pOverlap) \ 120 miRegionValidate(badreg, pOverlap) 121 122#define BITMAP_TO_REGION(_pScreen, pPix) \ 123 (*(_pScreen)->BitmapToRegion)(pPix) /* no mi version?! */ 124 125#define RECTS_TO_REGION(_pScreen, nrects, prect, ctype) \ 126 miRectsToRegion(nrects, prect, ctype) 127 128#define REGION_EQUAL(_pScreen, _pReg1, _pReg2) \ 129 miRegionEqual(_pReg1, _pReg2) 130 131#define REGION_BREAK(_pScreen, _pReg) \ 132 miRegionBreak(_pReg) 133 134#ifdef DONT_INLINE_REGION_OPS 135 136#define REGION_INIT(_pScreen, _pReg, _rect, _size) \ 137 miRegionInit(_pReg, _rect, _size) 138 139#define REGION_UNINIT(_pScreen, _pReg) \ 140 miRegionUninit(_pReg) 141 142#define REGION_RESET(_pScreen, _pReg, _pBox) \ 143 miRegionReset(_pReg, _pBox) 144 145#define REGION_NOTEMPTY(_pScreen, _pReg) \ 146 miRegionNotEmpty(_pReg) 147 148#define REGION_BROKEN(_pScreen, _pReg) \ 149 miRegionBroken(_pReg) 150 151#define REGION_EMPTY(_pScreen, _pReg) \ 152 miRegionEmpty(_pReg) 153 154#define REGION_EXTENTS(_pScreen, _pReg) \ 155 miRegionExtents(_pReg) 156 157#else /* inline certain simple region ops for performance */ 158 159#define REGION_INIT(_pScreen, _pReg, _rect, _size) \ 160{ \ 161 if (_rect) \ 162 { \ 163 (_pReg)->extents = *(_rect); \ 164 (_pReg)->data = (RegDataPtr)NULL; \ 165 } \ 166 else \ 167 { \ 168 (_pReg)->extents = miEmptyBox; \ 169 if (((_size) > 1) && ((_pReg)->data = \ 170 (RegDataPtr)xalloc(REGION_SZOF(_size)))) \ 171 { \ 172 (_pReg)->data->size = (_size); \ 173 (_pReg)->data->numRects = 0; \ 174 } \ 175 else \ 176 (_pReg)->data = &miEmptyData; \ 177 } \ 178 } 179 180 181#define REGION_UNINIT(_pScreen, _pReg) \ 182{ \ 183 if ((_pReg)->data && (_pReg)->data->size) { \ 184 xfree((_pReg)->data); \ 185 (_pReg)->data = NULL; \ 186 } \ 187} 188 189#define REGION_RESET(_pScreen, _pReg, _pBox) \ 190{ \ 191 (_pReg)->extents = *(_pBox); \ 192 REGION_UNINIT(_pScreen, _pReg); \ 193 (_pReg)->data = (RegDataPtr)NULL; \ 194} 195 196#define REGION_NOTEMPTY(_pScreen, _pReg) \ 197 !REGION_NIL(_pReg) 198 199#define REGION_BROKEN(_pScreen, _pReg) \ 200 REGION_NAR(_pReg) 201 202#define REGION_EMPTY(_pScreen, _pReg) \ 203{ \ 204 REGION_UNINIT(_pScreen, _pReg); \ 205 (_pReg)->extents.x2 = (_pReg)->extents.x1; \ 206 (_pReg)->extents.y2 = (_pReg)->extents.y1; \ 207 (_pReg)->data = &miEmptyData; \ 208} 209 210#define REGION_EXTENTS(_pScreen, _pReg) \ 211 (&(_pReg)->extents) 212 213#define REGION_NULL(_pScreen, _pReg) \ 214{ \ 215 (_pReg)->extents = miEmptyBox; \ 216 (_pReg)->data = &miEmptyData; \ 217} 218 219#endif /* DONT_INLINE_REGION_OPS */ 220 221#ifndef REGION_NULL 222#define REGION_NULL(_pScreen, _pReg) \ 223 REGION_INIT(_pScreen, _pReg, NullBox, 1) 224#endif 225 226/* moved from mi.h */ 227 228extern void InitRegions (void); 229 230extern RegionPtr miRegionCreate( 231 BoxPtr /*rect*/, 232 int /*size*/); 233 234extern void miRegionInit( 235 RegionPtr /*pReg*/, 236 BoxPtr /*rect*/, 237 int /*size*/); 238 239extern void miRegionDestroy( 240 RegionPtr /*pReg*/); 241 242extern void miRegionUninit( 243 RegionPtr /*pReg*/); 244 245extern Bool miRegionCopy( 246 RegionPtr /*dst*/, 247 RegionPtr /*src*/); 248 249extern Bool miIntersect( 250 RegionPtr /*newReg*/, 251 RegionPtr /*reg1*/, 252 RegionPtr /*reg2*/); 253 254extern Bool miUnion( 255 RegionPtr /*newReg*/, 256 RegionPtr /*reg1*/, 257 RegionPtr /*reg2*/); 258 259extern Bool miRegionAppend( 260 RegionPtr /*dstrgn*/, 261 RegionPtr /*rgn*/); 262 263extern Bool miRegionValidate( 264 RegionPtr /*badreg*/, 265 Bool * /*pOverlap*/); 266 267extern RegionPtr miRectsToRegion( 268 int /*nrects*/, 269 xRectanglePtr /*prect*/, 270 int /*ctype*/); 271 272extern Bool miSubtract( 273 RegionPtr /*regD*/, 274 RegionPtr /*regM*/, 275 RegionPtr /*regS*/); 276 277extern Bool miInverse( 278 RegionPtr /*newReg*/, 279 RegionPtr /*reg1*/, 280 BoxPtr /*invRect*/); 281 282extern int miRectIn( 283 RegionPtr /*region*/, 284 BoxPtr /*prect*/); 285 286extern void miTranslateRegion( 287 RegionPtr /*pReg*/, 288 int /*x*/, 289 int /*y*/); 290 291extern void miRegionReset( 292 RegionPtr /*pReg*/, 293 BoxPtr /*pBox*/); 294 295extern Bool miRegionBreak( 296 RegionPtr /*pReg*/); 297 298extern Bool miPointInRegion( 299 RegionPtr /*pReg*/, 300 int /*x*/, 301 int /*y*/, 302 BoxPtr /*box*/); 303 304extern Bool miRegionEqual( 305 RegionPtr /*pReg1*/, 306 RegionPtr /*pReg2*/); 307 308extern Bool miRegionNotEmpty( 309 RegionPtr /*pReg*/); 310 311extern void miRegionEmpty( 312 RegionPtr /*pReg*/); 313 314extern BoxPtr miRegionExtents( 315 RegionPtr /*pReg*/); 316 317extern void miPrintRegion( 318 RegionPtr /*pReg*/); 319 320#endif /* REGIONSTRUCT_H */ 321