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 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); | 1243 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); |
1244 key1.setCustomData(data.get()); | 1244 key1.setCustomData(data.get()); |
1245 REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132); | 1245 REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132); |
1246 REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); | 1246 REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); |
1247 | 1247 |
1248 // Test that copying a key also takes a ref on its custom data. | 1248 // Test that copying a key also takes a ref on its custom data. |
1249 GrUniqueKey key3 = key1; | 1249 GrUniqueKey key3 = key1; |
1250 REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); | 1250 REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); |
1251 } | 1251 } |
1252 | 1252 |
| 1253 static void test_abandoned(skiatest::Reporter* reporter) { |
| 1254 Mock mock(10, 300); |
| 1255 GrContext* context = mock.context(); |
| 1256 TestResource* resource = new TestResource(context->getGpu()); |
| 1257 context->abandonContext(); |
| 1258 |
| 1259 REPORTER_ASSERT(reporter, resource->wasDestroyed()); |
| 1260 |
| 1261 // Call all the public methods on resource in the abandoned state. They shou
ldn't crash. |
| 1262 |
| 1263 int foo = 4132; |
| 1264 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); |
| 1265 resource->setCustomData(data.get()); |
| 1266 resource->getCustomData(); |
| 1267 resource->getUniqueID(); |
| 1268 resource->getUniqueKey(); |
| 1269 resource->wasDestroyed(); |
| 1270 resource->gpuMemorySize(); |
| 1271 resource->getContext(); |
| 1272 |
| 1273 resource->abandon(); |
| 1274 resource->resourcePriv().getScratchKey(); |
| 1275 resource->resourcePriv().isBudgeted(); |
| 1276 resource->resourcePriv().makeBudgeted(); |
| 1277 resource->resourcePriv().makeUnbudgeted(); |
| 1278 resource->resourcePriv().removeScratchKey(); |
| 1279 GrUniqueKey key; |
| 1280 make_unique_key<0>(&key, 1); |
| 1281 resource->resourcePriv().setUniqueKey(key); |
| 1282 resource->resourcePriv().removeUniqueKey(); |
| 1283 } |
| 1284 |
1253 //////////////////////////////////////////////////////////////////////////////// | 1285 //////////////////////////////////////////////////////////////////////////////// |
1254 DEF_GPUTEST(ResourceCache, reporter, factory) { | 1286 DEF_GPUTEST(ResourceCache, reporter, factory) { |
1255 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 1287 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
1256 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 1288 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
1257 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 1289 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
1258 continue; | 1290 continue; |
1259 } | 1291 } |
1260 GrContext* context = factory->get(glType); | 1292 GrContext* context = factory->get(glType); |
1261 if (nullptr == context) { | 1293 if (nullptr == context) { |
1262 continue; | 1294 continue; |
(...skipping 20 matching lines...) Expand all Loading... |
1283 test_duplicate_scratch_key(reporter); | 1315 test_duplicate_scratch_key(reporter); |
1284 test_remove_scratch_key(reporter); | 1316 test_remove_scratch_key(reporter); |
1285 test_scratch_key_consistency(reporter); | 1317 test_scratch_key_consistency(reporter); |
1286 test_purge_invalidated(reporter); | 1318 test_purge_invalidated(reporter); |
1287 test_cache_chained_purge(reporter); | 1319 test_cache_chained_purge(reporter); |
1288 test_resource_size_changed(reporter); | 1320 test_resource_size_changed(reporter); |
1289 test_timestamp_wrap(reporter); | 1321 test_timestamp_wrap(reporter); |
1290 test_flush(reporter); | 1322 test_flush(reporter); |
1291 test_large_resource_count(reporter); | 1323 test_large_resource_count(reporter); |
1292 test_custom_data(reporter); | 1324 test_custom_data(reporter); |
| 1325 test_abandoned(reporter); |
1293 } | 1326 } |
1294 | 1327 |
1295 #endif | 1328 #endif |
OLD | NEW |