|
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/. */ |
|
4 |
|
5 #include "mozilla/ipc/DocumentRendererParent.h" |
|
6 #include "gfxImageSurface.h" |
|
7 #include "gfxPattern.h" |
|
8 #include "nsICanvasRenderingContextInternal.h" |
|
9 |
|
10 using namespace mozilla::ipc; |
|
11 |
|
12 DocumentRendererParent::DocumentRendererParent() |
|
13 {} |
|
14 |
|
15 DocumentRendererParent::~DocumentRendererParent() |
|
16 {} |
|
17 |
|
18 void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas, |
|
19 gfxContext* ctx) |
|
20 { |
|
21 mCanvas = aCanvas; |
|
22 mCanvasContext = ctx; |
|
23 } |
|
24 |
|
25 void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize, |
|
26 const nsCString& aData) |
|
27 { |
|
28 if (!mCanvas || !mCanvasContext) |
|
29 return; |
|
30 |
|
31 nsRefPtr<gfxImageSurface> surf = |
|
32 new gfxImageSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()), |
|
33 gfxIntSize(aSize.width, aSize.height), |
|
34 aSize.width * 4, |
|
35 gfxImageFormat::ARGB32); |
|
36 nsRefPtr<gfxPattern> pat = new gfxPattern(surf); |
|
37 |
|
38 gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height)); |
|
39 mCanvasContext->NewPath(); |
|
40 mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat); |
|
41 mCanvasContext->Fill(); |
|
42 |
|
43 // get rid of the pattern surface ref, because aData is very |
|
44 // likely to go away shortly |
|
45 mCanvasContext->SetColor(gfxRGBA(1,1,1,1)); |
|
46 |
|
47 gfxRect damageRect = mCanvasContext->UserToDevice(rect); |
|
48 mCanvas->Redraw(damageRect); |
|
49 } |
|
50 |
|
51 bool |
|
52 DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize, |
|
53 const nsCString& data) |
|
54 { |
|
55 DrawToCanvas(renderedSize, data); |
|
56 return true; |
|
57 } |