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

View File

@ -48,6 +48,7 @@ namespace mozilla {
class gfxAlphaBoxBlur
{
typedef mozilla::gfx::Color Color;
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
public:
@ -89,7 +90,8 @@ public:
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
@ -176,7 +178,7 @@ protected:
const bool& aHasBorderRadius,
const mozilla::gfx::Point aShadowOffset,
bool& aMovedOffset,
gfxContext* aDestinationCtx);
DrawTarget* aDestDrawTarget);
/**
* The context of the temporary alpha surface.