Back to index

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

#include <nsDrawingSurfaceGTK.h>

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

List of all members.

Public Member Functions

 nsDrawingSurfaceGTK ()
virtual ~nsDrawingSurfaceGTK ()
nsresult Init (GdkDrawable *aDrawable, GdkGC *aGC)
 Initialize a drawing surface using a windows DC.
nsresult Init (GdkGC *aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags)
 Initialize an offscreen drawing surface using a windows DC.
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.
GdkDrawable * GetDrawable (void)
void GetSize (PRUint32 *aWidth, PRUint32 *aHeight)
PRInt32 GetDepth ()

Protected Member Functions

PRUint8 ConvertMaskToCount (unsigned long val)

Private Attributes

GdkPixmap * mPixmap
GdkGC * mGC
gint mDepth
nsPixelFormat mPixFormat
PRUint32 mWidth
PRUint32 mHeight
PRUint32 mFlags
PRBool mIsOffscreen
GdkImage * mImage
PRInt32 mLockX
PRInt32 mLockY
PRUint32 mLockWidth
PRUint32 mLockHeight
PRUint32 mLockFlags
PRBool mLocked

Detailed Description

Definition at line 53 of file nsDrawingSurfaceGTK.h.


Constructor & Destructor Documentation

Definition at line 55 of file nsDrawingSurfaceGTK.cpp.

{
  GdkVisual *v;

  mPixmap = nsnull;
  mGC = nsnull;
  mDepth = 0;
  mWidth = 0;
  mHeight = 0;
  mFlags = 0;

  mImage = nsnull;
  mLockWidth = 0;
  mLockHeight = 0;
  mLockFlags = 0;
  mLockX = 0;
  mLockY = 0;
  mLocked = PR_FALSE;

  v = ::gdk_rgb_get_visual();

  mPixFormat.mRedMask = v->red_mask;
  mPixFormat.mGreenMask = v->green_mask;
  mPixFormat.mBlueMask = v->blue_mask;
  // FIXME
  mPixFormat.mAlphaMask = 0;

  mPixFormat.mRedCount = ConvertMaskToCount(v->red_mask);
  mPixFormat.mGreenCount = ConvertMaskToCount(v->green_mask);
  mPixFormat.mBlueCount = ConvertMaskToCount(v->blue_mask);;


  mPixFormat.mRedShift = v->red_shift;
  mPixFormat.mGreenShift = v->green_shift;
  mPixFormat.mBlueShift = v->blue_shift;
  // FIXME
  mPixFormat.mAlphaShift = 0;

  mDepth = v->depth;

#ifdef MOZ_ENABLE_XFT
  mXftDraw = nsnull;
#endif
}

Here is the call graph for this function:

Definition at line 100 of file nsDrawingSurfaceGTK.cpp.

{
  if (mPixmap)
    ::gdk_pixmap_unref(mPixmap);

  if (mImage)
    ::gdk_image_destroy(mImage);

  if (mGC)
    gdk_gc_unref(mGC);

#ifdef MOZ_ENABLE_XFT
  if (mXftDraw)
    XftDrawDestroy(mXftDraw);
#endif
}

Member Function Documentation

PRUint8 nsDrawingSurfaceGTK::ConvertMaskToCount ( unsigned long  val) [inline, protected]

Definition at line 357 of file nsDrawingSurfaceGTK.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:

Definition at line 108 of file nsDrawingSurfaceGTK.h.

{ return mDepth; }

Here is the caller graph for this function:

NS_IMETHODIMP nsDrawingSurfaceGTK::GetDimensions ( PRUint32 aWidth,
PRUint32 aHeight 
) [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 239 of file nsDrawingSurfaceGTK.cpp.

{
  *aWidth = mWidth;
  *aHeight = mHeight;

  return NS_OK;
}

Here is the caller graph for this function:

GdkDrawable* nsDrawingSurfaceGTK::GetDrawable ( void  ) [inline]

Definition at line 104 of file nsDrawingSurfaceGTK.h.

{ return mPixmap; }

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 260 of file nsDrawingSurfaceGTK.cpp.

{
  *aFormat = mPixFormat;

  return NS_OK;
}
void nsDrawingSurfaceGTK::GetSize ( PRUint32 aWidth,
PRUint32 aHeight 
) [inline]

Definition at line 106 of file nsDrawingSurfaceGTK.h.

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

Here is the caller graph for this function:

nsresult nsDrawingSurfaceGTK::Init ( GdkDrawable *  aDrawable,
GdkGC *  aGC 
)

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

Definition at line 267 of file nsDrawingSurfaceGTK.cpp.

{
  if (mGC)
    gdk_gc_unref(mGC);

  mGC = gdk_gc_ref(aGC);
  mPixmap = aDrawable;

#ifdef MOZ_WIDGET_GTK
  mWidth  = ((GdkWindowPrivate*)aDrawable)->width;
  mHeight = ((GdkWindowPrivate*)aDrawable)->height;
#endif /* MOZ_WIDGET_GTK */

#ifdef MOZ_WIDGET_GTK2
  gint width = 0;
  gint height = 0;
  gdk_drawable_get_size(aDrawable, &width, &height);
  mWidth = width;
  mHeight = height;
#endif /* MOZ_WIDGET_GTK2 */

  // XXX was i smoking crack when i wrote this comment?
  // this is definatly going to be on the screen, as it will be the window of a
  // widget or something.
  mIsOffscreen = PR_FALSE;

  if (mImage)
    gdk_image_destroy(mImage);
  mImage = nsnull;

  g_return_val_if_fail(mPixmap != nsnull, NS_ERROR_FAILURE);
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDrawingSurfaceGTK::Init ( GdkGC *  aGC,
PRUint32  aWidth,
PRUint32  aHeight,
PRUint32  aFlags 
)

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

Definition at line 302 of file nsDrawingSurfaceGTK.cpp.

{
  //  ::g_return_val_if_fail (aGC != nsnull, NS_ERROR_FAILURE);
  //  ::g_return_val_if_fail ((aWidth > 0) && (aHeight > 0), NS_ERROR_FAILURE);
  if (mGC)
    gdk_gc_unref(mGC);

  mGC = gdk_gc_ref(aGC);
  mWidth = aWidth;
  mHeight = aHeight;
  mFlags = aFlags;

  // we can draw on this offscreen because it has no parent
  mIsOffscreen = PR_TRUE;

  mPixmap = ::gdk_pixmap_new(nsnull, mWidth, mHeight, mDepth);
#ifdef MOZ_WIDGET_GTK2
  gdk_drawable_set_colormap(GDK_DRAWABLE(mPixmap), gdk_rgb_get_colormap());
#endif

  if (mImage)
    gdk_image_destroy(mImage);
  mImage = nsnull;

  return mPixmap ? 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 nsIDrawingSurface.

Definition at line 247 of file nsDrawingSurfaceGTK.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 nsIDrawingSurface.

Definition at line 253 of file nsDrawingSurfaceGTK.cpp.

{
// FIXME
  *aAddressable = PR_FALSE;
  return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK::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 134 of file nsDrawingSurfaceGTK.cpp.

{
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
  mLockTime = PR_Now();
  //  MOZ_TIMER_RESET(mLockTime);
  //  MOZ_TIMER_START(mLockTime);
#endif

#if 0
  g_print("nsDrawingSurfaceGTK::Lock() called\n" \
          "  aX = %i, aY = %i,\n" \
          "  aWidth = %i, aHeight = %i,\n" \
          "  aBits, aStride, aWidthBytes,\n" \
          "  aFlags = %i\n", aX, aY, aWidth, aHeight, aFlags);
#endif

  if (mLocked)
  {
    NS_ASSERTION(0, "nested lock attempt");
    return NS_ERROR_FAILURE;
  }
  mLocked = PR_TRUE;

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

  // Obtain an ximage from the pixmap.
  mImage = ::gdk_image_get(mPixmap, mLockX, mLockY, mLockWidth, mLockHeight);

  if (!mImage) {
    mLocked = PR_FALSE;
    return NS_ERROR_FAILURE;
  }

  *aBits = GDK_IMAGE_XIMAGE(mImage)->data;

  // Use GDK_IMAGE_XIMAGE(mImage)->bits_per_pixel instead of mImage->bpp
  // since, although bpp is documented as *bytes* per pixel, GDK1 sometimes
  // set it as *bits* per pixel.
  *aWidthBytes = aWidth * ((GDK_IMAGE_XIMAGE(mImage)->bits_per_pixel + 7) / 8);
  *aStride = GDK_IMAGE_XIMAGE(mImage)->bytes_per_line;

#ifdef CHEAP_PERFORMANCE_MEASUREMENT
  //  MOZ_TIMER_STOP(mLockTime);
  //  MOZ_TIMER_LOG(("Time taken to lock: "));
  //  MOZ_TIMER_PRINT(mLockTime);
  printf("Time taken to lock:   %d\n", PR_Now() - mLockTime);
#endif

  return NS_OK;
}

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 192 of file nsDrawingSurfaceGTK.cpp.

{

#ifdef CHEAP_PERFORMANCE_MEASUREMENT
  mUnlockTime = PR_Now();
#endif

  //  g_print("nsDrawingSurfaceGTK::UnLock() called\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))
  {
#if 0
    g_print("%p gdk_draw_image(pixmap=%p,lockx=%d,locky=%d,lockw=%d,lockh=%d)\n",
            this,
            mPixmap,
            mLockX, mLockY,
            mLockWidth, mLockHeight);
#endif

    gdk_draw_image(mPixmap,
                   mGC,
                   mImage,
                   0, 0,
                   mLockX, mLockY,
                   mLockWidth, mLockHeight);
  }

  if (mImage)
    ::gdk_image_destroy(mImage);
  mImage = nsnull;

  mLocked = PR_FALSE;


#ifdef CHEAP_PERFORMANCE_MEASUREMENT
  printf("Time taken to unlock: %d\n", PR_Now() - mUnlockTime);
#endif

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 123 of file nsDrawingSurfaceGTK.h.

Definition at line 127 of file nsDrawingSurfaceGTK.h.

GdkGC* nsDrawingSurfaceGTK::mGC [private]

Definition at line 122 of file nsDrawingSurfaceGTK.h.

Definition at line 126 of file nsDrawingSurfaceGTK.h.

GdkImage* nsDrawingSurfaceGTK::mImage [private]

Definition at line 131 of file nsDrawingSurfaceGTK.h.

Definition at line 128 of file nsDrawingSurfaceGTK.h.

Definition at line 137 of file nsDrawingSurfaceGTK.h.

Definition at line 136 of file nsDrawingSurfaceGTK.h.

Definition at line 135 of file nsDrawingSurfaceGTK.h.

Definition at line 134 of file nsDrawingSurfaceGTK.h.

Definition at line 132 of file nsDrawingSurfaceGTK.h.

Definition at line 133 of file nsDrawingSurfaceGTK.h.

Definition at line 124 of file nsDrawingSurfaceGTK.h.

GdkPixmap* nsDrawingSurfaceGTK::mPixmap [private]

Definition at line 121 of file nsDrawingSurfaceGTK.h.

Definition at line 125 of file nsDrawingSurfaceGTK.h.


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