Line data Source code
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 :
7 : #include "gfx2DGlue.h"
8 : #include "mozilla/gfx/2D.h"
9 : #include "mozilla/gfx/PathHelpers.h"
10 : #include "mozilla/RefPtr.h"
11 : #include "nsICanvasRenderingContextInternal.h"
12 :
13 : using namespace mozilla;
14 : using namespace mozilla::gfx;
15 : using namespace mozilla::ipc;
16 :
17 0 : DocumentRendererParent::DocumentRendererParent()
18 0 : {}
19 :
20 0 : DocumentRendererParent::~DocumentRendererParent()
21 0 : {}
22 :
23 0 : void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas,
24 : gfxContext* ctx)
25 : {
26 0 : mCanvas = aCanvas;
27 0 : mCanvasContext = ctx;
28 0 : }
29 :
30 0 : void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
31 : const nsCString& aData)
32 : {
33 0 : if (!mCanvas || !mCanvasContext)
34 0 : return;
35 :
36 0 : DrawTarget* drawTarget = mCanvasContext->GetDrawTarget();
37 0 : Rect rect(0, 0, aSize.width, aSize.height);
38 0 : MaybeSnapToDevicePixels(rect, *drawTarget, true);
39 : RefPtr<DataSourceSurface> dataSurface =
40 0 : Factory::CreateWrappingDataSourceSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()),
41 0 : aSize.width * 4,
42 0 : IntSize(aSize.width, aSize.height),
43 0 : SurfaceFormat::B8G8R8A8);
44 0 : SurfacePattern pattern(dataSurface, ExtendMode::CLAMP);
45 0 : drawTarget->FillRect(rect, pattern);
46 :
47 0 : gfxRect damageRect = mCanvasContext->UserToDevice(ThebesRect(rect));
48 0 : mCanvas->Redraw(damageRect);
49 : }
50 :
51 : void
52 0 : DocumentRendererParent::ActorDestroy(ActorDestroyReason aWhy)
53 : {
54 : // Implement me! Bug 1005139
55 0 : }
56 :
57 : mozilla::ipc::IPCResult
58 0 : DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize,
59 : const nsCString& data)
60 : {
61 0 : DrawToCanvas(renderedSize, data);
62 0 : return IPC_OK();
63 : }
|