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

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

Issue 112833003: add more tests for discardable caches (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | « no previous file | src/lazy/SkDiscardableMemoryPool.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 #include "SkScaledImageCache.h" 8 #include "SkScaledImageCache.h"
9 #include "SkMipMap.h" 9 #include "SkMipMap.h"
10 #include "SkOnce.h" 10 #include "SkOnce.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; 202 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
203 virtual void onUnlockPixels() SK_OVERRIDE; 203 virtual void onUnlockPixels() SK_OVERRIDE;
204 virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE; 204 virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
205 205
206 private: 206 private:
207 SkImageInfo fInfo; // remove when SkPixelRef gets this in baseclass 207 SkImageInfo fInfo; // remove when SkPixelRef gets this in baseclass
208 208
209 SkDiscardableMemory* fDM; 209 SkDiscardableMemory* fDM;
210 size_t fRB; 210 size_t fRB;
211 bool fFirstTime; 211 bool fFirstTime;
212 bool fIsLocked;
212 213
213 typedef SkPixelRef INHERITED; 214 typedef SkPixelRef INHERITED;
214 }; 215 };
215 216
216 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in fo, 217 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in fo,
217 SkDiscardableMemory* dm, 218 SkDiscardableMemory* dm,
218 size_t rowBytes) 219 size_t rowBytes)
219 : INHERITED(info) 220 : INHERITED(info)
220 , fDM(dm) 221 , fDM(dm)
221 , fRB(rowBytes) 222 , fRB(rowBytes)
222 { 223 {
223 fInfo = info; // remove this redundant field when SkPixelRef has info 224 fInfo = info; // remove this redundant field when SkPixelRef has info
224 225
225 SkASSERT(dm->data()); 226 SkASSERT(dm->data());
226 fFirstTime = true; 227 fFirstTime = true;
228 fIsLocked = false;
227 } 229 }
228 230
229 SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() { 231 SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() {
230 SkDELETE(fDM); 232 SkDELETE(fDM);
231 } 233 }
232 234
233 void* SkOneShotDiscardablePixelRef::onLockPixels(SkColorTable** ctable) { 235 void* SkOneShotDiscardablePixelRef::onLockPixels(SkColorTable** ctable) {
234 if (fFirstTime) { 236 if (fFirstTime) {
235 // we're already locked 237 // we're already locked
236 fFirstTime = false; 238 fFirstTime = false;
237 return fDM->data(); 239 return fDM->data();
238 } 240 }
239 return fDM->lock() ? fDM->data() : NULL; 241
242 SkASSERT(!fIsLocked);
243 fIsLocked = fDM->lock();
244 return fIsLocked ? fDM->data() : NULL;
240 } 245 }
241 246
242 void SkOneShotDiscardablePixelRef::onUnlockPixels() { 247 void SkOneShotDiscardablePixelRef::onUnlockPixels() {
243 SkASSERT(!fFirstTime); 248 SkASSERT(!fFirstTime);
244 fDM->unlock(); 249 if (fIsLocked) {
250 fIsLocked = false;
251 fDM->unlock();
252 }
245 } 253 }
246 254
247 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const { 255 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const {
248 return fInfo.fHeight * fRB; 256 return fInfo.fHeight * fRB;
249 } 257 }
250 258
251 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator { 259 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator {
252 public: 260 public:
253 SkScaledImageCacheDiscardableAllocator( 261 SkScaledImageCacheDiscardableAllocator(
254 SkScaledImageCache::DiscardableFactory factory) { 262 SkScaledImageCache::DiscardableFactory factory) {
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 return SkScaledImageCache::GetBytesUsed(); 761 return SkScaledImageCache::GetBytesUsed();
754 } 762 }
755 763
756 size_t SkGraphics::GetImageCacheByteLimit() { 764 size_t SkGraphics::GetImageCacheByteLimit() {
757 return SkScaledImageCache::GetByteLimit(); 765 return SkScaledImageCache::GetByteLimit();
758 } 766 }
759 767
760 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { 768 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) {
761 return SkScaledImageCache::SetByteLimit(newLimit); 769 return SkScaledImageCache::SetByteLimit(newLimit);
762 } 770 }
OLDNEW
« no previous file with comments | « no previous file | src/lazy/SkDiscardableMemoryPool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698