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

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

Issue 22850006: Replace uses of GrAssert by SkASSERT. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrResource.cpp ('k') | src/gpu/GrStencil.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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 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 10
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 22
23 return static_cast<ResourceType>(type); 23 return static_cast<ResourceType>(type);
24 } 24 }
25 25
26 /////////////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////////////
27 27
28 GrResourceEntry::GrResourceEntry(const GrResourceKey& key, GrResource* resource) 28 GrResourceEntry::GrResourceEntry(const GrResourceKey& key, GrResource* resource)
29 : fKey(key), fResource(resource) { 29 : fKey(key), fResource(resource) {
30 // we assume ownership of the resource, and will unref it when we die 30 // we assume ownership of the resource, and will unref it when we die
31 GrAssert(resource); 31 SkASSERT(resource);
32 resource->ref(); 32 resource->ref();
33 } 33 }
34 34
35 GrResourceEntry::~GrResourceEntry() { 35 GrResourceEntry::~GrResourceEntry() {
36 fResource->setCacheEntry(NULL); 36 fResource->setCacheEntry(NULL);
37 fResource->unref(); 37 fResource->unref();
38 } 38 }
39 39
40 #if GR_DEBUG 40 #if GR_DEBUG
41 void GrResourceEntry::validate() const { 41 void GrResourceEntry::validate() const {
42 GrAssert(fResource); 42 SkASSERT(fResource);
43 GrAssert(fResource->getCacheEntry() == this); 43 SkASSERT(fResource->getCacheEntry() == this);
44 fResource->validate(); 44 fResource->validate();
45 } 45 }
46 #endif 46 #endif
47 47
48 /////////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////////
49 49
50 GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) : 50 GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) :
51 fMaxCount(maxCount), 51 fMaxCount(maxCount),
52 fMaxBytes(maxBytes) { 52 fMaxBytes(maxBytes) {
53 #if GR_CACHE_STATS 53 #if GR_CACHE_STATS
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 #if GR_CACHE_STATS 119 #if GR_CACHE_STATS
120 if (fHighWaterClientDetachedCount < fClientDetachedCount) { 120 if (fHighWaterClientDetachedCount < fClientDetachedCount) {
121 fHighWaterClientDetachedCount = fClientDetachedCount; 121 fHighWaterClientDetachedCount = fClientDetachedCount;
122 } 122 }
123 if (fHighWaterClientDetachedBytes < fClientDetachedBytes) { 123 if (fHighWaterClientDetachedBytes < fClientDetachedBytes) {
124 fHighWaterClientDetachedBytes = fClientDetachedBytes; 124 fHighWaterClientDetachedBytes = fClientDetachedBytes;
125 } 125 }
126 #endif 126 #endif
127 127
128 } else { 128 } else {
129 GrAssert(kAccountFor_BudgetBehavior == behavior); 129 SkASSERT(kAccountFor_BudgetBehavior == behavior);
130 130
131 fEntryCount -= 1; 131 fEntryCount -= 1;
132 fEntryBytes -= entry->resource()->sizeInBytes(); 132 fEntryBytes -= entry->resource()->sizeInBytes();
133 } 133 }
134 } 134 }
135 135
136 void GrResourceCache::attachToHead(GrResourceEntry* entry, 136 void GrResourceCache::attachToHead(GrResourceEntry* entry,
137 BudgetBehaviors behavior) { 137 BudgetBehaviors behavior) {
138 fList.addToHead(entry); 138 fList.addToHead(entry);
139 139
140 // update our stats 140 // update our stats
141 if (kIgnore_BudgetBehavior == behavior) { 141 if (kIgnore_BudgetBehavior == behavior) {
142 fClientDetachedCount -= 1; 142 fClientDetachedCount -= 1;
143 fClientDetachedBytes -= entry->resource()->sizeInBytes(); 143 fClientDetachedBytes -= entry->resource()->sizeInBytes();
144 } else { 144 } else {
145 GrAssert(kAccountFor_BudgetBehavior == behavior); 145 SkASSERT(kAccountFor_BudgetBehavior == behavior);
146 146
147 fEntryCount += 1; 147 fEntryCount += 1;
148 fEntryBytes += entry->resource()->sizeInBytes(); 148 fEntryBytes += entry->resource()->sizeInBytes();
149 149
150 #if GR_CACHE_STATS 150 #if GR_CACHE_STATS
151 if (fHighWaterEntryCount < fEntryCount) { 151 if (fHighWaterEntryCount < fEntryCount) {
152 fHighWaterEntryCount = fEntryCount; 152 fHighWaterEntryCount = fEntryCount;
153 } 153 }
154 if (fHighWaterEntryBytes < fEntryBytes) { 154 if (fHighWaterEntryBytes < fEntryBytes) {
155 fHighWaterEntryBytes = fEntryBytes; 155 fHighWaterEntryBytes = fEntryBytes;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 this->internalDetach(entry); 192 this->internalDetach(entry);
193 this->attachToHead(entry); 193 this->attachToHead(entry);
194 } 194 }
195 195
196 return entry->fResource; 196 return entry->fResource;
197 } 197 }
198 198
199 void GrResourceCache::addResource(const GrResourceKey& key, 199 void GrResourceCache::addResource(const GrResourceKey& key,
200 GrResource* resource, 200 GrResource* resource,
201 uint32_t ownershipFlags) { 201 uint32_t ownershipFlags) {
202 GrAssert(NULL == resource->getCacheEntry()); 202 SkASSERT(NULL == resource->getCacheEntry());
203 // we don't expect to create new resources during a purge. In theory 203 // we don't expect to create new resources during a purge. In theory
204 // this could cause purgeAsNeeded() into an infinite loop (e.g. 204 // this could cause purgeAsNeeded() into an infinite loop (e.g.
205 // each resource destroyed creates and locks 2 resources and 205 // each resource destroyed creates and locks 2 resources and
206 // unlocks 1 thereby causing a new purge). 206 // unlocks 1 thereby causing a new purge).
207 GrAssert(!fPurging); 207 SkASSERT(!fPurging);
208 GrAutoResourceCacheValidate atcv(this); 208 GrAutoResourceCacheValidate atcv(this);
209 209
210 GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource)); 210 GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource));
211 resource->setCacheEntry(entry); 211 resource->setCacheEntry(entry);
212 212
213 this->attachToHead(entry); 213 this->attachToHead(entry);
214 fCache.insert(key, entry); 214 fCache.insert(key, entry);
215 215
216 if (ownershipFlags & kHide_OwnershipFlag) { 216 if (ownershipFlags & kHide_OwnershipFlag) {
217 this->makeExclusive(entry); 217 this->makeExclusive(entry);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // release some resources and purge again. 292 // release some resources and purge again.
293 if ((*fOverbudgetCB)(fOverbudgetData)) { 293 if ((*fOverbudgetCB)(fOverbudgetData)) {
294 this->internalPurge(extraCount, extraBytes); 294 this->internalPurge(extraCount, extraBytes);
295 } 295 }
296 } 296 }
297 297
298 fPurging = false; 298 fPurging = false;
299 } 299 }
300 300
301 void GrResourceCache::deleteResource(GrResourceEntry* entry) { 301 void GrResourceCache::deleteResource(GrResourceEntry* entry) {
302 GrAssert(1 == entry->fResource->getRefCnt()); 302 SkASSERT(1 == entry->fResource->getRefCnt());
303 303
304 // remove from our cache 304 // remove from our cache
305 fCache.remove(entry->key(), entry); 305 fCache.remove(entry->key(), entry);
306 306
307 // remove from our llist 307 // remove from our llist
308 this->internalDetach(entry); 308 this->internalDetach(entry);
309 delete entry; 309 delete entry;
310 } 310 }
311 311
312 void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) { 312 void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // so we don't want to just do a simple loop kicking each 354 // so we don't want to just do a simple loop kicking each
355 // entry out. Instead change the budget and purge. 355 // entry out. Instead change the budget and purge.
356 356
357 int savedMaxBytes = fMaxBytes; 357 int savedMaxBytes = fMaxBytes;
358 int savedMaxCount = fMaxCount; 358 int savedMaxCount = fMaxCount;
359 fMaxBytes = (size_t) -1; 359 fMaxBytes = (size_t) -1;
360 fMaxCount = 0; 360 fMaxCount = 0;
361 this->purgeAsNeeded(); 361 this->purgeAsNeeded();
362 362
363 #if GR_DEBUG 363 #if GR_DEBUG
364 GrAssert(fExclusiveList.countEntries() == fClientDetachedCount); 364 SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount);
365 GrAssert(countBytes(fExclusiveList) == fClientDetachedBytes); 365 SkASSERT(countBytes(fExclusiveList) == fClientDetachedBytes);
366 if (!fCache.count()) { 366 if (!fCache.count()) {
367 // Items may have been detached from the cache (such as the backing 367 // Items may have been detached from the cache (such as the backing
368 // texture for an SkGpuDevice). The above purge would not have removed 368 // texture for an SkGpuDevice). The above purge would not have removed
369 // them. 369 // them.
370 GrAssert(fEntryCount == fClientDetachedCount); 370 SkASSERT(fEntryCount == fClientDetachedCount);
371 GrAssert(fEntryBytes == fClientDetachedBytes); 371 SkASSERT(fEntryBytes == fClientDetachedBytes);
372 GrAssert(fList.isEmpty()); 372 SkASSERT(fList.isEmpty());
373 } 373 }
374 #endif 374 #endif
375 375
376 fMaxBytes = savedMaxBytes; 376 fMaxBytes = savedMaxBytes;
377 fMaxCount = savedMaxCount; 377 fMaxCount = savedMaxCount;
378 } 378 }
379 379
380 /////////////////////////////////////////////////////////////////////////////// 380 ///////////////////////////////////////////////////////////////////////////////
381 381
382 #if GR_DEBUG 382 #if GR_DEBUG
(...skipping 11 matching lines...) Expand all
394 return bytes; 394 return bytes;
395 } 395 }
396 396
397 static bool both_zero_or_nonzero(int count, size_t bytes) { 397 static bool both_zero_or_nonzero(int count, size_t bytes) {
398 return (count == 0 && bytes == 0) || (count > 0 && bytes > 0); 398 return (count == 0 && bytes == 0) || (count > 0 && bytes > 0);
399 } 399 }
400 400
401 void GrResourceCache::validate() const { 401 void GrResourceCache::validate() const {
402 fList.validate(); 402 fList.validate();
403 fExclusiveList.validate(); 403 fExclusiveList.validate();
404 GrAssert(both_zero_or_nonzero(fEntryCount, fEntryBytes)); 404 SkASSERT(both_zero_or_nonzero(fEntryCount, fEntryBytes));
405 GrAssert(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes)); 405 SkASSERT(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes));
406 GrAssert(fClientDetachedBytes <= fEntryBytes); 406 SkASSERT(fClientDetachedBytes <= fEntryBytes);
407 GrAssert(fClientDetachedCount <= fEntryCount); 407 SkASSERT(fClientDetachedCount <= fEntryCount);
408 GrAssert((fEntryCount - fClientDetachedCount) == fCache.count()); 408 SkASSERT((fEntryCount - fClientDetachedCount) == fCache.count());
409 409
410 fCache.validate(); 410 fCache.validate();
411 411
412 412
413 EntryList::Iter iter; 413 EntryList::Iter iter;
414 414
415 // check that the exclusively held entries are okay 415 // check that the exclusively held entries are okay
416 const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveLi st), 416 const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveLi st),
417 EntryList::Iter::kHead_IterStart); 417 EntryList::Iter::kHead_IterStart);
418 418
419 for ( ; NULL != entry; entry = iter.next()) { 419 for ( ; NULL != entry; entry = iter.next()) {
420 entry->validate(); 420 entry->validate();
421 } 421 }
422 422
423 // check that the shareable entries are okay 423 // check that the shareable entries are okay
424 entry = iter.init(const_cast<EntryList&>(fList), EntryList::Iter::kHead_Iter Start); 424 entry = iter.init(const_cast<EntryList&>(fList), EntryList::Iter::kHead_Iter Start);
425 425
426 int count = 0; 426 int count = 0;
427 for ( ; NULL != entry; entry = iter.next()) { 427 for ( ; NULL != entry; entry = iter.next()) {
428 entry->validate(); 428 entry->validate();
429 GrAssert(fCache.find(entry->key())); 429 SkASSERT(fCache.find(entry->key()));
430 count += 1; 430 count += 1;
431 } 431 }
432 GrAssert(count == fEntryCount - fClientDetachedCount); 432 SkASSERT(count == fEntryCount - fClientDetachedCount);
433 433
434 size_t bytes = countBytes(fList); 434 size_t bytes = countBytes(fList);
435 GrAssert(bytes == fEntryBytes - fClientDetachedBytes); 435 SkASSERT(bytes == fEntryBytes - fClientDetachedBytes);
436 436
437 bytes = countBytes(fExclusiveList); 437 bytes = countBytes(fExclusiveList);
438 GrAssert(bytes == fClientDetachedBytes); 438 SkASSERT(bytes == fClientDetachedBytes);
439 439
440 GrAssert(fList.countEntries() == fEntryCount - fClientDetachedCount); 440 SkASSERT(fList.countEntries() == fEntryCount - fClientDetachedCount);
441 441
442 GrAssert(fExclusiveList.countEntries() == fClientDetachedCount); 442 SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount);
443 } 443 }
444 #endif // GR_DEBUG 444 #endif // GR_DEBUG
445 445
446 #if GR_CACHE_STATS 446 #if GR_CACHE_STATS
447 447
448 void GrResourceCache::printStats() { 448 void GrResourceCache::printStats() {
449 int locked = 0; 449 int locked = 0;
450 450
451 EntryList::Iter iter; 451 EntryList::Iter iter;
452 452
(...skipping 12 matching lines...) Expand all
465 fEntryBytes, fHighWaterEntryBytes); 465 fEntryBytes, fHighWaterEntryBytes);
466 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", 466 SkDebugf("\t\tDetached Entry Count: current %d high %d\n",
467 fClientDetachedCount, fHighWaterClientDetachedCount); 467 fClientDetachedCount, fHighWaterClientDetachedCount);
468 SkDebugf("\t\tDetached Bytes: current %d high %d\n", 468 SkDebugf("\t\tDetached Bytes: current %d high %d\n",
469 fClientDetachedBytes, fHighWaterClientDetachedBytes); 469 fClientDetachedBytes, fHighWaterClientDetachedBytes);
470 } 470 }
471 471
472 #endif 472 #endif
473 473
474 /////////////////////////////////////////////////////////////////////////////// 474 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/gpu/GrResource.cpp ('k') | src/gpu/GrStencil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698