OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkLruImageCache_DEFINED | 8 #ifndef SkLruImageCache_DEFINED |
9 #define SkLruImageCache_DEFINED | 9 #define SkLruImageCache_DEFINED |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 public: | 22 public: |
23 SkLruImageCache(size_t budget); | 23 SkLruImageCache(size_t budget); |
24 | 24 |
25 virtual ~SkLruImageCache(); | 25 virtual ~SkLruImageCache(); |
26 | 26 |
27 #ifdef SK_DEBUG | 27 #ifdef SK_DEBUG |
28 CacheStatus getCacheStatus(intptr_t ID) const SK_OVERRIDE; | 28 CacheStatus getCacheStatus(intptr_t ID) const SK_OVERRIDE; |
29 #endif | 29 #endif |
30 | 30 |
31 void setBudget(size_t newBudget); | 31 /** |
| 32 * Set the byte limit on cached pixels. If more bytes are used than this, t
he cache will free |
| 33 * unpinned memory until under the new limit or until all unpinned memory i
s freed. This will |
| 34 * never free pinned memory, so the cache can potentially remain over the l
imit. The limit is |
| 35 * enforced each time memory is allocated or released. |
| 36 * 0 is a special flag for an infinite budget. |
| 37 * @return size_t The previous limit. |
| 38 */ |
| 39 size_t setImageCacheLimit(size_t newLimit); |
| 40 |
| 41 /** |
| 42 * Return the number of bytes of memory currently in use by the cache. Can
include memory that |
| 43 * is no longer pinned, but has not been freed. |
| 44 */ |
| 45 size_t getImageCacheUsed() const { return fRamUsed; } |
32 | 46 |
33 virtual void* allocAndPinCache(size_t bytes, intptr_t* ID) SK_OVERRIDE; | 47 virtual void* allocAndPinCache(size_t bytes, intptr_t* ID) SK_OVERRIDE; |
34 virtual void* pinCache(intptr_t ID) SK_OVERRIDE; | 48 virtual void* pinCache(intptr_t ID) SK_OVERRIDE; |
35 virtual void releaseCache(intptr_t ID) SK_OVERRIDE; | 49 virtual void releaseCache(intptr_t ID) SK_OVERRIDE; |
36 virtual void throwAwayCache(intptr_t ID) SK_OVERRIDE; | 50 virtual void throwAwayCache(intptr_t ID) SK_OVERRIDE; |
37 | 51 |
38 private: | 52 private: |
39 // Linked list of recently used. Head is the most recently used, and tail is
the least. | 53 // Linked list of recently used. Head is the most recently used, and tail is
the least. |
40 SkTInternalLList<CachedPixels> fLRU; | 54 SkTInternalLList<CachedPixels> fLRU; |
41 typedef SkTInternalLList<CachedPixels>::Iter Iter; | 55 typedef SkTInternalLList<CachedPixels>::Iter Iter; |
(...skipping 23 matching lines...) Expand all Loading... |
65 */ | 79 */ |
66 void purgeTilAtOrBelow(size_t limit); | 80 void purgeTilAtOrBelow(size_t limit); |
67 | 81 |
68 /** | 82 /** |
69 * Remove a set of CachedPixels. Mutex must be locked before calling. | 83 * Remove a set of CachedPixels. Mutex must be locked before calling. |
70 */ | 84 */ |
71 void removePixels(CachedPixels*); | 85 void removePixels(CachedPixels*); |
72 }; | 86 }; |
73 | 87 |
74 #endif // SkLruImageCache_DEFINED | 88 #endif // SkLruImageCache_DEFINED |
OLD | NEW |