Fix SkImageFilterCache race
BUG=chromium:668937
R=reed@google.com,robertphillips@google.com
Change-Id: I72ceaf1d88946c277a38f32014640e01ae9cbded
Reviewed-on: https://skia-review.googlesource.com/6954
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 8ce5e8e..40a7a22 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -207,9 +207,9 @@
const SkIRect srcSubset = fUsesSrcInput ? src->subset() : SkIRect::MakeWH(0, 0);
SkImageFilterCacheKey key(fUniqueID, context.ctm(), context.clipBounds(), srcGenID, srcSubset);
if (context.cache()) {
- SkSpecialImage* result = context.cache()->get(key, offset);
+ sk_sp<SkSpecialImage> result = context.cache()->get(key, offset);
if (result) {
- return sk_sp<SkSpecialImage>(SkRef(result));
+ return result;
}
}
diff --git a/src/core/SkImageFilterCache.cpp b/src/core/SkImageFilterCache.cpp
index 889e81f..0d9e367 100644
--- a/src/core/SkImageFilterCache.cpp
+++ b/src/core/SkImageFilterCache.cpp
@@ -52,7 +52,7 @@
SK_DECLARE_INTERNAL_LLIST_INTERFACE(Value);
};
- SkSpecialImage* get(const Key& key, SkIPoint* offset) const override {
+ sk_sp<SkSpecialImage> get(const Key& key, SkIPoint* offset) const override {
SkAutoMutexAcquire mutex(fMutex);
if (Value* v = fLookup.find(key)) {
*offset = v->fOffset;
@@ -60,7 +60,7 @@
fLRU.remove(v);
fLRU.addToHead(v);
}
- return v->fImage.get();
+ return v->fImage;
}
return nullptr;
}
diff --git a/src/core/SkImageFilterCache.h b/src/core/SkImageFilterCache.h
index a65357f..8f0d9f1 100644
--- a/src/core/SkImageFilterCache.h
+++ b/src/core/SkImageFilterCache.h
@@ -53,7 +53,7 @@
virtual ~SkImageFilterCache() {}
static SkImageFilterCache* Create(size_t maxBytes);
static SkImageFilterCache* Get();
- virtual SkSpecialImage* get(const SkImageFilterCacheKey& key, SkIPoint* offset) const = 0;
+ virtual sk_sp<SkSpecialImage> get(const SkImageFilterCacheKey& key, SkIPoint* offset) const = 0;
virtual void set(const SkImageFilterCacheKey& key, SkSpecialImage* image,
const SkIPoint& offset) = 0;
virtual void purge() = 0;
diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp
index e0aceda..650d4cb 100644
--- a/tests/ImageFilterCacheTest.cpp
+++ b/tests/ImageFilterCacheTest.cpp
@@ -41,7 +41,7 @@
SkIPoint foundOffset;
- SkSpecialImage* foundImage = cache->get(key1, &foundOffset);
+ sk_sp<SkSpecialImage> foundImage = cache->get(key1, &foundOffset);
REPORTER_ASSERT(reporter, foundImage);
REPORTER_ASSERT(reporter, offset == foundOffset);