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

Unified Diff: src/lazy/SkDiscardableMemoryPool.h

Issue 223403012: SkDiscardableMemoryPool to abstract class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 9 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 | « gm/factory.cpp ('k') | src/lazy/SkDiscardableMemoryPool.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lazy/SkDiscardableMemoryPool.h
diff --git a/src/lazy/SkDiscardableMemoryPool.h b/src/lazy/SkDiscardableMemoryPool.h
index 61bad701825aaa26279d22b4c9f75c7acabfb6a5..d141507004151360931df09b8622862dc480962b 100644
--- a/src/lazy/SkDiscardableMemoryPool.h
+++ b/src/lazy/SkDiscardableMemoryPool.h
@@ -9,60 +9,50 @@
#define SkDiscardableMemoryPool_DEFINED
#include "SkDiscardableMemory.h"
-#include "SkTInternalLList.h"
-#include "SkThread.h"
-class SkPoolDiscardableMemory;
-
-#ifdef SK_DEBUG
- #define LAZY_CACHE_STATS 1
-#elif !defined(LAZY_CACHE_STATS)
- #define LAZY_CACHE_STATS 0
+#ifndef SK_LAZY_CACHE_STATS
+ #ifdef SK_DEBUG
+ #define SK_LAZY_CACHE_STATS 1
+ #else
+ #define SK_LAZY_CACHE_STATS 0
+ #endif
#endif
/**
- * This non-global pool can be used for unit tests to verify that the
- * pool works.
+ * An implementation of Discardable Memory that manages a fixed-size
+ * budget of memory. When the allocated memory exceeds this size,
+ * unlocked blocks of memory are purged. If all memory is locked, it
+ * can exceed the memory-use budget.
*/
class SkDiscardableMemoryPool : public SkDiscardableMemory::Factory {
public:
- /**
- * Without mutex, will be not be thread safe.
- */
- SkDiscardableMemoryPool(size_t budget, SkBaseMutex* mutex = NULL);
- virtual ~SkDiscardableMemoryPool();
+ virtual ~SkDiscardableMemoryPool() { }
- virtual SkDiscardableMemory* create(size_t bytes) SK_OVERRIDE;
-
- size_t getRAMUsed();
- void setRAMBudget(size_t budget);
+ virtual size_t getRAMUsed() = 0;
+ virtual void setRAMBudget(size_t budget) = 0;
+ virtual size_t getRAMBudget() = 0;
/** purges all unlocked DMs */
- void dumpPool();
-
- #if LAZY_CACHE_STATS
- int fCacheHits;
- int fCacheMisses;
- #endif // LAZY_CACHE_STATS
-
-private:
- SkBaseMutex* fMutex;
- size_t fBudget;
- size_t fUsed;
- SkTInternalLList<SkPoolDiscardableMemory> fList;
+ virtual void dumpPool() = 0;
- /** Function called to free memory if needed */
- void dumpDownTo(size_t budget);
- /** called by SkDiscardableMemoryPool upon destruction */
- void free(SkPoolDiscardableMemory* dm);
- /** called by SkDiscardableMemoryPool::lock() */
- bool lock(SkPoolDiscardableMemory* dm);
- /** called by SkDiscardableMemoryPool::unlock() */
- void unlock(SkPoolDiscardableMemory* dm);
-
- friend class SkPoolDiscardableMemory;
+ #if SK_LAZY_CACHE_STATS
+ /**
+ * These two values are a count of the number of successful and
+ * failed calls to SkDiscardableMemory::lock() for all DMs managed
+ * by this pool.
+ */
+ virtual int getCacheHits() = 0;
+ virtual int getCacheMisses() = 0;
+ virtual void resetCacheHitsAndMisses() = 0;
+ #endif
- typedef SkDiscardableMemory::Factory INHERITED;
+ /**
+ * This non-global pool can be used for unit tests to verify that
+ * the pool works.
+ * Without mutex, will be not be thread safe.
+ */
+ static SkDiscardableMemoryPool* Create(
+ size_t size, SkBaseMutex* mutex = NULL);
};
/**
« no previous file with comments | « gm/factory.cpp ('k') | src/lazy/SkDiscardableMemoryPool.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698