Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsCanvasRenderingContext2D.cpp File Reference
#include <math.h>
#include "prmem.h"
#include "nsIServiceManager.h"
#include "nsContentUtils.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIDOMCanvasRenderingContext2D.h"
#include "nsICanvasRenderingContextInternal.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
#include "nsIVariant.h"
#include "imgIRequest.h"
#include "imgIContainer.h"
#include "gfxIImageFrame.h"
#include "nsIDOMHTMLCanvasElement.h"
#include "nsICanvasElement.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIImageLoadingContent.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIImage.h"
#include "nsIFrame.h"
#include "nsDOMError.h"
#include "nsICSSParser.h"
#include "nsPrintfCString.h"
#include "nsReadableUtils.h"
#include "nsColor.h"
#include "nsTransform2D.h"
#include "nsIRenderingContext.h"
#include "nsIDeviceContext.h"
#include "nsIBlender.h"
#include "nsGfxCIID.h"
#include "nsIDrawingSurface.h"
#include "nsIScriptSecurityManager.h"
#include "nsIDocShell.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
#include "jsnum.h"
#include "nsTArray.h"
#include "cairo.h"
#include "imgIEncoder.h"

Go to the source code of this file.

Classes

class  nsCanvasGradient
class  nsCanvasPattern
class  nsCanvasRenderingContext2D
 nsCanvasRenderingContext2D More...
class  nsCanvasRenderingContext2D::ContextState

Defines

#define STYLE_STACK_DEPTH   50
#define STYLE_CURRENT_STACK   ((mSaveCount<STYLE_STACK_DEPTH)?mSaveCount:STYLE_STACK_DEPTH-1)
#define VALIDATE(_f)   if (!JSDOUBLE_IS_FINITE(_f)) return PR_FALSE
#define NS_CANVASGRADIENT_PRIVATE_IID   { 0x491d39d8, 0x4058, 0x42bd, { 0xac, 0x76, 0x70, 0xd5, 0x62, 0x7f, 0x02, 0x10 } }
 nsCanvasGradient
#define NS_CANVASPATTERN_PRIVATE_IID   { 0xb85c6c8a, 0x0624, 0x4530, { 0xb8, 0xee, 0xff, 0xdf, 0x42, 0xe8, 0x21, 0x6d } }
 nsCanvasPattern
#define STYLE_MAX   3
#define GET_ARG(dest, whicharg)   do { if (!ConvertJSValToDouble(dest, ctx, whicharg)) { rv = NS_ERROR_INVALID_ARG; goto FAIL; } } while (0)
#define CANVAS_OP_TO_CAIRO_OP(cvsop, cairoop)
#define CANVAS_OP_TO_CAIRO_OP(cvsop, cairoop)
#define BLUE_BYTE   0
#define GREEN_BYTE   1
#define RED_BYTE   2
#define ALPHA_BYTE   3

Functions

static NS_DEFINE_IID (kBlenderCID, NS_BLENDER_CID)
static PRBool CheckSaneImageSize (PRInt32 width, PRInt32 height)
static PRBool CheckSaneSubrectSize (PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h, PRInt32 realWidth, PRInt32 realHeight)
static PRBool FloatValidate (double f1)
static PRBool FloatValidate (double f1, double f2)
static PRBool FloatValidate (double f1, double f2, double f3)
static PRBool FloatValidate (double f1, double f2, double f3, double f4)
static PRBool FloatValidate (double f1, double f2, double f3, double f4, double f5)
static PRBool FloatValidate (double f1, double f2, double f3, double f4, double f5, double f6)
NS_INTERFACE_MAP_END nsresult NS_NewCanvasRenderingContext2D (nsIDOMCanvasRenderingContext2D **aResult)
 CanvasRenderingContext2D impl.
static PRUint32 ComputeScaleFactor (PRUint32 aBits)
 Given aBits, the number of bits in a color channel, compute a number N such that for values v with aBits bits, floor((N*v)/256) is close to v*255.0/(2^aBits - 1) and in particular we need floor((N*(2^aBits - 1))/256) = 255.

Define Documentation

#define ALPHA_BYTE   3
#define BLUE_BYTE   0
#define CANVAS_OP_TO_CAIRO_OP (   cvsop,
  cairoop 
)
Value:
if (op.EqualsLiteral(cvsop))   \
        cairo_op = CAIRO_OPERATOR_##cairoop;
#define CANVAS_OP_TO_CAIRO_OP (   cvsop,
  cairoop 
)
Value:
if (cairo_op == CAIRO_OPERATOR_##cairoop) \
        op.AssignLiteral(cvsop);
#define GET_ARG (   dest,
  whicharg 
)    do { if (!ConvertJSValToDouble(dest, ctx, whicharg)) { rv = NS_ERROR_INVALID_ARG; goto FAIL; } } while (0)
#define GREEN_BYTE   1
#define NS_CANVASGRADIENT_PRIVATE_IID   { 0x491d39d8, 0x4058, 0x42bd, { 0xac, 0x76, 0x70, 0xd5, 0x62, 0x7f, 0x02, 0x10 } }
#define NS_CANVASPATTERN_PRIVATE_IID   { 0xb85c6c8a, 0x0624, 0x4530, { 0xb8, 0xee, 0xff, 0xdf, 0x42, 0xe8, 0x21, 0x6d } }

nsCanvasPattern

Definition at line 296 of file nsCanvasRenderingContext2D.cpp.

#define RED_BYTE   2
#define STYLE_CURRENT_STACK   ((mSaveCount<STYLE_STACK_DEPTH)?mSaveCount:STYLE_STACK_DEPTH-1)

Definition at line 174 of file nsCanvasRenderingContext2D.cpp.

#define STYLE_MAX   3

Definition at line 393 of file nsCanvasRenderingContext2D.cpp.

Definition at line 173 of file nsCanvasRenderingContext2D.cpp.

Definition at line 181 of file nsCanvasRenderingContext2D.cpp.


Function Documentation

PRBool CheckSaneImageSize ( PRInt32  width,
PRInt32  height 
) [static]

Definition at line 2507 of file nsCanvasRenderingContext2D.cpp.

{
    if (width <= 0 || height <= 0)
        return PR_FALSE;

    /* check to make sure we don't overflow a 32-bit */
    PRInt32 tmp = width * height;
    if (tmp / height != width)
        return PR_FALSE;

    tmp = tmp * 4;
    if (tmp / 4 != width * height)
        return PR_FALSE;

    /* reject over-wide or over-tall images */
    const PRInt32 kSizeLimit = 0x00007FFF;
    if (width > kSizeLimit || height > kSizeLimit)
        return PR_FALSE;

    return PR_TRUE;
}

Here is the caller graph for this function:

PRBool CheckSaneSubrectSize ( PRInt32  x,
PRInt32  y,
PRInt32  w,
PRInt32  h,
PRInt32  realWidth,
PRInt32  realHeight 
) [static]

Definition at line 2533 of file nsCanvasRenderingContext2D.cpp.

{
    if (w <= 0 || h <= 0 || x < 0 || y < 0)
        return PR_FALSE;

    if (x >= realWidth  || w > (realWidth - x) ||
        y >= realHeight || h > (realHeight - y))
        return PR_FALSE;

    return PR_TRUE;
}
static PRUint32 ComputeScaleFactor ( PRUint32  aBits) [static]

Given aBits, the number of bits in a color channel, compute a number N such that for values v with aBits bits, floor((N*v)/256) is close to v*255.0/(2^aBits - 1) and in particular we need floor((N*(2^aBits - 1))/256) = 255.

We'll just use a table that gives good results :-).

Definition at line 2772 of file nsCanvasRenderingContext2D.cpp.

{
  static PRUint32 table[9] = {
    0, 255*256, 85*256, 9330, 17*256, 2110, 1038, 515, 256
  };
  
  NS_ASSERTION(aBits <= 8, "more than 8 bits in a color channel not supported");
  NS_ASSERTION(((table[aBits]*((1 << aBits) - 1)) >> 8) == 255,
               "Invalid table entry");
  return table[aBits];
}

Here is the caller graph for this function:

static PRBool FloatValidate ( double  f1) [static]

Definition at line 188 of file nsCanvasRenderingContext2D.cpp.

                                        {
    VALIDATE(f1);
    return PR_TRUE;
}

Here is the caller graph for this function:

static PRBool FloatValidate ( double  f1,
double  f2 
) [static]

Definition at line 193 of file nsCanvasRenderingContext2D.cpp.

                                                   {
    VALIDATE(f1); VALIDATE(f2);
    return PR_TRUE;
}
static PRBool FloatValidate ( double  f1,
double  f2,
double  f3 
) [static]

Definition at line 198 of file nsCanvasRenderingContext2D.cpp.

                                                              {
    VALIDATE(f1); VALIDATE(f2); VALIDATE(f3);
    return PR_TRUE;
}
static PRBool FloatValidate ( double  f1,
double  f2,
double  f3,
double  f4 
) [static]

Definition at line 203 of file nsCanvasRenderingContext2D.cpp.

                                                                         {
    VALIDATE(f1); VALIDATE(f2); VALIDATE(f3); VALIDATE(f4);
    return PR_TRUE;
}
static PRBool FloatValidate ( double  f1,
double  f2,
double  f3,
double  f4,
double  f5 
) [static]

Definition at line 208 of file nsCanvasRenderingContext2D.cpp.

                                                                                    {
    VALIDATE(f1); VALIDATE(f2); VALIDATE(f3); VALIDATE(f4); VALIDATE(f5);
    return PR_TRUE;
}
static PRBool FloatValidate ( double  f1,
double  f2,
double  f3,
double  f4,
double  f5,
double  f6 
) [static]

Definition at line 213 of file nsCanvasRenderingContext2D.cpp.

                                                                                               {
    VALIDATE(f1); VALIDATE(f2); VALIDATE(f3); VALIDATE(f4); VALIDATE(f5); VALIDATE(f6);
    return PR_TRUE;
}
static NS_DEFINE_IID ( kBlenderCID  ,
NS_BLENDER_CID   
) [static]

CanvasRenderingContext2D impl.

Definition at line 518 of file nsCanvasRenderingContext2D.cpp.

{
    nsIDOMCanvasRenderingContext2D* ctx = new nsCanvasRenderingContext2D();
    if (!ctx)
        return NS_ERROR_OUT_OF_MEMORY;

    NS_ADDREF(*aResult = ctx);
    return NS_OK;
}

Here is the call graph for this function: