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

Unified Diff: src/core/SkMaskCache.cpp

Issue 729463002: Cache blur mask for rects which can not break into nine-patch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: handle clipped path Created 5 years, 11 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
« no previous file with comments | « src/core/SkMaskCache.h ('k') | src/core/SkMaskFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkMaskCache.cpp
diff --git a/src/core/SkMaskCache.cpp b/src/core/SkMaskCache.cpp
index b4b8b4faf359e18957c6a3b2998ee0c8bb39bb36..207ea0e77d330ebc0da8fb5f321a8af8a905b00d 100644
--- a/src/core/SkMaskCache.cpp
+++ b/src/core/SkMaskCache.cpp
@@ -18,6 +18,28 @@ 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)
@@ -90,6 +112,20 @@ 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 {
@@ -181,3 +217,17 @@ 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);
+ }
+}
« no previous file with comments | « src/core/SkMaskCache.h ('k') | src/core/SkMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698