Bug 1074012, part 3 - Make nsSVGUtils::MakeFillPatternFor/MakeStrokePatternFor return using a Moz2D GeneralPattern out-param rather than a Thebes gfxPattern. r=Bas

This commit is contained in:
Jonathan Watt 2014-09-29 14:26:15 +01:00
parent 8345574117
commit e514b2b327
5 changed files with 76 additions and 67 deletions

View File

@ -14,6 +14,7 @@
#include "gfxTypes.h"
#include "LookAndFeel.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PatternHelpers.h"
#include "nsAlgorithm.h"
#include "nsBlockFrame.h"
#include "nsCaret.h"
@ -2739,7 +2740,7 @@ private:
* Sets the gfxContext paint to the appropriate color or pattern
* for filling text geometry.
*/
already_AddRefed<gfxPattern> MakeFillPattern();
void MakeFillPattern(GeneralPattern* aOutPattern);
/**
* Fills and strokes a piece of text geometry, using group opacity
@ -2825,11 +2826,12 @@ SVGTextDrawPathCallbacks::NotifySelectionBackgroundPathEmitted()
return;
}
nsRefPtr<gfxPattern> fillPattern = MakeFillPattern();
if (fillPattern) {
gfx->SetPattern(fillPattern);
GeneralPattern fillPattern;
MakeFillPattern(&fillPattern);
if (fillPattern.GetPattern()) {
gfx->SetFillRule(nsSVGUtils::ToFillRule(mFrame->StyleSVG()->mFillRule));
gfx->FillWithOpacity(mColor == NS_40PERCENT_FOREGROUND_COLOR ? 0.4 : 1.0);
gfx->FillWithOpacity(fillPattern,
mColor == NS_40PERCENT_FOREGROUND_COLOR ? 0.4 : 1.0);
}
gfx->Restore();
}
@ -2906,20 +2908,20 @@ SVGTextDrawPathCallbacks::HandleTextGeometry()
}
}
already_AddRefed<gfxPattern>
SVGTextDrawPathCallbacks::MakeFillPattern()
void
SVGTextDrawPathCallbacks::MakeFillPattern(GeneralPattern* aOutPattern)
{
if (mColor == NS_SAME_AS_FOREGROUND_COLOR ||
mColor == NS_40PERCENT_FOREGROUND_COLOR) {
return nsSVGUtils::MakeFillPatternFor(mFrame, gfx);
nsSVGUtils::MakeFillPatternFor(mFrame, gfx, aOutPattern);
return;
}
if (mColor == NS_TRANSPARENT) {
return nullptr;
return;
}
nsRefPtr<gfxPattern> pattern = new gfxPattern(gfxRGBA(mColor));
return pattern.forget();
aOutPattern->InitColorPattern(ToColor(gfxRGBA(mColor)));
}
void
@ -2960,11 +2962,11 @@ SVGTextDrawPathCallbacks::FillAndStrokeGeometry()
void
SVGTextDrawPathCallbacks::FillGeometry()
{
nsRefPtr<gfxPattern> fillPattern = MakeFillPattern();
if (fillPattern) {
gfx->SetPattern(fillPattern);
GeneralPattern fillPattern;
MakeFillPattern(&fillPattern);
if (fillPattern.GetPattern()) {
gfx->SetFillRule(nsSVGUtils::ToFillRule(mFrame->StyleSVG()->mFillRule));
gfx->Fill();
gfx->Fill(fillPattern);
}
}
@ -2975,12 +2977,11 @@ SVGTextDrawPathCallbacks::StrokeGeometry()
if (mColor == NS_SAME_AS_FOREGROUND_COLOR ||
mColor == NS_40PERCENT_FOREGROUND_COLOR) {
if (nsSVGUtils::HasStroke(mFrame, /*aContextPaint*/ nullptr)) {
nsRefPtr<gfxPattern> strokePattern =
nsSVGUtils::MakeStrokePatternFor(mFrame, gfx, /*aContextPaint*/ nullptr);
if (strokePattern) {
GeneralPattern strokePattern;
nsSVGUtils::MakeStrokePatternFor(mFrame, gfx, &strokePattern, /*aContextPaint*/ nullptr);
if (strokePattern.GetPattern()) {
nsSVGUtils::SetupCairoStrokeGeometry(mFrame, gfx, /*aContextPaint*/ nullptr);
gfx->SetPattern(strokePattern);
gfx->Stroke();
gfx->Stroke(strokePattern);
}
}
}

View File

@ -14,6 +14,7 @@
#include "gfxPlatform.h"
#include "gfxUtils.h"
#include "mozilla/gfx/Helpers.h"
#include "mozilla/gfx/PatternHelpers.h"
#include "nsISVGChildFrame.h"
#include "nsRenderingContext.h"
#include "nsCSSFilterInstance.h"
@ -368,15 +369,15 @@ nsFilterInstance::BuildSourcePaint(SourceInfo *aSource,
gfx->Multiply(mPaintTransform *
deviceToFilterSpace *
gfxMatrix::Translation(-neededRect.TopLeft()));
nsRefPtr<gfxPattern> pattern;
GeneralPattern pattern;
if (aSource == &mFillPaint) {
pattern = nsSVGUtils::MakeFillPatternFor(mTargetFrame, gfx);
nsSVGUtils::MakeFillPatternFor(mTargetFrame, gfx, &pattern);
} else if (aSource == &mStrokePaint) {
pattern = nsSVGUtils::MakeStrokePatternFor(mTargetFrame, gfx);
nsSVGUtils::MakeStrokePatternFor(mTargetFrame, gfx, &pattern);
}
if (pattern) {
if (pattern.GetPattern()) {
offscreenDT->FillRect(ToRect(FilterSpaceToUserSpace(neededRect)),
*pattern->GetPattern(offscreenDT));
pattern);
}
gfx->Restore();
}

View File

@ -672,25 +672,23 @@ nsSVGPathGeometryFrame::Render(nsRenderingContext *aContext,
(gfxTextContextPaint*)aContext->GetDrawTarget()->GetUserData(&gfxTextContextPaint::sUserDataKey);
if ((aRenderComponents & eRenderFill)) {
nsRefPtr<gfxPattern> fillPattern =
nsSVGUtils::MakeFillPatternFor(this, gfx, contextPaint);
if (fillPattern) {
GeneralPattern fillPattern;
nsSVGUtils::MakeFillPatternFor(this, gfx, &fillPattern, contextPaint);
if (fillPattern.GetPattern()) {
gfx->SetPath(path);
gfx->SetPattern(fillPattern);
gfx->SetFillRule(fillRule);
gfx->Fill();
gfx->Fill(fillPattern);
}
}
if ((aRenderComponents & eRenderStroke) &&
nsSVGUtils::HasStroke(this, contextPaint)) {
nsRefPtr<gfxPattern> strokePattern =
nsSVGUtils::MakeStrokePatternFor(this, gfx, contextPaint);
if (strokePattern) {
GeneralPattern strokePattern;
nsSVGUtils::MakeStrokePatternFor(this, gfx, &strokePattern, contextPaint);
if (strokePattern.GetPattern()) {
gfx->SetPath(path);
nsSVGUtils::SetupCairoStrokeGeometry(this, gfx, contextPaint);
gfx->SetPattern(strokePattern);
gfx->Stroke();
gfx->Stroke(strokePattern);
}
}

View File

@ -16,6 +16,7 @@
#include "gfxRect.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PatternHelpers.h"
#include "mozilla/Preferences.h"
#include "nsCSSFrameConstructor.h"
#include "nsDisplayList.h"
@ -1243,14 +1244,15 @@ MaybeOptimizeOpacity(nsIFrame *aFrame, float aFillOrStrokeOpacity)
return aFillOrStrokeOpacity;
}
/* static */ already_AddRefed<gfxPattern>
nsSVGUtils::MakeFillPatternFor(nsIFrame *aFrame,
/* static */ void
nsSVGUtils::MakeFillPatternFor(nsIFrame* aFrame,
gfxContext* aContext,
gfxTextContextPaint *aContextPaint)
GeneralPattern* aOutPattern,
gfxTextContextPaint* aContextPaint)
{
const nsStyleSVG* style = aFrame->StyleSVG();
if (style->mFill.mType == eStyleSVGPaintType_None) {
return nullptr;
return;
}
float opacity = MaybeOptimizeOpacity(aFrame,
@ -1259,21 +1261,22 @@ nsSVGUtils::MakeFillPatternFor(nsIFrame *aFrame,
aContextPaint));
const DrawTarget* dt = aContext->GetDrawTarget();
nsRefPtr<gfxPattern> pattern;
nsSVGPaintServerFrame *ps =
nsSVGEffects::GetPaintServer(aFrame, &style->mFill,
nsSVGEffects::FillProperty());
if (ps) {
pattern = ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(),
&nsStyleSVG::mFill, opacity);
nsRefPtr<gfxPattern> pattern =
ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(),
&nsStyleSVG::mFill, opacity);
if (pattern) {
pattern->CacheColorStops(dt);
return pattern.forget();
aOutPattern->Init(*pattern->GetPattern(dt));
return;
}
}
if (aContextPaint) {
nsRefPtr<gfxPattern> pattern;
switch (style->mFill.mType) {
case eStyleSVGPaintType_ContextFill:
pattern = aContextPaint->GetFillPattern(dt, opacity,
@ -1287,7 +1290,8 @@ nsSVGUtils::MakeFillPatternFor(nsIFrame *aFrame,
;
}
if (pattern) {
return pattern.forget();
aOutPattern->Init(*pattern->GetPattern(dt));
return;
}
}
@ -1296,21 +1300,21 @@ nsSVGUtils::MakeFillPatternFor(nsIFrame *aFrame,
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
nscolor color = GetFallbackOrPaintColor(aFrame->StyleContext(),
&nsStyleSVG::mFill);
pattern = new gfxPattern(gfxRGBA(NS_GET_R(color)/255.0,
NS_GET_G(color)/255.0,
NS_GET_B(color)/255.0,
NS_GET_A(color)/255.0 * opacity));
return pattern.forget();
aOutPattern->InitColorPattern(Color(NS_GET_R(color)/255.0,
NS_GET_G(color)/255.0,
NS_GET_B(color)/255.0,
NS_GET_A(color)/255.0 * opacity));
}
/* static */ already_AddRefed<gfxPattern>
nsSVGUtils::MakeStrokePatternFor(nsIFrame *aFrame,
/* static */ void
nsSVGUtils::MakeStrokePatternFor(nsIFrame* aFrame,
gfxContext* aContext,
gfxTextContextPaint *aContextPaint)
GeneralPattern* aOutPattern,
gfxTextContextPaint* aContextPaint)
{
const nsStyleSVG* style = aFrame->StyleSVG();
if (style->mStroke.mType == eStyleSVGPaintType_None) {
return nullptr;
return;
}
float opacity = MaybeOptimizeOpacity(aFrame,
@ -1320,21 +1324,22 @@ nsSVGUtils::MakeStrokePatternFor(nsIFrame *aFrame,
const DrawTarget* dt = aContext->GetDrawTarget();
nsRefPtr<gfxPattern> pattern;
nsSVGPaintServerFrame *ps =
nsSVGEffects::GetPaintServer(aFrame, &style->mStroke,
nsSVGEffects::StrokeProperty());
if (ps) {
pattern = ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(),
&nsStyleSVG::mStroke, opacity);
nsRefPtr<gfxPattern> pattern =
ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(),
&nsStyleSVG::mStroke, opacity);
if (pattern) {
pattern->CacheColorStops(dt);
return pattern.forget();
aOutPattern->Init(*pattern->GetPattern(dt));
return;
}
}
if (aContextPaint) {
nsRefPtr<gfxPattern> pattern;
switch (style->mStroke.mType) {
case eStyleSVGPaintType_ContextFill:
pattern = aContextPaint->GetFillPattern(dt, opacity,
@ -1348,7 +1353,8 @@ nsSVGUtils::MakeStrokePatternFor(nsIFrame *aFrame,
;
}
if (pattern) {
return pattern.forget();
aOutPattern->Init(*pattern->GetPattern(dt));
return;
}
}
@ -1357,11 +1363,10 @@ nsSVGUtils::MakeStrokePatternFor(nsIFrame *aFrame,
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
nscolor color = GetFallbackOrPaintColor(aFrame->StyleContext(),
&nsStyleSVG::mStroke);
pattern = new gfxPattern(gfxRGBA(NS_GET_R(color)/255.0,
NS_GET_G(color)/255.0,
NS_GET_B(color)/255.0,
NS_GET_A(color)/255.0 * opacity));
return pattern.forget();
aOutPattern->InitColorPattern(Color(NS_GET_R(color)/255.0,
NS_GET_G(color)/255.0,
NS_GET_B(color)/255.0,
NS_GET_A(color)/255.0 * opacity));
}
/* static */ float

View File

@ -61,6 +61,7 @@ class Element;
class UserSpaceMetrics;
} // namespace dom
namespace gfx {
class GeneralPattern;
class SourceSurface;
}
} // namespace mozilla
@ -200,6 +201,7 @@ class nsSVGUtils
public:
typedef mozilla::dom::Element Element;
typedef mozilla::gfx::FillRule FillRule;
typedef mozilla::gfx::GeneralPattern GeneralPattern;
static void Init();
@ -501,14 +503,16 @@ public:
static nscolor GetFallbackOrPaintColor(nsStyleContext *aStyleContext,
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke);
static already_AddRefed<gfxPattern>
static void
MakeFillPatternFor(nsIFrame *aFrame,
gfxContext* aContext,
GeneralPattern* aOutPattern,
gfxTextContextPaint *aContextPaint = nullptr);
static already_AddRefed<gfxPattern>
static void
MakeStrokePatternFor(nsIFrame* aFrame,
gfxContext* aContext,
GeneralPattern* aOutPattern,
gfxTextContextPaint *aContextPaint = nullptr);
static float GetOpacity(nsStyleSVGOpacitySource aOpacityType,