diff options
author | qiankun.miao <qiankun.miao@intel.com> | 2015-01-07 19:20:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-07 19:20:49 -0800 |
commit | eabd0d73eebb940ec5ea06625f612a80156b61db (patch) | |
tree | eccab3cb3ab4aea0a1a5d9ee191e6f073fcbcaed /src | |
parent | 5a5b4e900ee69540fc35952882a323c63d6d0db9 (diff) |
Revert of Cache blur mask for rects which can not break into nine-patch (patchset #10 id:200001 of https://codereview.chromium.org/729463002/)
Reason for revert:
revert it due to a memory leak.
==8017==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 25992 byte(s) in 2 object(s) allocated from:
#0 0x7feb53030e0b in __interceptor_malloc
(/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/gm+0x24fe0b)
#1 0x7feb54d54f76 in sk_malloc_flags(unsigned long, unsigned int)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/ports/SkMemory_malloc.cpp:54:15
#2 0x7feb54d54d4a in sk_malloc_throw(unsigned long)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/ports/SkMemory_malloc.cpp:40:12
#3 0x7feb539f5a77 in SkMask::AllocImage(unsigned long)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkMask.cpp:37:22
#4 0x7feb53fe5c34 in (anonymous
namespace)::copy_cacheddata_to_mask(SkCachedData*, SkMask*)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkMaskCache.cpp:25:20
#5 0x7feb53fea064 in SkMaskCache::FindAndCopy(float, SkBlurStyle,
SkBlurQuality, SkRect const*, int, SkMask*)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkMaskCache.cpp:224:26
#6 0x7feb539f957e in SkMaskFilter::filterPath(SkPath const&, SkMatrix
const&, SkRasterClip const&, SkBlitter*, SkPaint::Style) const
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkMaskFilter.cpp:270:14
#7 0x7feb5392e920 in SkDraw::drawPath(SkPath const&, SkPaint const&,
SkMatrix const*, bool, bool, SkBlitter*) const
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkDraw.cpp:1117:13
#8 0x7feb53694afc in SkDraw::drawPath(SkPath const&, SkPaint const&,
SkMatrix const*, bool) const
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../include/core/SkDraw.h:54:9
#9 0x7feb5368d799 in SkBitmapDevice::drawPath(SkDraw const&, SkPath const&,
SkPaint const&, SkMatrix const*, bool)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkBitmapDevice.cpp:216:5
#10 0x7feb5386aa57 in SkCanvas::onDrawPath(SkPath const&, SkPaint const&)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkCanvas.cpp:1908:9
#11 0x7feb5386386b in SkCanvas::drawPath(SkPath const&, SkPaint const&)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../src/core/SkCanvas.cpp:1703:5
#12 0x7feb53109572 in Blur2RectsNonNinePatchGM::onDraw(SkCanvas*)
/home/default/storage/skia-repo/buildbot/skiabot-linux-xsan-000/build/slave/Test-Ubuntu13_10-GCE-NoGPU-x86_64-Debug-ASAN/build/skia/out/Debug/../../gm/blurs.cpp:166:9
Original issue's description:
> Cache blur mask for rects which can not break into nine-patch
>
> With this CL performance improves:
> blurrectsnonninepatch 42.4us -> 20.5us 0.48x
>
> BUG=431021,skia:3118
>
> Committed: https://skia.googlesource.com/skia/+/5a5b4e900ee69540fc35952882a323c63d6d0db9
TBR=reed@google.com,humper@google.com,reed@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=431021,skia:3118
Review URL: https://codereview.chromium.org/844673002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkMaskCache.cpp | 50 | ||||
-rw-r--r-- | src/core/SkMaskCache.h | 19 | ||||
-rw-r--r-- | src/core/SkMaskFilter.cpp | 37 | ||||
-rw-r--r-- | src/effects/SkBlurMaskFilter.cpp | 62 |
4 files changed, 58 insertions, 110 deletions
diff --git a/src/core/SkMaskCache.cpp b/src/core/SkMaskCache.cpp index 207ea0e77d..b4b8b4faf3 100644 --- a/src/core/SkMaskCache.cpp +++ b/src/core/SkMaskCache.cpp @@ -18,28 +18,6 @@ struct MaskValue { namespace { static unsigned gRRectBlurKeyNamespaceLabel; -static bool copy_cacheddata_to_mask(SkCachedData* data, SkMask* mask) { - const size_t size = data->size(); - SkASSERT(mask->computeTotalImageSize() <= size); - - mask->fImage = SkMask::AllocImage(size); - if (mask->fImage) { - memcpy(mask->fImage, data->data(), size); - return true; - } - return false; -} - -static SkCachedData* copy_mask_to_cacheddata(const SkMask& mask) { - const size_t size = mask.computeTotalImageSize(); - SkCachedData* data = SkResourceCache::NewCachedData(size); - if (data) { - memcpy(data->writable_data(), mask.fImage, size); - return data; - } - return NULL; -} - struct RRectBlurKey : public SkResourceCache::Key { public: RRectBlurKey(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, SkBlurQuality quality) @@ -112,20 +90,6 @@ void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RRectBlurRec, (key, mask, data))); } -bool SkMaskCache::FindAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRRect& rrect, SkMask* mask) { - SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, quality, rrect, mask)); - return data.get() && copy_cacheddata_to_mask(data, mask); -} - -void SkMaskCache::AddAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRRect& rrect, const SkMask& mask) { - SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask)); - if (data.get()) { - SkMaskCache::Add(sigma, style, quality, rrect, mask, data); - } -} - ////////////////////////////////////////////////////////////////////////////////////////// namespace { @@ -217,17 +181,3 @@ void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, RectsBlurKey key(sigma, style, quality, rects, count); return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RectsBlurRec, (key, mask, data))); } - -bool SkMaskCache::FindAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRect rects[], int count, SkMask* mask) { - SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, quality, rects, count, mask)); - return data.get() && copy_cacheddata_to_mask(data, mask); -} - -void SkMaskCache::AddAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRect rects[], int count, const SkMask& mask) { - SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask)); - if (data.get()) { - SkMaskCache::Add(sigma, style, quality, rects, count, mask, data); - } -} diff --git a/src/core/SkMaskCache.h b/src/core/SkMaskCache.h index 2cfb971dde..f98387b206 100644 --- a/src/core/SkMaskCache.h +++ b/src/core/SkMaskCache.h @@ -39,25 +39,6 @@ public: static void Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, const SkRect rects[], int count, const SkMask& mask, SkCachedData* data, SkResourceCache* localCache = NULL); - - /** - * On success, set mask with cached value, allocate memory for mask->fImage, - * copy pixels from SkCachedData in the cache to mask->fImage, then return true. - * - * On failure, return false, no memory allocated for mask->fImage. - */ - static bool FindAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRRect& rrect, SkMask* mask); - static bool FindAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRect rects[], int count, SkMask* mask); - - /** - * Create a new SkCachedData, copy pixels from mask.fImage to it, then add it into cache. - */ - static void AddAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRRect& rrect, const SkMask& mask); - static void AddAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, - const SkRect rects[], int count, const SkMask& mask); }; #endif diff --git a/src/core/SkMaskFilter.cpp b/src/core/SkMaskFilter.cpp index 3a4e3a41e9..c9783e76d6 100644 --- a/src/core/SkMaskFilter.cpp +++ b/src/core/SkMaskFilter.cpp @@ -10,7 +10,6 @@ #include "SkMaskFilter.h" #include "SkBlitter.h" #include "SkDraw.h" -#include "SkMaskCache.h" #include "SkRasterClip.h" #include "SkRRect.h" #include "SkTypes.h" @@ -264,41 +263,9 @@ bool SkMaskFilter::filterPath(const SkPath& devPath, const SkMatrix& matrix, } SkAutoMaskFreeImage autoSrc(srcM.fImage); - BlurRec rec; - if (this->asABlur(&rec) && rectCount) { - SkScalar scaledSigma = matrix.mapRadius(rec.fSigma); - if (!SkMaskCache::FindAndCopy(scaledSigma, rec.fStyle, rec.fQuality, - rects, rectCount, &dstM)) { - if (!this->filterMask(&dstM, srcM, matrix, NULL)) { - return false; - } - SkMaskCache::AddAndCopy(scaledSigma, rec.fStyle, rec.fQuality, rects, rectCount, dstM); - } else { - // Compute the correct bounds of dst mask if dst mask is got from cache. - SkMask tmpSrc, tmpDst; - tmpSrc = srcM; - tmpSrc.fImage = NULL; - if (!this->filterMask(&tmpDst, tmpSrc, matrix, NULL)) { - return false; - } - - // Fallback to original calculation if size of bounds is different with - // size of the cached mask. - if (dstM.fBounds.width() != tmpDst.fBounds.width() || - dstM.fBounds.height() != tmpDst.fBounds.height()) { - if (!this->filterMask(&dstM, srcM, matrix, NULL)) { - return false; - } - } else { - dstM.fBounds = tmpDst.fBounds; - } - } - } else { - if (!this->filterMask(&dstM, srcM, matrix, NULL)) { - return false; - } + if (!this->filterMask(&dstM, srcM, matrix, NULL)) { + return false; } - SkAutoMaskFreeImage autoDst(dstM.fImage); // if we get here, we need to (possibly) resolve the clip and blitter diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index 38b2acca9e..97ae436367 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -11,7 +11,6 @@ #include "SkGpuBlurUtils.h" #include "SkReadBuffer.h" #include "SkWriteBuffer.h" -#include "SkMaskCache.h" #include "SkMaskFilter.h" #include "SkRRect.h" #include "SkRTConf.h" @@ -261,6 +260,58 @@ static bool rect_exceeds(const SkRect& r, SkScalar v) { r.width() > v || r.height() > v; } +#include "SkMaskCache.h" + +static bool copy_cacheddata_to_mask(SkCachedData* data, SkMask* mask) { + const size_t size = data->size(); + SkASSERT(mask->computeTotalImageSize() <= size); + + mask->fImage = SkMask::AllocImage(size); + if (mask->fImage) { + memcpy(mask->fImage, data->data(), size); + return true; + } + return false; +} + +static SkCachedData* copy_mask_to_cacheddata(const SkMask& mask) { + const size_t size = mask.computeTotalImageSize(); + SkCachedData* data = SkResourceCache::NewCachedData(size); + if (data) { + memcpy(data->writable_data(), mask.fImage, size); + return data; + } + return NULL; +} + +static bool find_cached_rrect(SkMask* mask, SkScalar sigma, SkBlurStyle style, + SkBlurQuality quality, const SkRRect& rrect) { + SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, quality, rrect, mask)); + return data.get() && copy_cacheddata_to_mask(data, mask); +} + +static void add_cached_rrect(const SkMask& mask, SkScalar sigma, SkBlurStyle style, + SkBlurQuality quality, const SkRRect& rrect) { + SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask)); + if (data.get()) { + SkMaskCache::Add(sigma, style, quality, rrect, mask, data); + } +} + +static bool find_cached_rects(SkMask* mask, SkScalar sigma, SkBlurStyle style, + SkBlurQuality quality, const SkRect rects[], int count) { + SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, quality, rects, count, mask)); + return data.get() && copy_cacheddata_to_mask(data, mask); +} + +static void add_cached_rects(const SkMask& mask, SkScalar sigma, SkBlurStyle style, + SkBlurQuality quality, const SkRect rects[], int count) { + SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask)); + if (data.get()) { + SkMaskCache::Add(sigma, style, quality, rects, count, mask, data); + } +} + #ifdef SK_IGNORE_FAST_RRECT_BLUR SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect", false, "Use the faster analytic blur approach for ninepatch rects" ); #else @@ -369,7 +420,7 @@ SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma smallRR.setRectRadii(smallR, radii); const SkScalar sigma = this->computeXformedSigma(matrix); - if (!SkMaskCache::FindAndCopy(sigma, fBlurStyle, this->getQuality(), smallRR, &patch->fMask)) { + if (!find_cached_rrect(&patch->fMask, sigma, fBlurStyle, this->getQuality(), smallRR)) { bool analyticBlurWorked = false; if (c_analyticBlurRRect) { analyticBlurWorked = @@ -388,7 +439,7 @@ SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma return kFalse_FilterReturn; } } - SkMaskCache::AddAndCopy(sigma, fBlurStyle, this->getQuality(), smallRR, patch->fMask); + add_cached_rrect(patch->fMask, sigma, fBlurStyle, this->getQuality(), smallRR); } patch->fMask.fBounds.offsetTo(0, 0); @@ -499,8 +550,7 @@ SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count, } const SkScalar sigma = this->computeXformedSigma(matrix); - if (!SkMaskCache::FindAndCopy(sigma, fBlurStyle, this->getQuality(), - smallR, count, &patch->fMask)) { + if (!find_cached_rects(&patch->fMask, sigma, fBlurStyle, this->getQuality(), smallR, count)) { if (count > 1 || !c_analyticBlurNinepatch) { if (!draw_rects_into_mask(smallR, count, &srcM)) { return kFalse_FilterReturn; @@ -517,7 +567,7 @@ SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count, return kFalse_FilterReturn; } } - SkMaskCache::AddAndCopy(sigma, fBlurStyle, this->getQuality(), smallR, count, patch->fMask); + add_cached_rects(patch->fMask, sigma, fBlurStyle, this->getQuality(), smallR, count); } patch->fMask.fBounds.offsetTo(0, 0); patch->fOuterRect = dstM.fBounds; |