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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 1032873002: Add mechanism to proactively purge old resources in GrResourceCache. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comment Created 5 years, 8 months 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 unified diff | Download patch
« no previous file with comments | « src/gpu/GrResourceCache.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
9 #include "SkTypes.h"
10
8 #if SK_SUPPORT_GPU 11 #if SK_SUPPORT_GPU
9 12
10 #include "GrContext.h" 13 #include "GrContext.h"
11 #include "GrContextFactory.h" 14 #include "GrContextFactory.h"
12 #include "GrGpu.h" 15 #include "GrGpu.h"
13 #include "GrGpuResourceCacheAccess.h" 16 #include "GrGpuResourceCacheAccess.h"
14 #include "GrGpuResourcePriv.h" 17 #include "GrGpuResourcePriv.h"
15 #include "GrRenderTarget.h" 18 #include "GrRenderTarget.h"
16 #include "GrRenderTargetPriv.h" 19 #include "GrRenderTargetPriv.h"
17 #include "GrResourceCache.h" 20 #include "GrResourceCache.h"
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1019 }
1017 SkSafeUnref(res); 1020 SkSafeUnref(res);
1018 } 1021 }
1019 1022
1020 for (int j = 0; j < resourcesToUnref.count(); ++j) { 1023 for (int j = 0; j < resourcesToUnref.count(); ++j) {
1021 resourcesToUnref[j]->unref(); 1024 resourcesToUnref[j]->unref();
1022 } 1025 }
1023 } 1026 }
1024 } 1027 }
1025 1028
1029 static void test_flush(skiatest::Reporter* reporter) {
1030 Mock mock(1000000, 1000000);
1031 GrContext* context = mock.context();
1032 GrResourceCache* cache = mock.cache();
1033
1034 // The current cache impl will round the max flush count to the next power o f 2. So we choose a
1035 // power of two here to keep things simpler.
1036 static const int kFlushCount = 16;
1037 cache->setLimits(1000000, 1000000, kFlushCount);
1038
1039 {
1040 // Insert a resource and send a flush notification kFlushCount times.
1041 for (int i = 0; i < kFlushCount; ++i) {
1042 TestResource* r = SkNEW_ARGS(TestResource, (context->getGpu()));
1043 GrUniqueKey k;
1044 make_unique_key<1>(&k, i);
1045 r->resourcePriv().setUniqueKey(k);
1046 r->unref();
1047 cache->notifyFlushOccurred();
1048 }
1049
1050 // Send flush notifications to the cache. Each flush should purge the ol dest resource.
1051 for (int i = 0; i < kFlushCount - 1; ++i) {
1052 // The first resource was purged after the last flush in the initial loop, hence the -1.
1053 REPORTER_ASSERT(reporter, kFlushCount - i - 1 == cache->getResourceC ount());
1054 for (int j = 0; j < i; ++j) {
1055 GrUniqueKey k;
1056 make_unique_key<1>(&k, j);
1057 GrGpuResource* r = cache->findAndRefUniqueResource(k);
1058 REPORTER_ASSERT(reporter, !SkToBool(r));
1059 SkSafeUnref(r);
1060 }
1061 cache->notifyFlushOccurred();
1062 }
1063
1064 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
1065 cache->purgeAllUnlocked();
1066 }
1067
1068 // Do a similar test but where we leave refs on some resources to prevent th em from being
1069 // purged.
1070 {
1071 GrGpuResource* refedResources[kFlushCount >> 1];
1072 for (int i = 0; i < kFlushCount; ++i) {
1073 TestResource* r = SkNEW_ARGS(TestResource, (context->getGpu()));
1074 GrUniqueKey k;
1075 make_unique_key<1>(&k, i);
1076 r->resourcePriv().setUniqueKey(k);
1077 // Leave a ref on every other resource, beginning with the first.
1078 if (SkToBool(i & 0x1)) {
1079 refedResources[i/2] = r;
1080 } else {
1081 r->unref();
1082 }
1083 cache->notifyFlushOccurred();
1084 }
1085
1086 for (int i = 0; i < kFlushCount; ++i) {
1087 // Should get a resource purged every other flush.
1088 REPORTER_ASSERT(reporter, kFlushCount - i/2 - 1 == cache->getResourc eCount());
1089 cache->notifyFlushOccurred();
1090 }
1091
1092 // Unref all the resources that we kept refs on in the first loop.
1093 for (int i = 0; i < kFlushCount >> 1; ++i) {
1094 refedResources[i]->unref();
1095 }
1096
1097 // When we unref'ed them their timestamps got updated. So nothing should be purged until we
1098 // get kFlushCount additional flushes. Then everything should be purged.
1099 for (int i = 0; i < kFlushCount; ++i) {
1100 REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCoun t());
1101 cache->notifyFlushOccurred();
1102 }
1103 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
1104
1105 cache->purgeAllUnlocked();
1106 }
1107
1108 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
1109 }
1110
1026 static void test_large_resource_count(skiatest::Reporter* reporter) { 1111 static void test_large_resource_count(skiatest::Reporter* reporter) {
1027 // Set the cache size to double the resource count because we're going to cr eate 2x that number 1112 // Set the cache size to double the resource count because we're going to cr eate 2x that number
1028 // resources, using two different key domains. Add a little slop to the byte s because we resize 1113 // resources, using two different key domains. Add a little slop to the byte s because we resize
1029 // down to 1 byte after creating the resource. 1114 // down to 1 byte after creating the resource.
1030 static const int kResourceCnt = 2000; 1115 static const int kResourceCnt = 2000;
1031 1116
1032 Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); 1117 Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000);
1033 GrContext* context = mock.context(); 1118 GrContext* context = mock.context();
1034 GrResourceCache* cache = mock.cache(); 1119 GrResourceCache* cache = mock.cache();
1035 1120
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 test_unbudgeted(reporter); 1196 test_unbudgeted(reporter);
1112 test_unbudgeted_to_scratch(reporter); 1197 test_unbudgeted_to_scratch(reporter);
1113 test_duplicate_unique_key(reporter); 1198 test_duplicate_unique_key(reporter);
1114 test_duplicate_scratch_key(reporter); 1199 test_duplicate_scratch_key(reporter);
1115 test_remove_scratch_key(reporter); 1200 test_remove_scratch_key(reporter);
1116 test_scratch_key_consistency(reporter); 1201 test_scratch_key_consistency(reporter);
1117 test_purge_invalidated(reporter); 1202 test_purge_invalidated(reporter);
1118 test_cache_chained_purge(reporter); 1203 test_cache_chained_purge(reporter);
1119 test_resource_size_changed(reporter); 1204 test_resource_size_changed(reporter);
1120 test_timestamp_wrap(reporter); 1205 test_timestamp_wrap(reporter);
1206 test_flush(reporter);
1121 test_large_resource_count(reporter); 1207 test_large_resource_count(reporter);
1122 } 1208 }
1123 1209
1124 #endif 1210 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698