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

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

Issue 93673005: Revert of ensure that we call onUnlock only when we onLock succeeded (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 | « src/core/SkPixelRef.cpp ('k') | src/images/SkImageRef_ashmem.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 #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 SkASSERT(fDM->data());
237 fFirstTime = false; 238 fFirstTime = false;
238 return fDM->data(); 239 return fDM->data();
239 } 240 }
240 return fDM->lock() ? fDM->data() : NULL; 241
242 SkASSERT(!fIsLocked);
243 fIsLocked = fDM->lock();
244 return fIsLocked ? fDM->data() : NULL;
241 } 245 }
242 246
243 void SkOneShotDiscardablePixelRef::onUnlockPixels() { 247 void SkOneShotDiscardablePixelRef::onUnlockPixels() {
244 SkASSERT(!fFirstTime); 248 SkASSERT(!fFirstTime);
245 fDM->unlock(); 249 if (fIsLocked) {
250 fIsLocked = false;
251 fDM->unlock();
252 }
246 } 253 }
247 254
248 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const { 255 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const {
249 return fInfo.fHeight * fRB; 256 return fInfo.fHeight * fRB;
250 } 257 }
251 258
252 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator { 259 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator {
253 public: 260 public:
254 SkScaledImageCacheDiscardableAllocator( 261 SkScaledImageCacheDiscardableAllocator(
255 SkScaledImageCache::DiscardableFactory factory) { 262 SkScaledImageCache::DiscardableFactory factory) {
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 return SkScaledImageCache::GetBytesUsed(); 761 return SkScaledImageCache::GetBytesUsed();
755 } 762 }
756 763
757 size_t SkGraphics::GetImageCacheByteLimit() { 764 size_t SkGraphics::GetImageCacheByteLimit() {
758 return SkScaledImageCache::GetByteLimit(); 765 return SkScaledImageCache::GetByteLimit();
759 } 766 }
760 767
761 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { 768 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) {
762 return SkScaledImageCache::SetByteLimit(newLimit); 769 return SkScaledImageCache::SetByteLimit(newLimit);
763 } 770 }
OLDNEW
« no previous file with comments | « src/core/SkPixelRef.cpp ('k') | src/images/SkImageRef_ashmem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698