mBuffer->Init(0, 0, mWidth, mHeight, gfxIFormats::BGR_A8, 24);
mBuffer->Init(0, 0, mWidth, mHeight, gfxIFormats::BGR, 24);
nsSVGCairoCanvas::Init(nsIRenderingContext *ctx,                       nsPresContext *presContext,                       const nsRect &dirtyRect){  mPresContext = presContext;  mMozContext = ctx;  NS_ASSERTION(mMozContext, "empty rendering context");  mRenderMode = SVG_RENDER_MODE_NORMAL;#if defined(MOZ_ENABLE_CAIRO_GFX)  mOwnsCR = PR_FALSE;  void* data = ctx->GetNativeGraphicData(nsIRenderingContext::NATIVE_CAIRO_CONTEXT);  mCR = (cairo_t*)data;  cairo_get_matrix(mCR, &mInitialTransform);  return NS_OK;#else // !MOZ_ENABLE_CAIRO_GFX  cairo_surface_t* cairoSurf = nsnull;#if defined(XP_MACOSX)  nsIDrawingSurface *surface;  ctx->GetDrawingSurface(&surface);  mSurface = do_QueryInterface(surface);  surface->GetDimensions(&mWidth, &mHeight);  mQuartzRef = mSurface->StartQuartzDrawing();  CGrafPtr port;  mSurface->GetGrafPtr(&port);  Rect portRect;  ::GetPortBounds(port, &portRect);#ifdef DEBUG_tor  fprintf(stderr, "CAIRO: DS=0x%08x port x=%d y=%d w=%d h=%d\n",          mSurface.get(), portRect.right, portRect.top,          portRect.right - portRect.left, portRect.bottom - portRect.top);#endif  ::SyncCGContextOriginWithPort(mQuartzRef, port);  cairoSurf = cairo_quartz_surface_create(mQuartzRef,                                          portRect.right - portRect.left,                                          portRect.bottom - portRect.top);#elif defined(MOZ_WIDGET_XLIB)  nsIDrawingSurfaceXlib* surface;  ctx->GetDrawingSurface((nsIDrawingSurface**)&surface);  surface->GetDimensions(&mWidth, &mHeight);  XlibRgbHandle* handle;  surface->GetXlibRgbHandle(handle);  Drawable drawable = surface->GetDrawable();  cairoSurf = cairo_xlib_surface_create(xxlib_rgb_get_display(handle),                                        drawable,                                        xxlib_rgb_get_visual(handle),                                        mWidth, mHeight);#elif defined(MOZ_WIDGET_QT)  nsDrawingSurfaceQt* surface;  ctx->GetDrawingSurface((nsIDrawingSurface**)&surface);  surface->GetDimensions(&mWidth, &mHeight);  QPaintDevice* dev = surface->GetPaintDevice();  cairoSurf = cairo_xlib_surface_create(dev->x11Display(),                                        dev->handle(),                                        (Visual*)dev->x11Visual(),                                        mWidth, mHeight);#elif defined(XP_WIN)  nsDrawingSurfaceWin *surface;  HDC hdc;  ctx->GetDrawingSurface((nsIDrawingSurface**)&surface);  surface->GetDimensions(&mWidth, &mHeight);  surface->GetDC(&hdc);  cairoSurf = cairo_win32_surface_create(hdc);#elif defined(MOZ_ENABLE_GTK2) || defined(MOZ_ENABLE_GTK)  nsDrawingSurfaceGTK *surface;  ctx->GetDrawingSurface((nsIDrawingSurface**)&surface);  if (surface) {    surface->GetSize(&mWidth, &mHeight);    GdkDrawable *drawable = surface->GetDrawable();    GdkVisual *visual = gdk_window_get_visual(drawable);    cairoSurf = cairo_xlib_surface_create(GDK_WINDOW_XDISPLAY(drawable),                                          GDK_WINDOW_XWINDOW(drawable),                                          GDK_VISUAL_XVISUAL(visual),                                          mWidth, mHeight);  }#endif  // Account for the transform in the rendering context. We set dx,dy  // to the translation required in the cairo context that will  // ensure the cairo context's origin coincides with the top-left  // of the area we need to draw.  nsTransform2D* xform;  mMozContext->GetCurrentTransform(xform);  float dx, dy;  xform->GetTranslation(&dx, &dy);    if (!cairoSurf) {    /* printing or some platform we don't know about yet - use an image */    float scaledTwipsPerPx = presContext->ScaledPixelsToTwips();    mDestRectScaledTwips = dirtyRect;    mDestRectScaledTwips.ScaleRoundOut(scaledTwipsPerPx);        float twipsPerPx = presContext->PixelsToTwips();    nsRect r = dirtyRect;    r.ScaleRoundOut(twipsPerPx);    mSrcSizeTwips = r.Size();      mWidth = dirtyRect.width;    mHeight = dirtyRect.height;    mContainer = do_CreateInstance("@mozilla.org/image/container;1");    mContainer->Init(mWidth, mHeight, nsnull);        mBuffer = do_CreateInstance("@mozilla.org/gfx/image/frame;2");#ifdef XP_WIN    mBuffer->Init(0, 0, mWidth, mHeight, gfxIFormats::BGR_A8, 24);#else    mBuffer->Init(0, 0, mWidth, mHeight, gfxIFormats::RGB_A8, 24);#endif    mContainer->AppendFrame(mBuffer);    mData = (PRUint8 *)calloc(4 * mWidth * mHeight, 1);    if (!mData)      return NS_ERROR_FAILURE;    cairoSurf = cairo_image_surface_create_for_data(mData, CAIRO_FORMAT_ARGB32,                                                    mWidth, mHeight, 4 * mWidth);        // Ensure that dirtyRect.TopLeft() is translated to (0,0) in the surface                                dx = -dirtyRect.x;    dy = -dirtyRect.y;  }  mOwnsCR = PR_TRUE;  mCR = cairo_create(cairoSurf);  // Destroy our reference to the surface; the cairo_t will continue to hold a reference to it  cairo_surface_destroy(cairoSurf);  cairo_translate(mCR, dx, dy);  cairo_get_matrix(mCR, &mInitialTransform);#if defined(DEBUG_tor) || defined(DEBUG_roc) || defined(DEBUG_scooter)  fprintf(stderr, "cairo translate: %f %f\n", dx, dy);  fprintf(stderr, "cairo dirty: %d %d %d %d\n",                  dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height);#endif  // clip to dirtyRect  cairo_new_path(mCR);  cairo_rectangle(mCR,                  dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height);  cairo_clip(mCR);  cairo_new_path(mCR);  return NS_OK;#endif // !MOZ_ENABLE_CAIRO_GFX}