NS_ASSERTION(cairoSurf, "No surface"); mOwnsCR = PR_TRUE; mCR = cairo_create(cairoSurf);
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->RetrieveCurrentNativeGraphicData(&data);  mCR = (cairo_t*)data;  cairo_get_matrix(mCR, &mInitialTranslation);  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(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);  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  NS_ASSERTION(cairoSurf, "No surface");  mOwnsCR = PR_TRUE;  mCR = cairo_create(cairoSurf);  // get the translation set on the rendering context. It will be in  // displayunits (i.e. pixels*scale), *not* pixels:  nsTransform2D* xform;  mMozContext->GetCurrentTransform(xform);  float dx, dy;  xform->GetTranslation(&dx, &dy);  cairo_translate(mCR, dx, dy);  cairo_get_matrix(mCR, &mInitialTransform);#if defined(DEBUG_tor) || defined(DEBUG_roc)  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}