2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-29 20:58:31 +03:00
|
|
|
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "mozilla/ipc/DocumentRendererChild.h"
|
|
|
|
|
2009-11-05 08:11:33 +03:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2013-12-26 22:06:53 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2017-06-09 22:14:53 +03:00
|
|
|
#include "gfxContext.h"
|
2009-10-29 20:58:31 +03:00
|
|
|
#include "gfxPattern.h"
|
2014-03-31 15:52:33 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2009-10-29 20:58:31 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2012-06-06 11:42:47 +04:00
|
|
|
#include "nsIDocShell.h"
|
2009-10-29 20:58:31 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2010-03-08 23:16:41 +03:00
|
|
|
#include "nsCSSParser.h"
|
2009-10-29 20:58:31 +03:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-01 01:26:04 +04:00
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsRuleNode.h"
|
2013-12-26 22:06:53 +04:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2017-10-16 04:06:39 +03:00
|
|
|
#include "mozilla/ServoCSSParser.h"
|
2009-11-05 08:11:33 +03:00
|
|
|
|
2013-12-26 22:06:53 +04:00
|
|
|
using namespace mozilla;
|
2014-03-31 15:52:33 +04:00
|
|
|
using namespace mozilla::gfx;
|
2009-10-29 20:58:31 +03:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
DocumentRendererChild::DocumentRendererChild()
|
|
|
|
{}
|
|
|
|
|
|
|
|
DocumentRendererChild::~DocumentRendererChild()
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool
|
2016-01-30 20:05:36 +03:00
|
|
|
DocumentRendererChild::RenderDocument(nsPIDOMWindowOuter* window,
|
2010-10-27 02:20:53 +04:00
|
|
|
const nsRect& documentRect,
|
2013-12-26 22:06:53 +04:00
|
|
|
const mozilla::gfx::Matrix& transform,
|
2012-06-06 11:36:38 +04:00
|
|
|
const nsString& aBGColor,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t renderFlags,
|
2013-12-26 22:06:53 +04:00
|
|
|
bool flushLayout,
|
2010-10-27 02:20:53 +04:00
|
|
|
const nsIntSize& renderSize,
|
|
|
|
nsCString& data)
|
2009-10-29 20:58:31 +03:00
|
|
|
{
|
2010-10-27 02:20:53 +04:00
|
|
|
if (flushLayout)
|
2010-11-03 15:57:15 +03:00
|
|
|
nsContentUtils::FlushLayoutForTree(window);
|
2009-10-29 20:58:31 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> presContext;
|
2016-01-30 20:05:36 +03:00
|
|
|
if (window) {
|
|
|
|
nsIDocShell* docshell = window->GetDocShell();
|
2009-10-29 20:58:31 +03:00
|
|
|
if (docshell) {
|
|
|
|
docshell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!presContext)
|
|
|
|
return false;
|
|
|
|
|
2017-10-16 17:15:34 +03:00
|
|
|
nscolor bgColor;
|
2017-10-16 04:06:39 +03:00
|
|
|
|
|
|
|
ServoStyleSet* servoStyleSet = presContext->StyleSet()
|
|
|
|
? presContext->StyleSet()->GetAsServo()
|
|
|
|
: nullptr;
|
|
|
|
|
|
|
|
if (servoStyleSet) {
|
|
|
|
if (!ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0),
|
|
|
|
aBGColor, &bgColor)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsCSSParser parser;
|
|
|
|
nsCSSValue bgColorValue;
|
|
|
|
if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue) ||
|
|
|
|
!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) {
|
2012-06-06 11:36:38 +04:00
|
|
|
return false;
|
2017-10-16 04:06:39 +03:00
|
|
|
}
|
2012-06-06 11:36:38 +04:00
|
|
|
}
|
2009-10-29 20:58:31 +03:00
|
|
|
|
|
|
|
// Draw directly into the output array.
|
2010-10-27 02:20:53 +04:00
|
|
|
data.SetLength(renderSize.width * renderSize.height * 4);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> dt =
|
2017-02-26 22:38:24 +03:00
|
|
|
Factory::CreateDrawTargetForData(gfxPlatform::GetPlatform()->GetSoftwareBackend(),
|
2014-03-31 15:52:33 +04:00
|
|
|
reinterpret_cast<uint8_t*>(data.BeginWriting()),
|
|
|
|
IntSize(renderSize.width, renderSize.height),
|
|
|
|
4 * renderSize.width,
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!dt || !dt->IsValid()) {
|
2015-03-09 22:48:20 +03:00
|
|
|
gfxWarning() << "DocumentRendererChild::RenderDocument failed to Factory::CreateDrawTargetForData";
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-07 02:39:56 +03:00
|
|
|
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(dt);
|
2016-04-12 22:18:11 +03:00
|
|
|
MOZ_ASSERT(ctx); // already checked the draw target above
|
2013-12-26 22:06:53 +04:00
|
|
|
ctx->SetMatrix(mozilla::gfx::ThebesMatrix(transform));
|
2009-10-29 20:58:31 +03:00
|
|
|
|
2012-10-27 05:02:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
|
|
|
|
shell->RenderDocument(documentRect, renderFlags, bgColor, ctx);
|
2009-10-29 20:58:31 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|