5ec28e
diff --git a/BUILDING.txt b/BUILDING.txt
5ec28e
index 9449810..99c8698 100644
5ec28e
--- a/BUILDING.txt
5ec28e
+++ b/BUILDING.txt
5ec28e
@@ -11,6 +11,8 @@ Build Requirements (All Systems)
5ec28e
 
5ec28e
 -- zlib
5ec28e
 
5ec28e
+-- pixman
5ec28e
+
5ec28e
 -- FLTK 1.3.3 or later
5ec28e
 
5ec28e
 -- If building TLS support:
5ec28e
diff --git a/CMakeLists.txt b/CMakeLists.txt
5ec28e
index 94ec2ef..dfdf197 100644
5ec28e
--- a/CMakeLists.txt
5ec28e
+++ b/CMakeLists.txt
5ec28e
@@ -134,6 +134,9 @@ endif()
5ec28e
 # Check for zlib
5ec28e
 find_package(ZLIB REQUIRED)
5ec28e
 
5ec28e
+# Check for pixman
5ec28e
+find_package(Pixman REQUIRED)
5ec28e
+
5ec28e
 # Check for gettext
5ec28e
 option(ENABLE_NLS "Enable translation of program messages" ON)
5ec28e
 if(ENABLE_NLS)
5ec28e
diff --git a/cmake/Modules/FindPixman.cmake b/cmake/Modules/FindPixman.cmake
5ec28e
new file mode 100644
5ec28e
index 0000000..7bfca77
5ec28e
--- /dev/null
5ec28e
+++ b/cmake/Modules/FindPixman.cmake
5ec28e
@@ -0,0 +1,40 @@
5ec28e
+# - Find Pixman
5ec28e
+# Find the Pixman libraries
5ec28e
+#
5ec28e
+#  This module defines the following variables:
5ec28e
+#     PIXMAN_FOUND        - true if PIXMAN_INCLUDE_DIR & PIXMAN_LIBRARY are found
5ec28e
+#     PIXMAN_LIBRARIES    - Set when PIXMAN_LIBRARY is found
5ec28e
+#     PIXMAN_INCLUDE_DIRS - Set when PIXMAN_INCLUDE_DIR is found
5ec28e
+#
5ec28e
+#     PIXMAN_INCLUDE_DIR  - where to find pixman.h, etc.
5ec28e
+#     PIXMAN_LIBRARY      - the Pixman library
5ec28e
+#
5ec28e
+
5ec28e
+#=============================================================================
5ec28e
+# Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
5ec28e
+#
5ec28e
+# Licensed under the Apache License, Version 2.0 (the "License");
5ec28e
+# you may not use this file except in compliance with the License.
5ec28e
+# You may obtain a copy of the License at
5ec28e
+#
5ec28e
+#     http://www.apache.org/licenses/LICENSE-2.0
5ec28e
+#
5ec28e
+# Unless required by applicable law or agreed to in writing, software
5ec28e
+# distributed under the License is distributed on an "AS IS" BASIS,
5ec28e
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5ec28e
+# See the License for the specific language governing permissions and
5ec28e
+# limitations under the License.
5ec28e
+#=============================================================================
5ec28e
+
5ec28e
+find_path(PIXMAN_INCLUDE_DIR NAMES pixman.h PATH_SUFFIXES pixman-1)
5ec28e
+
5ec28e
+find_library(PIXMAN_LIBRARY NAMES pixman-1)
5ec28e
+
5ec28e
+find_package_handle_standard_args(pixman-1 DEFAULT_MSG PIXMAN_LIBRARY PIXMAN_INCLUDE_DIR)
5ec28e
+
5ec28e
+if(PIXMAN-1_FOUND)
5ec28e
+	set(PIXMAN_LIBRARIES ${PIXMAN_LIBRARY})
5ec28e
+	set(PIXMAN_INCLUDE_DIRS ${PIXMAN_INCLUDE_DIR})
5ec28e
+endif()
5ec28e
+
5ec28e
+mark_as_advanced(PIXMAN_INCLUDE_DIR PIXMAN_LIBRARY)
5ec28e
diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake
5ec28e
index 6db0e14..db30c5c 100644
5ec28e
--- a/cmake/StaticBuild.cmake
5ec28e
+++ b/cmake/StaticBuild.cmake
5ec28e
@@ -19,6 +19,7 @@ if(BUILD_STATIC)
5ec28e
   set(BUILD_STATIC_GCC 1)
5ec28e
 
5ec28e
   set(JPEG_LIBRARIES "-Wl,-Bstatic -ljpeg -Wl,-Bdynamic")
5ec28e
+  set(PIXMAN_LIBRARY "-Wl,-Bstatic -lpixman-1 -Wl,-Bdynamic")
5ec28e
 
5ec28e
   if(WIN32)
5ec28e
     set(ZLIB_LIBRARIES "-Wl,-Bstatic -lz -Wl,-Bdynamic")
5ec28e
@@ -133,7 +134,7 @@ if(BUILD_STATIC_GCC)
5ec28e
     # these things again
5ec28e
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt")
5ec28e
   else()
5ec28e
-    set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lgcc -lgcc_eh -lc")
5ec28e
+    set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lm -lgcc -lgcc_eh -lc")
5ec28e
   endif()
5ec28e
   set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${STATIC_BASE_LIBRARIES}")
5ec28e
 endif()
5ec28e
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
5ec28e
index e4489f6..6fd1e10 100644
5ec28e
--- a/common/CMakeLists.txt
5ec28e
+++ b/common/CMakeLists.txt
5ec28e
@@ -1,7 +1,6 @@
5ec28e
 add_subdirectory(os)
5ec28e
 add_subdirectory(rdr)
5ec28e
 add_subdirectory(network)
5ec28e
-add_subdirectory(Xregion)
5ec28e
 add_subdirectory(rfb)
5ec28e
 
5ec28e
 # For any convenience libraries that are linked into libvnc.so, we need to
5ec28e
@@ -10,6 +9,6 @@ add_subdirectory(rfb)
5ec28e
 # is passed (additionally, libvnc is not used on Windows.)
5ec28e
 
5ec28e
 if(NOT WIN32)
5ec28e
-  set_target_properties(os rdr network Xregion rfb
5ec28e
+  set_target_properties(os rdr network rfb
5ec28e
     PROPERTIES COMPILE_FLAGS -fPIC)
5ec28e
 endif()
5ec28e
diff --git a/common/Xregion/CMakeLists.txt b/common/Xregion/CMakeLists.txt
5ec28e
deleted file mode 100644
5ec28e
index 40ca97e..0000000
5ec28e
--- a/common/Xregion/CMakeLists.txt
5ec28e
+++ /dev/null
5ec28e
@@ -1,6 +0,0 @@
5ec28e
-add_library(Xregion STATIC
5ec28e
-  Region.c)
5ec28e
-
5ec28e
-if(UNIX)
5ec28e
-  libtool_create_control_file(Xregion)
5ec28e
-endif()
5ec28e
diff --git a/common/Xregion/Region.c b/common/Xregion/Region.c
5ec28e
deleted file mode 100644
5ec28e
index 1acf581..0000000
5ec28e
--- a/common/Xregion/Region.c
5ec28e
+++ /dev/null
5ec28e
@@ -1,1612 +0,0 @@
5ec28e
-/************************************************************************
5ec28e
-
5ec28e
-Copyright 1987, 1988, 1998  The Open Group
5ec28e
-
5ec28e
-Permission to use, copy, modify, distribute, and sell this software and its
5ec28e
-documentation for any purpose is hereby granted without fee, provided that
5ec28e
-the above copyright notice appear in all copies and that both that
5ec28e
-copyright notice and this permission notice appear in supporting
5ec28e
-documentation.
5ec28e
-
5ec28e
-The above copyright notice and this permission notice shall be included in
5ec28e
-all copies or substantial portions of the Software.
5ec28e
-
5ec28e
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5ec28e
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5ec28e
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
5ec28e
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
5ec28e
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
5ec28e
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5ec28e
-
5ec28e
-Except as contained in this notice, the name of The Open Group shall not be
5ec28e
-used in advertising or otherwise to promote the sale, use or other dealings
5ec28e
-in this Software without prior written authorization from The Open Group.
5ec28e
-
5ec28e
-
5ec28e
-Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
5ec28e
-
5ec28e
-                        All Rights Reserved
5ec28e
-
5ec28e
-Permission to use, copy, modify, and distribute this software and its
5ec28e
-documentation for any purpose and without fee is hereby granted,
5ec28e
-provided that the above copyright notice appear in all copies and that
5ec28e
-both that copyright notice and this permission notice appear in
5ec28e
-supporting documentation, and that the name of Digital not be
5ec28e
-used in advertising or publicity pertaining to distribution of the
5ec28e
-software without specific, written prior permission.
5ec28e
-
5ec28e
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
5ec28e
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
5ec28e
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
5ec28e
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
5ec28e
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
5ec28e
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5ec28e
-SOFTWARE.
5ec28e
-
5ec28e
-************************************************************************/
5ec28e
-/*
5ec28e
- * The functions in this file implement the Region abstraction, similar to one
5ec28e
- * used in the X11 sample server. A Region is simply an area, as the name
5ec28e
- * implies, and is implemented as a "y-x-banded" array of rectangles. To
5ec28e
- * explain: Each Region is made up of a certain number of rectangles sorted
5ec28e
- * by y coordinate first, and then by x coordinate.
5ec28e
- *
5ec28e
- * Furthermore, the rectangles are banded such that every rectangle with a
5ec28e
- * given upper-left y coordinate (y1) will have the same lower-right y
5ec28e
- * coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it
5ec28e
- * will span the entire vertical distance of the band. This means that some
5ec28e
- * areas that could be merged into a taller rectangle will be represented as
5ec28e
- * several shorter rectangles to account for shorter rectangles to its left
5ec28e
- * or right but within its "vertical scope".
5ec28e
- *
5ec28e
- * An added constraint on the rectangles is that they must cover as much
5ec28e
- * horizontal area as possible. E.g. no two rectangles in a band are allowed
5ec28e
- * to touch.
5ec28e
- *
5ec28e
- * Whenever possible, bands will be merged together to cover a greater vertical
5ec28e
- * distance (and thus reduce the number of rectangles). Two bands can be merged
5ec28e
- * only if the bottom of one touches the top of the other and they have
5ec28e
- * rectangles in the same places (of the same width, of course). This maintains
5ec28e
- * the y-x-banding that's so nice to have...
5ec28e
- */
5ec28e
-
5ec28e
-#include <string.h>
5ec28e
-
5ec28e
-#include "Xlibint.h"
5ec28e
-#include "Xutil.h"
5ec28e
-#include "Xregion.h"
5ec28e
-
5ec28e
-#ifndef min
5ec28e
-#define min(a,b)            (((a) < (b)) ? (a) : (b))
5ec28e
-#endif
5ec28e
-#ifndef max
5ec28e
-#define max(a,b)            (((a) > (b)) ? (a) : (b))
5ec28e
-#endif
5ec28e
-
5ec28e
-#ifdef DEBUG
5ec28e
-#include <stdio.h>
5ec28e
-#define assert(expr) {if (!(expr)) fprintf(stderr,\
5ec28e
-"Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__); }
5ec28e
-#else
5ec28e
-#define assert(expr)
5ec28e
-#endif
5ec28e
-
5ec28e
-typedef int (*overlapProcp)(
5ec28e
-        register Region     pReg,
5ec28e
-        register BoxPtr     r1,
5ec28e
-        BoxPtr              r1End,
5ec28e
-        register BoxPtr     r2,
5ec28e
-        BoxPtr              r2End,
5ec28e
-        short               y1,
5ec28e
-        short               y2);
5ec28e
-
5ec28e
-typedef int (*nonOverlapProcp)(
5ec28e
-    register Region     pReg,
5ec28e
-    register BoxPtr     r,
5ec28e
-    BoxPtr              rEnd,
5ec28e
-    register short      y1,
5ec28e
-    register short      y2);
5ec28e
-
5ec28e
-static void miRegionOp(
5ec28e
-    register Region 	newReg,	    	    	/* Place to store result */
5ec28e
-    Region	  	reg1,	    	    	/* First region in operation */
5ec28e
-    Region	  	reg2,	    	    	/* 2d region in operation */
5ec28e
-    int    	  	(*overlapFunc)(
5ec28e
-        register Region     pReg,
5ec28e
-        register BoxPtr     r1,
5ec28e
-        BoxPtr              r1End,
5ec28e
-        register BoxPtr     r2,
5ec28e
-        BoxPtr              r2End,
5ec28e
-        short               y1,
5ec28e
-        short               y2),                /* Function to call for over-
5ec28e
-						 * lapping bands */
5ec28e
-    int    	  	(*nonOverlap1Func)(
5ec28e
-        register Region     pReg,
5ec28e
-        register BoxPtr     r,
5ec28e
-        BoxPtr              rEnd,
5ec28e
-        register short      y1,
5ec28e
-        register short      y2),                /* Function to call for non-
5ec28e
-						 * overlapping bands in region
5ec28e
-						 * 1 */
5ec28e
-    int    	  	(*nonOverlap2Func)(
5ec28e
-        register Region     pReg,
5ec28e
-        register BoxPtr     r,
5ec28e
-        BoxPtr              rEnd,
5ec28e
-        register short      y1,
5ec28e
-        register short      y2));               /* Function to call for non-
5ec28e
-						 * overlapping bands in region
5ec28e
-						 * 2 */
5ec28e
-
5ec28e
-
5ec28e
-/*	Create a new empty region	*/
5ec28e
-Region
5ec28e
-XCreateRegion(void)
5ec28e
-{
5ec28e
-    Region temp;
5ec28e
-
5ec28e
-    if (! (temp = Xmalloc(sizeof( REGION ))))
5ec28e
-	return (Region) NULL;
5ec28e
-    if (! (temp->rects = Xmalloc(sizeof( BOX )))) {
5ec28e
-	Xfree(temp);
5ec28e
-	return (Region) NULL;
5ec28e
-    }
5ec28e
-    temp->numRects = 0;
5ec28e
-    temp->extents.x1 = 0;
5ec28e
-    temp->extents.y1 = 0;
5ec28e
-    temp->extents.x2 = 0;
5ec28e
-    temp->extents.y2 = 0;
5ec28e
-    temp->size = 1;
5ec28e
-    return( temp );
5ec28e
-}
5ec28e
-
5ec28e
-int
5ec28e
-XClipBox(
5ec28e
-    Region r,
5ec28e
-    XRectangle *rect)
5ec28e
-{
5ec28e
-    rect->x = r->extents.x1;
5ec28e
-    rect->y = r->extents.y1;
5ec28e
-    rect->width = r->extents.x2 - r->extents.x1;
5ec28e
-    rect->height = r->extents.y2 - r->extents.y1;
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-
5ec28e
-int
5ec28e
-XUnionRectWithRegion(
5ec28e
-    register XRectangle *rect,
5ec28e
-    Region source, Region dest)
5ec28e
-{
5ec28e
-    REGION region;
5ec28e
-
5ec28e
-    if (!rect->width || !rect->height)
5ec28e
-	return 0;
5ec28e
-    region.rects = &region.extents;
5ec28e
-    region.numRects = 1;
5ec28e
-    region.extents.x1 = rect->x;
5ec28e
-    region.extents.y1 = rect->y;
5ec28e
-    region.extents.x2 = rect->x + rect->width;
5ec28e
-    region.extents.y2 = rect->y + rect->height;
5ec28e
-    region.size = 1;
5ec28e
-
5ec28e
-    return XUnionRegion(&region, source, dest);
5ec28e
-}
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miSetExtents --
5ec28e
- *	Reset the extents of a region to what they should be. Called by
5ec28e
- *	miSubtract and miIntersect b/c they can't figure it out along the
5ec28e
- *	way or do so easily, as miUnion can.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	None.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	The region's 'extents' structure is overwritten.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-static void
5ec28e
-miSetExtents (
5ec28e
-    Region	  	pReg)
5ec28e
-{
5ec28e
-    register BoxPtr	pBox,
5ec28e
-			pBoxEnd,
5ec28e
-			pExtents;
5ec28e
-
5ec28e
-    if (pReg->numRects == 0)
5ec28e
-    {
5ec28e
-	pReg->extents.x1 = 0;
5ec28e
-	pReg->extents.y1 = 0;
5ec28e
-	pReg->extents.x2 = 0;
5ec28e
-	pReg->extents.y2 = 0;
5ec28e
-	return;
5ec28e
-    }
5ec28e
-
5ec28e
-    pExtents = &pReg->extents;
5ec28e
-    pBox = pReg->rects;
5ec28e
-    pBoxEnd = &pBox[pReg->numRects - 1];
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Since pBox is the first rectangle in the region, it must have the
5ec28e
-     * smallest y1 and since pBoxEnd is the last rectangle in the region,
5ec28e
-     * it must have the largest y2, because of banding. Initialize x1 and
5ec28e
-     * x2 from  pBox and pBoxEnd, resp., as good things to initialize them
5ec28e
-     * to...
5ec28e
-     */
5ec28e
-    pExtents->x1 = pBox->x1;
5ec28e
-    pExtents->y1 = pBox->y1;
5ec28e
-    pExtents->x2 = pBoxEnd->x2;
5ec28e
-    pExtents->y2 = pBoxEnd->y2;
5ec28e
-
5ec28e
-    assert(pExtents->y1 < pExtents->y2);
5ec28e
-    while (pBox <= pBoxEnd)
5ec28e
-    {
5ec28e
-	if (pBox->x1 < pExtents->x1)
5ec28e
-	{
5ec28e
-	    pExtents->x1 = pBox->x1;
5ec28e
-	}
5ec28e
-	if (pBox->x2 > pExtents->x2)
5ec28e
-	{
5ec28e
-	    pExtents->x2 = pBox->x2;
5ec28e
-	}
5ec28e
-	pBox++;
5ec28e
-    }
5ec28e
-    assert(pExtents->x1 < pExtents->x2);
5ec28e
-}
5ec28e
-
5ec28e
-#if 0
5ec28e
-int
5ec28e
-XSetRegion(
5ec28e
-    Display *dpy,
5ec28e
-    GC gc,
5ec28e
-    register Region r)
5ec28e
-{
5ec28e
-    register int i;
5ec28e
-    register XRectangle *xr, *pr;
5ec28e
-    register BOX *pb;
5ec28e
-    unsigned long total;
5ec28e
-
5ec28e
-    LockDisplay (dpy);
5ec28e
-    total = r->numRects * sizeof (XRectangle);
5ec28e
-    if ((xr = (XRectangle *) _XAllocTemp(dpy, total))) {
5ec28e
-	for (pr = xr, pb = r->rects, i = r->numRects; --i >= 0; pr++, pb++) {
5ec28e
-	    pr->x = pb->x1;
5ec28e
-	    pr->y = pb->y1;
5ec28e
-	    pr->width = pb->x2 - pb->x1;
5ec28e
-	    pr->height = pb->y2 - pb->y1;
5ec28e
-	}
5ec28e
-    }
5ec28e
-    if (xr || !r->numRects)
5ec28e
-	_XSetClipRectangles(dpy, gc, 0, 0, xr, r->numRects, YXBanded);
5ec28e
-    if (xr)
5ec28e
-	_XFreeTemp(dpy, (char *)xr, total);
5ec28e
-    UnlockDisplay(dpy);
5ec28e
-    SyncHandle();
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-#endif
5ec28e
-
5ec28e
-int
5ec28e
-XDestroyRegion(
5ec28e
-    Region r)
5ec28e
-{
5ec28e
-    Xfree( (char *) r->rects );
5ec28e
-    Xfree( (char *) r );
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-
5ec28e
-
5ec28e
-/* TranslateRegion(pRegion, x, y)
5ec28e
-   translates in place
5ec28e
-   added by raymond
5ec28e
-*/
5ec28e
-
5ec28e
-int
5ec28e
-XOffsetRegion(
5ec28e
-    register Region pRegion,
5ec28e
-    register int x,
5ec28e
-    register int y)
5ec28e
-{
5ec28e
-    register int nbox;
5ec28e
-    register BOX *pbox;
5ec28e
-
5ec28e
-    pbox = pRegion->rects;
5ec28e
-    nbox = pRegion->numRects;
5ec28e
-
5ec28e
-    while(nbox--)
5ec28e
-    {
5ec28e
-	pbox->x1 += x;
5ec28e
-	pbox->x2 += x;
5ec28e
-	pbox->y1 += y;
5ec28e
-	pbox->y2 += y;
5ec28e
-	pbox++;
5ec28e
-    }
5ec28e
-    pRegion->extents.x1 += x;
5ec28e
-    pRegion->extents.x2 += x;
5ec28e
-    pRegion->extents.y1 += y;
5ec28e
-    pRegion->extents.y2 += y;
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-
5ec28e
-/*
5ec28e
-   Utility procedure Compress:
5ec28e
-   Replace r by the region r', where
5ec28e
-     p in r' iff (Quantifer m <= dx) (p + m in r), and
5ec28e
-     Quantifier is Exists if grow is TRUE, For all if grow is FALSE, and
5ec28e
-     (x,y) + m = (x+m,y) if xdir is TRUE; (x,y+m) if xdir is FALSE.
5ec28e
-
5ec28e
-   Thus, if xdir is TRUE and grow is FALSE, r is replaced by the region
5ec28e
-   of all points p such that p and the next dx points on the same
5ec28e
-   horizontal scan line are all in r.  We do this using by noting
5ec28e
-   that p is the head of a run of length 2^i + k iff p is the head
5ec28e
-   of a run of length 2^i and p+2^i is the head of a run of length
5ec28e
-   k. Thus, the loop invariant: s contains the region corresponding
5ec28e
-   to the runs of length shift.  r contains the region corresponding
5ec28e
-   to the runs of length 1 + dxo & (shift-1), where dxo is the original
5ec28e
-   value of dx.  dx = dxo & ~(shift-1).  As parameters, s and t are
5ec28e
-   scratch regions, so that we don't have to allocate them on every
5ec28e
-   call.
5ec28e
-*/
5ec28e
-
5ec28e
-#define ZOpRegion(a,b,c) if (grow) XUnionRegion(a,b,c); \
5ec28e
-			 else XIntersectRegion(a,b,c)
5ec28e
-#define ZShiftRegion(a,b) if (xdir) XOffsetRegion(a,b,0); \
5ec28e
-			  else XOffsetRegion(a,0,b)
5ec28e
-#define ZCopyRegion(a,b) XUnionRegion(a,a,b)
5ec28e
-
5ec28e
-static void
5ec28e
-Compress(
5ec28e
-    Region r, Region s, Region t,
5ec28e
-    register unsigned dx,
5ec28e
-    register int xdir, register int grow)
5ec28e
-{
5ec28e
-    register unsigned shift = 1;
5ec28e
-
5ec28e
-    ZCopyRegion(r, s);
5ec28e
-    while (dx) {
5ec28e
-        if (dx & shift) {
5ec28e
-            ZShiftRegion(r, -(int)shift);
5ec28e
-            ZOpRegion(r, s, r);
5ec28e
-            dx -= shift;
5ec28e
-            if (!dx) break;
5ec28e
-        }
5ec28e
-        ZCopyRegion(s, t);
5ec28e
-        ZShiftRegion(s, -(int)shift);
5ec28e
-        ZOpRegion(s, t, s);
5ec28e
-        shift <<= 1;
5ec28e
-    }
5ec28e
-}
5ec28e
-
5ec28e
-#undef ZOpRegion
5ec28e
-#undef ZShiftRegion
5ec28e
-#undef ZCopyRegion
5ec28e
-
5ec28e
-int
5ec28e
-XShrinkRegion(
5ec28e
-    Region r,
5ec28e
-    int dx, int dy)
5ec28e
-{
5ec28e
-    Region s, t;
5ec28e
-    int grow;
5ec28e
-
5ec28e
-    if (!dx && !dy) return 0;
5ec28e
-    if (! (s = XCreateRegion()) )
5ec28e
-	return 0;
5ec28e
-    if (! (t = XCreateRegion()) ) {
5ec28e
-	XDestroyRegion(s);
5ec28e
-	return 0;
5ec28e
-    }
5ec28e
-    if ((grow = (dx < 0))) dx = -dx;
5ec28e
-    if (dx) Compress(r, s, t, (unsigned) 2*dx, TRUE, grow);
5ec28e
-    if ((grow = (dy < 0))) dy = -dy;
5ec28e
-    if (dy) Compress(r, s, t, (unsigned) 2*dy, FALSE, grow);
5ec28e
-    XOffsetRegion(r, dx, dy);
5ec28e
-    XDestroyRegion(s);
5ec28e
-    XDestroyRegion(t);
5ec28e
-    return 0;
5ec28e
-}
5ec28e
-
5ec28e
-
5ec28e
-/*======================================================================
5ec28e
- *	    Region Intersection
5ec28e
- *====================================================================*/
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miIntersectO --
5ec28e
- *	Handle an overlapping band for miIntersect.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	None.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	Rectangles may be added to the region.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-/* static void*/
5ec28e
-static int
5ec28e
-miIntersectO (
5ec28e
-    register Region	pReg,
5ec28e
-    register BoxPtr	r1,
5ec28e
-    BoxPtr  	  	r1End,
5ec28e
-    register BoxPtr	r2,
5ec28e
-    BoxPtr  	  	r2End,
5ec28e
-    short    	  	y1,
5ec28e
-    short    	  	y2)
5ec28e
-{
5ec28e
-    register short  	x1;
5ec28e
-    register short  	x2;
5ec28e
-    register BoxPtr	pNextRect;
5ec28e
-
5ec28e
-    pNextRect = &pReg->rects[pReg->numRects];
5ec28e
-
5ec28e
-    while ((r1 != r1End) && (r2 != r2End))
5ec28e
-    {
5ec28e
-	x1 = max(r1->x1,r2->x1);
5ec28e
-	x2 = min(r1->x2,r2->x2);
5ec28e
-
5ec28e
-	/*
5ec28e
-	 * If there's any overlap between the two rectangles, add that
5ec28e
-	 * overlap to the new region.
5ec28e
-	 * There's no need to check for subsumption because the only way
5ec28e
-	 * such a need could arise is if some region has two rectangles
5ec28e
-	 * right next to each other. Since that should never happen...
5ec28e
-	 */
5ec28e
-	if (x1 < x2)
5ec28e
-	{
5ec28e
-	    assert(y1
5ec28e
-
5ec28e
-	    MEMCHECK(pReg, pNextRect, pReg->rects);
5ec28e
-	    pNextRect->x1 = x1;
5ec28e
-	    pNextRect->y1 = y1;
5ec28e
-	    pNextRect->x2 = x2;
5ec28e
-	    pNextRect->y2 = y2;
5ec28e
-	    pReg->numRects += 1;
5ec28e
-	    pNextRect++;
5ec28e
-	    assert(pReg->numRects <= pReg->size);
5ec28e
-	}
5ec28e
-
5ec28e
-	/*
5ec28e
-	 * Need to advance the pointers. Shift the one that extends
5ec28e
-	 * to the right the least, since the other still has a chance to
5ec28e
-	 * overlap with that region's next rectangle, if you see what I mean.
5ec28e
-	 */
5ec28e
-	if (r1->x2 < r2->x2)
5ec28e
-	{
5ec28e
-	    r1++;
5ec28e
-	}
5ec28e
-	else if (r2->x2 < r1->x2)
5ec28e
-	{
5ec28e
-	    r2++;
5ec28e
-	}
5ec28e
-	else
5ec28e
-	{
5ec28e
-	    r1++;
5ec28e
-	    r2++;
5ec28e
-	}
5ec28e
-    }
5ec28e
-    return 0;	/* lint */
5ec28e
-}
5ec28e
-
5ec28e
-int
5ec28e
-XIntersectRegion(
5ec28e
-    Region 	  	reg1,
5ec28e
-    Region	  	reg2,          /* source regions     */
5ec28e
-    register Region 	newReg)               /* destination Region */
5ec28e
-{
5ec28e
-   /* check for trivial reject */
5ec28e
-    if ( (!(reg1->numRects)) || (!(reg2->numRects))  ||
5ec28e
-	(!EXTENTCHECK(&reg1->extents, &reg2->extents)))
5ec28e
-        newReg->numRects = 0;
5ec28e
-    else
5ec28e
-	miRegionOp (newReg, reg1, reg2,
5ec28e
-    		miIntersectO, NULL, NULL);
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Can't alter newReg's extents before we call miRegionOp because
5ec28e
-     * it might be one of the source regions and miRegionOp depends
5ec28e
-     * on the extents of those regions being the same. Besides, this
5ec28e
-     * way there's no checking against rectangles that will be nuked
5ec28e
-     * due to coalescing, so we have to examine fewer rectangles.
5ec28e
-     */
5ec28e
-    miSetExtents(newReg);
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-
5ec28e
-static int
5ec28e
-miRegionCopy(
5ec28e
-    register Region dstrgn,
5ec28e
-    register Region rgn)
5ec28e
-
5ec28e
-{
5ec28e
-    if (dstrgn != rgn) /*  don't want to copy to itself */
5ec28e
-    {
5ec28e
-        if (dstrgn->size < rgn->numRects)
5ec28e
-        {
5ec28e
-            if (dstrgn->rects)
5ec28e
-            {
5ec28e
-		BOX *prevRects = dstrgn->rects;
5ec28e
-
5ec28e
-		dstrgn->rects = Xrealloc(dstrgn->rects,
5ec28e
-					 rgn->numRects * (sizeof(BOX)));
5ec28e
-		if (! dstrgn->rects) {
5ec28e
-		    Xfree(prevRects);
5ec28e
-		    dstrgn->size = 0;
5ec28e
-		    return 0;
5ec28e
-		}
5ec28e
-            }
5ec28e
-            dstrgn->size = rgn->numRects;
5ec28e
-	}
5ec28e
-        dstrgn->numRects = rgn->numRects;
5ec28e
-        dstrgn->extents.x1 = rgn->extents.x1;
5ec28e
-        dstrgn->extents.y1 = rgn->extents.y1;
5ec28e
-        dstrgn->extents.x2 = rgn->extents.x2;
5ec28e
-        dstrgn->extents.y2 = rgn->extents.y2;
5ec28e
-
5ec28e
-	memcpy((char *) dstrgn->rects, (char *) rgn->rects,
5ec28e
-	       (int) (rgn->numRects * sizeof(BOX)));
5ec28e
-    }
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-
5ec28e
-/*======================================================================
5ec28e
- *	    Generic Region Operator
5ec28e
- *====================================================================*/
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miCoalesce --
5ec28e
- *	Attempt to merge the boxes in the current band with those in the
5ec28e
- *	previous one. Used only by miRegionOp.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	The new index for the previous band.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	If coalescing takes place:
5ec28e
- *	    - rectangles in the previous band will have their y2 fields
5ec28e
- *	      altered.
5ec28e
- *	    - pReg->numRects will be decreased.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-/* static int*/
5ec28e
-static int
5ec28e
-miCoalesce(
5ec28e
-    register Region	pReg,	    	/* Region to coalesce */
5ec28e
-    int	    	  	prevStart,  	/* Index of start of previous band */
5ec28e
-    int	    	  	curStart)   	/* Index of start of current band */
5ec28e
-{
5ec28e
-    register BoxPtr	pPrevBox;   	/* Current box in previous band */
5ec28e
-    register BoxPtr	pCurBox;    	/* Current box in current band */
5ec28e
-    register BoxPtr	pRegEnd;    	/* End of region */
5ec28e
-    int	    	  	curNumRects;	/* Number of rectangles in current
5ec28e
-					 * band */
5ec28e
-    int	    	  	prevNumRects;	/* Number of rectangles in previous
5ec28e
-					 * band */
5ec28e
-    int	    	  	bandY1;	    	/* Y1 coordinate for current band */
5ec28e
-
5ec28e
-    pRegEnd = &pReg->rects[pReg->numRects];
5ec28e
-
5ec28e
-    pPrevBox = &pReg->rects[prevStart];
5ec28e
-    prevNumRects = curStart - prevStart;
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Figure out how many rectangles are in the current band. Have to do
5ec28e
-     * this because multiple bands could have been added in miRegionOp
5ec28e
-     * at the end when one region has been exhausted.
5ec28e
-     */
5ec28e
-    pCurBox = &pReg->rects[curStart];
5ec28e
-    bandY1 = pCurBox->y1;
5ec28e
-    for (curNumRects = 0;
5ec28e
-	 (pCurBox != pRegEnd) && (pCurBox->y1 == bandY1);
5ec28e
-	 curNumRects++)
5ec28e
-    {
5ec28e
-	pCurBox++;
5ec28e
-    }
5ec28e
-
5ec28e
-    if (pCurBox != pRegEnd)
5ec28e
-    {
5ec28e
-	/*
5ec28e
-	 * If more than one band was added, we have to find the start
5ec28e
-	 * of the last band added so the next coalescing job can start
5ec28e
-	 * at the right place... (given when multiple bands are added,
5ec28e
-	 * this may be pointless -- see above).
5ec28e
-	 */
5ec28e
-	pRegEnd--;
5ec28e
-	while (pRegEnd[-1].y1 == pRegEnd->y1)
5ec28e
-	{
5ec28e
-	    pRegEnd--;
5ec28e
-	}
5ec28e
-	curStart = pRegEnd - pReg->rects;
5ec28e
-	pRegEnd = pReg->rects + pReg->numRects;
5ec28e
-    }
5ec28e
-
5ec28e
-    if ((curNumRects == prevNumRects) && (curNumRects != 0)) {
5ec28e
-	pCurBox -= curNumRects;
5ec28e
-	/*
5ec28e
-	 * The bands may only be coalesced if the bottom of the previous
5ec28e
-	 * matches the top scanline of the current.
5ec28e
-	 */
5ec28e
-	if (pPrevBox->y2 == pCurBox->y1)
5ec28e
-	{
5ec28e
-	    /*
5ec28e
-	     * Make sure the bands have boxes in the same places. This
5ec28e
-	     * assumes that boxes have been added in such a way that they
5ec28e
-	     * cover the most area possible. I.e. two boxes in a band must
5ec28e
-	     * have some horizontal space between them.
5ec28e
-	     */
5ec28e
-	    do
5ec28e
-	    {
5ec28e
-		if ((pPrevBox->x1 != pCurBox->x1) ||
5ec28e
-		    (pPrevBox->x2 != pCurBox->x2))
5ec28e
-		{
5ec28e
-		    /*
5ec28e
-		     * The bands don't line up so they can't be coalesced.
5ec28e
-		     */
5ec28e
-		    return (curStart);
5ec28e
-		}
5ec28e
-		pPrevBox++;
5ec28e
-		pCurBox++;
5ec28e
-		prevNumRects -= 1;
5ec28e
-	    } while (prevNumRects != 0);
5ec28e
-
5ec28e
-	    pReg->numRects -= curNumRects;
5ec28e
-	    pCurBox -= curNumRects;
5ec28e
-	    pPrevBox -= curNumRects;
5ec28e
-
5ec28e
-	    /*
5ec28e
-	     * The bands may be merged, so set the bottom y of each box
5ec28e
-	     * in the previous band to that of the corresponding box in
5ec28e
-	     * the current band.
5ec28e
-	     */
5ec28e
-	    do
5ec28e
-	    {
5ec28e
-		pPrevBox->y2 = pCurBox->y2;
5ec28e
-		pPrevBox++;
5ec28e
-		pCurBox++;
5ec28e
-		curNumRects -= 1;
5ec28e
-	    } while (curNumRects != 0);
5ec28e
-
5ec28e
-	    /*
5ec28e
-	     * If only one band was added to the region, we have to backup
5ec28e
-	     * curStart to the start of the previous band.
5ec28e
-	     *
5ec28e
-	     * If more than one band was added to the region, copy the
5ec28e
-	     * other bands down. The assumption here is that the other bands
5ec28e
-	     * came from the same region as the current one and no further
5ec28e
-	     * coalescing can be done on them since it's all been done
5ec28e
-	     * already... curStart is already in the right place.
5ec28e
-	     */
5ec28e
-	    if (pCurBox == pRegEnd)
5ec28e
-	    {
5ec28e
-		curStart = prevStart;
5ec28e
-	    }
5ec28e
-	    else
5ec28e
-	    {
5ec28e
-		do
5ec28e
-		{
5ec28e
-		    *pPrevBox++ = *pCurBox++;
5ec28e
-		} while (pCurBox != pRegEnd);
5ec28e
-	    }
5ec28e
-
5ec28e
-	}
5ec28e
-    }
5ec28e
-    return (curStart);
5ec28e
-}
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miRegionOp --
5ec28e
- *	Apply an operation to two regions. Called by miUnion, miInverse,
5ec28e
- *	miSubtract, miIntersect...
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	None.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	The new region is overwritten.
5ec28e
- *
5ec28e
- * Notes:
5ec28e
- *	The idea behind this function is to view the two regions as sets.
5ec28e
- *	Together they cover a rectangle of area that this function divides
5ec28e
- *	into horizontal bands where points are covered only by one region
5ec28e
- *	or by both. For the first case, the nonOverlapFunc is called with
5ec28e
- *	each the band and the band's upper and lower extents. For the
5ec28e
- *	second, the overlapFunc is called to process the entire band. It
5ec28e
- *	is responsible for clipping the rectangles in the band, though
5ec28e
- *	this function provides the boundaries.
5ec28e
- *	At the end of each band, the new region is coalesced, if possible,
5ec28e
- *	to reduce the number of rectangles in the region.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-/* static void*/
5ec28e
-static void
5ec28e
-miRegionOp(
5ec28e
-    register Region 	newReg,	    	    	/* Place to store result */
5ec28e
-    Region	  	reg1,	    	    	/* First region in operation */
5ec28e
-    Region	  	reg2,	    	    	/* 2d region in operation */
5ec28e
-    int    	  	(*overlapFunc)(
5ec28e
-        register Region     pReg,
5ec28e
-        register BoxPtr     r1,
5ec28e
-        BoxPtr              r1End,
5ec28e
-        register BoxPtr     r2,
5ec28e
-        BoxPtr              r2End,
5ec28e
-        short               y1,
5ec28e
-        short               y2),                /* Function to call for over-
5ec28e
-						 * lapping bands */
5ec28e
-    int    	  	(*nonOverlap1Func)(
5ec28e
-        register Region     pReg,
5ec28e
-        register BoxPtr     r,
5ec28e
-        BoxPtr              rEnd,
5ec28e
-        register short      y1,
5ec28e
-        register short      y2),                /* Function to call for non-
5ec28e
-						 * overlapping bands in region
5ec28e
-						 * 1 */
5ec28e
-    int    	  	(*nonOverlap2Func)(
5ec28e
-        register Region     pReg,
5ec28e
-        register BoxPtr     r,
5ec28e
-        BoxPtr              rEnd,
5ec28e
-        register short      y1,
5ec28e
-        register short      y2))                /* Function to call for non-
5ec28e
-						 * overlapping bands in region
5ec28e
-						 * 2 */
5ec28e
-{
5ec28e
-    register BoxPtr	r1; 	    	    	/* Pointer into first region */
5ec28e
-    register BoxPtr	r2; 	    	    	/* Pointer into 2d region */
5ec28e
-    BoxPtr  	  	r1End;	    	    	/* End of 1st region */
5ec28e
-    BoxPtr  	  	r2End;	    	    	/* End of 2d region */
5ec28e
-    register short  	ybot;	    	    	/* Bottom of intersection */
5ec28e
-    register short  	ytop;	    	    	/* Top of intersection */
5ec28e
-    BoxPtr  	  	oldRects;   	    	/* Old rects for newReg */
5ec28e
-    int	    	  	prevBand;   	    	/* Index of start of
5ec28e
-						 * previous band in newReg */
5ec28e
-    int	    	  	curBand;    	    	/* Index of start of current
5ec28e
-						 * band in newReg */
5ec28e
-    register BoxPtr 	r1BandEnd;  	    	/* End of current band in r1 */
5ec28e
-    register BoxPtr 	r2BandEnd;  	    	/* End of current band in r2 */
5ec28e
-    short     	  	top;	    	    	/* Top of non-overlapping
5ec28e
-						 * band */
5ec28e
-    short     	  	bot;	    	    	/* Bottom of non-overlapping
5ec28e
-						 * band */
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Initialization:
5ec28e
-     *	set r1, r2, r1End and r2End appropriately, preserve the important
5ec28e
-     * parts of the destination region until the end in case it's one of
5ec28e
-     * the two source regions, then mark the "new" region empty, allocating
5ec28e
-     * another array of rectangles for it to use.
5ec28e
-     */
5ec28e
-    r1 = reg1->rects;
5ec28e
-    r2 = reg2->rects;
5ec28e
-    r1End = r1 + reg1->numRects;
5ec28e
-    r2End = r2 + reg2->numRects;
5ec28e
-
5ec28e
-    oldRects = newReg->rects;
5ec28e
-
5ec28e
-    EMPTY_REGION(newReg);
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Allocate a reasonable number of rectangles for the new region. The idea
5ec28e
-     * is to allocate enough so the individual functions don't need to
5ec28e
-     * reallocate and copy the array, which is time consuming, yet we don't
5ec28e
-     * have to worry about using too much memory. I hope to be able to
5ec28e
-     * nuke the Xrealloc() at the end of this function eventually.
5ec28e
-     */
5ec28e
-    newReg->size = max(reg1->numRects,reg2->numRects) * 2;
5ec28e
-
5ec28e
-    if (! (newReg->rects = Xmalloc (sizeof(BoxRec) * newReg->size))) {
5ec28e
-	newReg->size = 0;
5ec28e
-	return;
5ec28e
-    }
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Initialize ybot and ytop.
5ec28e
-     * In the upcoming loop, ybot and ytop serve different functions depending
5ec28e
-     * on whether the band being handled is an overlapping or non-overlapping
5ec28e
-     * band.
5ec28e
-     * 	In the case of a non-overlapping band (only one of the regions
5ec28e
-     * has points in the band), ybot is the bottom of the most recent
5ec28e
-     * intersection and thus clips the top of the rectangles in that band.
5ec28e
-     * ytop is the top of the next intersection between the two regions and
5ec28e
-     * serves to clip the bottom of the rectangles in the current band.
5ec28e
-     *	For an overlapping band (where the two regions intersect), ytop clips
5ec28e
-     * the top of the rectangles of both regions and ybot clips the bottoms.
5ec28e
-     */
5ec28e
-    if (reg1->extents.y1 < reg2->extents.y1)
5ec28e
-	ybot = reg1->extents.y1;
5ec28e
-    else
5ec28e
-	ybot = reg2->extents.y1;
5ec28e
-
5ec28e
-    /*
5ec28e
-     * prevBand serves to mark the start of the previous band so rectangles
5ec28e
-     * can be coalesced into larger rectangles. qv. miCoalesce, above.
5ec28e
-     * In the beginning, there is no previous band, so prevBand == curBand
5ec28e
-     * (curBand is set later on, of course, but the first band will always
5ec28e
-     * start at index 0). prevBand and curBand must be indices because of
5ec28e
-     * the possible expansion, and resultant moving, of the new region's
5ec28e
-     * array of rectangles.
5ec28e
-     */
5ec28e
-    prevBand = 0;
5ec28e
-
5ec28e
-    do
5ec28e
-    {
5ec28e
-	curBand = newReg->numRects;
5ec28e
-
5ec28e
-	/*
5ec28e
-	 * This algorithm proceeds one source-band (as opposed to a
5ec28e
-	 * destination band, which is determined by where the two regions
5ec28e
-	 * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
5ec28e
-	 * rectangle after the last one in the current band for their
5ec28e
-	 * respective regions.
5ec28e
-	 */
5ec28e
-	r1BandEnd = r1;
5ec28e
-	while ((r1BandEnd != r1End) && (r1BandEnd->y1 == r1->y1))
5ec28e
-	{
5ec28e
-	    r1BandEnd++;
5ec28e
-	}
5ec28e
-
5ec28e
-	r2BandEnd = r2;
5ec28e
-	while ((r2BandEnd != r2End) && (r2BandEnd->y1 == r2->y1))
5ec28e
-	{
5ec28e
-	    r2BandEnd++;
5ec28e
-	}
5ec28e
-
5ec28e
-	/*
5ec28e
-	 * First handle the band that doesn't intersect, if any.
5ec28e
-	 *
5ec28e
-	 * Note that attention is restricted to one band in the
5ec28e
-	 * non-intersecting region at once, so if a region has n
5ec28e
-	 * bands between the current position and the next place it overlaps
5ec28e
-	 * the other, this entire loop will be passed through n times.
5ec28e
-	 */
5ec28e
-	if (r1->y1 < r2->y1)
5ec28e
-	{
5ec28e
-	    top = max(r1->y1,ybot);
5ec28e
-	    bot = min(r1->y2,r2->y1);
5ec28e
-
5ec28e
-	    if ((top != bot) && (nonOverlap1Func != NULL))
5ec28e
-	    {
5ec28e
-		(* nonOverlap1Func) (newReg, r1, r1BandEnd, top, bot);
5ec28e
-	    }
5ec28e
-
5ec28e
-	    ytop = r2->y1;
5ec28e
-	}
5ec28e
-	else if (r2->y1 < r1->y1)
5ec28e
-	{
5ec28e
-	    top = max(r2->y1,ybot);
5ec28e
-	    bot = min(r2->y2,r1->y1);
5ec28e
-
5ec28e
-	    if ((top != bot) && (nonOverlap2Func != NULL))
5ec28e
-	    {
5ec28e
-		(* nonOverlap2Func) (newReg, r2, r2BandEnd, top, bot);
5ec28e
-	    }
5ec28e
-
5ec28e
-	    ytop = r1->y1;
5ec28e
-	}
5ec28e
-	else
5ec28e
-	{
5ec28e
-	    ytop = r1->y1;
5ec28e
-	}
5ec28e
-
5ec28e
-	/*
5ec28e
-	 * If any rectangles got added to the region, try and coalesce them
5ec28e
-	 * with rectangles from the previous band. Note we could just do
5ec28e
-	 * this test in miCoalesce, but some machines incur a not
5ec28e
-	 * inconsiderable cost for function calls, so...
5ec28e
-	 */
5ec28e
-	if (newReg->numRects != curBand)
5ec28e
-	{
5ec28e
-	    prevBand = miCoalesce (newReg, prevBand, curBand);
5ec28e
-	}
5ec28e
-
5ec28e
-	/*
5ec28e
-	 * Now see if we've hit an intersecting band. The two bands only
5ec28e
-	 * intersect if ybot > ytop
5ec28e
-	 */
5ec28e
-	ybot = min(r1->y2, r2->y2);
5ec28e
-	curBand = newReg->numRects;
5ec28e
-	if (ybot > ytop)
5ec28e
-	{
5ec28e
-	    (* overlapFunc) (newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot);
5ec28e
-
5ec28e
-	}
5ec28e
-
5ec28e
-	if (newReg->numRects != curBand)
5ec28e
-	{
5ec28e
-	    prevBand = miCoalesce (newReg, prevBand, curBand);
5ec28e
-	}
5ec28e
-
5ec28e
-	/*
5ec28e
-	 * If we've finished with a band (y2 == ybot) we skip forward
5ec28e
-	 * in the region to the next band.
5ec28e
-	 */
5ec28e
-	if (r1->y2 == ybot)
5ec28e
-	{
5ec28e
-	    r1 = r1BandEnd;
5ec28e
-	}
5ec28e
-	if (r2->y2 == ybot)
5ec28e
-	{
5ec28e
-	    r2 = r2BandEnd;
5ec28e
-	}
5ec28e
-    } while ((r1 != r1End) && (r2 != r2End));
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Deal with whichever region still has rectangles left.
5ec28e
-     */
5ec28e
-    curBand = newReg->numRects;
5ec28e
-    if (r1 != r1End)
5ec28e
-    {
5ec28e
-	if (nonOverlap1Func != NULL)
5ec28e
-	{
5ec28e
-	    do
5ec28e
-	    {
5ec28e
-		r1BandEnd = r1;
5ec28e
-		while ((r1BandEnd < r1End) && (r1BandEnd->y1 == r1->y1))
5ec28e
-		{
5ec28e
-		    r1BandEnd++;
5ec28e
-		}
5ec28e
-		(* nonOverlap1Func) (newReg, r1, r1BandEnd,
5ec28e
-				     max(r1->y1,ybot), r1->y2);
5ec28e
-		r1 = r1BandEnd;
5ec28e
-	    } while (r1 != r1End);
5ec28e
-	}
5ec28e
-    }
5ec28e
-    else if ((r2 != r2End) && (nonOverlap2Func != NULL))
5ec28e
-    {
5ec28e
-	do
5ec28e
-	{
5ec28e
-	    r2BandEnd = r2;
5ec28e
-	    while ((r2BandEnd < r2End) && (r2BandEnd->y1 == r2->y1))
5ec28e
-	    {
5ec28e
-		 r2BandEnd++;
5ec28e
-	    }
5ec28e
-	    (* nonOverlap2Func) (newReg, r2, r2BandEnd,
5ec28e
-				max(r2->y1,ybot), r2->y2);
5ec28e
-	    r2 = r2BandEnd;
5ec28e
-	} while (r2 != r2End);
5ec28e
-    }
5ec28e
-
5ec28e
-    if (newReg->numRects != curBand)
5ec28e
-    {
5ec28e
-	(void) miCoalesce (newReg, prevBand, curBand);
5ec28e
-    }
5ec28e
-
5ec28e
-    /*
5ec28e
-     * A bit of cleanup. To keep regions from growing without bound,
5ec28e
-     * we shrink the array of rectangles to match the new number of
5ec28e
-     * rectangles in the region. This never goes to 0, however...
5ec28e
-     *
5ec28e
-     * Only do this stuff if the number of rectangles allocated is more than
5ec28e
-     * twice the number of rectangles in the region (a simple optimization...).
5ec28e
-     */
5ec28e
-    if (newReg->numRects < (newReg->size >> 1))
5ec28e
-    {
5ec28e
-	if (REGION_NOT_EMPTY(newReg))
5ec28e
-	{
5ec28e
-	    BoxPtr prev_rects = newReg->rects;
5ec28e
-	    newReg->rects = Xrealloc (newReg->rects,
5ec28e
-				      sizeof(BoxRec) * newReg->numRects);
5ec28e
-	    if (! newReg->rects)
5ec28e
-		newReg->rects = prev_rects;
5ec28e
-	    else
5ec28e
-		newReg->size = newReg->numRects;
5ec28e
-	}
5ec28e
-	else
5ec28e
-	{
5ec28e
-	    /*
5ec28e
-	     * No point in doing the extra work involved in an Xrealloc if
5ec28e
-	     * the region is empty
5ec28e
-	     */
5ec28e
-	    newReg->size = 1;
5ec28e
-	    Xfree(newReg->rects);
5ec28e
-	    newReg->rects = Xmalloc(sizeof(BoxRec));
5ec28e
-	}
5ec28e
-    }
5ec28e
-    Xfree (oldRects);
5ec28e
-    return;
5ec28e
-}
5ec28e
-
5ec28e
-
5ec28e
-/*======================================================================
5ec28e
- *	    Region Union
5ec28e
- *====================================================================*/
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miUnionNonO --
5ec28e
- *	Handle a non-overlapping band for the union operation. Just
5ec28e
- *	Adds the rectangles into the region. Doesn't have to check for
5ec28e
- *	subsumption or anything.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	None.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	pReg->numRects is incremented and the final rectangles overwritten
5ec28e
- *	with the rectangles we're passed.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-/* static void*/
5ec28e
-static int
5ec28e
-miUnionNonO (
5ec28e
-    register Region	pReg,
5ec28e
-    register BoxPtr	r,
5ec28e
-    BoxPtr  	  	rEnd,
5ec28e
-    register short  	y1,
5ec28e
-    register short  	y2)
5ec28e
-{
5ec28e
-    register BoxPtr	pNextRect;
5ec28e
-
5ec28e
-    pNextRect = &pReg->rects[pReg->numRects];
5ec28e
-
5ec28e
-    assert(y1 < y2);
5ec28e
-
5ec28e
-    while (r != rEnd)
5ec28e
-    {
5ec28e
-	assert(r->x1 < r->x2);
5ec28e
-	MEMCHECK(pReg, pNextRect, pReg->rects);
5ec28e
-	pNextRect->x1 = r->x1;
5ec28e
-	pNextRect->y1 = y1;
5ec28e
-	pNextRect->x2 = r->x2;
5ec28e
-	pNextRect->y2 = y2;
5ec28e
-	pReg->numRects += 1;
5ec28e
-	pNextRect++;
5ec28e
-
5ec28e
-	assert(pReg->numRects<=pReg->size);
5ec28e
-	r++;
5ec28e
-    }
5ec28e
-    return 0;	/* lint */
5ec28e
-}
5ec28e
-
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miUnionO --
5ec28e
- *	Handle an overlapping band for the union operation. Picks the
5ec28e
- *	left-most rectangle each time and merges it into the region.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	None.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	Rectangles are overwritten in pReg->rects and pReg->numRects will
5ec28e
- *	be changed.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-
5ec28e
-/* static void*/
5ec28e
-static int
5ec28e
-miUnionO (
5ec28e
-    register Region	pReg,
5ec28e
-    register BoxPtr	r1,
5ec28e
-    BoxPtr  	  	r1End,
5ec28e
-    register BoxPtr	r2,
5ec28e
-    BoxPtr  	  	r2End,
5ec28e
-    register short	y1,
5ec28e
-    register short	y2)
5ec28e
-{
5ec28e
-    register BoxPtr	pNextRect;
5ec28e
-
5ec28e
-    pNextRect = &pReg->rects[pReg->numRects];
5ec28e
-
5ec28e
-#define MERGERECT(r) \
5ec28e
-    if ((pReg->numRects != 0) &&  \
5ec28e
-	(pNextRect[-1].y1 == y1) &&  \
5ec28e
-	(pNextRect[-1].y2 == y2) &&  \
5ec28e
-	(pNextRect[-1].x2 >= r->x1))  \
5ec28e
-    {  \
5ec28e
-	if (pNextRect[-1].x2 < r->x2)  \
5ec28e
-	{  \
5ec28e
-	    pNextRect[-1].x2 = r->x2;  \
5ec28e
-	    assert(pNextRect[-1].x1
5ec28e
-	}  \
5ec28e
-    }  \
5ec28e
-    else  \
5ec28e
-    {  \
5ec28e
-	MEMCHECK(pReg, pNextRect, pReg->rects);  \
5ec28e
-	pNextRect->y1 = y1;  \
5ec28e
-	pNextRect->y2 = y2;  \
5ec28e
-	pNextRect->x1 = r->x1;  \
5ec28e
-	pNextRect->x2 = r->x2;  \
5ec28e
-	pReg->numRects += 1;  \
5ec28e
-        pNextRect += 1;  \
5ec28e
-    }  \
5ec28e
-    assert(pReg->numRects<=pReg->size);\
5ec28e
-    r++;
5ec28e
-
5ec28e
-    assert (y1
5ec28e
-    while ((r1 != r1End) && (r2 != r2End))
5ec28e
-    {
5ec28e
-	if (r1->x1 < r2->x1)
5ec28e
-	{
5ec28e
-	    MERGERECT(r1);
5ec28e
-	}
5ec28e
-	else
5ec28e
-	{
5ec28e
-	    MERGERECT(r2);
5ec28e
-	}
5ec28e
-    }
5ec28e
-
5ec28e
-    if (r1 != r1End)
5ec28e
-    {
5ec28e
-	do
5ec28e
-	{
5ec28e
-	    MERGERECT(r1);
5ec28e
-	} while (r1 != r1End);
5ec28e
-    }
5ec28e
-    else while (r2 != r2End)
5ec28e
-    {
5ec28e
-	MERGERECT(r2);
5ec28e
-    }
5ec28e
-    return 0;	/* lint */
5ec28e
-}
5ec28e
-
5ec28e
-int
5ec28e
-XUnionRegion(
5ec28e
-    Region 	  reg1,
5ec28e
-    Region	  reg2,             /* source regions     */
5ec28e
-    Region 	  newReg)                  /* destination Region */
5ec28e
-{
5ec28e
-    /*  checks all the simple cases */
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Region 1 and 2 are the same or region 1 is empty
5ec28e
-     */
5ec28e
-    if ( (reg1 == reg2) || (!(reg1->numRects)) )
5ec28e
-    {
5ec28e
-        if (newReg != reg2)
5ec28e
-            return miRegionCopy(newReg, reg2);
5ec28e
-        return 1;
5ec28e
-    }
5ec28e
-
5ec28e
-    /*
5ec28e
-     * if nothing to union (region 2 empty)
5ec28e
-     */
5ec28e
-    if (!(reg2->numRects))
5ec28e
-    {
5ec28e
-        if (newReg != reg1)
5ec28e
-            return miRegionCopy(newReg, reg1);
5ec28e
-        return 1;
5ec28e
-    }
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Region 1 completely subsumes region 2
5ec28e
-     */
5ec28e
-    if ((reg1->numRects == 1) &&
5ec28e
-	(reg1->extents.x1 <= reg2->extents.x1) &&
5ec28e
-	(reg1->extents.y1 <= reg2->extents.y1) &&
5ec28e
-	(reg1->extents.x2 >= reg2->extents.x2) &&
5ec28e
-	(reg1->extents.y2 >= reg2->extents.y2))
5ec28e
-    {
5ec28e
-        if (newReg != reg1)
5ec28e
-            return miRegionCopy(newReg, reg1);
5ec28e
-        return 1;
5ec28e
-    }
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Region 2 completely subsumes region 1
5ec28e
-     */
5ec28e
-    if ((reg2->numRects == 1) &&
5ec28e
-	(reg2->extents.x1 <= reg1->extents.x1) &&
5ec28e
-	(reg2->extents.y1 <= reg1->extents.y1) &&
5ec28e
-	(reg2->extents.x2 >= reg1->extents.x2) &&
5ec28e
-	(reg2->extents.y2 >= reg1->extents.y2))
5ec28e
-    {
5ec28e
-        if (newReg != reg2)
5ec28e
-            return miRegionCopy(newReg, reg2);
5ec28e
-        return 1;
5ec28e
-    }
5ec28e
-
5ec28e
-    miRegionOp (newReg, reg1, reg2, miUnionO,
5ec28e
-    		miUnionNonO, miUnionNonO);
5ec28e
-
5ec28e
-    newReg->extents.x1 = min(reg1->extents.x1, reg2->extents.x1);
5ec28e
-    newReg->extents.y1 = min(reg1->extents.y1, reg2->extents.y1);
5ec28e
-    newReg->extents.x2 = max(reg1->extents.x2, reg2->extents.x2);
5ec28e
-    newReg->extents.y2 = max(reg1->extents.y2, reg2->extents.y2);
5ec28e
-
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-
5ec28e
-
5ec28e
-/*======================================================================
5ec28e
- * 	    	  Region Subtraction
5ec28e
- *====================================================================*/
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miSubtractNonO --
5ec28e
- *	Deal with non-overlapping band for subtraction. Any parts from
5ec28e
- *	region 2 we discard. Anything from region 1 we add to the region.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	None.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	pReg may be affected.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-/* static void*/
5ec28e
-static int
5ec28e
-miSubtractNonO1 (
5ec28e
-    register Region	pReg,
5ec28e
-    register BoxPtr	r,
5ec28e
-    BoxPtr  	  	rEnd,
5ec28e
-    register short  	y1,
5ec28e
-    register short   	y2)
5ec28e
-{
5ec28e
-    register BoxPtr	pNextRect;
5ec28e
-
5ec28e
-    pNextRect = &pReg->rects[pReg->numRects];
5ec28e
-
5ec28e
-    assert(y1
5ec28e
-
5ec28e
-    while (r != rEnd)
5ec28e
-    {
5ec28e
-	assert(r->x1<r->x2);
5ec28e
-	MEMCHECK(pReg, pNextRect, pReg->rects);
5ec28e
-	pNextRect->x1 = r->x1;
5ec28e
-	pNextRect->y1 = y1;
5ec28e
-	pNextRect->x2 = r->x2;
5ec28e
-	pNextRect->y2 = y2;
5ec28e
-	pReg->numRects += 1;
5ec28e
-	pNextRect++;
5ec28e
-
5ec28e
-	assert(pReg->numRects <= pReg->size);
5ec28e
-
5ec28e
-	r++;
5ec28e
-    }
5ec28e
-    return 0;	/* lint */
5ec28e
-}
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miSubtractO --
5ec28e
- *	Overlapping band subtraction. x1 is the left-most point not yet
5ec28e
- *	checked.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	None.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	pReg may have rectangles added to it.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-/* static void*/
5ec28e
-static int
5ec28e
-miSubtractO (
5ec28e
-    register Region	pReg,
5ec28e
-    register BoxPtr	r1,
5ec28e
-    BoxPtr  	  	r1End,
5ec28e
-    register BoxPtr	r2,
5ec28e
-    BoxPtr  	  	r2End,
5ec28e
-    register short  	y1,
5ec28e
-    register short  	y2)
5ec28e
-{
5ec28e
-    register BoxPtr	pNextRect;
5ec28e
-    register int  	x1;
5ec28e
-
5ec28e
-    x1 = r1->x1;
5ec28e
-
5ec28e
-    assert(y1
5ec28e
-    pNextRect = &pReg->rects[pReg->numRects];
5ec28e
-
5ec28e
-    while ((r1 != r1End) && (r2 != r2End))
5ec28e
-    {
5ec28e
-	if (r2->x2 <= x1)
5ec28e
-	{
5ec28e
-	    /*
5ec28e
-	     * Subtrahend missed the boat: go to next subtrahend.
5ec28e
-	     */
5ec28e
-	    r2++;
5ec28e
-	}
5ec28e
-	else if (r2->x1 <= x1)
5ec28e
-	{
5ec28e
-	    /*
5ec28e
-	     * Subtrahend preceds minuend: nuke left edge of minuend.
5ec28e
-	     */
5ec28e
-	    x1 = r2->x2;
5ec28e
-	    if (x1 >= r1->x2)
5ec28e
-	    {
5ec28e
-		/*
5ec28e
-		 * Minuend completely covered: advance to next minuend and
5ec28e
-		 * reset left fence to edge of new minuend.
5ec28e
-		 */
5ec28e
-		r1++;
5ec28e
-		if (r1 != r1End)
5ec28e
-		    x1 = r1->x1;
5ec28e
-	    }
5ec28e
-	    else
5ec28e
-	    {
5ec28e
-		/*
5ec28e
-		 * Subtrahend now used up since it doesn't extend beyond
5ec28e
-		 * minuend
5ec28e
-		 */
5ec28e
-		r2++;
5ec28e
-	    }
5ec28e
-	}
5ec28e
-	else if (r2->x1 < r1->x2)
5ec28e
-	{
5ec28e
-	    /*
5ec28e
-	     * Left part of subtrahend covers part of minuend: add uncovered
5ec28e
-	     * part of minuend to region and skip to next subtrahend.
5ec28e
-	     */
5ec28e
-	    assert(x1<r2->x1);
5ec28e
-	    MEMCHECK(pReg, pNextRect, pReg->rects);
5ec28e
-	    pNextRect->x1 = x1;
5ec28e
-	    pNextRect->y1 = y1;
5ec28e
-	    pNextRect->x2 = r2->x1;
5ec28e
-	    pNextRect->y2 = y2;
5ec28e
-	    pReg->numRects += 1;
5ec28e
-	    pNextRect++;
5ec28e
-
5ec28e
-	    assert(pReg->numRects<=pReg->size);
5ec28e
-
5ec28e
-	    x1 = r2->x2;
5ec28e
-	    if (x1 >= r1->x2)
5ec28e
-	    {
5ec28e
-		/*
5ec28e
-		 * Minuend used up: advance to new...
5ec28e
-		 */
5ec28e
-		r1++;
5ec28e
-		if (r1 != r1End)
5ec28e
-		    x1 = r1->x1;
5ec28e
-	    }
5ec28e
-	    else
5ec28e
-	    {
5ec28e
-		/*
5ec28e
-		 * Subtrahend used up
5ec28e
-		 */
5ec28e
-		r2++;
5ec28e
-	    }
5ec28e
-	}
5ec28e
-	else
5ec28e
-	{
5ec28e
-	    /*
5ec28e
-	     * Minuend used up: add any remaining piece before advancing.
5ec28e
-	     */
5ec28e
-	    if (r1->x2 > x1)
5ec28e
-	    {
5ec28e
-		MEMCHECK(pReg, pNextRect, pReg->rects);
5ec28e
-		pNextRect->x1 = x1;
5ec28e
-		pNextRect->y1 = y1;
5ec28e
-		pNextRect->x2 = r1->x2;
5ec28e
-		pNextRect->y2 = y2;
5ec28e
-		pReg->numRects += 1;
5ec28e
-		pNextRect++;
5ec28e
-		assert(pReg->numRects<=pReg->size);
5ec28e
-	    }
5ec28e
-	    r1++;
5ec28e
-	    if (r1 != r1End)
5ec28e
-		x1 = r1->x1;
5ec28e
-	}
5ec28e
-    }
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Add remaining minuend rectangles to region.
5ec28e
-     */
5ec28e
-    while (r1 != r1End)
5ec28e
-    {
5ec28e
-	assert(x1<r1->x2);
5ec28e
-	MEMCHECK(pReg, pNextRect, pReg->rects);
5ec28e
-	pNextRect->x1 = x1;
5ec28e
-	pNextRect->y1 = y1;
5ec28e
-	pNextRect->x2 = r1->x2;
5ec28e
-	pNextRect->y2 = y2;
5ec28e
-	pReg->numRects += 1;
5ec28e
-	pNextRect++;
5ec28e
-
5ec28e
-	assert(pReg->numRects<=pReg->size);
5ec28e
-
5ec28e
-	r1++;
5ec28e
-	if (r1 != r1End)
5ec28e
-	{
5ec28e
-	    x1 = r1->x1;
5ec28e
-	}
5ec28e
-    }
5ec28e
-    return 0;	/* lint */
5ec28e
-}
5ec28e
-
5ec28e
-/*-
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- * miSubtract --
5ec28e
- *	Subtract regS from regM and leave the result in regD.
5ec28e
- *	S stands for subtrahend, M for minuend and D for difference.
5ec28e
- *
5ec28e
- * Results:
5ec28e
- *	TRUE.
5ec28e
- *
5ec28e
- * Side Effects:
5ec28e
- *	regD is overwritten.
5ec28e
- *
5ec28e
- *-----------------------------------------------------------------------
5ec28e
- */
5ec28e
-
5ec28e
-int
5ec28e
-XSubtractRegion(
5ec28e
-    Region 	  	regM,
5ec28e
-    Region	  	regS,
5ec28e
-    register Region	regD)
5ec28e
-{
5ec28e
-   /* check for trivial reject */
5ec28e
-    if ( (!(regM->numRects)) || (!(regS->numRects))  ||
5ec28e
-	(!EXTENTCHECK(&regM->extents, &regS->extents)) )
5ec28e
-    {
5ec28e
-	return miRegionCopy(regD, regM);
5ec28e
-    }
5ec28e
-
5ec28e
-    miRegionOp (regD, regM, regS, miSubtractO,
5ec28e
-    		miSubtractNonO1, NULL);
5ec28e
-
5ec28e
-    /*
5ec28e
-     * Can't alter newReg's extents before we call miRegionOp because
5ec28e
-     * it might be one of the source regions and miRegionOp depends
5ec28e
-     * on the extents of those regions being the unaltered. Besides, this
5ec28e
-     * way there's no checking against rectangles that will be nuked
5ec28e
-     * due to coalescing, so we have to examine fewer rectangles.
5ec28e
-     */
5ec28e
-    miSetExtents (regD);
5ec28e
-    return 1;
5ec28e
-}
5ec28e
-
5ec28e
-int
5ec28e
-XXorRegion(Region sra, Region srb, Region dr)
5ec28e
-{
5ec28e
-    Region tra, trb;
5ec28e
-
5ec28e
-    if (! (tra = XCreateRegion()) )
5ec28e
-	return 0;
5ec28e
-    if (! (trb = XCreateRegion()) ) {
5ec28e
-	XDestroyRegion(tra);
5ec28e
-	return 0;
5ec28e
-    }
5ec28e
-    (void) XSubtractRegion(sra,srb,tra);
5ec28e
-    (void) XSubtractRegion(srb,sra,trb);
5ec28e
-    (void) XUnionRegion(tra,trb,dr);
5ec28e
-    XDestroyRegion(tra);
5ec28e
-    XDestroyRegion(trb);
5ec28e
-    return 0;
5ec28e
-}
5ec28e
-
5ec28e
-/*
5ec28e
- * Check to see if the region is empty.  Assumes a region is passed
5ec28e
- * as a parameter
5ec28e
- */
5ec28e
-int
5ec28e
-XEmptyRegion(
5ec28e
-    Region r)
5ec28e
-{
5ec28e
-    if( r->numRects == 0 ) return TRUE;
5ec28e
-    else  return FALSE;
5ec28e
-}
5ec28e
-
5ec28e
-/*
5ec28e
- *	Check to see if two regions are equal
5ec28e
- */
5ec28e
-int
5ec28e
-XEqualRegion(Region r1, Region r2)
5ec28e
-{
5ec28e
-    int i;
5ec28e
-
5ec28e
-    if( r1->numRects != r2->numRects ) return FALSE;
5ec28e
-    else if( r1->numRects == 0 ) return TRUE;
5ec28e
-    else if ( r1->extents.x1 != r2->extents.x1 ) return FALSE;
5ec28e
-    else if ( r1->extents.x2 != r2->extents.x2 ) return FALSE;
5ec28e
-    else if ( r1->extents.y1 != r2->extents.y1 ) return FALSE;
5ec28e
-    else if ( r1->extents.y2 != r2->extents.y2 ) return FALSE;
5ec28e
-    else for( i=0; i < r1->numRects; i++ ) {
5ec28e
-    	if ( r1->rects[i].x1 != r2->rects[i].x1 ) return FALSE;
5ec28e
-    	else if ( r1->rects[i].x2 != r2->rects[i].x2 ) return FALSE;
5ec28e
-    	else if ( r1->rects[i].y1 != r2->rects[i].y1 ) return FALSE;
5ec28e
-    	else if ( r1->rects[i].y2 != r2->rects[i].y2 ) return FALSE;
5ec28e
-    }
5ec28e
-    return TRUE;
5ec28e
-}
5ec28e
-
5ec28e
-int
5ec28e
-XPointInRegion(
5ec28e
-    Region pRegion,
5ec28e
-    int x, int y)
5ec28e
-{
5ec28e
-    int i;
5ec28e
-
5ec28e
-    if (pRegion->numRects == 0)
5ec28e
-        return FALSE;
5ec28e
-    if (!INBOX(pRegion->extents, x, y))
5ec28e
-        return FALSE;
5ec28e
-    for (i=0; i<pRegion->numRects; i++)
5ec28e
-    {
5ec28e
-        if (INBOX (pRegion->rects[i], x, y))
5ec28e
-	    return TRUE;
5ec28e
-    }
5ec28e
-    return FALSE;
5ec28e
-}
5ec28e
-
5ec28e
-int
5ec28e
-XRectInRegion(
5ec28e
-    register Region	region,
5ec28e
-    int rx, int ry,
5ec28e
-    unsigned int rwidth, unsigned int rheight)
5ec28e
-{
5ec28e
-    register BoxPtr pbox;
5ec28e
-    register BoxPtr pboxEnd;
5ec28e
-    Box rect;
5ec28e
-    register BoxPtr prect = ▭
5ec28e
-    int      partIn, partOut;
5ec28e
-
5ec28e
-    prect->x1 = rx;
5ec28e
-    prect->y1 = ry;
5ec28e
-    prect->x2 = rwidth + rx;
5ec28e
-    prect->y2 = rheight + ry;
5ec28e
-
5ec28e
-    /* this is (just) a useful optimization */
5ec28e
-    if ((region->numRects == 0) || !EXTENTCHECK(&region->extents, prect))
5ec28e
-        return(RectangleOut);
5ec28e
-
5ec28e
-    partOut = FALSE;
5ec28e
-    partIn = FALSE;
5ec28e
-
5ec28e
-    /* can stop when both partOut and partIn are TRUE, or we reach prect->y2 */
5ec28e
-    for (pbox = region->rects, pboxEnd = pbox + region->numRects;
5ec28e
-	 pbox < pboxEnd;
5ec28e
-	 pbox++)
5ec28e
-    {
5ec28e
-
5ec28e
-	if (pbox->y2 <= ry)
5ec28e
-	   continue;	/* getting up to speed or skipping remainder of band */
5ec28e
-
5ec28e
-	if (pbox->y1 > ry)
5ec28e
-	{
5ec28e
-	   partOut = TRUE;	/* missed part of rectangle above */
5ec28e
-	   if (partIn || (pbox->y1 >= prect->y2))
5ec28e
-	      break;
5ec28e
-	   ry = pbox->y1;	/* x guaranteed to be == prect->x1 */
5ec28e
-	}
5ec28e
-
5ec28e
-	if (pbox->x2 <= rx)
5ec28e
-	   continue;		/* not far enough over yet */
5ec28e
-
5ec28e
-	if (pbox->x1 > rx)
5ec28e
-	{
5ec28e
-	   partOut = TRUE;	/* missed part of rectangle to left */
5ec28e
-	   if (partIn)
5ec28e
-	      break;
5ec28e
-	}
5ec28e
-
5ec28e
-	if (pbox->x1 < prect->x2)
5ec28e
-	{
5ec28e
-	    partIn = TRUE;	/* definitely overlap */
5ec28e
-	    if (partOut)
5ec28e
-	       break;
5ec28e
-	}
5ec28e
-
5ec28e
-	if (pbox->x2 >= prect->x2)
5ec28e
-	{
5ec28e
-	   ry = pbox->y2;	/* finished with this band */
5ec28e
-	   if (ry >= prect->y2)
5ec28e
-	      break;
5ec28e
-	   rx = prect->x1;	/* reset x out to left again */
5ec28e
-	} else
5ec28e
-	{
5ec28e
-	    /*
5ec28e
-	     * Because boxes in a band are maximal width, if the first box
5ec28e
-	     * to overlap the rectangle doesn't completely cover it in that
5ec28e
-	     * band, the rectangle must be partially out, since some of it
5ec28e
-	     * will be uncovered in that band. partIn will have been set true
5ec28e
-	     * by now...
5ec28e
-	     */
5ec28e
-	    break;
5ec28e
-	}
5ec28e
-
5ec28e
-    }
5ec28e
-
5ec28e
-    return(partIn ? ((ry < prect->y2) ? RectanglePart : RectangleIn) :
5ec28e
-		RectangleOut);
5ec28e
-}
5ec28e
diff --git a/common/Xregion/Xlib.h b/common/Xregion/Xlib.h
5ec28e
deleted file mode 100644
5ec28e
index ba6f281..0000000
5ec28e
--- a/common/Xregion/Xlib.h
5ec28e
+++ /dev/null
5ec28e
@@ -1,50 +0,0 @@
5ec28e
-/*
5ec28e
-
5ec28e
-Copyright 1985, 1986, 1987, 1991, 1998  The Open Group
5ec28e
-
5ec28e
-Permission to use, copy, modify, distribute, and sell this software and its
5ec28e
-documentation for any purpose is hereby granted without fee, provided that
5ec28e
-the above copyright notice appear in all copies and that both that
5ec28e
-copyright notice and this permission notice appear in supporting
5ec28e
-documentation.
5ec28e
-
5ec28e
-The above copyright notice and this permission notice shall be included in
5ec28e
-all copies or substantial portions of the Software.
5ec28e
-
5ec28e
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5ec28e
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5ec28e
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
5ec28e
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
5ec28e
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
5ec28e
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5ec28e
-
5ec28e
-Except as contained in this notice, the name of The Open Group shall not be
5ec28e
-used in advertising or otherwise to promote the sale, use or other dealings
5ec28e
-in this Software without prior written authorization from The Open Group.
5ec28e
-
5ec28e
-*/
5ec28e
-
5ec28e
-
5ec28e
-/*
5ec28e
- *	Xlib.h - Header definition and support file for the C subroutine
5ec28e
- *	interface library (Xlib) to the X Window System Protocol (V11).
5ec28e
- *	Structures and symbols starting with "_" are private to the library.
5ec28e
- */
5ec28e
-#ifndef _X11_XLIB_H_
5ec28e
-#define _X11_XLIB_H_
5ec28e
-
5ec28e
-#define NeedFunctionPrototypes 1
5ec28e
-
5ec28e
-#define Bool int
5ec28e
-
5ec28e
-typedef struct {
5ec28e
-    short x, y;
5ec28e
-} XPoint;
5ec28e
-
5ec28e
-typedef struct {
5ec28e
-    short x, y;
5ec28e
-    unsigned short width, height;
5ec28e
-} XRectangle;
5ec28e
-
5ec28e
-
5ec28e
-#endif /* _X11_XLIB_H_ */
5ec28e
diff --git a/common/Xregion/Xlibint.h b/common/Xregion/Xlibint.h
5ec28e
deleted file mode 100644
5ec28e
index 9b9ae28..0000000
5ec28e
--- a/common/Xregion/Xlibint.h
5ec28e
+++ /dev/null
5ec28e
@@ -1,48 +0,0 @@
5ec28e
-
5ec28e
-/*
5ec28e
-
5ec28e
-Copyright 1984, 1985, 1987, 1989, 1998  The Open Group
5ec28e
-
5ec28e
-Permission to use, copy, modify, distribute, and sell this software and its
5ec28e
-documentation for any purpose is hereby granted without fee, provided that
5ec28e
-the above copyright notice appear in all copies and that both that
5ec28e
-copyright notice and this permission notice appear in supporting
5ec28e
-documentation.
5ec28e
-
5ec28e
-The above copyright notice and this permission notice shall be included
5ec28e
-in all copies or substantial portions of the Software.
5ec28e
-
5ec28e
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5ec28e
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5ec28e
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
5ec28e
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
5ec28e
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
5ec28e
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
5ec28e
-OTHER DEALINGS IN THE SOFTWARE.
5ec28e
-
5ec28e
-Except as contained in this notice, the name of The Open Group shall
5ec28e
-not be used in advertising or otherwise to promote the sale, use or
5ec28e
-other dealings in this Software without prior written authorization
5ec28e
-from The Open Group.
5ec28e
-
5ec28e
-*/
5ec28e
-
5ec28e
-#ifndef _X11_XLIBINT_H_
5ec28e
-#define _X11_XLIBINT_H_ 1
5ec28e
-
5ec28e
-/*
5ec28e
- *	Xlibint.h - Header definition and support file for the internal
5ec28e
- *	support routines used by the C subroutine interface
5ec28e
- *	library (Xlib) to the X Window System.
5ec28e
- *
5ec28e
- *	Warning, there be dragons here....
5ec28e
- */
5ec28e
-
5ec28e
-#include <stdlib.h>
5ec28e
-
5ec28e
-#define Xfree(ptr) free((ptr))
5ec28e
-#define Xmalloc(size) malloc((size))
5ec28e
-#define Xrealloc(ptr, size) realloc((ptr), (size))
5ec28e
-#define Xcalloc(nelem, elsize) calloc((nelem), (elsize))
5ec28e
-
5ec28e
-#endif /* _X11_XLIBINT_H_ */
5ec28e
diff --git a/common/Xregion/Xregion.h b/common/Xregion/Xregion.h
5ec28e
deleted file mode 100644
5ec28e
index cf10f86..0000000
5ec28e
--- a/common/Xregion/Xregion.h
5ec28e
+++ /dev/null
5ec28e
@@ -1,190 +0,0 @@
5ec28e
-/************************************************************************
5ec28e
-
5ec28e
-Copyright 1987, 1998  The Open Group
5ec28e
-
5ec28e
-Permission to use, copy, modify, distribute, and sell this software and its
5ec28e
-documentation for any purpose is hereby granted without fee, provided that
5ec28e
-the above copyright notice appear in all copies and that both that
5ec28e
-copyright notice and this permission notice appear in supporting
5ec28e
-documentation.
5ec28e
-
5ec28e
-The above copyright notice and this permission notice shall be included in
5ec28e
-all copies or substantial portions of the Software.
5ec28e
-
5ec28e
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5ec28e
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5ec28e
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
5ec28e
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
5ec28e
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
5ec28e
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5ec28e
-
5ec28e
-Except as contained in this notice, the name of The Open Group shall not be
5ec28e
-used in advertising or otherwise to promote the sale, use or other dealings
5ec28e
-in this Software without prior written authorization from The Open Group.
5ec28e
-
5ec28e
-
5ec28e
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
5ec28e
-
5ec28e
-                        All Rights Reserved
5ec28e
-
5ec28e
-Permission to use, copy, modify, and distribute this software and its
5ec28e
-documentation for any purpose and without fee is hereby granted,
5ec28e
-provided that the above copyright notice appear in all copies and that
5ec28e
-both that copyright notice and this permission notice appear in
5ec28e
-supporting documentation, and that the name of Digital not be
5ec28e
-used in advertising or publicity pertaining to distribution of the
5ec28e
-software without specific, written prior permission.
5ec28e
-
5ec28e
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
5ec28e
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
5ec28e
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
5ec28e
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
5ec28e
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
5ec28e
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5ec28e
-SOFTWARE.
5ec28e
-
5ec28e
-************************************************************************/
5ec28e
-
5ec28e
-#ifndef _X11_XREGION_H_
5ec28e
-#define _X11_XREGION_H_
5ec28e
-
5ec28e
-typedef struct {
5ec28e
-    short x1, x2, y1, y2;
5ec28e
-} Box, BOX, BoxRec, *BoxPtr;
5ec28e
-
5ec28e
-typedef struct {
5ec28e
-    short x, y, width, height;
5ec28e
-}RECTANGLE, RectangleRec, *RectanglePtr;
5ec28e
-
5ec28e
-#define TRUE 1
5ec28e
-#define FALSE 0
5ec28e
-#define MAXSHORT 32767
5ec28e
-#define MINSHORT -MAXSHORT
5ec28e
-#ifndef MAX
5ec28e
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
5ec28e
-#endif
5ec28e
-#ifndef MIN
5ec28e
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
5ec28e
-#endif
5ec28e
-
5ec28e
-
5ec28e
-/*
5ec28e
- *   clip region
5ec28e
- */
5ec28e
-
5ec28e
-typedef struct _XRegion {
5ec28e
-    long size;
5ec28e
-    long numRects;
5ec28e
-    BOX *rects;
5ec28e
-    BOX extents;
5ec28e
-} REGION;
5ec28e
-
5ec28e
-/* Xutil.h contains the declaration:
5ec28e
- * typedef struct _XRegion *Region;
5ec28e
- */
5ec28e
-
5ec28e
-/*  1 if two BOXs overlap.
5ec28e
- *  0 if two BOXs do not overlap.
5ec28e
- *  Remember, x2 and y2 are not in the region
5ec28e
- */
5ec28e
-#define EXTENTCHECK(r1, r2) \
5ec28e
-	((r1)->x2 > (r2)->x1 && \
5ec28e
-	 (r1)->x1 < (r2)->x2 && \
5ec28e
-	 (r1)->y2 > (r2)->y1 && \
5ec28e
-	 (r1)->y1 < (r2)->y2)
5ec28e
-
5ec28e
-/*
5ec28e
- *  update region extents
5ec28e
- */
5ec28e
-#define EXTENTS(r,idRect){\
5ec28e
-            if((r)->x1 < (idRect)->extents.x1)\
5ec28e
-              (idRect)->extents.x1 = (r)->x1;\
5ec28e
-            if((r)->y1 < (idRect)->extents.y1)\
5ec28e
-              (idRect)->extents.y1 = (r)->y1;\
5ec28e
-            if((r)->x2 > (idRect)->extents.x2)\
5ec28e
-              (idRect)->extents.x2 = (r)->x2;\
5ec28e
-            if((r)->y2 > (idRect)->extents.y2)\
5ec28e
-              (idRect)->extents.y2 = (r)->y2;\
5ec28e
-        }
5ec28e
-
5ec28e
-/*
5ec28e
- *   Check to see if there is enough memory in the present region.
5ec28e
- */
5ec28e
-#define MEMCHECK(reg, rect, firstrect){\
5ec28e
-        if ((reg)->numRects >= ((reg)->size - 1)){\
5ec28e
-          BoxPtr tmpRect = Xrealloc ((firstrect), \
5ec28e
-                                     (2 * (sizeof(BOX)) * ((reg)->size))); \
5ec28e
-          if (tmpRect == NULL) \
5ec28e
-            return(0);\
5ec28e
-          (firstrect) = tmpRect; \
5ec28e
-          (reg)->size *= 2;\
5ec28e
-          (rect) = &(firstrect)[(reg)->numRects];\
5ec28e
-         }\
5ec28e
-       }
5ec28e
-
5ec28e
-/*  this routine checks to see if the previous rectangle is the same
5ec28e
- *  or subsumes the new rectangle to add.
5ec28e
- */
5ec28e
-
5ec28e
-#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
5ec28e
-               (!(((Reg)->numRects > 0)&&\
5ec28e
-                  ((R-1)->y1 == (Ry1)) &&\
5ec28e
-                  ((R-1)->y2 == (Ry2)) &&\
5ec28e
-                  ((R-1)->x1 <= (Rx1)) &&\
5ec28e
-                  ((R-1)->x2 >= (Rx2))))
5ec28e
-
5ec28e
-/*  add a rectangle to the given Region */
5ec28e
-#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
5ec28e
-    if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
5ec28e
-        CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
5ec28e
-              (r)->x1 = (rx1);\
5ec28e
-              (r)->y1 = (ry1);\
5ec28e
-              (r)->x2 = (rx2);\
5ec28e
-              (r)->y2 = (ry2);\
5ec28e
-              EXTENTS((r), (reg));\
5ec28e
-              (reg)->numRects++;\
5ec28e
-              (r)++;\
5ec28e
-            }\
5ec28e
-        }
5ec28e
-
5ec28e
-
5ec28e
-
5ec28e
-/*  add a rectangle to the given Region */
5ec28e
-#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
5ec28e
-            if ((rx1 < rx2) && (ry1 < ry2) &&\
5ec28e
-                CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
5ec28e
-              (r)->x1 = (rx1);\
5ec28e
-              (r)->y1 = (ry1);\
5ec28e
-              (r)->x2 = (rx2);\
5ec28e
-              (r)->y2 = (ry2);\
5ec28e
-              (reg)->numRects++;\
5ec28e
-              (r)++;\
5ec28e
-            }\
5ec28e
-        }
5ec28e
-
5ec28e
-#define EMPTY_REGION(pReg) pReg->numRects = 0
5ec28e
-
5ec28e
-#define REGION_NOT_EMPTY(pReg) pReg->numRects
5ec28e
-
5ec28e
-#define INBOX(r, x, y) \
5ec28e
-      ( ( ((r).x2 >  x)) && \
5ec28e
-        ( ((r).x1 <= x)) && \
5ec28e
-        ( ((r).y2 >  y)) && \
5ec28e
-        ( ((r).y1 <= y)) )
5ec28e
-
5ec28e
-/*
5ec28e
- * number of points to buffer before sending them off
5ec28e
- * to scanlines() :  Must be an even number
5ec28e
- */
5ec28e
-#define NUMPTSTOBUFFER 200
5ec28e
-
5ec28e
-/*
5ec28e
- * used to allocate buffers for points and link
5ec28e
- * the buffers together
5ec28e
- */
5ec28e
-typedef struct _POINTBLOCK {
5ec28e
-    XPoint pts[NUMPTSTOBUFFER];
5ec28e
-    struct _POINTBLOCK *next;
5ec28e
-} POINTBLOCK;
5ec28e
-
5ec28e
-#endif /* _X11_XREGION_H_ */
5ec28e
diff --git a/common/Xregion/Xutil.h b/common/Xregion/Xutil.h
5ec28e
deleted file mode 100644
5ec28e
index 4da56a5..0000000
5ec28e
--- a/common/Xregion/Xutil.h
5ec28e
+++ /dev/null
5ec28e
@@ -1,167 +0,0 @@
5ec28e
-
5ec28e
-/***********************************************************
5ec28e
-
5ec28e
-Copyright 1987, 1998  The Open Group
5ec28e
-
5ec28e
-Permission to use, copy, modify, distribute, and sell this software and its
5ec28e
-documentation for any purpose is hereby granted without fee, provided that
5ec28e
-the above copyright notice appear in all copies and that both that
5ec28e
-copyright notice and this permission notice appear in supporting
5ec28e
-documentation.
5ec28e
-
5ec28e
-The above copyright notice and this permission notice shall be included in
5ec28e
-all copies or substantial portions of the Software.
5ec28e
-
5ec28e
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5ec28e
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5ec28e
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
5ec28e
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
5ec28e
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
5ec28e
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5ec28e
-
5ec28e
-Except as contained in this notice, the name of The Open Group shall not be
5ec28e
-used in advertising or otherwise to promote the sale, use or other dealings
5ec28e
-in this Software without prior written authorization from The Open Group.
5ec28e
-
5ec28e
-
5ec28e
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
5ec28e
-
5ec28e
-                        All Rights Reserved
5ec28e
-
5ec28e
-Permission to use, copy, modify, and distribute this software and its
5ec28e
-documentation for any purpose and without fee is hereby granted,
5ec28e
-provided that the above copyright notice appear in all copies and that
5ec28e
-both that copyright notice and this permission notice appear in
5ec28e
-supporting documentation, and that the name of Digital not be
5ec28e
-used in advertising or publicity pertaining to distribution of the
5ec28e
-software without specific, written prior permission.
5ec28e
-
5ec28e
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
5ec28e
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
5ec28e
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
5ec28e
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
5ec28e
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
5ec28e
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5ec28e
-SOFTWARE.
5ec28e
-
5ec28e
-******************************************************************/
5ec28e
-
5ec28e
-#ifndef _X11_XUTIL_H_
5ec28e
-#define _X11_XUTIL_H_
5ec28e
-
5ec28e
-/* You must include <X11/Xlib.h> before including this file */
5ec28e
-#include "Xlib.h"
5ec28e
-
5ec28e
-/****** Avoid symbol clash with "real" libX11 ******/
5ec28e
-#define XClipBox vncXClipBox
5ec28e
-#define XCreateRegion vncXCreateRegion
5ec28e
-#define XDestroyRegion vncXDestroyRegion
5ec28e
-#define XEmptyRegion vncXEmptyRegion
5ec28e
-#define XEqualRegion vncXEqualRegion
5ec28e
-#define XIntersectRegion vncXIntersectRegion
5ec28e
-#define XOffsetRegion vncXOffsetRegion
5ec28e
-#define XPointInRegion vncXPointInRegion
5ec28e
-#define XPolygonRegion vncXPolygonRegion
5ec28e
-#define XRectInRegion vncXRectInRegion
5ec28e
-#define XShrinkRegion vncXShrinkRegion
5ec28e
-#define XSubtractRegion vncXSubtractRegion
5ec28e
-#define XUnionRectWithRegion vncXUnionRectWithRegion
5ec28e
-#define XUnionRegion vncXUnionRegion
5ec28e
-#define XXorRegion vncXXorRegion
5ec28e
-
5ec28e
-/*
5ec28e
- * opaque reference to Region data type
5ec28e
- */
5ec28e
-typedef struct _XRegion *Region;
5ec28e
-
5ec28e
-/* Return values from XRectInRegion() */
5ec28e
-
5ec28e
-#define RectangleOut 0
5ec28e
-#define RectangleIn  1
5ec28e
-#define RectanglePart 2
5ec28e
-
5ec28e
-extern int XClipBox(
5ec28e
-    Region		/* r */,
5ec28e
-    XRectangle*		/* rect_return */
5ec28e
-);
5ec28e
-
5ec28e
-extern Region XCreateRegion(
5ec28e
-    void
5ec28e
-);
5ec28e
-
5ec28e
-extern int XDestroyRegion(
5ec28e
-    Region		/* r */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XEmptyRegion(
5ec28e
-    Region		/* r */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XEqualRegion(
5ec28e
-    Region		/* r1 */,
5ec28e
-    Region		/* r2 */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XIntersectRegion(
5ec28e
-    Region		/* sra */,
5ec28e
-    Region		/* srb */,
5ec28e
-    Region		/* dr_return */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XOffsetRegion(
5ec28e
-    Region		/* r */,
5ec28e
-    int			/* dx */,
5ec28e
-    int			/* dy */
5ec28e
-);
5ec28e
-
5ec28e
-extern Bool XPointInRegion(
5ec28e
-    Region		/* r */,
5ec28e
-    int			/* x */,
5ec28e
-    int			/* y */
5ec28e
-);
5ec28e
-
5ec28e
-extern Region XPolygonRegion(
5ec28e
-    XPoint*		/* points */,
5ec28e
-    int			/* n */,
5ec28e
-    int			/* fill_rule */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XRectInRegion(
5ec28e
-    Region		/* r */,
5ec28e
-    int			/* x */,
5ec28e
-    int			/* y */,
5ec28e
-    unsigned int	/* width */,
5ec28e
-    unsigned int	/* height */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XShrinkRegion(
5ec28e
-    Region		/* r */,
5ec28e
-    int			/* dx */,
5ec28e
-    int			/* dy */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XSubtractRegion(
5ec28e
-    Region		/* sra */,
5ec28e
-    Region		/* srb */,
5ec28e
-    Region		/* dr_return */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XUnionRectWithRegion(
5ec28e
-    XRectangle*		/* rectangle */,
5ec28e
-    Region		/* src_region */,
5ec28e
-    Region		/* dest_region_return */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XUnionRegion(
5ec28e
-    Region		/* sra */,
5ec28e
-    Region		/* srb */,
5ec28e
-    Region		/* dr_return */
5ec28e
-);
5ec28e
-
5ec28e
-extern int XXorRegion(
5ec28e
-    Region		/* sra */,
5ec28e
-    Region		/* srb */,
5ec28e
-    Region		/* dr_return */
5ec28e
-);
5ec28e
-
5ec28e
-#endif /* _X11_XUTIL_H_ */
5ec28e
diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt
5ec28e
index 5047e5e..ecfcb03 100644
5ec28e
--- a/common/rfb/CMakeLists.txt
5ec28e
+++ b/common/rfb/CMakeLists.txt
5ec28e
@@ -1,4 +1,4 @@
5ec28e
-include_directories(${CMAKE_SOURCE_DIR}/common ${JPEG_INCLUDE_DIR})
5ec28e
+include_directories(${CMAKE_SOURCE_DIR}/common ${JPEG_INCLUDE_DIR} ${PIXMAN_INCLUDE_DIR})
5ec28e
 
5ec28e
 set(RFB_SOURCES
5ec28e
   Blacklist.cxx
5ec28e
@@ -72,7 +72,7 @@ if(WIN32)
5ec28e
   set(RFB_SOURCES ${RFB_SOURCES} WinPasswdValidator.cxx)
5ec28e
 endif(WIN32)
5ec28e
 
5ec28e
-set(RFB_LIBRARIES ${JPEG_LIBRARIES} os rdr Xregion)
5ec28e
+set(RFB_LIBRARIES ${JPEG_LIBRARIES} ${PIXMAN_LIBRARY} os rdr)
5ec28e
 
5ec28e
 if(HAVE_PAM)
5ec28e
   set(RFB_SOURCES ${RFB_SOURCES} UnixPasswordValidator.cxx
5ec28e
diff --git a/common/rfb/ComparingUpdateTracker.cxx b/common/rfb/ComparingUpdateTracker.cxx
5ec28e
index 237adc4..d565120 100644
5ec28e
--- a/common/rfb/ComparingUpdateTracker.cxx
5ec28e
+++ b/common/rfb/ComparingUpdateTracker.cxx
5ec28e
@@ -120,8 +120,6 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged)
5ec28e
   rdr::U8* oldData = oldFb.getBufferRW(r, &oldStride);
5ec28e
   int oldStrideBytes = oldStride * bytesPerPixel;
5ec28e
 
5ec28e
-  std::vector<Rect> changedBlocks;
5ec28e
-
5ec28e
   for (int blockTop = r.tl.y; blockTop < r.br.y; blockTop += BLOCK_SIZE)
5ec28e
   {
5ec28e
     // Get a strip of the source buffer
5ec28e
@@ -146,8 +144,8 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged)
5ec28e
         if (memcmp(oldPtr, newPtr, blockWidthInBytes) != 0)
5ec28e
         {
5ec28e
           // A block has changed - copy the remainder to the oldFb
5ec28e
-          changedBlocks.push_back(Rect(blockLeft, blockTop,
5ec28e
-                                       blockRight, blockBottom));
5ec28e
+          newChanged->assign_union(Region(Rect(blockLeft, blockTop,
5ec28e
+                                               blockRight, blockBottom)));
5ec28e
           for (int y2 = y; y2 < blockBottom; y2++)
5ec28e
           {
5ec28e
             memcpy(oldPtr, newPtr, blockWidthInBytes);
5ec28e
@@ -169,12 +167,6 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged)
5ec28e
   }
5ec28e
 
5ec28e
   oldFb.commitBufferRW(r);
5ec28e
-
5ec28e
-  if (!changedBlocks.empty()) {
5ec28e
-    Region temp;
5ec28e
-    temp.setOrderedRects(changedBlocks);
5ec28e
-    newChanged->assign_union(temp);
5ec28e
-  }
5ec28e
 }
5ec28e
 
5ec28e
 void ComparingUpdateTracker::logStats()
5ec28e
diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx
5ec28e
index 0cd5206..6a153a8 100644
5ec28e
--- a/common/rfb/EncodeManager.cxx
5ec28e
+++ b/common/rfb/EncodeManager.cxx
5ec28e
@@ -273,7 +273,7 @@ void EncodeManager::writeUpdate(const UpdateInfo& ui, const PixelBuffer* pb,
5ec28e
      * We start by searching for solid rects, which are then removed
5ec28e
      * from the changed region.
5ec28e
      */
5ec28e
-    changed.copyFrom(ui.changed);
5ec28e
+    changed = ui.changed;
5ec28e
 
5ec28e
     if (conn->cp.supportsLastRect)
5ec28e
       writeSolidRects(&changed, pb);
5ec28e
diff --git a/common/rfb/Region.cxx b/common/rfb/Region.cxx
5ec28e
index 995f8c5..2b5d0cf 100644
5ec28e
--- a/common/rfb/Region.cxx
5ec28e
+++ b/common/rfb/Region.cxx
5ec28e
@@ -1,4 +1,5 @@
5ec28e
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
5ec28e
+ * Copyright 2016-2020 Pierre Ossman for Cendio AB
5ec28e
  * 
5ec28e
  * This is free software; you can redistribute it and/or modify
5ec28e
  * it under the terms of the GNU General Public License as published by
5ec28e
@@ -16,190 +17,110 @@
5ec28e
  * USA.
5ec28e
  */
5ec28e
 
5ec28e
-// Cross-platform Region class based on the X11 region implementation.  Note
5ec28e
-// that for efficiency this code manipulates the Xlib region structure
5ec28e
-// directly.  Apart from the layout of the structure, there is one other key
5ec28e
-// assumption made: a Region returned from XCreateRegion must always have its
5ec28e
-// rects member allocated so that there is space for at least one rectangle.
5ec28e
-//
5ec28e
-
5ec28e
 #include <rfb/Region.h>
5ec28e
-#include <assert.h>
5ec28e
-#include <stdio.h>
5ec28e
 
5ec28e
 extern "C" {
5ec28e
-#include <Xregion/Xlibint.h>
5ec28e
-#include <Xregion/Xutil.h>
5ec28e
-#include <Xregion/Xregion.h>
5ec28e
-}
5ec28e
-
5ec28e
-// A _RectRegion must never be passed as a return parameter to the Xlib region
5ec28e
-// operations.  This is because for efficiency its "rects" member has not been
5ec28e
-// allocated with Xmalloc.  It is however safe to pass it as an input
5ec28e
-// parameter.
5ec28e
-
5ec28e
-class _RectRegion {
5ec28e
-public:
5ec28e
-  _RectRegion(const rfb::Rect& r) {
5ec28e
-    region.rects = &region.extents;
5ec28e
-    region.numRects = 1;
5ec28e
-    region.extents.x1 = r.tl.x;
5ec28e
-    region.extents.y1 = r.tl.y;
5ec28e
-    region.extents.x2 = r.br.x;
5ec28e
-    region.extents.y2 = r.br.y;
5ec28e
-    region.size = 1;
5ec28e
-    if (r.is_empty())
5ec28e
-      region.numRects = 0;
5ec28e
-  }
5ec28e
-  REGION region;
5ec28e
-};
5ec28e
-
5ec28e
+#include <pixman.h>
5ec28e
+#include <stdio.h>
5ec28e
+}
5ec28e
 
5ec28e
 rfb::Region::Region() {
5ec28e
-  xrgn = XCreateRegion();
5ec28e
-  assert(xrgn);
5ec28e
+  rgn = new struct pixman_region16;
5ec28e
+  pixman_region_init(rgn);
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Region::Region(const Rect& r) {
5ec28e
-  xrgn = XCreateRegion();
5ec28e
-  assert(xrgn);
5ec28e
-  reset(r);
5ec28e
+  rgn = new struct pixman_region16;
5ec28e
+  pixman_region_init_rect(rgn, r.tl.x, r.tl.y, r.width(), r.height());
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Region::Region(const rfb::Region& r) {
5ec28e
-  xrgn = XCreateRegion();
5ec28e
-  assert(xrgn);
5ec28e
-  XUnionRegion(xrgn, r.xrgn, xrgn);
5ec28e
+  rgn = new struct pixman_region16;
5ec28e
+  pixman_region_init(rgn);
5ec28e
+  pixman_region_copy(rgn, r.rgn);
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Region::~Region() {
5ec28e
-  XDestroyRegion(xrgn);
5ec28e
+  pixman_region_fini(rgn);
5ec28e
+  delete rgn;
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Region& rfb::Region::operator=(const rfb::Region& r) {
5ec28e
-  clear();
5ec28e
-  XUnionRegion(xrgn, r.xrgn, xrgn);
5ec28e
+  pixman_region_copy(rgn, r.rgn);
5ec28e
   return *this;
5ec28e
 }
5ec28e
 
5ec28e
 void rfb::Region::clear() {
5ec28e
-  xrgn->numRects = 0;
5ec28e
-  xrgn->extents.x1 = 0;
5ec28e
-  xrgn->extents.y1 = 0;
5ec28e
-  xrgn->extents.x2 = 0;
5ec28e
-  xrgn->extents.y2 = 0;
5ec28e
+  // pixman_region_clear() isn't available on some older systems
5ec28e
+  pixman_region_fini(rgn);
5ec28e
+  pixman_region_init(rgn);
5ec28e
 }
5ec28e
 
5ec28e
 void rfb::Region::reset(const Rect& r) {
5ec28e
-  if (r.is_empty()) {
5ec28e
-    clear();
5ec28e
-  } else {
5ec28e
-    xrgn->numRects = 1;
5ec28e
-    xrgn->rects[0].x1 = xrgn->extents.x1 = r.tl.x;
5ec28e
-    xrgn->rects[0].y1 = xrgn->extents.y1 = r.tl.y;
5ec28e
-    xrgn->rects[0].x2 = xrgn->extents.x2 = r.br.x;
5ec28e
-    xrgn->rects[0].y2 = xrgn->extents.y2 = r.br.y;
5ec28e
-  }
5ec28e
+  pixman_region_fini(rgn);
5ec28e
+  pixman_region_init_rect(rgn, r.tl.x, r.tl.y, r.width(), r.height());
5ec28e
 }
5ec28e
 
5ec28e
 void rfb::Region::translate(const Point& delta) {
5ec28e
-  XOffsetRegion(xrgn, delta.x, delta.y);
5ec28e
-}
5ec28e
-
5ec28e
-void rfb::Region::setOrderedRects(const std::vector<Rect>& rects) {
5ec28e
-  clear();
5ec28e
-  std::vector<Rect>::const_iterator i;
5ec28e
-  for (i=rects.begin(); i != rects.end(); i++) {
5ec28e
-    _RectRegion rr(*i);
5ec28e
-    XUnionRegion(xrgn, &rr.region, xrgn);
5ec28e
-  }
5ec28e
-}
5ec28e
-
5ec28e
-void rfb::Region::setExtentsAndOrderedRects(const ShortRect* extents,
5ec28e
-                                            int nRects, const ShortRect* rects)
5ec28e
-{
5ec28e
-  if (xrgn->size < nRects)
5ec28e
-  {
5ec28e
-    BOX* prevRects = xrgn->rects;
5ec28e
-    xrgn->rects = (BOX*)Xrealloc((char*)xrgn->rects, nRects * sizeof(BOX));
5ec28e
-    if (!xrgn->rects) {
5ec28e
-      fprintf(stderr,"Xrealloc failed\n");
5ec28e
-      Xfree(prevRects);
5ec28e
-      return;
5ec28e
-    }
5ec28e
-    xrgn->size = nRects;
5ec28e
-  }
5ec28e
-
5ec28e
-  xrgn->numRects = nRects;
5ec28e
-  xrgn->extents.x1 = extents->x1;
5ec28e
-  xrgn->extents.y1 = extents->y1;
5ec28e
-  xrgn->extents.x2 = extents->x2;
5ec28e
-  xrgn->extents.y2 = extents->y2;
5ec28e
-  for (int i = 0; i < nRects; i++) {
5ec28e
-    xrgn->rects[i].x1 = rects[i].x1;
5ec28e
-    xrgn->rects[i].y1 = rects[i].y1;
5ec28e
-    xrgn->rects[i].x2 = rects[i].x2;
5ec28e
-    xrgn->rects[i].y2 = rects[i].y2;
5ec28e
-  }
5ec28e
-}
5ec28e
-
5ec28e
-void rfb::Region::copyFrom(const rfb::Region& r) {
5ec28e
-  XUnionRegion(r.xrgn, r.xrgn, xrgn);
5ec28e
+  pixman_region_translate(rgn, delta.x, delta.y);
5ec28e
 }
5ec28e
 
5ec28e
 void rfb::Region::assign_intersect(const rfb::Region& r) {
5ec28e
-  XIntersectRegion(xrgn, r.xrgn, xrgn);
5ec28e
+  pixman_region_intersect(rgn, rgn, r.rgn);
5ec28e
 }
5ec28e
 
5ec28e
 void rfb::Region::assign_union(const rfb::Region& r) {
5ec28e
-  XUnionRegion(xrgn, r.xrgn, xrgn);
5ec28e
+  pixman_region_union(rgn, rgn, r.rgn);
5ec28e
 }
5ec28e
 
5ec28e
 void rfb::Region::assign_subtract(const rfb::Region& r) {
5ec28e
-  XSubtractRegion(xrgn, r.xrgn, xrgn);
5ec28e
++  pixman_region_subtract(rgn, rgn, r.rgn);
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Region rfb::Region::intersect(const rfb::Region& r) const {
5ec28e
   rfb::Region ret;
5ec28e
-  XIntersectRegion(xrgn, r.xrgn, ret.xrgn);
5ec28e
+  pixman_region_intersect(ret.rgn, rgn, r.rgn);
5ec28e
   return ret;
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Region rfb::Region::union_(const rfb::Region& r) const {
5ec28e
   rfb::Region ret;
5ec28e
-  XUnionRegion(xrgn, r.xrgn, ret.xrgn);
5ec28e
+  pixman_region_union(ret.rgn, rgn, r.rgn);
5ec28e
   return ret;
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Region rfb::Region::subtract(const rfb::Region& r) const {
5ec28e
   rfb::Region ret;
5ec28e
-  XSubtractRegion(xrgn, r.xrgn, ret.xrgn);
5ec28e
+  pixman_region_subtract(ret.rgn, rgn, r.rgn);
5ec28e
   return ret;
5ec28e
 }
5ec28e
 
5ec28e
 bool rfb::Region::equals(const rfb::Region& r) const {
5ec28e
-  return XEqualRegion(xrgn, r.xrgn);
5ec28e
+  return pixman_region_equal(rgn, r.rgn);
5ec28e
 }
5ec28e
 
5ec28e
 int rfb::Region::numRects() const {
5ec28e
-  return xrgn->numRects;
5ec28e
+  return pixman_region_n_rects(rgn);
5ec28e
 }
5ec28e
 
5ec28e
 bool rfb::Region::get_rects(std::vector<Rect>* rects,
5ec28e
                             bool left2right, bool topdown, int maxArea) const
5ec28e
 {
5ec28e
-  int nRects = xrgn->numRects;
5ec28e
-  int xInc = left2right ? 1 : -1;
5ec28e
-  int yInc = topdown ? 1 : -1;
5ec28e
-  int i = topdown ? 0 : nRects-1;
5ec28e
-  rects->clear();
5ec28e
-  rects->reserve(nRects);
5ec28e
+  int nRects;
5ec28e
+  const pixman_box16_t* boxes;
5ec28e
+  int xInc, yInc, i;
5ec28e
+
5ec28e
+  boxes = pixman_region_rectangles(rgn, &nRects);
5ec28e
+
5ec28e
+  xInc = left2right ? 1 : -1;
5ec28e
+  yInc = topdown ? 1 : -1;
5ec28e
+  i = topdown ? 0 : nRects-1;
5ec28e
 
5ec28e
   while (nRects > 0) {
5ec28e
     int firstInNextBand = i;
5ec28e
     int nRectsInBand = 0;
5ec28e
 
5ec28e
-    while (nRects > 0 && xrgn->rects[firstInNextBand].y1 == xrgn->rects[i].y1)
5ec28e
+    while (nRects > 0 && boxes[firstInNextBand].y1 == boxes[i].y1)
5ec28e
     {
5ec28e
       firstInNextBand += yInc;
5ec28e
       nRects--;
5ec28e
@@ -210,18 +131,10 @@ bool rfb::Region::get_rects(std::vector<Rect>* rects,
5ec28e
       i = firstInNextBand - yInc;
5ec28e
 
5ec28e
     while (nRectsInBand > 0) {
5ec28e
-      int y = xrgn->rects[i].y1;
5ec28e
-      int h = maxArea / (xrgn->rects[i].x2 - xrgn->rects[i].x1);
5ec28e
-      if (!h) h = xrgn->rects[i].y2 - y;
5ec28e
-      do {
5ec28e
-        if (h > xrgn->rects[i].y2 - y)
5ec28e
-          h = xrgn->rects[i].y2 - y;
5ec28e
-        Rect r(xrgn->rects[i].x1, y, xrgn->rects[i].x2, y+h);
5ec28e
-        rects->push_back(r);
5ec28e
-        y += h;
5ec28e
-      } while (y < xrgn->rects[i].y2);
5ec28e
-      i += xInc;
5ec28e
-      nRectsInBand--;
5ec28e
+       Rect r(boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2);
5ec28e
+       rects->push_back(r);
5ec28e
+       i += xInc;
5ec28e
+       nRectsInBand--;
5ec28e
     }
5ec28e
 
5ec28e
     i = firstInNextBand;
5ec28e
@@ -231,22 +144,28 @@ bool rfb::Region::get_rects(std::vector<Rect>* rects,
5ec28e
 }
5ec28e
 
5ec28e
 rfb::Rect rfb::Region::get_bounding_rect() const {
5ec28e
-  return Rect(xrgn->extents.x1, xrgn->extents.y1,
5ec28e
-              xrgn->extents.x2, xrgn->extents.y2);
5ec28e
+  const pixman_box16_t* extents;
5ec28e
+  extents = pixman_region_extents(rgn);
5ec28e
+  return Rect(extents->x1, extents->y1, extents->x2, extents->y2);
5ec28e
 }
5ec28e
 
5ec28e
 
5ec28e
 void rfb::Region::debug_print(const char* prefix) const
5ec28e
 {
5ec28e
+  Rect extents;
5ec28e
+  std::vector<Rect> rects;
5ec28e
+  std::vector<Rect>::const_iterator iter;
5ec28e
+
5ec28e
+  extents = get_bounding_rect();
5ec28e
+  get_rects(&rects;;
5ec28e
+
5ec28e
   fprintf(stderr,"%s num rects %3ld extents %3d,%3d %3dx%3d\n",
5ec28e
-          prefix, xrgn->numRects, xrgn->extents.x1, xrgn->extents.y1,
5ec28e
-          xrgn->extents.x2-xrgn->extents.x1,
5ec28e
-          xrgn->extents.y2-xrgn->extents.y1);
5ec28e
+          prefix, (long)rects.size(), extents.tl.x, extents.tl.y,
5ec28e
+          extents.width(), extents.height());
5ec28e
 
5ec28e
-  for (int i = 0; i < xrgn->numRects; i++) {
5ec28e
+  for (iter = rects.begin(); iter != rects.end(); ++iter) {
5ec28e
     fprintf(stderr,"    rect %3d,%3d %3dx%3d\n",
5ec28e
-            xrgn->rects[i].x1, xrgn->rects[i].y1,
5ec28e
-            xrgn->rects[i].x2-xrgn->rects[i].x1,
5ec28e
-            xrgn->rects[i].y2-xrgn->rects[i].y1);
5ec28e
+            iter->tl.x, iter->tl.y, iter->width(), iter->height());
5ec28e
+
5ec28e
   }
5ec28e
 }
5ec28e
diff --git a/common/rfb/Region.h b/common/rfb/Region.h
5ec28e
index 9337556..c12beed 100644
5ec28e
--- a/common/rfb/Region.h
5ec28e
+++ b/common/rfb/Region.h
5ec28e
@@ -1,4 +1,5 @@
5ec28e
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
5ec28e
+ * Copyright 2016-2020 Pierre Ossman for Cendio AB
5ec28e
  * 
5ec28e
  * This is free software; you can redistribute it and/or modify
5ec28e
  * it under the terms of the GNU General Public License as published by
5ec28e
@@ -16,7 +17,7 @@
5ec28e
  * USA.
5ec28e
  */
5ec28e
 
5ec28e
-// Cross-platform Region class based on the X11 region implementation
5ec28e
+// Region class wrapper around pixman's region operations
5ec28e
 
5ec28e
 #ifndef __RFB_REGION_INCLUDED__
5ec28e
 #define __RFB_REGION_INCLUDED__
5ec28e
@@ -24,14 +25,10 @@
5ec28e
 #include <rfb/Rect.h>
5ec28e
 #include <vector>
5ec28e
 
5ec28e
-struct _XRegion;
5ec28e
+struct pixman_region16;
5ec28e
 
5ec28e
 namespace rfb {
5ec28e
 
5ec28e
-  struct ShortRect {
5ec28e
-    short x1, y1, x2, y2;
5ec28e
-  };
5ec28e
-
5ec28e
   class Region {
5ec28e
   public:
5ec28e
     // Create an empty region
5ec28e
@@ -49,10 +46,6 @@ namespace rfb {
5ec28e
     void clear();
5ec28e
     void reset(const Rect& r);
5ec28e
     void translate(const rfb::Point& delta);
5ec28e
-    void setOrderedRects(const std::vector<Rect>& rects);
5ec28e
-    void setExtentsAndOrderedRects(const ShortRect* extents, int nRects,
5ec28e
-                                   const ShortRect* rects);
5ec28e
-    void copyFrom(const Region& r);
5ec28e
 
5ec28e
     void assign_intersect(const Region& r);
5ec28e
     void assign_union(const Region& r);
5ec28e
@@ -76,7 +69,7 @@ namespace rfb {
5ec28e
 
5ec28e
   protected:
5ec28e
 
5ec28e
-    struct _XRegion* xrgn;
5ec28e
+    struct pixman_region16* rgn;
5ec28e
   };
5ec28e
 
5ec28e
 };
5ec28e
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
5ec28e
index d2206f9..d1c7709 100644
5ec28e
--- a/common/rfb/VNCSConnectionST.cxx
5ec28e
+++ b/common/rfb/VNCSConnectionST.cxx
5ec28e
@@ -1028,7 +1028,7 @@ void VNCSConnectionST::writeDataUpdate()
5ec28e
   if (!ui.copied.is_empty() && !damagedCursorRegion.is_empty()) {
5ec28e
     Region bogusCopiedCursor;
5ec28e
 
5ec28e
-    bogusCopiedCursor.copyFrom(damagedCursorRegion);
5ec28e
+    bogusCopiedCursor = damagedCursorRegion;
5ec28e
     bogusCopiedCursor.translate(ui.copy_delta);
5ec28e
     bogusCopiedCursor.assign_intersect(server->pb->getRect());
5ec28e
     if (!ui.copied.intersect(bogusCopiedCursor).is_empty()) {
5ec28e
diff --git a/unix/xserver/hw/vnc/Makefile.am b/unix/xserver/hw/vnc/Makefile.am
5ec28e
index 0d6a4ac..9a26e45 100644
5ec28e
--- a/unix/xserver/hw/vnc/Makefile.am
5ec28e
+++ b/unix/xserver/hw/vnc/Makefile.am
5ec28e
@@ -5,8 +5,7 @@ RFB_LIB=$(LIB_DIR)/rfb/librfb.la
5ec28e
 RDR_LIB=$(LIB_DIR)/rdr/librdr.la
5ec28e
 OS_LIB=$(LIB_DIR)/os/libos.la
5ec28e
 NETWORK_LIB=$(LIB_DIR)/network/libnetwork.la
5ec28e
-XREGION_LIB=$(LIB_DIR)/Xregion/libXregion.la
5ec28e
-COMMON_LIBS=$(NETWORK_LIB) $(RFB_LIB) $(RDR_LIB) $(XREGION_LIB) $(OS_LIB)
5ec28e
+COMMON_LIBS=$(NETWORK_LIB) $(RFB_LIB) $(RDR_LIB) $(OS_LIB)
5ec28e
 
5ec28e
 noinst_LTLIBRARIES = libvnccommon.la
5ec28e
 
5ec28e
diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc
5ec28e
index 57bf6d8..b369ec3 100644
5ec28e
--- a/unix/xserver/hw/vnc/vncExtInit.cc
5ec28e
+++ b/unix/xserver/hw/vnc/vncExtInit.cc
5ec28e
@@ -149,11 +149,6 @@ void vncExtensionInit(void)
5ec28e
     return;
5ec28e
   }
5ec28e
 
5ec28e
-  if (sizeof(ShortRect) != sizeof(struct UpdateRect)) {
5ec28e
-    vlog.error("vncExtensionInit: Incompatible ShortRect size");
5ec28e
-    return;
5ec28e
-  }
5ec28e
-
5ec28e
   ret = vncAddExtension();
5ec28e
   if (ret == -1)
5ec28e
     return;
5ec28e
@@ -358,25 +353,24 @@ void vncBell()
5ec28e
   }
5ec28e
 }
5ec28e
 
5ec28e
-void vncAddChanged(int scrIdx, const struct UpdateRect *extents,
5ec28e
-                   int nRects, const struct UpdateRect *rects)
5ec28e
+void vncAddChanged(int scrIdx, int nRects,
5ec28e
+                   const struct UpdateRect *rects)
5ec28e
 {
5ec28e
-  Region reg;
5ec28e
-
5ec28e
-  reg.setExtentsAndOrderedRects((const ShortRect*)extents,
5ec28e
-                                nRects, (const ShortRect*)rects);
5ec28e
-  desktop[scrIdx]->add_changed(reg);
5ec28e
+  for (int i = 0;i < nRects;i++) {
5ec28e
+    desktop[scrIdx]->add_changed(Region(Rect(rects[i].x1, rects[i].y1,
5ec28e
+                                             rects[i].x2, rects[i].y2)));
5ec28e
+  }
5ec28e
 }
5ec28e
 
5ec28e
-void vncAddCopied(int scrIdx, const struct UpdateRect *extents,
5ec28e
-                  int nRects, const struct UpdateRect *rects,
5ec28e
+void vncAddCopied(int scrIdx, int nRects,
5ec28e
+                  const struct UpdateRect *rects,
5ec28e
                   int dx, int dy)
5ec28e
 {
5ec28e
-  Region reg;
5ec28e
-
5ec28e
-  reg.setExtentsAndOrderedRects((const ShortRect*)extents,
5ec28e
-                                nRects, (const ShortRect*)rects);
5ec28e
-  desktop[scrIdx]->add_copied(reg, rfb::Point(dx, dy));
5ec28e
+  for (int i = 0;i < nRects;i++) {
5ec28e
+    desktop[scrIdx]->add_copied(Region(Rect(rects[i].x1, rects[i].y1,
5ec28e
+                                            rects[i].x2, rects[i].y2)),
5ec28e
+                                Point(dx, dy));
5ec28e
+  }
5ec28e
 }
5ec28e
 
5ec28e
 void vncSetCursor(int width, int height, int hotX, int hotY,
5ec28e
diff --git a/unix/xserver/hw/vnc/vncExtInit.h b/unix/xserver/hw/vnc/vncExtInit.h
5ec28e
index 9f8d9e7..0d7d691 100644
5ec28e
--- a/unix/xserver/hw/vnc/vncExtInit.h
5ec28e
+++ b/unix/xserver/hw/vnc/vncExtInit.h
5ec28e
@@ -76,10 +76,10 @@ struct UpdateRect {
5ec28e
   short x1, y1, x2, y2;
5ec28e
 };
5ec28e
 
5ec28e
-void vncAddChanged(int scrIdx, const struct UpdateRect *extents,
5ec28e
-                   int nRects, const struct UpdateRect *rects);
5ec28e
-void vncAddCopied(int scrIdx, const struct UpdateRect *extents,
5ec28e
-                  int nRects, const struct UpdateRect *rects,
5ec28e
+void vncAddChanged(int scrIdx, int nRects,
5ec28e
+                   const struct UpdateRect *rects);
5ec28e
+void vncAddCopied(int scrIdx, int nRects,
5ec28e
+                  const struct UpdateRect *rects,
5ec28e
                   int dx, int dy);
5ec28e
 
5ec28e
 void vncSetCursor(int width, int height, int hotX, int hotY,
5ec28e
diff --git a/unix/xserver/hw/vnc/vncHooks.c b/unix/xserver/hw/vnc/vncHooks.c
5ec28e
index 5b90f53..498ee3d 100644
5ec28e
--- a/unix/xserver/hw/vnc/vncHooks.c
5ec28e
+++ b/unix/xserver/hw/vnc/vncHooks.c
5ec28e
@@ -369,9 +369,8 @@ static inline void add_changed(ScreenPtr pScreen, RegionPtr reg)
5ec28e
   if (vncHooksScreen->ignoreHooks)
5ec28e
     return;
5ec28e
   vncAddChanged(pScreen->myNum,
5ec28e
-                (const struct UpdateRect*)REGION_EXTENTS(pScreen, reg),
5ec28e
-                REGION_NUM_RECTS(reg),
5ec28e
-                (const struct UpdateRect*)REGION_RECTS(reg));
5ec28e
+                RegionNumRects(reg),
5ec28e
+                (const struct UpdateRect*)RegionRects(reg));
5ec28e
 }
5ec28e
 
5ec28e
 static inline void add_copied(ScreenPtr pScreen, RegionPtr dst,
5ec28e
@@ -381,9 +380,8 @@ static inline void add_copied(ScreenPtr pScreen, RegionPtr dst,
5ec28e
   if (vncHooksScreen->ignoreHooks)
5ec28e
     return;
5ec28e
   vncAddCopied(pScreen->myNum,
5ec28e
-               (const struct UpdateRect*)REGION_EXTENTS(pScreen, dst),
5ec28e
-               REGION_NUM_RECTS(dst),
5ec28e
-               (const struct UpdateRect*)REGION_RECTS(dst), dx, dy);
5ec28e
+               RegionNumRects(dst),
5ec28e
+               (const struct UpdateRect*)RegionRects(dst), dx, dy);
5ec28e
 }
5ec28e
 
5ec28e
 static inline Bool is_visible(DrawablePtr drawable)
5ec28e
@@ -515,15 +513,15 @@ static void vncHooksCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
5ec28e
 
5ec28e
   SCREEN_PROLOGUE(pWin->drawable.pScreen, CopyWindow);
5ec28e
 
5ec28e
-  REGION_NULL(pScreen, &copied);
5ec28e
-  REGION_COPY(pScreen, &copied, pOldRegion);
5ec28e
+  RegionNull(&copied);
5ec28e
+  RegionCopy(&copied, pOldRegion);
5ec28e
 
5ec28e
   screen_box.x1 = 0;
5ec28e
   screen_box.y1 = 0;
5ec28e
   screen_box.x2 = pScreen->width;
5ec28e
   screen_box.y2 = pScreen->height;
5ec28e
 
5ec28e
-  REGION_INIT(pScreen, &screen_rgn, &screen_box, 1);
5ec28e
+  RegionInitBoxes(&screen_rgn, &screen_box, 1);
5ec28e
 
5ec28e
   dx = pWin->drawable.x - ptOldOrg.x;
5ec28e
   dy = pWin->drawable.y - ptOldOrg.y;
5ec28e
@@ -532,18 +530,18 @@ static void vncHooksCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
5ec28e
   // We also need to copy with changes to the Window's clipping region.
5ec28e
   // Finally, make sure we don't get copies to or from regions outside
5ec28e
   // the framebuffer.
5ec28e
-  REGION_INTERSECT(pScreen, &copied, &copied, &screen_rgn);
5ec28e
-  REGION_TRANSLATE(pScreen, &copied, dx, dy);
5ec28e
-  REGION_INTERSECT(pScreen, &copied, &copied, &screen_rgn);
5ec28e
-  REGION_INTERSECT(pScreen, &copied, &copied, &pWin->borderClip);
5ec28e
+  RegionIntersect(&copied, &copied, &screen_rgn);
5ec28e
+  RegionTranslate(&copied, dx, dy);
5ec28e
+  RegionIntersect(&copied, &copied, &screen_rgn);
5ec28e
+  RegionIntersect(&copied, &copied, &pWin->borderClip);
5ec28e
 
5ec28e
   (*pScreen->CopyWindow) (pWin, ptOldOrg, pOldRegion);
5ec28e
 
5ec28e
   if (REGION_NOTEMPTY(pScreen, &copied))
5ec28e
     add_copied(pScreen, &copied, dx, dy);
5ec28e
 
5ec28e
-  REGION_UNINIT(pScreen, &copied);
5ec28e
-  REGION_UNINIT(pScreen, &screen_rgn);
5ec28e
+  RegionUninit(&copied);
5ec28e
+  RegionUninit(&screen_rgn);
5ec28e
 
5ec28e
   SCREEN_EPILOGUE(CopyWindow);
5ec28e
 }
5ec28e
@@ -564,8 +562,8 @@ static void vncHooksClearToBackground(WindowPtr pWin, int x, int y, int w,
5ec28e
   box.x2 = w ? (box.x1 + w) : (pWin->drawable.x + pWin->drawable.width);
5ec28e
   box.y2 = h ? (box.y1 + h) : (pWin->drawable.y + pWin->drawable.height);
5ec28e
 
5ec28e
-  REGION_INIT(pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pScreen, &reg, &reg, &pWin->clipList);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, &pWin->clipList);
5ec28e
 
5ec28e
   (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures);
5ec28e
 
5ec28e
@@ -573,7 +571,7 @@ static void vncHooksClearToBackground(WindowPtr pWin, int x, int y, int w,
5ec28e
     add_changed(pScreen, ®);
5ec28e
   }
5ec28e
 
5ec28e
-  REGION_UNINIT(pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
   SCREEN_EPILOGUE(ClearToBackground);
5ec28e
 }
5ec28e
@@ -765,19 +763,19 @@ static void vncHooksComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
5ec28e
     box.y1 = max(pDst->pDrawable->y + yDst, 0);
5ec28e
     box.x2 = box.x1 + width;
5ec28e
     box.y2 = box.y1 + height;
5ec28e
-    REGION_INIT(pScreen, &changed, &box, 0);
5ec28e
+    RegionInitBoxes(&changed, &box, 1);
5ec28e
 
5ec28e
     box.x1 = 0;
5ec28e
     box.y1 = 0;
5ec28e
     box.x2 = pScreen->width;
5ec28e
     box.y2 = pScreen->height;
5ec28e
-    REGION_INIT(pScreen, &fbreg, &box, 0);
5ec28e
+    RegionInitBoxes(&fbreg, &box, 1);
5ec28e
 
5ec28e
-    REGION_INTERSECT(pScreen, &changed, &changed, &fbreg);
5ec28e
+    RegionIntersect(&changed, &changed, &fbreg);
5ec28e
 
5ec28e
-    REGION_UNINIT(pScreen, &fbreg);
5ec28e
+    RegionUninit(&fbreg);
5ec28e
   } else {
5ec28e
-    REGION_NULL(pScreen, &changed);
5ec28e
+    RegionNull(&changed);
5ec28e
   }
5ec28e
 
5ec28e
 
5ec28e
@@ -787,7 +785,7 @@ static void vncHooksComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
5ec28e
   if (REGION_NOTEMPTY(pScreen, &changed))
5ec28e
     add_changed(pScreen, &changed);
5ec28e
 
5ec28e
-  REGION_UNINIT(pScreen, &changed);
5ec28e
+  RegionUninit(&changed);
5ec28e
 
5ec28e
   RENDER_EPILOGUE(Composite);
5ec28e
 }
5ec28e
@@ -855,20 +853,20 @@ static void vncHooksGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
5ec28e
     RegionRec fbreg;
5ec28e
 
5ec28e
     changed = GlyphsToRegion(pScreen, nlists, lists, glyphs);
5ec28e
-    REGION_TRANSLATE(pScreen, changed,
5ec28e
+    RegionTranslate(changed,
5ec28e
                      pDst->pDrawable->x, pDst->pDrawable->y);
5ec28e
 
5ec28e
     fbbox.x1 = 0;
5ec28e
     fbbox.y1 = 0;
5ec28e
     fbbox.x2 = pScreen->width;
5ec28e
     fbbox.y2 = pScreen->height;
5ec28e
-    REGION_INIT(pScreen, &fbreg, &fbbox, 0);
5ec28e
+    RegionInitBoxes(&fbreg, &fbbox, 1);
5ec28e
 
5ec28e
-    REGION_INTERSECT(pScreen, changed, changed, &fbreg);
5ec28e
+    RegionIntersect(changed, changed, &fbreg);
5ec28e
 
5ec28e
-    REGION_UNINIT(pScreen, &fbreg);
5ec28e
+    RegionUninit(&fbreg);
5ec28e
   } else {
5ec28e
-    changed = REGION_CREATE(pScreen, NullBox, 0);
5ec28e
+    changed = RegionCreate(NullBox, 0);
5ec28e
   }
5ec28e
 
5ec28e
   (*ps->Glyphs)(op, pSrc, pDst, maskFormat, xSrc, ySrc, nlists, lists, glyphs);
5ec28e
@@ -876,7 +874,7 @@ static void vncHooksGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
5ec28e
   if (REGION_NOTEMPTY(pScreen, changed))
5ec28e
     add_changed(pScreen, changed);
5ec28e
 
5ec28e
-  REGION_DESTROY(pScreen, changed);
5ec28e
+  RegionDestroy(changed);
5ec28e
 
5ec28e
   RENDER_EPILOGUE(Glyphs);
5ec28e
 }
5ec28e
@@ -1067,17 +1065,17 @@ static void vncHooksFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nInit,
5ec28e
 
5ec28e
   GC_OP_PROLOGUE(pGC, FillSpans);
5ec28e
 
5ec28e
-  REGION_NULL(pGC->pScreen, ®);
5ec28e
-  REGION_COPY(pGC->pScreen, &reg, pGC->pCompositeClip);
5ec28e
+  RegionNull(®);
5ec28e
+  RegionCopy(&reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   if (pDrawable->type == DRAWABLE_WINDOW)
5ec28e
-    REGION_INTERSECT(pScreen, &reg, &reg, &((WindowPtr)pDrawable)->borderClip);
5ec28e
+    RegionIntersect(&reg, &reg, &((WindowPtr)pDrawable)->borderClip);
5ec28e
 
5ec28e
   (*pGC->ops->FillSpans) (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
 }
5ec28e
@@ -1093,17 +1091,17 @@ static void vncHooksSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
5ec28e
 
5ec28e
   GC_OP_PROLOGUE(pGC, SetSpans);
5ec28e
 
5ec28e
-  REGION_NULL(pGC->pScreen, ®);
5ec28e
-  REGION_COPY(pGC->pScreen, &reg, pGC->pCompositeClip);
5ec28e
+  RegionNull(®);
5ec28e
+  RegionCopy(&reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   if (pDrawable->type == DRAWABLE_WINDOW)
5ec28e
-    REGION_INTERSECT(pScreen, &reg, &reg, &((WindowPtr)pDrawable)->borderClip);
5ec28e
+    RegionIntersect(&reg, &reg, &((WindowPtr)pDrawable)->borderClip);
5ec28e
 
5ec28e
   (*pGC->ops->SetSpans) (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
 }
5ec28e
@@ -1124,15 +1122,15 @@ static void vncHooksPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
5ec28e
   box.x2 = box.x1 + w;
5ec28e
   box.y2 = box.y1 + h;
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PutImage) (pDrawable, pGC, depth, x, y, w, h, leftPad, format,
5ec28e
                          pBits);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
 }
5ec28e
@@ -1153,7 +1151,7 @@ static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
5ec28e
 
5ec28e
   // Apparently this happens now and then...
5ec28e
   if ((w == 0) || (h == 0))
5ec28e
-    REGION_NULL(pGC->pScreen, &dst);
5ec28e
+    RegionNull(&dst);
5ec28e
   else {
5ec28e
     BoxRec box;
5ec28e
 
5ec28e
@@ -1162,10 +1160,10 @@ static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
5ec28e
     box.x2 = box.x1 + w;
5ec28e
     box.y2 = box.y1 + h;
5ec28e
 
5ec28e
-    REGION_INIT(pGC->pScreen, &dst, &box, 0);
5ec28e
+    RegionInitBoxes(&dst, &box, 1);
5ec28e
   }
5ec28e
 
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &dst, &dst, pGC->pCompositeClip);
5ec28e
+  RegionIntersect(&dst, &dst, pGC->pCompositeClip);
5ec28e
 
5ec28e
   // The source of the data has to be something that's on screen.
5ec28e
   if (is_visible(pSrc)) {
5ec28e
@@ -1176,24 +1174,24 @@ static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
5ec28e
     box.x2 = box.x1 + w;
5ec28e
     box.y2 = box.y1 + h;
5ec28e
 
5ec28e
-    REGION_INIT(pGC->pScreen, &src, &box, 0);
5ec28e
+    RegionInitBoxes(&src, &box, 1);
5ec28e
 
5ec28e
     if ((pSrc->type == DRAWABLE_WINDOW) &&
5ec28e
-        REGION_NOTEMPTY(pScreen, &((WindowPtr)pSrc)->clipList)) {
5ec28e
-      REGION_INTERSECT(pScreen, &src, &src, &((WindowPtr)pSrc)->clipList);
5ec28e
+        RegionNotEmpty(&((WindowPtr)pSrc)->clipList)) {
5ec28e
+      RegionIntersect(&src, &src, &((WindowPtr)pSrc)->clipList);
5ec28e
     }
5ec28e
 
5ec28e
-    REGION_TRANSLATE(pScreen, &src,
5ec28e
+    RegionTranslate(&src,
5ec28e
                      dstx + pDst->x - srcx - pSrc->x,
5ec28e
                      dsty + pDst->y - srcy - pSrc->y);
5ec28e
   } else {
5ec28e
-    REGION_NULL(pGC->pScreen, &src;;
5ec28e
+    RegionNull(&src;;
5ec28e
   }
5ec28e
 
5ec28e
-  REGION_NULL(pGC->pScreen, &changed);
5ec28e
+  RegionNull(&changed);
5ec28e
 
5ec28e
-  REGION_SUBTRACT(pScreen, &changed, &dst, &src;;
5ec28e
-  REGION_INTERSECT(pScreen, &dst, &dst, &src;;
5ec28e
+  RegionSubtract(&changed, &dst, &src;;
5ec28e
+  RegionIntersect(&dst, &dst, &src;;
5ec28e
 
5ec28e
   ret = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
5ec28e
 
5ec28e
@@ -1205,9 +1203,9 @@ static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
5ec28e
   if (REGION_NOTEMPTY(pScreen, &changed))
5ec28e
     add_changed(pGC->pScreen, &changed);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, &dst);
5ec28e
-  REGION_UNINIT(pGC->pScreen, &src;;
5ec28e
-  REGION_UNINIT(pGC->pScreen, &changed);
5ec28e
+  RegionUninit(&dst);
5ec28e
+  RegionUninit(&src;;
5ec28e
+  RegionUninit(&changed);
5ec28e
 
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
 
5ec28e
@@ -1234,15 +1232,15 @@ static RegionPtr vncHooksCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
5ec28e
   box.x2 = box.x1 + w;
5ec28e
   box.y2 = box.y1 + h;
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   ret = (*pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, w, h,
5ec28e
                                 dstx, dsty, plane);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
 
5ec28e
@@ -1298,14 +1296,14 @@ static void vncHooksPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
5ec28e
   box.x2 = maxX + 1 + pDrawable->x;
5ec28e
   box.y2 = maxY + 1 + pDrawable->y;
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pts);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1425,13 +1423,13 @@ static void vncHooksPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode,
5ec28e
   }
5ec28e
 
5ec28e
   reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
5ec28e
+  RegionIntersect(reg, reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, ppts);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, reg);
5ec28e
 
5ec28e
-  REGION_DESTROY(pGC->pScreen, reg);
5ec28e
+  RegionDestroy(reg);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1510,13 +1508,13 @@ static void vncHooksPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
5ec28e
   }
5ec28e
 
5ec28e
   reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
5ec28e
+  RegionIntersect(reg, reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PolySegment) (pDrawable, pGC, nseg, segs);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, reg);
5ec28e
 
5ec28e
-  REGION_DESTROY(pGC->pScreen, reg);
5ec28e
+  RegionDestroy(reg);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1599,13 +1597,13 @@ static void vncHooksPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nrects,
5ec28e
   }
5ec28e
 
5ec28e
   reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
5ec28e
+  RegionIntersect(reg, reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PolyRectangle) (pDrawable, pGC, nrects, rects);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, reg);
5ec28e
 
5ec28e
-  REGION_DESTROY(pGC->pScreen, reg);
5ec28e
+  RegionDestroy(reg);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1674,13 +1672,13 @@ static void vncHooksPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
5ec28e
   }
5ec28e
 
5ec28e
   reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
5ec28e
+  RegionIntersect(reg, reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PolyArc) (pDrawable, pGC, narcs, arcs);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, reg);
5ec28e
 
5ec28e
-  REGION_DESTROY(pGC->pScreen, reg);
5ec28e
+  RegionDestroy(reg);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1737,14 +1735,14 @@ static void vncHooksFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
5ec28e
   box.x2 = maxX + 1 + pDrawable->x;
5ec28e
   box.y2 = maxY + 1 + pDrawable->y;
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, count, pts);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1803,13 +1801,13 @@ static void vncHooksPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrects,
5ec28e
   }
5ec28e
 
5ec28e
   reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
5ec28e
+  RegionIntersect(reg, reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrects, rects);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, reg);
5ec28e
 
5ec28e
-  REGION_DESTROY(pGC->pScreen, reg);
5ec28e
+  RegionDestroy(reg);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1878,13 +1876,13 @@ static void vncHooksPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
5ec28e
   }
5ec28e
 
5ec28e
   reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
5ec28e
+  RegionIntersect(reg, reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PolyFillArc) (pDrawable, pGC, narcs, arcs);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, reg);
5ec28e
 
5ec28e
-  REGION_DESTROY(pGC->pScreen, reg);
5ec28e
+  RegionDestroy(reg);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1929,14 +1927,14 @@ static int vncHooksPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
5ec28e
 
5ec28e
   GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   ret = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1963,14 +1961,14 @@ static int vncHooksPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
5ec28e
 
5ec28e
   GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   ret = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -1996,14 +1994,14 @@ static void vncHooksImageText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
5ec28e
 
5ec28e
   GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -2027,14 +2025,14 @@ static void vncHooksImageText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
5ec28e
 
5ec28e
   GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -2059,14 +2057,14 @@ static void vncHooksImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
5ec28e
 
5ec28e
   GetTextBoundingRect(pDrawable, pGC->font, x, y, nglyph, &box);
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -2091,14 +2089,14 @@ static void vncHooksPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
5ec28e
 
5ec28e
   GetTextBoundingRect(pDrawable, pGC->font, x, y, nglyph, &box);
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
 out:
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
@@ -2121,14 +2119,14 @@ static void vncHooksPushPixels(GCPtr pGC, PixmapPtr pBitMap,
5ec28e
   box.x2 = box.x1 + w;
5ec28e
   box.y2 = box.y1 + h;
5ec28e
 
5ec28e
-  REGION_INIT(pGC->pScreen, &reg, &box, 0);
5ec28e
-  REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
5ec28e
+  RegionInitBoxes(&reg, &box, 1);
5ec28e
+  RegionIntersect(&reg, &reg, pGC->pCompositeClip);
5ec28e
 
5ec28e
   (*pGC->ops->PushPixels) (pGC, pBitMap, pDrawable, w, h, x, y);
5ec28e
 
5ec28e
   add_changed(pGC->pScreen, ®);
5ec28e
 
5ec28e
-  REGION_UNINIT(pGC->pScreen, ®);
5ec28e
+  RegionUninit(®);
5ec28e
 
5ec28e
   GC_OP_EPILOGUE(pGC);
5ec28e
 }
5ec28e
diff --git a/unix/xserver/hw/vnc/xvnc.c b/unix/xserver/hw/vnc/xvnc.c
5ec28e
index 93d8af4..dccea9c 100644
5ec28e
--- a/unix/xserver/hw/vnc/xvnc.c
5ec28e
+++ b/unix/xserver/hw/vnc/xvnc.c
5ec28e
@@ -1000,8 +1000,8 @@ xf86SetRootClip (ScreenPtr pScreen, Bool enable)
5ec28e
 	    {
5ec28e
 		RegionPtr	borderVisible;
5ec28e
 
5ec28e
-		borderVisible = REGION_CREATE(pScreen, NullBox, 1);
5ec28e
-		REGION_SUBTRACT(pScreen, borderVisible,
5ec28e
+		borderVisible = RegionCreate(NullBox, 1);
5ec28e
+		RegionSubtract(borderVisible,
5ec28e
 				&pWin->borderClip, &pWin->winSize);
5ec28e
 		pWin->valdata->before.borderVisible = borderVisible;
5ec28e
 	    }
5ec28e
@@ -1010,7 +1010,7 @@ xf86SetRootClip (ScreenPtr pScreen, Bool enable)
5ec28e
     }
5ec28e
     
5ec28e
     /*
5ec28e
-     * Use REGION_BREAK to avoid optimizations in ValidateTree
5ec28e
+     * Use RegionBreak to avoid optimizations in ValidateTree
5ec28e
      * that assume the root borderClip can't change well, normally
5ec28e
      * it doesn't...)
5ec28e
      */
5ec28e
@@ -1020,18 +1020,18 @@ xf86SetRootClip (ScreenPtr pScreen, Bool enable)
5ec28e
 	box.y1 = 0;
5ec28e
 	box.x2 = pScreen->width;
5ec28e
 	box.y2 = pScreen->height;
5ec28e
-	REGION_INIT (pScreen, &pWin->winSize, &box, 1);
5ec28e
-	REGION_INIT (pScreen, &pWin->borderSize, &box, 1);
5ec28e
+	RegionInit(&pWin->winSize, &box, 1);
5ec28e
+	RegionInit(&pWin->borderSize, &box, 1);
5ec28e
 	if (WasViewable)
5ec28e
-	    REGION_RESET(pScreen, &pWin->borderClip, &box);
5ec28e
+	    RegionReset(&pWin->borderClip, &box);
5ec28e
 	pWin->drawable.width = pScreen->width;
5ec28e
 	pWin->drawable.height = pScreen->height;
5ec28e
-        REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
5ec28e
+        RegionBreak(&pWin->clipList);
5ec28e
     }
5ec28e
     else
5ec28e
     {
5ec28e
-	REGION_EMPTY(pScreen, &pWin->borderClip);
5ec28e
-	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
5ec28e
+	RegionEmpty(&pWin->borderClip);
5ec28e
+	RegionBreak(&pWin->clipList);
5ec28e
     }
5ec28e
     
5ec28e
     ResizeChildrenWinSize (pWin, 0, 0, 0, 0);