Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / DocumentRendererParent.cpp
blob7775e4bc2e6e06919cc3c88a1cd35331fe697ccd
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/gfx/2D.h"
6 #include "mozilla/ipc/DocumentRendererParent.h"
7 #include "mozilla/RefPtr.h"
8 #include "gfxPattern.h"
9 #include "nsICanvasRenderingContextInternal.h"
11 using namespace mozilla;
12 using namespace mozilla::gfx;
13 using namespace mozilla::ipc;
15 DocumentRendererParent::DocumentRendererParent()
18 DocumentRendererParent::~DocumentRendererParent()
21 void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas,
22 gfxContext* ctx)
24 mCanvas = aCanvas;
25 mCanvasContext = ctx;
28 void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
29 const nsCString& aData)
31 if (!mCanvas || !mCanvasContext)
32 return;
34 RefPtr<DataSourceSurface> dataSurface =
35 Factory::CreateWrappingDataSourceSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()),
36 aSize.width * 4,
37 IntSize(aSize.width, aSize.height),
38 SurfaceFormat::B8G8R8A8);
39 nsRefPtr<gfxPattern> pat = new gfxPattern(dataSurface, Matrix());
41 gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height));
42 mCanvasContext->NewPath();
43 mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat);
44 mCanvasContext->Fill();
46 // get rid of the pattern surface ref, because aData is very
47 // likely to go away shortly
48 mCanvasContext->SetColor(gfxRGBA(1,1,1,1));
50 gfxRect damageRect = mCanvasContext->UserToDevice(rect);
51 mCanvas->Redraw(damageRect);
54 void
55 DocumentRendererParent::ActorDestroy(ActorDestroyReason aWhy)
57 // Implement me! Bug 1005139
60 bool
61 DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize,
62 const nsCString& data)
64 DrawToCanvas(renderedSize, data);
65 return true;