From a6a8b844babd0c332c3bed0dfa15f8f8bdd12368 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Mon, 29 Sep 2014 14:15:19 +0100 Subject: [PATCH] Bug 1073964 - Pass a const DrawTarget* through to nsSVGPaintServerFrame::GetPaintServerPattern so that it can create a pattern of the appropriate type. r=Bas --- gfx/thebes/gfxFont.cpp | 2 ++ gfx/thebes/gfxGradientCache.cpp | 4 +-- gfx/thebes/gfxGradientCache.h | 4 +-- gfx/thebes/gfxPattern.cpp | 2 +- gfx/thebes/gfxPattern.h | 2 +- gfx/thebes/gfxSVGGlyphs.h | 25 +++++++++++----- layout/base/nsCSSRendering.cpp | 1 + layout/svg/SVGTextFrame.cpp | 45 ++++++++++++++++++---------- layout/svg/SVGTextFrame.h | 16 +++++++--- layout/svg/nsSVGGradientFrame.cpp | 5 ++-- layout/svg/nsSVGGradientFrame.h | 5 ++-- layout/svg/nsSVGIntegrationUtils.cpp | 6 ++-- layout/svg/nsSVGIntegrationUtils.h | 6 ++++ layout/svg/nsSVGPaintServerFrame.h | 9 ++++++ layout/svg/nsSVGPatternFrame.cpp | 11 +++---- layout/svg/nsSVGPatternFrame.h | 4 ++- layout/svg/nsSVGUtils.cpp | 25 +++++++++++----- 17 files changed, 118 insertions(+), 54 deletions(-) diff --git a/gfx/thebes/gfxFont.cpp b/gfx/thebes/gfxFont.cpp index f502e8f74d8b..b83be18fc6b1 100644 --- a/gfx/thebes/gfxFont.cpp +++ b/gfx/thebes/gfxFont.cpp @@ -1548,6 +1548,7 @@ private: nsRefPtr fillPattern; if (!mFontParams.contextPaint || !(fillPattern = mFontParams.contextPaint->GetFillPattern( + mRunParams.context->GetDrawTarget(), mRunParams.context->CurrentMatrix()))) { if (state.pattern) { pat = state.pattern->GetPattern(mRunParams.dt, @@ -1630,6 +1631,7 @@ private: if (mFontParams.contextPaint) { nsRefPtr strokePattern = mFontParams.contextPaint->GetStrokePattern( + mRunParams.context->GetDrawTarget(), mRunParams.context->CurrentMatrix()); if (strokePattern) { mRunParams.dt->Stroke(path, diff --git a/gfx/thebes/gfxGradientCache.cpp b/gfx/thebes/gfxGradientCache.cpp index 5bfbb71c2c9e..bb15913d696e 100644 --- a/gfx/thebes/gfxGradientCache.cpp +++ b/gfx/thebes/gfxGradientCache.cpp @@ -178,7 +178,7 @@ class GradientCache MOZ_FINAL : public nsExpirationTracker static GradientCache* gGradientCache = nullptr; GradientStops * -gfxGradientCache::GetGradientStops(DrawTarget *aDT, nsTArray& aStops, ExtendMode aExtend) +gfxGradientCache::GetGradientStops(const DrawTarget *aDT, nsTArray& aStops, ExtendMode aExtend) { if (!gGradientCache) { gGradientCache = new GradientCache(); @@ -189,7 +189,7 @@ gfxGradientCache::GetGradientStops(DrawTarget *aDT, nsTArray& aSto } GradientStops * -gfxGradientCache::GetOrCreateGradientStops(DrawTarget *aDT, nsTArray& aStops, ExtendMode aExtend) +gfxGradientCache::GetOrCreateGradientStops(const DrawTarget *aDT, nsTArray& aStops, ExtendMode aExtend) { RefPtr gs = GetGradientStops(aDT, aStops, aExtend); if (!gs) { diff --git a/gfx/thebes/gfxGradientCache.h b/gfx/thebes/gfxGradientCache.h index b783d15ff83d..b4c3478ac7e3 100644 --- a/gfx/thebes/gfxGradientCache.h +++ b/gfx/thebes/gfxGradientCache.h @@ -17,12 +17,12 @@ namespace gfx { class gfxGradientCache { public: static gfx::GradientStops* - GetGradientStops(gfx::DrawTarget *aDT, + GetGradientStops(const gfx::DrawTarget *aDT, nsTArray& aStops, gfx::ExtendMode aExtend); static gfx::GradientStops* - GetOrCreateGradientStops(gfx::DrawTarget *aDT, + GetOrCreateGradientStops(const gfx::DrawTarget *aDT, nsTArray& aStops, gfx::ExtendMode aExtend); diff --git a/gfx/thebes/gfxPattern.cpp b/gfx/thebes/gfxPattern.cpp index 98ff57ed78c1..f81da84f9526 100644 --- a/gfx/thebes/gfxPattern.cpp +++ b/gfx/thebes/gfxPattern.cpp @@ -78,7 +78,7 @@ gfxPattern::SetColorStops(GradientStops* aStops) } void -gfxPattern::CacheColorStops(DrawTarget *aDT) +gfxPattern::CacheColorStops(const DrawTarget *aDT) { mStops = gfxGradientCache::GetOrCreateGradientStops(aDT, mStopsList, ToExtendMode(mExtend)); diff --git a/gfx/thebes/gfxPattern.h b/gfx/thebes/gfxPattern.h index 2324b0773643..037131d39d31 100644 --- a/gfx/thebes/gfxPattern.h +++ b/gfx/thebes/gfxPattern.h @@ -41,7 +41,7 @@ public: // This should only be called on a cairo pattern that we want to use with // Azure. We will read back the color stops from cairo and try to look // them up in the cache. - void CacheColorStops(mozilla::gfx::DrawTarget *aDT); + void CacheColorStops(const mozilla::gfx::DrawTarget *aDT); void SetMatrix(const gfxMatrix& matrix); gfxMatrix GetMatrix() const; diff --git a/gfx/thebes/gfxSVGGlyphs.h b/gfx/thebes/gfxSVGGlyphs.h index 7b191f752c12..af996b711103 100644 --- a/gfx/thebes/gfxSVGGlyphs.h +++ b/gfx/thebes/gfxSVGGlyphs.h @@ -6,6 +6,7 @@ #define GFX_SVG_GLYPHS_WRAPPER_H #include "gfxFontUtils.h" +#include "mozilla/gfx/2D.h" #include "nsString.h" #include "nsAutoPtr.h" #include "nsClassHashtable.h" @@ -166,6 +167,8 @@ private: class gfxTextContextPaint { protected: + typedef mozilla::gfx::DrawTarget DrawTarget; + gfxTextContextPaint() { } public: @@ -176,9 +179,11 @@ public: * This lets us inherit paints and paint opacities (i.e. fill/stroke and * fill-opacity/stroke-opacity) separately. */ - virtual already_AddRefed GetFillPattern(float aOpacity, + virtual already_AddRefed GetFillPattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) = 0; - virtual already_AddRefed GetStrokePattern(float aOpacity, + virtual already_AddRefed GetStrokePattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) = 0; virtual float GetFillOpacity() { return 1.0f; } @@ -199,12 +204,14 @@ public: return mStrokeWidth; } - already_AddRefed GetFillPattern(const gfxMatrix& aCTM) { - return GetFillPattern(GetFillOpacity(), aCTM); + already_AddRefed GetFillPattern(const DrawTarget* aDrawTarget, + const gfxMatrix& aCTM) { + return GetFillPattern(aDrawTarget, GetFillOpacity(), aCTM); } - already_AddRefed GetStrokePattern(const gfxMatrix& aCTM) { - return GetStrokePattern(GetStrokeOpacity(), aCTM); + already_AddRefed GetStrokePattern(const DrawTarget* aDrawTarget, + const gfxMatrix& aCTM) { + return GetStrokePattern(aDrawTarget, GetStrokeOpacity(), aCTM); } virtual ~gfxTextContextPaint() { } @@ -247,7 +254,8 @@ public: mStrokeMatrix = SetupDeviceToPatternMatrix(aStrokePattern, aCTM); } - already_AddRefed GetFillPattern(float aOpacity, + already_AddRefed GetFillPattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) { if (mFillPattern) { mFillPattern->SetMatrix(aCTM * mFillMatrix); @@ -256,7 +264,8 @@ public: return fillPattern.forget(); } - already_AddRefed GetStrokePattern(float aOpacity, + already_AddRefed GetStrokePattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) { if (mStrokePattern) { mStrokePattern->SetMatrix(aCTM * mStrokeMatrix); diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 4263290719a2..cdc7a848506d 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -4699,6 +4699,7 @@ nsImageRenderer::DrawableForElement(const nsRect& aImageRect, nsRefPtr drawable = nsSVGIntegrationUtils::DrawableFromPaintServer( mPaintServerFrame, mForFrame, mSize, imageSize, + aRenderingContext.GetDrawTarget(), aRenderingContext.ThebesContext()->CurrentMatrix(), mFlags & FLAG_SYNC_DECODE_IMAGES ? nsSVGIntegrationUtils::FLAG_SYNC_DECODE_IMAGES diff --git a/layout/svg/SVGTextFrame.cpp b/layout/svg/SVGTextFrame.cpp index a34c267fd7a6..46a888701879 100644 --- a/layout/svg/SVGTextFrame.cpp +++ b/layout/svg/SVGTextFrame.cpp @@ -2993,21 +2993,24 @@ SVGTextDrawPathCallbacks::StrokeGeometry() // SVGTextContextPaint methods: already_AddRefed -SVGTextContextPaint::GetFillPattern(float aOpacity, +SVGTextContextPaint::GetFillPattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) { - return mFillPaint.GetPattern(aOpacity, &nsStyleSVG::mFill, aCTM); + return mFillPaint.GetPattern(aDrawTarget, aOpacity, &nsStyleSVG::mFill, aCTM); } already_AddRefed -SVGTextContextPaint::GetStrokePattern(float aOpacity, +SVGTextContextPaint::GetStrokePattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) { - return mStrokePaint.GetPattern(aOpacity, &nsStyleSVG::mStroke, aCTM); + return mStrokePaint.GetPattern(aDrawTarget, aOpacity, &nsStyleSVG::mStroke, aCTM); } already_AddRefed -SVGTextContextPaint::Paint::GetPattern(float aOpacity, +SVGTextContextPaint::Paint::GetPattern(const DrawTarget* aDrawTarget, + float aOpacity, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, const gfxMatrix& aCTM) { @@ -3034,6 +3037,7 @@ SVGTextContextPaint::Paint::GetPattern(float aOpacity, break; case eStyleSVGPaintType_Server: pattern = mPaintDefinition.mPaintServerFrame->GetPaintServerPattern(mFrame, + aDrawTarget, mContextMatrix, aFillOrStroke, aOpacity); @@ -3050,12 +3054,14 @@ SVGTextContextPaint::Paint::GetPattern(float aOpacity, pattern->SetMatrix(aCTM * mPatternMatrix); break; case eStyleSVGPaintType_ContextFill: - pattern = mPaintDefinition.mContextPaint->GetFillPattern(aOpacity, aCTM); + pattern = mPaintDefinition.mContextPaint->GetFillPattern(aDrawTarget, + aOpacity, aCTM); // Don't cache this. mContextPaint will have cached it anyway. If we // cache it, we'll have to compute mPatternMatrix, which is annoying. return pattern.forget(); case eStyleSVGPaintType_ContextStroke: - pattern = mPaintDefinition.mContextPaint->GetStrokePattern(aOpacity, aCTM); + pattern = mPaintDefinition.mContextPaint->GetStrokePattern(aDrawTarget, + aOpacity, aCTM); // Don't cache this. mContextPaint will have cached it anyway. If we // cache it, we'll have to compute mPatternMatrix, which is annoying. return pattern.forget(); @@ -3677,8 +3683,8 @@ SVGTextFrame::PaintSVG(nsRenderingContext* aContext, SVGTextContextPaint contextPaint; DrawMode drawMode = - SetupContextPaint(gfx->CurrentMatrix(), frame, outerContextPaint, - &contextPaint); + SetupContextPaint(gfx->GetDrawTarget(), gfx->CurrentMatrix(), + frame, outerContextPaint, &contextPaint); if (int(drawMode) & int(DrawMode::GLYPH_STROKE)) { // This may change the gfxContext's transform (for non-scaling stroke), @@ -5587,7 +5593,8 @@ SVGTextFrame::TransformFrameRectFromTextChild(const nsRect& aRect, * server frame */ static void -SetupInheritablePaint(const gfxMatrix& aContextMatrix, +SetupInheritablePaint(const DrawTarget* aDrawTarget, + const gfxMatrix& aContextMatrix, nsIFrame* aFrame, float& aOpacity, gfxTextContextPaint* aOuterContextPaint, @@ -5601,7 +5608,8 @@ SetupInheritablePaint(const gfxMatrix& aContextMatrix, if (ps) { nsRefPtr pattern = - ps->GetPaintServerPattern(aFrame, aContextMatrix, aFillOrStroke, aOpacity); + ps->GetPaintServerPattern(aFrame, aDrawTarget, aContextMatrix, + aFillOrStroke, aOpacity); if (pattern) { aTargetPaint.SetPaintServer(aFrame, aContextMatrix, ps); return; @@ -5611,10 +5619,12 @@ SetupInheritablePaint(const gfxMatrix& aContextMatrix, nsRefPtr pattern; switch ((style->*aFillOrStroke).mType) { case eStyleSVGPaintType_ContextFill: - pattern = aOuterContextPaint->GetFillPattern(aOpacity, aContextMatrix); + pattern = aOuterContextPaint->GetFillPattern(aDrawTarget, aOpacity, + aContextMatrix); break; case eStyleSVGPaintType_ContextStroke: - pattern = aOuterContextPaint->GetStrokePattern(aOpacity, aContextMatrix); + pattern = aOuterContextPaint->GetStrokePattern(aDrawTarget, aOpacity, + aContextMatrix); break; default: ; @@ -5630,7 +5640,8 @@ SetupInheritablePaint(const gfxMatrix& aContextMatrix, } DrawMode -SVGTextFrame::SetupContextPaint(const gfxMatrix& aContextMatrix, +SVGTextFrame::SetupContextPaint(const DrawTarget* aDrawTarget, + const gfxMatrix& aContextMatrix, nsIFrame* aFrame, gfxTextContextPaint* aOuterContextPaint, SVGTextContextPaint* aThisContextPaint) @@ -5647,7 +5658,8 @@ SVGTextFrame::SetupContextPaint(const gfxMatrix& aContextMatrix, style->mFillOpacity, aOuterContextPaint); - SetupInheritablePaint(aContextMatrix, aFrame, opacity, aOuterContextPaint, + SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame, + opacity, aOuterContextPaint, aThisContextPaint->mFillPaint, &nsStyleSVG::mFill, nsSVGEffects::FillProperty()); @@ -5664,7 +5676,8 @@ SVGTextFrame::SetupContextPaint(const gfxMatrix& aContextMatrix, style->mStrokeOpacity, aOuterContextPaint); - SetupInheritablePaint(aContextMatrix, aFrame, opacity, aOuterContextPaint, + SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame, + opacity, aOuterContextPaint, aThisContextPaint->mStrokePaint, &nsStyleSVG::mStroke, nsSVGEffects::StrokeProperty()); diff --git a/layout/svg/SVGTextFrame.h b/layout/svg/SVGTextFrame.h index 76ce11854a9a..0e49e4658abb 100644 --- a/layout/svg/SVGTextFrame.h +++ b/layout/svg/SVGTextFrame.h @@ -139,9 +139,14 @@ private: // Slightly horrible callback for deferring application of opacity struct SVGTextContextPaint : public gfxTextContextPaint { - already_AddRefed GetFillPattern(float aOpacity, +protected: + typedef mozilla::gfx::DrawTarget DrawTarget; +public: + already_AddRefed GetFillPattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) MOZ_OVERRIDE; - already_AddRefed GetStrokePattern(float aOpacity, + already_AddRefed GetStrokePattern(const DrawTarget* aDrawTarget, + float aOpacity, const gfxMatrix& aCTM) MOZ_OVERRIDE; void SetFillOpacity(float aOpacity) { mFillOpacity = aOpacity; } @@ -190,7 +195,8 @@ struct SVGTextContextPaint : public gfxTextContextPaint { gfxMatrix mPatternMatrix; nsRefPtrHashtable mPatternCache; - already_AddRefed GetPattern(float aOpacity, + already_AddRefed GetPattern(const DrawTarget* aDrawTarget, + float aOpacity, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, const gfxMatrix& aCTM); }; @@ -252,6 +258,7 @@ class SVGTextFrame MOZ_FINAL : public SVGTextFrameBase friend class MutationObserver; friend class nsDisplaySVGText; + typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::Path Path; typedef mozilla::gfx::Point Point; typedef mozilla::SVGTextContextPaint SVGTextContextPaint; @@ -594,7 +601,8 @@ private: gfxFloat GetOffsetScale(nsIFrame* aTextPathFrame); gfxFloat GetStartOffset(nsIFrame* aTextPathFrame); - DrawMode SetupContextPaint(const gfxMatrix& aContextMatrix, + DrawMode SetupContextPaint(const DrawTarget* aDrawTarget, + const gfxMatrix& aContextMatrix, nsIFrame* aFrame, gfxTextContextPaint* aOuterContextPaint, SVGTextContextPaint* aThisContextPaint); diff --git a/layout/svg/nsSVGGradientFrame.cpp b/layout/svg/nsSVGGradientFrame.cpp index 0919eafa4090..912c7308d350 100644 --- a/layout/svg/nsSVGGradientFrame.cpp +++ b/layout/svg/nsSVGGradientFrame.cpp @@ -209,11 +209,12 @@ static void GetStopInformation(nsIFrame* aStopFrame, } already_AddRefed -nsSVGGradientFrame::GetPaintServerPattern(nsIFrame *aSource, +nsSVGGradientFrame::GetPaintServerPattern(nsIFrame* aSource, + const DrawTarget* aDrawTarget, const gfxMatrix& aContextMatrix, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, float aGraphicOpacity, - const gfxRect *aOverrideBounds) + const gfxRect* aOverrideBounds) { uint16_t gradientUnits = GetGradientUnits(); MOZ_ASSERT(gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX || diff --git a/layout/svg/nsSVGGradientFrame.h b/layout/svg/nsSVGGradientFrame.h index a9921d58ff10..ccb4cc0808c7 100644 --- a/layout/svg/nsSVGGradientFrame.h +++ b/layout/svg/nsSVGGradientFrame.h @@ -47,11 +47,12 @@ public: // nsSVGPaintServerFrame methods: virtual already_AddRefed - GetPaintServerPattern(nsIFrame *aSource, + GetPaintServerPattern(nsIFrame* aSource, + const DrawTarget* aDrawTarget, const gfxMatrix& aContextMatrix, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, float aGraphicOpacity, - const gfxRect *aOverrideBounds) MOZ_OVERRIDE; + const gfxRect* aOverrideBounds) MOZ_OVERRIDE; // nsIFrame interface: virtual nsresult AttributeChanged(int32_t aNameSpaceID, diff --git a/layout/svg/nsSVGIntegrationUtils.cpp b/layout/svg/nsSVGIntegrationUtils.cpp index b60d7788bf82..b0e523adbc14 100644 --- a/layout/svg/nsSVGIntegrationUtils.cpp +++ b/layout/svg/nsSVGIntegrationUtils.cpp @@ -695,6 +695,7 @@ nsSVGIntegrationUtils::DrawableFromPaintServer(nsIFrame* aFrame, nsIFrame* aTarget, const nsSize& aPaintServerSize, const gfxIntSize& aRenderSize, + const DrawTarget* aDrawTarget, const gfxMatrix& aContextMatrix, uint32_t aFlags) { @@ -715,8 +716,9 @@ nsSVGIntegrationUtils::DrawableFromPaintServer(nsIFrame* aFrame, aPaintServerSize.width, aPaintServerSize.height); overrideBounds.ScaleInverse(aFrame->PresContext()->AppUnitsPerDevPixel()); nsRefPtr pattern = - server->GetPaintServerPattern(aTarget, aContextMatrix, - &nsStyleSVG::mFill, 1.0, &overrideBounds); + server->GetPaintServerPattern(aTarget, aDrawTarget, + aContextMatrix, &nsStyleSVG::mFill, 1.0, + &overrideBounds); if (!pattern) return nullptr; diff --git a/layout/svg/nsSVGIntegrationUtils.h b/layout/svg/nsSVGIntegrationUtils.h index bb5b89ac81a1..f05ab1ce30d9 100644 --- a/layout/svg/nsSVGIntegrationUtils.h +++ b/layout/svg/nsSVGIntegrationUtils.h @@ -22,6 +22,9 @@ struct nsRect; struct nsIntRect; namespace mozilla { +namespace gfx { +class DrawTarget; +} namespace layers { class LayerManager; } @@ -36,6 +39,8 @@ struct nsSize; */ class nsSVGIntegrationUtils MOZ_FINAL { + typedef mozilla::gfx::DrawTarget DrawTarget; + public: /** * Returns true if SVG effects are currently applied to this frame. @@ -166,6 +171,7 @@ public: nsIFrame* aTarget, const nsSize& aPaintServerSize, const gfxIntSize& aRenderSize, + const DrawTarget* aDrawTarget, const gfxMatrix& aContextMatrix, uint32_t aFlags); }; diff --git a/layout/svg/nsSVGPaintServerFrame.h b/layout/svg/nsSVGPaintServerFrame.h index 7807bb9b22b1..44abe008bb15 100644 --- a/layout/svg/nsSVGPaintServerFrame.h +++ b/layout/svg/nsSVGPaintServerFrame.h @@ -14,6 +14,12 @@ #include "nsSVGContainerFrame.h" #include "nsSVGUtils.h" +namespace mozilla { +namespace gfx { +class DrawTarget; +} +} + class gfxContext; class gfxPattern; class nsStyleContext; @@ -25,6 +31,8 @@ typedef nsSVGContainerFrame nsSVGPaintServerFrameBase; class nsSVGPaintServerFrame : public nsSVGPaintServerFrameBase { protected: + typedef mozilla::gfx::DrawTarget DrawTarget; + explicit nsSVGPaintServerFrame(nsStyleContext* aContext) : nsSVGPaintServerFrameBase(aContext) { @@ -44,6 +52,7 @@ public: */ virtual already_AddRefed GetPaintServerPattern(nsIFrame *aSource, + const DrawTarget* aDrawTarget, const gfxMatrix& aContextMatrix, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, float aOpacity, diff --git a/layout/svg/nsSVGPatternFrame.cpp b/layout/svg/nsSVGPatternFrame.cpp index 8aad7675542d..12ed1faf2cd9 100644 --- a/layout/svg/nsSVGPatternFrame.cpp +++ b/layout/svg/nsSVGPatternFrame.cpp @@ -231,7 +231,8 @@ GetTargetGeometry(gfxRect *aBBox, } TemporaryRef -nsSVGPatternFrame::PaintPattern(Matrix* patternMatrix, +nsSVGPatternFrame::PaintPattern(const DrawTarget* aDrawTarget, + Matrix* patternMatrix, const Matrix &aContextMatrix, nsIFrame *aSource, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, @@ -373,8 +374,7 @@ nsSVGPatternFrame::PaintPattern(Matrix* patternMatrix, } RefPtr dt = - gfxPlatform::GetPlatform()-> - CreateOffscreenContentDrawTarget(surfaceSize, SurfaceFormat::B8G8R8A8); + aDrawTarget->CreateSimilarDrawTarget(surfaceSize, SurfaceFormat::B8G8R8A8); if (!dt) { return nullptr; } @@ -707,6 +707,7 @@ nsSVGPatternFrame::ConstructCTM(const nsSVGViewBox& aViewBox, already_AddRefed nsSVGPatternFrame::GetPaintServerPattern(nsIFrame *aSource, + const DrawTarget* aDrawTarget, const gfxMatrix& aContextMatrix, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, float aGraphicOpacity, @@ -720,8 +721,8 @@ nsSVGPatternFrame::GetPaintServerPattern(nsIFrame *aSource, // Paint it! Matrix pMatrix; RefPtr surface = - PaintPattern(&pMatrix, ToMatrix(aContextMatrix), aSource, aFillOrStroke, - aGraphicOpacity, aOverrideBounds); + PaintPattern(aDrawTarget, &pMatrix, ToMatrix(aContextMatrix), aSource, + aFillOrStroke, aGraphicOpacity, aOverrideBounds); if (!surface) { return nullptr; diff --git a/layout/svg/nsSVGPatternFrame.h b/layout/svg/nsSVGPatternFrame.h index 8cc7325eec35..37fab695055c 100644 --- a/layout/svg/nsSVGPatternFrame.h +++ b/layout/svg/nsSVGPatternFrame.h @@ -46,6 +46,7 @@ public: // nsSVGPaintServerFrame methods: virtual already_AddRefed GetPaintServerPattern(nsIFrame *aSource, + const DrawTarget* aDrawTarget, const gfxMatrix& aContextMatrix, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, float aOpacity, @@ -112,7 +113,8 @@ protected: } mozilla::TemporaryRef - PaintPattern(Matrix *patternMatrix, + PaintPattern(const DrawTarget* aDrawTarget, + Matrix *patternMatrix, const Matrix &aContextMatrix, nsIFrame *aSource, nsStyleSVGPaint nsStyleSVG::*aFillOrStroke, diff --git a/layout/svg/nsSVGUtils.cpp b/layout/svg/nsSVGUtils.cpp index c1a5ea991898..c7701533bf86 100644 --- a/layout/svg/nsSVGUtils.cpp +++ b/layout/svg/nsSVGUtils.cpp @@ -1257,16 +1257,18 @@ nsSVGUtils::MakeFillPatternFor(nsIFrame *aFrame, GetOpacity(style->mFillOpacitySource, style->mFillOpacity, aContextPaint)); + const DrawTarget* dt = aContext->GetDrawTarget(); + nsRefPtr pattern; nsSVGPaintServerFrame *ps = nsSVGEffects::GetPaintServer(aFrame, &style->mFill, nsSVGEffects::FillProperty()); if (ps) { - pattern = ps->GetPaintServerPattern(aFrame, aContext->CurrentMatrix(), + pattern = ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(), &nsStyleSVG::mFill, opacity); if (pattern) { - pattern->CacheColorStops(aContext->GetDrawTarget()); + pattern->CacheColorStops(dt); return pattern.forget(); } } @@ -1274,10 +1276,12 @@ nsSVGUtils::MakeFillPatternFor(nsIFrame *aFrame, if (aContextPaint) { switch (style->mFill.mType) { case eStyleSVGPaintType_ContextFill: - pattern = aContextPaint->GetFillPattern(opacity, aContext->CurrentMatrix()); + pattern = aContextPaint->GetFillPattern(dt, opacity, + aContext->CurrentMatrix()); break; case eStyleSVGPaintType_ContextStroke: - pattern = aContextPaint->GetStrokePattern(opacity, aContext->CurrentMatrix()); + pattern = aContextPaint->GetStrokePattern(dt, opacity, + aContext->CurrentMatrix()); break; default: ; @@ -1313,16 +1317,19 @@ nsSVGUtils::MakeStrokePatternFor(nsIFrame *aFrame, GetOpacity(style->mStrokeOpacitySource, style->mStrokeOpacity, aContextPaint)); + + const DrawTarget* dt = aContext->GetDrawTarget(); + nsRefPtr pattern; nsSVGPaintServerFrame *ps = nsSVGEffects::GetPaintServer(aFrame, &style->mStroke, nsSVGEffects::StrokeProperty()); if (ps) { - pattern = ps->GetPaintServerPattern(aFrame, aContext->CurrentMatrix(), + pattern = ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(), &nsStyleSVG::mStroke, opacity); if (pattern) { - pattern->CacheColorStops(aContext->GetDrawTarget()); + pattern->CacheColorStops(dt); return pattern.forget(); } } @@ -1330,10 +1337,12 @@ nsSVGUtils::MakeStrokePatternFor(nsIFrame *aFrame, if (aContextPaint) { switch (style->mStroke.mType) { case eStyleSVGPaintType_ContextFill: - pattern = aContextPaint->GetFillPattern(opacity, aContext->CurrentMatrix()); + pattern = aContextPaint->GetFillPattern(dt, opacity, + aContext->CurrentMatrix()); break; case eStyleSVGPaintType_ContextStroke: - pattern = aContextPaint->GetStrokePattern(opacity, aContext->CurrentMatrix()); + pattern = aContextPaint->GetStrokePattern(dt, opacity, + aContext->CurrentMatrix()); break; default: ;