aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-01-06 12:04:19 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-06 17:54:03 +0000
commit1090da6433db575d59b93aec99f6bda49b808b84 (patch)
tree1aaba527e5cc1603fe16ccd153119e46870e4ad1 /tests
parent7f71d8845c3c57c6e4b33c3666cca46b55e91d02 (diff)
Add support for tagging GrUniqueKeys with a debug string
Change-Id: Ie7d56214fdee7a19a1e8ca3869e5e4d5e72cedf8 Reviewed-on: https://skia-review.googlesource.com/6632 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ResourceCacheTest.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 06304cf65d..17820935e6 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -415,9 +415,10 @@ static void test_no_key(skiatest::Reporter* reporter) {
}
// Each integer passed as a template param creates a new domain.
-template <int> static void make_unique_key(GrUniqueKey* key, int data) {
+template <int>
+static void make_unique_key(GrUniqueKey* key, int data, const char* tag = nullptr) {
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
- GrUniqueKey::Builder builder(key, d, 1);
+ GrUniqueKey::Builder builder(key, d, 1, tag);
builder[0] = data;
}
@@ -1324,6 +1325,42 @@ static void test_abandoned(skiatest::Reporter* reporter) {
resource->resourcePriv().removeUniqueKey();
}
+static void test_tags(skiatest::Reporter* reporter) {
+#ifdef SK_DEBUG
+ // We will insert 1 resource with tag "tag1", 2 with "tag2", and so on, up through kLastTagIdx.
+ static constexpr int kLastTagIdx = 10;
+ static constexpr int kNumResources = kLastTagIdx * (kLastTagIdx + 1) / 2;
+
+ Mock mock(kNumResources, kNumResources * TestResource::kDefaultSize);
+ GrContext* context = mock.context();
+ GrResourceCache* cache = mock.cache();
+
+ SkString tagStr;
+ int tagIdx = 0;
+ int currTagCnt = 0;
+
+ for (int i = 0; i < kNumResources; ++i, ++currTagCnt) {
+ sk_sp<GrGpuResource> resource(new TestResource(context->getGpu()));
+ GrUniqueKey key;
+ if (currTagCnt == tagIdx) {
+ tagIdx += 1;
+ currTagCnt = 0;
+ tagStr.printf("tag%d", tagIdx);
+ }
+ make_unique_key<1>(&key, i, tagStr.c_str());
+ resource->resourcePriv().setUniqueKey(key);
+ }
+ SkASSERT(kLastTagIdx == tagIdx);
+ SkASSERT(currTagCnt == kLastTagIdx);
+
+ // Test i = 0 to exercise unused tag string.
+ for (int i = 0; i <= kLastTagIdx; ++i) {
+ tagStr.printf("tag%d", i);
+ REPORTER_ASSERT(reporter, cache->countUniqueKeysWithTag(tagStr.c_str()) == i);
+ }
+#endif
+}
+
DEF_GPUTEST(ResourceCacheMisc, reporter, factory) {
// The below tests create their own mock contexts.
test_no_key(reporter);
@@ -1342,6 +1379,7 @@ DEF_GPUTEST(ResourceCacheMisc, reporter, factory) {
test_large_resource_count(reporter);
test_custom_data(reporter);
test_abandoned(reporter);
+ test_tags(reporter);
}
////////////////////////////////////////////////////////////////////////////////