| 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 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. | 8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. |
| 9 #include "SkTypes.h" | 9 #include "SkTypes.h" |
| 10 | 10 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 242 |
| 243 class TestResource : public GrGpuResource { | 243 class TestResource : public GrGpuResource { |
| 244 enum ScratchConstructor { kScratchConstructor }; | 244 enum ScratchConstructor { kScratchConstructor }; |
| 245 public: | 245 public: |
| 246 static const size_t kDefaultSize = 100; | 246 static const size_t kDefaultSize = 100; |
| 247 | 247 |
| 248 /** Property that distinctly categorizes the resource. | 248 /** Property that distinctly categorizes the resource. |
| 249 * For example, textures have width, height, ... */ | 249 * For example, textures have width, height, ... */ |
| 250 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; | 250 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; |
| 251 | 251 |
| 252 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle) | 252 TestResource(GrGpu* gpu, SkBudgeted budgeted = SkBudgeted::kYes, size_t size
= kDefaultSize) |
| 253 : INHERITED(gpu, lifeCycle) | 253 : INHERITED(gpu) |
| 254 , fToDelete(nullptr) | 254 , fToDelete(nullptr) |
| 255 , fSize(size) | 255 , fSize(size) |
| 256 , fProperty(kA_SimulatedProperty) { | 256 , fProperty(kA_SimulatedProperty) |
| 257 , fIsScratch(false) { |
| 257 ++fNumAlive; | 258 ++fNumAlive; |
| 258 this->registerWithCache(); | 259 this->registerWithCache(budgeted); |
| 259 } | 260 } |
| 260 | 261 |
| 261 TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle) | 262 static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted, |
| 262 : INHERITED(gpu, lifeCycle) | 263 SimulatedProperty property) { |
| 263 , fToDelete(nullptr) | 264 return new TestResource(gpu, budgeted, property, kScratchConstructor); |
| 264 , fSize(kDefaultSize) | |
| 265 , fProperty(kA_SimulatedProperty) { | |
| 266 ++fNumAlive; | |
| 267 this->registerWithCache(); | |
| 268 } | 265 } |
| 269 | 266 static TestResource* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) { |
| 270 TestResource(GrGpu* gpu) | 267 return new TestResource(gpu, size); |
| 271 : INHERITED(gpu, kCached_LifeCycle) | |
| 272 , fToDelete(nullptr) | |
| 273 , fSize(kDefaultSize) | |
| 274 , fProperty(kA_SimulatedProperty) { | |
| 275 ++fNumAlive; | |
| 276 this->registerWithCache(); | |
| 277 } | |
| 278 | |
| 279 static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, b
ool cached = true) { | |
| 280 return new TestResource(gpu, property, cached, kScratchConstructor); | |
| 281 } | 268 } |
| 282 | 269 |
| 283 ~TestResource() { | 270 ~TestResource() { |
| 284 --fNumAlive; | 271 --fNumAlive; |
| 285 SkSafeUnref(fToDelete); | 272 SkSafeUnref(fToDelete); |
| 286 } | 273 } |
| 287 | 274 |
| 288 void setSize(size_t size) { | 275 void setSize(size_t size) { |
| 289 fSize = size; | 276 fSize = size; |
| 290 this->didChangeGpuMemorySize(); | 277 this->didChangeGpuMemorySize(); |
| 291 } | 278 } |
| 292 | 279 |
| 293 static int NumAlive() { return fNumAlive; } | 280 static int NumAlive() { return fNumAlive; } |
| 294 | 281 |
| 295 void setUnrefWhenDestroyed(TestResource* resource) { | 282 void setUnrefWhenDestroyed(TestResource* resource) { |
| 296 SkRefCnt_SafeAssign(fToDelete, resource); | 283 SkRefCnt_SafeAssign(fToDelete, resource); |
| 297 } | 284 } |
| 298 | 285 |
| 299 static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key)
{ | 286 static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key)
{ |
| 300 static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType
(); | 287 static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType
(); |
| 301 GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt); | 288 GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt); |
| 302 for (int i = 0; i < kScratchKeyFieldCnt; ++i) { | 289 for (int i = 0; i < kScratchKeyFieldCnt; ++i) { |
| 303 builder[i] = static_cast<uint32_t>(i + property); | 290 builder[i] = static_cast<uint32_t>(i + property); |
| 304 } | 291 } |
| 305 } | 292 } |
| 306 | 293 |
| 307 static size_t ExpectedScratchKeySize() { | 294 static size_t ExpectedScratchKeySize() { |
| 308 return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaData
Cnt); | 295 return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaData
Cnt); |
| 309 } | 296 } |
| 310 | |
| 311 private: | 297 private: |
| 312 static const int kScratchKeyFieldCnt = 6; | 298 static const int kScratchKeyFieldCnt = 6; |
| 313 | 299 |
| 314 TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchCon
structor) | 300 TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, Sc
ratchConstructor) |
| 315 : INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle) | 301 : INHERITED(gpu) |
| 316 , fToDelete(nullptr) | 302 , fToDelete(nullptr) |
| 317 , fSize(kDefaultSize) | 303 , fSize(kDefaultSize) |
| 318 , fProperty(property) { | 304 , fProperty(property) |
| 319 GrScratchKey scratchKey; | 305 , fIsScratch(true) { |
| 320 ComputeScratchKey(fProperty, &scratchKey); | |
| 321 this->setScratchKey(scratchKey); | |
| 322 ++fNumAlive; | 306 ++fNumAlive; |
| 323 this->registerWithCache(); | 307 this->registerWithCache(budgeted); |
| 308 } |
| 309 |
| 310 // Constructor for simulating resources that wrap backend objects. |
| 311 TestResource(GrGpu* gpu, size_t size) |
| 312 : INHERITED(gpu) |
| 313 , fToDelete(nullptr) |
| 314 , fSize(size) |
| 315 , fProperty(kA_SimulatedProperty) |
| 316 , fIsScratch(false) { |
| 317 ++fNumAlive; |
| 318 this->registerWithCacheWrapped(); |
| 319 } |
| 320 |
| 321 void computeScratchKey(GrScratchKey* key) const override { |
| 322 if (fIsScratch) { |
| 323 ComputeScratchKey(fProperty, key); |
| 324 } |
| 324 } | 325 } |
| 325 | 326 |
| 326 size_t onGpuMemorySize() const override { return fSize; } | 327 size_t onGpuMemorySize() const override { return fSize; } |
| 327 | 328 |
| 328 TestResource* fToDelete; | 329 TestResource* fToDelete; |
| 329 size_t fSize; | 330 size_t fSize; |
| 330 static int fNumAlive; | 331 static int fNumAlive; |
| 331 SimulatedProperty fProperty; | 332 SimulatedProperty fProperty; |
| 333 bool fIsScratch; |
| 332 typedef GrGpuResource INHERITED; | 334 typedef GrGpuResource INHERITED; |
| 333 }; | 335 }; |
| 334 int TestResource::fNumAlive = 0; | 336 int TestResource::fNumAlive = 0; |
| 335 | 337 |
| 336 class Mock { | 338 class Mock { |
| 337 public: | 339 public: |
| 338 Mock(int maxCnt, size_t maxBytes) { | 340 Mock(int maxCnt, size_t maxBytes) { |
| 339 fContext.reset(GrContext::CreateMockContext()); | 341 fContext.reset(GrContext::CreateMockContext()); |
| 340 SkASSERT(fContext); | 342 SkASSERT(fContext); |
| 341 fContext->setResourceCacheLimits(maxCnt, maxBytes); | 343 fContext->setResourceCacheLimits(maxCnt, maxBytes); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 static void test_budgeting(skiatest::Reporter* reporter) { | 413 static void test_budgeting(skiatest::Reporter* reporter) { |
| 412 Mock mock(10, 300); | 414 Mock mock(10, 300); |
| 413 GrContext* context = mock.context(); | 415 GrContext* context = mock.context(); |
| 414 GrResourceCache* cache = mock.cache(); | 416 GrResourceCache* cache = mock.cache(); |
| 415 | 417 |
| 416 GrUniqueKey uniqueKey; | 418 GrUniqueKey uniqueKey; |
| 417 make_unique_key<0>(&uniqueKey, 0); | 419 make_unique_key<0>(&uniqueKey, 0); |
| 418 | 420 |
| 419 // Create a scratch, a unique, and a wrapped resource | 421 // Create a scratch, a unique, and a wrapped resource |
| 420 TestResource* scratch = | 422 TestResource* scratch = |
| 421 TestResource::CreateScratch(context->getGpu(), TestResource::kB_Simu
latedProperty); | 423 TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, Tes
tResource::kB_SimulatedProperty); |
| 422 scratch->setSize(10); | 424 scratch->setSize(10); |
| 423 TestResource* unique = new TestResource(context->getGpu()); | 425 TestResource* unique = new TestResource(context->getGpu()); |
| 424 unique->setSize(11); | 426 unique->setSize(11); |
| 425 unique->resourcePriv().setUniqueKey(uniqueKey); | 427 unique->resourcePriv().setUniqueKey(uniqueKey); |
| 426 TestResource* wrapped = new TestResource(context->getGpu(), GrGpuResource::k
Borrowed_LifeCycle); | 428 TestResource* wrapped = TestResource::CreateWrapped(context->getGpu()); |
| 427 wrapped->setSize(12); | 429 wrapped->setSize(12); |
| 428 TestResource* unbudgeted = | 430 TestResource* unbudgeted = |
| 429 new TestResource(context->getGpu(), GrGpuResource::kUncached_LifeCyc
le); | 431 new TestResource(context->getGpu(), SkBudgeted::kNo); |
| 430 unbudgeted->setSize(13); | 432 unbudgeted->setSize(13); |
| 431 | 433 |
| 432 // Make sure we can't add a unique key to the wrapped resource | 434 // Make sure we can't add a unique key to the wrapped resource |
| 433 GrUniqueKey uniqueKey2; | 435 GrUniqueKey uniqueKey2; |
| 434 make_unique_key<0>(&uniqueKey2, 1); | 436 make_unique_key<0>(&uniqueKey2, 1); |
| 435 wrapped->resourcePriv().setUniqueKey(uniqueKey2); | 437 wrapped->resourcePriv().setUniqueKey(uniqueKey2); |
| 436 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefUniqueResource(uniqueK
ey2)); | 438 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefUniqueResource(uniqueK
ey2)); |
| 437 | 439 |
| 438 // Make sure sizes are as we expect | 440 // Make sure sizes are as we expect |
| 439 REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); | 441 REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 454 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize()
== | 456 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize()
== |
| 455 cache->getBudgetedResourceBytes()); | 457 cache->getBudgetedResourceBytes()); |
| 456 | 458 |
| 457 // Unreffing the wrapped resource should free it right away. | 459 // Unreffing the wrapped resource should free it right away. |
| 458 wrapped->unref(); | 460 wrapped->unref(); |
| 459 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); | 461 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 460 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize()
+ | 462 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize()
+ |
| 461 unbudgeted->gpuMemorySize() == cache->getResourceB
ytes()); | 463 unbudgeted->gpuMemorySize() == cache->getResourceB
ytes()); |
| 462 | 464 |
| 463 // Now try freeing the budgeted resources first | 465 // Now try freeing the budgeted resources first |
| 464 wrapped = new TestResource(context->getGpu(), GrGpuResource::kBorrowed_LifeC
ycle); | 466 wrapped = TestResource::CreateWrapped(context->getGpu()); |
| 465 scratch->setSize(12); | 467 scratch->setSize(12); |
| 466 unique->unref(); | 468 unique->unref(); |
| 467 cache->purgeAllUnlocked(); | 469 cache->purgeAllUnlocked(); |
| 468 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); | 470 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 469 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize(
) + | 471 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize(
) + |
| 470 unbudgeted->gpuMemorySize() == cache->getResourceB
ytes()); | 472 unbudgeted->gpuMemorySize() == cache->getResourceB
ytes()); |
| 471 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); | 473 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 472 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedReso
urceBytes()); | 474 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedReso
urceBytes()); |
| 473 | 475 |
| 474 scratch->unref(); | 476 scratch->unref(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 499 | 501 |
| 500 GrUniqueKey uniqueKey; | 502 GrUniqueKey uniqueKey; |
| 501 make_unique_key<0>(&uniqueKey, 0); | 503 make_unique_key<0>(&uniqueKey, 0); |
| 502 | 504 |
| 503 TestResource* scratch; | 505 TestResource* scratch; |
| 504 TestResource* unique; | 506 TestResource* unique; |
| 505 TestResource* wrapped; | 507 TestResource* wrapped; |
| 506 TestResource* unbudgeted; | 508 TestResource* unbudgeted; |
| 507 | 509 |
| 508 // A large uncached or wrapped resource shouldn't evict anything. | 510 // A large uncached or wrapped resource shouldn't evict anything. |
| 509 scratch = TestResource::CreateScratch(context->getGpu(), TestResource::kB_Si
mulatedProperty); | 511 scratch = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, |
| 512 TestResource::kB_SimulatedProperty); |
| 513 |
| 510 scratch->setSize(10); | 514 scratch->setSize(10); |
| 511 scratch->unref(); | 515 scratch->unref(); |
| 512 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); | 516 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 513 REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes()); | 517 REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes()); |
| 514 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); | 518 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 515 REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); | 519 REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); |
| 516 | 520 |
| 517 unique = new TestResource(context->getGpu()); | 521 unique = new TestResource(context->getGpu()); |
| 518 unique->setSize(11); | 522 unique->setSize(11); |
| 519 unique->resourcePriv().setUniqueKey(uniqueKey); | 523 unique->resourcePriv().setUniqueKey(uniqueKey); |
| 520 unique->unref(); | 524 unique->unref(); |
| 521 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); | 525 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 522 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); | 526 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 523 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 527 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 524 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 528 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
| 525 | 529 |
| 526 size_t large = 2 * cache->getResourceBytes(); | 530 size_t large = 2 * cache->getResourceBytes(); |
| 527 unbudgeted = new TestResource(context->getGpu(), large, GrGpuResource::kUnca
ched_LifeCycle); | 531 unbudgeted = new TestResource(context->getGpu(), SkBudgeted::kNo, large); |
| 528 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); | 532 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 529 REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); | 533 REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 530 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 534 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 531 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 535 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
| 532 | 536 |
| 533 unbudgeted->unref(); | 537 unbudgeted->unref(); |
| 534 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); | 538 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 535 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); | 539 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 536 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 540 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 537 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 541 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
| 538 | 542 |
| 539 wrapped = new TestResource(context->getGpu(), large, GrGpuResource::kBorrowe
d_LifeCycle); | 543 wrapped = TestResource::CreateWrapped(context->getGpu(), large); |
| 540 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); | 544 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 541 REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); | 545 REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 542 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 546 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 543 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 547 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
| 544 | 548 |
| 545 wrapped->unref(); | 549 wrapped->unref(); |
| 546 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); | 550 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 547 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); | 551 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 548 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 552 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 549 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 553 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
| 550 | 554 |
| 551 cache->purgeAllUnlocked(); | 555 cache->purgeAllUnlocked(); |
| 552 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 556 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 553 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); | 557 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 554 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); | 558 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 555 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); | 559 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
| 556 } | 560 } |
| 557 | 561 |
| 558 // This method can't be static because it needs to friended in GrGpuResource::Ca
cheAccess. | 562 // This method can't be static because it needs to friended in GrGpuResource::Ca
cheAccess. |
| 559 void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); | 563 void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); |
| 560 /*static*/ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { | 564 /*static*/ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { |
| 561 Mock mock(10, 300); | 565 Mock mock(10, 300); |
| 562 GrContext* context = mock.context(); | 566 GrContext* context = mock.context(); |
| 563 GrResourceCache* cache = mock.cache(); | 567 GrResourceCache* cache = mock.cache(); |
| 564 | 568 |
| 565 TestResource* resource = | 569 TestResource* resource = |
| 566 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate
dProperty, false); | 570 TestResource::CreateScratch(context->getGpu(), SkBudgeted::kNo, |
| 571 TestResource::kA_SimulatedProperty); |
| 567 GrScratchKey key; | 572 GrScratchKey key; |
| 568 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); | 573 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); |
| 569 | 574 |
| 570 size_t size = resource->gpuMemorySize(); | 575 size_t size = resource->gpuMemorySize(); |
| 571 for (int i = 0; i < 2; ++i) { | 576 for (int i = 0; i < 2; ++i) { |
| 572 // Since this resource is unbudgeted, it should not be reachable as scra
tch. | 577 // Since this resource is unbudgeted, it should not be reachable as scra
tch. |
| 573 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke
y); | 578 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke
y); |
| 574 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); | 579 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); |
| 575 REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().is
Budgeted()); | 580 REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().is
Budgeted()); |
| 576 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(ke
y, TestResource::kDefaultSize, 0)); | 581 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(ke
y, TestResource::kDefaultSize, 0)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 } | 621 } |
| 617 } | 622 } |
| 618 | 623 |
| 619 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { | 624 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { |
| 620 Mock mock(5, 30000); | 625 Mock mock(5, 30000); |
| 621 GrContext* context = mock.context(); | 626 GrContext* context = mock.context(); |
| 622 GrResourceCache* cache = mock.cache(); | 627 GrResourceCache* cache = mock.cache(); |
| 623 | 628 |
| 624 // Create two resources that have the same scratch key. | 629 // Create two resources that have the same scratch key. |
| 625 TestResource* a = TestResource::CreateScratch(context->getGpu(), | 630 TestResource* a = TestResource::CreateScratch(context->getGpu(), |
| 631 SkBudgeted::kYes, |
| 626 TestResource::kB_SimulatedProp
erty); | 632 TestResource::kB_SimulatedProp
erty); |
| 627 TestResource* b = TestResource::CreateScratch(context->getGpu(), | 633 TestResource* b = TestResource::CreateScratch(context->getGpu(), |
| 634 SkBudgeted::kYes, |
| 628 TestResource::kB_SimulatedProp
erty); | 635 TestResource::kB_SimulatedProp
erty); |
| 629 a->setSize(11); | 636 a->setSize(11); |
| 630 b->setSize(12); | 637 b->setSize(12); |
| 631 GrScratchKey scratchKey1; | 638 GrScratchKey scratchKey1; |
| 632 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch
Key1); | 639 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch
Key1); |
| 633 // Check for negative case consistency. (leaks upon test failure.) | 640 // Check for negative case consistency. (leaks upon test failure.) |
| 634 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(scratc
hKey1, TestResource::kDefaultSize, 0)); | 641 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(scratc
hKey1, TestResource::kDefaultSize, 0)); |
| 635 | 642 |
| 636 GrScratchKey scratchKey; | 643 GrScratchKey scratchKey; |
| 637 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch
Key); | 644 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch
Key); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 660 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 667 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 661 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(
scratchKey));) | 668 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(
scratchKey));) |
| 662 } | 669 } |
| 663 | 670 |
| 664 static void test_remove_scratch_key(skiatest::Reporter* reporter) { | 671 static void test_remove_scratch_key(skiatest::Reporter* reporter) { |
| 665 Mock mock(5, 30000); | 672 Mock mock(5, 30000); |
| 666 GrContext* context = mock.context(); | 673 GrContext* context = mock.context(); |
| 667 GrResourceCache* cache = mock.cache(); | 674 GrResourceCache* cache = mock.cache(); |
| 668 | 675 |
| 669 // Create two resources that have the same scratch key. | 676 // Create two resources that have the same scratch key. |
| 670 TestResource* a = TestResource::CreateScratch(context->getGpu(), | 677 TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted:
:kYes, |
| 671 TestResource::kB_SimulatedProp
erty); | 678 TestResource::kB_SimulatedProp
erty); |
| 672 TestResource* b = TestResource::CreateScratch(context->getGpu(), | 679 TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted:
:kYes, |
| 673 TestResource::kB_SimulatedProp
erty); | 680 TestResource::kB_SimulatedProp
erty); |
| 674 a->unref(); | 681 a->unref(); |
| 675 b->unref(); | 682 b->unref(); |
| 676 | 683 |
| 677 GrScratchKey scratchKey; | 684 GrScratchKey scratchKey; |
| 678 // Ensure that scratch key lookup is correct for negative case. | 685 // Ensure that scratch key lookup is correct for negative case. |
| 679 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch
Key); | 686 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch
Key); |
| 680 // (following leaks upon test failure). | 687 // (following leaks upon test failure). |
| 681 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR
esource::kDefaultSize, 0) == nullptr); | 688 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR
esource::kDefaultSize, 0) == nullptr); |
| 682 | 689 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(
scratchKey));) | 726 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(
scratchKey));) |
| 720 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 727 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 721 } | 728 } |
| 722 | 729 |
| 723 static void test_scratch_key_consistency(skiatest::Reporter* reporter) { | 730 static void test_scratch_key_consistency(skiatest::Reporter* reporter) { |
| 724 Mock mock(5, 30000); | 731 Mock mock(5, 30000); |
| 725 GrContext* context = mock.context(); | 732 GrContext* context = mock.context(); |
| 726 GrResourceCache* cache = mock.cache(); | 733 GrResourceCache* cache = mock.cache(); |
| 727 | 734 |
| 728 // Create two resources that have the same scratch key. | 735 // Create two resources that have the same scratch key. |
| 729 TestResource* a = TestResource::CreateScratch(context->getGpu(), | 736 TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted:
:kYes, |
| 730 TestResource::kB_SimulatedProp
erty); | 737 TestResource::kB_SimulatedProp
erty); |
| 731 TestResource* b = TestResource::CreateScratch(context->getGpu(), | 738 TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted:
:kYes, |
| 732 TestResource::kB_SimulatedProp
erty); | 739 TestResource::kB_SimulatedProp
erty); |
| 733 a->unref(); | 740 a->unref(); |
| 734 b->unref(); | 741 b->unref(); |
| 735 | 742 |
| 736 GrScratchKey scratchKey; | 743 GrScratchKey scratchKey; |
| 737 // Ensure that scratch key comparison and assignment is consistent. | 744 // Ensure that scratch key comparison and assignment is consistent. |
| 738 GrScratchKey scratchKey1; | 745 GrScratchKey scratchKey1; |
| 739 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch
Key1); | 746 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch
Key1); |
| 740 GrScratchKey scratchKey2; | 747 GrScratchKey scratchKey2; |
| 741 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch
Key2); | 748 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch
Key2); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 GrResourceCache* cache = mock.cache(); | 888 GrResourceCache* cache = mock.cache(); |
| 882 | 889 |
| 883 GrUniqueKey key1, key2, key3; | 890 GrUniqueKey key1, key2, key3; |
| 884 make_unique_key<0>(&key1, 1); | 891 make_unique_key<0>(&key1, 1); |
| 885 make_unique_key<0>(&key2, 2); | 892 make_unique_key<0>(&key2, 2); |
| 886 make_unique_key<0>(&key3, 3); | 893 make_unique_key<0>(&key3, 3); |
| 887 | 894 |
| 888 // Add three resources to the cache. Only c is usable as scratch. | 895 // Add three resources to the cache. Only c is usable as scratch. |
| 889 TestResource* a = new TestResource(context->getGpu()); | 896 TestResource* a = new TestResource(context->getGpu()); |
| 890 TestResource* b = new TestResource(context->getGpu()); | 897 TestResource* b = new TestResource(context->getGpu()); |
| 891 TestResource* c = TestResource::CreateScratch(context->getGpu(), | 898 TestResource* c = TestResource::CreateScratch(context->getGpu(), SkBudgeted:
:kYes, |
| 892 TestResource::kA_SimulatedProp
erty); | 899 TestResource::kA_SimulatedProp
erty); |
| 893 a->resourcePriv().setUniqueKey(key1); | 900 a->resourcePriv().setUniqueKey(key1); |
| 894 b->resourcePriv().setUniqueKey(key2); | 901 b->resourcePriv().setUniqueKey(key2); |
| 895 c->resourcePriv().setUniqueKey(key3); | 902 c->resourcePriv().setUniqueKey(key3); |
| 896 a->unref(); | 903 a->unref(); |
| 897 // hold b until *after* the message is sent. | 904 // hold b until *after* the message is sent. |
| 898 c->unref(); | 905 c->unref(); |
| 899 | 906 |
| 900 REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); | 907 REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); |
| 901 REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); | 908 REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 test_cache_chained_purge(reporter); | 1318 test_cache_chained_purge(reporter); |
| 1312 test_resource_size_changed(reporter); | 1319 test_resource_size_changed(reporter); |
| 1313 test_timestamp_wrap(reporter); | 1320 test_timestamp_wrap(reporter); |
| 1314 test_flush(reporter); | 1321 test_flush(reporter); |
| 1315 test_large_resource_count(reporter); | 1322 test_large_resource_count(reporter); |
| 1316 test_custom_data(reporter); | 1323 test_custom_data(reporter); |
| 1317 test_abandoned(reporter); | 1324 test_abandoned(reporter); |
| 1318 } | 1325 } |
| 1319 | 1326 |
| 1320 #endif | 1327 #endif |
| OLD | NEW |