Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: src/effects/SkBlurMask.cpp

Issue 471473002: Optimize CSS box-shadow performance (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: backed blur mask with a bitmap Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/effects/SkBlurMask.cpp
diff --git a/src/effects/SkBlurMask.cpp b/src/effects/SkBlurMask.cpp
index bf50845ab6cb1d308562ea44fa279133bcafd46f..da3e8ed811283b27c74dcda596d97488dd881f66 100644
--- a/src/effects/SkBlurMask.cpp
+++ b/src/effects/SkBlurMask.cpp
@@ -9,6 +9,7 @@
#include "SkBlurMask.h"
#include "SkMath.h"
+#include "SkResourceCache.h"
#include "SkTemplates.h"
#include "SkEndian.h"
@@ -479,6 +480,14 @@ void SkMask_FreeImage(uint8_t* image) {
SkMask::FreeImage(image);
}
+SkBitmap createBitmap(const SkImageInfo& info, size_t rowBytes) {
+ SkBitmap bitmap;
+ SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator();
+ bitmap.setInfo(info, rowBytes);
+ bitmap.allocPixels(allocator, NULL);
+ return bitmap;
+}
+
bool SkBlurMask::BoxBlur(SkMask* dst, const SkMask& src,
SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
SkIPoint* margin, bool force_quality) {
@@ -541,8 +550,10 @@ bool SkBlurMask::BoxBlur(SkMask* dst, const SkMask& src,
int sw = src.fBounds.width();
int sh = src.fBounds.height();
const uint8_t* sp = src.fImage;
- uint8_t* dp = SkMask::AllocImage(dstSize);
- SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp);
+ SkBitmap bitmap;
+ bitmap = createBitmap(SkImageInfo::MakeA8(dst->fBounds.width(),dst->fBounds.height()), dst->fRowBytes);
+ SkAutoLockPixels alp(bitmap);
+ uint8_t* dp = bitmap.getAddr8(0, 0);
// build the blurry destination
SkAutoTMalloc<uint8_t> tmpBuffer(dstSize);
@@ -582,6 +593,7 @@ bool SkBlurMask::BoxBlur(SkMask* dst, const SkMask& src,
}
dst->fImage = dp;
+ dst->fBitmap = bitmap;
// if need be, alloc the "real" dst (same size as src) and copy/merge
// the blur into it (applying the src)
if (style == kInner_SkBlurStyle) {
@@ -590,17 +602,17 @@ bool SkBlurMask::BoxBlur(SkMask* dst, const SkMask& src,
if (0 == srcSize) {
return false; // too big to allocate, abort
}
- dst->fImage = SkMask::AllocImage(srcSize);
+ dst->fBitmap = createBitmap(SkImageInfo::MakeA8(sw, sh), src.fRowBytes);
+ SkAutoLockPixels alp(dst->fBitmap);
+ dst->fImage = dst->fBitmap.getAddr8(0, 0);
merge_src_with_blur(dst->fImage, src.fRowBytes,
sp, src.fRowBytes,
dp + passCount * (rx + ry * dst->fRowBytes),
dst->fRowBytes, sw, sh);
- SkMask::FreeImage(dp);
} else if (style != kNormal_SkBlurStyle) {
clamp_with_orig(dp + passCount * (rx + ry * dst->fRowBytes),
dst->fRowBytes, sp, src.fRowBytes, sw, sh, style);
}
- (void)autoCall.detach();
}
if (style == kInner_SkBlurStyle) {
@@ -779,13 +791,15 @@ bool SkBlurMask::BlurRect(SkScalar sigma, SkMask *dst,
return false; // too big to allocate, abort
}
- uint8_t* dp = SkMask::AllocImage(dstSize);
-
- dst->fImage = dp;
-
int dstHeight = dst->fBounds.height();
int dstWidth = dst->fBounds.width();
+ SkBitmap bitmap = createBitmap(SkImageInfo::MakeA8(dstWidth, dstHeight), dst->fRowBytes);
+ SkAutoLockPixels alp(bitmap);
+ uint8_t* dp = bitmap.getAddr8(0, 0);
+ dst->fImage = dp;
+ dst->fBitmap = bitmap;
+
uint8_t *outptr = dp;
SkAutoTMalloc<uint8_t> horizontalScanline(dstWidth);
@@ -807,20 +821,21 @@ bool SkBlurMask::BlurRect(SkScalar sigma, SkMask *dst,
if (0 == srcSize) {
return false; // too big to allocate, abort
}
- dst->fImage = SkMask::AllocImage(srcSize);
- for (int y = 0 ; y < sh ; y++) {
- uint8_t *blur_scanline = dp + (y+pad)*dstWidth + pad;
- uint8_t *inner_scanline = dst->fImage + y*sw;
- memcpy(inner_scanline, blur_scanline, sw);
- }
- SkMask::FreeImage(dp);
-
dst->fBounds.set(SkScalarRoundToInt(src.fLeft),
SkScalarRoundToInt(src.fTop),
SkScalarRoundToInt(src.fRight),
SkScalarRoundToInt(src.fBottom)); // restore trimmed bounds
dst->fRowBytes = sw;
+ dst->fBitmap = createBitmap(SkImageInfo::MakeA8(dst->fBounds.width(),
+ dst->fBounds.height()), dst->fRowBytes);
+ SkAutoLockPixels alp(dst->fBitmap);
+ dst->fImage = dst->fBitmap.getAddr8(0, 0);
+ for (int y = 0 ; y < sh ; y++) {
+ uint8_t *blur_scanline = dp + (y+pad)*dstWidth + pad;
+ uint8_t *inner_scanline = dst->fImage + y*sw;
+ memcpy(inner_scanline, blur_scanline, sw);
+ }
} else if (style == kOuter_SkBlurStyle) {
for (int y = pad ; y < dstHeight-pad ; y++) {
uint8_t *dst_scanline = dp + y*dstWidth + pad;

Powered by Google App Engine
This is Rietveld 408576698