OLD | NEW |
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. | 8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. |
9 #include "SkTypes.h" | 9 #include "SkTypes.h" |
10 | 10 |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 cache->setLimits(1000000, 1000000, kFlushCount); | 1126 cache->setLimits(1000000, 1000000, kFlushCount); |
1127 | 1127 |
1128 { | 1128 { |
1129 // Insert a resource and send a flush notification kFlushCount times. | 1129 // Insert a resource and send a flush notification kFlushCount times. |
1130 for (int i = 0; i < kFlushCount; ++i) { | 1130 for (int i = 0; i < kFlushCount; ++i) { |
1131 TestResource* r = new TestResource(context->getGpu()); | 1131 TestResource* r = new TestResource(context->getGpu()); |
1132 GrUniqueKey k; | 1132 GrUniqueKey k; |
1133 make_unique_key<1>(&k, i); | 1133 make_unique_key<1>(&k, i); |
1134 r->resourcePriv().setUniqueKey(k); | 1134 r->resourcePriv().setUniqueKey(k); |
1135 r->unref(); | 1135 r->unref(); |
1136 cache->notifyFlushOccurred(); | 1136 cache->notifyFlushOccurred(GrResourceCache::kExternal); |
1137 } | 1137 } |
1138 | 1138 |
1139 // Send flush notifications to the cache. Each flush should purge the ol
dest resource. | 1139 // Send flush notifications to the cache. Each flush should purge the ol
dest resource. |
1140 for (int i = 0; i < kFlushCount - 1; ++i) { | 1140 for (int i = 0; i < kFlushCount - 1; ++i) { |
1141 // The first resource was purged after the last flush in the initial
loop, hence the -1. | 1141 // The first resource was purged after the last flush in the initial
loop, hence the -1. |
1142 REPORTER_ASSERT(reporter, kFlushCount - i - 1 == cache->getResourceC
ount()); | 1142 REPORTER_ASSERT(reporter, kFlushCount - i - 1 == cache->getResourceC
ount()); |
1143 for (int j = 0; j < i; ++j) { | 1143 for (int j = 0; j < i; ++j) { |
1144 GrUniqueKey k; | 1144 GrUniqueKey k; |
1145 make_unique_key<1>(&k, j); | 1145 make_unique_key<1>(&k, j); |
1146 GrGpuResource* r = cache->findAndRefUniqueResource(k); | 1146 GrGpuResource* r = cache->findAndRefUniqueResource(k); |
1147 REPORTER_ASSERT(reporter, !SkToBool(r)); | 1147 REPORTER_ASSERT(reporter, !SkToBool(r)); |
1148 SkSafeUnref(r); | 1148 SkSafeUnref(r); |
1149 } | 1149 } |
1150 cache->notifyFlushOccurred(); | 1150 cache->notifyFlushOccurred(GrResourceCache::kExternal); |
1151 } | 1151 } |
1152 | 1152 |
1153 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 1153 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
1154 cache->purgeAllUnlocked(); | 1154 cache->purgeAllUnlocked(); |
1155 } | 1155 } |
1156 | 1156 |
1157 // Do a similar test but where we leave refs on some resources to prevent th
em from being | 1157 // Do a similar test but where we leave refs on some resources to prevent th
em from being |
1158 // purged. | 1158 // purged. |
1159 { | 1159 { |
1160 GrGpuResource* refedResources[kFlushCount >> 1]; | 1160 GrGpuResource* refedResources[kFlushCount >> 1]; |
1161 for (int i = 0; i < kFlushCount; ++i) { | 1161 for (int i = 0; i < kFlushCount; ++i) { |
1162 TestResource* r = new TestResource(context->getGpu()); | 1162 TestResource* r = new TestResource(context->getGpu()); |
1163 GrUniqueKey k; | 1163 GrUniqueKey k; |
1164 make_unique_key<1>(&k, i); | 1164 make_unique_key<1>(&k, i); |
1165 r->resourcePriv().setUniqueKey(k); | 1165 r->resourcePriv().setUniqueKey(k); |
1166 // Leave a ref on every other resource, beginning with the first. | 1166 // Leave a ref on every other resource, beginning with the first. |
1167 if (SkToBool(i & 0x1)) { | 1167 if (SkToBool(i & 0x1)) { |
1168 refedResources[i/2] = r; | 1168 refedResources[i/2] = r; |
1169 } else { | 1169 } else { |
1170 r->unref(); | 1170 r->unref(); |
1171 } | 1171 } |
1172 cache->notifyFlushOccurred(); | 1172 cache->notifyFlushOccurred(GrResourceCache::kExternal); |
1173 } | 1173 } |
1174 | 1174 |
1175 for (int i = 0; i < kFlushCount; ++i) { | 1175 for (int i = 0; i < kFlushCount; ++i) { |
1176 // Should get a resource purged every other flush. | 1176 // Should get a resource purged every other flush. |
1177 REPORTER_ASSERT(reporter, kFlushCount - i/2 - 1 == cache->getResourc
eCount()); | 1177 REPORTER_ASSERT(reporter, kFlushCount - i/2 - 1 == cache->getResourc
eCount()); |
1178 cache->notifyFlushOccurred(); | 1178 cache->notifyFlushOccurred(GrResourceCache::kExternal); |
1179 } | 1179 } |
1180 | 1180 |
1181 // Unref all the resources that we kept refs on in the first loop. | 1181 // Unref all the resources that we kept refs on in the first loop. |
1182 for (int i = 0; i < kFlushCount >> 1; ++i) { | 1182 for (int i = 0; i < kFlushCount >> 1; ++i) { |
1183 refedResources[i]->unref(); | 1183 refedResources[i]->unref(); |
1184 } | 1184 } |
1185 | 1185 |
1186 // When we unref'ed them their timestamps got updated. So nothing should
be purged until we | 1186 // When we unref'ed them their timestamps got updated. So nothing should
be purged until we |
1187 // get kFlushCount additional flushes. Then everything should be purged. | 1187 // get kFlushCount additional flushes. Then everything should be purged. |
1188 for (int i = 0; i < kFlushCount; ++i) { | 1188 for (int i = 0; i < kFlushCount; ++i) { |
1189 REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCoun
t()); | 1189 REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCoun
t()); |
1190 cache->notifyFlushOccurred(); | 1190 cache->notifyFlushOccurred(GrResourceCache::kExternal); |
1191 } | 1191 } |
1192 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 1192 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
1193 | 1193 |
1194 cache->purgeAllUnlocked(); | 1194 cache->purgeAllUnlocked(); |
1195 } | 1195 } |
1196 | 1196 |
1197 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 1197 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
1198 | 1198 |
1199 // Verify that calling flush() on a GrContext with nothing to do will not tr
igger resource | 1199 // Verify that calling flush() on a GrContext with nothing to do will not tr
igger resource |
1200 // eviction. | 1200 // eviction. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 test_cache_chained_purge(reporter); | 1328 test_cache_chained_purge(reporter); |
1329 test_resource_size_changed(reporter); | 1329 test_resource_size_changed(reporter); |
1330 test_timestamp_wrap(reporter); | 1330 test_timestamp_wrap(reporter); |
1331 test_flush(reporter); | 1331 test_flush(reporter); |
1332 test_large_resource_count(reporter); | 1332 test_large_resource_count(reporter); |
1333 test_custom_data(reporter); | 1333 test_custom_data(reporter); |
1334 test_abandoned(reporter); | 1334 test_abandoned(reporter); |
1335 } | 1335 } |
1336 | 1336 |
1337 #endif | 1337 #endif |
OLD | NEW |