Bug 1058040, part 5 - Move the code from nsSVGUtils::SetupContextPaint and nsSVGUtils::GetContextPaint into SVGContextPaint. r=dholbert

--HG--
extra : rebase_source : 00c5ef270ff9591a16727a2e35405177f063c8e6
This commit is contained in:
Jonathan Watt 2016-07-25 17:34:18 +01:00
Родитель 17c835c445
Коммит 9f767c7d64
6 изменённых файлов: 139 добавлений и 137 удалений

Просмотреть файл

@ -5,13 +5,122 @@
#include "SVGContextPaint.h"
#include "gfxContext.h"
#include "mozilla/gfx/2D.h"
#include "nsIDocument.h"
#include "nsSVGPaintServerFrame.h"
#include "nsSVGEffects.h"
#include "nsSVGPaintServerFrame.h"
using namespace mozilla::gfx;
namespace mozilla {
/**
* 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
*/
static void
SetupInheritablePaint(const DrawTarget* aDrawTarget,
const gfxMatrix& aContextMatrix,
nsIFrame* aFrame,
float& aOpacity,
SVGContextPaint* aOuterContextPaint,
SVGContextPaintImpl::Paint& aTargetPaint,
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
nsSVGEffects::PaintingPropertyDescriptor aProperty)
{
const nsStyleSVG *style = aFrame->StyleSVG();
nsSVGPaintServerFrame *ps =
nsSVGEffects::GetPaintServer(aFrame, aFillOrStroke, aProperty);
if (ps) {
RefPtr<gfxPattern> pattern =
ps->GetPaintServerPattern(aFrame, aDrawTarget, aContextMatrix,
aFillOrStroke, aOpacity);
if (pattern) {
aTargetPaint.SetPaintServer(aFrame, aContextMatrix, ps);
return;
}
}
if (aOuterContextPaint) {
RefPtr<gfxPattern> pattern;
switch ((style->*aFillOrStroke).mType) {
case eStyleSVGPaintType_ContextFill:
pattern = aOuterContextPaint->GetFillPattern(aDrawTarget, aOpacity,
aContextMatrix);
break;
case eStyleSVGPaintType_ContextStroke:
pattern = aOuterContextPaint->GetStrokePattern(aDrawTarget, aOpacity,
aContextMatrix);
break;
default:
;
}
if (pattern) {
aTargetPaint.SetContextPaint(aOuterContextPaint, (style->*aFillOrStroke).mType);
return;
}
}
nscolor color =
nsSVGUtils::GetFallbackOrPaintColor(aFrame->StyleContext(), aFillOrStroke);
aTargetPaint.SetColor(color);
}
DrawMode
SVGContextPaintImpl::Init(const DrawTarget* aDrawTarget,
const gfxMatrix& aContextMatrix,
nsIFrame* aFrame,
SVGContextPaint* aOuterContextPaint)
{
DrawMode toDraw = DrawMode(0);
const nsStyleSVG *style = aFrame->StyleSVG();
// fill:
if (style->mFill.mType == eStyleSVGPaintType_None) {
SetFillOpacity(0.0f);
} else {
float opacity = nsSVGUtils::GetOpacity(style->FillOpacitySource(),
style->mFillOpacity,
aOuterContextPaint);
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
opacity, aOuterContextPaint,
mFillPaint, &nsStyleSVG::mFill,
nsSVGEffects::FillProperty());
SetFillOpacity(opacity);
toDraw |= DrawMode::GLYPH_FILL;
}
// stroke:
if (style->mStroke.mType == eStyleSVGPaintType_None) {
SetStrokeOpacity(0.0f);
} else {
float opacity = nsSVGUtils::GetOpacity(style->StrokeOpacitySource(),
style->mStrokeOpacity,
aOuterContextPaint);
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
opacity, aOuterContextPaint,
mStrokePaint, &nsStyleSVG::mStroke,
nsSVGEffects::StrokeProperty());
SetStrokeOpacity(opacity);
toDraw |= DrawMode::GLYPH_STROKE;
}
return toDraw;
}
void
SVGContextPaint::InitStrokeGeometry(gfxContext* aContext,
float devUnitsPerSVGUnit)
@ -24,6 +133,19 @@ SVGContextPaint::InitStrokeGeometry(gfxContext* aContext,
mDashOffset /= devUnitsPerSVGUnit;
}
/* static */ SVGContextPaint*
SVGContextPaint::GetContextPaint(nsIContent* aContent)
{
nsIDocument* ownerDoc = aContent->OwnerDoc();
if (!ownerDoc->IsBeingUsedAsImage()) {
return nullptr;
}
return static_cast<SVGContextPaint*>(
ownerDoc->GetProperty(nsGkAtoms::svgContextPaint));
}
already_AddRefed<gfxPattern>
SVGContextPaintImpl::GetFillPattern(const DrawTarget* aDrawTarget,
float aOpacity,
@ -118,7 +240,7 @@ AutoSetRestoreSVGContextPaint::AutoSetRestoreSVGContextPaint(
MOZ_ASSERT(aContextPaint);
MOZ_ASSERT(aSVGDocument->IsBeingUsedAsImage(),
"nsSVGUtils::GetContextPaint assumes this");
"SVGContextPaint::GetContextPaint assumes this");
if (mOuterContextPaint) {
mSVGDocument->UnsetProperty(nsGkAtoms::svgContextPaint);

Просмотреть файл

@ -6,6 +6,7 @@
#ifndef MOZILLA_SVGCONTEXTPAINT_H_
#define MOZILLA_SVGCONTEXTPAINT_H_
#include "DrawMode.h"
#include "gfxMatrix.h"
#include "gfxPattern.h"
#include "gfxTypes.h"
@ -61,6 +62,8 @@ public:
return GetStrokePattern(aDrawTarget, GetStrokeOpacity(), aCTM);
}
static SVGContextPaint* GetContextPaint(nsIContent* aContent);
// XXX This gets the geometry params from the gfxContext. We should get that
// information from the actual paint context!
void InitStrokeGeometry(gfxContext *aContext,
@ -87,7 +90,7 @@ private:
/**
* RAII class used to temporarily set and remove an SVGContextPaint while a
* piece of SVG is being painted. The context paint is set on the SVG's owner
* document, as expected by nsSVGUtils::GetContextPaint. Any pre-existing
* document, as expected by SVGContextPaint::GetContextPaint. Any pre-existing
* context paint is restored after this class removes the context paint that it
* set.
*/
@ -114,6 +117,11 @@ struct SVGContextPaintImpl : public SVGContextPaint
protected:
typedef mozilla::gfx::DrawTarget DrawTarget;
public:
DrawMode Init(const DrawTarget* aDrawTarget,
const gfxMatrix& aContextMatrix,
nsIFrame* aFrame,
SVGContextPaint* aOuterContextPaint);
already_AddRefed<gfxPattern> GetFillPattern(const DrawTarget* aDrawTarget,
float aOpacity,
const gfxMatrix& aCTM) override;

Просмотреть файл

@ -3638,7 +3638,8 @@ SVGTextFrame::PaintSVG(gfxContext& aContext,
TextRenderedRunIterator it(this, TextRenderedRunIterator::eVisibleFrames);
TextRenderedRun run = it.Current();
SVGContextPaint* outerContextPaint = nsSVGUtils::GetContextPaint(mContent);
SVGContextPaint* outerContextPaint =
SVGContextPaint::GetContextPaint(mContent);
nsRenderingContext rendCtx(&aContext);
@ -3654,9 +3655,9 @@ SVGTextFrame::PaintSVG(gfxContext& aContext,
aContext.SetMatrix(initialMatrix);
SVGContextPaintImpl contextPaint;
DrawMode drawMode =
nsSVGUtils::SetupContextPaint(&aDrawTarget, aContext.CurrentMatrix(),
frame, outerContextPaint, &contextPaint);
DrawMode drawMode = contextPaint.Init(&aDrawTarget,
aContext.CurrentMatrix(),
frame, outerContextPaint);
if (drawMode & DrawMode::GLYPH_STROKE) {
// This may change the gfxContext's transform (for non-scaling stroke),

Просмотреть файл

@ -809,7 +809,7 @@ nsSVGPathGeometryFrame::Render(gfxContext* aContext,
}
}
SVGContextPaint* contextPaint = nsSVGUtils::GetContextPaint(mContent);
SVGContextPaint* contextPaint = SVGContextPaint::GetContextPaint(mContent);
if (aRenderComponents & eRenderFill) {
GeneralPattern fillPattern;
@ -877,7 +877,7 @@ void
nsSVGPathGeometryFrame::PaintMarkers(gfxContext& aContext,
const gfxMatrix& aTransform)
{
SVGContextPaint* contextPaint = nsSVGUtils::GetContextPaint(mContent);
SVGContextPaint* contextPaint = SVGContextPaint::GetContextPaint(mContent);
if (static_cast<nsSVGPathGeometryElement*>(mContent)->IsMarkable()) {
MarkerProperties properties = GetMarkerProperties(this);

Просмотреть файл

@ -1300,126 +1300,6 @@ nsSVGUtils::GetFallbackOrPaintColor(nsStyleContext *aStyleContext,
return color;
}
/* static */ SVGContextPaint*
nsSVGUtils::GetContextPaint(nsIContent* aContent)
{
nsIDocument* ownerDoc = aContent->OwnerDoc();
if (!ownerDoc->IsBeingUsedAsImage()) {
return nullptr;
}
return static_cast<SVGContextPaint*>(
ownerDoc->GetProperty(nsGkAtoms::svgContextPaint));
}
/**
* 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
*/
static void
SetupInheritablePaint(const DrawTarget* aDrawTarget,
const gfxMatrix& aContextMatrix,
nsIFrame* aFrame,
float& aOpacity,
SVGContextPaint* aOuterContextPaint,
SVGContextPaintImpl::Paint& aTargetPaint,
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
nsSVGEffects::PaintingPropertyDescriptor aProperty)
{
const nsStyleSVG *style = aFrame->StyleSVG();
nsSVGPaintServerFrame *ps =
nsSVGEffects::GetPaintServer(aFrame, aFillOrStroke, aProperty);
if (ps) {
RefPtr<gfxPattern> pattern =
ps->GetPaintServerPattern(aFrame, aDrawTarget, aContextMatrix,
aFillOrStroke, aOpacity);
if (pattern) {
aTargetPaint.SetPaintServer(aFrame, aContextMatrix, ps);
return;
}
}
if (aOuterContextPaint) {
RefPtr<gfxPattern> pattern;
switch ((style->*aFillOrStroke).mType) {
case eStyleSVGPaintType_ContextFill:
pattern = aOuterContextPaint->GetFillPattern(aDrawTarget, aOpacity,
aContextMatrix);
break;
case eStyleSVGPaintType_ContextStroke:
pattern = aOuterContextPaint->GetStrokePattern(aDrawTarget, aOpacity,
aContextMatrix);
break;
default:
;
}
if (pattern) {
aTargetPaint.SetContextPaint(aOuterContextPaint, (style->*aFillOrStroke).mType);
return;
}
}
nscolor color =
nsSVGUtils::GetFallbackOrPaintColor(aFrame->StyleContext(), aFillOrStroke);
aTargetPaint.SetColor(color);
}
/* static */ DrawMode
nsSVGUtils::SetupContextPaint(const DrawTarget* aDrawTarget,
const gfxMatrix& aContextMatrix,
nsIFrame* aFrame,
SVGContextPaint* aOuterContextPaint,
SVGContextPaintImpl* aThisContextPaint)
{
DrawMode toDraw = DrawMode(0);
const nsStyleSVG *style = aFrame->StyleSVG();
// fill:
if (style->mFill.mType == eStyleSVGPaintType_None) {
aThisContextPaint->SetFillOpacity(0.0f);
} else {
float opacity = nsSVGUtils::GetOpacity(style->FillOpacitySource(),
style->mFillOpacity,
aOuterContextPaint);
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
opacity, aOuterContextPaint,
aThisContextPaint->mFillPaint, &nsStyleSVG::mFill,
nsSVGEffects::FillProperty());
aThisContextPaint->SetFillOpacity(opacity);
toDraw |= DrawMode::GLYPH_FILL;
}
// stroke:
if (style->mStroke.mType == eStyleSVGPaintType_None) {
aThisContextPaint->SetStrokeOpacity(0.0f);
} else {
float opacity = nsSVGUtils::GetOpacity(style->StrokeOpacitySource(),
style->mStrokeOpacity,
aOuterContextPaint);
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
opacity, aOuterContextPaint,
aThisContextPaint->mStrokePaint, &nsStyleSVG::mStroke,
nsSVGEffects::StrokeProperty());
aThisContextPaint->SetStrokeOpacity(opacity);
toDraw |= DrawMode::GLYPH_STROKE;
}
return toDraw;
}
/* static */ void
nsSVGUtils::MakeFillPatternFor(nsIFrame* aFrame,
gfxContext* aContext,

Просмотреть файл

@ -498,15 +498,6 @@ public:
static nscolor GetFallbackOrPaintColor(nsStyleContext *aStyleContext,
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke);
static SVGContextPaint* GetContextPaint(nsIContent* aContent);
static DrawMode
SetupContextPaint(const DrawTarget* aDrawTarget,
const gfxMatrix& aContextMatrix,
nsIFrame* aFrame,
SVGContextPaint* aOuterContextPaint,
SVGContextPaintImpl* aThisContextPaint);
static void
MakeFillPatternFor(nsIFrame *aFrame,
gfxContext* aContext,