Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsCanvasRenderingContext2D Class Reference

nsCanvasRenderingContext2D More...

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

List of all members.

Classes

class  ContextState

Public Member Functions

 nsCanvasRenderingContext2D ()
virtual ~nsCanvasRenderingContext2D ()
nsresult Redraw ()
void SetCairoColor (nscolor c)
NS_IMETHOD SetCanvasElement (nsICanvasElement *aParentCanvas)
NS_IMETHOD SetDimensions (PRInt32 width, PRInt32 height)
NS_IMETHOD Render (nsIRenderingContext *rc)
NS_IMETHOD RenderToSurface (cairo_surface_t *surf)
NS_IMETHOD GetInputStream (const nsACString &aMimeType, const nsAString &aEncoderOptions, nsIInputStream **aStream)
void save ()
void restore ()
void scale (in float x, in float y)
void rotate (in float angle)
void translate (in float x, in float y)
nsIDOMCanvasGradient createLinearGradient (in float x0, in float y0, in float x1, in float y1)
nsIDOMCanvasGradient createRadialGradient (in float x0, in float y0, in float r0, in float x1, in float y1, in float r1)
nsIDOMCanvasPattern createPattern (in nsIDOMHTMLElement image, in DOMString repetition)
void clearRect (in float x, in float y, in float w, in float h)
void fillRect (in float x, in float y, in float w, in float h)
void strokeRect (in float x, in float y, in float w, in float h)
void beginPath ()
void closePath ()
void moveTo (in float x, in float y)
void lineTo (in float x, in float y)
void quadraticCurveTo (in float cpx, in float cpy, in float x, in float y)
void bezierCurveTo (in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y)
void arcTo (in float x1, in float y1, in float x2, in float y2, in float radius)
void arc (in float x, in float y, in float r, in float startAngle, in float endAngle, in boolean clockwise)
void rect (in float x, in float y, in float w, in float h)
void fill ()
void stroke ()
void clip ()
void drawImage ()
boolean isPointInPath (in float x, in float y)
void getImageData ()
void putImageData ()
void drawWindow (in nsIDOMWindow window, in long x, in long y, in long w, in long h, in DOMString bgColor)
 Renders a region of a window into the canvas.
NS_IMETHOD RenderToSurface (struct _cairo_surface *surf)=0

Public Attributes

readonly attribute
nsIDOMHTMLCanvasElement 
canvas
attribute float globalAlpha
attribute DOMString globalCompositeOperation
attribute nsIVariant strokeStyle
attribute nsIVariant fillStyle
attribute float lineWidth
attribute DOMString lineCap
attribute DOMString lineJoin
attribute float miterLimit
attribute float shadowOffsetX
attribute float shadowOffsetY
attribute float shadowBlur
attribute DOMString shadowColor

Protected Types

enum  { STYLE_STROKE = 0, STYLE_FILL, STYLE_SHADOW }

Protected Member Functions

void Destroy ()
nsIFrameGetCanvasLayoutFrame ()
nsresult SetStyleFromVariant (nsIVariant *aStyle, PRInt32 aWhichStyle)
void StyleColorToString (const nscolor &aColor, nsAString &aStr)
void DirtyAllStyles ()
void ApplyStyle (PRInt32 aWhichStyle)
void DoDrawImageSecurityCheck (nsIURI *aURI, PRBool forceWriteOnly)
ContextStateCurrentState ()
nsresult CairoSurfaceFromElement (nsIDOMElement *imgElt, cairo_surface_t **aCairoSurface, PRUint8 **imgDataOut, PRInt32 *widthOut, PRInt32 *heightOut, nsIURI **uriOut, PRBool *forceWriteOnlyOut)
nsresult DrawNativeSurfaces (nsIDrawingSurface *aBlackSurface, nsIDrawingSurface *aWhiteSurface, const nsIntSize &aSurfaceSize, nsIRenderingContext *aBlackContext)

Static Protected Member Functions

static PRBool ConvertJSValToUint32 (PRUint32 *aProp, JSContext *aContext, jsval aValue)
static PRBool ConvertJSValToXPCObject (nsISupports **aSupports, REFNSIID aIID, JSContext *aContext, jsval aValue)
static PRBool ConvertJSValToDouble (double *aProp, JSContext *aContext, jsval aValue)

Protected Attributes

PRInt32 mWidth
PRInt32 mHeight
nsICanvasElementmCanvasElement
nsCOMPtr< nsICSSParsermCSSParser
PRUint32 mSaveCount
cairo_t * mCairo
cairo_surface_t * mSurface
PRUint8mImageSurfaceData
PRInt32 mLastStyle
PRPackedBool mDirtyStyle [STYLE_MAX]
nsTArray< ContextStatemStyleStack

Detailed Description

nsCanvasRenderingContext2D

Definition at line 352 of file nsCanvasRenderingContext2D.cpp.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
STYLE_STROKE 
STYLE_FILL 
STYLE_SHADOW 

Definition at line 385 of file nsCanvasRenderingContext2D.cpp.

         {
        STYLE_STROKE = 0,
        STYLE_FILL,
        STYLE_SHADOW
        //STYLE_MAX
    };

Constructor & Destructor Documentation

Definition at line 528 of file nsCanvasRenderingContext2D.cpp.

    : mCanvasElement(nsnull),
      mSaveCount(0), mCairo(nsnull), mSurface(nsnull), mImageSurfaceData(nsnull), mStyleStack(20)
{
#ifdef MOZ_WIDGET_GTK2
    mSurfacePixmap = None;
#endif
}

Definition at line 537 of file nsCanvasRenderingContext2D.cpp.

{
    Destroy();
}

Here is the call graph for this function:


Member Function Documentation

void nsCanvasRenderingContext2D::ApplyStyle ( PRInt32  aWhichStyle) [protected]

Definition at line 732 of file nsCanvasRenderingContext2D.cpp.

{
    if (mLastStyle == aWhichStyle &&
        !mDirtyStyle[aWhichStyle])
    {
        // nothing to do, this is already the set style
        return;
    }

    mDirtyStyle[aWhichStyle] = PR_FALSE;
    mLastStyle = aWhichStyle;

    nsCanvasPattern* pattern = CurrentState().patternStyles[aWhichStyle];
    if (pattern) {
        if (!mCanvasElement)
            return;

        DoDrawImageSecurityCheck(pattern->GetURI(), pattern->GetForceWriteOnly());
        pattern->Apply(mCairo);
        return;
    }

    if (CurrentState().gradientStyles[aWhichStyle]) {
        CurrentState().gradientStyles[aWhichStyle]->Apply(mCairo);
        return;
    }

    SetCairoColor(CurrentState().colorStyles[aWhichStyle]);
}

Here is the call graph for this function:

void nsIDOMCanvasRenderingContext2D::arc ( in float  x,
in float  y,
in float  r,
in float  startAngle,
in float  endAngle,
in boolean  clockwise 
) [inherited]
void nsIDOMCanvasRenderingContext2D::arcTo ( in float  x1,
in float  y1,
in float  x2,
in float  y2,
in float  radius 
) [inherited]
void nsIDOMCanvasRenderingContext2D::bezierCurveTo ( in float  cp1x,
in float  cp1y,
in float  cp2x,
in float  cp2y,
in float  x,
in float  y 
) [inherited]
nsresult nsCanvasRenderingContext2D::CairoSurfaceFromElement ( nsIDOMElement imgElt,
cairo_surface_t **  aCairoSurface,
PRUint8 **  imgDataOut,
PRInt32 widthOut,
PRInt32 heightOut,
nsIURI **  uriOut,
PRBool forceWriteOnlyOut 
) [protected]

Definition at line 2137 of file nsCanvasRenderingContext2D.cpp.

{
    nsresult rv;

    nsCOMPtr<imgIContainer> imgContainer;

    nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(imgElt);
    if (imageLoader) {
        nsCOMPtr<imgIRequest> imgRequest;
        rv = imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                                     getter_AddRefs(imgRequest));
        NS_ENSURE_SUCCESS(rv, rv);
        if (!imgRequest)
            // XXX ERRMSG we need to report an error to developers here! (bug 329026)
            return NS_ERROR_NOT_AVAILABLE;

        PRUint32 status;
        imgRequest->GetImageStatus(&status);
        if ((status & imgIRequest::STATUS_LOAD_COMPLETE) == 0)
            return NS_ERROR_NOT_AVAILABLE;

        nsCOMPtr<nsIURI> uri;
        rv = imageLoader->GetCurrentURI(uriOut);
        NS_ENSURE_SUCCESS(rv, rv);

        *forceWriteOnlyOut = PR_FALSE;

        rv = imgRequest->GetImage(getter_AddRefs(imgContainer));
        NS_ENSURE_SUCCESS(rv, rv);
    } else {
        // maybe a canvas
        nsCOMPtr<nsICanvasElement> canvas = do_QueryInterface(imgElt);
        if (canvas) {
            PRUint32 w, h;
            rv = canvas->GetSize(&w, &h);
            NS_ENSURE_SUCCESS(rv, rv);

            cairo_surface_t *surf =
                cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                            w, h);
            cairo_t *cr = cairo_create (surf);
            cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
            cairo_paint (cr);
            cairo_destroy (cr);

            rv = canvas->RenderContextsToSurface(surf);
            if (NS_FAILED(rv)) {
                cairo_surface_destroy (surf);
                return rv;
            }

            *aCairoSurface = surf;
            *imgData = nsnull;
            *widthOut = w;
            *heightOut = h;

            *uriOut = nsnull;
            *forceWriteOnlyOut = canvas->IsWriteOnly();

            return NS_OK;
        } else {
            NS_WARNING("No way to get surface from non-canvas, non-imageloader");
            return NS_ERROR_NOT_AVAILABLE;
        }
    }

    if (!imgContainer)
        return NS_ERROR_NOT_AVAILABLE;

    nsCOMPtr<gfxIImageFrame> frame;
    rv = imgContainer->GetCurrentFrame(getter_AddRefs(frame));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIImage> img(do_GetInterface(frame));

    PRInt32 imgWidth, imgHeight;
    rv = frame->GetWidth(&imgWidth);
    rv |= frame->GetHeight(&imgHeight);
    if (NS_FAILED(rv))
        return NS_ERROR_FAILURE;

    if (widthOut)
        *widthOut = imgWidth;
    if (heightOut)
        *heightOut = imgHeight;

#ifdef MOZ_CAIRO_GFX
    gfxASurface* gfxsurf = nsnull;
    rv = img->GetSurface(&gfxsurf);
    NS_ENSURE_SUCCESS(rv, rv);

    *aCairoSurface = gfxsurf->CairoSurface();
    cairo_surface_reference (*aCairoSurface);
    *imgData = nsnull;
#else
    //
    // We now need to create a cairo_surface with the same data as
    // this image element.
    //

    PRUint8 *cairoImgData = (PRUint8 *)nsMemory::Alloc(imgHeight * imgWidth * 4);
    PRUint8 *outData = cairoImgData;

    gfx_format format;
    rv = frame->GetFormat(&format);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = frame->LockImageData();
    if (img->GetHasAlphaMask())
        rv |= frame->LockAlphaData();
    if (NS_FAILED(rv)) {
        nsMemory::Free(cairoImgData);
        return NS_ERROR_FAILURE;
    }

    PRUint8 *inPixBits, *inAlphaBits = nsnull;
    PRUint32 inPixStride, inAlphaStride = 0;
    inPixBits = img->GetBits();
    inPixStride = img->GetLineStride();
    if (img->GetHasAlphaMask()) {
        inAlphaBits = img->GetAlphaBits();
        inAlphaStride = img->GetAlphaLineStride();
    }

    PRBool topToBottom = img->GetIsRowOrderTopToBottom();
    PRBool useBGR;

    // The gtk backend optimizes away the alpha mask of images
    // with a fully opaque alpha, but doesn't update its format (bug?);
    // you end up with a RGB_A8 image with GetHasAlphaMask() == false.
    // We need to treat that case as RGB.  We also need to understand
    // that with 1-bit alpha the data is actually RGB_A1, not RGB_A8,
    // no matter what the format says.
#ifdef MOZ_WIDGET_GTK2
    PRInt8 alphaDepth = img->GetAlphaDepth();
    if (alphaDepth == 0) {
        if (format == gfxIFormats::RGB_A8)
            format = gfxIFormats::RGB;
        else if (format == gfxIFormats::BGR_A8)
            format = gfxIFormats::BGR;
    } else if (alphaDepth == 1) {
        if (format == gfxIFormats::RGB_A8)
            format = gfxIFormats::RGB_A1;
        else if (format == gfxIFormats::BGR_A8)
            format = gfxIFormats::BGR_A1;
    }
#endif

    // We probably don't need the GetHasAlphaMask check here, because it
    // should've been handled up above, but as this patch is going into
    // the release branch I don't want to change this code unnecessarily.
    if ((format == gfxIFormats::RGB || format == gfxIFormats::BGR) ||
        (!(img->GetHasAlphaMask()) && (format == gfxIFormats::RGB_A8 || format == gfxIFormats::BGR_A8)))
    {
        useBGR = (format & 1);

#ifdef IS_BIG_ENDIAN
        useBGR = !useBGR;
#endif

        for (PRUint32 j = 0; j < (PRUint32) imgHeight; j++) {
            PRUint32 rowIndex;
            if (topToBottom)
                rowIndex = j;
            else
                rowIndex = imgHeight - j - 1;

            PRUint8 *inrowrgb = inPixBits + (inPixStride * rowIndex);

            for (PRUint32 i = 0; i < (PRUint32) imgWidth; i++) {
                // handle rgb data; no alpha to premultiply
#ifdef XP_MACOSX
                // skip extra OSX byte
                inrowrgb++;
#endif
                PRUint8 b = *inrowrgb++;
                PRUint8 g = *inrowrgb++;
                PRUint8 r = *inrowrgb++;

#ifdef IS_BIG_ENDIAN
                // alpha
                *outData++ = 0xff;
#endif

                if (useBGR) {
                    *outData++ = b;
                    *outData++ = g;
                    *outData++ = r;
                } else {
                    *outData++ = r;
                    *outData++ = g;
                    *outData++ = b;
                }

#ifdef IS_LITTLE_ENDIAN
                // alpha
                *outData++ = 0xff;
#endif
            }
        }
        rv = NS_OK;
    } else if (format == gfxIFormats::RGB_A1 || format == gfxIFormats::BGR_A1) {
        useBGR = (format & 1);

#ifdef IS_BIG_ENDIAN
        useBGR = !useBGR;
#endif

        for (PRUint32 j = 0; j < (PRUint32) imgHeight; j++) {
            PRUint32 rowIndex;
            if (topToBottom)
                rowIndex = j;
            else
                rowIndex = imgHeight - j - 1;

            PRUint8 *inrowrgb = inPixBits + (inPixStride * rowIndex);
            PRUint8 *inrowalpha = inAlphaBits + (inAlphaStride * rowIndex);

            for (PRUint32 i = 0; i < (PRUint32) imgWidth; i++) {
                // pull out the bit value into alpha
                PRInt32 bit = i % 8;
                PRInt32 byte = i / 8;

#ifdef IS_LITTLE_ENDIAN
                PRUint8 a = (inrowalpha[byte] >> (7-bit)) & 1;
#else
                PRUint8 a = (inrowalpha[byte] >> bit) & 1;
#endif

#ifdef XP_MACOSX
                // skip extra X8 byte on OSX
                inrowrgb++;
#endif

                // handle rgb data; need to multiply the alpha out,
                // but we short-circuit that here since we know that a
                // can only be 0 or 1
                if (a) {
                    PRUint8 b = *inrowrgb++;
                    PRUint8 g = *inrowrgb++;
                    PRUint8 r = *inrowrgb++;

#ifdef IS_BIG_ENDIAN
                    // alpha
                    *outData++ = 0xff;
#endif

                    if (useBGR) {
                        *outData++ = b;
                        *outData++ = g;
                        *outData++ = r;
                    } else {
                        *outData++ = r;
                        *outData++ = g;
                        *outData++ = b;
                    }

#ifdef IS_LITTLE_ENDIAN
                    // alpha
                    *outData++ = 0xff;
#endif
                } else {
                    // alpha is 0, so we need to write all 0's,
                    // ignoring input color
                    inrowrgb += 3;
                    *outData++ = 0;
                    *outData++ = 0;
                    *outData++ = 0;
                    *outData++ = 0;
                }
            }
        }
        rv = NS_OK;
    } else if (format == gfxIFormats::RGB_A8 || format == gfxIFormats::BGR_A8) {
        useBGR = (format & 1);

#ifdef IS_BIG_ENDIAN
        useBGR = !useBGR;
#endif

        for (PRUint32 j = 0; j < (PRUint32) imgHeight; j++) {
            PRUint32 rowIndex;
            if (topToBottom)
                rowIndex = j;
            else
                rowIndex = imgHeight - j - 1;

            PRUint8 *inrowrgb = inPixBits + (inPixStride * rowIndex);
            PRUint8 *inrowalpha = inAlphaBits + (inAlphaStride * rowIndex);

            for (PRUint32 i = 0; i < (PRUint32) imgWidth; i++) {
                // pull out alpha; we'll need it to premultiply
                PRUint8 a = *inrowalpha++;

                // handle rgb data; we need to fully premultiply
                // with the alpha
#ifdef XP_MACOSX
                // skip extra X8 byte on OSX
                inrowrgb++;
#endif

                // XXX gcc bug: gcc seems to push "r" into a register
                // early, and pretends that it's in that register
                // throughout the 3 macros below.  At the end
                // of the 3rd macro, the correct r value is
                // calculated but never stored anywhere -- the r variable
                // has the value of the low byte of register that it
                // was stuffed into, which has the result of some 
                // intermediate calculation.
                // I've seen this on gcc 3.4.2 x86 (Fedora Core 3)
                // and gcc 3.3 PPC (OS X 10.3)

                //PRUint8 b, g, r;
                //FAST_DIVIDE_BY_255(b, *inrowrgb++ * a - a / 2);
                //FAST_DIVIDE_BY_255(g, *inrowrgb++ * a - a / 2);
                //FAST_DIVIDE_BY_255(r, *inrowrgb++ * a - a / 2);

                PRUint8 b = (*inrowrgb++ * a - a / 2) / 255;
                PRUint8 g = (*inrowrgb++ * a - a / 2) / 255;
                PRUint8 r = (*inrowrgb++ * a - a / 2) / 255;

#ifdef IS_BIG_ENDIAN
                *outData++ = a;
#endif

                if (useBGR) {
                    *outData++ = b;
                    *outData++ = g;
                    *outData++ = r;
                } else {
                    *outData++ = r;
                    *outData++ = g;
                    *outData++ = b;
                }

#ifdef IS_LITTLE_ENDIAN
                *outData++ = a;
#endif
            }
        }
        rv = NS_OK;
    } else {
        rv = NS_ERROR_FAILURE;
    }

    if (img->GetHasAlphaMask())
        frame->UnlockAlphaData();
    frame->UnlockImageData();

    if (NS_FAILED(rv)) {
        nsMemory::Free(cairoImgData);
        return rv;
    }

    cairo_surface_t *imgSurf =
        cairo_image_surface_create_for_data(cairoImgData, CAIRO_FORMAT_ARGB32,
                                            imgWidth, imgHeight, imgWidth*4);

    *aCairoSurface = imgSurf;
    *imgData = cairoImgData;
#endif

    return NS_OK;
}

Here is the call graph for this function:

void nsIDOMCanvasRenderingContext2D::clearRect ( in float  x,
in float  y,
in float  w,
in float  h 
) [inherited]
PRBool nsCanvasRenderingContext2D::ConvertJSValToDouble ( double *  aProp,
JSContext aContext,
jsval  aValue 
) [static, protected]

Definition at line 2096 of file nsCanvasRenderingContext2D.cpp.

{
  jsdouble temp;
  if (::JS_ValueToNumber(aContext, aValue, &temp)) {
    *aProp = (jsdouble)temp;
  }
  else {
    ::JS_ReportError(aContext, "Parameter must be a number");
    return JS_FALSE;
  }

  return JS_TRUE;
}

Here is the call graph for this function:

PRBool nsCanvasRenderingContext2D::ConvertJSValToUint32 ( PRUint32 aProp,
JSContext aContext,
jsval  aValue 
) [static, protected]

Definition at line 2080 of file nsCanvasRenderingContext2D.cpp.

{
  uint32 temp;
  if (::JS_ValueToECMAUint32(aContext, aValue, &temp)) {
    *aProp = (PRUint32)temp;
  }
  else {
    ::JS_ReportError(aContext, "Parameter must be an integer");
    return JS_FALSE;
  }

  return JS_TRUE;
}

Here is the call graph for this function:

PRBool nsCanvasRenderingContext2D::ConvertJSValToXPCObject ( nsISupports **  aSupports,
REFNSIID  aIID,
JSContext aContext,
jsval  aValue 
) [static, protected]

Definition at line 2112 of file nsCanvasRenderingContext2D.cpp.

{
  *aSupports = nsnull;
  if (JSVAL_IS_NULL(aValue)) {
    return JS_TRUE;
  }

  if (JSVAL_IS_OBJECT(aValue)) {
    // WrapJS does all the work to recycle an existing wrapper and/or do a QI
    nsresult rv = nsContentUtils::XPConnect()->
      WrapJS(aContext, JSVAL_TO_OBJECT(aValue), aIID, (void**)aSupports);

    return NS_SUCCEEDED(rv);
  }

  return JS_FALSE;
}

Here is the call graph for this function:

nsIDOMCanvasGradient nsIDOMCanvasRenderingContext2D::createLinearGradient ( in float  x0,
in float  y0,
in float  x1,
in float  y1 
) [inherited]
nsIDOMCanvasGradient nsIDOMCanvasRenderingContext2D::createRadialGradient ( in float  x0,
in float  y0,
in float  r0,
in float  x1,
in float  y1,
in float  r1 
) [inherited]

Definition at line 474 of file nsCanvasRenderingContext2D.cpp.

                                        {
        return mStyleStack[mSaveCount];
    }

Here is the caller graph for this function:

Definition at line 554 of file nsCanvasRenderingContext2D.cpp.

{
    if (mCairo) {
        cairo_destroy(mCairo);
        mCairo = nsnull;
    }

    if (mSurface) {
        cairo_surface_destroy(mSurface);
        mSurface = nsnull;
    }

#ifdef MOZ_WIDGET_GTK2
    if (mSurfacePixmap != None) {
        XFreePixmap(GDK_DISPLAY(), mSurfacePixmap);
        mSurfacePixmap = None;
    }
#endif

    if (mImageSurfaceData) {
        PR_Free (mImageSurfaceData);
        mImageSurfaceData = nsnull;
    }
}

Here is the caller graph for this function:

Definition at line 661 of file nsCanvasRenderingContext2D.cpp.

{
    for (int i = 0; i < STYLE_MAX; i++) {
        mDirtyStyle[i] = PR_TRUE;
    }
}

Here is the caller graph for this function:

void nsCanvasRenderingContext2D::DoDrawImageSecurityCheck ( nsIURI aURI,
PRBool  forceWriteOnly 
) [protected]

Definition at line 669 of file nsCanvasRenderingContext2D.cpp.

{
    // Callers should ensure that mCanvasElement is non-null before calling this
    if (!mCanvasElement) {
        NS_WARNING("DoDrawImageSecurityCheck called without canvas element!");
        return;
    }

    if (mCanvasElement->IsWriteOnly())
        return;

    // If we explicitly set WriteOnly just do it and get out
    if (forceWriteOnly) {
        mCanvasElement->SetWriteOnly();
        return;
    }

    // Further security checks require a URI. If we don't have one the image
    // must be another canvas and we inherit the forceWriteOnly state
    if (!aURI)
        return;

    nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();

#ifdef MOZILLA_1_8_BRANCH
    nsCOMPtr<nsIDOMNode> elem = do_QueryInterface(mCanvasElement);
    if (elem && ssm) {
        nsCOMPtr<nsIPrincipal> elemPrincipal;
        nsCOMPtr<nsIPrincipal> uriPrincipal;
        nsCOMPtr<nsIDocument> elemDocument;
        nsContentUtils::GetDocumentAndPrincipal(elem, getter_AddRefs(elemDocument), getter_AddRefs(elemPrincipal));
        ssm->GetCodebasePrincipal(aURI, getter_AddRefs(uriPrincipal));

        if (uriPrincipal && elemPrincipal) {
            nsresult rv =
                ssm->CheckSameOriginPrincipal(elemPrincipal, uriPrincipal);
            if (NS_SUCCEEDED(rv)) {
                // Same origin
                return;
            }
        }
    }
#else
    nsCOMPtr<nsINode> elem = do_QueryInterface(mCanvasElement);
    if (elem && ssm) {
        nsCOMPtr<nsIPrincipal> uriPrincipal;
        ssm->GetCodebasePrincipal(aURI, getter_AddRefs(uriPrincipal));

        if (uriPrincipal) {
            nsresult rv = ssm->CheckSameOriginPrincipal(elem->NodePrincipal(),
                                                        uriPrincipal);
            if (NS_SUCCEEDED(rv)) {
                // Same origin
                return;
            }
        }
    }
#endif

    mCanvasElement->SetWriteOnly();
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCanvasRenderingContext2D::DrawNativeSurfaces ( nsIDrawingSurface aBlackSurface,
nsIDrawingSurface aWhiteSurface,
const nsIntSize aSurfaceSize,
nsIRenderingContext aBlackContext 
) [protected]

Definition at line 2785 of file nsCanvasRenderingContext2D.cpp.

{
    // check if the dimensions are too large;
    // if they are, we may easily overflow malloc later on
    if (!CheckSaneImageSize (aSurfaceSize.width, aSurfaceSize.height))
        return NS_ERROR_FAILURE;

    // Acquire alpha values
    nsAutoArrayPtr<PRUint8> alphas;
    nsresult rv;
    if (aWhiteSurface) {
        // There is transparency. Use the blender to recover alphas.
        nsCOMPtr<nsIBlender> blender = do_CreateInstance(kBlenderCID, &rv);
        NS_ENSURE_SUCCESS(rv, rv);
        nsIDeviceContext* dc = nsnull;
        aBlackContext->GetDeviceContext(dc);
        rv = blender->Init(dc);
        NS_ENSURE_SUCCESS(rv, rv);
        
        rv = blender->GetAlphas(nsRect(0, 0, aSurfaceSize.width, aSurfaceSize.height),
                                aBlackSurface, aWhiteSurface, getter_Transfers(alphas));
        NS_ENSURE_SUCCESS(rv, rv);
    }

    // We use aBlackSurface to get the image color data
    PRUint8* data;
    PRInt32 rowLen, rowSpan;
    rv = aBlackSurface->Lock(0, 0, aSurfaceSize.width, aSurfaceSize.height,
                             (void**)&data, &rowSpan, &rowLen,
                             NS_LOCK_SURFACE_READ_ONLY);
    if (NS_FAILED(rv))
        return rv;

    // Get info about native surface layout
    PRUint32 bytesPerPix = rowLen/aSurfaceSize.width;
    nsPixelFormat format;
    
#ifndef XP_MACOSX
    rv = aBlackSurface->GetPixelFormat(&format);
    if (NS_FAILED(rv)) {
        aBlackSurface->Unlock();
        return rv;
    }
#else
    // On the mac, GetPixelFormat returns NS_ERROR_NOT_IMPLEMENTED;
    // we fake the pixel format here.  The data that we care about
    // will be in ABGR format, either 8-8-8 or 5-5-5.

    if (bytesPerPix == 4) {
        format.mRedZeroMask   = 0xff;
        format.mGreenZeroMask = 0xff;
        format.mBlueZeroMask  = 0xff;
        format.mAlphaZeroMask = 0;
        
        format.mRedMask   = 0x00ff0000;
        format.mGreenMask = 0x0000ff00;
        format.mBlueMask  = 0x000000ff;
        format.mAlphaMask = 0;
        
        format.mRedCount   = 8;
        format.mGreenCount = 8;
        format.mBlueCount  = 8;
        format.mAlphaCount = 0;
        
        format.mRedShift   = 16;
        format.mGreenShift = 8;
        format.mBlueShift  = 0;
        format.mAlphaShift = 0;
    } else if (bytesPerPix == 2) {
        format.mRedZeroMask   = 0x1f;
        format.mGreenZeroMask = 0x1f;
        format.mBlueZeroMask  = 0x1f;
        format.mAlphaZeroMask = 0;
        
        format.mRedMask   = 0x7C00;
        format.mGreenMask = 0x03E0;
        format.mBlueMask  = 0x001F;
        format.mAlphaMask = 0;
        
        format.mRedCount   = 5;
        format.mGreenCount = 5;
        format.mBlueCount  = 5;
        format.mAlphaCount = 0;
        
        format.mRedShift   = 10;
        format.mGreenShift = 5;
        format.mBlueShift  = 0;
        format.mAlphaShift = 0;
    } else {
        // no clue!
        aBlackSurface->Unlock();
        return NS_ERROR_FAILURE;
    }
    
#endif

    // Create a temporary surface to hold the full-size image in cairo
    // image format.
    nsAutoArrayPtr<PRUint8> tmpBuf(new PRUint8[aSurfaceSize.width*aSurfaceSize.height*4]);
    if (!tmpBuf) {
        aBlackSurface->Unlock();
        return NS_ERROR_OUT_OF_MEMORY;
    }

    cairo_surface_t *tmpSurf =
        cairo_image_surface_create_for_data(tmpBuf.get(),
                                            CAIRO_FORMAT_ARGB32, aSurfaceSize.width, aSurfaceSize.height,
                                            aSurfaceSize.width*4);
    if (!tmpSurf) {
        aBlackSurface->Unlock();
        return NS_ERROR_OUT_OF_MEMORY;
    }

#ifdef IS_BIG_ENDIAN
#define BLUE_BYTE 3
#define GREEN_BYTE 2
#define RED_BYTE 1
#define ALPHA_BYTE 0
#else
#define BLUE_BYTE 0
#define GREEN_BYTE 1
#define RED_BYTE 2
#define ALPHA_BYTE 3
#endif

// Mac surfaces are big endian.
#if defined(IS_BIG_ENDIAN) || defined(XP_MACOSX)
#define NATIVE_SURFACE_IS_BIG_ENDIAN
#endif

// OS/2 needs this painted the other way around
#ifdef XP_OS2
#define NATIVE_SURFACE_IS_VERTICALLY_FLIPPED
#endif

    // Convert the data
    PRUint8* dest = tmpBuf;
    PRInt32 index = 0;
    
    PRUint32 RScale = ComputeScaleFactor(format.mRedCount);
    PRUint32 GScale = ComputeScaleFactor(format.mGreenCount);
    PRUint32 BScale = ComputeScaleFactor(format.mBlueCount);
    
    for (PRInt32 i = 0; i < aSurfaceSize.height; ++i) {
#ifdef NATIVE_SURFACE_IS_VERTICALLY_FLIPPED
        PRUint8* src = data + (aSurfaceSize.height-1 - i)*rowSpan;
#else
        PRUint8* src = data + i*rowSpan;
#endif
        for (PRInt32 j = 0; j < aSurfaceSize.width; ++j) {
            /* v is the pixel value */
#ifdef NATIVE_SURFACE_IS_BIG_ENDIAN
            PRUint32 v = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
            v >>= (32 - 8*bytesPerPix);
#else
            PRUint32 v = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
#endif
            // Note that because aBlackSurface is the image rendered
            // onto black, the channel values we get here have
            // effectively been premultipled by the alpha value.
            dest[BLUE_BYTE] = 
              (PRUint8)((((v & format.mBlueMask) >> format.mBlueShift)*BScale) >> 8);
            dest[GREEN_BYTE] =
              (PRUint8)((((v & format.mGreenMask) >> format.mGreenShift)*GScale) >> 8);
            dest[RED_BYTE] =
              (PRUint8)((((v & format.mRedMask) >> format.mRedShift)*RScale) >> 8);
            dest[ALPHA_BYTE] = alphas ? alphas[index++] : 0xFF;
            src += bytesPerPix;
            dest += 4;
        }
    }

#undef RED_BYTE
#undef GREEN_BYTE
#undef BLUE_BYTE
#undef ALPHA_BYTE

    cairo_set_source_surface(mCairo, tmpSurf, 0, 0);
    cairo_paint_with_alpha(mCairo, CurrentState().globalAlpha);
    
    cairo_surface_destroy(tmpSurf);
    aBlackSurface->Unlock();
    return Redraw();
}

Here is the call graph for this function:

void nsIDOMCanvasRenderingContext2D::drawWindow ( in nsIDOMWindow  window,
in long  x,
in long  y,
in long  w,
in long  h,
in DOMString  bgColor 
) [inherited]

Renders a region of a window into the canvas.

The contents of the window's viewport are rendered, ignoring viewport clipping and scrolling.

Parameters:
x
y
w
hspecify the area of the window to render, in CSS pixels.
backgroundColorthe canvas is filled with this color before we render the window into it. This color may be transparent/translucent. It is given as a CSS color string (e.g., rgb() or rgba()).

Of course, the rendering obeys the current scale, transform and globalAlpha values.

Hints: -- If 'rgba(0,0,0,0)' is used for the background color, the drawing will be transparent wherever the window is transparent. -- Top-level browsed documents are usually not transparent because the user's background-color preference is applied, but IFRAMEs are transparent if the page doesn't set a background. -- If an opaque color is used for the background color, rendering will be faster because we won't have to compute the window's transparency.

This API cannot currently be used by Web content. It is chrome only.

void nsIDOMCanvasRenderingContext2D::fillRect ( in float  x,
in float  y,
in float  w,
in float  h 
) [inherited]

Definition at line 543 of file nsCanvasRenderingContext2D.cpp.

{
    if (!mCanvasElement)
        return nsnull;

    nsIFrame *fr = nsnull;
    mCanvasElement->GetPrimaryCanvasFrame(&fr);
    return fr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsCanvasRenderingContext2D::GetInputStream ( const nsACString &  aMimeType,
const nsAString &  aEncoderOptions,
nsIInputStream **  aStream 
) [virtual]

Implements nsICanvasRenderingContextInternal.

Definition at line 1083 of file nsCanvasRenderingContext2D.cpp.

{
    if (!mSurface || cairo_surface_status(mSurface) != CAIRO_STATUS_SUCCESS)
        return NS_ERROR_FAILURE;

    nsCString conid(NS_LITERAL_CSTRING("@mozilla.org/image/encoder;2?type="));
    conid += aMimeType;

    nsCOMPtr<imgIEncoder> encoder = do_CreateInstance(conid.get());
    if (!encoder)
        return NS_ERROR_FAILURE;

    if (mImageSurfaceData) {
        encoder->InitFromData(mImageSurfaceData,
                              mWidth * mHeight * 4, mWidth, mHeight, mWidth * 4,
                              imgIEncoder::INPUT_FORMAT_HOSTARGB,
                              aEncoderOptions);
    } else {
        nsAutoArrayPtr<PRUint8> imageBuffer((PRUint8*) PR_Malloc(sizeof(PRUint8) * mWidth * mHeight * 4));
        if (!imageBuffer)
            return NS_ERROR_FAILURE;

        cairo_surface_t *imgsurf = cairo_image_surface_create_for_data (imageBuffer.get(),
                                                                        CAIRO_FORMAT_ARGB32,
                                                                        mWidth, mHeight, mWidth * 4);
        if (!imgsurf || cairo_surface_status(imgsurf))
            return NS_ERROR_FAILURE;

        cairo_t *cr = cairo_create(imgsurf);
        cairo_surface_destroy (imgsurf);

        cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
        cairo_set_source_surface (cr, mSurface, 0, 0);
        cairo_paint (cr);
        cairo_destroy (cr);

        encoder->InitFromData(imageBuffer.get(),
                              mWidth * mHeight * 4, mWidth, mHeight, mWidth * 4,
                              imgIEncoder::INPUT_FORMAT_HOSTARGB,
                              aEncoderOptions);
    }

    return CallQueryInterface(encoder, aStream);
}

Here is the call graph for this function:

boolean nsIDOMCanvasRenderingContext2D::isPointInPath ( in float  x,
in float  y 
) [inherited]
void nsIDOMCanvasRenderingContext2D::lineTo ( in float  x,
in float  y 
) [inherited]
void nsIDOMCanvasRenderingContext2D::moveTo ( in float  x,
in float  y 
) [inherited]
void nsIDOMCanvasRenderingContext2D::quadraticCurveTo ( in float  cpx,
in float  cpy,
in float  x,
in float  y 
) [inherited]
void nsIDOMCanvasRenderingContext2D::rect ( in float  x,
in float  y,
in float  w,
in float  h 
) [inherited]

Definition at line 763 of file nsCanvasRenderingContext2D.cpp.

{
    nsIFrame *frame = GetCanvasLayoutFrame();
    if (frame) {
        nsRect r = frame->GetRect();
        r.x = r.y = 0;
        frame->Invalidate(r, PR_FALSE);
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsICanvasRenderingContextInternal.

Definition at line 891 of file nsCanvasRenderingContext2D.cpp.

{
    nsresult rv = NS_OK;

    if (!mSurface || !mCairo ||
        cairo_surface_status(mSurface) ||
        cairo_status(mCairo))
        return NS_ERROR_FAILURE;

#ifdef MOZ_CAIRO_GFX

    if (!mThebesSurface)
        return NS_ERROR_FAILURE;

    gfxContext* ctx = (gfxContext*) rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
    nsRefPtr<gfxPattern> pat = new gfxPattern(mThebesSurface);

    // XXX I don't want to use PixelSnapped here, but layout doesn't guarantee
    // pixel alignment for this stuff!
    ctx->NewPath();
    ctx->PixelSnappedRectangleAndSetPattern(gfxRect(0, 0, mWidth, mHeight), pat);
    ctx->Fill();

#else

    // non-Thebes; this becomes exciting
    cairo_surface_t *dest = nsnull;
    cairo_t *dest_cr = nsnull;

#ifdef XP_WIN
    void *ptr = nsnull;
#ifdef MOZILLA_1_8_BRANCH
    rv = rc->RetrieveCurrentNativeGraphicData(&ptr);
    if (NS_FAILED(rv) || !ptr)
        return NS_ERROR_FAILURE;
#else
    ptr = rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_WINDOWS_DC);
#endif
    HDC dc = (HDC) ptr;

    dest = cairo_win32_surface_create (dc);
    dest_cr = cairo_create (dest);
#endif

#ifdef XP_OS2
    void *ptr = nsnull;
#ifdef MOZILLA_1_8_BRANCH
    rv = rc->RetrieveCurrentNativeGraphicData(&ptr);
    if (NS_FAILED(rv) || !ptr)
        return NS_ERROR_FAILURE;
#else
    /* OS/2 also uses NATIVE_WINDOWS_DC to get a native OS/2 PS */
    ptr = rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_WINDOWS_DC);
#endif

    HPS hps = (HPS)ptr;
    nsDrawingSurfaceOS2 *surface; /* to get the dimensions from this */
    PRUint32 width, height;
    rc->GetDrawingSurface((nsIDrawingSurface**)&surface);
    surface->GetDimensions(&width, &height);

    dest = cairo_os2_surface_create(hps, width, height);
    cairo_surface_mark_dirty(dest); // needed on OS/2 for initialization
    dest_cr = cairo_create(dest);
#endif

#ifdef MOZ_WIDGET_GTK2
    GdkDrawable *gdkdraw = nsnull;
#ifdef MOZILLA_1_8_BRANCH
    rv = rc->RetrieveCurrentNativeGraphicData((void**) &gdkdraw);
    if (NS_FAILED(rv) || !gdkdraw)
        return NS_ERROR_FAILURE;
#else
    gdkdraw = (GdkDrawable*) rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_GDK_DRAWABLE);
    if (!gdkdraw)
        return NS_ERROR_FAILURE;
#endif

    gint w, h;
    gdk_drawable_get_size (gdkdraw, &w, &h);
    dest = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY(gdkdraw),
                                      GDK_DRAWABLE_XID(gdkdraw),
                                      GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(gdkdraw)),
                                      w, h);
    dest_cr = cairo_create (dest);
#endif

    nsTransform2D *tx = nsnull;
    rc->GetCurrentTransform(tx);

    nsIDeviceContext *dctx;
    rc->GetDeviceContext(dctx);

    // Until we can use the quartz2 surface, mac will be different,
    // since we'll use CG to render.
#ifndef XP_MACOSX

    float x0 = 0.0, y0 = 0.0;
    float sx = 1.0, sy = 1.0;

    if (tx->GetType() & MG_2DTRANSLATION) {
        tx->Transform(&x0, &y0);
    }

    if (tx->GetType() & MG_2DSCALE) {
        sx = sy = dctx->DevUnitsToTwips();
        tx->TransformNoXLate(&sx, &sy);
    }

    cairo_translate (dest_cr, NSToIntRound(x0), NSToIntRound(y0));
    if (sx != 1.0 || sy != 1.0)
        cairo_scale (dest_cr, sx, sy);

    cairo_rectangle (dest_cr, 0, 0, mWidth, mHeight);
    cairo_clip (dest_cr);

    cairo_set_source_surface (dest_cr, mSurface, 0, 0);
    cairo_paint (dest_cr);

    if (dest_cr)
        cairo_destroy (dest_cr);
    if (dest)
        cairo_surface_destroy (dest);

#else

    // OSX path
    nsIDrawingSurface *ds = nsnull;
    rc->GetDrawingSurface(&ds);
    if (!ds)
        return NS_ERROR_FAILURE;

    nsDrawingSurfaceMac *macds = NS_STATIC_CAST(nsDrawingSurfaceMac*, ds);
    CGContextRef cgc = macds->StartQuartzDrawing();

    CGDataProviderRef dataProvider;
    CGImageRef img;

    dataProvider = CGDataProviderCreateWithData (NULL, mImageSurfaceData,
                                                 mWidth * mHeight * 4,
                                                 NULL);
    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
    img = CGImageCreate (mWidth, mHeight, 8, 32, mWidth * 4, rgb,
                         (CGImageAlphaInfo)(kCGImageAlphaPremultipliedFirst |
                                            CG_BITMAP_BYTE_ORDER_FLAG),
                         dataProvider, NULL, false, kCGRenderingIntentDefault);
    CGColorSpaceRelease (rgb);
    CGDataProviderRelease (dataProvider);

    float x0 = 0.0, y0 = 0.0;
    float sx = 1.0, sy = 1.0;
    if (tx->GetType() & MG_2DTRANSLATION) {
        tx->Transform(&x0, &y0);
    }

    if (tx->GetType() & MG_2DSCALE) {
        float p2t = dctx->DevUnitsToTwips();
        sx = p2t, sy = p2t;
        tx->TransformNoXLate(&sx, &sy);
    }

    CGContextTranslateCTM (cgc, NSToIntRound(x0), NSToIntRound(y0));
    if (sx != 1.0 || sy != 1.0)
        CGContextScaleCTM (cgc, sx, sy);

    // flip, so that the image gets drawn correct-side up
    CGContextScaleCTM (cgc, 1.0, -1.0);
    CGContextDrawImage (cgc, CGRectMake(0, -mHeight, mWidth, mHeight), img);

    CGImageRelease (img);

    macds->EndQuartzDrawing(cgc);

    rv = NS_OK;
#endif
#endif

    return rv;
}

Here is the call graph for this function:

Definition at line 1072 of file nsCanvasRenderingContext2D.cpp.

{
    cairo_t *cr = cairo_create (surf);
    cairo_set_source_surface (cr, mSurface, 0, 0);
    cairo_paint (cr);
    cairo_destroy (cr);

    return NS_OK;
}

Here is the call graph for this function:

void nsIDOMCanvasRenderingContext2D::rotate ( in float  angle) [inherited]
void nsIDOMCanvasRenderingContext2D::scale ( in float  x,
in float  y 
) [inherited]

Definition at line 776 of file nsCanvasRenderingContext2D.cpp.

{
    double r = double(NS_GET_R(c) / 255.0);
    double g = double(NS_GET_G(c) / 255.0);
    double b = double(NS_GET_B(c) / 255.0);
    double a = double(NS_GET_A(c) / 255.0) * CurrentState().globalAlpha;

    cairo_set_source_rgba (mCairo, r, g, b, a);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsICanvasRenderingContextInternal.

Definition at line 1135 of file nsCanvasRenderingContext2D.cpp.

{
    // don't hold a ref to this!
    mCanvasElement = aCanvasElement;

    // set up our css parser, if necessary
    if (!mCSSParser) {
        mCSSParser = do_CreateInstance("@mozilla.org/content/css-parser;1");
    }

    return NS_OK;
}

Here is the call graph for this function:

Implements nsICanvasRenderingContextInternal.

Definition at line 787 of file nsCanvasRenderingContext2D.cpp.

{
    Destroy();

    // Check that the dimensions are sane
    if (!CheckSaneImageSize(width, height))
        return NS_ERROR_FAILURE;

    mWidth = width;
    mHeight = height;

#ifdef MOZ_CAIRO_GFX
    mThebesSurface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(width, height, gfxASurface::ImageFormatARGB32);
    mThebesContext = new gfxContext(mThebesSurface);

    mSurface = mThebesSurface->CairoSurface();
    cairo_surface_reference(mSurface);
    mCairo = mThebesContext->GetCairo();
    cairo_reference(mCairo);
#else
    // non-cairo gfx
#ifdef XP_WIN
#ifndef MOZILLA_1_8_BRANCH
    mSurface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32,
                                                    mWidth, mHeight);
#else
    mSurface = _cairo_win32_surface_create_dib (CAIRO_FORMAT_ARGB32,
                                                mWidth, mHeight);
#endif
#elif MOZ_WIDGET_GTK2
    // On most current X servers, using the software-only surface
    // actually provides a much smoother and faster display.
    // However, we provide MOZ_CANVAS_USE_RENDER for whomever wants to
    // go that route.
    if (getenv("MOZ_CANVAS_USE_RENDER")) {
        XRenderPictFormat *fmt = XRenderFindStandardFormat (GDK_DISPLAY(),
                                                            PictStandardARGB32);
        if (fmt) {
            int npfmts = 0;
            XPixmapFormatValues *pfmts = XListPixmapFormats(GDK_DISPLAY(), &npfmts);
            for (int i = 0; i < npfmts; i++) {
                if (pfmts[i].depth == 32) {
                    npfmts = -1;
                    break;
                }
            }
            XFree(pfmts);

            if (npfmts == -1) {
                mSurfacePixmap = XCreatePixmap (GDK_DISPLAY(),
                                                DefaultRootWindow(GDK_DISPLAY()),
                                                width, height, 32);
                mSurface = cairo_xlib_surface_create_with_xrender_format
                    (GDK_DISPLAY(), mSurfacePixmap, DefaultScreenOfDisplay(GDK_DISPLAY()),
                     fmt, mWidth, mHeight);
            }
        }
    }
#endif

    // fall back to image surface
    if (!mSurface) {
        mImageSurfaceData = (PRUint8*) PR_Malloc (mWidth * mHeight * 4);
        if (!mImageSurfaceData)
            return NS_ERROR_OUT_OF_MEMORY;

        mSurface = cairo_image_surface_create_for_data (mImageSurfaceData,
                                                        CAIRO_FORMAT_ARGB32,
                                                        mWidth, mHeight,
                                                        mWidth * 4);
    }

    mCairo = cairo_create(mSurface);
#endif

    // set up the initial canvas defaults
    mStyleStack.Clear();
    mSaveCount = 0;

    ContextState *state = mStyleStack.AppendElement();
    state->globalAlpha = 1.0;
    for (int i = 0; i < STYLE_MAX; i++)
        state->colorStyles[i] = NS_RGB(0,0,0);
    mLastStyle = -1;

    DirtyAllStyles();

    cairo_set_operator(mCairo, CAIRO_OPERATOR_CLEAR);
    cairo_new_path(mCairo);
    cairo_rectangle(mCairo, 0, 0, mWidth, mHeight);
    cairo_fill(mCairo);

    cairo_set_line_width(mCairo, 1.0);
    cairo_set_operator(mCairo, CAIRO_OPERATOR_OVER);
    cairo_set_miter_limit(mCairo, 10.0);
    cairo_set_line_cap(mCairo, CAIRO_LINE_CAP_BUTT);
    cairo_set_line_join(mCairo, CAIRO_LINE_JOIN_MITER);

    cairo_new_path(mCairo);

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsCanvasRenderingContext2D::SetStyleFromVariant ( nsIVariant aStyle,
PRInt32  aWhichStyle 
) [protected]

Definition at line 580 of file nsCanvasRenderingContext2D.cpp.

{
    nsresult rv;
    nscolor color;

    PRUint16 paramType;
    rv = aStyle->GetDataType(&paramType);
    NS_ENSURE_SUCCESS(rv, rv);

    if (paramType == nsIDataType::VTYPE_DOMSTRING) {
        nsString str;
        rv = aStyle->GetAsDOMString(str);
        NS_ENSURE_SUCCESS(rv, rv);

        rv = mCSSParser->ParseColorString(str, nsnull, 0, PR_TRUE, &color);
        if (NS_FAILED(rv))
            return NS_ERROR_DOM_SYNTAX_ERR;

        CurrentState().SetColorStyle(aWhichStyle, color);

        mDirtyStyle[aWhichStyle] = PR_TRUE;
        return NS_OK;
    } else if (paramType == nsIDataType::VTYPE_WSTRING_SIZE_IS) {
        nsAutoString str;

        rv = aStyle->GetAsAString(str);
        NS_ENSURE_SUCCESS(rv, rv);

        rv = mCSSParser->ParseColorString(str, nsnull, 0, PR_TRUE, &color);
        if (NS_FAILED(rv))
            return NS_ERROR_DOM_SYNTAX_ERR;

        CurrentState().SetColorStyle(aWhichStyle, color);

        mDirtyStyle[aWhichStyle] = PR_TRUE;
        return NS_OK;
    } else if (paramType == nsIDataType::VTYPE_INTERFACE ||
               paramType == nsIDataType::VTYPE_INTERFACE_IS)
    {
        nsID *iid;
        nsCOMPtr<nsISupports> iface;
        rv = aStyle->GetAsInterface(&iid, getter_AddRefs(iface));

        nsCOMPtr<nsCanvasGradient> grad(do_QueryInterface(iface));
        if (grad) {
            CurrentState().SetGradientStyle(aWhichStyle, grad);
            mDirtyStyle[aWhichStyle] = PR_TRUE;
            return NS_OK;
        }

        nsCOMPtr<nsCanvasPattern> pattern(do_QueryInterface(iface));
        if (pattern) {
            CurrentState().SetPatternStyle(aWhichStyle, pattern);
            mDirtyStyle[aWhichStyle] = PR_TRUE;
            return NS_OK;
        }
    }

    return NS_ERROR_DOM_SYNTAX_ERR;
}

Here is the call graph for this function:

void nsIDOMCanvasRenderingContext2D::strokeRect ( in float  x,
in float  y,
in float  w,
in float  h 
) [inherited]
void nsCanvasRenderingContext2D::StyleColorToString ( const nscolor aColor,
nsAString &  aStr 
) [protected]

Definition at line 642 of file nsCanvasRenderingContext2D.cpp.

{
    if (NS_GET_A(aColor) == 255) {
        CopyUTF8toUTF16(nsPrintfCString(100, "#%02x%02x%02x",
                                        NS_GET_R(aColor),
                                        NS_GET_G(aColor),
                                        NS_GET_B(aColor)),
                        aStr);
    } else {
        CopyUTF8toUTF16(nsPrintfCString(100, "rgba(%d,%d,%d,%0.2f)",
                                        NS_GET_R(aColor),
                                        NS_GET_G(aColor),
                                        NS_GET_B(aColor),
                                        NS_GET_A(aColor) / 255.0f),
                        aStr);
    }
}

Here is the call graph for this function:

void nsIDOMCanvasRenderingContext2D::translate ( in float  x,
in float  y 
) [inherited]

Member Data Documentation

Definition at line 62 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 79 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 74 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 75 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 86 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 87 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 85 of file nsIDOMCanvasRenderingContext2D.idl.

cairo_t* nsCanvasRenderingContext2D::mCairo [protected]

Definition at line 425 of file nsCanvasRenderingContext2D.cpp.

Definition at line 413 of file nsCanvasRenderingContext2D.cpp.

Definition at line 416 of file nsCanvasRenderingContext2D.cpp.

Definition at line 433 of file nsCanvasRenderingContext2D.cpp.

Definition at line 409 of file nsCanvasRenderingContext2D.cpp.

Definition at line 429 of file nsCanvasRenderingContext2D.cpp.

Definition at line 88 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 432 of file nsCanvasRenderingContext2D.cpp.

Definition at line 424 of file nsCanvasRenderingContext2D.cpp.

Definition at line 472 of file nsCanvasRenderingContext2D.cpp.

cairo_surface_t* nsCanvasRenderingContext2D::mSurface [protected]

Definition at line 426 of file nsCanvasRenderingContext2D.cpp.

Definition at line 409 of file nsCanvasRenderingContext2D.cpp.

Definition at line 93 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 94 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 91 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 92 of file nsIDOMCanvasRenderingContext2D.idl.

Definition at line 78 of file nsIDOMCanvasRenderingContext2D.idl.


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