[PATCH 3/4] Change region implementation from macros to inline functions.

Keith Packard keithp at keithp.com
Fri May 21 12:43:25 PDT 2010


This makes all of the previous macros into inline functions and also
turns all of the direct calls to pixman region code into inline
functions as well.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 dix/region.c         |  172 -----------------------
 include/regionstr.h  |  375 +++++++++++++++++++++++++-------------------------
 include/scrnintstr.h |    4 +
 3 files changed, 192 insertions(+), 359 deletions(-)

diff --git a/dix/region.c b/dix/region.c
index 9bfff37..5a9c705 100644
--- a/dix/region.c
+++ b/dix/region.c
@@ -275,12 +275,6 @@ PrintRegion(RegionPtr rgn)
     ErrorF("[mi] \n");
 }
 
-Bool
-RegionEqual(RegionPtr reg1, RegionPtr reg2)
-{
-    return pixman_region_equal (reg1, reg2);
-}
-
 #ifdef DEBUG
 Bool
 ValidRegion(RegionPtr reg)
@@ -328,30 +322,6 @@ ValidRegion(RegionPtr reg)
 }
 #endif /* DEBUG */
 
-/*****************************************************************
- *   RegionInit(pReg, rect, size)
- *     Outer region rect is statically allocated.
- *****************************************************************/
-
-#ifndef RegionInit
-void
-RegionInit(RegionPtr pReg, BoxPtr rect, int size)
-{
-    if (rect)
-	pixman_region_init_with_extents (pReg, rect);
-    else
-	pixman_region_init (pReg);
-}
-#endif
-
-#ifndef RegionUninit
-void
-RegionUninit(RegionPtr pReg)
-{
-    pixman_region_fini (pReg);
-}
-#endif
-
 Bool
 RegionBreak (RegionPtr pReg)
 {
@@ -400,12 +370,6 @@ RectAlloc(RegionPtr pRgn, int n)
     return TRUE;
 }
 
-Bool
-RegionCopy(RegionPtr dst, RegionPtr src)
-{
-    return pixman_region_copy (dst, src);
-}
-
 /*======================================================================
  *	    Generic Region Operator
  *====================================================================*/
@@ -893,15 +857,6 @@ SetExtents (RegionPtr pReg)
  *-----------------------------------------------------------------------
  */
 /*ARGSUSED*/
-Bool
-Intersect(
-    RegionPtr	newReg,     /* destination Region */
-    RegionPtr	reg1,
-    RegionPtr	reg2        /* source regions     */
-    )
-{
-    return pixman_region_intersect (newReg, reg1, reg2);
-}
 
 #define MERGERECT(r)						\
 {								\
@@ -997,16 +952,6 @@ UnionO (
     return TRUE;
 }
 
-Bool
-Union(
-    RegionPtr	newReg,          /* destination Region */
-    RegionPtr	reg1,
-    RegionPtr	reg2             /* source regions     */
-    )
-{
-    return pixman_region_union (newReg, reg1, reg2);
-}
-
 /*======================================================================
  *	    Batch Rectangle Union
  *====================================================================*/
@@ -1501,127 +1446,10 @@ RectsToRegion(int nrects, xRectangle *prect, int ctype)
  */
 /*ARGSUSED*/
 
-/*-
- *-----------------------------------------------------------------------
- * Subtract --
- *	Subtract regS from regM and leave the result in regD.
- *	S stands for subtrahend, M for minuend and D for difference.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	regD is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-Bool
-Subtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
-{
-    return pixman_region_subtract (regD, regM, regS);
-}
-
 /*======================================================================
  *	    Region Inversion
  *====================================================================*/
 
-/*-
- *-----------------------------------------------------------------------
- * Inverse --
- *	Take a region and a box and return a region that is everything
- *	in the box but not in the region. The careful reader will note
- *	that this is the same as subtracting the region from the box...
- *
- * Results:
- *	TRUE.
- *
- * Side Effects:
- *	newReg is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-Bool
-Inverse(
-    RegionPtr	  newReg,       /* Destination region */
-    RegionPtr	  reg1,         /* Region to invert */
-    BoxPtr	  invRect	/* Bounding box for inversion */
-    )
-{
-    return pixman_region_inverse (newReg, reg1, invRect);
-}
-int
-RectIn(RegionPtr region, BoxPtr prect)
-{
-    return pixman_region_contains_rectangle (region, prect);
-}
-
-/* TranslateRegion(pReg, x, y)
-   translates in place
-*/
-
-void
-TranslateRegion(RegionPtr pReg, int x, int y)
-{
-    pixman_region_translate (pReg, x, y);
-}
-
-#ifndef RegionReset
-void
-RegionReset(RegionPtr pReg, BoxPtr pBox)
-{
-    pixman_region_reset (pReg, pBox);
-}
-#endif
-
-Bool
-PointInRegion(
-    RegionPtr pReg,
-    int x,
-    int y,
-    BoxPtr box      /* "return" value */
-    )
-{
-    return pixman_region_contains_point (pReg, x, y, box);
-}
-
-#ifndef RegionNotEmpty
-Bool
-RegionNotEmpty(RegionPtr pReg)
-{
-    return pixman_region_not_empty (pReg);
-}
-#endif
-
-#ifndef RegionBroken
-Bool
-RegionBroken(RegionPtr pReg)
-{
-    good(pReg);
-    return (RegionNar(pReg));
-}
-#endif
-
-#ifndef RegionEmpty
-void
-RegionEmpty(RegionPtr pReg)
-{
-    good(pReg);
-    xfreeData(pReg);
-    pReg->extents.x2 = pReg->extents.x1;
-    pReg->extents.y2 = pReg->extents.y1;
-    pReg->data = &EmptyData;
-}
-#endif
-
-#ifndef RegionExtents
-BoxPtr
-RegionExtents(RegionPtr pReg)
-{
-    good(pReg);
-    return(&pReg->extents);
-}
-#endif
-
 #define ExchangeSpans(a, b)				    \
 {							    \
     DDXPointRec	tpt;				    	    \
diff --git a/include/regionstr.h b/include/regionstr.h
index c21e236..a670370 100644
--- a/include/regionstr.h
+++ b/include/regionstr.h
@@ -70,168 +70,144 @@ extern _X_EXPORT BoxRec EmptyBox;
 extern _X_EXPORT RegDataRec EmptyData;
 extern _X_EXPORT RegDataRec BrokenData;
 
-#define RegionNil(reg) ((reg)->data && !(reg)->data->numRects)
+static inline Bool RegionNil(RegionPtr reg) {
+    return ((reg)->data && !(reg)->data->numRects);
+}
+
 /* not a region */
-#define RegionNar(reg)	((reg)->data == &BrokenData)
-#define RegionNumRects(reg) ((reg)->data ? (reg)->data->numRects : 1)
-#define RegionSize(reg) ((reg)->data ? (reg)->data->size : 0)
-#define RegionRects(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
-			               : &(reg)->extents)
-#define RegionBoxptr(reg) ((BoxPtr)((reg)->data + 1))
-#define RegionBox(reg,i) (&RegionBoxptr(reg)[i])
-#define RegionTop(reg) RegionBox(reg, (reg)->data->numRects)
-#define RegionEnd(reg) RegionBox(reg, (reg)->data->numRects - 1)
-#define RegionSizeof(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))
-
-#define RegionCreate(_rect, _size) \
-    RegionCreate(_rect, _size)
-
-#define RegionCopy(dst, src) \
-    RegionCopy(dst, src)
-
-#define RegionDestroy( _pReg) \
-    RegionDestroy(_pReg)
-
-#define RegionIntersect(newReg, reg1, reg2) \
-    Intersect(newReg, reg1, reg2)
-
-#define RegionUnion(newReg, reg1, reg2) \
-    Union(newReg, reg1, reg2)
-
-#define RegionSubtract(newReg, reg1, reg2) \
-    Subtract(newReg, reg1, reg2)
-
-#define RegionInverse(newReg, reg1, invRect) \
-    Inverse(newReg, reg1, invRect)
-
-#define RegionTranslate(_pReg, _x, _y) \
-    TranslateRegion(_pReg, _x, _y)
-
-#define RectInRegion(_pReg, prect) \
-    RectIn(_pReg, prect)
-
-#define PointInRegion(_pReg, _x, _y, prect) \
-    PointInRegion(_pReg, _x, _y, prect)
-
-#define RegionAppend(dstrgn, rgn) \
-    RegionAppend(dstrgn, rgn)
-
-#define RegionValidate(badreg, pOverlap) \
-    RegionValidate(badreg, pOverlap)
-
-#define BitmapToRegion(_pScreen, pPix)				\
-    (*(_pScreen)->BitmapToRegion)(pPix) /* no mi version?! */
-
-#define RECTS_TO_REGION(_pScreen, nrects, prect, ctype) \
-    RectsToRegion(nrects, prect, ctype)
-
-#define REGION_EQUAL(_pScreen, _pReg1, _pReg2) \
-    RegionEqual(_pReg1, _pReg2)
-
-#define REGION_BREAK(_pScreen, _pReg) \
-    RegionBreak(_pReg)
-
-#define RegionInit(_pReg, _rect, _size) \
-{ \
-    if ((_rect) != NULL)				\
-    { \
-        (_pReg)->extents = *(_rect); \
-        (_pReg)->data = (RegDataPtr)NULL; \
-    } \
-    else \
-    { \
-        (_pReg)->extents = EmptyBox; \
-        if (((_size) > 1) && ((_pReg)->data = \
-                             (RegDataPtr)malloc(RegionSizeof(_size)))) \
-        { \
-            (_pReg)->data->size = (_size); \
-            (_pReg)->data->numRects = 0; \
-        } \
-        else \
-            (_pReg)->data = &EmptyData; \
-    } \
- }
-
-
-#define RegionUninit(_pReg) \
-{ \
-    if ((_pReg)->data && (_pReg)->data->size) { \
-	free((_pReg)->data); \
-	(_pReg)->data = NULL; \
-    } \
+static inline Bool RegionNar(RegionPtr reg) {
+    return ((reg)->data == &BrokenData);
 }
 
-#define RegionReset(_pReg, _pBox) \
-{ \
-    (_pReg)->extents = *(_pBox); \
-    RegionUninit(_pReg); \
-    (_pReg)->data = (RegDataPtr)NULL; \
+static inline int RegionNumRects(RegionPtr reg) {
+    return ((reg)->data ? (reg)->data->numRects : 1);
 }
 
-#define RegionNotEmpty(_pReg) \
-    !RegionNil(_pReg)
+static inline int RegionSize(RegionPtr reg) {
+    return ((reg)->data ? (reg)->data->size : 0);
+}
 
-#define RegionBroken(_pReg) \
-    RegionNar(_pReg)
+static inline BoxPtr RegionRects(RegionPtr reg) {
+    return ((reg)->data ? (BoxPtr)((reg)->data + 1) : &(reg)->extents);
+}
 
-#define RegionEmpty(_pReg) \
-{ \
-    RegionUninit(_pReg); \
-    (_pReg)->extents.x2 = (_pReg)->extents.x1; \
-    (_pReg)->extents.y2 = (_pReg)->extents.y1; \
-    (_pReg)->data = &EmptyData; \
+static inline BoxPtr RegionBoxptr(RegionPtr reg) {
+    return ((BoxPtr)((reg)->data + 1));
 }
 
-#define RegionExtents(_pReg) \
-    (&(_pReg)->extents)
+static inline BoxPtr RegionBox(RegionPtr reg, int i) {
+    return (&RegionBoxptr(reg)[i]);
+}
 
-#define RegionNull(_pReg) \
-{ \
-    (_pReg)->extents = EmptyBox; \
-    (_pReg)->data = &EmptyData; \
+static inline BoxPtr RegionTop(RegionPtr reg) {
+    return RegionBox(reg, (reg)->data->numRects);
 }
 
-#ifndef RegionNull
-#define RegionNull(_pReg) \
-    RegionInit(_pReg, NullBox, 1)
-#endif
+static inline BoxPtr RegionEnd(RegionPtr reg) {
+    return RegionBox(reg, (reg)->data->numRects - 1);
+}
 
-/* moved from mi.h */
+static inline size_t RegionSizeof(int n) {
+    return (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)));
+}
 
-extern _X_EXPORT void InitRegions (void);
+static inline void RegionInit(RegionPtr _pReg, BoxPtr _rect, int _size)
+{
+    if ((_rect) != NULL)
+    {
+        (_pReg)->extents = *(_rect);
+        (_pReg)->data = (RegDataPtr)NULL;
+    }
+    else
+    {
+        (_pReg)->extents = EmptyBox;
+        if (((_size) > 1) && ((_pReg)->data =
+			      (RegDataPtr)malloc(RegionSizeof(_size))))
+        {
+            (_pReg)->data->size = (_size);
+            (_pReg)->data->numRects = 0;
+        }
+        else
+            (_pReg)->data = &EmptyData;
+    }
+}
 
-extern _X_EXPORT RegionPtr RegionCreate(
-    BoxPtr /*rect*/,
-    int /*size*/);
+static inline void RegionUninit(RegionPtr _pReg)
+{
+    if ((_pReg)->data && (_pReg)->data->size) {
+	free((_pReg)->data);
+	(_pReg)->data = NULL;
+    }
+}
+
+static inline void RegionReset(RegionPtr _pReg, BoxPtr _pBox)
+{
+    (_pReg)->extents = *(_pBox);
+    RegionUninit(_pReg);
+    (_pReg)->data = (RegDataPtr)NULL;
+}
+
+static inline Bool RegionNotEmpty(RegionPtr _pReg) {
+    return !RegionNil(_pReg);
+}
+
+static inline Bool RegionBroken(RegionPtr _pReg) {
+    return RegionNar(_pReg);
+}
+
+static inline void RegionEmpty(RegionPtr _pReg)
+{
+    RegionUninit(_pReg);
+    (_pReg)->extents.x2 = (_pReg)->extents.x1;
+    (_pReg)->extents.y2 = (_pReg)->extents.y1;
+    (_pReg)->data = &EmptyData;
+}
 
-#ifndef RegionInit
-extern _X_EXPORT void RegionInit(
-    RegionPtr /*pReg*/,
+static inline BoxPtr RegionExtents(RegionPtr _pReg)
+{
+    return (&(_pReg)->extents);
+}
+
+static inline void RegionNull(RegionPtr _pReg)
+{
+    (_pReg)->extents = EmptyBox;
+    (_pReg)->data = &EmptyData;
+}
+
+extern _X_EXPORT void InitRegions(void);
+
+extern _X_EXPORT RegionPtr RegionCreate(
     BoxPtr /*rect*/,
     int /*size*/);
-#endif
 
 extern _X_EXPORT void RegionDestroy(
     RegionPtr /*pReg*/);
 
-#ifndef RegionUninit
-extern _X_EXPORT void RegionUninit(
-    RegionPtr /*pReg*/);
-#endif
-
-extern _X_EXPORT Bool RegionCopy(
-    RegionPtr /*dst*/,
-    RegionPtr /*src*/);
+static inline Bool
+RegionCopy(RegionPtr dst, RegionPtr src)
+{
+    return pixman_region_copy (dst, src);
+}
 
-extern _X_EXPORT Bool Intersect(
-    RegionPtr /*newReg*/,
-    RegionPtr /*reg1*/,
-    RegionPtr /*reg2*/);
+static inline Bool
+RegionIntersect(
+    RegionPtr	newReg,     /* destination Region */
+    RegionPtr	reg1,
+    RegionPtr	reg2        /* source regions     */
+    )
+{
+    return pixman_region_intersect (newReg, reg1, reg2);
+}
 
-extern _X_EXPORT Bool Union(
-    RegionPtr /*newReg*/,
-    RegionPtr /*reg1*/,
-    RegionPtr /*reg2*/);
+static inline Bool
+RegionUnion(
+    RegionPtr	newReg,          /* destination Region */
+    RegionPtr	reg1,
+    RegionPtr	reg2             /* source regions     */
+    )
+{
+    return pixman_region_union (newReg, reg1, reg2);
+}
 
 extern _X_EXPORT Bool RegionAppend(
     RegionPtr /*dstrgn*/,
@@ -246,58 +222,87 @@ extern _X_EXPORT RegionPtr RectsToRegion(
     xRectanglePtr /*prect*/,
     int /*ctype*/);
 
-extern _X_EXPORT Bool Subtract(
-    RegionPtr /*regD*/,
-    RegionPtr /*regM*/,
-    RegionPtr /*regS*/);
-
-extern _X_EXPORT Bool Inverse(
-    RegionPtr /*newReg*/,
-    RegionPtr /*reg1*/,
-    BoxPtr /*invRect*/);
-
-extern _X_EXPORT int RectIn(
-    RegionPtr /*region*/,
-    BoxPtr /*prect*/);
-
-extern _X_EXPORT void TranslateRegion(
-    RegionPtr /*pReg*/,
-    int /*x*/,
-    int /*y*/);
-
-#ifndef RegionReset
-extern _X_EXPORT void RegionReset(
-    RegionPtr /*pReg*/,
-    BoxPtr /*pBox*/);
-#endif
+/*-
+ *-----------------------------------------------------------------------
+ * Subtract --
+ *	Subtract regS from regM and leave the result in regD.
+ *	S stands for subtrahend, M for minuend and D for difference.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *	regD is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+static inline Bool
+RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
+{
+    return pixman_region_subtract (regD, regM, regS);
+}
 
-extern _X_EXPORT Bool RegionBreak(
-    RegionPtr /*pReg*/);
+/*-
+ *-----------------------------------------------------------------------
+ * Inverse --
+ *	Take a region and a box and return a region that is everything
+ *	in the box but not in the region. The careful reader will note
+ *	that this is the same as subtracting the region from the box...
+ *
+ * Results:
+ *	TRUE.
+ *
+ * Side Effects:
+ *	newReg is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
 
-extern _X_EXPORT Bool PointInRegion(
-    RegionPtr /*pReg*/,
-    int /*x*/,
-    int /*y*/,
-    BoxPtr /*box*/);
+static inline Bool
+RegionInverse(
+    RegionPtr	  newReg,       /* Destination region */
+    RegionPtr	  reg1,         /* Region to invert */
+    BoxPtr	  invRect	/* Bounding box for inversion */
+    )
+{
+    return pixman_region_inverse (newReg, reg1, invRect);
+}
 
-extern _X_EXPORT Bool RegionEqual(
-    RegionPtr /*pReg1*/,
-    RegionPtr /*pReg2*/);
+static inline int
+RectInRegion(RegionPtr region, BoxPtr prect)
+{
+    return pixman_region_contains_rectangle (region, prect);
+}
 
-#ifndef RegionNotEmpty
-extern _X_EXPORT Bool RegionNotEmpty(
-    RegionPtr /*pReg*/);
-#endif
+/* TranslateRegion(pReg, x, y)
+   translates in place
+*/
 
-#ifndef RegionEmpty
-extern _X_EXPORT void RegionEmpty(
-    RegionPtr /*pReg*/);
-#endif
+static inline void
+RegionTranslate(RegionPtr pReg, int x, int y)
+{
+    pixman_region_translate (pReg, x, y);
+}
 
-#ifndef RegionExtents
-extern _X_EXPORT BoxPtr RegionExtents(
+extern _X_EXPORT Bool RegionBreak(
     RegionPtr /*pReg*/);
-#endif
+
+static inline Bool
+PointInRegion(
+    RegionPtr pReg,
+    int x,
+    int y,
+    BoxPtr box      /* "return" value */
+    )
+{
+    return pixman_region_contains_point (pReg, x, y, box);
+}
+
+static inline Bool
+RegionEqual(RegionPtr reg1, RegionPtr reg2)
+{
+    return pixman_region_equal (reg1, reg2);
+}
 
 extern _X_EXPORT void PrintRegion(
     RegionPtr /*pReg*/);
@@ -313,10 +318,6 @@ extern _X_EXPORT Bool ValidRegion(
 );
 #endif
 
-#ifndef RegionBroken
-extern _X_EXPORT Bool RegionBroken(RegionPtr pReg);
-#endif
-
 extern _X_EXPORT int ClipSpans(
     RegionPtr /*prgnDst*/,
     DDXPointPtr /*ppt*/,
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 6f1936c..8d01438 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -590,6 +590,10 @@ typedef struct _Screen {
     DeviceCursorCleanupProcPtr    DeviceCursorCleanup;
 } ScreenRec;
 
+static inline RegionPtr BitmapToRegion(ScreenPtr _pScreen, PixmapPtr pPix) {
+    return (*(_pScreen)->BitmapToRegion)(pPix); /* no mi version?! */
+}
+
 typedef struct _ScreenInfo {
     int		imageByteOrder;
     int		bitmapScanlineUnit;
-- 
1.7.1



More information about the xorg-devel mailing list