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

Side by Side Diff: src/gpu/GrResourceCache.cpp

Issue 938943002: Allow GrGpuResources' unique keys to be changed. (Closed) Base URL: https://skia.googlesource.com/skia.git@rename
Patch Set: Address comments Created 5 years, 10 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/gpu/GrResourceCache.h ('k') | src/gpu/SkGr.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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrResourceCache.h" 10 #include "GrResourceCache.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 this->validate(); 230 this->validate();
231 } 231 }
232 return resource; 232 return resource;
233 } 233 }
234 234
235 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { 235 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) {
236 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); 236 SkASSERT(resource->resourcePriv().getScratchKey().isValid());
237 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); 237 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
238 } 238 }
239 239
240 void GrResourceCache::willRemoveUniqueKey(const GrGpuResource* resource) { 240 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) {
241 // Someone has a ref to this resource in order to invalidate it. When the re f count reaches 241 // Someone has a ref to this resource in order to invalidate it. When the re f count reaches
242 // zero we will get a notifyPurgable() and figure out what to do with it. 242 // zero we will get a notifyPurgable() and figure out what to do with it.
243 SkASSERT(resource->getUniqueKey().isValid()); 243 if (resource->getUniqueKey().isValid()) {
244 fUniqueHash.remove(resource->getUniqueKey()); 244 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
245 fUniqueHash.remove(resource->getUniqueKey());
246 }
247 resource->cacheAccess().removeUniqueKey();
248 this->validate();
245 } 249 }
246 250
247 bool GrResourceCache::didSetUniqueKey(GrGpuResource* resource) { 251 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey & newKey) {
248 SkASSERT(resource); 252 SkASSERT(resource);
249 SkASSERT(this->isInCache(resource)); 253 SkASSERT(this->isInCache(resource));
250 SkASSERT(resource->getUniqueKey().isValid());
251 254
252 GrGpuResource* res = fUniqueHash.find(resource->getUniqueKey()); 255 // Remove the entry for this resource if it already has a unique key.
253 if (NULL != res) { 256 if (resource->getUniqueKey().isValid()) {
254 return false; 257 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
258 fUniqueHash.remove(resource->getUniqueKey());
259 SkASSERT(NULL == fUniqueHash.find(resource->getUniqueKey()));
255 } 260 }
256 261
257 fUniqueHash.add(resource); 262 // If another resource has the new key, remove its key then install the key on this resource.
263 if (newKey.isValid()) {
264 if (GrGpuResource* old = fUniqueHash.find(newKey)) {
265 // If the old resource using the key is purgeable and is unreachable , then remove it.
266 if (!old->resourcePriv().getScratchKey().isValid() && old->isPurgeab le()) {
267 // release may call validate() which will assert that resource i s in fUniqueHash
268 // if it has a valid key. So in debug reset the key here before we assign it.
269 SkDEBUGCODE(resource->cacheAccess().removeUniqueKey();)
270 old->cacheAccess().release();
271 } else {
272 fUniqueHash.remove(newKey);
273 old->cacheAccess().removeUniqueKey();
274 }
275 }
276 SkASSERT(NULL == fUniqueHash.find(newKey));
277 resource->cacheAccess().setUniqueKey(newKey);
278 fUniqueHash.add(resource);
279 } else {
280 resource->cacheAccess().removeUniqueKey();
281 }
282
258 this->validate(); 283 this->validate();
259 return true;
260 } 284 }
261 285
262 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { 286 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) {
263 SkASSERT(resource); 287 SkASSERT(resource);
264 SkASSERT(this->isInCache(resource)); 288 SkASSERT(this->isInCache(resource));
265 if (resource->isPurgeable()) { 289 if (resource->isPurgeable()) {
266 // It's about to become unpurgeable. 290 // It's about to become unpurgeable.
267 fPurgeableQueue.remove(resource); 291 fPurgeableQueue.remove(resource);
268 this->addToNonpurgeableArray(resource); 292 this->addToNonpurgeableArray(resource);
269 } 293 }
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 return true; 548 return true;
525 } 549 }
526 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { 550 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) {
527 return true; 551 return true;
528 } 552 }
529 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che."); 553 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che.");
530 return false; 554 return false;
531 } 555 }
532 556
533 #endif 557 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698