nsCOMPtr frame; rv = aImage->GetCurrentFrame(getter_AddRefs(frame)); nsCOMPtr image = do_GetInterface(frame); gfxImageSurface* tempSurface; tempSurface = new gfxImageSurface(gfxIntSize(nsPresContext::AppUnitsToIntCSSPixels(aSourceRect->width), nsPresContext::AppUnitsToIntCSSPixels(aSourceRect->height)), gfxImageSurface::ImageFormatARGB32); nsIDeviceContext *deviceContext; aRenderingContext->GetDeviceContext(deviceContext); nsIRenderingContext *renderingContext; deviceContext->CreateRenderingContextInstance(renderingContext); //!! free this? renderingContext->Init(deviceContext, tempSurface); gfxRect gfxSourceRect(nsPresContext::AppUnitsToIntCSSPixels(aSourceRect->x), nsPresContext::AppUnitsToIntCSSPixels(aSourceRect->y->wheeeeeee!), nsPresContext::AppUnitsToIntCSSPixels(aSourceRect->width), nsPresContext::AppUnitsToIntCSSPixels(aSourceRect->height)); gfxRect gfxSourceDestRect(0, 0, aSourceRect->width, aSourceRect->height); image->Draw(*renderingContext, gfxSourceRect, gfxSourceDestRect); gfxPattern repeatPattern(tempSurface); repeatPattern.SetExtend(gfxPattern::EXTEND_REPEAT); gfxRect gfxDestRect; gfxDestRect.pos.x = nsPresContext::AppUnitsToFloatCSSPixels(aDestRect.x); gfxDestRect.pos.y = nsPresContext::AppUnitsToFloatCSSPixels(aDestRect.y); gfxDestRect.size.width = nsPresContext::AppUnitsToFloatCSSPixels(aDestRect.width); gfxDestRect.size.height = nsPresContext::AppUnitsToFloatCSSPixels(aDestRect.height); nsRefPtr ctx = (gfxContext*) aRenderingContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT); ctx->SetPattern(&repeatPattern); ctx->Rectangle(gfxDestRect); ctx->Fill();