OLD | NEW |
---|---|
(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 | |
scroggo
2013/12/03 23:00:01
If this is just for unit tests, does it need to be
hal.canary
2013/12/04 00:01:36
Done.
Mike suggested that too.
| |
24 * pool works. | |
25 */ | |
26 class SkPoolDiscardableMemory; | |
27 class SkDiscardableMemoryPool : public SkDiscardableMemory::Factory { | |
28 public: | |
29 // Without mutex, will be not be thread safe. | |
30 SkDiscardableMemoryPool(size_t budget, SkBaseMutex* mutex = NULL); | |
31 ~SkDiscardableMemoryPool(); | |
32 SkDiscardableMemory* create(size_t bytes); | |
33 size_t getRAMUsed(); | |
34 void setRAMBudget(size_t budget); | |
35 void dumpPool(); | |
36 friend class SkPoolDiscardableMemory; | |
37 #if LAZY_CACHE_STATS | |
38 int fCacheHits; | |
39 int fCacheMisses; | |
40 #endif // LAZY_CACHE_STATS | |
41 private: | |
42 SkBaseMutex* fMutex; | |
43 size_t fBudget; | |
44 size_t fUsed; | |
45 SkTInternalLList<SkPoolDiscardableMemory> fList; | |
46 void dumpDownTo(size_t budget); | |
47 void free(SkPoolDiscardableMemory* dm); | |
scroggo
2013/12/03 23:00:01
I think I follow all your functions, but comments
hal.canary
2013/12/04 00:01:36
Done.
| |
48 bool lock(SkPoolDiscardableMemory* dm); | |
49 void unlock(SkPoolDiscardableMemory* dm); | |
50 typedef SkNoncopyable INHERITED; | |
scroggo
2013/12/03 23:00:01
SkDiscardableMemory::Factory should be set to INHE
hal.canary
2013/12/04 00:01:36
Done.
| |
51 }; | |
52 | |
53 /** | |
54 * Used for calling getRAMUsed(), setRAMBudget() or dumpPool(), or to | |
scroggo
2013/12/03 23:00:01
I would say that this returns (and possibly create
hal.canary
2013/12/04 00:01:36
Done.
| |
55 * act as a SkDiscardableMemory::Factory | |
56 */ | |
57 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool(); | |
58 | |
59 /* | |
60 * Motivation: by combining SkCreateGlobalPoolDiscardableMemory and | |
scroggo
2013/12/03 23:00:01
Motivation for what? Is this the motivation for th
hal.canary
2013/12/04 00:01:36
Done. Those comments were meant for myself; I mea
| |
61 * SkDiscardablePixelRef, we can replace SkImageRef_GlobalPool, | |
62 * currently in use by Android. We can also properly test | |
63 * SkDiscardablePixelRef as a SkLazyPixelRef within the Skia tools. | |
scroggo
2013/12/03 23:00:01
SkLazyPixelRef is removed, correct?
hal.canary
2013/12/04 00:01:36
yes. I meant to say that I wanted to use Discard
| |
64 */ | |
65 | |
66 /** | |
67 * The same signature as SkDiscardableMemory::Create, but there are | |
68 * situations where we want to choose types of DiscardableMemory - | |
69 * see Android's BitmapFactory for an example. | |
70 * | |
71 * Only returns NULL if malloc fails. | |
72 **/ | |
73 inline SkDiscardableMemory* SkCreateGlobalPoolDiscardableMemory(size_t bytes) { | |
74 return SkGetGlobalDiscardableMemoryPool()->create(bytes); | |
75 } | |
76 | |
77 #if !defined(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE) | |
78 #define SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE (128 * 1024 * 1024) | |
79 #endif | |
80 | |
81 #endif // SkDiscardableMemoryPool_DEFINED | |
OLD | NEW |