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

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

Issue 483493003: expose generalized imagecache key (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove more dead code Created 6 years, 4 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
« no previous file with comments | « src/core/SkBitmapProcState.cpp ('k') | src/core/SkScaledImageCache.cpp » ('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 SkScaledImageCache_DEFINED 8 #ifndef SkScaledImageCache_DEFINED
9 #define SkScaledImageCache_DEFINED 9 #define SkScaledImageCache_DEFINED
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 * Returns a locked/pinned SkDiscardableMemory instance for the specified 66 * Returns a locked/pinned SkDiscardableMemory instance for the specified
67 * number of bytes, or NULL on failure. 67 * number of bytes, or NULL on failure.
68 */ 68 */
69 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes); 69 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes);
70 70
71 /* 71 /*
72 * The following static methods are thread-safe wrappers around a global 72 * The following static methods are thread-safe wrappers around a global
73 * instance of this cache. 73 * instance of this cache.
74 */ 74 */
75 75
76 static ID* FindAndLock(uint32_t pixelGenerationID, 76 static ID* FindAndLock(const Key&, SkBitmap* result);
77 int32_t width, 77 static ID* AddAndLock(const Key&, const SkBitmap& result);
78 int32_t height, 78
79 SkBitmap* returnedBitmap); 79 static ID* FindAndLock(const Key&, const SkMipMap** result);
80 80 static ID* AddAndLock(const Key&, const SkMipMap* result);
81 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, 81
82 SkScalar scaleY, SkBitmap* returnedBitmap);
83 static ID* FindAndLockMip(const SkBitmap& original,
84 SkMipMap const** returnedMipMap);
85
86
87 static ID* AddAndLock(uint32_t pixelGenerationID,
88 int32_t width,
89 int32_t height,
90 const SkBitmap& bitmap);
91
92 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX,
93 SkScalar scaleY, const SkBitmap& bitmap);
94 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
95
96 static void Unlock(ID*); 82 static void Unlock(ID*);
97 83
98 static size_t GetTotalBytesUsed(); 84 static size_t GetTotalBytesUsed();
99 static size_t GetTotalByteLimit(); 85 static size_t GetTotalByteLimit();
100 static size_t SetTotalByteLimit(size_t newLimit); 86 static size_t SetTotalByteLimit(size_t newLimit);
101 87
102 static size_t SetSingleAllocationByteLimit(size_t); 88 static size_t SetSingleAllocationByteLimit(size_t);
103 static size_t GetSingleAllocationByteLimit(); 89 static size_t GetSingleAllocationByteLimit();
104 90
105 static SkBitmap::Allocator* GetAllocator(); 91 static SkBitmap::Allocator* GetAllocator();
(...skipping 13 matching lines...) Expand all
119 * will ignore its argument and return 0. 105 * will ignore its argument and return 0.
120 */ 106 */
121 SkScaledImageCache(DiscardableFactory); 107 SkScaledImageCache(DiscardableFactory);
122 108
123 /** 109 /**
124 * Construct the cache, allocating memory with malloc, and respect the 110 * Construct the cache, allocating memory with malloc, and respect the
125 * byteLimit, purging automatically when a new image is added to the cache 111 * byteLimit, purging automatically when a new image is added to the cache
126 * that pushes the total bytesUsed over the limit. Note: The limit can be 112 * that pushes the total bytesUsed over the limit. Note: The limit can be
127 * changed at runtime with setTotalByteLimit. 113 * changed at runtime with setTotalByteLimit.
128 */ 114 */
129 SkScaledImageCache(size_t byteLimit); 115 explicit SkScaledImageCache(size_t byteLimit);
130
131 ~SkScaledImageCache(); 116 ~SkScaledImageCache();
132 117
133 /** 118 /**
134 * Search the cache for a matching bitmap (using generationID, 119 * Search the cache for a matching key. If found, return its bitmap and ret urn its ID pointer.
135 * width, and height as a search key). If found, return it in 120 * Use the returned ID to unlock the cache when you are done using outBitma p.
136 * returnedBitmap, and return its ID pointer. Use the returned
137 * ptr to unlock the cache when you are done using
138 * returnedBitmap.
139 * 121 *
140 * If a match is not found, returnedBitmap will be unmodifed, and 122 * If a match is not found, outBitmap will be unmodifed, and NULL will be r eturned.
141 * NULL will be returned.
142 *
143 * This is used if there is no scaling or subsetting, for example
144 * by SkLazyPixelRef.
145 */ 123 */
146 ID* findAndLock(uint32_t pixelGenerationID, int32_t width, int32_t height, 124 ID* findAndLock(const Key& key, SkBitmap* outBitmap);
147 SkBitmap* returnedBitmap); 125 ID* findAndLock(const Key& key, const SkMipMap** returnedMipMap);
148
149 /**
150 * Search the cache for a scaled version of original. If found,
151 * return it in returnedBitmap, and return its ID pointer. Use
152 * the returned ptr to unlock the cache when you are done using
153 * returnedBitmap.
154 *
155 * If a match is not found, returnedBitmap will be unmodifed, and
156 * NULL will be returned.
157 */
158 ID* findAndLock(const SkBitmap& original, SkScalar scaleX,
159 SkScalar scaleY, SkBitmap* returnedBitmap);
160 ID* findAndLockMip(const SkBitmap& original,
161 SkMipMap const** returnedMipMap);
162 126
163 /** 127 /**
164 * To add a new bitmap (or mipMap) to the cache, call 128 * To add a new bitmap (or mipMap) to the cache, call
165 * AddAndLock. Use the returned ptr to unlock the cache when you 129 * AddAndLock. Use the returned ptr to unlock the cache when you
166 * are done using scaled. 130 * are done using scaled.
167 * 131 *
168 * Use (generationID, width, and height) or (original, scaleX, 132 * Use (generationID, width, and height) or (original, scaleX,
169 * scaleY) or (original) as a search key 133 * scaleY) or (original) as a search key
170 */ 134 */
171 ID* addAndLock(uint32_t pixelGenerationID, int32_t width, int32_t height, 135 ID* addAndLock(const Key&, const SkBitmap& bitmap);
172 const SkBitmap& bitmap); 136 ID* addAndLock(const Key&, const SkMipMap* mipMap);
173 ID* addAndLock(const SkBitmap& original, SkScalar scaleX,
174 SkScalar scaleY, const SkBitmap& bitmap);
175 ID* addAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
176 137
177 /** 138 /**
178 * Given a non-null ID ptr returned by either findAndLock or addAndLock, 139 * Given a non-null ID ptr returned by either findAndLock or addAndLock,
179 * this releases the associated resources to be available to be purged 140 * this releases the associated resources to be available to be purged
180 * if needed. After this, the cached bitmap should no longer be 141 * if needed. After this, the cached bitmap should no longer be
181 * referenced by the caller. 142 * referenced by the caller.
182 */ 143 */
183 void unlock(ID*); 144 void unlock(ID*);
184 145
185 size_t getTotalBytesUsed() const { return fTotalBytesUsed; } 146 size_t getTotalBytesUsed() const { return fTotalBytesUsed; }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 178
218 DiscardableFactory fDiscardableFactory; 179 DiscardableFactory fDiscardableFactory;
219 // the allocator is NULL or one that matches discardables 180 // the allocator is NULL or one that matches discardables
220 SkBitmap::Allocator* fAllocator; 181 SkBitmap::Allocator* fAllocator;
221 182
222 size_t fTotalBytesUsed; 183 size_t fTotalBytesUsed;
223 size_t fTotalByteLimit; 184 size_t fTotalByteLimit;
224 size_t fSingleAllocationByteLimit; 185 size_t fSingleAllocationByteLimit;
225 int fCount; 186 int fCount;
226 187
227 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy,
228 const SkIRect& bounds);
229 Rec* findAndLock(const Key& key); 188 Rec* findAndLock(const Key& key);
230 ID* addAndLock(Rec* rec); 189 ID* addAndLock(Rec* rec);
231 190
232 void purgeRec(Rec*); 191 void purgeRec(Rec*);
233 void purgeAsNeeded(); 192 void purgeAsNeeded();
234 193
235 // linklist management 194 // linklist management
236 void moveToHead(Rec*); 195 void moveToHead(Rec*);
237 void addToHead(Rec*); 196 void addToHead(Rec*);
238 void detach(Rec*); 197 void detach(Rec*);
239 198
240 void init(); // called by constructors 199 void init(); // called by constructors
241 200
242 #ifdef SK_DEBUG 201 #ifdef SK_DEBUG
243 void validate() const; 202 void validate() const;
244 #else 203 #else
245 void validate() const {} 204 void validate() const {}
246 #endif 205 #endif
247 }; 206 };
248 #endif 207 #endif
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcState.cpp ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698