michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/ipc/DocumentRendererParent.h" michael@0: #include "gfxImageSurface.h" michael@0: #include "gfxPattern.h" michael@0: #include "nsICanvasRenderingContextInternal.h" michael@0: michael@0: using namespace mozilla::ipc; michael@0: michael@0: DocumentRendererParent::DocumentRendererParent() michael@0: {} michael@0: michael@0: DocumentRendererParent::~DocumentRendererParent() michael@0: {} michael@0: michael@0: void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas, michael@0: gfxContext* ctx) michael@0: { michael@0: mCanvas = aCanvas; michael@0: mCanvasContext = ctx; michael@0: } michael@0: michael@0: void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize, michael@0: const nsCString& aData) michael@0: { michael@0: if (!mCanvas || !mCanvasContext) michael@0: return; michael@0: michael@0: nsRefPtr surf = michael@0: new gfxImageSurface(reinterpret_cast(const_cast(aData).BeginWriting()), michael@0: gfxIntSize(aSize.width, aSize.height), michael@0: aSize.width * 4, michael@0: gfxImageFormat::ARGB32); michael@0: nsRefPtr pat = new gfxPattern(surf); michael@0: michael@0: gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height)); michael@0: mCanvasContext->NewPath(); michael@0: mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat); michael@0: mCanvasContext->Fill(); michael@0: michael@0: // get rid of the pattern surface ref, because aData is very michael@0: // likely to go away shortly michael@0: mCanvasContext->SetColor(gfxRGBA(1,1,1,1)); michael@0: michael@0: gfxRect damageRect = mCanvasContext->UserToDevice(rect); michael@0: mCanvas->Redraw(damageRect); michael@0: } michael@0: michael@0: bool michael@0: DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize, michael@0: const nsCString& data) michael@0: { michael@0: DrawToCanvas(renderedSize, data); michael@0: return true; michael@0: }