diff options
Diffstat (limited to 'tests/ResourceCacheTest.cpp')
-rw-r--r-- | tests/ResourceCacheTest.cpp | 168 |
1 files changed, 35 insertions, 133 deletions
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index aee64842a9..b6ccd515c2 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -274,8 +274,8 @@ public: } static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted, - SimulatedProperty property) { - return new TestResource(gpu, budgeted, property, kScratchConstructor); + SimulatedProperty property, size_t size = kDefaultSize) { + return new TestResource(gpu, budgeted, property, kScratchConstructor, size); } static TestResource* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) { return new TestResource(gpu, size); @@ -286,11 +286,6 @@ public: SkSafeUnref(fToDelete); } - void setSize(size_t size) { - fSize = size; - this->didChangeGpuMemorySize(); - } - static int NumAlive() { return fNumAlive; } void setUnrefWhenDestroyed(TestResource* resource) { @@ -311,10 +306,11 @@ public: private: static const int kScratchKeyFieldCnt = 6; - TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor) + TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor, + size_t size = kDefaultSize) : INHERITED(gpu) , fToDelete(nullptr) - , fSize(kDefaultSize) + , fSize(size) , fProperty(property) , fIsScratch(true) { ++fNumAlive; @@ -376,14 +372,10 @@ static void test_no_key(skiatest::Reporter* reporter) { GrGpu* gpu = context->contextPriv().getGpu(); // Create a bunch of resources with no keys - TestResource* a = new TestResource(gpu); - TestResource* b = new TestResource(gpu); - TestResource* c = new TestResource(gpu); - TestResource* d = new TestResource(gpu); - a->setSize(11); - b->setSize(12); - c->setSize(13); - d->setSize(14); + TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11); + TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12); + TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13 ); + TestResource* d = new TestResource(gpu, SkBudgeted::kYes, 14 ); REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); @@ -435,27 +427,23 @@ static void test_purge_unlocked(skiatest::Reporter* reporter) { // Create two resource w/ a unique key and two w/o but all of which have scratch keys. TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kA_SimulatedProperty); - a->setSize(11); + TestResource::kA_SimulatedProperty, 11); GrUniqueKey uniqueKey; make_unique_key<0>(&uniqueKey, 0); TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kA_SimulatedProperty); - b->setSize(12); + TestResource::kA_SimulatedProperty, 12); b->resourcePriv().setUniqueKey(uniqueKey); TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kA_SimulatedProperty); - c->setSize(13); + TestResource::kA_SimulatedProperty, 13); GrUniqueKey uniqueKey2; make_unique_key<0>(&uniqueKey2, 1); TestResource* d = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kA_SimulatedProperty); - d->setSize(14); + TestResource::kA_SimulatedProperty, 14); d->resourcePriv().setUniqueKey(uniqueKey2); @@ -506,15 +494,12 @@ static void test_budgeting(skiatest::Reporter* reporter) { // Create a scratch, a unique, and a wrapped resource TestResource* scratch = - TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); - scratch->setSize(10); - TestResource* unique = new TestResource(gpu); - unique->setSize(11); + TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty, + 10); + TestResource* unique = new TestResource(gpu, SkBudgeted::kYes, 11); unique->resourcePriv().setUniqueKey(uniqueKey); - TestResource* wrapped = TestResource::CreateWrapped(gpu); - wrapped->setSize(12); - TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo); - unbudgeted->setSize(13); + TestResource* wrapped = TestResource::CreateWrapped(gpu, 12); + TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 13); // Make sure we can add a unique key to the wrapped resource GrUniqueKey uniqueKey2; @@ -556,7 +541,6 @@ static void test_budgeting(skiatest::Reporter* reporter) { // Now try freeing the budgeted resources first wrapped = TestResource::CreateWrapped(gpu); - scratch->setSize(12); unique->unref(); REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes()); cache->purgeAllUnlocked(); @@ -568,7 +552,7 @@ static void test_budgeting(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); scratch->unref(); - REPORTER_ASSERT(reporter, 12 == cache->getPurgeableBytes()); + REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes()); cache->purgeAllUnlocked(); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySize() == @@ -608,9 +592,8 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { // A large uncached or wrapped resource shouldn't evict anything. scratch = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kB_SimulatedProperty); + TestResource::kB_SimulatedProperty, 10); - scratch->setSize(10); scratch->unref(); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes()); @@ -618,8 +601,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes()); - unique = new TestResource(gpu); - unique->setSize(11); + unique = new TestResource(gpu, SkBudgeted::kYes, 11); unique->resourcePriv().setUniqueKey(uniqueKey); unique->unref(); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); @@ -740,12 +722,10 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { // Create two resources that have the same scratch key. TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kB_SimulatedProperty); + TestResource::kB_SimulatedProperty, 11); TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kB_SimulatedProperty); - a->setSize(11); - b->setSize(12); + TestResource::kB_SimulatedProperty, 12); GrScratchKey scratchKey1; TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); // Check for negative case consistency. (leaks upon test failure.) @@ -909,8 +889,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { make_unique_key<0>(&key, 0); // Create two resources that we will attempt to register with the same unique key. - TestResource* a = new TestResource(gpu); - a->setSize(11); + TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11); // Set key on resource a. a->resourcePriv().setUniqueKey(key); @@ -926,8 +905,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); // Create resource b and set the same key. It should replace a's unique key cache entry. - TestResource* b = new TestResource(gpu); - b->setSize(12); + TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12); b->resourcePriv().setUniqueKey(key); REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key)); b->unref(); @@ -946,10 +924,9 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { // Now replace b with c, but make sure c can start with one unique key and change it to b's key. // Also make b be unreffed when replacement occurs. b->unref(); - TestResource* c = new TestResource(gpu); + TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13); GrUniqueKey differentKey; make_unique_key<0>(&differentKey, 1); - c->setSize(13); c->resourcePriv().setUniqueKey(differentKey); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() == cache->getResourceBytes()); @@ -1101,73 +1078,6 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); } -static void test_resource_size_changed(skiatest::Reporter* reporter) { - GrUniqueKey key1, key2; - make_unique_key<0>(&key1, 1); - make_unique_key<0>(&key2, 2); - - // Test changing resources sizes (both increase & decrease). - { - Mock mock(3, 30000); - GrContext* context = mock.context(); - GrResourceCache* cache = mock.cache(); - GrGpu* gpu = context->contextPriv().getGpu(); - - TestResource* a = new TestResource(gpu); - a->resourcePriv().setUniqueKey(key1); - a->unref(); - - TestResource* b = new TestResource(gpu); - b->resourcePriv().setUniqueKey(key2); - b->unref(); - - REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); - REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); - { - sk_sp<TestResource> find2( - static_cast<TestResource*>(cache->findAndRefUniqueResource(key2))); - find2->setSize(200); - sk_sp<TestResource> find1( - static_cast<TestResource*>(cache->findAndRefUniqueResource(key1))); - find1->setSize(50); - } - - REPORTER_ASSERT(reporter, 250 == cache->getResourceBytes()); - REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); - } - - // Test increasing a resources size beyond the cache budget. - { - Mock mock(2, 300); - GrContext* context = mock.context(); - GrResourceCache* cache = mock.cache(); - GrGpu* gpu = context->contextPriv().getGpu(); - - TestResource* a = new TestResource(gpu); - a->setSize(100); - a->resourcePriv().setUniqueKey(key1); - a->unref(); - - TestResource* b = new TestResource(gpu); - b->setSize(100); - b->resourcePriv().setUniqueKey(key2); - b->unref(); - - REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); - REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); - - { - sk_sp<TestResource> find2(static_cast<TestResource*>( - cache->findAndRefUniqueResource(key2))); - find2->setSize(201); - } - REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); - - REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes()); - REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); - } -} - static void test_timestamp_wrap(skiatest::Reporter* reporter) { static const int kCount = 50; static const int kBudgetCnt = kCount / 2; @@ -1459,26 +1369,21 @@ static void test_partial_purge(skiatest::Reporter* reporter) { make_unique_key<0>(&key3, 3); // Add three unique resources to the cache. - TestResource *unique1 = new TestResource(gpu); - TestResource *unique2 = new TestResource(gpu); - TestResource *unique3 = new TestResource(gpu); + TestResource *unique1 = new TestResource(gpu, SkBudgeted::kYes, 10); + TestResource *unique2 = new TestResource(gpu, SkBudgeted::kYes, 11); + TestResource *unique3 = new TestResource(gpu, SkBudgeted::kYes, 12); unique1->resourcePriv().setUniqueKey(key1); unique2->resourcePriv().setUniqueKey(key2); unique3->resourcePriv().setUniqueKey(key3); - unique1->setSize(10); - unique2->setSize(11); - unique3->setSize(12); - // Add two scratch resources to the cache. TestResource *scratch1 = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kA_SimulatedProperty); + TestResource::kA_SimulatedProperty, + 13); TestResource *scratch2 = TestResource::CreateScratch(gpu, SkBudgeted::kYes, - TestResource::kB_SimulatedProperty); - scratch1->setSize(13); - scratch2->setSize(14); - + TestResource::kB_SimulatedProperty, + 14); REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount()); REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes()); @@ -1562,14 +1467,12 @@ static void test_large_resource_count(skiatest::Reporter* reporter) { TestResource* resource; - resource = new TestResource(gpu); + resource = new TestResource(gpu, SkBudgeted::kYes, 1); resource->resourcePriv().setUniqueKey(key1); - resource->setSize(1); resource->unref(); - resource = new TestResource(gpu); + resource = new TestResource(gpu, SkBudgeted::kYes, 1); resource->resourcePriv().setUniqueKey(key2); - resource->setSize(1); resource->unref(); } @@ -1705,7 +1608,6 @@ DEF_GPUTEST(ResourceCacheMisc, reporter, /* options */) { test_scratch_key_consistency(reporter); test_purge_invalidated(reporter); test_cache_chained_purge(reporter); - test_resource_size_changed(reporter); test_timestamp_wrap(reporter); test_flush(reporter); test_time_purge(reporter); |