| OLD | NEW |
| 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 #if SK_SUPPORT_GPU | 8 #if SK_SUPPORT_GPU |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 TestResource(GrGpu* gpu) | 77 TestResource(GrGpu* gpu) |
| 78 : INHERITED(gpu, false) | 78 : INHERITED(gpu, false) |
| 79 , fToDelete(NULL) | 79 , fToDelete(NULL) |
| 80 , fSize(kDefaultSize) { | 80 , fSize(kDefaultSize) { |
| 81 ++fNumAlive; | 81 ++fNumAlive; |
| 82 this->registerWithCache(); | 82 this->registerWithCache(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 TestResource(GrGpu* gpu, const GrResourceKey& scratchKey) | 85 TestResource(GrGpu* gpu, const GrScratchKey& scratchKey) |
| 86 : INHERITED(gpu, false) | 86 : INHERITED(gpu, false) |
| 87 , fToDelete(NULL) | 87 , fToDelete(NULL) |
| 88 , fSize(kDefaultSize) { | 88 , fSize(kDefaultSize) { |
| 89 this->setScratchKey(scratchKey); | 89 this->setScratchKey(scratchKey); |
| 90 ++fNumAlive; | 90 ++fNumAlive; |
| 91 this->registerWithCache(); | 91 this->registerWithCache(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 ~TestResource() { | 94 ~TestResource() { |
| 95 --fNumAlive; | 95 --fNumAlive; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); | 166 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 167 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); | 167 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); |
| 168 REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes()); | 168 REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes()); |
| 169 | 169 |
| 170 b->unref(); | 170 b->unref(); |
| 171 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); | 171 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 172 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); | 172 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); |
| 173 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); | 173 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 static void make_scratch_key(GrScratchKey* key) { |
| 177 static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType(); |
| 178 GrScratchKey::Builder builder(key, t, 0); |
| 179 } |
| 180 |
| 176 static void test_budgeting(skiatest::Reporter* reporter) { | 181 static void test_budgeting(skiatest::Reporter* reporter) { |
| 177 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 182 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 178 REPORTER_ASSERT(reporter, SkToBool(context)); | 183 REPORTER_ASSERT(reporter, SkToBool(context)); |
| 179 if (NULL == context) { | 184 if (NULL == context) { |
| 180 return; | 185 return; |
| 181 } | 186 } |
| 182 context->setResourceCacheLimits(10, 300); | 187 context->setResourceCacheLimits(10, 300); |
| 183 GrResourceCache2* cache2 = context->getResourceCache2(); | 188 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 184 cache2->purgeAllUnlocked(); | 189 cache2->purgeAllUnlocked(); |
| 185 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; | 190 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; |
| 186 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted
ResourceBytes()); | 191 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted
ResourceBytes()); |
| 187 | 192 |
| 193 GrScratchKey scratchKey; |
| 194 make_scratch_key(&scratchKey); |
| 195 |
| 188 GrCacheID::Key keyData; | 196 GrCacheID::Key keyData; |
| 189 memset(&keyData, 0, sizeof(keyData)); | 197 memset(&keyData, 0, sizeof(keyData)); |
| 190 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | 198 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0)
; |
| 191 GrResourceKey scratchKey(GrCacheID(GrResourceKey::ScratchDomain(), keyData),
t, 0); | |
| 192 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), t,
0); | |
| 193 | 199 |
| 194 // Create a scratch, a content, and a wrapped resource | 200 // Create a scratch, a content, and a wrapped resource |
| 195 TestResource* scratch = new TestResource(context->getGpu(), scratchKey); | 201 TestResource* scratch = new TestResource(context->getGpu(), scratchKey); |
| 196 scratch->setSize(10); | 202 scratch->setSize(10); |
| 197 TestResource* content = new TestResource(context->getGpu()); | 203 TestResource* content = new TestResource(context->getGpu()); |
| 198 scratch->setSize(11); | 204 scratch->setSize(11); |
| 199 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); | 205 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); |
| 200 TestResource* wrapped = new TestResource(context->getGpu(), true); | 206 TestResource* wrapped = new TestResource(context->getGpu(), true); |
| 201 scratch->setSize(12); | 207 scratch->setSize(12); |
| 202 TestResource* unbudgeted = new TestResource(context->getGpu()); | 208 TestResource* unbudgeted = new TestResource(context->getGpu()); |
| 203 unbudgeted->setSize(13); | 209 unbudgeted->setSize(13); |
| 204 unbudgeted->cacheAccess().setBudgeted(false); | 210 unbudgeted->cacheAccess().setBudgeted(false); |
| 205 | 211 |
| 206 // Make sure we can't add a content key to the wrapped resource | 212 // Make sure we can't add a content key to the wrapped resource |
| 207 keyData.fData8[0] = 1; | 213 keyData.fData8[0] = 1; |
| 208 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), t
, 0); | 214 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0
); |
| 209 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2)
); | 215 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2)
); |
| 210 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK
ey2)); | 216 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK
ey2)); |
| 211 | 217 |
| 212 // Make sure sizes are as we expect | 218 // Make sure sizes are as we expect |
| 213 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount()); | 219 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount()); |
| 214 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize(
) + | 220 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize(
) + |
| 215 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi
ze() == | 221 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi
ze() == |
| 216 cache2->getResourceBytes()); | 222 cache2->getResourceBytes()); |
| 217 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount()); | 223 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount()); |
| 218 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize(
) == | 224 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize(
) == |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 276 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 271 REPORTER_ASSERT(reporter, SkToBool(context)); | 277 REPORTER_ASSERT(reporter, SkToBool(context)); |
| 272 if (NULL == context) { | 278 if (NULL == context) { |
| 273 return; | 279 return; |
| 274 } | 280 } |
| 275 context->setResourceCacheLimits(5, 30000); | 281 context->setResourceCacheLimits(5, 30000); |
| 276 GrResourceCache2* cache2 = context->getResourceCache2(); | 282 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 277 cache2->purgeAllUnlocked(); | 283 cache2->purgeAllUnlocked(); |
| 278 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; | 284 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; |
| 279 | 285 |
| 280 GrCacheID::Key keyData; | 286 GrScratchKey scratchKey; |
| 281 memset(&keyData, 0, sizeof(keyData)); | 287 make_scratch_key(&scratchKey); |
| 282 GrCacheID::Domain domain = GrResourceKey::ScratchDomain(); | |
| 283 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | |
| 284 GrResourceKey scratchKey(GrCacheID(domain, keyData), t, 0); | |
| 285 | 288 |
| 286 // Create two resources that have the same scratch key. | 289 // Create two resources that have the same scratch key. |
| 287 TestResource* a = new TestResource(context->getGpu(), scratchKey); | 290 TestResource* a = new TestResource(context->getGpu(), scratchKey); |
| 288 TestResource* b = new TestResource(context->getGpu(), scratchKey); | 291 TestResource* b = new TestResource(context->getGpu(), scratchKey); |
| 289 a->setSize(11); | 292 a->setSize(11); |
| 290 b->setSize(12); | 293 b->setSize(12); |
| 291 // Scratch resources are registered with GrResourceCache2 just by existing.
There are 2. | 294 // Scratch resources are registered with GrResourceCache2 just by existing.
There are 2. |
| 292 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); | 295 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 293 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey
(scratchKey));) | 296 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey
(scratchKey));) |
| 294 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); | 297 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 317 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 320 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 318 REPORTER_ASSERT(reporter, SkToBool(context)); | 321 REPORTER_ASSERT(reporter, SkToBool(context)); |
| 319 if (NULL == context) { | 322 if (NULL == context) { |
| 320 return; | 323 return; |
| 321 } | 324 } |
| 322 context->setResourceCacheLimits(5, 30000); | 325 context->setResourceCacheLimits(5, 30000); |
| 323 GrResourceCache2* cache2 = context->getResourceCache2(); | 326 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 324 cache2->purgeAllUnlocked(); | 327 cache2->purgeAllUnlocked(); |
| 325 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; | 328 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; |
| 326 | 329 |
| 327 GrCacheID::Key keyData; | 330 GrScratchKey scratchKey; |
| 328 memset(&keyData, 0, sizeof(keyData)); | 331 make_scratch_key(&scratchKey); |
| 329 GrCacheID::Domain domain = GrResourceKey::ScratchDomain(); | |
| 330 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | |
| 331 GrResourceKey scratchKey(GrCacheID(domain, keyData), t, 0); | |
| 332 | 332 |
| 333 // Create two resources that have the same scratch key. | 333 // Create two resources that have the same scratch key. |
| 334 TestResource* a = new TestResource(context->getGpu(), scratchKey); | 334 TestResource* a = new TestResource(context->getGpu(), scratchKey); |
| 335 TestResource* b = new TestResource(context->getGpu(), scratchKey); | 335 TestResource* b = new TestResource(context->getGpu(), scratchKey); |
| 336 a->unref(); | 336 a->unref(); |
| 337 b->unref(); | 337 b->unref(); |
| 338 | 338 |
| 339 // Scratch resources are registered with GrResourceCache2 just by existing.
There are 2. | 339 // Scratch resources are registered with GrResourceCache2 just by existing.
There are 2. |
| 340 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); | 340 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 341 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey
(scratchKey));) | 341 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey
(scratchKey));) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 return; | 382 return; |
| 383 } | 383 } |
| 384 context->setResourceCacheLimits(5, 30000); | 384 context->setResourceCacheLimits(5, 30000); |
| 385 GrResourceCache2* cache2 = context->getResourceCache2(); | 385 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 386 cache2->purgeAllUnlocked(); | 386 cache2->purgeAllUnlocked(); |
| 387 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; | 387 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; |
| 388 | 388 |
| 389 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); | 389 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 390 GrCacheID::Key keyData; | 390 GrCacheID::Key keyData; |
| 391 memset(&keyData, 0, sizeof(keyData)); | 391 memset(&keyData, 0, sizeof(keyData)); |
| 392 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | 392 GrResourceKey key(GrCacheID(domain, keyData), 0); |
| 393 GrResourceKey key(GrCacheID(domain, keyData), t, 0); | |
| 394 | 393 |
| 395 // Create two resources that we will attempt to register with the same conte
nt key. | 394 // Create two resources that we will attempt to register with the same conte
nt key. |
| 396 TestResource* a = new TestResource(context->getGpu()); | 395 TestResource* a = new TestResource(context->getGpu()); |
| 397 TestResource* b = new TestResource(context->getGpu()); | 396 TestResource* b = new TestResource(context->getGpu()); |
| 398 a->setSize(11); | 397 a->setSize(11); |
| 399 b->setSize(12); | 398 b->setSize(12); |
| 400 | 399 |
| 401 // Can't set the same content key on two resources. | 400 // Can't set the same content key on two resources. |
| 402 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key)); | 401 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key)); |
| 403 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key)); | 402 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 434 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 436 REPORTER_ASSERT(reporter, SkToBool(context)); | 435 REPORTER_ASSERT(reporter, SkToBool(context)); |
| 437 if (NULL == context) { | 436 if (NULL == context) { |
| 438 return; | 437 return; |
| 439 } | 438 } |
| 440 | 439 |
| 441 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); | 440 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 442 GrCacheID::Key keyData; | 441 GrCacheID::Key keyData; |
| 443 memset(&keyData, 0, sizeof(keyData)); | 442 memset(&keyData, 0, sizeof(keyData)); |
| 444 | 443 |
| 445 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | |
| 446 | |
| 447 keyData.fData64[0] = 1; | 444 keyData.fData64[0] = 1; |
| 448 GrResourceKey key1(GrCacheID(domain, keyData), t, 0); | 445 GrResourceKey key1(GrCacheID(domain, keyData), 0); |
| 449 keyData.fData64[0] = 2; | 446 keyData.fData64[0] = 2; |
| 450 GrResourceKey key2(GrCacheID(domain, keyData), t, 0); | 447 GrResourceKey key2(GrCacheID(domain, keyData), 0); |
| 451 keyData.fData64[0] = 3; | 448 keyData.fData64[0] = 3; |
| 452 GrResourceKey key3(GrCacheID(domain, keyData), t, 0); | 449 GrResourceKey key3(GrCacheID(domain, keyData), 0); |
| 453 | 450 |
| 454 context->setResourceCacheLimits(5, 30000); | 451 context->setResourceCacheLimits(5, 30000); |
| 455 GrResourceCache2* cache2 = context->getResourceCache2(); | 452 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 456 cache2->purgeAllUnlocked(); | 453 cache2->purgeAllUnlocked(); |
| 457 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; | 454 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; |
| 458 | 455 |
| 459 // Add three resources to the cache. | 456 // Add three resources to the cache. |
| 460 TestResource* a = new TestResource(context->getGpu()); | 457 TestResource* a = new TestResource(context->getGpu()); |
| 461 TestResource* b = new TestResource(context->getGpu()); | 458 TestResource* b = new TestResource(context->getGpu()); |
| 462 TestResource* c = new TestResource(context->getGpu()); | 459 TestResource* c = new TestResource(context->getGpu()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 static void test_cache_chained_purge(skiatest::Reporter* reporter) { | 500 static void test_cache_chained_purge(skiatest::Reporter* reporter) { |
| 504 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 501 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 505 REPORTER_ASSERT(reporter, SkToBool(context)); | 502 REPORTER_ASSERT(reporter, SkToBool(context)); |
| 506 if (NULL == context) { | 503 if (NULL == context) { |
| 507 return; | 504 return; |
| 508 } | 505 } |
| 509 | 506 |
| 510 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); | 507 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 511 GrCacheID::Key keyData; | 508 GrCacheID::Key keyData; |
| 512 memset(&keyData, 0, sizeof(keyData)); | 509 memset(&keyData, 0, sizeof(keyData)); |
| 513 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | |
| 514 | 510 |
| 515 keyData.fData64[0] = 1; | 511 keyData.fData64[0] = 1; |
| 516 GrResourceKey key1(GrCacheID(domain, keyData), t, 0); | 512 GrResourceKey key1(GrCacheID(domain, keyData), 0); |
| 517 | 513 |
| 518 keyData.fData64[0] = 2; | 514 keyData.fData64[0] = 2; |
| 519 GrResourceKey key2(GrCacheID(domain, keyData), t, 0); | 515 GrResourceKey key2(GrCacheID(domain, keyData), 0); |
| 520 | 516 |
| 521 { | 517 { |
| 522 context->setResourceCacheLimits(3, 30000); | 518 context->setResourceCacheLimits(3, 30000); |
| 523 GrResourceCache2* cache2 = context->getResourceCache2(); | 519 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 524 cache2->purgeAllUnlocked(); | 520 cache2->purgeAllUnlocked(); |
| 525 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); | 521 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); |
| 526 | 522 |
| 527 TestResource* a = new TestResource(context->getGpu()); | 523 TestResource* a = new TestResource(context->getGpu()); |
| 528 TestResource* b = new TestResource(context->getGpu()); | 524 TestResource* b = new TestResource(context->getGpu()); |
| 529 a->cacheAccess().setContentKey(key1); | 525 a->cacheAccess().setContentKey(key1); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 553 } | 549 } |
| 554 | 550 |
| 555 static void test_resource_size_changed(skiatest::Reporter* reporter) { | 551 static void test_resource_size_changed(skiatest::Reporter* reporter) { |
| 556 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 552 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 557 REPORTER_ASSERT(reporter, SkToBool(context)); | 553 REPORTER_ASSERT(reporter, SkToBool(context)); |
| 558 if (NULL == context) { | 554 if (NULL == context) { |
| 559 return; | 555 return; |
| 560 } | 556 } |
| 561 | 557 |
| 562 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); | 558 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
| 563 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | |
| 564 | 559 |
| 565 GrCacheID::Key key1Data; | 560 GrCacheID::Key key1Data; |
| 566 key1Data.fData64[0] = 0; | 561 key1Data.fData64[0] = 0; |
| 567 key1Data.fData64[1] = 0; | 562 key1Data.fData64[1] = 0; |
| 568 GrResourceKey key1(GrCacheID(domain, key1Data), t, 0); | 563 GrResourceKey key1(GrCacheID(domain, key1Data), 0); |
| 569 | 564 |
| 570 GrCacheID::Key key2Data; | 565 GrCacheID::Key key2Data; |
| 571 key2Data.fData64[0] = 1; | 566 key2Data.fData64[0] = 1; |
| 572 key2Data.fData64[1] = 0; | 567 key2Data.fData64[1] = 0; |
| 573 GrResourceKey key2(GrCacheID(domain, key2Data), t, 0); | 568 GrResourceKey key2(GrCacheID(domain, key2Data), 0); |
| 574 | 569 |
| 575 // Test changing resources sizes (both increase & decrease). | 570 // Test changing resources sizes (both increase & decrease). |
| 576 { | 571 { |
| 577 context->setResourceCacheLimits(3, 30000); | 572 context->setResourceCacheLimits(3, 30000); |
| 578 GrResourceCache2* cache2 = context->getResourceCache2(); | 573 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 579 cache2->purgeAllUnlocked(); | 574 cache2->purgeAllUnlocked(); |
| 580 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); | 575 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); |
| 581 | 576 |
| 582 TestResource* a = new TestResource(context->getGpu()); | 577 TestResource* a = new TestResource(context->getGpu()); |
| 583 a->cacheAccess().setContentKey(key1); | 578 a->cacheAccess().setContentKey(key1); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 // Set the cache size to double the resource count because we're going to cr
eate 2x that number | 637 // Set the cache size to double the resource count because we're going to cr
eate 2x that number |
| 643 // resources, using two different key domains. Add a little slop to the byte
s because we resize | 638 // resources, using two different key domains. Add a little slop to the byte
s because we resize |
| 644 // down to 1 byte after creating the resource. | 639 // down to 1 byte after creating the resource. |
| 645 context->setResourceCacheLimits(2 * kResourceCnt, 2 * kResourceCnt + 1000); | 640 context->setResourceCacheLimits(2 * kResourceCnt, 2 * kResourceCnt + 1000); |
| 646 GrResourceCache2* cache2 = context->getResourceCache2(); | 641 GrResourceCache2* cache2 = context->getResourceCache2(); |
| 647 cache2->purgeAllUnlocked(); | 642 cache2->purgeAllUnlocked(); |
| 648 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; | 643 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes())
; |
| 649 | 644 |
| 650 GrCacheID::Domain domain0 = GrCacheID::GenerateDomain(); | 645 GrCacheID::Domain domain0 = GrCacheID::GenerateDomain(); |
| 651 GrCacheID::Domain domain1 = GrCacheID::GenerateDomain(); | 646 GrCacheID::Domain domain1 = GrCacheID::GenerateDomain(); |
| 652 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | |
| 653 | 647 |
| 654 GrCacheID::Key keyData; | 648 GrCacheID::Key keyData; |
| 655 memset(&keyData, 0, sizeof(keyData)); | 649 memset(&keyData, 0, sizeof(keyData)); |
| 656 | 650 |
| 657 for (int i = 0; i < kResourceCnt; ++i) { | 651 for (int i = 0; i < kResourceCnt; ++i) { |
| 658 TestResource* resource; | 652 TestResource* resource; |
| 659 keyData.fData32[0] = i; | 653 keyData.fData32[0] = i; |
| 660 | 654 |
| 661 GrResourceKey key0(GrCacheID(domain0, keyData), t, 0); | 655 GrResourceKey key0(GrCacheID(domain0, keyData), 0); |
| 662 resource = SkNEW_ARGS(TestResource, (context->getGpu())); | 656 resource = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 663 resource->cacheAccess().setContentKey(key0); | 657 resource->cacheAccess().setContentKey(key0); |
| 664 resource->setSize(1); | 658 resource->setSize(1); |
| 665 resource->unref(); | 659 resource->unref(); |
| 666 | 660 |
| 667 GrResourceKey key1(GrCacheID(domain1, keyData), t, 0); | 661 GrResourceKey key1(GrCacheID(domain1, keyData), 0); |
| 668 resource = SkNEW_ARGS(TestResource, (context->getGpu())); | 662 resource = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 669 resource->cacheAccess().setContentKey(key1); | 663 resource->cacheAccess().setContentKey(key1); |
| 670 resource->setSize(1); | 664 resource->setSize(1); |
| 671 resource->unref(); | 665 resource->unref(); |
| 672 } | 666 } |
| 673 | 667 |
| 674 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt); | 668 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt); |
| 675 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 2 * kResourc
eCnt); | 669 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 2 * kResourc
eCnt); |
| 676 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 2 * kResourc
eCnt); | 670 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 2 * kResourc
eCnt); |
| 677 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 2 * kResourceCnt); | 671 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 2 * kResourceCnt); |
| 678 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 2 * kResourceCnt); | 672 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 2 * kResourceCnt); |
| 679 for (int i = 0; i < kResourceCnt; ++i) { | 673 for (int i = 0; i < kResourceCnt; ++i) { |
| 680 keyData.fData32[0] = i; | 674 keyData.fData32[0] = i; |
| 681 GrResourceKey key0(GrCacheID(domain0, keyData), t, 0); | 675 GrResourceKey key0(GrCacheID(domain0, keyData), 0); |
| 682 REPORTER_ASSERT(reporter, cache2->hasContentKey(key0)); | 676 REPORTER_ASSERT(reporter, cache2->hasContentKey(key0)); |
| 683 GrResourceKey key1(GrCacheID(domain0, keyData), t, 0); | 677 GrResourceKey key1(GrCacheID(domain0, keyData), 0); |
| 684 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1)); | 678 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1)); |
| 685 } | 679 } |
| 686 | 680 |
| 687 cache2->purgeAllUnlocked(); | 681 cache2->purgeAllUnlocked(); |
| 688 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0); | 682 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0); |
| 689 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 0); | 683 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 0); |
| 690 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 0); | 684 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 0); |
| 691 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 0); | 685 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 0); |
| 692 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 0); | 686 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 0); |
| 693 | 687 |
| 694 for (int i = 0; i < kResourceCnt; ++i) { | 688 for (int i = 0; i < kResourceCnt; ++i) { |
| 695 keyData.fData32[0] = i; | 689 keyData.fData32[0] = i; |
| 696 GrResourceKey key0(GrCacheID(domain0, keyData), t, 0); | 690 GrResourceKey key0(GrCacheID(domain0, keyData), 0); |
| 697 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key0)); | 691 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key0)); |
| 698 GrResourceKey key1(GrCacheID(domain0, keyData), t, 0); | 692 GrResourceKey key1(GrCacheID(domain0, keyData), 0); |
| 699 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1)); | 693 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1)); |
| 700 } | 694 } |
| 701 } | 695 } |
| 702 | 696 |
| 703 | 697 |
| 704 //////////////////////////////////////////////////////////////////////////////// | 698 //////////////////////////////////////////////////////////////////////////////// |
| 705 DEF_GPUTEST(ResourceCache, reporter, factory) { | 699 DEF_GPUTEST(ResourceCache, reporter, factory) { |
| 706 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 700 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 707 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 701 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
| 708 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 702 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 728 test_duplicate_content_key(reporter); | 722 test_duplicate_content_key(reporter); |
| 729 test_duplicate_scratch_key(reporter); | 723 test_duplicate_scratch_key(reporter); |
| 730 test_remove_scratch_key(reporter); | 724 test_remove_scratch_key(reporter); |
| 731 test_purge_invalidated(reporter); | 725 test_purge_invalidated(reporter); |
| 732 test_cache_chained_purge(reporter); | 726 test_cache_chained_purge(reporter); |
| 733 test_resource_size_changed(reporter); | 727 test_resource_size_changed(reporter); |
| 734 test_large_resource_count(reporter); | 728 test_large_resource_count(reporter); |
| 735 } | 729 } |
| 736 | 730 |
| 737 #endif | 731 #endif |
| OLD | NEW |