Bug 1236802 (part 1) - Moz2Dify some blur code a little. r=mattwoodrow.

gfxAlphaBoxBlur::GetInsetBlur() can be trivially passed a DrawTarget instead of
a gfxContext.

The patch also removes the DrawTarget parameter from GetBlur() because it can
be obtained from the gfxContext parameter.
This commit is contained in:
Nicholas Nethercote 2016-01-10 14:05:26 -08:00
parent 3f5b88256d
commit 26bade2c4c
2 changed files with 22 additions and 18 deletions

View File

@ -511,14 +511,13 @@ CreateBoxShadow(SourceSurface* aBlurMask, const Color& aShadowColor)
} }
static already_AddRefed<SourceSurface> static already_AddRefed<SourceSurface>
GetBlur(DrawTarget& aDT, GetBlur(gfxContext* aDestinationCtx,
const IntSize& aRectSize, const IntSize& aRectSize,
const IntSize& aBlurRadius, const IntSize& aBlurRadius,
RectCornerRadii* aCornerRadii, RectCornerRadii* aCornerRadii,
const Color& aShadowColor, const Color& aShadowColor,
IntMargin& aExtendDestBy, IntMargin& aExtendDestBy,
IntMargin& aSlice, IntMargin& aSlice)
gfxContext* aDestinationCtx)
{ {
if (!gBlurCache) { if (!gBlurCache) {
gBlurCache = new BlurCache(); gBlurCache = new BlurCache();
@ -536,9 +535,11 @@ GetBlur(DrawTarget& aDT,
minSize = aRectSize; minSize = aRectSize;
} }
DrawTarget& destDT = *aDestinationCtx->GetDrawTarget();
BlurCacheData* cached = gBlurCache->Lookup(minSize, aBlurRadius, BlurCacheData* cached = gBlurCache->Lookup(minSize, aBlurRadius,
aCornerRadii, aShadowColor, aCornerRadii, aShadowColor,
aDT.GetBackendType()); destDT.GetBackendType());
if (cached && !useDestRect) { if (cached && !useDestRect) {
// See CreateBlurMask() for these values // See CreateBlurMask() for these values
aExtendDestBy = cached->mExtendDest; aExtendDestBy = cached->mExtendDest;
@ -548,7 +549,8 @@ GetBlur(DrawTarget& aDT,
} }
RefPtr<SourceSurface> blurMask = RefPtr<SourceSurface> blurMask =
CreateBlurMask(minSize, aCornerRadii, aBlurRadius, aExtendDestBy, aSlice, aDT); CreateBlurMask(minSize, aCornerRadii, aBlurRadius, aExtendDestBy, aSlice,
destDT);
if (!blurMask) { if (!blurMask) {
return nullptr; return nullptr;
@ -563,7 +565,8 @@ GetBlur(DrawTarget& aDT,
// Since we're just going to paint the actual rect to the destination // Since we're just going to paint the actual rect to the destination
aSlice.SizeTo(0, 0, 0, 0); aSlice.SizeTo(0, 0, 0, 0);
} else { } else {
CacheBlur(aDT, minSize, aBlurRadius, aCornerRadii, aShadowColor, aExtendDestBy, boxShadow); CacheBlur(destDT, minSize, aBlurRadius, aCornerRadii, aShadowColor,
aExtendDestBy, boxShadow);
} }
return boxShadow.forget(); return boxShadow.forget();
} }
@ -701,22 +704,21 @@ gfxAlphaBoxBlur::BlurRectangle(gfxContext* aDestinationCtx,
const gfxRect& aDirtyRect, const gfxRect& aDirtyRect,
const gfxRect& aSkipRect) const gfxRect& aSkipRect)
{ {
DrawTarget& destDrawTarget = *aDestinationCtx->GetDrawTarget();
IntSize blurRadius = CalculateBlurRadius(aBlurStdDev); IntSize blurRadius = CalculateBlurRadius(aBlurStdDev);
IntRect rect = RoundedToInt(ToRect(aRect)); IntRect rect = RoundedToInt(ToRect(aRect));
IntMargin extendDestBy; IntMargin extendDestBy;
IntMargin slice; IntMargin slice;
RefPtr<SourceSurface> boxShadow = GetBlur(destDrawTarget, RefPtr<SourceSurface> boxShadow = GetBlur(aDestinationCtx,
rect.Size(), blurRadius, rect.Size(), blurRadius,
aCornerRadii, aShadowColor, aCornerRadii, aShadowColor,
extendDestBy, slice, extendDestBy, slice);
aDestinationCtx);
if (!boxShadow) { if (!boxShadow) {
return; return;
} }
DrawTarget& destDrawTarget = *aDestinationCtx->GetDrawTarget();
destDrawTarget.PushClipRect(ToRect(aDirtyRect)); destDrawTarget.PushClipRect(ToRect(aDirtyRect));
// Copy the right parts from boxShadow into destDrawTarget. The middle parts // Copy the right parts from boxShadow into destDrawTarget. The middle parts
@ -921,7 +923,7 @@ gfxAlphaBoxBlur::GetInsetBlur(IntMargin& aExtendDestBy,
const bool& aHasBorderRadius, const bool& aHasBorderRadius,
const Point aShadowOffset, const Point aShadowOffset,
bool& aMovedOffset, bool& aMovedOffset,
gfxContext* aDestinationCtx) DrawTarget* aDestDrawTarget)
{ {
if (!gBlurCache) { if (!gBlurCache) {
gBlurCache = new BlurCache(); gBlurCache = new BlurCache();
@ -948,13 +950,12 @@ gfxAlphaBoxBlur::GetInsetBlur(IntMargin& aExtendDestBy,
aMovedOffset = true; aMovedOffset = true;
} }
DrawTarget* destDrawTarget = aDestinationCtx->GetDrawTarget();
BlurCacheData* cached = BlurCacheData* cached =
gBlurCache->LookupInsetBoxShadow(outerRect.Size(), innerRect.Size(), gBlurCache->LookupInsetBoxShadow(outerRect.Size(), innerRect.Size(),
aBlurRadius, aSpreadRadius, aBlurRadius, aSpreadRadius,
&aInnerClipRadii, aShadowColor, &aInnerClipRadii, aShadowColor,
aHasBorderRadius, aHasBorderRadius,
destDrawTarget->GetBackendType()); aDestDrawTarget->GetBackendType());
if (cached && !useDestRect) { if (cached && !useDestRect) {
aExtendDestBy = cached->mExtendDest; aExtendDestBy = cached->mExtendDest;
// Need to extend it twice: once for the outer rect and once for the inner rect. // Need to extend it twice: once for the outer rect and once for the inner rect.
@ -1011,7 +1012,7 @@ gfxAlphaBoxBlur::GetInsetBlur(IntMargin& aExtendDestBy,
CacheInsetBlur(outerRect.Size(), innerRect.Size(), CacheInsetBlur(outerRect.Size(), innerRect.Size(),
aBlurRadius, aSpreadRadius, aBlurRadius, aSpreadRadius,
&aInnerClipRadii, aShadowColor, &aInnerClipRadii, aShadowColor,
aHasBorderRadius, destDrawTarget->GetBackendType(), aHasBorderRadius, aDestDrawTarget->GetBackendType(),
aExtendDestBy, minInsetBlur); aExtendDestBy, minInsetBlur);
} }
@ -1041,6 +1042,8 @@ gfxAlphaBoxBlur::BlurInsetBox(gfxContext* aDestinationCtx,
const Rect aSkipRect, const Rect aSkipRect,
const Point aShadowOffset) const Point aShadowOffset)
{ {
DrawTarget* destDrawTarget = aDestinationCtx->GetDrawTarget();
// Blur inset shadows ALWAYS have a 0 spread radius. // Blur inset shadows ALWAYS have a 0 spread radius.
if ((aBlurRadius.width <= 0 && aBlurRadius.height <= 0)) { if ((aBlurRadius.width <= 0 && aBlurRadius.height <= 0)) {
FillDestinationPath(aDestinationCtx, aDestinationRect, aShadowClipRect, FillDestinationPath(aDestinationCtx, aDestinationRect, aShadowClipRect,
@ -1056,7 +1059,7 @@ gfxAlphaBoxBlur::BlurInsetBox(gfxContext* aDestinationCtx,
aBlurRadius, aSpreadRadius, aBlurRadius, aSpreadRadius,
aInnerClipRadii, aShadowColor, aInnerClipRadii, aShadowColor,
aHasBorderRadius, aShadowOffset, aHasBorderRadius, aShadowOffset,
didMoveOffset, aDestinationCtx); didMoveOffset, destDrawTarget);
if (!minInsetBlur) { if (!minInsetBlur) {
return; return;
} }
@ -1073,7 +1076,6 @@ gfxAlphaBoxBlur::BlurInsetBox(gfxContext* aDestinationCtx,
Rect dstInner = dstOuter; Rect dstInner = dstOuter;
dstInner.Deflate(Margin(slice)); dstInner.Deflate(Margin(slice));
DrawTarget* destDrawTarget = aDestinationCtx->GetDrawTarget();
if (dstOuter.Size() == srcOuter.Size()) { if (dstOuter.Size() == srcOuter.Size()) {
destDrawTarget->DrawSurface(minInsetBlur, dstOuter, srcOuter); destDrawTarget->DrawSurface(minInsetBlur, dstOuter, srcOuter);
} else { } else {

View File

@ -48,6 +48,7 @@ namespace mozilla {
class gfxAlphaBoxBlur class gfxAlphaBoxBlur
{ {
typedef mozilla::gfx::Color Color; typedef mozilla::gfx::Color Color;
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::RectCornerRadii RectCornerRadii; typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
public: public:
@ -89,7 +90,8 @@ public:
return mContext; return mContext;
} }
already_AddRefed<mozilla::gfx::SourceSurface> DoBlur(mozilla::gfx::DrawTarget* aDT, mozilla::gfx::IntPoint* aTopLeft); already_AddRefed<mozilla::gfx::SourceSurface>
DoBlur(DrawTarget* aDT, mozilla::gfx::IntPoint* aTopLeft);
/** /**
* Does the actual blurring/spreading and mask applying. Users of this * Does the actual blurring/spreading and mask applying. Users of this
@ -176,7 +178,7 @@ protected:
const bool& aHasBorderRadius, const bool& aHasBorderRadius,
const mozilla::gfx::Point aShadowOffset, const mozilla::gfx::Point aShadowOffset,
bool& aMovedOffset, bool& aMovedOffset,
gfxContext* aDestinationCtx); DrawTarget* aDestDrawTarget);
/** /**
* The context of the temporary alpha surface. * The context of the temporary alpha surface.