diff options
Diffstat (limited to 'nx-X11/programs/Xserver/dix/region.c')
-rw-r--r-- | nx-X11/programs/Xserver/dix/region.c | 978 |
1 files changed, 71 insertions, 907 deletions
diff --git a/nx-X11/programs/Xserver/dix/region.c b/nx-X11/programs/Xserver/dix/region.c index 410772ff8..e927b9fde 100644 --- a/nx-X11/programs/Xserver/dix/region.c +++ b/nx-X11/programs/Xserver/dix/region.c @@ -86,8 +86,6 @@ Equipment Corporation. #include "regionstr.h" #include <nx-X11/Xprotostr.h> #include "gc.h" -#include "mi.h" -#include "mispans.h" #if defined (__GNUC__) && !defined (NO_INLINES) #define INLINE __inline @@ -104,7 +102,7 @@ Equipment Corporation. #define assert(expr) #endif -#define good(reg) assert(miValidRegion(reg)) +#define good(reg) assert(RegionIsValid(reg)) /* * The functions in this file implement the Region abstraction used extensively @@ -147,7 +145,7 @@ Equipment Corporation. * * Adam de Boor wrote most of the original region code. Joel McCormack * substantially modified or rewrote most of the core arithmetic routines, - * and added miRegionValidate in order to support several speed improvements + * and added RegionValidate in order to support several speed improvements * to miValidateTree. Bob Scheifler changed the representation to be more * compact when empty or a single rectangle, and did a bunch of gratuitous * reformatting. @@ -178,11 +176,11 @@ Equipment Corporation. #define RECTALLOC_BAIL(pReg,n,bail) \ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \ - if (!miRectAlloc(pReg, n)) { goto bail; } + if (!RegionRectAlloc(pReg, n)) { goto bail; } #define RECTALLOC(pReg,n) \ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \ - if (!miRectAlloc(pReg, n)) { return FALSE; } + if (!RegionRectAlloc(pReg, n)) { return FALSE; } #define ADDRECT(pNextRect,nx1,ny1,nx2,ny2) \ { \ @@ -197,7 +195,7 @@ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \ { \ if (!(pReg)->data || ((pReg)->data->numRects == (pReg)->data->size))\ { \ - if (!miRectAlloc(pReg, 1)) \ + if (!RegionRectAlloc(pReg, 1)) \ return FALSE; \ pNextRect = RegionTop(pReg); \ } \ @@ -221,15 +219,15 @@ if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \ } -pixman_box16_t miEmptyBox = {0, 0, 0, 0}; -RegDataRec miEmptyData = {0, 0}; +pixman_box16_t RegionEmptyBox = {0, 0, 0, 0}; +RegDataRec RegionEmptyData = {0, 0}; -RegDataRec miBrokenData = {0, 0}; -RegionRec miBrokenRegion = { { 0, 0, 0, 0 }, &miBrokenData }; +RegDataRec RegionBrokenData = {0, 0}; +RegionRec RegionBrokenRegion = { { 0, 0, 0, 0 }, &RegionBrokenData }; #ifdef DEBUG int -miPrintRegion(rgn) +RegionPrint(rgn) RegionPtr rgn; { int num, size; @@ -250,36 +248,9 @@ miPrintRegion(rgn) } #endif /* DEBUG */ -Bool -miRegionEqual(reg1, reg2) - RegionPtr reg1; - RegionPtr reg2; -{ - int i, num; - BoxPtr rects1, rects2; - - if (reg1->extents.x1 != reg2->extents.x1) return FALSE; - if (reg1->extents.x2 != reg2->extents.x2) return FALSE; - if (reg1->extents.y1 != reg2->extents.y1) return FALSE; - if (reg1->extents.y2 != reg2->extents.y2) return FALSE; - - num = RegionNumRects(reg1); - if (num != RegionNumRects(reg2)) return FALSE; - - rects1 = RegionRects(reg1); - rects2 = RegionRects(reg2); - for (i = 0; i != num; i++) { - if (rects1[i].x1 != rects2[i].x1) return FALSE; - if (rects1[i].x2 != rects2[i].x2) return FALSE; - if (rects1[i].y1 != rects2[i].y1) return FALSE; - if (rects1[i].y2 != rects2[i].y2) return FALSE; - } - return TRUE; -} - #ifdef DEBUG Bool -miValidRegion(reg) +RegionIsValid(reg) RegionPtr reg; { register int i, numRects; @@ -291,7 +262,7 @@ miValidRegion(reg) if (!numRects) return ((reg->extents.x1 == reg->extents.x2) && (reg->extents.y1 == reg->extents.y2) && - (reg->data->size || (reg->data == &miEmptyData))); + (reg->data->size || (reg->data == &RegionEmptyData))); else if (numRects == 1) return (!reg->data); else @@ -334,7 +305,7 @@ miValidRegion(reg) *****************************************************************/ RegionPtr -miRegionCreate(rect, size) +RegionCreate(rect, size) BoxPtr rect; int size; { @@ -342,7 +313,7 @@ miRegionCreate(rect, size) size_t newSize; pReg = (RegionPtr)xalloc(sizeof(RegionRec)); if (!pReg) - return &miBrokenRegion; + return &RegionBrokenRegion; if (rect) { pReg->extents = *rect; @@ -350,7 +321,7 @@ miRegionCreate(rect, size) } else { - pReg->extents = miEmptyBox; + pReg->extents = RegionEmptyBox; newSize = RegionSizeof(size); if ((size > 1) && (newSize > 0) && (pReg->data = xalloc(newSize))) @@ -359,74 +330,33 @@ miRegionCreate(rect, size) pReg->data->numRects = 0; } else - pReg->data = &miEmptyData; + pReg->data = &RegionEmptyData; } return(pReg); } -/***************************************************************** - * RegionInit(pReg, rect, size) - * Outer region rect is statically allocated. - *****************************************************************/ - void -miRegionInit(pReg, rect, size) - RegionPtr pReg; - BoxPtr rect; - int size; -{ - size_t newSize; - - if (rect) - { - pReg->extents = *rect; - pReg->data = (RegDataPtr)NULL; - } - else - { - pReg->extents = miEmptyBox; - newSize = RegionSizeof(size); - if ((size > 1) && (newSize > 0) && - (pReg->data = xalloc(newSize))) - { - pReg->data->size = size; - pReg->data->numRects = 0; - } - else - pReg->data = &miEmptyData; - } -} - -void -miRegionDestroy(pReg) +RegionDestroy(pReg) RegionPtr pReg; { good(pReg); xfreeData(pReg); - if (pReg != &miBrokenRegion) + if (pReg != &RegionBrokenRegion) xfree(pReg); } -void -miRegionUninit(pReg) - RegionPtr pReg; -{ - good(pReg); - xfreeData(pReg); -} - Bool -miRegionBreak (pReg) +RegionBreak (pReg) RegionPtr pReg; { xfreeData (pReg); - pReg->extents = miEmptyBox; - pReg->data = &miBrokenData; + pReg->extents = RegionEmptyBox; + pReg->data = &RegionBrokenData; return FALSE; } Bool -miRectAlloc( +RegionRectAlloc( register RegionPtr pRgn, int n) { @@ -439,7 +369,7 @@ miRectAlloc( rgnSize = RegionSizeof(n); pRgn->data = (rgnSize > 0) ? xalloc(rgnSize) : NULL; if (!pRgn->data) - return miRegionBreak (pRgn); + return RegionBreak (pRgn); pRgn->data->numRects = 1; *RegionBoxptr(pRgn) = pRgn->extents; } @@ -448,7 +378,7 @@ miRectAlloc( rgnSize = RegionSizeof(n); pRgn->data = (rgnSize > 0) ? xalloc(rgnSize) : NULL; if (!pRgn->data) - return miRegionBreak (pRgn); + return RegionBreak (pRgn); pRgn->data->numRects = 0; } else @@ -463,44 +393,13 @@ miRectAlloc( rgnSize = RegionSizeof(n); data = (rgnSize > 0) ? xrealloc(pRgn->data, rgnSize) : NULL; if (!data) - return miRegionBreak (pRgn); + return RegionBreak (pRgn); pRgn->data = data; } pRgn->data->size = n; return TRUE; } -Bool -miRegionCopy(dst, src) - register RegionPtr dst; - register RegionPtr src; -{ - good(dst); - good(src); - if (dst == src) - return TRUE; - dst->extents = src->extents; - if (!src->data || !src->data->size) - { - xfreeData(dst); - dst->data = src->data; - return TRUE; - } - if (!dst->data || (dst->data->size < src->data->numRects)) - { - size_t newSize = RegionSizeof(src->data->numRects); - xfreeData(dst); - - dst->data = newSize > 0 ? xalloc(newSize) : NULL; - if (!dst->data) - return miRegionBreak (dst); - dst->data->size = src->data->numRects; - } - dst->data->numRects = src->data->numRects; - memmove((char *)RegionBoxptr(dst),(char *)RegionBoxptr(src), - dst->data->numRects * sizeof(BoxRec)); - return TRUE; -} /*====================================================================== @@ -509,10 +408,10 @@ miRegionCopy(dst, src) /*- *----------------------------------------------------------------------- - * miCoalesce -- + * RegionCoalesce -- * Attempt to merge the boxes in the current band with those in the * previous one. We are guaranteed that the current band extends to - * the end of the rects array. Used only by miRegionOp. + * the end of the rects array. Used only by RegionOp. * * Results: * The new index for the previous band. @@ -526,7 +425,7 @@ miRegionCopy(dst, src) *----------------------------------------------------------------------- */ INLINE static int -miCoalesce ( +RegionCoalesce ( register RegionPtr pReg, /* Region to coalesce */ int prevStart, /* Index of start of previous band */ int curStart) /* Index of start of current band */ @@ -583,18 +482,18 @@ miCoalesce ( } -/* Quicky macro to avoid trivial reject procedure calls to miCoalesce */ +/* Quicky macro to avoid trivial reject procedure calls to RegionCoalesce */ #define Coalesce(newReg, prevBand, curBand) \ if (curBand - prevBand == newReg->data->numRects - curBand) { \ - prevBand = miCoalesce(newReg, prevBand, curBand); \ + prevBand = RegionCoalesce(newReg, prevBand, curBand); \ } else { \ prevBand = curBand; \ } /*- *----------------------------------------------------------------------- - * miAppendNonO -- + * RegionAppendNonO -- * Handle a non-overlapping band for the union and subtract operations. * Just adds the (top/bottom-clipped) rectangles into the region. * Doesn't have to check for subsumption or anything. @@ -610,7 +509,7 @@ miCoalesce ( */ INLINE static Bool -miAppendNonO ( +RegionAppendNonO ( register RegionPtr pReg, register BoxPtr r, BoxPtr rEnd, @@ -660,9 +559,9 @@ miAppendNonO ( /*- *----------------------------------------------------------------------- - * miRegionOp -- - * Apply an operation to two regions. Called by miUnion, miInverse, - * miSubtract, miIntersect.... Both regions MUST have at least one + * RegionOp -- + * Apply an operation to two regions. Called by RegionUnion, RegionInverse, + * RegionSubtract, RegionIntersect.... Both regions MUST have at least one * rectangle, and cannot be the same object. * * Results: @@ -698,7 +597,7 @@ typedef Bool (*OverlapProcPtr)( Bool *pOverlap); static Bool -miRegionOp( +RegionOp( RegionPtr newReg, /* Place to store result */ RegionPtr reg1, /* First region in operation */ RegionPtr reg2, /* 2d region in operation */ @@ -734,7 +633,7 @@ miRegionOp( * Break any region computed from a broken region */ if (RegionNar (reg1) || RegionNar(reg2)) - return miRegionBreak (newReg); + return RegionBreak (newReg); /* * Initialization: @@ -758,18 +657,18 @@ miRegionOp( ((newReg == reg2) && (numRects > 1))) { oldData = newReg->data; - newReg->data = &miEmptyData; + newReg->data = &RegionEmptyData; } /* guess at new size */ if (numRects > newSize) newSize = numRects; newSize <<= 1; if (!newReg->data) - newReg->data = &miEmptyData; + newReg->data = &RegionEmptyData; else if (newReg->data->size) newReg->data->numRects = 0; if (newSize > newReg->data->size) - if (!miRectAlloc(newReg, newSize)) + if (!RegionRectAlloc(newReg, newSize)) return FALSE; /* @@ -790,7 +689,7 @@ miRegionOp( /* * prevBand serves to mark the start of the previous band so rectangles - * can be coalesced into larger rectangles. qv. miCoalesce, above. + * can be coalesced into larger rectangles. qv. RegionCoalesce, above. * In the beginning, there is no previous band, so prevBand == curBand * (curBand is set later on, of course, but the first band will always * start at index 0). prevBand and curBand must be indices because of @@ -827,7 +726,7 @@ miRegionOp( bot = min(r1->y2, r2y1); if (top != bot) { curBand = newReg->data->numRects; - miAppendNonO(newReg, r1, r1BandEnd, top, bot); + RegionAppendNonO(newReg, r1, r1BandEnd, top, bot); Coalesce(newReg, prevBand, curBand); } } @@ -838,7 +737,7 @@ miRegionOp( bot = min(r2->y2, r1y1); if (top != bot) { curBand = newReg->data->numRects; - miAppendNonO(newReg, r2, r2BandEnd, top, bot); + RegionAppendNonO(newReg, r2, r2BandEnd, top, bot); Coalesce(newReg, prevBand, curBand); } } @@ -880,7 +779,7 @@ miRegionOp( /* Do first nonOverlap1Func call, which may be able to coalesce */ FindBand(r1, r1BandEnd, r1End, r1y1); curBand = newReg->data->numRects; - miAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2); + RegionAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2); Coalesce(newReg, prevBand, curBand); /* Just append the rest of the boxes */ AppendRegions(newReg, r1BandEnd, r1End); @@ -889,7 +788,7 @@ miRegionOp( /* Do first nonOverlap2Func call, which may be able to coalesce */ FindBand(r2, r2BandEnd, r2End, r2y1); curBand = newReg->data->numRects; - miAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2); + RegionAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2); Coalesce(newReg, prevBand, curBand); /* Append rest of boxes */ AppendRegions(newReg, r2BandEnd, r2End); @@ -901,7 +800,7 @@ miRegionOp( if (!(numRects = newReg->data->numRects)) { xfreeData(newReg); - newReg->data = &miEmptyData; + newReg->data = &RegionEmptyData; } else if (numRects == 1) { @@ -919,10 +818,10 @@ miRegionOp( /*- *----------------------------------------------------------------------- - * miSetExtents -- + * RegionSetExtents -- * Reset the extents of a region to what they should be. Called by - * miSubtract and miIntersect as they can't figure it out along the - * way or do so easily, as miUnion can. + * RegionSubtract and RegionIntersect as they can't figure it out along the + * way or do so easily, as RegionUnion can. * * Results: * None. @@ -933,7 +832,7 @@ miRegionOp( *----------------------------------------------------------------------- */ void -miSetExtents (pReg) +RegionSetExtents (pReg) register RegionPtr pReg; { register BoxPtr pBox, pBoxEnd; @@ -974,132 +873,6 @@ miSetExtents (pReg) assert(pReg->extents.x1 < pReg->extents.x2); } -/*====================================================================== - * Region Intersection - *====================================================================*/ -/*- - *----------------------------------------------------------------------- - * miIntersectO -- - * Handle an overlapping band for miIntersect. - * - * Results: - * TRUE if successful. - * - * Side Effects: - * Rectangles may be added to the region. - * - *----------------------------------------------------------------------- - */ -/*ARGSUSED*/ -static Bool -miIntersectO ( - register RegionPtr pReg, - register BoxPtr r1, - BoxPtr r1End, - register BoxPtr r2, - BoxPtr r2End, - short y1, - short y2, - Bool *pOverlap) -{ - register int x1; - register int x2; - register BoxPtr pNextRect; - - pNextRect = RegionTop(pReg); - - assert(y1 < y2); - assert(r1 != r1End && r2 != r2End); - - do { - x1 = max(r1->x1, r2->x1); - x2 = min(r1->x2, r2->x2); - - /* - * If there's any overlap between the two rectangles, add that - * overlap to the new region. - */ - if (x1 < x2) - NEWRECT(pReg, pNextRect, x1, y1, x2, y2); - - /* - * Advance the pointer(s) with the leftmost right side, since the next - * rectangle on that list may still overlap the other region's - * current rectangle. - */ - if (r1->x2 == x2) { - r1++; - } - if (r2->x2 == x2) { - r2++; - } - } while ((r1 != r1End) && (r2 != r2End)); - - return TRUE; -} - - -Bool -miIntersect(newReg, reg1, reg2) - register RegionPtr newReg; /* destination Region */ - register RegionPtr reg1; - register RegionPtr reg2; /* source regions */ -{ - good(reg1); - good(reg2); - good(newReg); - /* check for trivial reject */ - if (RegionNil(reg1) || RegionNil(reg2) || - !EXTENTCHECK(®1->extents, ®2->extents)) - { - /* Covers about 20% of all cases */ - xfreeData(newReg); - newReg->extents.x2 = newReg->extents.x1; - newReg->extents.y2 = newReg->extents.y1; - if (RegionNar(reg1) || RegionNar(reg2)) - { - newReg->data = &miBrokenData; - return FALSE; - } - else - newReg->data = &miEmptyData; - } - else if (!reg1->data && !reg2->data) - { - /* Covers about 80% of cases that aren't trivially rejected */ - newReg->extents.x1 = max(reg1->extents.x1, reg2->extents.x1); - newReg->extents.y1 = max(reg1->extents.y1, reg2->extents.y1); - newReg->extents.x2 = min(reg1->extents.x2, reg2->extents.x2); - newReg->extents.y2 = min(reg1->extents.y2, reg2->extents.y2); - xfreeData(newReg); - newReg->data = (RegDataPtr)NULL; - } - else if (!reg2->data && SUBSUMES(®2->extents, ®1->extents)) - { - return miRegionCopy(newReg, reg1); - } - else if (!reg1->data && SUBSUMES(®1->extents, ®2->extents)) - { - return miRegionCopy(newReg, reg2); - } - else if (reg1 == reg2) - { - return miRegionCopy(newReg, reg1); - } - else - { - /* General purpose intersection */ - Bool overlap; /* result ignored */ - if (!miRegionOp(newReg, reg1, reg2, miIntersectO, FALSE, FALSE, - &overlap)) - return FALSE; - miSetExtents(newReg); - } - - good(newReg); - return(TRUE); -} - #define MERGERECT(r) \ { \ if (r->x1 <= x2) { \ @@ -1121,7 +894,7 @@ miIntersect(newReg, reg1, reg2) /*- *----------------------------------------------------------------------- - * miUnionO -- + * RegionUnionO -- * Handle an overlapping band for the union operation. Picks the * left-most rectangle each time and merges it into the region. * @@ -1135,7 +908,7 @@ miIntersect(newReg, reg1, reg2) *----------------------------------------------------------------------- */ static Bool -miUnionO ( +RegionUnionO ( register RegionPtr pReg, register BoxPtr r1, BoxPtr r1End, @@ -1194,97 +967,19 @@ miUnionO ( return TRUE; } -Bool -miUnion(newReg, reg1, reg2) - RegionPtr newReg; /* destination Region */ - register RegionPtr reg1; - register RegionPtr reg2; /* source regions */ -{ - Bool overlap; /* result ignored */ - - /* Return TRUE if some overlap between reg1, reg2 */ - good(reg1); - good(reg2); - good(newReg); - /* checks all the simple cases */ - - /* - * Region 1 and 2 are the same - */ - if (reg1 == reg2) - { - return miRegionCopy(newReg, reg1); - } - - /* - * Region 1 is empty - */ - if (RegionNil(reg1)) - { - if (RegionNar(reg1)) - return miRegionBreak (newReg); - if (newReg != reg2) - return miRegionCopy(newReg, reg2); - return TRUE; - } - - /* - * Region 2 is empty - */ - if (RegionNil(reg2)) - { - if (RegionNar(reg2)) - return miRegionBreak (newReg); - if (newReg != reg1) - return miRegionCopy(newReg, reg1); - return TRUE; - } - - /* - * Region 1 completely subsumes region 2 - */ - if (!reg1->data && SUBSUMES(®1->extents, ®2->extents)) - { - if (newReg != reg1) - return miRegionCopy(newReg, reg1); - return TRUE; - } - - /* - * Region 2 completely subsumes region 1 - */ - if (!reg2->data && SUBSUMES(®2->extents, ®1->extents)) - { - if (newReg != reg2) - return miRegionCopy(newReg, reg2); - return TRUE; - } - - if (!miRegionOp(newReg, reg1, reg2, miUnionO, TRUE, TRUE, &overlap)) - return FALSE; - - newReg->extents.x1 = min(reg1->extents.x1, reg2->extents.x1); - newReg->extents.y1 = min(reg1->extents.y1, reg2->extents.y1); - newReg->extents.x2 = max(reg1->extents.x2, reg2->extents.x2); - newReg->extents.y2 = max(reg1->extents.y2, reg2->extents.y2); - good(newReg); - return TRUE; -} - - /*====================================================================== * Batch Rectangle Union *====================================================================*/ /*- *----------------------------------------------------------------------- - * miRegionAppend -- + * RegionAppend -- * * "Append" the rgn rectangles onto the end of dstrgn, maintaining * knowledge of YX-banding when it's easy. Otherwise, dstrgn just * becomes a non-y-x-banded random collection of rectangles, and not * yet a true region. After a sequence of appends, the caller must - * call miRegionValidate to ensure that a valid region is constructed. + * call RegionValidate to ensure that a valid region is constructed. * * Results: * TRUE if successful. @@ -1294,7 +989,7 @@ miUnion(newReg, reg1, reg2) * */ Bool -miRegionAppend(dstrgn, rgn) +RegionAppend(dstrgn, rgn) register RegionPtr dstrgn; register RegionPtr rgn; { @@ -1303,9 +998,9 @@ miRegionAppend(dstrgn, rgn) Bool prepend; if (RegionNar(rgn)) - return miRegionBreak (dstrgn); + return RegionBreak (dstrgn); - if (!rgn->data && (dstrgn->data == &miEmptyData)) + if (!rgn->data && (dstrgn->data == &RegionEmptyData)) { dstrgn->extents = rgn->extents; dstrgn->data = (RegDataPtr)NULL; @@ -1449,7 +1144,7 @@ QuickSortRects( /*- *----------------------------------------------------------------------- - * miRegionValidate -- + * RegionValidate -- * * Take a ``region'' which is a non-y-x-banded random collection of * rectangles, and compute a nice region which is the union of all the @@ -1473,14 +1168,14 @@ QuickSortRects( * or a coalescing into 1 box (ala Menus). * * Step 3. Merge the separate regions down to a single region by calling - * miUnion. Maximize the work each miUnion call does by using + * RegionUnion. Maximize the work each RegionUnion call does by using * a binary merge. * *----------------------------------------------------------------------- */ Bool -miRegionValidate(badreg, pOverlap) +RegionValidate(badreg, pOverlap) RegionPtr badreg; Bool *pOverlap; { @@ -1542,7 +1237,7 @@ miRegionValidate(badreg, pOverlap) /* Note that step 2 code will never overflow the ri[0].reg rects array */ ri = (RegionInfo *) xalloc(4 * sizeof(RegionInfo)); if (!ri) - return miRegionBreak (badreg); + return RegionBreak (badreg); sizeRI = 4; numRI = 1; ri[0].prevBand = 0; @@ -1615,7 +1310,7 @@ miRegionValidate(badreg, pOverlap) rit->curBand = 0; rit->reg.extents = *box; rit->reg.data = (RegDataPtr)NULL; - if (!miRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */ + if (!RegionRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */ goto bail; NextRect: ; } /* for i */ @@ -1645,7 +1340,7 @@ NextRect: ; { reg = &ri[j].reg; hreg = &ri[j+half].reg; - if (!miRegionOp(reg, reg, hreg, miUnionO, TRUE, TRUE, pOverlap)) + if (!RegionOp(reg, reg, hreg, RegionUnionO, TRUE, TRUE, pOverlap)) ret = FALSE; if (hreg->extents.x1 < reg->extents.x1) reg->extents.x1 = hreg->extents.x1; @@ -1667,11 +1362,11 @@ bail: for (i = 0; i < numRI; i++) xfreeData(&ri[i].reg); xfree (ri); - return miRegionBreak (badreg); + return RegionBreak (badreg); } RegionPtr -miRectsToRegion(nrects, prect, ctype) +RegionFromRects(nrects, prect, ctype) int nrects; register xRectangle *prect; int ctype; @@ -1683,7 +1378,7 @@ miRectsToRegion(nrects, prect, ctype) int x1, y1, x2, y2; size_t newSize; - pRgn = miRegionCreate(NullBox, 0); + pRgn = RegionCreate(NullBox, 0); if (RegionNar (pRgn)) return pRgn; if (!nrects) @@ -1710,7 +1405,7 @@ miRectsToRegion(nrects, prect, ctype) pData = newSize > 0 ? xalloc(newSize) : NULL; if (!pData) { - miRegionBreak (pRgn); + RegionBreak (pRgn); return pRgn; } pBox = (BoxPtr) (pData + 1); @@ -1740,10 +1435,10 @@ miRectsToRegion(nrects, prect, ctype) { Bool overlap; /* result ignored */ pRgn->extents.x1 = pRgn->extents.x2 = 0; - miRegionValidate(pRgn, &overlap); + RegionValidate(pRgn, &overlap); } else - miSetExtents(pRgn); + RegionSetExtents(pRgn); good(pRgn); } else @@ -1753,456 +1448,6 @@ miRectsToRegion(nrects, prect, ctype) return pRgn; } -/*====================================================================== - * Region Subtraction - *====================================================================*/ - - -/*- - *----------------------------------------------------------------------- - * miSubtractO -- - * Overlapping band subtraction. x1 is the left-most point not yet - * checked. - * - * Results: - * TRUE if successful. - * - * Side Effects: - * pReg may have rectangles added to it. - * - *----------------------------------------------------------------------- - */ -/*ARGSUSED*/ -static Bool -miSubtractO ( - register RegionPtr pReg, - register BoxPtr r1, - BoxPtr r1End, - register BoxPtr r2, - BoxPtr r2End, - register short y1, - short y2, - Bool *pOverlap) -{ - register BoxPtr pNextRect; - register int x1; - - x1 = r1->x1; - - assert(y1<y2); - assert(r1 != r1End && r2 != r2End); - - pNextRect = RegionTop(pReg); - - do - { - if (r2->x2 <= x1) - { - /* - * Subtrahend entirely to left of minuend: go to next subtrahend. - */ - r2++; - } - else if (r2->x1 <= x1) - { - /* - * Subtrahend preceeds minuend: nuke left edge of minuend. - */ - x1 = r2->x2; - if (x1 >= r1->x2) - { - /* - * Minuend completely covered: advance to next minuend and - * reset left fence to edge of new minuend. - */ - r1++; - if (r1 != r1End) - x1 = r1->x1; - } - else - { - /* - * Subtrahend now used up since it doesn't extend beyond - * minuend - */ - r2++; - } - } - else if (r2->x1 < r1->x2) - { - /* - * Left part of subtrahend covers part of minuend: add uncovered - * part of minuend to region and skip to next subtrahend. - */ - assert(x1<r2->x1); - NEWRECT(pReg, pNextRect, x1, y1, r2->x1, y2); - - x1 = r2->x2; - if (x1 >= r1->x2) - { - /* - * Minuend used up: advance to new... - */ - r1++; - if (r1 != r1End) - x1 = r1->x1; - } - else - { - /* - * Subtrahend used up - */ - r2++; - } - } - else - { - /* - * Minuend used up: add any remaining piece before advancing. - */ - if (r1->x2 > x1) - NEWRECT(pReg, pNextRect, x1, y1, r1->x2, y2); - r1++; - if (r1 != r1End) - x1 = r1->x1; - } - } while ((r1 != r1End) && (r2 != r2End)); - - - /* - * Add remaining minuend rectangles to region. - */ - while (r1 != r1End) - { - assert(x1<r1->x2); - NEWRECT(pReg, pNextRect, x1, y1, r1->x2, y2); - r1++; - if (r1 != r1End) - x1 = r1->x1; - } - return TRUE; -} - -/*- - *----------------------------------------------------------------------- - * miSubtract -- - * 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. - * - *----------------------------------------------------------------------- - */ -Bool -miSubtract(regD, regM, regS) - register RegionPtr regD; - register RegionPtr regM; - register RegionPtr regS; -{ - Bool overlap; /* result ignored */ - - good(regM); - good(regS); - good(regD); - /* check for trivial rejects */ - if (RegionNil(regM) || RegionNil(regS) || - !EXTENTCHECK(®M->extents, ®S->extents)) - { - if (RegionNar (regS)) - return miRegionBreak (regD); - return miRegionCopy(regD, regM); - } - else if (regM == regS) - { - xfreeData(regD); - regD->extents.x2 = regD->extents.x1; - regD->extents.y2 = regD->extents.y1; - regD->data = &miEmptyData; - return TRUE; - } - - /* Add those rectangles in region 1 that aren't in region 2, - do yucky substraction for overlaps, and - just throw away rectangles in region 2 that aren't in region 1 */ - if (!miRegionOp(regD, regM, regS, miSubtractO, TRUE, FALSE, &overlap)) - return FALSE; - - /* - * Can't alter RegD's extents before we call miRegionOp because - * it might be one of the source regions and miRegionOp depends - * on the extents of those regions being unaltered. Besides, this - * way there's no checking against rectangles that will be nuked - * due to coalescing, so we have to examine fewer rectangles. - */ - miSetExtents(regD); - good(regD); - return TRUE; -} - -/*====================================================================== - * Region Inversion - *====================================================================*/ - -/*- - *----------------------------------------------------------------------- - * miInverse -- - * 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. - * - *----------------------------------------------------------------------- - */ -Bool -miInverse(newReg, reg1, invRect) - RegionPtr newReg; /* Destination region */ - RegionPtr reg1; /* Region to invert */ - BoxPtr invRect; /* Bounding box for inversion */ -{ - RegionRec invReg; /* Quick and dirty region made from the - * bounding box */ - Bool overlap; /* result ignored */ - - good(reg1); - good(newReg); - /* check for trivial rejects */ - if (RegionNil(reg1) || !EXTENTCHECK(invRect, ®1->extents)) - { - if (RegionNar(reg1)) - return miRegionBreak (newReg); - newReg->extents = *invRect; - xfreeData(newReg); - newReg->data = (RegDataPtr)NULL; - return TRUE; - } - - /* Add those rectangles in region 1 that aren't in region 2, - do yucky substraction for overlaps, and - just throw away rectangles in region 2 that aren't in region 1 */ - invReg.extents = *invRect; - invReg.data = (RegDataPtr)NULL; - if (!miRegionOp(newReg, &invReg, reg1, miSubtractO, TRUE, FALSE, &overlap)) - return FALSE; - - /* - * Can't alter newReg's extents before we call miRegionOp because - * it might be one of the source regions and miRegionOp depends - * on the extents of those regions being unaltered. Besides, this - * way there's no checking against rectangles that will be nuked - * due to coalescing, so we have to examine fewer rectangles. - */ - miSetExtents(newReg); - good(newReg); - return TRUE; -} - -/* - * RectIn(region, rect) - * This routine takes a pointer to a region and a pointer to a box - * and determines if the box is outside/inside/partly inside the region. - * - * The idea is to travel through the list of rectangles trying to cover the - * passed box with them. Anytime a piece of the rectangle isn't covered - * by a band of rectangles, partOut is set TRUE. Any time a rectangle in - * the region covers part of the box, partIn is set TRUE. The process ends - * when either the box has been completely covered (we reached a band that - * doesn't overlap the box, partIn is TRUE and partOut is false), the - * box has been partially covered (partIn == partOut == TRUE -- because of - * the banding, the first time this is true we know the box is only - * partially in the region) or is outside the region (we reached a band - * that doesn't overlap the box at all and partIn is false) - */ - -int -miRectIn(region, prect) - register RegionPtr region; - register BoxPtr prect; -{ - register int x; - register int y; - register BoxPtr pbox; - register BoxPtr pboxEnd; - int partIn, partOut; - int numRects; - - good(region); - numRects = RegionNumRects(region); - /* useful optimization */ - if (!numRects || !EXTENTCHECK(®ion->extents, prect)) - return(rgnOUT); - - if (numRects == 1) - { - /* We know that it must be rgnIN or rgnPART */ - if (SUBSUMES(®ion->extents, prect)) - return(rgnIN); - else - return(rgnPART); - } - - partOut = FALSE; - partIn = FALSE; - - /* (x,y) starts at upper left of rect, moving to the right and down */ - x = prect->x1; - y = prect->y1; - - /* can stop when both partOut and partIn are TRUE, or we reach prect->y2 */ - for (pbox = RegionBoxptr(region), pboxEnd = pbox + numRects; - pbox != pboxEnd; - pbox++) - { - - if (pbox->y2 <= y) - continue; /* getting up to speed or skipping remainder of band */ - - if (pbox->y1 > y) - { - partOut = TRUE; /* missed part of rectangle above */ - if (partIn || (pbox->y1 >= prect->y2)) - break; - y = pbox->y1; /* x guaranteed to be == prect->x1 */ - } - - if (pbox->x2 <= x) - continue; /* not far enough over yet */ - - if (pbox->x1 > x) - { - partOut = TRUE; /* missed part of rectangle to left */ - if (partIn) - break; - } - - if (pbox->x1 < prect->x2) - { - partIn = TRUE; /* definitely overlap */ - if (partOut) - break; - } - - if (pbox->x2 >= prect->x2) - { - y = pbox->y2; /* finished with this band */ - if (y >= prect->y2) - break; - x = prect->x1; /* reset x out to left again */ - } - else - { - /* - * Because boxes in a band are maximal width, if the first box - * to overlap the rectangle doesn't completely cover it in that - * band, the rectangle must be partially out, since some of it - * will be uncovered in that band. partIn will have been set true - * by now... - */ - partOut = TRUE; - break; - } - } - - return(partIn ? ((y < prect->y2) ? rgnPART : rgnIN) : rgnOUT); -} - -/* TranslateRegion(pReg, x, y) - translates in place -*/ - -void -miTranslateRegion(pReg, x, y) - register RegionPtr pReg; - register int x; - register int y; -{ - int x1, x2, y1, y2; - register int nbox; - register BoxPtr pbox; - - good(pReg); - pReg->extents.x1 = x1 = pReg->extents.x1 + x; - pReg->extents.y1 = y1 = pReg->extents.y1 + y; - pReg->extents.x2 = x2 = pReg->extents.x2 + x; - pReg->extents.y2 = y2 = pReg->extents.y2 + y; - if (((x1 - MINSHORT)|(y1 - MINSHORT)|(MAXSHORT - x2)|(MAXSHORT - y2)) >= 0) - { - if (pReg->data && (nbox = pReg->data->numRects)) - { - for (pbox = RegionBoxptr(pReg); nbox--; pbox++) - { - pbox->x1 += x; - pbox->y1 += y; - pbox->x2 += x; - pbox->y2 += y; - } - } - return; - } - if (((x2 - MINSHORT)|(y2 - MINSHORT)|(MAXSHORT - x1)|(MAXSHORT - y1)) <= 0) - { - pReg->extents.x2 = pReg->extents.x1; - pReg->extents.y2 = pReg->extents.y1; - xfreeData(pReg); - pReg->data = &miEmptyData; - return; - } - if (x1 < MINSHORT) - pReg->extents.x1 = MINSHORT; - else if (x2 > MAXSHORT) - pReg->extents.x2 = MAXSHORT; - if (y1 < MINSHORT) - pReg->extents.y1 = MINSHORT; - else if (y2 > MAXSHORT) - pReg->extents.y2 = MAXSHORT; - if (pReg->data && (nbox = pReg->data->numRects)) - { - register BoxPtr pboxout; - - for (pboxout = pbox = RegionBoxptr(pReg); nbox--; pbox++) - { - pboxout->x1 = x1 = pbox->x1 + x; - pboxout->y1 = y1 = pbox->y1 + y; - pboxout->x2 = x2 = pbox->x2 + x; - pboxout->y2 = y2 = pbox->y2 + y; - if (((x2 - MINSHORT)|(y2 - MINSHORT)| - (MAXSHORT - x1)|(MAXSHORT - y1)) <= 0) - { - pReg->data->numRects--; - continue; - } - if (x1 < MINSHORT) - pboxout->x1 = MINSHORT; - else if (x2 > MAXSHORT) - pboxout->x2 = MAXSHORT; - if (y1 < MINSHORT) - pboxout->y1 = MINSHORT; - else if (y2 > MAXSHORT) - pboxout->y2 = MAXSHORT; - pboxout++; - } - if (pboxout != pbox) - { - if (pReg->data->numRects == 1) - { - pReg->extents = *RegionBoxptr(pReg); - xfreeData(pReg); - pReg->data = (RegDataPtr)NULL; - } - else - miSetExtents(pReg); - } - } -} - Bool miRegionDataCopy( register RegionPtr dst, @@ -2226,94 +1471,13 @@ miRegionDataCopy( xfreeData(dst); dst->data = newSize > 0 ? xalloc(newSize) : NULL; if (!dst->data) - return miRegionBreak (dst); + return RegionBreak (dst); } dst->data->size = src->data->size; dst->data->numRects = src->data->numRects; return TRUE; } -void -miRegionReset(pReg, pBox) - RegionPtr pReg; - BoxPtr pBox; -{ - good(pReg); - assert(pBox->x1<=pBox->x2); - assert(pBox->y1<=pBox->y2); - pReg->extents = *pBox; - xfreeData(pReg); - pReg->data = (RegDataPtr)NULL; -} - -Bool -miPointInRegion(pReg, x, y, box) - register RegionPtr pReg; - register int x, y; - BoxPtr box; /* "return" value */ -{ - register BoxPtr pbox, pboxEnd; - int numRects; - - good(pReg); - numRects = RegionNumRects(pReg); - if (!numRects || !INBOX(&pReg->extents, x, y)) - return(FALSE); - if (numRects == 1) - { - *box = pReg->extents; - return(TRUE); - } - for (pbox = RegionBoxptr(pReg), pboxEnd = pbox + numRects; - pbox != pboxEnd; - pbox++) - { - if (y >= pbox->y2) - continue; /* not there yet */ - if ((y < pbox->y1) || (x < pbox->x1)) - break; /* missed it */ - if (x >= pbox->x2) - continue; /* not there yet */ - *box = *pbox; - return(TRUE); - } - return(FALSE); -} - -Bool -miRegionNotEmpty(pReg) - RegionPtr pReg; -{ - good(pReg); - return(!RegionNil(pReg)); -} - -Bool -miRegionBroken(RegionPtr pReg) -{ - good(pReg); - return (RegionNar(pReg)); -} - -void -miRegionEmpty(pReg) - RegionPtr pReg; -{ - good(pReg); - xfreeData(pReg); - pReg->extents.x2 = pReg->extents.x1; - pReg->extents.y2 = pReg->extents.y1; - pReg->data = &miEmptyData; -} - -BoxPtr -miRegionExtents(pReg) - RegionPtr pReg; -{ - good(pReg); - return(&pReg->extents); -} - #define ExchangeSpans(a, b) \ { \ DDXPointRec tpt; \ @@ -2433,7 +1597,7 @@ static void QuickSortSpans( */ int -miClipSpans( +RegionClipSpans( RegionPtr prgnDst, register DDXPointPtr ppt, register int *pwidth, |