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

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

Issue 960563002: only notify bitmaps that have been added to the cache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address reviewer comments Created 5 years, 9 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/SkBitmapCache.cpp ('k') | src/core/SkResourceCache.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 "SkPixelRef.h" 9 #include "SkPixelRef.h"
10 #include "SkThread.h" 10 #include "SkThread.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 , fStableID(SkNextPixelRefGenerationID()) 93 , fStableID(SkNextPixelRefGenerationID())
94 #endif 94 #endif
95 95
96 { 96 {
97 this->setMutex(NULL); 97 this->setMutex(NULL);
98 fRec.zero(); 98 fRec.zero();
99 fLockCount = 0; 99 fLockCount = 0;
100 this->needsNewGenID(); 100 this->needsNewGenID();
101 fIsImmutable = false; 101 fIsImmutable = false;
102 fPreLocked = false; 102 fPreLocked = false;
103 fAddedToCache.store(false);
103 } 104 }
104 105
105 106
106 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) 107 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex)
107 : fInfo(validate_info(info)) 108 : fInfo(validate_info(info))
108 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 109 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
109 , fStableID(SkNextPixelRefGenerationID()) 110 , fStableID(SkNextPixelRefGenerationID())
110 #endif 111 #endif
111 { 112 {
112 this->setMutex(mutex); 113 this->setMutex(mutex);
113 fRec.zero(); 114 fRec.zero();
114 fLockCount = 0; 115 fLockCount = 0;
115 this->needsNewGenID(); 116 this->needsNewGenID();
116 fIsImmutable = false; 117 fIsImmutable = false;
117 fPreLocked = false; 118 fPreLocked = false;
119 fAddedToCache.store(false);
118 } 120 }
119 121
120 SkPixelRef::~SkPixelRef() { 122 SkPixelRef::~SkPixelRef() {
121 this->callGenIDChangeListeners(); 123 this->callGenIDChangeListeners();
122 } 124 }
123 125
124 void SkPixelRef::needsNewGenID() { 126 void SkPixelRef::needsNewGenID() {
125 fGenerationID.store(0); 127 fGenerationID.store(0);
126 fUniqueGenerationID.store(false); 128 fUniqueGenerationID.store(false);
127 } 129 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 220 }
219 221
220 // we need to be called *before* the genID gets changed or zerod 222 // we need to be called *before* the genID gets changed or zerod
221 void SkPixelRef::callGenIDChangeListeners() { 223 void SkPixelRef::callGenIDChangeListeners() {
222 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID. 224 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID.
223 if (fUniqueGenerationID.load()) { 225 if (fUniqueGenerationID.load()) {
224 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { 226 for (int i = 0; i < fGenIDChangeListeners.count(); i++) {
225 fGenIDChangeListeners[i]->onChange(); 227 fGenIDChangeListeners[i]->onChange();
226 } 228 }
227 229
228 // If we can flag the pixelref somehow whenever it was actually added to the cache, 230 // TODO: SkAtomic could add "old_value = atomic.xchg(new_value)" to make this clearer.
229 // perhaps it would be nice to only call this notifier in that case. For now we always 231 if (fAddedToCache.load()) {
230 // call it, since we don't know if it was cached or not. 232 SkNotifyBitmapGenIDIsStale(this->getGenerationID());
231 SkNotifyBitmapGenIDIsStale(this->getGenerationID()); 233 fAddedToCache.store(false);
234 }
232 } 235 }
233 // Listeners get at most one shot, so whether these triggered or not, blow t hem away. 236 // Listeners get at most one shot, so whether these triggered or not, blow t hem away.
234 fGenIDChangeListeners.deleteAll(); 237 fGenIDChangeListeners.deleteAll();
235 } 238 }
236 239
237 void SkPixelRef::notifyPixelsChanged() { 240 void SkPixelRef::notifyPixelsChanged() {
238 #ifdef SK_DEBUG 241 #ifdef SK_DEBUG
239 if (fIsImmutable) { 242 if (fIsImmutable) {
240 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); 243 SkDebugf("========== notifyPixelsChanged called on immutable pixelref");
241 } 244 }
(...skipping 24 matching lines...) Expand all
266 269
267 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], 270 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3],
268 SkYUVColorSpace* colorSpace) { 271 SkYUVColorSpace* colorSpace) {
269 return false; 272 return false;
270 } 273 }
271 274
272 size_t SkPixelRef::getAllocatedSizeInBytes() const { 275 size_t SkPixelRef::getAllocatedSizeInBytes() const {
273 return 0; 276 return 0;
274 } 277 }
275 278
OLDNEW
« no previous file with comments | « src/core/SkBitmapCache.cpp ('k') | src/core/SkResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698