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

Unified Diff: src/core/SkScaledImageCache.h

Issue 20005003: add scaledimagecache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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
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

Powered by Google App Engine
This is Rietveld 408576698