aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-11-24 08:25:05 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-24 08:25:05 -0800
commit4e4303f002c5958c6c958e7ba8e49b24c25f0b22 (patch)
treec235168ac114ff7b49f5e13c463475bb966dd5b9 /tests
parent04c96950554b4e416755c5bc23022674518a6e8b (diff)
Cleanup res cache bench and split out into a unit test.
Diffstat (limited to 'tests')
-rw-r--r--tests/ResourceCacheTest.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 930bd1217c..45e28425d0 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -569,6 +569,76 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) {
}
}
+static void test_large_resource_count(skiatest::Reporter* reporter) {
+ SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
+ REPORTER_ASSERT(reporter, SkToBool(context));
+ if (NULL == context) {
+ return;
+ }
+
+ static const int kResourceCnt = 2000;
+ // Set the cache size to double the resource count because we're going to create 2x that number
+ // resources, using two different key domains. Add a little slop to the bytes because we resize
+ // down to 1 byte after creating the resource.
+ context->setResourceCacheLimits(2 * kResourceCnt, 2 * kResourceCnt + 1000);
+ GrResourceCache2* cache2 = context->getResourceCache2();
+ cache2->purgeAllUnlocked();
+ SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
+
+ GrCacheID::Domain domain0 = GrCacheID::GenerateDomain();
+ GrCacheID::Domain domain1 = GrCacheID::GenerateDomain();
+ GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
+
+ GrCacheID::Key keyData;
+ memset(&keyData, 0, sizeof(keyData));
+
+ for (int i = 0; i < kResourceCnt; ++i) {
+ TestResource* resource;
+ keyData.fData32[0] = i;
+
+ GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
+ resource = SkNEW_ARGS(TestResource, (context->getGpu()));
+ resource->cacheAccess().setContentKey(key0);
+ resource->setSize(1);
+ resource->unref();
+
+ GrResourceKey key1(GrCacheID(domain1, keyData), t, 0);
+ resource = SkNEW_ARGS(TestResource, (context->getGpu()));
+ resource->cacheAccess().setContentKey(key1);
+ resource->setSize(1);
+ resource->unref();
+ }
+
+ REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt);
+ REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 2 * kResourceCnt);
+ REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 2 * kResourceCnt);
+ REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 2 * kResourceCnt);
+ REPORTER_ASSERT(reporter, cache2->getResourceCount() == 2 * kResourceCnt);
+ for (int i = 0; i < kResourceCnt; ++i) {
+ keyData.fData32[0] = i;
+ GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
+ REPORTER_ASSERT(reporter, cache2->hasContentKey(key0));
+ GrResourceKey key1(GrCacheID(domain0, keyData), t, 0);
+ REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
+ }
+
+ cache2->purgeAllUnlocked();
+ REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0);
+ REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 0);
+ REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 0);
+ REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 0);
+ REPORTER_ASSERT(reporter, cache2->getResourceCount() == 0);
+
+ for (int i = 0; i < kResourceCnt; ++i) {
+ keyData.fData32[0] = i;
+ GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
+ REPORTER_ASSERT(reporter, !cache2->hasContentKey(key0));
+ GrResourceKey key1(GrCacheID(domain0, keyData), t, 0);
+ REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
+ }
+}
+
+
////////////////////////////////////////////////////////////////////////////////
DEF_GPUTEST(ResourceCache, reporter, factory) {
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
@@ -598,6 +668,7 @@ DEF_GPUTEST(ResourceCache, reporter, factory) {
test_purge_invalidated(reporter);
test_cache_chained_purge(reporter);
test_resource_size_changed(reporter);
+ test_large_resource_count(reporter);
}
#endif