Index: src/core/SkScaledImageCache.h |
diff --git a/src/core/SkScaledImageCache.h b/src/core/SkScaledImageCache.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0f41c0b76685c1a312c8e0e068a4884cea43c52d |
--- /dev/null |
+++ b/src/core/SkScaledImageCache.h |
@@ -0,0 +1,65 @@ |
+#ifndef SkScaledImageCache_DEFINED |
+#define SkScaledImageCache_DEFINED |
+ |
+#include "SkBitmap.h" |
+ |
+class SkScaledImageCache { |
+public: |
+ struct ID; |
+ |
+ /** |
+ * Search the cache for a scaled version of original. If found, return it |
+ * in scaled, and return its ID pointer. Use the returned ptr to unlock |
+ * the cache when you are done using scaled. |
+ * |
+ * If a match is not found, scaled will be unmodifed, and NULL will be |
+ * returned. |
+ */ |
+ static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, |
+ SkScalar scaleY, SkBitmap* scaled); |
+ |
+ /** |
+ * To add a new (scaled) bitmap to the cache, call AddAndLock. Use the |
+ * returned ptr to unlock the cache when you are done using scaled. |
+ */ |
+ static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, |
+ SkScalar scaleY, const SkBitmap& scaled); |
+ |
+ static void Unlock(ID*); |
+ |
+ static size_t GetByteLimit(); |
+ static size_t SetByteLimit(size_t newLimit); |
+ static size_t GetBytesUsed(); |
+ |
+ SkScaledImageCache(); |
+ ~SkScaledImageCache(); |
+ |
+private: |
+ ID* findAndLock(const SkBitmap& original, SkScalar scaleX, |
+ SkScalar scaleY, SkBitmap* scaled); |
+ ID* addAndLock(const SkBitmap& original, SkScalar scaleX, |
+ SkScalar scaleY, const SkBitmap& scaled); |
+ void unlock(ID*); |
+ |
+ struct Rec; |
+ Rec* fHead; |
+ Rec* fTail; |
+ |
+ size_t fBytesUsed; |
+ size_t fByteLimit; |
+ int fCount; |
+ |
+ void purgeAsNeeded(); |
+ |
+ // linklist management |
+ void moveToHead(Rec*); |
+ void addToHead(Rec*); |
+ void detach(Rec*); |
+#ifdef SK_DEBUG |
+ void validate() const; |
+#else |
+ void validate() const {} |
+#endif |
+}; |
+ |
+#endif |