Back to index

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

#include <nsDrawingSurfaceXlib.h>

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

List of all members.

Public Member Functions

 nsDrawingSurfaceXlibImpl ()
virtual ~nsDrawingSurfaceXlibImpl ()
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_IMETHOD GetDimensions (PRUint32 *aWidth, PRUint32 *aHeight)
 Get the dimensions 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 Init (XlibRgbHandle *aHandle, Drawable aDrawable, xGC *aGC)
NS_IMETHOD Init (XlibRgbHandle *aHandle, xGC *aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags)
NS_IMETHOD GetDrawable (Drawable &aDrawable)
NS_IMETHOD GetXlibRgbHandle (XlibRgbHandle *&aHandle)
NS_IMETHOD GetGC (xGC *&aXGC)
virtual Drawable GetDrawable ()

Private Member Functions

void CommonInit ()

Static Private Member Functions

static PRUint8 ConvertMaskToCount (unsigned long val)
static PRUint8 GetShiftForMask (unsigned long val)

Private Attributes

XlibRgbHandle * mXlibRgbHandle
DisplaymDisplay
Screen * mScreen
Visual * mVisual
int mDepth
xGCmGC
Drawable mDrawable
XImage * mImage
nsPixelFormat mPixFormat
PRInt32 mLockX
PRInt32 mLockY
PRUint32 mLockWidth
PRUint32 mLockHeight
PRUint32 mLockFlags
PRBool mLocked
PRUint32 mWidth
PRUint32 mHeight
PRBool mIsOffscreen

Detailed Description

Definition at line 69 of file nsDrawingSurfaceXlib.h.


Constructor & Destructor Documentation

Definition at line 50 of file nsDrawingSurfaceXlib.cpp.

                                                   :
  nsIDrawingSurfaceXlib(),
  mXlibRgbHandle(nsnull),
  mDisplay(nsnull),
  mScreen(nsnull),
  mVisual(nsnull),
  mDepth(0),
  mGC(nsnull),
  mDrawable(None),
  mImage(nsnull),
  // set up lock info
  mLockX(0),
  mLockY(0),
  mLockWidth(0),
  mLockHeight(0),
  mLockFlags(0),
  mLocked(PR_FALSE),
  // dimensions...
  mWidth(0),
  mHeight(0),
  mIsOffscreen(PR_FALSE)
{
  PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::nsDrawingSurfaceXlibImpl()\n"));

}

Definition at line 76 of file nsDrawingSurfaceXlib.cpp.

{
  PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::~nsDrawingSurfaceXlibImpl()\n"));
  // if it's been labeled as destroy, it's a pixmap.
  if (mDrawable!=None && mIsOffscreen) {
    XFreePixmap(mDisplay, mDrawable);
  }
  if (mImage) {
    XDestroyImage(mImage);
  }

  // We are freeing the GC here now [See nsWidget::CreateGC()]
  if(mGC) {
    mGC->Release();
    mGC = nsnull;
  }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 148 of file nsDrawingSurfaceXlib.cpp.

{
  mDisplay = xxlib_rgb_get_display(mXlibRgbHandle);
  mScreen  = xxlib_rgb_get_screen(mXlibRgbHandle);
  mVisual  = xxlib_rgb_get_visual(mXlibRgbHandle);
  mDepth   = xxlib_rgb_get_depth(mXlibRgbHandle);

  XVisualInfo *x_visual_info = xxlib_rgb_get_visual_info(mXlibRgbHandle);
  NS_ASSERTION(nsnull != x_visual_info, "Visual info from xlibrgb is null.");

  if (x_visual_info)
  {
    mPixFormat.mRedMask = x_visual_info->red_mask;
    mPixFormat.mGreenMask = x_visual_info->green_mask;;
    mPixFormat.mBlueMask = x_visual_info->blue_mask;;
    mPixFormat.mAlphaMask = 0;

    mPixFormat.mRedCount = ConvertMaskToCount(x_visual_info->red_mask);
    mPixFormat.mGreenCount = ConvertMaskToCount(x_visual_info->green_mask);
    mPixFormat.mBlueCount = ConvertMaskToCount(x_visual_info->blue_mask);;
    mPixFormat.mAlphaCount = 0;

    mPixFormat.mRedShift = GetShiftForMask(x_visual_info->red_mask);
    mPixFormat.mGreenShift = GetShiftForMask(x_visual_info->green_mask);
    mPixFormat.mBlueShift = GetShiftForMask(x_visual_info->blue_mask);
    mPixFormat.mAlphaShift = 0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRUint8 nsDrawingSurfaceXlibImpl::ConvertMaskToCount ( unsigned long  val) [static, private]

Definition at line 275 of file nsDrawingSurfaceXlib.cpp.

{
  PRUint8 retval = 0;
  PRUint8 cur_bit = 0;
  // walk through the number, incrementing the value if
  // the bit in question is set.
  while (cur_bit < (sizeof(unsigned long) * 8)) {
    if ((val >> cur_bit) & 0x1) {
      retval++;
    }
    cur_bit++;
  }
  return retval;
}

Here is the caller graph for this function:

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 nsIDrawingSurfaceXlib.

Definition at line 246 of file nsDrawingSurfaceXlib.cpp.

{
  *aWidth = mWidth;
  *aHeight = mHeight;
  return NS_OK;
}
NS_IMETHOD nsDrawingSurfaceXlibImpl::GetDrawable ( Drawable &  aDrawable) [inline, virtual]

Implements nsIDrawingSurfaceXlib.

Definition at line 96 of file nsDrawingSurfaceXlib.h.

{ aDrawable = mDrawable; return NS_OK; }
virtual Drawable nsDrawingSurfaceXlibImpl::GetDrawable ( void  ) [inline, virtual]

Implements nsIDrawingSurfaceXlib.

Definition at line 100 of file nsDrawingSurfaceXlib.h.

{ return mDrawable; }
NS_IMETHOD nsDrawingSurfaceXlibImpl::GetGC ( xGC *&  aXGC) [inline, virtual]

Implements nsIDrawingSurfaceXlib.

Definition at line 98 of file nsDrawingSurfaceXlib.h.

{ mGC->AddRef(); aXGC = mGC; return NS_OK; }

Here is the call 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 nsIDrawingSurfaceXlib.

Definition at line 268 of file nsDrawingSurfaceXlib.cpp.

{
  *aFormat = mPixFormat;
  return NS_OK;
}
PRUint8 nsDrawingSurfaceXlibImpl::GetShiftForMask ( unsigned long  val) [static, private]

Definition at line 291 of file nsDrawingSurfaceXlib.cpp.

{
  PRUint8 cur_bit = 0;
  // walk through the number, looking for the first 1
  while (cur_bit < (sizeof(unsigned long) * 8)) {
    if ((val >> cur_bit) & 0x1) {
      return cur_bit;
    }
    cur_bit++;
  }
  return cur_bit;
}

Here is the caller graph for this function:

NS_IMETHOD nsDrawingSurfaceXlibImpl::GetXlibRgbHandle ( XlibRgbHandle *&  aHandle) [inline, virtual]

Implements nsIDrawingSurfaceXlib.

Definition at line 97 of file nsDrawingSurfaceXlib.h.

{ aHandle = mXlibRgbHandle; return NS_OK; }
NS_IMETHODIMP nsDrawingSurfaceXlibImpl::Init ( XlibRgbHandle *  aHandle,
Drawable  aDrawable,
xGC aGC 
)

Definition at line 97 of file nsDrawingSurfaceXlib.cpp.

{
  PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::Init()\n"));

  mXlibRgbHandle = aXlibRgbHandle;
  mDrawable      = aDrawable;

  CommonInit();
  
  if (mGC)
    mGC->Release();
  mGC = aGC;
  mGC->AddRef();
  
  mIsOffscreen = PR_FALSE;
  return NS_OK;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsDrawingSurfaceXlibImpl::Init ( XlibRgbHandle *  aHandle,
xGC aGC,
PRUint32  aWidth,
PRUint32  aHeight,
PRUint32  aFlags 
)

Definition at line 118 of file nsDrawingSurfaceXlib.cpp.

{
  mXlibRgbHandle = aXlibRgbHandle;
  mWidth = aWidth;
  mHeight = aHeight;
  mLockFlags = aFlags;

  CommonInit();
  
  if (mGC)
    mGC->Release();
  mGC = aGC;
  mGC->AddRef();
  
  mIsOffscreen = PR_TRUE;

  mDrawable = XCreatePixmap(mDisplay, 
                            XRootWindow(mDisplay, XScreenNumberOfScreen(mScreen)),
                            mWidth, 
                            mHeight, 
                            mDepth);

  return (mDrawable!=None)?(NS_OK):(NS_ERROR_FAILURE);
}

Here is the call graph for this function:

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 nsIDrawingSurfaceXlib.

Definition at line 254 of file nsDrawingSurfaceXlib.cpp.

{
  *aOffScreen = mIsOffscreen;
  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 nsIDrawingSurfaceXlib.

Definition at line 261 of file nsDrawingSurfaceXlib.cpp.

{
  *aAddressable = PR_FALSE;
  return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceXlibImpl::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 nsIDrawingSurfaceXlib.

Definition at line 178 of file nsDrawingSurfaceXlib.cpp.

{
  PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::Lock()\n"));
  if (mLocked)
  {
    NS_ASSERTION(0, "nested lock attempt");
    return NS_ERROR_FAILURE;
  }
  if (aWidth == 0 || aHeight == 0)
  {
    NS_ASSERTION(0, "Width or Height is 0");
    return NS_ERROR_FAILURE;
  }

  mLocked = PR_TRUE;

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

  mImage = XGetImage(mDisplay, mDrawable,
                     mLockX, mLockY,
                     mLockWidth, mLockHeight,
                     0xFFFFFFFF,
                     ZPixmap);

  if (!mImage) {
    mLocked = PR_FALSE;
    return NS_ERROR_FAILURE;
  }
  
  *aBits = mImage->data;
  
  *aWidthBytes = mImage->bytes_per_line;
  *aStride = mImage->bytes_per_line;

  return NS_OK;
}

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 nsIDrawingSurfaceXlib.

Definition at line 223 of file nsDrawingSurfaceXlib.cpp.

{
  PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::UnLock()\n"));
  if (!mLocked) {
    NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
    return NS_ERROR_FAILURE;
  }
  
  // If the lock was not read only, put the bits back on the pixmap
  if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY)) {
    XPutImage(mDisplay, mDrawable, *mGC, mImage,
              0, 0, mLockX, mLockY,
              mLockWidth, mLockHeight);
  }
  if (mImage) {
    XDestroyImage(mImage);
    mImage = nsnull;
  }
  mLocked = PR_FALSE;
  return NS_OK;
}

Member Data Documentation

Definition at line 109 of file nsDrawingSurfaceXlib.h.

Definition at line 106 of file nsDrawingSurfaceXlib.h.

Definition at line 111 of file nsDrawingSurfaceXlib.h.

Definition at line 110 of file nsDrawingSurfaceXlib.h.

Definition at line 125 of file nsDrawingSurfaceXlib.h.

Definition at line 112 of file nsDrawingSurfaceXlib.h.

Definition at line 128 of file nsDrawingSurfaceXlib.h.

Definition at line 121 of file nsDrawingSurfaceXlib.h.

Definition at line 120 of file nsDrawingSurfaceXlib.h.

Definition at line 119 of file nsDrawingSurfaceXlib.h.

Definition at line 118 of file nsDrawingSurfaceXlib.h.

Definition at line 116 of file nsDrawingSurfaceXlib.h.

Definition at line 117 of file nsDrawingSurfaceXlib.h.

Definition at line 113 of file nsDrawingSurfaceXlib.h.

Definition at line 107 of file nsDrawingSurfaceXlib.h.

Definition at line 108 of file nsDrawingSurfaceXlib.h.

Definition at line 124 of file nsDrawingSurfaceXlib.h.

XlibRgbHandle* nsDrawingSurfaceXlibImpl::mXlibRgbHandle [private]

Definition at line 105 of file nsDrawingSurfaceXlib.h.


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