1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/src/DocumentRendererChild.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "mozilla/ipc/DocumentRendererChild.h" 1.9 + 1.10 +#include "base/basictypes.h" 1.11 + 1.12 +#include "gfx2DGlue.h" 1.13 +#include "gfxPattern.h" 1.14 +#include "mozilla/gfx/2D.h" 1.15 +#include "mozilla/RefPtr.h" 1.16 +#include "nsPIDOMWindow.h" 1.17 +#include "nsIDOMWindow.h" 1.18 +#include "nsIDocShell.h" 1.19 +#include "nsIInterfaceRequestorUtils.h" 1.20 +#include "nsComponentManagerUtils.h" 1.21 +#include "nsCSSParser.h" 1.22 +#include "nsPresContext.h" 1.23 +#include "nsCOMPtr.h" 1.24 +#include "nsColor.h" 1.25 +#include "gfxContext.h" 1.26 +#include "nsLayoutUtils.h" 1.27 +#include "nsContentUtils.h" 1.28 +#include "nsCSSValue.h" 1.29 +#include "nsRuleNode.h" 1.30 +#include "mozilla/gfx/Matrix.h" 1.31 + 1.32 +using namespace mozilla; 1.33 +using namespace mozilla::gfx; 1.34 +using namespace mozilla::ipc; 1.35 + 1.36 +DocumentRendererChild::DocumentRendererChild() 1.37 +{} 1.38 + 1.39 +DocumentRendererChild::~DocumentRendererChild() 1.40 +{} 1.41 + 1.42 +bool 1.43 +DocumentRendererChild::RenderDocument(nsIDOMWindow *window, 1.44 + const nsRect& documentRect, 1.45 + const mozilla::gfx::Matrix& transform, 1.46 + const nsString& aBGColor, 1.47 + uint32_t renderFlags, 1.48 + bool flushLayout, 1.49 + const nsIntSize& renderSize, 1.50 + nsCString& data) 1.51 +{ 1.52 + if (flushLayout) 1.53 + nsContentUtils::FlushLayoutForTree(window); 1.54 + 1.55 + nsRefPtr<nsPresContext> presContext; 1.56 + nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window); 1.57 + if (win) { 1.58 + nsIDocShell* docshell = win->GetDocShell(); 1.59 + if (docshell) { 1.60 + docshell->GetPresContext(getter_AddRefs(presContext)); 1.61 + } 1.62 + } 1.63 + if (!presContext) 1.64 + return false; 1.65 + 1.66 + nsCSSParser parser; 1.67 + nsCSSValue bgColorValue; 1.68 + if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue)) { 1.69 + return false; 1.70 + } 1.71 + 1.72 + nscolor bgColor; 1.73 + if (!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) { 1.74 + return false; 1.75 + } 1.76 + 1.77 + // Draw directly into the output array. 1.78 + data.SetLength(renderSize.width * renderSize.height * 4); 1.79 + 1.80 + RefPtr<DrawTarget> dt = 1.81 + Factory::CreateDrawTargetForData(BackendType::CAIRO, 1.82 + reinterpret_cast<uint8_t*>(data.BeginWriting()), 1.83 + IntSize(renderSize.width, renderSize.height), 1.84 + 4 * renderSize.width, 1.85 + SurfaceFormat::B8G8R8A8); 1.86 + nsRefPtr<gfxContext> ctx = new gfxContext(dt); 1.87 + ctx->SetMatrix(mozilla::gfx::ThebesMatrix(transform)); 1.88 + 1.89 + nsCOMPtr<nsIPresShell> shell = presContext->PresShell(); 1.90 + shell->RenderDocument(documentRect, renderFlags, bgColor, ctx); 1.91 + 1.92 + return true; 1.93 +}