Commit 4a8d6eca authored by Mike Gabriel's avatar Mike Gabriel

Change region implementation from macros to inline functions.

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. v1: Keith Packard <keithp@keithp.com> v2: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
parent 63f1fff8
...@@ -295,7 +295,7 @@ extern int Ones( ...@@ -295,7 +295,7 @@ extern int Ones(
unsigned long /*mask*/); unsigned long /*mask*/);
typedef struct _xPoint *DDXPointPtr; typedef struct _xPoint *DDXPointPtr;
typedef struct _Box *BoxPtr; typedef struct pixman_box16 *BoxPtr;
typedef struct _xEvent *xEventPtr; typedef struct _xEvent *xEventPtr;
typedef struct _xRectangle *xRectanglePtr; typedef struct _xRectangle *xRectanglePtr;
typedef struct _GrabRec *GrabPtr; typedef struct _GrabRec *GrabPtr;
......
...@@ -50,15 +50,15 @@ SOFTWARE. ...@@ -50,15 +50,15 @@ SOFTWARE.
#ifndef MISCSTRUCT_H #ifndef MISCSTRUCT_H
#define MISCSTRUCT_H 1 #define MISCSTRUCT_H 1
#include <pixman.h>
#include "misc.h" #include "misc.h"
#include <nx-X11/Xprotostr.h> #include <nx-X11/Xprotostr.h>
#include "gc.h" #include "gc.h"
typedef xPoint DDXPointRec; typedef xPoint DDXPointRec;
typedef struct _Box { typedef struct pixman_box16 BoxRec;
short x1, y1, x2, y2;
} BoxRec;
typedef union _DevUnion { typedef union _DevUnion {
void * ptr; void * ptr;
......
...@@ -51,7 +51,9 @@ SOFTWARE. ...@@ -51,7 +51,9 @@ SOFTWARE.
#ifndef REGIONSTRUCT_H #ifndef REGIONSTRUCT_H
#define REGIONSTRUCT_H #define REGIONSTRUCT_H
typedef struct _Region RegionRec, *RegionPtr; #include <pixman.h>
typedef struct pixman_region16 RegionRec, *RegionPtr;
#include <stddef.h> #include <stddef.h>
#include <limits.h> #include <limits.h>
...@@ -70,261 +72,218 @@ typedef struct _Region RegionRec, *RegionPtr; ...@@ -70,261 +72,218 @@ typedef struct _Region RegionRec, *RegionPtr;
* clip region * clip region
*/ */
typedef struct _RegData { typedef struct pixman_region16_data RegDataRec, *RegDataPtr;
long size;
long numRects;
/* BoxRec rects[size]; in memory but not explicitly declared */
} RegDataRec, *RegDataPtr;
struct _Region {
BoxRec extents;
RegDataPtr data;
};
extern BoxRec miEmptyBox; extern BoxRec miEmptyBox;
extern RegDataRec miEmptyData; extern RegDataRec miEmptyData;
extern RegDataRec miBrokenData; extern RegDataRec miBrokenData;
#define REGION_NIL(reg) ((reg)->data && !(reg)->data->numRects) static inline Bool RegionNil(RegionPtr reg) {
/* not a region */ return ((reg)->data && !(reg)->data->numRects);
#define REGION_NAR(reg) ((reg)->data == &miBrokenData) }
#define REGION_NUM_RECTS(reg) ((reg)->data ? (reg)->data->numRects : 1)
#define REGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0)
#define REGION_RECTS(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
: &(reg)->extents)
#define REGION_BOXPTR(reg) ((BoxPtr)((reg)->data + 1))
#define REGION_BOX(reg,i) (&REGION_BOXPTR(reg)[i])
#define REGION_TOP(reg) REGION_BOX(reg, (reg)->data->numRects)
#define REGION_END(reg) REGION_BOX(reg, (reg)->data->numRects - 1)
#define REGION_SZOF(n) (n < ((INT_MAX - sizeof(RegDataRec)) / sizeof(BoxRec)) ? sizeof(RegDataRec) + ((n) * sizeof(BoxRec)) : 0)
/* Keith recommends weaning the region code of pScreen argument */
#define REG_pScreen screenInfo.screens[0]
#ifdef NEED_SCREEN_REGIONS
#define RegionCreate(_rect, _size) \
(*(REG_pScreen)->RegionCreate)(_rect, _size)
#define RegionInit(_pReg, _rect, _size) \
(*(REG_pScreen)->RegionInit)(_pReg, _rect, _size)
#define RegionCopy(dst, src) \
(*(REG_pScreen)->RegionCopy)(dst, src)
#define RegionDestroy(_pReg) \
(*(REG_pScreen)->RegionDestroy)(_pReg)
#define RegionUninit(_pReg) \
(*(REG_pScreen)->RegionUninit)(_pReg)
#define RegionIntersect(newReg, reg1, reg2) \
(*(REG_pScreen)->Intersect)(newReg, reg1, reg2)
#define RegionUnion(newReg, reg1, reg2) \
(*(REG_pScreen)->Union)(newReg, reg1, reg2)
#define RegionSubtract(newReg, reg1, reg2) \
(*(REG_pScreen)->Subtract)(newReg, reg1, reg2)
#define RegionInverse(newReg, reg1, invRect) \
(*(REG_pScreen)->Inverse)(newReg, reg1, invRect)
#define RegionReset(_pReg, _pBox) \
(*(REG_pScreen)->RegionReset)(_pReg, _pBox)
#define RegionTranslate(_pReg, _x, _y) \
(*(REG_pScreen)->TranslateRegion)(_pReg, _x, _y)
#define RegionContainsRect(_pReg, prect) \
(*(REG_pScreen)->RectIn)(_pReg, prect)
#define RegionContainsPoint(_pReg, _x, _y, prect) \
(*(REG_pScreen)->PointInRegion)(_pReg, _x, _y, prect)
#define RegionNotEmpty(_pReg) \
(*(REG_pScreen)->RegionNotEmpty)(_pReg)
#define RegionEqual(_pReg1, _pReg2) \
(*(REG_pScreen)->RegionEqual)(_pReg1, _pReg2)
#define RegionBroken(_pReg) \
(*(REG_pScreen)->RegionBroken)(_pReg)
#define RegionBreak(_pReg) \
(*(REG_pScreen)->RegionBreak)(_pReg)
#define RegionEmpty(_pReg) \
(*(REG_pScreen)->RegionEmpty)(_pReg)
#define RegionExtents(_pReg) \
(*(REG_pScreen)->RegionExtents)(_pReg)
#define RegionAppend(dstrgn, rgn) \
(*(REG_pScreen)->RegionAppend)(dstrgn, rgn)
#define RegionValidate(badreg, pOverlap) \
(*(REG_pScreen)->RegionValidate)(badreg, pOverlap)
#define BITMAP_TO_REGION(_pScreen, pPix) \
(*(REG_pScreen)->BitmapToRegion)(pPix)
#define RegionFromRects(nrects, prect, ctype) \
(*(REG_pScreen)->RectsToRegion)(nrects, prect, ctype)
#else /* !NEED_SCREEN_REGIONS */
/* Reference _pScreen macro argument and check its type */
#define REGION_SCREEN(_pScreen) (void)((REG_pScreen)->myNum)
#define RegionCreate(_rect, _size) \
(REGION_SCREEN(_pScreen), miRegionCreate(_rect, _size))
#define RegionCopy(dst, src) \
(REGION_SCREEN(_pScreen), miRegionCopy(dst, src))
#define RegionDestroy(_pReg) \
(REGION_SCREEN(_pScreen), miRegionDestroy(_pReg))
#define RegionIntersect(newReg, reg1, reg2) \
(REGION_SCREEN(_pScreen), miIntersect(newReg, reg1, reg2))
#define RegionUnion(newReg, reg1, reg2) \
(REGION_SCREEN(_pScreen), miUnion(newReg, reg1, reg2))
#define RegionSubtract(newReg, reg1, reg2) \
(REGION_SCREEN(_pScreen), miSubtract(newReg, reg1, reg2))
#define RegionInverse(newReg, reg1, invRect) \
(REGION_SCREEN(_pScreen), miInverse(newReg, reg1, invRect))
#define RegionTranslate(_pReg, _x, _y) \
(REGION_SCREEN(_pScreen), miTranslateRegion(_pReg, _x, _y))
#define RegionContainsRect(_pReg, prect) \
(REGION_SCREEN(_pScreen), miRectIn(_pReg, prect))
#define RegionContainsPoint(_pReg, _x, _y, prect) \
(REGION_SCREEN(_pScreen), miPointInRegion(_pReg, _x, _y, prect))
#define RegionAppend(dstrgn, rgn) \
(REGION_SCREEN(_pScreen), miRegionAppend(dstrgn, rgn))
#define RegionValidate(badreg, pOverlap) \ static inline Bool RegionNar(RegionPtr reg) {
(REGION_SCREEN(_pScreen), miRegionValidate(badreg, pOverlap)) return ((reg)->data == &miBrokenData);
}
#define BITMAP_TO_REGION(_pScreen, pPix) \ static inline int RegionNumRects(RegionPtr reg) {
(*(_pScreen)->BitmapToRegion)(pPix) /* no mi version?! */ return ((reg)->data ? (reg)->data->numRects : 1);
}
#define RegionFromRects(nrects, prect, ctype) \ static inline int RegionSize(RegionPtr reg) {
(REGION_SCREEN(_pScreen), miRectsToRegion(nrects, prect, ctype)) return ((reg)->data ? (reg)->data->size : 0);
}
#define RegionEqual(_pReg1, _pReg2) \ static inline BoxPtr RegionRects(RegionPtr reg) {
(REGION_SCREEN(_pScreen), miRegionEqual(_pReg1, _pReg2)) return ((reg)->data ? (BoxPtr)((reg)->data + 1) : &(reg)->extents);
}
#define RegionBreak(_pReg) \ static inline BoxPtr RegionBoxptr(RegionPtr reg) {
(REGION_SCREEN(_pScreen), miRegionBreak(_pReg)) return ((BoxPtr)((reg)->data + 1));
}
#ifdef DONT_INLINE_REGION_OPS static inline BoxPtr RegionBox(RegionPtr reg, int i) {
return (&RegionBoxptr(reg)[i]);
}
#define RegionInit(_pReg, _rect, _size) \ static inline BoxPtr RegionTop(RegionPtr reg) {
(REGION_SCREEN(_pScreen), miRegionInit(_pReg, _rect, _size)) return RegionBox(reg, (reg)->data->numRects);
}
#define RegionUninit(_pReg) \ static inline BoxPtr RegionEnd(RegionPtr reg) {
(REGION_SCREEN(_pScreen), miRegionUninit(_pReg)) return RegionBox(reg, (reg)->data->numRects - 1);
}
#define RegionReset(_pReg, _pBox) \ static inline size_t RegionSizeof(int n) {
(REGION_SCREEN(_pScreen), miRegionReset(_pReg, _pBox)) return (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)));
}
#define RegionNotEmpty(_pReg) \ static inline void RegionInit(RegionPtr _pReg, BoxPtr _rect, int _size)
(REGION_SCREEN(_pScreen), miRegionNotEmpty(_pReg)) {
if ((_rect) != NULL)
{
(_pReg)->extents = *(_rect);
(_pReg)->data = (RegDataPtr)NULL;
}
else
{
(_pReg)->extents = miEmptyBox;
if (((_size) > 1) && ((_pReg)->data =
(RegDataPtr)malloc(RegionSizeof(_size))))
{
(_pReg)->data->size = (_size);
(_pReg)->data->numRects = 0;
}
else
(_pReg)->data = &miEmptyData;
}
}
#define RegionBroken(_pReg) \ static inline void RegionUninit(RegionPtr _pReg)
(REGION_SCREEN(_pScreen), miRegionBroken(_pReg)) {
if ((_pReg)->data && (_pReg)->data->size) {
free((_pReg)->data);
(_pReg)->data = NULL;
}
}
#define RegionEmpty(_pReg) \ static inline void RegionReset(RegionPtr _pReg, BoxPtr _pBox)
(REGION_SCREEN(_pScreen), miRegionEmpty(_pReg)) {
(_pReg)->extents = *(_pBox);
RegionUninit(_pReg);
(_pReg)->data = (RegDataPtr)NULL;
}
#define RegionExtents(_pReg) \ static inline Bool RegionNotEmpty(RegionPtr _pReg) {
(REGION_SCREEN(_pScreen), miRegionExtents(_pReg)) return !RegionNil(_pReg);
}
#else /* inline certain simple region ops for performance */ static inline Bool RegionBroken(RegionPtr _pReg) {
return RegionNar(_pReg);
}
#define RegionInit(_pReg, _rect, _size) \ static inline void RegionEmpty(RegionPtr _pReg)
{ \ {
REGION_SCREEN(_pScreen); \ RegionUninit(_pReg);
if (_rect) \ (_pReg)->extents.x2 = (_pReg)->extents.x1;
{ \ (_pReg)->extents.y2 = (_pReg)->extents.y1;
(_pReg)->extents = *(_rect); \ (_pReg)->data = &miEmptyData;
(_pReg)->data = (RegDataPtr)NULL; \ }
} \
else \
{ \
size_t rgnSize; \
(_pReg)->extents = miEmptyBox; \
if (((_size) > 1) && ((rgnSize = REGION_SZOF(_size)) > 0) && \
((_pReg)->data = (RegDataPtr)xalloc(rgnSize))) \
{ \
(_pReg)->data->size = (_size); \
(_pReg)->data->numRects = 0; \
} \
else \
(_pReg)->data = &miEmptyData; \
} \
}
static inline BoxPtr RegionExtents(RegionPtr _pReg)
{
return (&(_pReg)->extents);
}
#define RegionUninit(_pReg) \ static inline void RegionNull(RegionPtr _pReg)
{ \ {
REGION_SCREEN(_pScreen); \ (_pReg)->extents = miEmptyBox;
if ((_pReg)->data && (_pReg)->data->size) { \ (_pReg)->data = &miEmptyData;
xfree((_pReg)->data); \
(_pReg)->data = NULL; \
} \
} }
#define RegionReset(_pReg, _pBox) \ static inline Bool
{ \ RegionCopy(RegionPtr dst, RegionPtr src)
REGION_SCREEN(_pScreen); \ {
(_pReg)->extents = *(_pBox); \ return pixman_region_copy (dst, src);
RegionUninit(_pReg); \
(_pReg)->data = (RegDataPtr)NULL; \
} }
#define RegionNotEmpty(_pReg) \ static inline Bool
(REGION_SCREEN(_pScreen), !REGION_NIL(_pReg)) RegionIntersect(
RegionPtr newReg, /* destination Region */
RegionPtr reg1,
RegionPtr reg2 /* source regions */
)
{
return pixman_region_intersect (newReg, reg1, reg2);
}
#define RegionBroken(_pReg) \ static inline Bool
(REGION_SCREEN(_pScreen), REGION_NAR(_pReg)) RegionUnion(
RegionPtr newReg, /* destination Region */
RegionPtr reg1,
RegionPtr reg2 /* source regions */
)
{
return pixman_region_union (newReg, reg1, reg2);
}
#define RegionEmpty(_pReg) \ /*
{ \ *-----------------------------------------------------------------------
RegionUninit(_pReg); \ * Subtract --
(_pReg)->extents.x2 = (_pReg)->extents.x1; \ * Subtract regS from regM and leave the result in regD.
(_pReg)->extents.y2 = (_pReg)->extents.y1; \ * S stands for subtrahend, M for minuend and D for difference.
(_pReg)->data = &miEmptyData; \ *
* 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);
} }
#define RegionExtents(_pReg) \ /*
(REGION_SCREEN(_pScreen), &(_pReg)->extents) *-----------------------------------------------------------------------
* 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.
*
*-----------------------------------------------------------------------
*/
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);
}
#define RegionNull(_pReg) \ static inline int
{ \ RegionContainsRect(RegionPtr region, BoxPtr prect)
REGION_SCREEN(_pScreen); \ {
(_pReg)->extents = miEmptyBox; \ return pixman_region_contains_rectangle (region, prect);
(_pReg)->data = &miEmptyData; \
} }
#endif /* DONT_INLINE_REGION_OPS */ /* TranslateRegion(pReg, x, y)
* translates in place
*/
#endif /* NEED_SCREEN_REGIONS */ static inline void
RegionTranslate(RegionPtr pReg, int x, int y)
{
pixman_region_translate (pReg, x, y);
}
#ifndef RegionNull static inline Bool
#define RegionNull(_pReg) \ RegionContainsPoint(
RegionInit(_pReg, NullBox, 1) RegionPtr pReg,
#endif int x,
int y,
BoxPtr box /* "return" value */
)
{
return pixman_region_contains_point (pReg, x, y, box);
}
/* moved from mi.h */ static inline Bool
RegionEqual(RegionPtr reg1, RegionPtr reg2)
{
return pixman_region_equal (reg1, reg2);
}
extern RegionPtr miRegionCreate( extern RegionPtr miRegionCreate(
BoxPtr /*rect*/, BoxPtr /*rect*/,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment