Back to index

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

#include <nsDrawingSurfacePh.h>

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

List of all members.

Public Member Functions

 nsDrawingSurfacePh ()
virtual ~nsDrawingSurfacePh ()
NS_DECL_ISUPPORTS NS_IMETHOD Lock (PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, PRUint32 aFlags)
 Lock a rect of a drawing surface and return a pointer to the upper left hand corner of the bitmap.
NS_IMETHOD Unlock (void)
 Unlock a rect of a drawing surface.
NS_IMETHODIMP GetDimensions (PRUint32 *aWidth, PRUint32 *aHeight)
 Get the dimensions of a drawing surface.
NS_IMETHODIMP IsOffscreen (PRBool *aOffScreen)
 Get the offscreen status of the drawing surface.
NS_IMETHODIMP IsPixelAddressable (PRBool *aAddressable)
 Get the pixel addressability status of the drawing surface.
NS_IMETHODIMP GetPixelFormat (nsPixelFormat *aFormat)
 Get the pixel format of a drawing surface.
NS_IMETHODIMP Init (PhDrawContext_t *aDC, PhGC_t *aGC)
 Initialize a drawing surface using a windows DC.
NS_IMETHOD Init (PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags)
 Initialize an offscreen drawing surface using a windows DC.
PhDrawContext_t * Select ()
PhGC_t * GetGC (void)
PhDrawContext_t * GetDC (void)
void GetSize (PRUint32 *aWidth, PRUint32 *aHeight)

Static Private Member Functions

static int prefChanged (const char *aPref, void *aClosure)

Private Attributes

PRUint32 mWidth
PRUint32 mHeight
PRBool mIsOffscreen
PhGC_t * mGC
PhDrawContext_t * mDrawContext
PRUint32 mFlags
PhDrawContext_t * mLockDrawContext
PRInt32 mLockX
PRInt32 mLockY
PRUint32 mLockWidth
PRUint32 mLockHeight
PRUint32 mLockFlags
PRBool mLocked

Static Private Attributes

static nsPixelFormat mPixFormat

Detailed Description

Definition at line 45 of file nsDrawingSurfacePh.h.


Constructor & Destructor Documentation

Definition at line 90 of file nsDrawingSurfacePh.cpp.

{
       if( mIsOffscreen ) {
              mDrawContext->gc = NULL;
              PhDCRelease( mDrawContext ); /* the mDrawContext->gc will be freed by the upper classes */
       }
       
       if( mLockDrawContext ) {
              PhDCRelease(mLockDrawContext);
       }

       if( mIsOffscreen ) {
              nsresult rv;
              nsCOMPtr<nsIPref> prefs = do_GetService(kPrefCID, &rv);
              if (NS_SUCCEEDED(rv)) {
                     prefs->UnregisterCallback("browser.display.internaluse.graphics_changed", prefChanged, (void *)this);
              }

              if( mGC ) PgDestroyGC( mGC );
       }
}

Here is the call graph for this function:


Member Function Documentation

PhDrawContext_t* nsDrawingSurfacePh::GetDC ( void  ) [inline]

Definition at line 105 of file nsDrawingSurfacePh.h.

{ return mDrawContext; }
NS_IMETHODIMP nsDrawingSurfacePh::GetDimensions ( PRUint32 aWidth,
PRUint32 aHeight 
) [inline, virtual]

Get the dimensions of a drawing surface.

Parameters:
aWidthout parameter for width of drawing surface
aHeightout parameter for height of drawing surface
Returns:
error status

Implements nsIDrawingSurface.

Definition at line 62 of file nsDrawingSurfacePh.h.

              {
              *aWidth = mWidth;
              *aHeight = mHeight;
              return NS_OK;
              }
PhGC_t* nsDrawingSurfacePh::GetGC ( void  ) [inline]

Definition at line 104 of file nsDrawingSurfacePh.h.

{ return mGC; }

Here is the caller graph for this function:

Get the pixel format of a drawing surface.

Parameters:
aOffscreenout parameter filled in with pixel format information.
Returns:
error status

Implements nsIDrawingSurface.

Definition at line 73 of file nsDrawingSurfacePh.h.

              { 
              *aFormat = mPixFormat;
              return NS_OK;
              }
void nsDrawingSurfacePh::GetSize ( PRUint32 aWidth,
PRUint32 aHeight 
) [inline]

Definition at line 106 of file nsDrawingSurfacePh.h.

{ *aWidth = mWidth; *aHeight = mHeight;}

Here is the caller graph for this function:

NS_IMETHODIMP nsDrawingSurfacePh::Init ( PhDrawContext_t *  aDC,
PhGC_t *  aGC 
) [inline, virtual]

Initialize a drawing surface using a windows DC.

aDC is "owned" by the drawing surface until the drawing surface is destroyed.

Parameters:
aDCHDC to initialize drawing surface with
Returns:
error status

Implements nsIDrawingSurfacePh.

Definition at line 83 of file nsDrawingSurfacePh.h.

              {
              mGC = aGC;
              mIsOffscreen = PR_FALSE;
              mDrawContext =  aDC;
              return NS_OK;
              }

Here is the caller graph for this function:

NS_IMETHODIMP nsDrawingSurfacePh::Init ( PRUint32  aWidth,
PRUint32  aHeight,
PRUint32  aFlags 
) [virtual]

Initialize an offscreen drawing surface using a windows DC.

aDC is not "owned" by this drawing surface, instead it is used to create a drawing surface compatible with aDC. if width or height are less than zero, aDC will be created with no offscreen bitmap installed.

Parameters:
aDCHDC to initialize drawing surface with
aWidthwidth of drawing surface
aHeightheight of drawing surface
aFlagsflags used to control type of drawing surface created
Returns:
error status

Implements nsIDrawingSurfacePh.

Definition at line 232 of file nsDrawingSurfacePh.cpp.

                                                                                             {
       mWidth = aWidth;
       mHeight = aHeight;
       mFlags = aFlags;
       
       mIsOffscreen = PR_TRUE;

       /* an offscreen surface owns its own PhGC_t */
       mGC = PgCreateGC( 0 );

       mDrawContext = (PhDrawContext_t *)PdCreateOffscreenContext(0, mWidth, mHeight, Pg_OSC_MEM_PAGE_ALIGN);
       if( !mDrawContext ) return NS_ERROR_FAILURE;

       PgSetDrawBufferSizeCx( mDrawContext, 0xffff );

       nsresult rv;
       nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
       if (NS_SUCCEEDED(rv)) {
              prefs->RegisterCallback("browser.display.internaluse.graphics_changed", prefChanged, (void *)this);
              }

       return NS_OK;
       }

Here is the call graph for this function:

NS_IMETHODIMP nsDrawingSurfacePh::IsOffscreen ( PRBool aOffScreen) [inline, virtual]

Get the offscreen status of the drawing surface.

Parameters:
aOffscreenout parameter for offscreen status of drawing surface. if PR_TRUE, then modifying the drawing surface does not immediately reflect the changes on the output device
Returns:
error status

Implements nsIDrawingSurface.

Definition at line 69 of file nsDrawingSurfacePh.h.

{ *aOffScreen = mIsOffscreen; return NS_OK; }
NS_IMETHODIMP nsDrawingSurfacePh::IsPixelAddressable ( PRBool aAddressable) [inline, virtual]

Get the pixel addressability status of the drawing surface.

Parameters:
aAddressableout parameter for pixel addressability status of drawing surface. if PR_TRUE, then the drawing surface is optimized for pixel addressability (i.e. the Lock() method has very low overhead). All drawing surfaces support Lock()ing, but doing so on drawing surfaces that do not return PR_TRUE here may impose significant overhead.
Returns:
error status

Implements nsIDrawingSurface.

Definition at line 70 of file nsDrawingSurfacePh.h.

{ *aAddressable = PR_FALSE; return NS_OK; }
NS_IMETHODIMP nsDrawingSurfacePh::Lock ( PRInt32  aX,
PRInt32  aY,
PRUint32  aWidth,
PRUint32  aHeight,
void **  aBits,
PRInt32 aStride,
PRInt32 aWidthBytes,
PRUint32  aFlags 
) [virtual]

Lock a rect of a drawing surface and return a pointer to the upper left hand corner of the bitmap.

Parameters:
aXx position of subrect of bitmap
aYy position of subrect of bitmap
aWidthwidth of subrect of bitmap
aHeightheight of subrect of bitmap
aBitsout parameter for upper left hand corner of bitmap
aStrideout parameter for number of bytes to add to aBits to go from scanline to scanline
aWidthBytesout parameter for number of bytes per line in aBits to process aWidth pixels
Returns:
error status

Implements nsIDrawingSurface.

Definition at line 129 of file nsDrawingSurfacePh.cpp.

                                                                                  {

       if( mLocked ) return NS_ERROR_FAILURE;

       PdOffscreenContext_t *odc = (PdOffscreenContext_t *) mDrawContext, *dc;
       int bpp, format = odc->format, offset;

       switch( format ) {
              case Pg_IMAGE_PALETTE_BYTE:
                     bpp = 1;
                     break;
              case Pg_IMAGE_DIRECT_8888:
                     bpp = 4;
              break;
              case Pg_IMAGE_DIRECT_888:
                     bpp = 3;
                     break;
              case Pg_IMAGE_DIRECT_565:
              case Pg_IMAGE_DIRECT_555:
                     bpp = 2;
                     break;
              default:
                  return NS_ERROR_FAILURE;
              }


       if( !( aFlags & NS_LOCK_SURFACE_READ_ONLY ) ) {
              PhArea_t dst_area, src_area;

              // create an offscreen context to save the locked rectangle into
              mLockDrawContext = ( PhDrawContext_t * )PdCreateOffscreenContext( format, aWidth, aHeight, Pg_OSC_MEM_PAGE_ALIGN );
              if( !mLockDrawContext ) return NS_ERROR_FAILURE;
           PgSetDrawBufferSizeCx( mLockDrawContext, 0xffff );

              dst_area.pos.x = dst_area.pos.y = 0;
              dst_area.size.w = aWidth;
              dst_area.size.h = aHeight;
              src_area.pos.x = aX;
              src_area.pos.y = aY;
              src_area.size.w = aWidth;
              src_area.size.h = aHeight;

              PhDCSetCurrent( mLockDrawContext );
              PgContextBlitAreaCx( mLockDrawContext, (PdOffscreenContext_t *)mDrawContext, &src_area, (PdOffscreenContext_t *) mLockDrawContext, &dst_area );
              PgFlushCx( mLockDrawContext );
              dc = (PdOffscreenContext_t *) mLockDrawContext; /* to be used to get the stride and bits */
              offset = 0;
              }
       else {
              mLockDrawContext = nsnull;
              dc = (PdOffscreenContext_t *) mDrawContext; /* to be used to get the stride and bits */
              offset = aX * bpp + aY * dc->pitch;
              }

       *aBits = PdGetOffscreenContextPtr( dc );
       if( *aBits == nsnull ) return NS_ERROR_FAILURE; /* on certain hardware this may fail */

       if( offset ) *aBits = ( (char*) *aBits ) + offset;

       *aWidthBytes = bpp * aWidth;
       *aStride = dc->pitch;

       mLocked = PR_TRUE;
       mLockX = aX;
       mLockY = aY;
       mLockWidth = aWidth;
       mLockHeight = aHeight;
       mLockFlags = aFlags;

       return NS_OK;
       }

Here is the caller graph for this function:

int nsDrawingSurfacePh::prefChanged ( const char *  aPref,
void aClosure 
) [static, private]

Definition at line 256 of file nsDrawingSurfacePh.cpp.

{
       nsDrawingSurfacePh *surface = (nsDrawingSurfacePh*)aClosure;
       
       if( surface->mLockDrawContext ) {
              PhDCRelease(surface->mLockDrawContext);
              surface->mLockDrawContext = nsnull;
              }

       if(surface->mIsOffscreen) {
              PhDrawContext_t *newdc;

              newdc = (PhDrawContext_t *)PdCreateOffscreenContext(0, surface->mWidth, surface->mHeight, Pg_OSC_MEM_PAGE_ALIGN);
              if ( !newdc )
                     return NS_ERROR_FAILURE;
              surface->mDrawContext->gc = nsnull; /* because we do not want to destroy the one we have since other have it */
              PhDCRelease( surface->mDrawContext ); 
              surface->mDrawContext = newdc;
              PgSetDrawBufferSizeCx( surface->mDrawContext, 0xffff );

              PgDestroyGC(surface->mDrawContext->gc);
              surface->mDrawContext->gc = surface->mGC;
              /* use the gc provided */
       }
       return 0;
}

Here is the caller graph for this function:

PhDrawContext_t* nsDrawingSurfacePh::Select ( ) [inline]

Definition at line 95 of file nsDrawingSurfacePh.h.

              {
              PgSetGC( NULL );
              PhDCSetCurrent( mDrawContext );
              PgSetGCCx( mDrawContext, mGC );
              return mDrawContext;
              }

Here is the caller graph for this function:

Unlock a rect of a drawing surface.

must be preceded by a call to Lock(). Lock()/Unlock() pairs do not nest.

Returns:
error status

Implements nsIDrawingSurface.

Definition at line 204 of file nsDrawingSurfacePh.cpp.

                                                 {
       PhArea_t dst_area, src_area;

       if( !mLocked ) return NS_ERROR_FAILURE;

       // If the lock was not read only, put the bits back on the draw context
       if( !( mLockFlags & NS_LOCK_SURFACE_READ_ONLY ) ) {
              dst_area.pos.x = mLockX;
              dst_area.pos.y = mLockY;
              dst_area.size.w = mLockWidth;
              dst_area.size.h = mLockHeight;
              src_area.pos.x = src_area.pos.y = 0;
              src_area.size.w = mLockWidth;
              src_area.size.h = mLockHeight;

              PhDCSetCurrent( mDrawContext );
              PgContextBlitAreaCx( mDrawContext, (PdOffscreenContext_t *) mLockDrawContext, &src_area, (PdOffscreenContext_t *) mDrawContext, &dst_area );
              PgFlushCx( mDrawContext );

              // release the mLockDrawContext
              PhDCRelease( (PdDirectContext_t *) mLockDrawContext );
              mLockDrawContext = nsnull;
              }

       mLocked = PR_FALSE;
       return NS_OK;
       }

Here is the caller graph for this function:


Member Data Documentation

PhDrawContext_t* nsDrawingSurfacePh::mDrawContext [private]

Definition at line 113 of file nsDrawingSurfacePh.h.

Definition at line 115 of file nsDrawingSurfacePh.h.

PhGC_t* nsDrawingSurfacePh::mGC [private]

Definition at line 112 of file nsDrawingSurfacePh.h.

Definition at line 110 of file nsDrawingSurfacePh.h.

Definition at line 111 of file nsDrawingSurfacePh.h.

PhDrawContext_t* nsDrawingSurfacePh::mLockDrawContext [private]

Definition at line 118 of file nsDrawingSurfacePh.h.

Definition at line 124 of file nsDrawingSurfacePh.h.

Definition at line 123 of file nsDrawingSurfacePh.h.

Definition at line 122 of file nsDrawingSurfacePh.h.

Definition at line 121 of file nsDrawingSurfacePh.h.

Definition at line 119 of file nsDrawingSurfacePh.h.

Definition at line 120 of file nsDrawingSurfacePh.h.

Initial value:
 {
       0, 
       0, 
       0, 
       0, 
       0xff0000, 
       0x00ff00, 
       0x0000ff, 
       0, 
       0, 
       0, 
       0, 
       0, 
       16, 
       8, 
       0, 
       0 
       }

Definition at line 125 of file nsDrawingSurfacePh.h.

Definition at line 109 of file nsDrawingSurfacePh.h.


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