Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsRegionPh Class Reference

#include <nsRegionPh.h>

Inheritance diagram for nsRegionPh:
Inheritance graph
[legend]
Collaboration diagram for nsRegionPh:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsRegionPh ()
 nsRegionPh (PhTile_t *tiles)
virtual ~nsRegionPh ()
virtual NS_DECL_ISUPPORTS nsresult Init ()
virtual void SetTo (const nsIRegion &aRegion)
 copy operator equivalent that takes another region
virtual void SetTo (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 copy operator equivalent that takes a rect
virtual void Intersect (const nsIRegion &aRegion)
 destructively intersect another region with this one
virtual void Intersect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively intersect a rect with this region
virtual void Union (const nsIRegion &aRegion)
 destructively union another region with this one
virtual void Union (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively union a rect with this region
virtual void Subtract (const nsIRegion &aRegion)
 destructively subtract another region with this one
virtual void Subtract (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively subtract a rect from this region
virtual PRBool IsEmpty (void)
 is this region empty? i.e.
virtual PRBool IsEqual (const nsIRegion &aRegion)
 == operator equivalent i.e.
virtual void GetBoundingBox (PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
 returns the bounding box of the region i.e.
virtual void Offset (PRInt32 aXOffset, PRInt32 aYOffset)
 offsets the region in x and y
virtual PRBool ContainsRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 does the region intersect the rectangle?
NS_IMETHOD GetRects (nsRegionRectSet **aRects)
 get the set of rects which make up this region.
NS_IMETHODIMP FreeRects (nsRegionRectSet *aRects)
 Free a rect set returned by GetRects.
NS_IMETHODIMP GetNativeRegion (void *&aRegion) const
 Get the native region that this nsIRegion represents.
NS_IMETHODIMP GetRegionComplexity (nsRegionComplexity &aComplexity) const
 Get the complexity of the region as defined by the nsRegionComplexity enum.
NS_IMETHOD GetNumRects (PRUint32 *aRects) const
 get the number of rects which make up this region.

Private Member Functions

virtual void SetRegionEmpty ()

Private Attributes

PhTile_t * mRegion
nsRegionComplexity mRegionType

Detailed Description

Definition at line 45 of file nsRegionPh.h.


Constructor & Destructor Documentation

nsRegionPh::nsRegionPh ( ) [inline]

Definition at line 48 of file nsRegionPh.h.

nsRegionPh::nsRegionPh ( PhTile_t *  tiles) [inline]

Definition at line 54 of file nsRegionPh.h.

              {
              mRegion = tiles; /* assume ownership */
              mRegionType = (mRegion == NULL) ? eRegionComplexity_empty : eRegionComplexity_complex;
              }
virtual nsRegionPh::~nsRegionPh ( ) [inline, virtual]

Definition at line 60 of file nsRegionPh.h.

              {
              if( mRegion ) PhFreeTiles( mRegion );
              mRegion = nsnull;
              }

Member Function Documentation

PRBool nsRegionPh::ContainsRect ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

does the region intersect the rectangle?

Parameters:
rectto check for containment
Returns:
true if the region intersects the rect

Implements nsIRegion.

Definition at line 138 of file nsRegionPh.cpp.

                                                                                           {
  if( !mRegion ) return PR_FALSE;

       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;

       PhTile_t *test;
       test = PhIntersectTilings( tile, mRegion, NULL );

       PhFreeTiles( tile );

       if( test ) {
              PhFreeTiles( test );
              return PR_TRUE;
              }
       else return PR_FALSE;
       }
NS_IMETHODIMP nsRegionPh::FreeRects ( nsRegionRectSet aRects) [inline, virtual]

Free a rect set returned by GetRects.

Parameters:
aRectsrects to free
Returns:
error status

Implements nsIRegion.

Definition at line 184 of file nsRegionPh.h.

              {
              if( nsnull != aRects ) PR_Free( ( void * )aRects );
              return NS_OK;
              }
void nsRegionPh::GetBoundingBox ( PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight 
) [virtual]

returns the bounding box of the region i.e.

the smallest rectangle that completely contains the region.

Parameters:
aXout parameter for xoffset of bounding rect for region
aYout parameter for yoffset of bounding rect for region
aWidthout parameter for width of bounding rect for region
aHeightout parameter for height of bounding rect for region
Returns:
void

Implements nsIRegion.

Definition at line 107 of file nsRegionPh.cpp.

                                                                                               {

       /* 99.99% there is only one tile - so simplify things, while allow the general case to work as well */
       if( mRegion && !mRegion->next ) {
              *aX = mRegion->rect.ul.x;
              *aY = mRegion->rect.ul.y;
              *aWidth = mRegion->rect.lr.x - mRegion->rect.ul.x + 1;
              *aHeight = mRegion->rect.lr.y - mRegion->rect.ul.y + 1;
              return;
              }

  int bX=-32767, bY=-32767;

  *aX = 32767; //0
  *aY = 32767; //0

       PhTile_t *t = mRegion;

       while( t ) {
              *aX = PR_MIN( *aX, tulx );
              *aY = PR_MIN( *aY, tuly );
              bX = PR_MAX( bX, tlrx );
              bY = PR_MAX( bY, tlry );     
              t = t->next;   
              }

       *aWidth =  bX - *aX + 1;
       *aHeight = bY - *aY + 1;
       }
NS_IMETHODIMP nsRegionPh::GetNativeRegion ( void *&  aRegion) const [inline, virtual]

Get the native region that this nsIRegion represents.

Parameters:
aRegionout parameter for native region handle
Returns:
error status

Implements nsIRegion.

Definition at line 190 of file nsRegionPh.h.

              {
              aRegion = (void *) mRegion;
              return NS_OK;
              }
NS_IMETHOD nsRegionPh::GetNumRects ( PRUint32 aRects) const [inline, virtual]

get the number of rects which make up this region.

Parameters:
aRectsout parameter containing the number of rects comprising the region
Returns:
error status

Implements nsIRegion.

Definition at line 202 of file nsRegionPh.h.

{ *aRects = 0; return NS_OK; }

get the set of rects which make up this region.

the aRects parameter must be freed by calling FreeRects before the region is deleted. aRects may be passed in again when requesting the rect list as a recycling method.

Parameters:
aRectsout parameter containing set of rects comprising the region
Returns:
error status

Implements nsIRegion.

Definition at line 164 of file nsRegionPh.cpp.

                                                               {

       /* 99.99% there is only one tile - so simplify things, while allow the general case to work as well */
       if( mRegion && !mRegion->next ) {
              if( *aRects == nsnull ) *aRects = ( nsRegionRectSet * ) PR_Malloc( sizeof( nsRegionRectSet ) );
              nsRegionRect *rect = (*aRects)->mRects;
              (*aRects)->mRectsLen = (*aRects)->mNumRects = 1;
              rect->x = mRegion->rect.ul.x;
              rect->y = mRegion->rect.ul.y;
              rect->width = mRegion->rect.lr.x - mRegion->rect.ul.x + 1;
              rect->height = mRegion->rect.lr.y - mRegion->rect.ul.y + 1;
              (*aRects)->mArea = rect->width * rect->height;
              return NS_OK;
              }

       /* the general case - old code */
  nsRegionRectSet   *rects;
  int               nbox = 0;
  nsRegionRect      *rect;
  PhTile_t            *t = mRegion;

  while( t ) { nbox++; t = t->next; } /* Count the Tiles */

  rects = *aRects;

  if ((nsnull == rects) || (rects->mRectsLen < (PRUint32) nbox)) {
    void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));//was -1
    if (nsnull == buf) {
      if (nsnull != rects) rects->mNumRects = 0;
      return NS_OK;
       }
                
    rects = (nsRegionRectSet *) buf;
    rects->mRectsLen = nbox;
       }

  rects->mNumRects = nbox;
  rects->mArea = 0;
  rect = &rects->mRects[0];
  t = mRegion;                  /* Reset tile indexer */

  while( nbox-- ) {
    rect->x = tulx;
    rect->width = (tlrx - tulx+1);
              rect->y = tuly;
    rect->height = (tlry - tuly+1);                                                                               
    rects->mArea += rect->width * rect->height;
    rect++;
    t = t->next;
       }
 
  *aRects = rects;
  return NS_OK;
       }

Here is the call graph for this function:

NS_IMETHODIMP nsRegionPh::GetRegionComplexity ( nsRegionComplexity aComplexity) const [inline, virtual]

Get the complexity of the region as defined by the nsRegionComplexity enum.

Parameters:
aComplexityout parameter for region complexity
Returns:
error status

Implements nsIRegion.

Definition at line 196 of file nsRegionPh.h.

              {
              aComplexity = mRegionType;
              return NS_OK;
              }
virtual NS_DECL_ISUPPORTS nsresult nsRegionPh::Init ( void  ) [inline, virtual]

Implements nsIRegion.

Definition at line 68 of file nsRegionPh.h.

              {
              SetRegionEmpty();
              return NS_OK;
              }

Here is the call graph for this function:

virtual void nsRegionPh::Intersect ( const nsIRegion aRegion) [inline, virtual]

destructively intersect another region with this one

Parameters:
regionto intersect
Returns:
void

Implements nsIRegion.

Definition at line 98 of file nsRegionPh.h.

              {
       PhTile_t *original = mRegion;
       PhTile_t *tiles;
       aRegion.GetNativeRegion( ( void*& ) tiles );
       mRegion = PhIntersectTilings( original, tiles, NULL);
       if( mRegion )
         mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
       PhFreeTiles( original );
       if ( mRegion == NULL )
         SetTo(0, 0, 1, 1);
              }

Here is the call graph for this function:

void nsRegionPh::Intersect ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

destructively intersect a rect with this region

Parameters:
aXxoffset of rect to intersect with region
aYyoffset of rect to intersect with region
aWidthwidth of rect to intersect with region
aHeightheight of rect to intersect with region
Returns:
void

Implements nsIRegion.

Definition at line 60 of file nsRegionPh.cpp.

{
       if( aWidth > 0 && aHeight > 0 ) {
              /* Create a temporary tile to  assign to mRegion */
              PhTile_t tile;
              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;
    
              PhTile_t *original = mRegion;
              mRegion = PhIntersectTilings( mRegion, &tile, NULL );
              PhFreeTiles( original );
              if ( mRegion == NULL )
                     SetTo(0, 0, 1, 1);
       }
       else 
              SetRegionEmpty();
}
virtual PRBool nsRegionPh::IsEmpty ( void  ) [inline, virtual]

is this region empty? i.e.

does it contain any pixels

Parameters:
none
Returns:
returns whether the region is empty

Implements nsIRegion.

Definition at line 157 of file nsRegionPh.h.

              {
              if ( !mRegion )
                return PR_TRUE;
              if ( mRegion->rect.ul.x == 0 && mRegion->rect.ul.y == 0 &&
                mRegion->rect.lr.x == 0 && mRegion->rect.lr.y == 0 )
                return PR_TRUE;
              return PR_FALSE;
              }
PRBool nsRegionPh::IsEqual ( const nsIRegion aRegion) [virtual]

== operator equivalent i.e.

do the regions contain exactly the same pixels

Parameters:
regionto compare
Returns:
whether the regions are identical

Implements nsIRegion.

Definition at line 82 of file nsRegionPh.cpp.

                                                       {
  PRBool result = PR_TRUE;
  PhTile_t *tiles;
  aRegion.GetNativeRegion((void*&)tiles);

  /* If both are equal/NULL then it is equal */
  if( mRegion == tiles ) return PR_TRUE;
  else if( mRegion == NULL || tiles == NULL ) return PR_FALSE;
    
  PhSortTiles( mRegion );
  PhSortTiles( tiles );

  PhTile_t *t = mRegion, *c = tiles;
  while( t ) {
    if( tulx != culx || tuly != culy || tlrx != clrx || tlry != clry ) {
      result = PR_FALSE;
      break;  
                     }
    t = t->next;  
    c = c->next;
       }
  return result;
       }

Here is the call graph for this function:

virtual void nsRegionPh::Offset ( PRInt32  aXOffset,
PRInt32  aYOffset 
) [inline, virtual]

offsets the region in x and y

Parameters:
xoffsetpixel offset in x
yoffsetpixel offset in y
Returns:
void

Implements nsIRegion.

Definition at line 170 of file nsRegionPh.h.

              {
       if( ( aXOffset || aYOffset ) && mRegion ) {
         PhPoint_t p = { aXOffset, aYOffset };

         /* 99.99% there is only one tile - so simplify things, while allow the general case to work as well */
         if( !mRegion->next ) PtTranslateRect( &mRegion->rect, &p );
         else PhTranslateTiles( mRegion, &p );
         }
              }
virtual void nsRegionPh::SetRegionEmpty ( ) [inline, private, virtual]

Definition at line 205 of file nsRegionPh.h.

Here is the caller graph for this function:

virtual void nsRegionPh::SetTo ( const nsIRegion aRegion) [inline, virtual]

copy operator equivalent that takes another region

Parameters:
regionto copy
Returns:
void

Implements nsIRegion.

Definition at line 74 of file nsRegionPh.h.

              {
              PhTile_t *tiles;
              aRegion.GetNativeRegion( ( void*& ) tiles );
              SetRegionEmpty( );
              mRegion = PhCopyTiles( tiles );
              }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void nsRegionPh::SetTo ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [inline, virtual]

copy operator equivalent that takes a rect

Parameters:
aXxoffset of rect to set region to
aYyoffset of rect to set region to
aWidthwidth of rect to set region to
aHeightheight of rect to set region to
Returns:
void

Implements nsIRegion.

Definition at line 82 of file nsRegionPh.h.

              {
       SetRegionEmpty( );

       if ( aWidth > 0 && aHeight > 0 ) {
         /* 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;
         mRegion = tile;
         }
              }

Here is the call graph for this function:

virtual void nsRegionPh::Subtract ( const nsIRegion aRegion) [inline, virtual]

destructively subtract another region with this one

Parameters:
regionto subtract
Returns:
void

Implements nsIRegion.

Definition at line 135 of file nsRegionPh.h.

              {
              PhTile_t *tiles;
              aRegion.GetNativeRegion((void*&)tiles);
              mRegion = PhClipTilings( mRegion, tiles, NULL );
              }

Here is the call graph for this function:

virtual void nsRegionPh::Subtract ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [inline, virtual]

destructively subtract a rect from this region

Parameters:
aXxoffset of rect to subtract with region
aYyoffset of rect to subtract with region
aWidthwidth of rect to subtract with region
aHeightheight of rect to subtract with region
Returns:
void

Implements nsIRegion.

Definition at line 142 of file nsRegionPh.h.

              {
              if( aWidth > 0 && aHeight > 0 ) {
                /* Create a temporary tile to  assign to mRegion */
                PhTile_t tile;
                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;

                mRegion = PhClipTilings( mRegion, &tile, NULL );
                     }
              }
virtual void nsRegionPh::Union ( const nsIRegion aRegion) [inline, virtual]

destructively union another region with this one

Parameters:
regionto union
Returns:
void

Implements nsIRegion.

Definition at line 113 of file nsRegionPh.h.

              {
              PhTile_t *tiles;
              aRegion.GetNativeRegion( ( void*& ) tiles );
              mRegion = PhAddMergeTiles( mRegion, PhCopyTiles( tiles ), NULL );
              }

Here is the call graph for this function:

virtual void nsRegionPh::Union ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [inline, virtual]

destructively union a rect with this region

Parameters:
aXxoffset of rect to union with region
aYyoffset of rect to union with region
aWidthwidth of rect to union with region
aHeightheight of rect to union with region
Returns:
void

Implements nsIRegion.

Definition at line 120 of file nsRegionPh.h.

              {
              if( aWidth > 0 && aHeight > 0 ) {
                /* 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;

                mRegion = PhAddMergeTiles( mRegion, tile, NULL );
                }
              }

Member Data Documentation

PhTile_t* nsRegionPh::mRegion [private]

Definition at line 212 of file nsRegionPh.h.

Definition at line 213 of file nsRegionPh.h.


The documentation for this class was generated from the following files: