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

Unified Diff: tests/ResourceCacheTest.cpp

Issue 815833004: Add a simpler key type for scratch resource keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: final fix Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrTexturePriv.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ResourceCacheTest.cpp
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index f925b0775443813e9c12a780665dc40573abb74f..a1a594e1dd4bbd8dc57c4771c038c4b28c5b40ef 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -82,7 +82,7 @@ public:
this->registerWithCache();
}
- TestResource(GrGpu* gpu, const GrResourceKey& scratchKey)
+ TestResource(GrGpu* gpu, const GrScratchKey& scratchKey)
: INHERITED(gpu, false)
, fToDelete(NULL)
, fSize(kDefaultSize) {
@@ -173,6 +173,11 @@ static void test_no_key(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
}
+static void make_scratch_key(GrScratchKey* key) {
+ static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType();
+ GrScratchKey::Builder builder(key, t, 0);
+}
+
static void test_budgeting(skiatest::Reporter* reporter) {
SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
REPORTER_ASSERT(reporter, SkToBool(context));
@@ -185,11 +190,12 @@ static void test_budgeting(skiatest::Reporter* reporter) {
SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgetedResourceBytes());
+ GrScratchKey scratchKey;
+ make_scratch_key(&scratchKey);
+
GrCacheID::Key keyData;
memset(&keyData, 0, sizeof(keyData));
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
- GrResourceKey scratchKey(GrCacheID(GrResourceKey::ScratchDomain(), keyData), t, 0);
- GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), t, 0);
+ GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0);
// Create a scratch, a content, and a wrapped resource
TestResource* scratch = new TestResource(context->getGpu(), scratchKey);
@@ -205,7 +211,7 @@ static void test_budgeting(skiatest::Reporter* reporter) {
// Make sure we can't add a content key to the wrapped resource
keyData.fData8[0] = 1;
- GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), t, 0);
+ GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0);
REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2));
REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentKey2));
@@ -277,11 +283,8 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
cache2->purgeAllUnlocked();
SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
- GrCacheID::Key keyData;
- memset(&keyData, 0, sizeof(keyData));
- GrCacheID::Domain domain = GrResourceKey::ScratchDomain();
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
- GrResourceKey scratchKey(GrCacheID(domain, keyData), t, 0);
+ GrScratchKey scratchKey;
+ make_scratch_key(&scratchKey);
// Create two resources that have the same scratch key.
TestResource* a = new TestResource(context->getGpu(), scratchKey);
@@ -324,11 +327,8 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) {
cache2->purgeAllUnlocked();
SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
- GrCacheID::Key keyData;
- memset(&keyData, 0, sizeof(keyData));
- GrCacheID::Domain domain = GrResourceKey::ScratchDomain();
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
- GrResourceKey scratchKey(GrCacheID(domain, keyData), t, 0);
+ GrScratchKey scratchKey;
+ make_scratch_key(&scratchKey);
// Create two resources that have the same scratch key.
TestResource* a = new TestResource(context->getGpu(), scratchKey);
@@ -389,8 +389,7 @@ static void test_duplicate_content_key(skiatest::Reporter* reporter) {
GrCacheID::Domain domain = GrCacheID::GenerateDomain();
GrCacheID::Key keyData;
memset(&keyData, 0, sizeof(keyData));
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
- GrResourceKey key(GrCacheID(domain, keyData), t, 0);
+ GrResourceKey key(GrCacheID(domain, keyData), 0);
// Create two resources that we will attempt to register with the same content key.
TestResource* a = new TestResource(context->getGpu());
@@ -442,14 +441,12 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
GrCacheID::Key keyData;
memset(&keyData, 0, sizeof(keyData));
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
-
keyData.fData64[0] = 1;
- GrResourceKey key1(GrCacheID(domain, keyData), t, 0);
+ GrResourceKey key1(GrCacheID(domain, keyData), 0);
keyData.fData64[0] = 2;
- GrResourceKey key2(GrCacheID(domain, keyData), t, 0);
+ GrResourceKey key2(GrCacheID(domain, keyData), 0);
keyData.fData64[0] = 3;
- GrResourceKey key3(GrCacheID(domain, keyData), t, 0);
+ GrResourceKey key3(GrCacheID(domain, keyData), 0);
context->setResourceCacheLimits(5, 30000);
GrResourceCache2* cache2 = context->getResourceCache2();
@@ -510,13 +507,12 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) {
GrCacheID::Domain domain = GrCacheID::GenerateDomain();
GrCacheID::Key keyData;
memset(&keyData, 0, sizeof(keyData));
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
keyData.fData64[0] = 1;
- GrResourceKey key1(GrCacheID(domain, keyData), t, 0);
+ GrResourceKey key1(GrCacheID(domain, keyData), 0);
keyData.fData64[0] = 2;
- GrResourceKey key2(GrCacheID(domain, keyData), t, 0);
+ GrResourceKey key2(GrCacheID(domain, keyData), 0);
{
context->setResourceCacheLimits(3, 30000);
@@ -560,17 +556,16 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) {
}
GrCacheID::Domain domain = GrCacheID::GenerateDomain();
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
GrCacheID::Key key1Data;
key1Data.fData64[0] = 0;
key1Data.fData64[1] = 0;
- GrResourceKey key1(GrCacheID(domain, key1Data), t, 0);
+ GrResourceKey key1(GrCacheID(domain, key1Data), 0);
GrCacheID::Key key2Data;
key2Data.fData64[0] = 1;
key2Data.fData64[1] = 0;
- GrResourceKey key2(GrCacheID(domain, key2Data), t, 0);
+ GrResourceKey key2(GrCacheID(domain, key2Data), 0);
// Test changing resources sizes (both increase & decrease).
{
@@ -649,7 +644,6 @@ static void test_large_resource_count(skiatest::Reporter* reporter) {
GrCacheID::Domain domain0 = GrCacheID::GenerateDomain();
GrCacheID::Domain domain1 = GrCacheID::GenerateDomain();
- GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
GrCacheID::Key keyData;
memset(&keyData, 0, sizeof(keyData));
@@ -658,13 +652,13 @@ static void test_large_resource_count(skiatest::Reporter* reporter) {
TestResource* resource;
keyData.fData32[0] = i;
- GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
+ GrResourceKey key0(GrCacheID(domain0, keyData), 0);
resource = SkNEW_ARGS(TestResource, (context->getGpu()));
resource->cacheAccess().setContentKey(key0);
resource->setSize(1);
resource->unref();
- GrResourceKey key1(GrCacheID(domain1, keyData), t, 0);
+ GrResourceKey key1(GrCacheID(domain1, keyData), 0);
resource = SkNEW_ARGS(TestResource, (context->getGpu()));
resource->cacheAccess().setContentKey(key1);
resource->setSize(1);
@@ -678,9 +672,9 @@ static void test_large_resource_count(skiatest::Reporter* reporter) {
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);
+ GrResourceKey key0(GrCacheID(domain0, keyData), 0);
REPORTER_ASSERT(reporter, cache2->hasContentKey(key0));
- GrResourceKey key1(GrCacheID(domain0, keyData), t, 0);
+ GrResourceKey key1(GrCacheID(domain0, keyData), 0);
REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
}
@@ -693,9 +687,9 @@ static void test_large_resource_count(skiatest::Reporter* reporter) {
for (int i = 0; i < kResourceCnt; ++i) {
keyData.fData32[0] = i;
- GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
+ GrResourceKey key0(GrCacheID(domain0, keyData), 0);
REPORTER_ASSERT(reporter, !cache2->hasContentKey(key0));
- GrResourceKey key1(GrCacheID(domain0, keyData), t, 0);
+ GrResourceKey key1(GrCacheID(domain0, keyData), 0);
REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
}
}
« no previous file with comments | « src/gpu/GrTexturePriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698