Back to index

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

#include <nsDrawingSurfaceOS2.h>

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

List of all members.

Public Member Functions

 nsOffscreenSurface ()
virtual ~nsOffscreenSurface ()
NS_IMETHOD Init (HPS aCompatiblePS, PRInt32 aWidth, PRInt32 aHeight, PRUint32 aFlags)
NS_IMETHOD Init (HPS aPS)
HDC GetDC ()
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 ()
 Unlock a rect of a drawing surface.
NS_IMETHOD IsOffscreen (PRBool *aOffScreen)
 Get the offscreen status of the drawing surface.
NS_IMETHOD IsPixelAddressable (PRBool *aAddressable)
 Get the pixel addressability status of the drawing surface.
NS_IMETHOD GetPixelFormat (nsPixelFormat *aFormat)
 Get the pixel format of a drawing surface.
NS_IMETHOD GetDimensions (PRUint32 *aWidth, PRUint32 *aHeight)
 Get the dimensions of a drawing surface.
HPS GetPS ()
void SelectFont (nsFontOS2 *aFont)
void FlushFontCache ()
virtual PRUint32 GetHeight ()
void NS2PM_ININ (const nsRect &in, RECTL &rcl)
void NS2PM_INEX (const nsRect &in, RECTL &rcl)
void PM2NS_ININ (const RECTL &in, nsRect &out)
void NS2PM (PPOINTL aPointl, ULONG cPointls)

Protected Member Functions

NS_DECL_ISUPPORTS void DisposeFonts ()

Protected Attributes

HPS mPS
PRBool mOwnPS
PRInt32 mWidth
PRInt32 mHeight

Private Attributes

HDC mDC
HBITMAP mBitmap
PBITMAPINFOHEADER2 mInfoHeader
PRUint8mBits
PRInt32 mYPels
PRUint32 mScans

Detailed Description

Definition at line 106 of file nsDrawingSurfaceOS2.h.


Constructor & Destructor Documentation

Definition at line 173 of file nsDrawingSurfaceOS2.cpp.

                                       : mDC(0), mBitmap(0),
                                           mInfoHeader(0), mBits(0),
                                           mYPels(0), mScans(0)
{
}

Definition at line 240 of file nsDrawingSurfaceOS2.cpp.

{
   DisposeFonts();
   
   if (mBitmap) {
      GFX (::GpiSetBitmap (mPS, 0), HBM_ERROR);
      GFX (::GpiDeleteBitmap (mBitmap), FALSE);
   }
   if (mOwnPS) {
      GFX (::GpiDestroyPS (mPS), FALSE);
   }
   if (mDC) {
      ::DevCloseDC(mDC);
   }

   if( mInfoHeader)
      free( mInfoHeader);
   delete [] mBits;
}

Here is the call graph for this function:


Member Function Documentation

void nsDrawingSurfaceOS2::DisposeFonts ( ) [protected, inherited]

Definition at line 67 of file nsDrawingSurfaceOS2.cpp.

{
   if( mHTFonts)
   {
      // free font things
      GFX (::GpiSetCharSet(mPS, LCID_DEFAULT), FALSE);

      for (int i = LCID_START; i <= mTopID; i++) {
         GFX (::GpiDeleteSetId(mPS, i), FALSE);
      }
      delete mHTFonts;
      mHTFonts = 0;
   }
}

Here is the caller graph for this function:

Definition at line 109 of file nsDrawingSurfaceOS2.cpp.

{
   mHTFonts->Reset();
   mNextID = LCID_START;
   // leave mTopID where it is.
}

Here is the caller graph for this function:

HDC nsOffscreenSurface::GetDC ( ) [inline]

Definition at line 125 of file nsDrawingSurfaceOS2.h.

{ return mDC; }
nsresult nsDrawingSurfaceOS2::GetDimensions ( PRUint32 aWidth,
PRUint32 aHeight 
) [virtual, inherited]

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.

Reimplemented in nsWindowSurface.

Definition at line 159 of file nsDrawingSurfaceOS2.cpp.

{
   if( !aWidth || !aHeight)
      return NS_ERROR_NULL_POINTER;

   *aWidth = mWidth;
   *aHeight = mHeight;

   return NS_OK;
}

Here is the caller graph for this function:

virtual PRUint32 nsDrawingSurfaceOS2::GetHeight ( ) [inline, virtual, inherited]

Reimplemented in nsWindowSurface.

Definition at line 96 of file nsDrawingSurfaceOS2.h.

{ return mHeight; }

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 371 of file nsDrawingSurfaceOS2.cpp.

{
   if( !aFormat)
      return NS_ERROR_NULL_POINTER;

   // Okay.  Who knows what's going on here - we (as wz) currently support
   // only 8 and 24 bpp bitmaps; dunno what should be done for 32 bpp,
   // even if os/2 supports them.
   //
   // (prob'ly need to get the FOURCC stuff into the act for 16bpp?)
   //
   BITMAPINFOHEADER bih = { sizeof( BITMAPINFOHEADER), 0, 0, 0, 0 };
   GFX (::GpiQueryBitmapInfoHeader (mBitmap, (PBITMAPINFOHEADER2)&bih), FALSE);

   switch( bih.cBitCount)
   {
      case 8:
         memset( aFormat, 0, sizeof(nsPixelFormat));
         break;

      case 16:
         aFormat->mRedZeroMask   = 0x001F;
         aFormat->mGreenZeroMask = 0x003F;
         aFormat->mBlueZeroMask  = 0x001F;
         aFormat->mAlphaZeroMask = 0;
         aFormat->mRedMask       = 0xF800;
         aFormat->mGreenMask     = 0x07E0;
         aFormat->mBlueMask      = 0x001F;
         aFormat->mAlphaMask     = 0;
         aFormat->mRedCount      = 5;
         aFormat->mGreenCount    = 6;
         aFormat->mBlueCount     = 5;
         aFormat->mAlphaCount    = 0;
         aFormat->mRedShift      = 11;
         aFormat->mGreenShift    = 5;
         aFormat->mBlueShift     = 0;
         aFormat->mAlphaShift    = 0;
         break;

      case 24:
         aFormat->mRedZeroMask   = 0x0000FF;
         aFormat->mGreenZeroMask = 0x0000FF;
         aFormat->mBlueZeroMask  = 0x0000FF;
         aFormat->mAlphaZeroMask = 0;
         aFormat->mRedMask       = 0x0000FF;
         aFormat->mGreenMask     = 0x00FF00;
         aFormat->mBlueMask      = 0xFF0000;
         aFormat->mAlphaMask     = 0;
         aFormat->mRedCount      = 8;
         aFormat->mGreenCount    = 8;
         aFormat->mBlueCount     = 8;
         aFormat->mAlphaCount    = 0;
         aFormat->mRedShift      = 0;
         aFormat->mGreenShift    = 8;
         aFormat->mBlueShift     = 16;
         aFormat->mAlphaShift    = 0;
         break;

      case 32:
         aFormat->mRedZeroMask   = 0x000000FF;
         aFormat->mGreenZeroMask = 0x000000FF;
         aFormat->mBlueZeroMask  = 0x000000FF;
         aFormat->mAlphaZeroMask = 0x000000FF;
         aFormat->mRedMask       = 0x00FF0000;
         aFormat->mGreenMask     = 0x0000FF00;
         aFormat->mBlueMask      = 0x000000FF;
         aFormat->mAlphaMask     = 0xFF000000;
         aFormat->mRedCount      = 8;
         aFormat->mGreenCount    = 8;
         aFormat->mBlueCount     = 8;
         aFormat->mAlphaCount    = 8;
         aFormat->mRedShift      = 16;
         aFormat->mGreenShift    = 8;
         aFormat->mBlueShift     = 0;
         aFormat->mAlphaShift    = 24;
         break;

      default:
#ifdef DEBUG
         printf( "Bad bit-depth for GetPixelFormat (%d)\n", bih.cBitCount);
#endif
         break;
   }

   return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HPS nsDrawingSurfaceOS2::GetPS ( ) [inline, inherited]

Definition at line 93 of file nsDrawingSurfaceOS2.h.

{ return mPS; }

Here is the caller graph for this function:

nsresult nsOffscreenSurface::Init ( HPS  aCompatiblePS,
PRInt32  aWidth,
PRInt32  aHeight,
PRUint32  aFlags 
)

Definition at line 188 of file nsDrawingSurfaceOS2.cpp.

{
   nsresult rc = NS_ERROR_FAILURE;

   // Find the compatible device context and create a memory one
   HDC hdcCompat = GFX (::GpiQueryDevice (aCompatiblePS), HDC_ERROR);
   DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
   mDC = GFX (::DevOpenDC( 0/*hab*/, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat), DEV_ERROR);

   if( DEV_ERROR != mDC)
   {
      // create the PS
      SIZEL sizel = { 0, 0 };
      mPS = GFX (::GpiCreatePS (0/*hab*/, mDC, &sizel,
                 PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);

      if( GPI_ERROR != mPS)
      {
         mOwnPS = PR_TRUE;

         nsPaletteOS2::SelectGlobalPalette(mPS);

         // now create a bitmap of the right size
         BITMAPINFOHEADER2 hdr = { 0 };
      
         hdr.cbFix = sizeof( BITMAPINFOHEADER2);
         hdr.cx = aWidth;
         hdr.cy = aHeight;
         hdr.cPlanes = 1;

         // find bitdepth
         LONG lBitCount = 0;
         GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
         hdr.cBitCount = (USHORT) lBitCount;

         mBitmap = GFX (::GpiCreateBitmap (mPS, &hdr, 0, 0, 0), GPI_ERROR);

         if( GPI_ERROR != mBitmap)
         {
            // set final stats & select bitmap into ps
            mHeight = aHeight;
            mWidth = aWidth;
            GFX (::GpiSetBitmap (mPS, mBitmap), HBM_ERROR);
            rc = NS_OK;
         }
      }
   }

   return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 179 of file nsDrawingSurfaceOS2.cpp.

{
  mPS = aPS;

  return NS_OK;
}
nsresult nsOffscreenSurface::IsOffscreen ( PRBool aOffScreen) [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 351 of file nsDrawingSurfaceOS2.cpp.

{
   if( !aOffScreen)
      return NS_ERROR_NULL_POINTER;

   *aOffScreen = PR_TRUE;

   return NS_OK;
}

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 361 of file nsDrawingSurfaceOS2.cpp.

{
   if( !aAddressable)
      return NS_ERROR_NULL_POINTER;

   *aAddressable = PR_TRUE;

   return NS_OK;
}
nsresult nsOffscreenSurface::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 269 of file nsDrawingSurfaceOS2.cpp.

{
   // Trust other platforms to ensure that we don't get nested!
   PRInt32 lStride = 0;
   ULONG   rc = 0;

   // Allocate buffers first time we get called.
   //
   // Need to look at the way in which this functionality is exercised:
   // may actually be more efficient to only grab the section of bitmap
   // required on each call, and to free up memory afterwards.
   //
   // Currently: * allocate once enough space for the entire bitmap
   //            * only grab & set the required scanlines
   //
   if( !mBits)
   {
      BITMAPINFOHEADER bih = { sizeof( BITMAPINFOHEADER), 0, 0, 0, 0 };
   
      rc = GFX (::GpiQueryBitmapInfoHeader (mBitmap, (PBITMAPINFOHEADER2) &bih), FALSE);
   
      // alloc space to query pel data into...
      lStride = RASWIDTH( bih.cx, bih.cBitCount);
      mBits = new PRUint8 [ lStride * bih.cy ];
   
      // ..and colour table too
      int cols = -1;
      if( bih.cBitCount >= 24) cols = 0;
      else cols = 1 << bih.cBitCount;
   
      int szStruct = sizeof( BITMAPINFOHEADER2) + cols * sizeof( RGB2);
   
      mInfoHeader = (PBITMAPINFOHEADER2) calloc( szStruct, 1);
      mInfoHeader->cbFix = sizeof( BITMAPINFOHEADER2);
      mInfoHeader->cx = bih.cx;
      mInfoHeader->cy = bih.cy;
      mInfoHeader->cPlanes = 1;
      mInfoHeader->cBitCount = (USHORT) bih.cBitCount;
      // GPI-Ref says these have to be set too...
      mInfoHeader->ulCompression = BCA_UNCOMP;
      mInfoHeader->usRecording = BRA_BOTTOMUP;
      mInfoHeader->usRendering = BRH_NOTHALFTONED; // ...hmm...
      mInfoHeader->ulColorEncoding = BCE_RGB;
   }
   else
      lStride = RASWIDTH( mInfoHeader->cx, mInfoHeader->cBitCount);

   // record starting scanline (bottom is 0)
   mYPels = mInfoHeader->cy - aY - aHeight;
   mScans = aHeight;

   rc = GFX (::GpiQueryBitmapBits (mPS, mYPels, mScans, (PBYTE)mBits,
                                   (PBITMAPINFO2)mInfoHeader), GPI_ALTERROR);

#ifdef DEBUG
   if( rc != mScans) {
     PMERROR( "GpiQueryBitmapBits");
     printf( "Lock, requested %d x %d and got %d x %d\n",
             aWidth, aHeight, (int) mInfoHeader->cx, aHeight);
   }
#endif

   // Okay.  Now have current state of bitmap in mBits.
   *aStride = lStride;
   *aBits = (void*) (mBits + (aX * (mInfoHeader->cBitCount >> 3)));
   *aWidthBytes = aWidth * (mInfoHeader->cBitCount >> 3);

   return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsDrawingSurfaceOS2::NS2PM ( PPOINTL  aPointl,
ULONG  cPointls 
) [inherited]

Definition at line 151 of file nsDrawingSurfaceOS2.cpp.

{
   PRInt32 ulHeight = GetHeight ();

   for( ULONG i = 0; i < cPointls; i++)
      aPointl[ i].y = ulHeight - aPointl[ i].y - 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsDrawingSurfaceOS2::NS2PM_INEX ( const nsRect in,
RECTL &  rcl 
) [inherited]

Definition at line 144 of file nsDrawingSurfaceOS2.cpp.

{
   NS2PM_ININ( in, rcl);
   rcl.xRight++;
   rcl.yTop++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsDrawingSurfaceOS2::NS2PM_ININ ( const nsRect in,
RECTL &  rcl 
) [inherited]

Definition at line 119 of file nsDrawingSurfaceOS2.cpp.

{
   const static nscoord kBottomLeftLimit = -8192;
   const static nscoord kTopRightLimit   =  16384;

   PRInt32 ulHeight = GetHeight ();

   rcl.xLeft    = PR_MAX(kBottomLeftLimit, in.x);
   rcl.xRight   = PR_MIN(in.x+in.width-1, kTopRightLimit);
   rcl.yTop     = PR_MIN(ulHeight-in.y-1, kTopRightLimit);
   rcl.yBottom  = PR_MAX(rcl.yTop-in.height+1, kBottomLeftLimit);
   return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsDrawingSurfaceOS2::PM2NS_ININ ( const RECTL &  in,
nsRect out 
) [inherited]

Definition at line 133 of file nsDrawingSurfaceOS2.cpp.

{
   PRInt32 ulHeight = GetHeight ();

   out.x = in.xLeft;
   out.width = in.xRight - in.xLeft + 1;
   out.y = ulHeight - in.yTop - 1;
   out.height = in.yTop - in.yBottom + 1;
}

Here is the call graph for this function:

Definition at line 85 of file nsDrawingSurfaceOS2.cpp.

{
   FontHandleKey key((void*)aFont->mHashMe);

   long lcid = (long) mHTFonts->Get(&key);
   if (lcid == 0) {
      if (mNextID == 255) {
         // ids used up, need to empty table and start again.
         FlushFontCache();
      }

      lcid = mNextID;
      mNextID++;
      CHK_SUCCESS (::GpiCreateLogFont(mPS, 0, lcid, &aFont->mFattrs),
                   FONT_MATCH);
      mHTFonts->Put(&key, (void *) lcid);
      if (mTopID < 254) {
         mTopID++;
      }
   }

   aFont->SelectIntoPS(mPS, lcid);
}

Here is the call graph for this function:

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 343 of file nsDrawingSurfaceOS2.cpp.

{
   GFX (::GpiSetBitmapBits (mPS, mYPels, mScans, (PBYTE)mBits,
                            (PBITMAPINFO2)mInfoHeader), GPI_ALTERROR);

   return NS_OK;
}

Here is the caller graph for this function:


Member Data Documentation

HBITMAP nsOffscreenSurface::mBitmap [private]

Definition at line 109 of file nsDrawingSurfaceOS2.h.

Definition at line 112 of file nsDrawingSurfaceOS2.h.

HDC nsOffscreenSurface::mDC [private]

Definition at line 108 of file nsDrawingSurfaceOS2.h.

PRInt32 nsDrawingSurfaceOS2::mHeight [protected, inherited]

Definition at line 78 of file nsDrawingSurfaceOS2.h.

PBITMAPINFOHEADER2 nsOffscreenSurface::mInfoHeader [private]

Definition at line 111 of file nsDrawingSurfaceOS2.h.

PRBool nsDrawingSurfaceOS2::mOwnPS [protected, inherited]

Definition at line 76 of file nsDrawingSurfaceOS2.h.

HPS nsDrawingSurfaceOS2::mPS [protected, inherited]

Definition at line 75 of file nsDrawingSurfaceOS2.h.

Definition at line 115 of file nsDrawingSurfaceOS2.h.

PRInt32 nsDrawingSurfaceOS2::mWidth [protected, inherited]

Definition at line 77 of file nsDrawingSurfaceOS2.h.

Definition at line 114 of file nsDrawingSurfaceOS2.h.


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