Back to index

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

#include <nsCairoDrawingSurface.h>

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

List of all members.

Public Member Functions

 nsCairoDrawingSurface ()
virtual ~nsCairoDrawingSurface ()
nsresult Init (nsCairoDeviceContext *aDC, PRUint32 aWidth, PRUint32 aHeight, PRBool aFastAccess)
nsresult Init (nsCairoDeviceContext *aDC, nsIWidget *aWidget)
nsresult Init (nsCairoDeviceContext *aDC, nsNativeWidget aWidget)
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.
cairo_surface_t * GetCairoSurface (void)
PRInt32 GetDepth ()
nsNativeWidget GetNativeWidget (void)

Private Attributes

cairo_surface_t * mSurface
cairo_surface_t * mImageSurface
nsCairoDeviceContextmDC
nsNativeWidget mNativeWidget
PRUint32 mLockFlags
PRBool mFastAccess
PRUint32 mWidth
PRUint32 mHeight

Detailed Description

Definition at line 61 of file nsCairoDrawingSurface.h.


Constructor & Destructor Documentation

Definition at line 56 of file nsCairoDrawingSurface.cpp.

    : mSurface(nsnull), mImageSurface(nsnull), mDC(nsnull), mNativeWidget(nsnull)
{
#if defined(MOZ_ENABLE_GTK2) || defined(MOZ_ENABLE_XLIB)
    mPixmap = 0;
    mShmInfo.shmid = -1;
#ifdef MOZ_ENABLE_XFT
    mXftDraw = nsnull;
#endif
#endif
}

Definition at line 68 of file nsCairoDrawingSurface.cpp.

{
    fprintf (stderr, "++++ [%p] DESTROY\n", this);

    if (mSurface)
        cairo_surface_destroy (mSurface);
    if (mImageSurface && !mFastAccess) // otherwise, mImageSurface == mSurface
        cairo_surface_destroy (mImageSurface);

#if defined(MOZ_ENABLE_GTK2) || defined(MOZ_ENABLE_XLIB)
    if (mPixmap != 0)
        XFreePixmap(mXDisplay, mPixmap);

    if (mShmInfo.shmid != -1 && mShmInfo.shmaddr != 0) {
        XShmDetach (mXDisplay, &mShmInfo);
        shmdt (mShmInfo.shmaddr);
    }
#endif
}

Here is the call graph for this function:


Member Function Documentation

cairo_surface_t* nsCairoDrawingSurface::GetCairoSurface ( void  ) [inline]

Definition at line 92 of file nsCairoDrawingSurface.h.

{ return mSurface; }

Here is the caller graph for this function:

Definition at line 93 of file nsCairoDrawingSurface.h.

{ /* XXX */ return 24; }
NS_IMETHODIMP nsCairoDrawingSurface::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 276 of file nsCairoDrawingSurface.cpp.

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

Here is the caller graph for this function:

Definition at line 94 of file nsCairoDrawingSurface.h.

{ return mNativeWidget; }

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 306 of file nsCairoDrawingSurface.cpp.

{
    aFormat->mRedMask = 0x000000ff;
    aFormat->mGreenMask = 0x0000ff00;
    aFormat->mBlueMask = 0x00ff0000;
    aFormat->mAlphaMask = 0xff000000;

    aFormat->mRedCount = 8;
    aFormat->mGreenCount = 8;
    aFormat->mBlueCount = 8;
    aFormat->mAlphaCount = 8;

    aFormat->mRedShift = 0;
    aFormat->mGreenShift = 8;
    aFormat->mBlueShift = 16;
    aFormat->mAlphaCount = 24;

    return NS_OK;
}
nsresult nsCairoDrawingSurface::Init ( nsCairoDeviceContext aDC,
PRUint32  aWidth,
PRUint32  aHeight,
PRBool  aFastAccess 
)

Definition at line 89 of file nsCairoDrawingSurface.cpp.

{
    NS_ASSERTION(mSurface == nsnull, "Surface already initialized!");
    NS_ASSERTION(aWidth > 0 && aHeight > 0, "Invalid surface dimensions!");

    mWidth = aWidth;
    mHeight = aHeight;
    mDC = aDC;

    if (aFastAccess) {
        fprintf (stderr, "++++ [%p] Creating IMAGE surface: %dx%d\n", this, aWidth, aHeight);
        mSurface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, aWidth, aHeight);
        mFastAccess = PR_TRUE;
        mDrawable = nsnull;
    } else {
        fprintf (stderr, "++++ [%p] Creating PIXMAP surface: %dx%d\n", this, aWidth, aHeight);
        // otherwise, we need to do toolkit-specific stuff
#if defined(MOZ_ENABLE_GTK2) || defined(MOZ_ENABLE_XLIB)
        mXDisplay = aDC->GetXDisplay();
#if 0
        mShmInfo.shmaddr = 0;
        mShmInfo.shmid = shmget (IPC_PRIVATE,
                                 aWidth * 4 * aHeight,
                                 IPC_CREAT | 0600);
        if (mShmInfo.shmid != -1) {
            mShmInfo.shmaddr = (char*) shmat (mShmInfo.shmid, 0, 0);
            mShmInfo.readOnly = False;
        }

        if (mShmInfo.shmid != -1 && mShmInfo.shmaddr != 0) {
            XShmAttach (mXDisplay, &mShmInfo);
            mPixmap = XShmCreatePixmap (mXDisplay, aDC->GetXPixmapParentDrawable(),
                                        mShmInfo.shmaddr, &mShmInfo,
                                        aWidth, aHeight, DefaultDepth(mXDisplay,DefaultScreen(mXDisplay)));
        } else {
#endif
            mPixmap = XCreatePixmap(mXDisplay,
                                    aDC->GetXPixmapParentDrawable(),
                                    aWidth, aHeight, DefaultDepth(mXDisplay,DefaultScreen(mXDisplay)));
#if 0
        }
#endif

        mDrawable = (Drawable)mPixmap;


        // clear the pixmap
        XGCValues gcv;
        gcv.foreground = WhitePixel(mXDisplay,DefaultScreen(mXDisplay));
        gcv.background = 0;
        GC gc = XCreateGC (mXDisplay, mPixmap, GCForeground | GCBackground, &gcv);
        XFillRectangle (mXDisplay, mPixmap, gc, 0, 0, aWidth, aHeight);
        XFreeGC (mXDisplay, gc);

        // create the surface
        mSurface = cairo_xlib_surface_create (mXDisplay,
                                              mPixmap,
                                              aDC->GetXVisual(),
                                              CAIRO_FORMAT_ARGB32,
                                              aDC->GetXColormap());

        mFastAccess = PR_FALSE;
#else
#error write me
#endif
    }

    mLockFlags = 0;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 162 of file nsCairoDrawingSurface.cpp.

{
    nsNativeWidget nativeWidget = aWidget->GetNativeData(NS_NATIVE_WIDGET);
    return Init (aDC, nativeWidget);
}

Here is the call graph for this function:

Definition at line 169 of file nsCairoDrawingSurface.cpp.

{
    fprintf (stderr, "++++ [%p] Creating DRAWABLE (0x%08x) surface\n", this, aNativeWidget);

    mDC = aDC;

#ifdef MOZ_ENABLE_GTK2
    mNativeWidget = aNativeWidget;
    mDrawable = GDK_DRAWABLE_XID(GDK_DRAWABLE(aNativeWidget));
    NS_ASSERTION (GDK_IS_WINDOW(aNativeWidget), "unsupported native widget type!");
    mSurface = cairo_xlib_surface_create
        (GDK_WINDOW_XDISPLAY(GDK_DRAWABLE(aNativeWidget)),
         GDK_WINDOW_XWINDOW(GDK_DRAWABLE(aNativeWidget)),
         GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(GDK_DRAWABLE(aNativeWidget))),
         CAIRO_FORMAT_ARGB32, // I hope!
         GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(GDK_DRAWABLE(aNativeWidget))));

    Window root_ignore;
    int x_ignore, y_ignore;
    unsigned int bwidth_ignore, width, height, depth;

    XGetGeometry(GDK_WINDOW_XDISPLAY(GDK_DRAWABLE(aNativeWidget)),
                 GDK_WINDOW_XWINDOW(GDK_DRAWABLE(aNativeWidget)),
                 &root_ignore, &x_ignore, &y_ignore,
                 &width, &height,
                 &bwidth_ignore, &depth);

#if 0
    if (depth != 32)
        fprintf (stderr, "**** nsCairoDrawingSurface::Init with Widget: depth is %d!\n", depth);
#endif

    mWidth = width;
    mHeight = height;
    mFastAccess = PR_FALSE;

#else
#error write me
#endif

    mPixmap = 0;
    mLockFlags = 0;

    return NS_OK;
}

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 284 of file nsCairoDrawingSurface.cpp.

{
    *aOffScreen = PR_FALSE;

    if (mFastAccess)
        *aOffScreen = PR_TRUE;
#if defined(MOZ_ENABLE_GTK2) || defined(MOZ_ENABLE_XLIB)
    else if (mPixmap)
        *aOffScreen = PR_TRUE;
#endif

    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 299 of file nsCairoDrawingSurface.cpp.

{
    *aAddressable = mFastAccess;
    return NS_OK;
}
NS_IMETHODIMP nsCairoDrawingSurface::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 216 of file nsCairoDrawingSurface.cpp.

{
    NS_ASSERTION(aX + aWidth <= mWidth, "Invalid aX/aWidth");
    NS_ASSERTION(aY + aHeight <= mHeight, "Invalid aY/aHeight");
    NS_ASSERTION(mLockFlags == 0, "nsCairoDrawingSurface::Lock while surface is already locked!");

#if 0
    if (!mFastAccess) {
        mImageSurface = cairo_surface_get_image (mSurface);
    }

    char *data;
    int width, height, stride, depth;

    if (cairo_image_surface_get_data (mImageSurface,
                                      &data, &width, &height, &stride, &depth)
        != 0)
    {
        /* Something went wrong */
        if (!mFastAccess) {
            cairo_surface_destroy(mImageSurface);
            mImageSurface = nsnull;
        }
        return NS_ERROR_FAILURE;
    }
    *aBits = data + (stride * aY) + (aX * (depth / 8));
    *aStride = stride;
    *aWidthBytes = width * (depth / 8);

    mLockFlags = 0;

#endif
    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 nsIDrawingSurface.

Definition at line 254 of file nsCairoDrawingSurface.cpp.

{
    NS_ASSERTION(mLockFlags != 0, "nsCairoDrawingSurface::Unlock on non-locked surface!");

    if (mFastAccess) {
        mLockFlags = 0;
        return NS_OK;
    }

    if (mLockFlags & NS_LOCK_SURFACE_WRITE_ONLY) {
        /* need to copy back */
        //cairo_surface_set_image (mSurface, mImageSurface);
    }

    cairo_surface_destroy (mImageSurface);
    mImageSurface = nsnull;
    mLockFlags = 0;

    return NS_OK;
}

Member Data Documentation

Definition at line 104 of file nsCairoDrawingSurface.h.

Definition at line 120 of file nsCairoDrawingSurface.h.

Definition at line 121 of file nsCairoDrawingSurface.h.

cairo_surface_t * nsCairoDrawingSurface::mImageSurface [private]

Definition at line 103 of file nsCairoDrawingSurface.h.

Definition at line 119 of file nsCairoDrawingSurface.h.

Definition at line 105 of file nsCairoDrawingSurface.h.

cairo_surface_t* nsCairoDrawingSurface::mSurface [private]

Definition at line 103 of file nsCairoDrawingSurface.h.

Definition at line 121 of file nsCairoDrawingSurface.h.


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