1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/src/DocumentRendererParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "mozilla/ipc/DocumentRendererParent.h" 1.9 +#include "gfxImageSurface.h" 1.10 +#include "gfxPattern.h" 1.11 +#include "nsICanvasRenderingContextInternal.h" 1.12 + 1.13 +using namespace mozilla::ipc; 1.14 + 1.15 +DocumentRendererParent::DocumentRendererParent() 1.16 +{} 1.17 + 1.18 +DocumentRendererParent::~DocumentRendererParent() 1.19 +{} 1.20 + 1.21 +void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas, 1.22 + gfxContext* ctx) 1.23 +{ 1.24 + mCanvas = aCanvas; 1.25 + mCanvasContext = ctx; 1.26 +} 1.27 + 1.28 +void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize, 1.29 + const nsCString& aData) 1.30 +{ 1.31 + if (!mCanvas || !mCanvasContext) 1.32 + return; 1.33 + 1.34 + nsRefPtr<gfxImageSurface> surf = 1.35 + new gfxImageSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()), 1.36 + gfxIntSize(aSize.width, aSize.height), 1.37 + aSize.width * 4, 1.38 + gfxImageFormat::ARGB32); 1.39 + nsRefPtr<gfxPattern> pat = new gfxPattern(surf); 1.40 + 1.41 + gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height)); 1.42 + mCanvasContext->NewPath(); 1.43 + mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat); 1.44 + mCanvasContext->Fill(); 1.45 + 1.46 + // get rid of the pattern surface ref, because aData is very 1.47 + // likely to go away shortly 1.48 + mCanvasContext->SetColor(gfxRGBA(1,1,1,1)); 1.49 + 1.50 + gfxRect damageRect = mCanvasContext->UserToDevice(rect); 1.51 + mCanvas->Redraw(damageRect); 1.52 +} 1.53 + 1.54 +bool 1.55 +DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize, 1.56 + const nsCString& data) 1.57 +{ 1.58 + DrawToCanvas(renderedSize, data); 1.59 + return true; 1.60 +}