aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar senorblanco <senorblanco@chromium.org>2016-04-27 11:31:23 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-27 11:31:23 -0700
commit900c36779610dc65c42a5004ee3693fd70961ba4 (patch)
tree603f3ab0fd1a59077c851a93148ee15064813073
parentf8e8d5ee432448a4ca5b6f22aabd148a6708d0c0 (diff)
Image filters: de-nest SkImageFilter::Cache and Cache::Key.
This reduces the public header, and also allows us to foward- declare them, so we can remove an #include from all the SkDevice subclass headers. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1919063002 Review-Url: https://codereview.chromium.org/1919063002
-rw-r--r--gyp/core.gypi3
-rw-r--r--include/core/SkBitmapDevice.h4
-rw-r--r--include/core/SkDevice.h4
-rw-r--r--include/core/SkImageFilter.h29
-rw-r--r--src/core/SkBitmapDevice.cpp5
-rw-r--r--src/core/SkCanvas.cpp2
-rw-r--r--src/core/SkDevice.cpp4
-rw-r--r--src/core/SkImageFilter.cpp127
-rw-r--r--src/core/SkImageFilterCache.cpp131
-rw-r--r--src/core/SkImageFilterCache.h62
-rw-r--r--src/core/SkImageFilterCacheKey.h41
-rw-r--r--src/gpu/GrLayerHoister.cpp3
-rw-r--r--src/gpu/SkGpuDevice.cpp5
-rw-r--r--src/gpu/SkGpuDevice.h2
-rw-r--r--src/svg/SkSVGDevice.h1
-rw-r--r--tests/ImageFilterCacheTest.cpp32
16 files changed, 242 insertions, 213 deletions
diff --git a/gyp/core.gypi b/gyp/core.gypi
index 66c9541a10..c2dd432535 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -146,7 +146,8 @@
'<(skia_src_path)/core/SkHalf.cpp',
'<(skia_src_path)/core/SkHalf.h',
'<(skia_src_path)/core/SkImageFilter.cpp',
- '<(skia_src_path)/core/SkImageFilterCacheKey.h',
+ '<(skia_src_path)/core/SkImageFilterCache.cpp',
+ '<(skia_src_path)/core/SkImageFilterCache.h',
'<(skia_src_path)/core/SkImageInfo.cpp',
'<(skia_src_path)/core/SkImageCacherator.h',
'<(skia_src_path)/core/SkImageCacherator.cpp',
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h
index b53bfd0622..f8cc5bec7a 100644
--- a/include/core/SkBitmapDevice.h
+++ b/include/core/SkBitmapDevice.h
@@ -13,7 +13,6 @@
#include "SkCanvas.h"
#include "SkColor.h"
#include "SkDevice.h"
-#include "SkImageFilter.h"
#include "SkImageInfo.h"
#include "SkRect.h"
#include "SkScalar.h"
@@ -22,6 +21,7 @@
#include "SkTypes.h"
class SkDraw;
+class SkImageFilterCache;
class SkMatrix;
class SkPaint;
class SkPath;
@@ -162,7 +162,7 @@ private:
sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override;
- SkImageFilter::Cache* getImageFilterCache() override;
+ SkImageFilterCache* getImageFilterCache() override;
SkBitmap fBitmap;
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 5301d1e3ff..73c35c3341 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -11,13 +11,13 @@
#include "SkRefCnt.h"
#include "SkCanvas.h"
#include "SkColor.h"
-#include "SkImageFilter.h"
#include "SkSurfaceProps.h"
class SkBitmap;
class SkClipStack;
class SkDraw;
class SkDrawFilter;
+class SkImageFilterCache;
struct SkIRect;
class SkMatrix;
class SkMetaData;
@@ -394,7 +394,7 @@ private:
*/
virtual void flush() {}
- virtual SkImageFilter::Cache* getImageFilterCache() { return NULL; }
+ virtual SkImageFilterCache* getImageFilterCache() { return NULL; }
SkIPoint fOrigin;
SkMetaData* fMetaData;
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 32a52d97fd..aa9648eb3c 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -21,6 +21,8 @@ class GrFragmentProcessor;
class SkColorFilter;
struct SkIPoint;
class SkSpecialImage;
+class SkImageFilterCache;
+struct SkImageFilterCacheKey;
/**
* Base class for image filters. If one is installed in the paint, then
@@ -31,24 +33,9 @@ class SkSpecialImage;
*/
class SK_API SkImageFilter : public SkFlattenable {
public:
- // This cache maps from (filter's unique ID + CTM + clipBounds + src bitmap generation ID) to
- // (result, offset).
- class Cache : public SkRefCnt {
- public:
- struct Key;
- virtual ~Cache() {}
- static Cache* Create(size_t maxBytes);
- static Cache* Get();
- virtual SkSpecialImage* get(const Key& key, SkIPoint* offset) const = 0;
- virtual void set(const Key& key, SkSpecialImage* image, const SkIPoint& offset) = 0;
- virtual void purge() = 0;
- virtual void purgeByKeys(const Key[], int) = 0;
- SkDEBUGCODE(virtual int count() const = 0;)
- };
-
class Context {
public:
- Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache)
+ Context(const SkMatrix& ctm, const SkIRect& clipBounds, SkImageFilterCache* cache)
: fCTM(ctm)
, fClipBounds(clipBounds)
, fCache(cache)
@@ -56,12 +43,12 @@ public:
const SkMatrix& ctm() const { return fCTM; }
const SkIRect& clipBounds() const { return fClipBounds; }
- Cache* cache() const { return fCache; }
+ SkImageFilterCache* cache() const { return fCache; }
private:
- SkMatrix fCTM;
- SkIRect fClipBounds;
- Cache* fCache;
+ SkMatrix fCTM;
+ SkIRect fClipBounds;
+ SkImageFilterCache* fCache;
};
class CropRect {
@@ -399,7 +386,7 @@ private:
bool fUsesSrcInput;
CropRect fCropRect;
uint32_t fUniqueID; // Globally unique
- mutable SkTArray<Cache::Key> fCacheKeys;
+ mutable SkTArray<SkImageFilterCacheKey> fCacheKeys;
mutable SkMutex fMutex;
typedef SkFlattenable INHERITED;
};
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 8a517a6f00..119a434cc9 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -8,6 +8,7 @@
#include "SkBitmapDevice.h"
#include "SkConfig8888.h"
#include "SkDraw.h"
+#include "SkImageFilterCache.h"
#include "SkMallocPixelRef.h"
#include "SkMatrix.h"
#include "SkPaint.h"
@@ -367,8 +368,8 @@ sk_sp<SkSurface> SkBitmapDevice::makeSurface(const SkImageInfo& info, const SkSu
return SkSurface::MakeRaster(info, &props);
}
-SkImageFilter::Cache* SkBitmapDevice::getImageFilterCache() {
- SkImageFilter::Cache* cache = SkImageFilter::Cache::Get();
+SkImageFilterCache* SkBitmapDevice::getImageFilterCache() {
+ SkImageFilterCache* cache = SkImageFilterCache::Get();
cache->ref();
return cache;
}
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 6c4cd27250..c7a9dc72f2 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -17,6 +17,8 @@
#include "SkErrorInternals.h"
#include "SkImage.h"
#include "SkImage_Base.h"
+#include "SkImageFilter.h"
+#include "SkImageFilterCache.h"
#include "SkMatrixUtils.h"
#include "SkMetaData.h"
#include "SkNinePatchIter.h"
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 70f4e07431..185b9bbd27 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -10,6 +10,8 @@
#include "SkDraw.h"
#include "SkDrawFilter.h"
#include "SkImage_Base.h"
+#include "SkImageFilter.h"
+#include "SkImageFilterCache.h"
#include "SkMetaData.h"
#include "SkNinePatchIter.h"
#include "SkPatchUtils.h"
@@ -413,7 +415,7 @@ void SkBaseDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitm
SkMatrix matrix = *draw.fMatrix;
matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y);
- SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache());
+ SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
sk_sp<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(bitmap, &this->surfaceProps()));
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 935ce77d5f..ed6d14ac14 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -6,20 +6,16 @@
*/
#include "SkImageFilter.h"
-#include "SkImageFilterCacheKey.h"
#include "SkCanvas.h"
-#include "SkChecksum.h"
#include "SkFuzzLogging.h"
+#include "SkImageFilterCache.h"
#include "SkLocalMatrixImageFilter.h"
#include "SkMatrixImageFilter.h"
-#include "SkOncePtr.h"
#include "SkReadBuffer.h"
#include "SkRect.h"
#include "SkSpecialImage.h"
#include "SkSpecialSurface.h"
-#include "SkTDynamicHash.h"
-#include "SkTInternalLList.h"
#include "SkValidationUtils.h"
#include "SkWriteBuffer.h"
#if SK_SUPPORT_GPU
@@ -27,12 +23,6 @@
#include "GrDrawContext.h"
#endif
-#ifdef SK_BUILD_FOR_IOS
- enum { kDefaultCacheSize = 2 * 1024 * 1024 };
-#else
- enum { kDefaultCacheSize = 128 * 1024 * 1024 };
-#endif
-
#ifndef SK_IGNORE_TO_STRING
void SkImageFilter::CropRect::toString(SkString* str) const {
if (!fFlags) {
@@ -179,7 +169,7 @@ SkImageFilter::SkImageFilter(sk_sp<SkImageFilter>* inputs,
}
SkImageFilter::~SkImageFilter() {
- Cache::Get()->purgeByKeys(fCacheKeys.begin(), fCacheKeys.count());
+ SkImageFilterCache::Get()->purgeByKeys(fCacheKeys.begin(), fCacheKeys.count());
}
SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer)
@@ -211,7 +201,7 @@ sk_sp<SkSpecialImage> SkImageFilter::filterImage(SkSpecialImage* src, const Cont
uint32_t srcGenID = fUsesSrcInput ? src->uniqueID() : 0;
const SkIRect srcSubset = fUsesSrcInput ? src->subset() : SkIRect::MakeWH(0, 0);
- Cache::Key key(fUniqueID, context.ctm(), context.clipBounds(), srcGenID, srcSubset);
+ SkImageFilterCacheKey key(fUniqueID, context.ctm(), context.clipBounds(), srcGenID, srcSubset);
if (context.cache()) {
SkSpecialImage* result = context.cache()->get(key, offset);
if (result) {
@@ -462,115 +452,6 @@ sk_sp<SkSpecialImage> SkImageFilter::filterInput(int index,
return result;
}
-namespace {
-
-class CacheImpl : public SkImageFilter::Cache {
-public:
- CacheImpl(size_t maxBytes) : fMaxBytes(maxBytes), fCurrentBytes(0) { }
- ~CacheImpl() override {
- SkTDynamicHash<Value, Key>::Iter iter(&fLookup);
-
- while (!iter.done()) {
- Value* v = &*iter;
- ++iter;
- delete v;
- }
- }
- struct Value {
- Value(const Key& key, SkSpecialImage* image, const SkIPoint& offset)
- : fKey(key), fImage(SkRef(image)), fOffset(offset) {}
-
- Key fKey;
- SkAutoTUnref<SkSpecialImage> fImage;
- SkIPoint fOffset;
- static const Key& GetKey(const Value& v) {
- return v.fKey;
- }
- static uint32_t Hash(const Key& key) {
- return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
- }
- SK_DECLARE_INTERNAL_LLIST_INTERFACE(Value);
- };
-
- SkSpecialImage* get(const Key& key, SkIPoint* offset) const override {
- SkAutoMutexAcquire mutex(fMutex);
- if (Value* v = fLookup.find(key)) {
- *offset = v->fOffset;
- if (v != fLRU.head()) {
- fLRU.remove(v);
- fLRU.addToHead(v);
- }
- return v->fImage;
- }
- return nullptr;
- }
-
- void set(const Key& key, SkSpecialImage* image, const SkIPoint& offset) override {
- SkAutoMutexAcquire mutex(fMutex);
- if (Value* v = fLookup.find(key)) {
- this->removeInternal(v);
- }
- Value* v = new Value(key, image, offset);
- fLookup.add(v);
- fLRU.addToHead(v);
- fCurrentBytes += image->getSize();
- while (fCurrentBytes > fMaxBytes) {
- Value* tail = fLRU.tail();
- SkASSERT(tail);
- if (tail == v) {
- break;
- }
- this->removeInternal(tail);
- }
- }
-
- void purge() override {
- SkAutoMutexAcquire mutex(fMutex);
- while (fCurrentBytes > 0) {
- Value* tail = fLRU.tail();
- SkASSERT(tail);
- this->removeInternal(tail);
- }
- }
-
- void purgeByKeys(const Key keys[], int count) override {
- SkAutoMutexAcquire mutex(fMutex);
- for (int i = 0; i < count; i++) {
- if (Value* v = fLookup.find(keys[i])) {
- this->removeInternal(v);
- }
- }
- }
-
- SkDEBUGCODE(int count() const override { return fLookup.count(); })
-private:
- void removeInternal(Value* v) {
- SkASSERT(v->fImage);
- fCurrentBytes -= v->fImage->getSize();
- fLRU.remove(v);
- fLookup.remove(v->fKey);
- delete v;
- }
-private:
- SkTDynamicHash<Value, Key> fLookup;
- mutable SkTInternalLList<Value> fLRU;
- size_t fMaxBytes;
- size_t fCurrentBytes;
- mutable SkMutex fMutex;
-};
-
-} // namespace
-
-SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) {
- return new CacheImpl(maxBytes);
-}
-
-SK_DECLARE_STATIC_ONCE_PTR(SkImageFilter::Cache, cache);
-SkImageFilter::Cache* SkImageFilter::Cache::Get() {
- return cache.get([]{ return SkImageFilter::Cache::Create(kDefaultCacheSize); });
-}
-
void SkImageFilter::PurgeCache() {
- Cache::Get()->purge();
+ SkImageFilterCache::Get()->purge();
}
-
diff --git a/src/core/SkImageFilterCache.cpp b/src/core/SkImageFilterCache.cpp
new file mode 100644
index 0000000000..d87cf6b7c3
--- /dev/null
+++ b/src/core/SkImageFilterCache.cpp
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkImageFilterCache.h"
+
+#include "SkChecksum.h"
+#include "SkMutex.h"
+#include "SkOncePtr.h"
+#include "SkRefCnt.h"
+#include "SkSpecialImage.h"
+#include "SkTDynamicHash.h"
+#include "SkTInternalLList.h"
+
+#ifdef SK_BUILD_FOR_IOS
+ enum { kDefaultCacheSize = 2 * 1024 * 1024 };
+#else
+ enum { kDefaultCacheSize = 128 * 1024 * 1024 };
+#endif
+
+namespace {
+
+class CacheImpl : public SkImageFilterCache {
+public:
+ typedef SkImageFilterCacheKey Key;
+ CacheImpl(size_t maxBytes) : fMaxBytes(maxBytes), fCurrentBytes(0) { }
+ ~CacheImpl() override {
+ SkTDynamicHash<Value, Key>::Iter iter(&fLookup);
+
+ while (!iter.done()) {
+ Value* v = &*iter;
+ ++iter;
+ delete v;
+ }
+ }
+ struct Value {
+ Value(const Key& key, SkSpecialImage* image, const SkIPoint& offset)
+ : fKey(key), fImage(SkRef(image)), fOffset(offset) {}
+
+ Key fKey;
+ SkAutoTUnref<SkSpecialImage> fImage;
+ SkIPoint fOffset;
+ static const Key& GetKey(const Value& v) {
+ return v.fKey;
+ }
+ static uint32_t Hash(const Key& key) {
+ return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
+ }
+ SK_DECLARE_INTERNAL_LLIST_INTERFACE(Value);
+ };
+
+ SkSpecialImage* get(const Key& key, SkIPoint* offset) const override {
+ SkAutoMutexAcquire mutex(fMutex);
+ if (Value* v = fLookup.find(key)) {
+ *offset = v->fOffset;
+ if (v != fLRU.head()) {
+ fLRU.remove(v);
+ fLRU.addToHead(v);
+ }
+ return v->fImage;
+ }
+ return nullptr;
+ }
+
+ void set(const Key& key, SkSpecialImage* image, const SkIPoint& offset) override {
+ SkAutoMutexAcquire mutex(fMutex);
+ if (Value* v = fLookup.find(key)) {
+ this->removeInternal(v);
+ }
+ Value* v = new Value(key, image, offset);
+ fLookup.add(v);
+ fLRU.addToHead(v);
+ fCurrentBytes += image->getSize();
+ while (fCurrentBytes > fMaxBytes) {
+ Value* tail = fLRU.tail();
+ SkASSERT(tail);
+ if (tail == v) {
+ break;
+ }
+ this->removeInternal(tail);
+ }
+ }
+
+ void purge() override {
+ SkAutoMutexAcquire mutex(fMutex);
+ while (fCurrentBytes > 0) {
+ Value* tail = fLRU.tail();
+ SkASSERT(tail);
+ this->removeInternal(tail);
+ }
+ }
+
+ void purgeByKeys(const Key keys[], int count) override {
+ SkAutoMutexAcquire mutex(fMutex);
+ for (int i = 0; i < count; i++) {
+ if (Value* v = fLookup.find(keys[i])) {
+ this->removeInternal(v);
+ }
+ }
+ }
+
+ SkDEBUGCODE(int count() const override { return fLookup.count(); })
+private:
+ void removeInternal(Value* v) {
+ SkASSERT(v->fImage);
+ fCurrentBytes -= v->fImage->getSize();
+ fLRU.remove(v);
+ fLookup.remove(v->fKey);
+ delete v;
+ }
+private:
+ SkTDynamicHash<Value, Key> fLookup;
+ mutable SkTInternalLList<Value> fLRU;
+ size_t fMaxBytes;
+ size_t fCurrentBytes;
+ mutable SkMutex fMutex;
+};
+
+} // namespace
+
+SkImageFilterCache* SkImageFilterCache::Create(size_t maxBytes) {
+ return new CacheImpl(maxBytes);
+}
+
+SK_DECLARE_STATIC_ONCE_PTR(SkImageFilterCache, cache);
+SkImageFilterCache* SkImageFilterCache::Get() {
+ return cache.get([]{ return SkImageFilterCache::Create(kDefaultCacheSize); });
+}
diff --git a/src/core/SkImageFilterCache.h b/src/core/SkImageFilterCache.h
new file mode 100644
index 0000000000..25079e194f
--- /dev/null
+++ b/src/core/SkImageFilterCache.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkImageFilterCache_DEFINED
+#define SkImageFilterCache_DEFINED
+
+#include "SkMatrix.h"
+#include "SkRefCnt.h"
+
+struct SkIPoint;
+class SkSpecialImage;
+
+struct SkImageFilterCacheKey {
+ SkImageFilterCacheKey(const uint32_t uniqueID, const SkMatrix& matrix,
+ const SkIRect& clipBounds, uint32_t srcGenID, const SkIRect& srcSubset)
+ : fUniqueID(uniqueID)
+ , fMatrix(matrix)
+ , fClipBounds(clipBounds)
+ , fSrcGenID(srcGenID)
+ , fSrcSubset(srcSubset) {
+ // Assert that Key is tightly-packed, since it is hashed.
+ static_assert(sizeof(SkImageFilterCacheKey) == sizeof(uint32_t) + sizeof(SkMatrix) +
+ sizeof(SkIRect) + sizeof(uint32_t) + 4 * sizeof(int32_t),
+ "image_filter_key_tight_packing");
+ fMatrix.getType(); // force initialization of type, so hashes match
+ }
+
+ uint32_t fUniqueID;
+ SkMatrix fMatrix;
+ SkIRect fClipBounds;
+ uint32_t fSrcGenID;
+ SkIRect fSrcSubset;
+
+ bool operator==(const SkImageFilterCacheKey& other) const {
+ return fUniqueID == other.fUniqueID &&
+ fMatrix == other.fMatrix &&
+ fClipBounds == other.fClipBounds &&
+ fSrcGenID == other.fSrcGenID &&
+ fSrcSubset == other.fSrcSubset;
+ }
+};
+
+// This cache maps from (filter's unique ID + CTM + clipBounds + src bitmap generation ID) to
+// (result, offset).
+class SkImageFilterCache : public SkRefCnt {
+public:
+ virtual ~SkImageFilterCache() {}
+ static SkImageFilterCache* Create(size_t maxBytes);
+ static SkImageFilterCache* Get();
+ virtual 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;
+ virtual void purgeByKeys(const SkImageFilterCacheKey[], int) = 0;
+ SkDEBUGCODE(virtual int count() const = 0;)
+};
+
+#endif
diff --git a/src/core/SkImageFilterCacheKey.h b/src/core/SkImageFilterCacheKey.h
deleted file mode 100644
index 3f5d1c8fa2..0000000000
--- a/src/core/SkImageFilterCacheKey.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkImageFilterCacheKey_DEFINED
-#define SkImageFilterCacheKey_DEFINED
-
-struct SkImageFilter::Cache::Key {
- Key(const uint32_t uniqueID, const SkMatrix& matrix,
- const SkIRect& clipBounds, uint32_t srcGenID, const SkIRect& srcSubset)
- : fUniqueID(uniqueID)
- , fMatrix(matrix)
- , fClipBounds(clipBounds)
- , fSrcGenID(srcGenID)
- , fSrcSubset(srcSubset) {
- // Assert that Key is tightly-packed, since it is hashed.
- static_assert(sizeof(Key) == sizeof(uint32_t) + sizeof(SkMatrix) + sizeof(SkIRect) +
- sizeof(uint32_t) + 4 * sizeof(int32_t),
- "image_filter_key_tight_packing");
- fMatrix.getType(); // force initialization of type, so hashes match
- }
-
- uint32_t fUniqueID;
- SkMatrix fMatrix;
- SkIRect fClipBounds;
- uint32_t fSrcGenID;
- SkIRect fSrcSubset;
-
- bool operator==(const Key& other) const {
- return fUniqueID == other.fUniqueID &&
- fMatrix == other.fMatrix &&
- fClipBounds == other.fClipBounds &&
- fSrcGenID == other.fSrcGenID &&
- fSrcSubset == other.fSrcSubset;
- }
-};
-
-#endif
diff --git a/src/gpu/GrLayerHoister.cpp b/src/gpu/GrLayerHoister.cpp
index a2d42e02a9..1c6e5738ba 100644
--- a/src/gpu/GrLayerHoister.cpp
+++ b/src/gpu/GrLayerHoister.cpp
@@ -12,6 +12,7 @@
#include "SkBigPicture.h"
#include "SkCanvas.h"
+#include "SkImageFilterCache.h"
#include "SkLayerInfo.h"
#include "SkRecordDraw.h"
#include "SkSpecialImage.h"
@@ -296,7 +297,7 @@ void GrLayerHoister::FilterLayer(GrContext* context,
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
- SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefaultCacheSize));
+ SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kDefaultCacheSize));
SkImageFilter::Context filterContext(totMat, clipBounds, cache);
// TODO: should the layer hoister store stand alone layers as SkSpecialImages internally?
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 3644da4b5a..78b3cfc7d0 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -26,6 +26,7 @@
#include "SkImage_Base.h"
#include "SkImageCacherator.h"
#include "SkImageFilter.h"
+#include "SkImageFilterCache.h"
#include "SkLayerInfo.h"
#include "SkMaskFilter.h"
#include "SkNinePatchIter.h"
@@ -1839,11 +1840,11 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
#endif
}
-SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
+SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
ASSERT_SINGLE_OWNER
// We always return a transient cache, so it is freed after each
// filter traversal.
- return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
+ return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
}
#endif
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index 1e8d301dc5..49bf13c438 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -169,7 +169,7 @@ private:
sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override;
- SkImageFilter::Cache* getImageFilterCache() override;
+ SkImageFilterCache* getImageFilterCache() override;
bool forceConservativeRasterClip() const override { return true; }
diff --git a/src/svg/SkSVGDevice.h b/src/svg/SkSVGDevice.h
index 8426ad5e10..3323471fb3 100644
--- a/src/svg/SkSVGDevice.h
+++ b/src/svg/SkSVGDevice.h
@@ -9,6 +9,7 @@
#define SkSVGDevice_DEFINED
#include "SkDevice.h"
+#include "SkTemplates.h"
class SkXMLWriter;
diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp
index 58d279c1c7..a7240dc417 100644
--- a/tests/ImageFilterCacheTest.cpp
+++ b/tests/ImageFilterCacheTest.cpp
@@ -10,7 +10,7 @@
#include "SkBitmap.h"
#include "SkImage.h"
#include "SkImageFilter.h"
-#include "SkImageFilterCacheKey.h"
+#include "SkImageFilterCache.h"
#include "SkMatrix.h"
#include "SkSpecialImage.h"
@@ -30,11 +30,11 @@ static void test_find_existing(skiatest::Reporter* reporter,
const sk_sp<SkSpecialImage>& image,
const sk_sp<SkSpecialImage>& subset) {
static const size_t kCacheSize = 1000000;
- SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
+ SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize));
SkIRect clip = SkIRect::MakeWH(100, 100);
- SkImageFilter::Cache::Key key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset());
- SkImageFilter::Cache::Key key2(0, SkMatrix::I(), clip, subset->uniqueID(), subset->subset());
+ SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset());
+ SkImageFilterCacheKey key2(0, SkMatrix::I(), clip, subset->uniqueID(), subset->subset());
SkIPoint offset = SkIPoint::Make(3, 4);
cache->set(key1, image.get(), offset);
@@ -54,16 +54,16 @@ static void test_dont_find_if_diff_key(skiatest::Reporter* reporter,
const sk_sp<SkSpecialImage>& image,
const sk_sp<SkSpecialImage>& subset) {
static const size_t kCacheSize = 1000000;
- SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
+ SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize));
SkIRect clip1 = SkIRect::MakeWH(100, 100);
SkIRect clip2 = SkIRect::MakeWH(200, 200);
- SkImageFilter::Cache::Key key0(0, SkMatrix::I(), clip1, image->uniqueID(), image->subset());
- SkImageFilter::Cache::Key key1(1, SkMatrix::I(), clip1, image->uniqueID(), image->subset());
- SkImageFilter::Cache::Key key2(0, SkMatrix::MakeTrans(5, 5), clip1,
+ SkImageFilterCacheKey key0(0, SkMatrix::I(), clip1, image->uniqueID(), image->subset());
+ SkImageFilterCacheKey key1(1, SkMatrix::I(), clip1, image->uniqueID(), image->subset());
+ SkImageFilterCacheKey key2(0, SkMatrix::MakeTrans(5, 5), clip1,
image->uniqueID(), image->subset());
- SkImageFilter::Cache::Key key3(0, SkMatrix::I(), clip2, image->uniqueID(), image->subset());
- SkImageFilter::Cache::Key key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subset->subset());
+ SkImageFilterCacheKey key3(0, SkMatrix::I(), clip2, image->uniqueID(), image->subset());
+ SkImageFilterCacheKey key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subset->subset());
SkIPoint offset = SkIPoint::Make(3, 4);
cache->set(key0, image.get(), offset);
@@ -79,11 +79,11 @@ static void test_dont_find_if_diff_key(skiatest::Reporter* reporter,
static void test_internal_purge(skiatest::Reporter* reporter, const sk_sp<SkSpecialImage>& image) {
SkASSERT(image->getSize());
const size_t kCacheSize = image->getSize() + 10;
- SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
+ SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize));
SkIRect clip = SkIRect::MakeWH(100, 100);
- SkImageFilter::Cache::Key key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset());
- SkImageFilter::Cache::Key key2(1, SkMatrix::I(), clip, image->uniqueID(), image->subset());
+ SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset());
+ SkImageFilterCacheKey key2(1, SkMatrix::I(), clip, image->uniqueID(), image->subset());
SkIPoint offset = SkIPoint::Make(3, 4);
cache->set(key1, image.get(), offset);
@@ -104,11 +104,11 @@ static void test_explicit_purging(skiatest::Reporter* reporter,
const sk_sp<SkSpecialImage>& image,
const sk_sp<SkSpecialImage>& subset) {
static const size_t kCacheSize = 1000000;
- SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
+ SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize));
SkIRect clip = SkIRect::MakeWH(100, 100);
- SkImageFilter::Cache::Key key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset());
- SkImageFilter::Cache::Key key2(1, SkMatrix::I(), clip, subset->uniqueID(), image->subset());
+ SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image->subset());
+ SkImageFilterCacheKey key2(1, SkMatrix::I(), clip, subset->uniqueID(), image->subset());
SkIPoint offset = SkIPoint::Make(3, 4);
cache->set(key1, image.get(), offset);