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

Side by Side Diff: include/lazy/SkLruImageCache.h

Issue 18612003: use typedef to name our ID type in SkImageCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/lazy/SkImageCache.h ('k') | include/lazy/SkPurgeableImageCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "SkImageCache.h" 11 #include "SkImageCache.h"
12 #include "SkThread.h" 12 #include "SkThread.h"
13 #include "SkTInternalLList.h" 13 #include "SkTInternalLList.h"
14 14
15 class CachedPixels; 15 class CachedPixels;
16 16
17 /** 17 /**
18 * SkImageCache implementation that uses an LRU cache to age out old images. 18 * SkImageCache implementation that uses an LRU cache to age out old images.
19 */ 19 */
20 class SkLruImageCache : public SkImageCache { 20 class SkLruImageCache : public SkImageCache {
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 virtual MemoryStatus getMemoryStatus(intptr_t ID) const SK_OVERRIDE; 28 virtual MemoryStatus getMemoryStatus(ID) const SK_OVERRIDE;
29 virtual void purgeAllUnpinnedCaches() SK_OVERRIDE; 29 virtual void purgeAllUnpinnedCaches() SK_OVERRIDE;
30 #endif 30 #endif
31 31
32 /** 32 /**
33 * Set the byte limit on cached pixels. If more bytes are used than this, t he cache will free 33 * Set the byte limit on cached pixels. If more bytes are used than this, t he cache will free
34 * unpinned memory until under the new limit or until all unpinned memory i s freed. This will 34 * unpinned memory until under the new limit or until all unpinned memory i s freed. This will
35 * never free pinned memory, so the cache can potentially remain over the l imit. The limit is 35 * never free pinned memory, so the cache can potentially remain over the l imit. The limit is
36 * enforced each time memory is allocated or released. 36 * enforced each time memory is allocated or released.
37 * 0 is a special flag for an infinite budget. 37 * 0 is a special flag for an infinite budget.
38 * @return size_t The previous limit. 38 * @return size_t The previous limit.
39 */ 39 */
40 size_t setImageCacheLimit(size_t newLimit); 40 size_t setImageCacheLimit(size_t newLimit);
41 41
42 /** 42 /**
43 * Return the number of bytes of memory currently in use by the cache. Can include memory that 43 * Return the number of bytes of memory currently in use by the cache. Can include memory that
44 * is no longer pinned, but has not been freed. 44 * is no longer pinned, but has not been freed.
45 */ 45 */
46 size_t getImageCacheUsed() const { return fRamUsed; } 46 size_t getImageCacheUsed() const { return fRamUsed; }
47 47
48 virtual void* allocAndPinCache(size_t bytes, intptr_t* ID) SK_OVERRIDE; 48 virtual void* allocAndPinCache(size_t bytes, ID*) SK_OVERRIDE;
49 virtual void* pinCache(intptr_t ID, SkImageCache::DataStatus*) SK_OVERRIDE; 49 virtual void* pinCache(ID, SkImageCache::DataStatus*) SK_OVERRIDE;
50 virtual void releaseCache(intptr_t ID) SK_OVERRIDE; 50 virtual void releaseCache(ID) SK_OVERRIDE;
51 virtual void throwAwayCache(intptr_t ID) SK_OVERRIDE; 51 virtual void throwAwayCache(ID) SK_OVERRIDE;
52 52
53 private: 53 private:
54 // Linked list of recently used. Head is the most recently used, and tail is the least. 54 // Linked list of recently used. Head is the most recently used, and tail is the least.
55 SkTInternalLList<CachedPixels> fLRU; 55 SkTInternalLList<CachedPixels> fLRU;
56 typedef SkTInternalLList<CachedPixels>::Iter Iter; 56 typedef SkTInternalLList<CachedPixels>::Iter Iter;
57 57
58 #ifdef SK_DEBUG 58 #ifdef SK_DEBUG
59 // fMutex is mutable so that getMemoryStatus can be const 59 // fMutex is mutable so that getMemoryStatus can be const
60 mutable 60 mutable
61 #endif 61 #endif
62 SkMutex fMutex; 62 SkMutex fMutex;
63 size_t fRamBudget; 63 size_t fRamBudget;
64 size_t fRamUsed; 64 size_t fRamUsed;
65 65
66 /** 66 /**
67 * Find the CachedPixels represented by ID, or NULL if not in the cache. Mu tex must be locked 67 * Find the CachedPixels represented by ID, or NULL if not in the cache. Mu tex must be locked
68 * before calling. 68 * before calling.
69 */ 69 */
70 CachedPixels* findByID(intptr_t ID) const; 70 CachedPixels* findByID(ID) const;
71 71
72 /** 72 /**
73 * If over budget, throw away pixels which are not currently in use until b elow budget or there 73 * If over budget, throw away pixels which are not currently in use until b elow budget or there
74 * are no more pixels eligible to be thrown away. Mutex must be locked befo re calling. 74 * are no more pixels eligible to be thrown away. Mutex must be locked befo re calling.
75 */ 75 */
76 void purgeIfNeeded(); 76 void purgeIfNeeded();
77 77
78 /** 78 /**
79 * Purge until below limit. Mutex must be locked before calling. 79 * Purge until below limit. Mutex must be locked before calling.
80 */ 80 */
81 void purgeTilAtOrBelow(size_t limit); 81 void purgeTilAtOrBelow(size_t limit);
82 82
83 /** 83 /**
84 * Remove a set of CachedPixels. Mutex must be locked before calling. 84 * Remove a set of CachedPixels. Mutex must be locked before calling.
85 */ 85 */
86 void removePixels(CachedPixels*); 86 void removePixels(CachedPixels*);
87 }; 87 };
88 88
89 #endif // SkLruImageCache_DEFINED 89 #endif // SkLruImageCache_DEFINED
OLDNEW
« no previous file with comments | « include/lazy/SkImageCache.h ('k') | include/lazy/SkPurgeableImageCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698