2016-07-22 14:07:39 +03: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/. */
|
|
|
|
|
|
|
|
#include "SVGContextPaint.h"
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2017-01-10 13:28:11 +03:00
|
|
|
#include "gfxUtils.h"
|
2016-07-25 19:34:18 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2017-04-25 14:47:19 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2016-07-22 14:07:39 +03:00
|
|
|
#include "nsIDocument.h"
|
2016-07-25 15:27:00 +03:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2016-07-25 19:34:18 +03:00
|
|
|
#include "nsSVGEffects.h"
|
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2016-07-25 15:27:00 +03:00
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
2017-03-21 05:12:23 +03:00
|
|
|
using namespace mozilla::image;
|
2016-07-22 14:07:39 +03:00
|
|
|
|
2016-07-22 16:56:09 +03:00
|
|
|
namespace mozilla {
|
2016-07-22 14:07:39 +03:00
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
using image::imgDrawingParams;
|
|
|
|
|
2017-04-25 14:47:19 +03:00
|
|
|
/* static */ bool
|
|
|
|
SVGContextPaint::IsAllowedForImageFromURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
static bool sEnabledForContent = false;
|
|
|
|
static bool sEnabledForContentCached = false;
|
|
|
|
|
|
|
|
if (!sEnabledForContentCached) {
|
|
|
|
Preferences::AddBoolVarCache(&sEnabledForContent,
|
|
|
|
"svg.context-properties.content.enabled", false);
|
|
|
|
sEnabledForContentCached = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sEnabledForContent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Context paint is pref'ed off for Web content. Ideally we'd have some
|
|
|
|
// easy means to determine whether the frame that has linked to the image
|
|
|
|
// is a frame for a content node that originated from Web content.
|
|
|
|
// Unfortunately different types of anonymous content, about: documents
|
|
|
|
// such as about:reader, etc. that are "our" code that we ship are
|
|
|
|
// sometimes hard to distinguish from real Web content. As a result,
|
|
|
|
// instead of trying to figure out what content is "ours" we instead let
|
|
|
|
// any content provide image context paint, but only if the image is
|
|
|
|
// chrome:// or resource:// do we return true. This should be sufficient
|
|
|
|
// to stop the image context paint feature being useful to (and therefore
|
|
|
|
// used by and relied upon by) Web content. (We don't want Web content to
|
|
|
|
// use this feature because we're not sure that image context paint is a
|
|
|
|
// good mechanism for wider use, or suitable for specification.)
|
|
|
|
//
|
|
|
|
// One case where we may return false here and prevent image context paint
|
|
|
|
// being used by "our" content is in-tree WebExtensions. These have scheme
|
|
|
|
// 'moz-extension://', but so do other developers' extensions, and we don't
|
|
|
|
// want extension developers coming to rely on image context paint either.
|
|
|
|
// We may be able to provide our in-tree extensions access to context paint
|
|
|
|
// once they are signed. For more information see:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1359762#c5
|
|
|
|
//
|
|
|
|
nsAutoCString scheme;
|
|
|
|
if (NS_SUCCEEDED(aURI->GetScheme(scheme)) &&
|
|
|
|
(scheme.EqualsLiteral("chrome") || scheme.EqualsLiteral("resource"))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-25 19:34:18 +03:00
|
|
|
/**
|
|
|
|
* Stores in |aTargetPaint| information on how to reconstruct the current
|
|
|
|
* fill or stroke pattern. Will also set the paint opacity to transparent if
|
|
|
|
* the paint is set to "none".
|
|
|
|
* @param aOuterContextPaint pattern information from the outer text context
|
|
|
|
* @param aTargetPaint where to store the current pattern information
|
|
|
|
* @param aFillOrStroke member pointer to the paint we are setting up
|
|
|
|
* @param aProperty the frame property descriptor of the fill or stroke paint
|
|
|
|
* server frame
|
|
|
|
*/
|
2017-05-18 23:03:50 +03:00
|
|
|
static void
|
2016-07-25 19:34:18 +03:00
|
|
|
SetupInheritablePaint(const DrawTarget* aDrawTarget,
|
|
|
|
const gfxMatrix& aContextMatrix,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
float& aOpacity,
|
|
|
|
SVGContextPaint* aOuterContextPaint,
|
|
|
|
SVGContextPaintImpl::Paint& aTargetPaint,
|
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
2017-05-18 23:03:50 +03:00
|
|
|
nsSVGEffects::PaintingPropertyDescriptor aProperty,
|
|
|
|
imgDrawingParams& aImgParams)
|
2016-07-25 19:34:18 +03:00
|
|
|
{
|
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
|
|
|
nsSVGPaintServerFrame *ps =
|
|
|
|
nsSVGEffects::GetPaintServer(aFrame, aFillOrStroke, aProperty);
|
|
|
|
|
|
|
|
if (ps) {
|
2017-05-18 23:03:50 +03:00
|
|
|
RefPtr<gfxPattern> pattern =
|
2016-07-25 19:34:18 +03:00
|
|
|
ps->GetPaintServerPattern(aFrame, aDrawTarget, aContextMatrix,
|
2017-05-18 23:03:50 +03:00
|
|
|
aFillOrStroke, aOpacity, aImgParams);
|
2017-03-21 05:12:23 +03:00
|
|
|
|
2016-07-25 19:34:18 +03:00
|
|
|
if (pattern) {
|
|
|
|
aTargetPaint.SetPaintServer(aFrame, aContextMatrix, ps);
|
2017-05-18 23:03:50 +03:00
|
|
|
return;
|
2016-07-25 19:34:18 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-21 05:12:23 +03:00
|
|
|
|
2016-07-25 19:34:18 +03:00
|
|
|
if (aOuterContextPaint) {
|
|
|
|
RefPtr<gfxPattern> pattern;
|
2016-10-11 09:56:11 +03:00
|
|
|
switch ((style->*aFillOrStroke).Type()) {
|
2016-07-25 19:34:18 +03:00
|
|
|
case eStyleSVGPaintType_ContextFill:
|
2017-05-18 23:03:50 +03:00
|
|
|
pattern =
|
2017-03-21 05:12:23 +03:00
|
|
|
aOuterContextPaint->GetFillPattern(aDrawTarget, aOpacity,
|
2017-05-18 23:03:50 +03:00
|
|
|
aContextMatrix, aImgParams);
|
2016-07-25 19:34:18 +03:00
|
|
|
break;
|
|
|
|
case eStyleSVGPaintType_ContextStroke:
|
2017-05-18 23:03:50 +03:00
|
|
|
pattern =
|
2017-03-21 05:12:23 +03:00
|
|
|
aOuterContextPaint->GetStrokePattern(aDrawTarget, aOpacity,
|
2017-05-18 23:03:50 +03:00
|
|
|
aContextMatrix, aImgParams);
|
2016-07-25 19:34:18 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
if (pattern) {
|
2016-10-11 09:56:11 +03:00
|
|
|
aTargetPaint.SetContextPaint(aOuterContextPaint, (style->*aFillOrStroke).Type());
|
2017-05-18 23:03:50 +03:00
|
|
|
return;
|
2016-07-25 19:34:18 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-21 05:12:23 +03:00
|
|
|
|
2016-07-25 19:34:18 +03:00
|
|
|
nscolor color =
|
|
|
|
nsSVGUtils::GetFallbackOrPaintColor(aFrame->StyleContext(), aFillOrStroke);
|
|
|
|
aTargetPaint.SetColor(color);
|
|
|
|
}
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
DrawMode
|
2016-07-25 19:34:18 +03:00
|
|
|
SVGContextPaintImpl::Init(const DrawTarget* aDrawTarget,
|
|
|
|
const gfxMatrix& aContextMatrix,
|
|
|
|
nsIFrame* aFrame,
|
2017-05-18 23:03:50 +03:00
|
|
|
SVGContextPaint* aOuterContextPaint,
|
|
|
|
imgDrawingParams& aImgParams)
|
2016-07-25 19:34:18 +03:00
|
|
|
{
|
|
|
|
DrawMode toDraw = DrawMode(0);
|
|
|
|
|
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
|
|
|
|
|
|
|
// fill:
|
2016-10-11 09:56:11 +03:00
|
|
|
if (style->mFill.Type() == eStyleSVGPaintType_None) {
|
2016-07-25 19:34:18 +03:00
|
|
|
SetFillOpacity(0.0f);
|
|
|
|
} else {
|
|
|
|
float opacity = nsSVGUtils::GetOpacity(style->FillOpacitySource(),
|
|
|
|
style->mFillOpacity,
|
|
|
|
aOuterContextPaint);
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame, opacity,
|
|
|
|
aOuterContextPaint, mFillPaint, &nsStyleSVG::mFill,
|
|
|
|
nsSVGEffects::FillProperty(), aImgParams);
|
2016-07-25 19:34:18 +03:00
|
|
|
|
|
|
|
SetFillOpacity(opacity);
|
|
|
|
|
|
|
|
toDraw |= DrawMode::GLYPH_FILL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// stroke:
|
2016-10-11 09:56:11 +03:00
|
|
|
if (style->mStroke.Type() == eStyleSVGPaintType_None) {
|
2016-07-25 19:34:18 +03:00
|
|
|
SetStrokeOpacity(0.0f);
|
|
|
|
} else {
|
|
|
|
float opacity = nsSVGUtils::GetOpacity(style->StrokeOpacitySource(),
|
|
|
|
style->mStrokeOpacity,
|
|
|
|
aOuterContextPaint);
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame, opacity,
|
|
|
|
aOuterContextPaint, mStrokePaint,
|
|
|
|
&nsStyleSVG::mStroke, nsSVGEffects::StrokeProperty(),
|
|
|
|
aImgParams);
|
2016-07-25 19:34:18 +03:00
|
|
|
|
|
|
|
SetStrokeOpacity(opacity);
|
|
|
|
|
|
|
|
toDraw |= DrawMode::GLYPH_STROKE;
|
|
|
|
}
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
return toDraw;
|
2016-07-25 19:34:18 +03:00
|
|
|
}
|
|
|
|
|
2016-07-22 14:07:39 +03:00
|
|
|
void
|
2016-07-22 16:56:09 +03:00
|
|
|
SVGContextPaint::InitStrokeGeometry(gfxContext* aContext,
|
|
|
|
float devUnitsPerSVGUnit)
|
2016-07-22 14:07:39 +03:00
|
|
|
{
|
|
|
|
mStrokeWidth = aContext->CurrentLineWidth() / devUnitsPerSVGUnit;
|
|
|
|
aContext->CurrentDash(mDashes, &mDashOffset);
|
|
|
|
for (uint32_t i = 0; i < mDashes.Length(); i++) {
|
|
|
|
mDashes[i] /= devUnitsPerSVGUnit;
|
|
|
|
}
|
|
|
|
mDashOffset /= devUnitsPerSVGUnit;
|
|
|
|
}
|
|
|
|
|
2016-07-25 19:34:18 +03:00
|
|
|
/* static */ SVGContextPaint*
|
|
|
|
SVGContextPaint::GetContextPaint(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
nsIDocument* ownerDoc = aContent->OwnerDoc();
|
|
|
|
|
|
|
|
if (!ownerDoc->IsBeingUsedAsImage()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-09 22:12:03 +03:00
|
|
|
// XXX The SVGContextPaint that was passed to SetProperty was const. Ideally
|
|
|
|
// we could and should re-apply that constness to the SVGContextPaint that
|
|
|
|
// we get here (SVGImageContext is never changed after it is initialized).
|
|
|
|
// Unfortunately lazy initialization of SVGContextPaint (which is a member of
|
|
|
|
// SVGImageContext, and also conceptually never changes after construction)
|
|
|
|
// prevents some of SVGContextPaint's conceptually const methods from being
|
|
|
|
// const. Trying to fix SVGContextPaint (perhaps by using |mutable|) is a
|
|
|
|
// bit of a headache so for now we punt on that, don't reapply the constness
|
|
|
|
// to the SVGContextPaint here, and trust that no one will add code that
|
|
|
|
// actually modifies the object.
|
|
|
|
|
2016-07-25 19:34:18 +03:00
|
|
|
return static_cast<SVGContextPaint*>(
|
|
|
|
ownerDoc->GetProperty(nsGkAtoms::svgContextPaint));
|
|
|
|
}
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
already_AddRefed<gfxPattern>
|
2016-07-25 18:04:20 +03:00
|
|
|
SVGContextPaintImpl::GetFillPattern(const DrawTarget* aDrawTarget,
|
2016-07-25 15:27:00 +03:00
|
|
|
float aOpacity,
|
2017-03-24 22:19:18 +03:00
|
|
|
const gfxMatrix& aCTM,
|
2017-05-18 23:03:50 +03:00
|
|
|
imgDrawingParams& aImgParams)
|
2016-07-25 15:27:00 +03:00
|
|
|
{
|
2017-03-24 22:19:18 +03:00
|
|
|
return mFillPaint.GetPattern(aDrawTarget, aOpacity, &nsStyleSVG::mFill, aCTM,
|
2017-05-18 23:03:50 +03:00
|
|
|
aImgParams);
|
2016-07-25 15:27:00 +03:00
|
|
|
}
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
already_AddRefed<gfxPattern>
|
2016-07-25 18:04:20 +03:00
|
|
|
SVGContextPaintImpl::GetStrokePattern(const DrawTarget* aDrawTarget,
|
2016-07-25 15:27:00 +03:00
|
|
|
float aOpacity,
|
2017-03-24 22:19:18 +03:00
|
|
|
const gfxMatrix& aCTM,
|
2017-05-18 23:03:50 +03:00
|
|
|
imgDrawingParams& aImgParams)
|
2016-07-25 15:27:00 +03:00
|
|
|
{
|
2017-03-24 22:19:18 +03:00
|
|
|
return mStrokePaint.GetPattern(aDrawTarget, aOpacity, &nsStyleSVG::mStroke,
|
2017-05-18 23:03:50 +03:00
|
|
|
aCTM, aImgParams);
|
2016-07-25 15:27:00 +03:00
|
|
|
}
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
already_AddRefed<gfxPattern>
|
2016-07-25 18:04:20 +03:00
|
|
|
SVGContextPaintImpl::Paint::GetPattern(const DrawTarget* aDrawTarget,
|
2016-07-25 15:27:00 +03:00
|
|
|
float aOpacity,
|
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
2017-03-24 22:19:18 +03:00
|
|
|
const gfxMatrix& aCTM,
|
2017-05-18 23:03:50 +03:00
|
|
|
imgDrawingParams& aImgParams)
|
2016-07-25 15:27:00 +03:00
|
|
|
{
|
|
|
|
RefPtr<gfxPattern> pattern;
|
|
|
|
if (mPatternCache.Get(aOpacity, getter_AddRefs(pattern))) {
|
|
|
|
// Set the pattern matrix just in case it was messed with by a previous
|
|
|
|
// caller. We should get the same matrix each time a pattern is constructed
|
|
|
|
// so this should be fine.
|
|
|
|
pattern->SetMatrix(aCTM * mPatternMatrix);
|
2017-05-18 23:03:50 +03:00
|
|
|
return pattern.forget();
|
2016-07-25 15:27:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (mPaintType) {
|
|
|
|
case eStyleSVGPaintType_None:
|
|
|
|
pattern = new gfxPattern(Color());
|
|
|
|
mPatternMatrix = gfxMatrix();
|
|
|
|
break;
|
|
|
|
case eStyleSVGPaintType_Color: {
|
|
|
|
Color color = Color::FromABGR(mPaintDefinition.mColor);
|
|
|
|
color.a *= aOpacity;
|
|
|
|
pattern = new gfxPattern(color);
|
|
|
|
mPatternMatrix = gfxMatrix();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eStyleSVGPaintType_Server:
|
2017-05-18 23:03:50 +03:00
|
|
|
pattern =
|
2017-03-21 05:12:23 +03:00
|
|
|
mPaintDefinition.mPaintServerFrame->GetPaintServerPattern(mFrame,
|
|
|
|
aDrawTarget,
|
|
|
|
mContextMatrix,
|
|
|
|
aFillOrStroke,
|
2017-03-24 22:19:18 +03:00
|
|
|
aOpacity,
|
2017-05-18 23:03:50 +03:00
|
|
|
aImgParams);
|
2016-07-25 15:27:00 +03:00
|
|
|
{
|
|
|
|
// m maps original-user-space to pattern space
|
|
|
|
gfxMatrix m = pattern->GetMatrix();
|
|
|
|
gfxMatrix deviceToOriginalUserSpace = mContextMatrix;
|
|
|
|
if (!deviceToOriginalUserSpace.Invert()) {
|
2017-05-18 23:03:50 +03:00
|
|
|
return nullptr;
|
2016-07-25 15:27:00 +03:00
|
|
|
}
|
|
|
|
// mPatternMatrix maps device space to pattern space via original user space
|
|
|
|
mPatternMatrix = deviceToOriginalUserSpace * m;
|
|
|
|
}
|
|
|
|
pattern->SetMatrix(aCTM * mPatternMatrix);
|
|
|
|
break;
|
|
|
|
case eStyleSVGPaintType_ContextFill:
|
2017-05-18 23:03:50 +03:00
|
|
|
pattern =
|
2017-03-21 05:12:23 +03:00
|
|
|
mPaintDefinition.mContextPaint->GetFillPattern(aDrawTarget,
|
2017-05-18 23:03:50 +03:00
|
|
|
aOpacity, aCTM,
|
|
|
|
aImgParams);
|
2016-07-25 15:27:00 +03:00
|
|
|
// Don't cache this. mContextPaint will have cached it anyway. If we
|
|
|
|
// cache it, we'll have to compute mPatternMatrix, which is annoying.
|
2017-05-18 23:03:50 +03:00
|
|
|
return pattern.forget();
|
2016-07-25 15:27:00 +03:00
|
|
|
case eStyleSVGPaintType_ContextStroke:
|
2017-05-18 23:03:50 +03:00
|
|
|
pattern =
|
2017-03-21 05:12:23 +03:00
|
|
|
mPaintDefinition.mContextPaint->GetStrokePattern(aDrawTarget,
|
2017-05-18 23:03:50 +03:00
|
|
|
aOpacity, aCTM,
|
|
|
|
aImgParams);
|
2016-07-25 15:27:00 +03:00
|
|
|
// Don't cache this. mContextPaint will have cached it anyway. If we
|
|
|
|
// cache it, we'll have to compute mPatternMatrix, which is annoying.
|
2017-05-18 23:03:50 +03:00
|
|
|
return pattern.forget();
|
2016-07-25 15:27:00 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "invalid paint type");
|
2017-05-18 23:03:50 +03:00
|
|
|
return nullptr;
|
2016-07-25 15:27:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mPatternCache.Put(aOpacity, pattern);
|
2017-05-18 23:03:50 +03:00
|
|
|
return pattern.forget();
|
2016-07-25 15:27:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-22 14:07:39 +03:00
|
|
|
AutoSetRestoreSVGContextPaint::AutoSetRestoreSVGContextPaint(
|
2017-01-09 22:12:03 +03:00
|
|
|
const SVGContextPaint* aContextPaint,
|
2016-07-22 14:07:39 +03:00
|
|
|
nsIDocument* aSVGDocument)
|
|
|
|
: mSVGDocument(aSVGDocument)
|
|
|
|
, mOuterContextPaint(aSVGDocument->GetProperty(nsGkAtoms::svgContextPaint))
|
|
|
|
{
|
|
|
|
// The way that we supply context paint is to temporarily set the context
|
|
|
|
// paint on the owner document of the SVG that we're painting while it's
|
|
|
|
// being painted.
|
|
|
|
|
|
|
|
MOZ_ASSERT(aContextPaint);
|
|
|
|
MOZ_ASSERT(aSVGDocument->IsBeingUsedAsImage(),
|
2016-07-25 19:34:18 +03:00
|
|
|
"SVGContextPaint::GetContextPaint assumes this");
|
2016-07-22 14:07:39 +03:00
|
|
|
|
|
|
|
if (mOuterContextPaint) {
|
|
|
|
mSVGDocument->UnsetProperty(nsGkAtoms::svgContextPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
DebugOnly<nsresult> res =
|
2017-01-09 22:12:03 +03:00
|
|
|
mSVGDocument->SetProperty(nsGkAtoms::svgContextPaint,
|
|
|
|
const_cast<SVGContextPaint*>(aContextPaint));
|
2016-07-22 14:07:39 +03:00
|
|
|
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(res), "Failed to set context paint");
|
2016-07-22 14:07:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoSetRestoreSVGContextPaint::~AutoSetRestoreSVGContextPaint()
|
|
|
|
{
|
|
|
|
mSVGDocument->UnsetProperty(nsGkAtoms::svgContextPaint);
|
|
|
|
if (mOuterContextPaint) {
|
|
|
|
DebugOnly<nsresult> res =
|
|
|
|
mSVGDocument->SetProperty(nsGkAtoms::svgContextPaint, mOuterContextPaint);
|
|
|
|
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(res), "Failed to restore context paint");
|
2016-07-22 14:07:39 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-22 16:56:09 +03:00
|
|
|
|
2017-01-10 13:28:11 +03:00
|
|
|
|
|
|
|
// SVGEmbeddingContextPaint
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
already_AddRefed<gfxPattern>
|
2017-02-24 17:55:28 +03:00
|
|
|
SVGEmbeddingContextPaint::GetFillPattern(const DrawTarget* aDrawTarget,
|
|
|
|
float aFillOpacity,
|
2017-03-24 22:19:18 +03:00
|
|
|
const gfxMatrix& aCTM,
|
2017-05-18 23:03:50 +03:00
|
|
|
imgDrawingParams& aImgParams)
|
2017-01-10 13:28:11 +03:00
|
|
|
{
|
2017-02-24 17:55:28 +03:00
|
|
|
if (!mFill) {
|
2017-05-18 23:03:50 +03:00
|
|
|
return nullptr;
|
2017-02-24 17:55:28 +03:00
|
|
|
}
|
|
|
|
// The gfxPattern that we create below depends on aFillOpacity, and since
|
|
|
|
// different elements in the SVG image may pass in different values for
|
|
|
|
// fill opacities we don't try to cache the gfxPattern that we create.
|
|
|
|
Color fill = *mFill;
|
|
|
|
fill.a *= aFillOpacity;
|
2017-05-18 23:03:50 +03:00
|
|
|
return do_AddRef(new gfxPattern(fill));
|
2017-01-10 13:28:11 +03:00
|
|
|
}
|
|
|
|
|
2017-05-18 23:03:50 +03:00
|
|
|
already_AddRefed<gfxPattern>
|
2017-02-24 17:55:28 +03:00
|
|
|
SVGEmbeddingContextPaint::GetStrokePattern(const DrawTarget* aDrawTarget,
|
|
|
|
float aStrokeOpacity,
|
2017-03-24 22:19:18 +03:00
|
|
|
const gfxMatrix& aCTM,
|
2017-05-18 23:03:50 +03:00
|
|
|
imgDrawingParams& aImgParams)
|
2017-01-10 13:28:11 +03:00
|
|
|
{
|
2017-02-24 17:55:28 +03:00
|
|
|
if (!mStroke) {
|
2017-05-18 23:03:50 +03:00
|
|
|
return nullptr;
|
2017-02-24 17:55:28 +03:00
|
|
|
}
|
|
|
|
Color stroke = *mStroke;
|
|
|
|
stroke.a *= aStrokeOpacity;
|
2017-05-18 23:03:50 +03:00
|
|
|
return do_AddRef(new gfxPattern(stroke));
|
2017-01-10 13:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SVGEmbeddingContextPaint::Hash() const
|
|
|
|
{
|
|
|
|
uint32_t hash = 0;
|
|
|
|
|
2017-02-24 17:55:28 +03:00
|
|
|
if (mFill) {
|
|
|
|
hash = HashGeneric(hash, mFill->ToABGR());
|
|
|
|
} else {
|
|
|
|
// Arbitrary number, just to avoid trivial hash collisions between pairs of
|
|
|
|
// instances where one embedding context has fill set to the same value as
|
|
|
|
// another context has stroke set to.
|
|
|
|
hash = 1;
|
2017-01-10 13:28:11 +03:00
|
|
|
}
|
2017-02-24 17:55:28 +03:00
|
|
|
|
|
|
|
if (mStroke) {
|
|
|
|
hash = HashGeneric(hash, mStroke->ToABGR());
|
2017-01-10 13:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2016-07-22 16:56:09 +03:00
|
|
|
} // namespace mozilla
|