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

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

Issue 1254383006: SkImage_Raster's pixels are always immutable. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 | « include/core/SkPixelRef.h ('k') | src/image/SkImage.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 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkMutex.h" 9 #include "SkMutex.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 #endif 99 #endif
100 100
101 { 101 {
102 #ifdef SK_TRACE_PIXELREF_LIFETIME 102 #ifdef SK_TRACE_PIXELREF_LIFETIME
103 SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter)); 103 SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter));
104 #endif 104 #endif
105 this->setMutex(NULL); 105 this->setMutex(NULL);
106 fRec.zero(); 106 fRec.zero();
107 fLockCount = 0; 107 fLockCount = 0;
108 this->needsNewGenID(); 108 this->needsNewGenID();
109 fIsImmutable = false; 109 fMutability = kMutable;
110 fPreLocked = false; 110 fPreLocked = false;
111 fAddedToCache.store(false); 111 fAddedToCache.store(false);
112 } 112 }
113 113
114 114
115 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) 115 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex)
116 : fInfo(validate_info(info)) 116 : fInfo(validate_info(info))
117 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 117 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
118 , fStableID(next_gen_id()) 118 , fStableID(next_gen_id())
119 #endif 119 #endif
120 { 120 {
121 #ifdef SK_TRACE_PIXELREF_LIFETIME 121 #ifdef SK_TRACE_PIXELREF_LIFETIME
122 SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter)); 122 SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter));
123 #endif 123 #endif
124 this->setMutex(mutex); 124 this->setMutex(mutex);
125 fRec.zero(); 125 fRec.zero();
126 fLockCount = 0; 126 fLockCount = 0;
127 this->needsNewGenID(); 127 this->needsNewGenID();
128 fIsImmutable = false; 128 fMutability = kMutable;
129 fPreLocked = false; 129 fPreLocked = false;
130 fAddedToCache.store(false); 130 fAddedToCache.store(false);
131 } 131 }
132 132
133 SkPixelRef::~SkPixelRef() { 133 SkPixelRef::~SkPixelRef() {
134 #ifndef SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT 134 #ifndef SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT
135 SkASSERT(SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount || 0 == fLockCount); 135 SkASSERT(SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount || 0 == fLockCount);
136 #endif 136 #endif
137 137
138 #ifdef SK_TRACE_PIXELREF_LIFETIME 138 #ifdef SK_TRACE_PIXELREF_LIFETIME
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 SkNotifyBitmapGenIDIsStale(this->getGenerationID()); 334 SkNotifyBitmapGenIDIsStale(this->getGenerationID());
335 fAddedToCache.store(false); 335 fAddedToCache.store(false);
336 } 336 }
337 } 337 }
338 // Listeners get at most one shot, so whether these triggered or not, blow t hem away. 338 // Listeners get at most one shot, so whether these triggered or not, blow t hem away.
339 fGenIDChangeListeners.deleteAll(); 339 fGenIDChangeListeners.deleteAll();
340 } 340 }
341 341
342 void SkPixelRef::notifyPixelsChanged() { 342 void SkPixelRef::notifyPixelsChanged() {
343 #ifdef SK_DEBUG 343 #ifdef SK_DEBUG
344 if (fIsImmutable) { 344 if (this->isImmutable()) {
345 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); 345 SkDebugf("========== notifyPixelsChanged called on immutable pixelref");
346 } 346 }
347 #endif 347 #endif
348 this->callGenIDChangeListeners(); 348 this->callGenIDChangeListeners();
349 this->needsNewGenID(); 349 this->needsNewGenID();
350 this->onNotifyPixelsChanged(); 350 this->onNotifyPixelsChanged();
351 } 351 }
352 352
353 void SkPixelRef::changeAlphaType(SkAlphaType at) { 353 void SkPixelRef::changeAlphaType(SkAlphaType at) {
354 *const_cast<SkImageInfo*>(&fInfo) = fInfo.makeAlphaType(at); 354 *const_cast<SkImageInfo*>(&fInfo) = fInfo.makeAlphaType(at);
355 } 355 }
356 356
357 void SkPixelRef::setImmutable() { 357 void SkPixelRef::setImmutable() {
358 fIsImmutable = true; 358 fMutability = kImmutable;
359 }
360 void SkPixelRef::setTemporarilyImmutable() {
361 SkASSERT(fMutability != kImmutable);
362 fMutability = kTemporarilyImmutable;
363 }
364
365 void SkPixelRef::restoreMutability() {
366 SkASSERT(fMutability != kImmutable);
367 fMutability = kMutable;
robertphillips 2015/07/29 19:26:29 Hmmm .. can we get rid of the 'notifyPixelsChanged
368 this->notifyPixelsChanged(); // This is just precautionary.
359 } 369 }
360 370
361 bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) { 371 bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) {
362 return this->onReadPixels(dst, subset); 372 return this->onReadPixels(dst, subset);
363 } 373 }
364 374
365 //////////////////////////////////////////////////////////////////////////////// /////////////////// 375 //////////////////////////////////////////////////////////////////////////////// ///////////////////
366 376
367 bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { 377 bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
368 return false; 378 return false;
(...skipping 26 matching lines...) Expand all
395 } 405 }
396 406
397 result->fUnlockProc = unlock_legacy_result; 407 result->fUnlockProc = unlock_legacy_result;
398 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr oc 408 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr oc
399 result->fCTable = fRec.fColorTable; 409 result->fCTable = fRec.fColorTable;
400 result->fPixels = fRec.fPixels; 410 result->fPixels = fRec.fPixels;
401 result->fRowBytes = fRec.fRowBytes; 411 result->fRowBytes = fRec.fRowBytes;
402 result->fSize.set(fInfo.width(), fInfo.height()); 412 result->fSize.set(fInfo.width(), fInfo.height());
403 return true; 413 return true;
404 } 414 }
OLDNEW
« no previous file with comments | « include/core/SkPixelRef.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698