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

Side by Side Diff: src/core/SkScaledImageCache.h

Issue 54203006: Break up SkLazyPixelRef functionally into class hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Use SkImageInfo Created 7 years, 1 month 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
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 SkScaledImageCache_DEFINED 8 #ifndef SkScaledImageCache_DEFINED
9 #define SkScaledImageCache_DEFINED 9 #define SkScaledImageCache_DEFINED
10 10
(...skipping 13 matching lines...) Expand all
24 */ 24 */
25 class SkScaledImageCache { 25 class SkScaledImageCache {
26 public: 26 public:
27 struct ID; 27 struct ID;
28 28
29 /* 29 /*
30 * The following static methods are thread-safe wrappers around a global 30 * The following static methods are thread-safe wrappers around a global
31 * instance of this cache. 31 * instance of this cache.
32 */ 32 */
33 33
34 static SkScaledImageCache* GetGlobalInstance();
35
34 static ID* FindAndLock(uint32_t pixelGenerationID, 36 static ID* FindAndLock(uint32_t pixelGenerationID,
35 int32_t width, 37 int32_t width,
36 int32_t height, 38 int32_t height,
37 SkBitmap* returnedBitmap); 39 SkBitmap* returnedBitmap);
38 40
39 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, 41 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX,
40 SkScalar scaleY, SkBitmap* returnedBitmap); 42 SkScalar scaleY, SkBitmap* returnedBitmap);
41 static ID* FindAndLockMip(const SkBitmap& original, 43 static ID* FindAndLockMip(const SkBitmap& original,
42 SkMipMap const** returnedMipMap); 44 SkMipMap const** returnedMipMap);
43 45
44 46
45 static ID* AddAndLock(uint32_t pixelGenerationID, 47 static ID* AddAndLock(uint32_t pixelGenerationID,
46 int32_t width, 48 int32_t width,
47 int32_t height, 49 int32_t height,
48 const SkBitmap& bitmap); 50 const SkBitmap& bitmap);
49 51
50 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, 52 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX,
51 SkScalar scaleY, const SkBitmap& bitmap); 53 SkScalar scaleY, const SkBitmap& bitmap);
52 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap* mipMap); 54 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
53 55
54 static void Unlock(ID*); 56 static void Unlock(ID*);
55 57
56 static size_t GetBytesUsed(); 58 static size_t GetBytesUsed();
57 static size_t GetByteLimit(); 59 static size_t GetByteLimit();
58 static size_t SetByteLimit(size_t newLimit); 60 static size_t SetByteLimit(size_t newLimit);
59 61
60 /////////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////////
61 63
62 SkScaledImageCache(size_t byteLimit); 64 SkScaledImageCache(size_t byteLimit, SkBaseMutex* mutex = NULL);
63 ~SkScaledImageCache(); 65 ~SkScaledImageCache();
64 66
65 /** 67 /**
66 * Search the cache for a matching bitmap (using generationID, 68 * Search the cache for a matching bitmap (using generationID,
67 * width, and height as a search key). If found, return it in 69 * width, and height as a search key). If found, return it in
68 * returnedBitmap, and return its ID pointer. Use the returned 70 * returnedBitmap, and return its ID pointer. Use the returned
69 * ptr to unlock the cache when you are done using 71 * ptr to unlock the cache when you are done using
70 * returnedBitmap. 72 * returnedBitmap.
71 * 73 *
72 * If a match is not found, returnedBitmap will be unmodifed, and 74 * If a match is not found, returnedBitmap will be unmodifed, and
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ID* addAndLockMip(const SkBitmap& original, const SkMipMap* mipMap); 109 ID* addAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
108 110
109 /** 111 /**
110 * Given a non-null ID ptr returned by either findAndLock or addAndLock, 112 * Given a non-null ID ptr returned by either findAndLock or addAndLock,
111 * this releases the associated resources to be available to be purged 113 * this releases the associated resources to be available to be purged
112 * if needed. After this, the cached bitmap should no longer be 114 * if needed. After this, the cached bitmap should no longer be
113 * referenced by the caller. 115 * referenced by the caller.
114 */ 116 */
115 void unlock(ID*); 117 void unlock(ID*);
116 118
117 size_t getBytesUsed() const { return fBytesUsed; } 119 size_t getBytesUsed() const;
118 size_t getByteLimit() const { return fByteLimit; } 120 size_t getByteLimit() const;
119 121
120 /** 122 /**
121 * Set the maximum number of bytes available to this cache. If the current 123 * Set the maximum number of bytes available to this cache. If the current
122 * cache exceeds this new value, it will be purged to try to fit within 124 * cache exceeds this new value, it will be purged to try to fit within
123 * this new limit. 125 * this new limit.
124 */ 126 */
125 size_t setByteLimit(size_t newLimit); 127 size_t setByteLimit(size_t newLimit);
126 128
127 public: 129 public:
128 struct Rec; 130 struct Rec;
129 private: 131 private:
132 SkBaseMutex* fMutex; // can be NULL
133
130 Rec* fHead; 134 Rec* fHead;
131 Rec* fTail; 135 Rec* fTail;
132 136
133 class Hash; 137 class Hash;
134 Hash* fHash; 138 Hash* fHash;
135 139
136 size_t fBytesUsed; 140 size_t fBytesUsed;
137 size_t fByteLimit; 141 size_t fByteLimit;
138 int fCount; 142 int fCount;
139 143
140 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy, 144 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy,
141 const SkIRect& bounds); 145 const SkIRect& bounds);
142 void addAndLock(Rec* rec); 146 void addAndLock(Rec* rec);
143 147
144 void purgeAsNeeded(); 148 void purgeAsNeeded();
145 149
146 // linklist management 150 // linklist management
147 void moveToHead(Rec*); 151 void moveToHead(Rec*);
148 void addToHead(Rec*); 152 void addToHead(Rec*);
149 void detach(Rec*); 153 void detach(Rec*);
150 #ifdef SK_DEBUG 154 #ifdef SK_DEBUG
151 void validate() const; 155 void validate() const;
152 #else 156 #else
153 void validate() const {} 157 void validate() const {}
154 #endif 158 #endif
155 }; 159 };
156 #endif 160 #endif
161
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698