From 4c1b0ad4f8687150c56172a13a0279686cf7d1b8 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 25 Mar 2016 22:14:50 -0400 Subject: [PATCH] Bug 1259621 - use AlphaBoxBlur in DrawTargetSkia::DrawSurfaceWithShadow. r=mchang --- gfx/2d/DrawTargetSkia.cpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp index 3232dde9c3c5..b44a4c8fba13 100644 --- a/gfx/2d/DrawTargetSkia.cpp +++ b/gfx/2d/DrawTargetSkia.cpp @@ -17,6 +17,7 @@ #include "skia/include/core/SkColorFilter.h" #include "skia/include/effects/SkBlurImageFilter.h" #include "skia/include/effects/SkLayerRasterizer.h" +#include "Blur.h" #include "Logging.h" #include "Tools.h" #include "DataSurfaceHelpers.h" @@ -432,16 +433,37 @@ DrawTargetSkia::DrawSurfaceWithShadow(SourceSurface *aSurface, // to blur the image ourselves. SkPaint shadowPaint; - SkAutoTUnref blurFilter(SkBlurImageFilter::Create(aSigma, aSigma)); - SkAutoTUnref colorFilter( - SkColorFilter::CreateModeFilter(ColorToSkColor(aColor, 1.0), SkXfermode::kSrcIn_Mode)); - shadowPaint.setXfermode(paint.getXfermode()); - shadowPaint.setImageFilter(blurFilter.get()); - shadowPaint.setColorFilter(colorFilter.get()); IntPoint shadowDest = RoundedToInt(aDest + aOffset); - mCanvas->drawBitmap(bitmap, shadowDest.x, shadowDest.y, &shadowPaint); + + SkBitmap blurMask; + if (!UsingSkiaGPU() && + bitmap.extractAlpha(&blurMask)) { + // Prefer using our own box blur instead of Skia's when we're + // not using the GPU. It currently performs much better than + // SkBlurImageFilter or SkBlurMaskFilter on the CPU. + AlphaBoxBlur blur(Rect(0, 0, blurMask.width(), blurMask.height()), + int32_t(blurMask.rowBytes()), + aSigma, aSigma); + blurMask.lockPixels(); + blur.Blur(reinterpret_cast(blurMask.getPixels())); + blurMask.unlockPixels(); + blurMask.notifyPixelsChanged(); + + shadowPaint.setColor(ColorToSkColor(aColor, 1.0f)); + + mCanvas->drawBitmap(blurMask, shadowDest.x, shadowDest.y, &shadowPaint); + } else { + SkAutoTUnref blurFilter(SkBlurImageFilter::Create(aSigma, aSigma)); + SkAutoTUnref colorFilter( + SkColorFilter::CreateModeFilter(ColorToSkColor(aColor, 1.0f), SkXfermode::kSrcIn_Mode)); + + shadowPaint.setImageFilter(blurFilter.get()); + shadowPaint.setColorFilter(colorFilter.get()); + + mCanvas->drawBitmap(bitmap, shadowDest.x, shadowDest.y, &shadowPaint); + } // Composite the original image after the shadow IntPoint dest = RoundedToInt(aDest);