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/ipc/DocumentRendererChild.h"
7 #include "base/basictypes.h"
10 #include "gfxPattern.h"
11 #include "mozilla/gfx/2D.h"
12 #include "mozilla/RefPtr.h"
13 #include "nsPIDOMWindow.h"
14 #include "nsIDOMWindow.h"
15 #include "nsIDocShell.h"
16 #include "nsIInterfaceRequestorUtils.h"
17 #include "nsComponentManagerUtils.h"
18 #include "nsCSSParser.h"
19 #include "nsPresContext.h"
22 #include "gfxContext.h"
23 #include "nsLayoutUtils.h"
24 #include "nsContentUtils.h"
25 #include "nsCSSValue.h"
26 #include "nsRuleNode.h"
27 #include "mozilla/gfx/Matrix.h"
29 using namespace mozilla
;
30 using namespace mozilla::gfx
;
31 using namespace mozilla::ipc
;
33 DocumentRendererChild::DocumentRendererChild()
36 DocumentRendererChild::~DocumentRendererChild()
40 DocumentRendererChild::RenderDocument(nsIDOMWindow
*window
,
41 const nsRect
& documentRect
,
42 const mozilla::gfx::Matrix
& transform
,
43 const nsString
& aBGColor
,
46 const nsIntSize
& renderSize
,
50 nsContentUtils::FlushLayoutForTree(window
);
52 nsRefPtr
<nsPresContext
> presContext
;
53 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(window
);
55 nsIDocShell
* docshell
= win
->GetDocShell();
57 docshell
->GetPresContext(getter_AddRefs(presContext
));
64 nsCSSValue bgColorValue
;
65 if (!parser
.ParseColorString(aBGColor
, nullptr, 0, bgColorValue
)) {
70 if (!nsRuleNode::ComputeColor(bgColorValue
, presContext
, nullptr, bgColor
)) {
74 // Draw directly into the output array.
75 data
.SetLength(renderSize
.width
* renderSize
.height
* 4);
77 RefPtr
<DrawTarget
> dt
=
78 Factory::CreateDrawTargetForData(BackendType::CAIRO
,
79 reinterpret_cast<uint8_t*>(data
.BeginWriting()),
80 IntSize(renderSize
.width
, renderSize
.height
),
82 SurfaceFormat::B8G8R8A8
);
83 nsRefPtr
<gfxContext
> ctx
= new gfxContext(dt
);
84 ctx
->SetMatrix(mozilla::gfx::ThebesMatrix(transform
));
86 nsCOMPtr
<nsIPresShell
> shell
= presContext
->PresShell();
87 shell
->RenderDocument(documentRect
, renderFlags
, bgColor
, ctx
);