Bumping manifests a=b2g-bump
[gecko.git] / dom / canvas / DocumentRendererChild.cpp
blobd81d00d052d1ec0e8481bcf267c9894897783ab1
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"
9 #include "gfx2DGlue.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"
20 #include "nsCOMPtr.h"
21 #include "nsColor.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()
39 bool
40 DocumentRendererChild::RenderDocument(nsIDOMWindow *window,
41 const nsRect& documentRect,
42 const mozilla::gfx::Matrix& transform,
43 const nsString& aBGColor,
44 uint32_t renderFlags,
45 bool flushLayout,
46 const nsIntSize& renderSize,
47 nsCString& data)
49 if (flushLayout)
50 nsContentUtils::FlushLayoutForTree(window);
52 nsRefPtr<nsPresContext> presContext;
53 nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window);
54 if (win) {
55 nsIDocShell* docshell = win->GetDocShell();
56 if (docshell) {
57 docshell->GetPresContext(getter_AddRefs(presContext));
60 if (!presContext)
61 return false;
63 nsCSSParser parser;
64 nsCSSValue bgColorValue;
65 if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue)) {
66 return false;
69 nscolor bgColor;
70 if (!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) {
71 return false;
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),
81 4 * renderSize.width,
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);
89 return true;