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

Unified Diff: src/effects/SkBlurMask.cpp

Issue 286273002: Optimize CSS box-shadow performance by caching the SkMask of the blur effect. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add mutex for thread-safe and use SkDiscardableMemory Created 6 years, 7 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..d03ca7716ccab358919be85f9499e8d35e9d12c1 100644
--- a/src/effects/SkBlurMask.cpp
+++ b/src/effects/SkBlurMask.cpp
@@ -541,8 +541,13 @@ 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);
+ uint8_t* dp = NULL;
+ SkDiscardableMemory* dm = NULL;
+ if (dst->fUseDiscardableMemory && (dm = SkDiscardableMemory::Create(dstSize))) {
+ dp = static_cast<uint8_t*>(dm->data());
+ dst->fDiscardableMemory = dm;
+ } else
+ dp = SkMask::AllocImage(dstSize);
// build the blurry destination
SkAutoTMalloc<uint8_t> tmpBuffer(dstSize);
@@ -588,6 +593,12 @@ bool SkBlurMask::BoxBlur(SkMask* dst, const SkMask& src,
// now we allocate the "real" dst, mirror the size of src
size_t srcSize = src.computeImageSize();
if (0 == srcSize) {
+ if (dm) {
+ dm->unlock();
+ SkDELETE(dm);
+ } else if (dp) {
+ SkMask::FreeImage(dp);
+ }
return false; // too big to allocate, abort
}
dst->fImage = SkMask::AllocImage(srcSize);
@@ -595,12 +606,16 @@ bool SkBlurMask::BoxBlur(SkMask* dst, const SkMask& src,
sp, src.fRowBytes,
dp + passCount * (rx + ry * dst->fRowBytes),
dst->fRowBytes, sw, sh);
- SkMask::FreeImage(dp);
+ if (dm) {
+ dm->unlock();
+ SkDELETE(dm);
+ } else if (dp) {
+ 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) {

Powered by Google App Engine
This is Rietveld 408576698