| 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 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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(GrResourceCache::kExternal); | 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; ++i) { | 
| 1141             // The first resource was purged after the last flush in the initial
       loop, hence the -1. | 1141             cache->notifyFlushOccurred(GrResourceCache::kExternal); | 
| 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(GrResourceCache::kExternal); |  | 
| 1151         } | 1150         } | 
| 1152 | 1151 | 
| 1153         REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 1152         REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 
| 1154         cache->purgeAllUnlocked(); | 1153         cache->purgeAllUnlocked(); | 
| 1155     } | 1154     } | 
| 1156 | 1155 | 
| 1157     // Do a similar test but where we leave refs on some resources to prevent th
      em from being | 1156     // Do a similar test but where we leave refs on some resources to prevent th
      em from being | 
| 1158     // purged. | 1157     // purged. | 
| 1159     { | 1158     { | 
| 1160         GrGpuResource* refedResources[kFlushCount >> 1]; | 1159         GrGpuResource* refedResources[kFlushCount >> 1]; | 
| 1161         for (int i = 0; i < kFlushCount; ++i) { | 1160         for (int i = 0; i < kFlushCount; ++i) { | 
| 1162             TestResource* r = new TestResource(context->getGpu()); | 1161             TestResource* r = new TestResource(context->getGpu()); | 
| 1163             GrUniqueKey k; | 1162             GrUniqueKey k; | 
| 1164             make_unique_key<1>(&k, i); | 1163             make_unique_key<1>(&k, i); | 
| 1165             r->resourcePriv().setUniqueKey(k); | 1164             r->resourcePriv().setUniqueKey(k); | 
| 1166             // Leave a ref on every other resource, beginning with the first. | 1165             // Leave a ref on every other resource, beginning with the first. | 
| 1167             if (SkToBool(i & 0x1)) { | 1166             if (SkToBool(i & 0x1)) { | 
| 1168                 refedResources[i/2] = r; | 1167                 refedResources[i/2] = r; | 
| 1169             } else { | 1168             } else { | 
| 1170                 r->unref(); | 1169                 r->unref(); | 
| 1171             } | 1170             } | 
| 1172             cache->notifyFlushOccurred(GrResourceCache::kExternal); | 1171             cache->notifyFlushOccurred(GrResourceCache::kExternal); | 
| 1173         } | 1172         } | 
| 1174 | 1173 | 
| 1175         for (int i = 0; i < kFlushCount; ++i) { | 1174         for (int i = 0; i < kFlushCount; ++i) { | 
| 1176             // Should get a resource purged every other flush. | 1175             // Should get a resource purged every other flush. | 
|  | 1176             cache->notifyFlushOccurred(GrResourceCache::kExternal); | 
| 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(GrResourceCache::kExternal); |  | 
| 1179         } | 1178         } | 
| 1180 | 1179 | 
| 1181         // Unref all the resources that we kept refs on in the first loop. | 1180         // Unref all the resources that we kept refs on in the first loop. | 
| 1182         for (int i = 0; i < kFlushCount >> 1; ++i) { | 1181         for (int i = 0; i < kFlushCount >> 1; ++i) { | 
| 1183             refedResources[i]->unref(); | 1182             refedResources[i]->unref(); | 
| 1184         } | 1183         } | 
| 1185 | 1184 | 
| 1186         // When we unref'ed them their timestamps got updated. So nothing should
       be purged until we | 1185         // After kFlushCount + 1 flushes they all will have sat in the purgeable
       queue for | 
| 1187         // get kFlushCount additional flushes. Then everything should be purged. | 1186         // kFlushCount full flushes. | 
| 1188         for (int i = 0; i < kFlushCount; ++i) { | 1187         for (int i = 0; i < kFlushCount + 1; ++i) { | 
| 1189             REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCoun
      t()); | 1188             REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCoun
      t()); | 
| 1190             cache->notifyFlushOccurred(GrResourceCache::kExternal); | 1189             cache->notifyFlushOccurred(GrResourceCache::kExternal); | 
| 1191         } | 1190         } | 
| 1192         REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 1191         REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 
| 1193 | 1192 | 
| 1194         cache->purgeAllUnlocked(); | 1193         cache->purgeAllUnlocked(); | 
| 1195     } | 1194     } | 
| 1196 | 1195 | 
| 1197     REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 1196     REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 
| 1198 | 1197 | 
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1328     test_cache_chained_purge(reporter); | 1327     test_cache_chained_purge(reporter); | 
| 1329     test_resource_size_changed(reporter); | 1328     test_resource_size_changed(reporter); | 
| 1330     test_timestamp_wrap(reporter); | 1329     test_timestamp_wrap(reporter); | 
| 1331     test_flush(reporter); | 1330     test_flush(reporter); | 
| 1332     test_large_resource_count(reporter); | 1331     test_large_resource_count(reporter); | 
| 1333     test_custom_data(reporter); | 1332     test_custom_data(reporter); | 
| 1334     test_abandoned(reporter); | 1333     test_abandoned(reporter); | 
| 1335 } | 1334 } | 
| 1336 | 1335 | 
| 1337 #endif | 1336 #endif | 
| OLD | NEW | 
|---|