Clean-up code, fixed a memory leak, removed dead code

This commit is contained in:
Jerry.Kirk%Nexwarecorp.com 1999-07-26 13:05:20 +00:00
Родитель 3e446b4eb2
Коммит 461c657187
2 изменённых файлов: 54 добавлений и 141 удалений

Просмотреть файл

@ -21,7 +21,6 @@
#include "nsPhGfxLog.h" #include "nsPhGfxLog.h"
static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID); static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID);
#define tulx t->rect.ul.x #define tulx t->rect.ul.x
@ -34,32 +33,19 @@ static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID);
#define clrx c->rect.lr.x #define clrx c->rect.lr.x
#define clry c->rect.lr.y #define clry c->rect.lr.y
static void MangleTiles(PhTile_t *t) /* Local debug flag, this create lots and lots of output */
{ #undef DEBUG_REGION
return;
while(t)
{
// printf("Tile %d is t=<%p> t->next=<%p> (%d, %d) - (%d,%d)\n", count,
// t, t->next, tulx, tuly, tlrx, tlry);
if (tlrx==-1 && tlry==-1)
{
printf ("drop bad tile\n");
tlrx=0; tlry=0;
}
t = t->next;
}
}
static void DumpTiles(PhTile_t *t) static void DumpTiles(PhTile_t *t)
{ {
#if 0 #ifdef DEBUG_REGION
return;
#else
int count=1; int count=1;
while(t) while(t)
{ {
printf("Tile %d is t=<%p> t->next=<%p> (%d, %d) - (%d,%d)\n", count, t, t->next, tulx, tuly, tlrx, tlry); //printf("Tile %d is t=<%p> t->next=<%p> (%d, %d) - (%d,%d)\n", count, t, t->next, tulx, tuly, tlrx, tlry);
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("Tile %d is t=<%p> t->next=<%p> (%d, %d) - (%d,%d)\n", count, t, t->next, tulx, tuly, tlrx, tlry)); PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("Tile %d is t=<%p> t->next=<%p> (%d, %d) - (%d,%d)\n", count, t, t->next, tulx, tuly, tlrx, tlry));
t = t->next; t = t->next;
count++; count++;
@ -67,29 +53,12 @@ static void DumpTiles(PhTile_t *t)
#endif #endif
} }
static PhTile_t *myIntersectTilings( PhTile_t const * const tile1, PhTile_t const *tile2, unsigned short *num_intersect_tiles )
{
PhTile_t *dupt1, *intersection = NULL;
dupt1 = PhCopyTiles( tile1 );
if (( dupt1 = PhClipTilings( dupt1, tile2, &intersection ) ) != NULL )
{
PhFreeTiles( dupt1 );
}
/*
if ( num_intersect_tiles )
for ( dupt1 = intersection,*num_intersect_tiles = 0; dupt1; *num_intersect_tiles++,dupt1 = dupt1->next );
*/
return(intersection);
}
nsRegionPh :: nsRegionPh() nsRegionPh :: nsRegionPh()
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
SetRegionEmpty();
mRegion = NULL;
mRegionType = eRegionComplexity_empty;
} }
@ -97,6 +66,10 @@ nsRegionPh :: ~nsRegionPh()
{ {
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::~nsRegion Destructor called\n")); PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::~nsRegion Destructor called\n"));
#ifdef DEBUG_REGION
DumpTiles(mRegion);
#endif
if (mRegion) if (mRegion)
PhFreeTiles(mRegion); PhFreeTiles(mRegion);
} }
@ -152,7 +125,7 @@ void nsRegionPh :: Intersect(const nsIRegion &aRegion)
PhTile_t *tiles; PhTile_t *tiles;
aRegion.GetNativeRegion((void*&)tiles); aRegion.GetNativeRegion((void*&)tiles);
mRegion = myIntersectTilings(orig_Tiles, tiles, NULL); mRegion = PhIntersectTilings(orig_Tiles, tiles, NULL);
if (mRegion) if (mRegion)
{ {
mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion ))); mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
@ -175,7 +148,7 @@ void nsRegionPh :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHe
tile->next = NULL; tile->next = NULL;
PhTile_t *orig_Tiles = mRegion; PhTile_t *orig_Tiles = mRegion;
mRegion = myIntersectTilings(mRegion, tile, NULL); mRegion = PhIntersectTilings(mRegion, tile, NULL);
} }
else else
{ {
@ -242,14 +215,8 @@ void nsRegionPh :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHei
tile->rect.lr.y = (aY+aHeight-1); tile->rect.lr.y = (aY+aHeight-1);
tile->next = NULL; tile->next = NULL;
/* //printf ("subtract: %d %d %d %d\n", tile->rect.ul.x, tile->rect.ul.y, tile->rect.lr.x, tile->rect.lr.y);
printf ("subtract: %d %d %d %d\n",
tile->rect.ul.x,
tile->rect.ul.y,
tile->rect.lr.x,
tile->rect.lr.y
);
*/
mRegion = PhClipTilings(mRegion, tile, NULL); mRegion = PhClipTilings(mRegion, tile, NULL);
} }
} }
@ -262,34 +229,8 @@ PRBool nsRegionPh :: IsEmpty(void)
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::IsEmpty mRegion=<%p>\n", mRegion)); PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::IsEmpty mRegion=<%p>\n", mRegion));
if (!mRegion) if (!mRegion)
return PR_TRUE; result = PR_TRUE;
#if 0
MangleTiles(mRegion);
mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
PhTile_t *t = mRegion;
// DumpTiles(t);
while(t)
{
/* if width is not 0 then it is not empty */
// if (tlrx - tulx)
if ((tlrx - tulx)>0)
{
result = PR_FALSE;
// printf ("should be false! (not empty)\n");
break;
}
t = t->next;
}
#endif
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::IsEmpty Result=<%d>\n", result));
return result; return result;
} }
@ -376,61 +317,33 @@ void nsRegionPh :: Offset(PRInt32 aXOffset, PRInt32 aYOffset)
PRBool nsRegionPh :: ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) PRBool nsRegionPh :: ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{ {
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::ContainsRect mRegion=<%p> (%d,%d) -> (%d,%d)\n", mRegion, aX, aY, aWidth, aHeight)); PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::ContainsRect mRegion=<%p> (%d,%d) -> (%d,%d)\n", mRegion, aX, aY, aWidth, aHeight));
#if 1
if (mRegion)
{
mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
/* Create a temporary tile to assign to mRegion */
PhTile_t *tile = PhGetTile();
tile->rect.ul.x = aX;
tile->rect.ul.y = aY;
tile->rect.lr.x = (aX+aWidth-1);
tile->rect.lr.y = (aY+aHeight-1);
tile->next = NULL;
if (tile->rect.lr.x == -1) printf ("problem 5\n");
//printf ("testing: %d %d %d %d\n",aX,aY,aWidth,aHeight);
PhTile_t *test;
test = myIntersectTilings(tile, mRegion, NULL);
/*
if (test)
{
PhTile_t *t = test;
printf ("testing done: %d %d %d %d\n",tulx,tuly,tlrx,tlry);
}
*/
if (test) return PR_TRUE; else return PR_FALSE;
}
else return PR_FALSE;
#else
//kedl, jerry's stuff below
PRBool ret = PR_FALSE;
if (mRegion) if (mRegion)
{
mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion ))); mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
PhTile_t *t = mRegion; /* Create a temporary tile to assign to mRegion */
while(t) PhTile_t *tile = PhGetTile();
{ tile->rect.ul.x = aX;
if ( tile->rect.ul.y = aY;
(tulx <= aX) && tile->rect.lr.x = (aX+aWidth-1);
(tuly <= aY) && tile->rect.lr.y = (aY+aHeight-1);
(tlrx >= (aX+aWidth-1)) && tile->next = NULL;
(tlry >= (aY+aHeight-1))
)
{
ret = PR_TRUE;
break;
}
t = t->next; if (tile->rect.lr.x == -1)
} PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::ContainsRect problem 5\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::ContainsRect returning %d\n", ret)); PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("testing: %d %d %d %d\n",aX,aY,aWidth,aHeight));
return ret; PhTile_t *test;
#endif test = PhIntersectTilings(tile, mRegion, NULL);
if (test)
return PR_TRUE;
else
return PR_FALSE;
}
else
return PR_FALSE;
} }
@ -471,17 +384,14 @@ NS_IMETHODIMP nsRegionPh :: GetRects(nsRegionRectSet **aRects)
} }
rects->mNumRects = nbox; rects->mNumRects = nbox;
// rects->mNumRects = nbox+1;
rects->mArea = 0; rects->mArea = 0;
rect = &rects->mRects[0]; rect = &rects->mRects[0];
t = mRegion; /* Reset tile indexer */ t = mRegion; /* Reset tile indexer */
// crap rect->x = 0;
rect->x = 0; rect->width = 0;
rect->width = 0; rect->y = 0;
rect->y = 0; rect->height = 0;
rect->height = 0;
// rect++;
while (nbox--) while (nbox--)
{ {
@ -490,12 +400,12 @@ NS_IMETHODIMP nsRegionPh :: GetRects(nsRegionRectSet **aRects)
rect->y = tuly; rect->y = tuly;
rect->height = (tlry - tuly+1); rect->height = (tlry - tuly+1);
rects->mArea += rect->width * rect->height; rects->mArea += rect->width * rect->height;
//printf ("getrect: %d %d %d %d\n",rect->x,rect->y,rect->width,rect->height); //printf ("getrect: %d %d %d %d\n",rect->x,rect->y,rect->width,rect->height);
rect++; rect++;
t = t->next; t = t->next;
} }
//printf ("num rects %d %d\n",rects->mNumRects,rects->mRectsLen); fflush(stdout); //printf ("num rects %d %d\n",rects->mNumRects,rects->mRectsLen); fflush(stdout);
*aRects = rects; *aRects = rects;
return NS_OK; return NS_OK;
} }
@ -514,7 +424,7 @@ NS_IMETHODIMP nsRegionPh :: FreeRects(nsRegionRectSet *aRects)
NS_IMETHODIMP nsRegionPh :: GetNativeRegion(void *&aRegion) const NS_IMETHODIMP nsRegionPh :: GetNativeRegion(void *&aRegion) const
{ {
// PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::GetNativeRegion mRegion=<%p>\n", mRegion)); //PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::GetNativeRegion mRegion=<%p>\n", mRegion));
aRegion = (void *) mRegion; aRegion = (void *) mRegion;
return NS_OK; return NS_OK;
} }
@ -532,10 +442,13 @@ void nsRegionPh :: SetRegionEmpty(void)
{ {
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::SetRegionEmpty mRegion=<%p>\n", mRegion)); PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::SetRegionEmpty mRegion=<%p>\n", mRegion));
// if (mRegion) #ifdef DEBUG_REGION
// PhFreeTiles(mRegion); DumpTiles(mRegion);
#endif
if (mRegion)
PhFreeTiles(mRegion);
mRegion = NULL; mRegion = NULL;
mRegionType = eRegionComplexity_empty; mRegionType = eRegionComplexity_empty;
} }

Просмотреть файл

@ -54,7 +54,7 @@ private:
virtual void SetRegionEmpty(); virtual void SetRegionEmpty();
PhTile_t *mRegion; PhTile_t *mRegion;
nsRegionComplexity mRegionType; nsRegionComplexity mRegionType; // Not really used!
}; };
#endif // nsRegionPh_h___ #endif // nsRegionPh_h___