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

Side by Side Diff: src/lazy/SkDiscardableMemoryPool.h

Issue 103033002: Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: cleanup test 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkDiscardableMemoryPool_DEFINED
9 #define SkDiscardableMemoryPool_DEFINED
10
11 #include "SkDiscardableMemory.h"
12 #include "SkTInternalLList.h"
13
14 class SkBaseMutex;
15
16 #ifdef SK_DEBUG
17 #define LAZY_CACHE_STATS 1
18 #elif !defined(LAZY_CACHE_STATS)
19 #define LAZY_CACHE_STATS 0
20 #endif
21
22 /**
23 * This non-global pool can be used for unit tests to verify that the
24 * pool works.
25 */
26 class SkPoolDiscardableMemory;
27 class SkDiscardableMemoryPool : public SkDiscardableMemory::Factory {
28 public:
29 /**
30 * Without mutex, will be not be thread safe.
31 */
32 SkDiscardableMemoryPool(size_t budget, SkBaseMutex* mutex = NULL);
33 ~SkDiscardableMemoryPool();
34 SkDiscardableMemory* create(size_t bytes) SK_OVERRIDE;
35 size_t getRAMUsed();
36 void setRAMBudget(size_t budget);
37 /** purges all unlocked DMs */
38 void dumpPool();
39 friend class SkPoolDiscardableMemory;
40 #if LAZY_CACHE_STATS
41 int fCacheHits;
42 int fCacheMisses;
43 #endif // LAZY_CACHE_STATS
44
45 private:
46 SkBaseMutex* fMutex;
47 size_t fBudget;
48 size_t fUsed;
49 SkTInternalLList<SkPoolDiscardableMemory> fList;
50 /** Function called to free memory if needed */
51 void dumpDownTo(size_t budget);
52 /** called by SkDiscardableMemoryPool upon destruction */
53 void free(SkPoolDiscardableMemory* dm);
54 /** called by SkDiscardableMemoryPool::lock() */
55 bool lock(SkPoolDiscardableMemory* dm);
56 /** called by SkDiscardableMemoryPool::unlock() */
57 void unlock(SkPoolDiscardableMemory* dm);
58 typedef SkDiscardableMemory::Factory INHERITED;
59 };
60
61 /**
62 * Returns (and creates if needed) a threadsafe global
63 * SkDiscardableMemoryPool.
64 */
65 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool();
66
67 #if !defined(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE)
68 #define SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE (128 * 1024 * 1024)
69 #endif
70
71 #endif // SkDiscardableMemoryPool_DEFINED
72
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698