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

Unified Diff: src/lazy/SkDiscardableMemoryPool.h

Issue 103033002: Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase one last time Created 7 years 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 | « src/lazy/SkBitmapFactory.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
new file mode 100644
index 0000000000000000000000000000000000000000..09392602af93e5032812173139ca47b66a095d39
--- /dev/null
+++ b/src/lazy/SkDiscardableMemoryPool.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkDiscardableMemoryPool_DEFINED
+#define SkDiscardableMemoryPool_DEFINED
+
+#include "SkDiscardableMemory.h"
+#include "SkTInternalLList.h"
+#include "SkThread.h"
+
+#ifdef SK_DEBUG
+ #define LAZY_CACHE_STATS 1
+#elif !defined(LAZY_CACHE_STATS)
+ #define LAZY_CACHE_STATS 0
+#endif
+
+/**
+ * This non-global pool can be used for unit tests to verify that the
+ * pool works.
+ */
+class SkPoolDiscardableMemory;
+class SkDiscardableMemoryPool : public SkDiscardableMemory::Factory {
+public:
+ /**
+ * Without mutex, will be not be thread safe.
+ */
+ SkDiscardableMemoryPool(size_t budget, SkBaseMutex* mutex = NULL);
+ ~SkDiscardableMemoryPool();
+ SkDiscardableMemory* create(size_t bytes) SK_OVERRIDE;
+ size_t getRAMUsed();
+ void setRAMBudget(size_t budget);
+ /** purges all unlocked DMs */
+ void dumpPool();
+ friend class SkPoolDiscardableMemory;
+ #if LAZY_CACHE_STATS
+ int fCacheHits;
+ int fCacheMisses;
+ #endif // LAZY_CACHE_STATS
+
+private:
+ SkBaseMutex* fMutex;
+ size_t fBudget;
+ size_t fUsed;
+ SkTInternalLList<SkPoolDiscardableMemory> fList;
+ /** 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);
+ typedef SkDiscardableMemory::Factory INHERITED;
+};
+
+/**
+ * Returns (and creates if needed) a threadsafe global
+ * SkDiscardableMemoryPool.
+ */
+SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool();
+
+#if !defined(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE)
+#define SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE (128 * 1024 * 1024)
+#endif
+
+#endif // SkDiscardableMemoryPool_DEFINED
+
« no previous file with comments | « src/lazy/SkBitmapFactory.cpp ('k') | src/lazy/SkDiscardableMemoryPool.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698