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 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 c->unref(); | 864 c->unref(); |
865 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 865 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
866 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); | 866 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
867 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); | 867 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
868 | 868 |
869 { | 869 { |
870 GrUniqueKey key2; | 870 GrUniqueKey key2; |
871 make_unique_key<0>(&key2, 0); | 871 make_unique_key<0>(&key2, 0); |
872 SkAutoTUnref<TestResource> d(new TestResource(context->getGpu())); | 872 SkAutoTUnref<TestResource> d(new TestResource(context->getGpu())); |
873 int foo = 4132; | 873 int foo = 4132; |
874 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); | 874 key2.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo))); |
875 key2.setCustomData(data.get()); | |
876 d->resourcePriv().setUniqueKey(key2); | 875 d->resourcePriv().setUniqueKey(key2); |
877 } | 876 } |
878 | 877 |
879 GrUniqueKey key3; | 878 GrUniqueKey key3; |
880 make_unique_key<0>(&key3, 0); | 879 make_unique_key<0>(&key3, 0); |
881 SkAutoTUnref<GrGpuResource> d2(cache->findAndRefUniqueResource(key3)); | 880 SkAutoTUnref<GrGpuResource> d2(cache->findAndRefUniqueResource(key3)); |
882 REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data()
== 4132); | 881 REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data()
== 4132); |
883 } | 882 } |
884 | 883 |
885 static void test_purge_invalidated(skiatest::Reporter* reporter) { | 884 static void test_purge_invalidated(skiatest::Reporter* reporter) { |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); | 1254 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
1256 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); | 1255 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
1257 } | 1256 } |
1258 } | 1257 } |
1259 | 1258 |
1260 static void test_custom_data(skiatest::Reporter* reporter) { | 1259 static void test_custom_data(skiatest::Reporter* reporter) { |
1261 GrUniqueKey key1, key2; | 1260 GrUniqueKey key1, key2; |
1262 make_unique_key<0>(&key1, 1); | 1261 make_unique_key<0>(&key1, 1); |
1263 make_unique_key<0>(&key2, 2); | 1262 make_unique_key<0>(&key2, 2); |
1264 int foo = 4132; | 1263 int foo = 4132; |
1265 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); | 1264 key1.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo))); |
1266 key1.setCustomData(data.get()); | |
1267 REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132); | 1265 REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132); |
1268 REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); | 1266 REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); |
1269 | 1267 |
1270 // Test that copying a key also takes a ref on its custom data. | 1268 // Test that copying a key also takes a ref on its custom data. |
1271 GrUniqueKey key3 = key1; | 1269 GrUniqueKey key3 = key1; |
1272 REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); | 1270 REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); |
1273 } | 1271 } |
1274 | 1272 |
1275 static void test_abandoned(skiatest::Reporter* reporter) { | 1273 static void test_abandoned(skiatest::Reporter* reporter) { |
1276 Mock mock(10, 300); | 1274 Mock mock(10, 300); |
1277 GrContext* context = mock.context(); | 1275 GrContext* context = mock.context(); |
1278 SkAutoTUnref<GrGpuResource> resource(new TestResource(context->getGpu())); | 1276 SkAutoTUnref<GrGpuResource> resource(new TestResource(context->getGpu())); |
1279 context->abandonContext(); | 1277 context->abandonContext(); |
1280 | 1278 |
1281 REPORTER_ASSERT(reporter, resource->wasDestroyed()); | 1279 REPORTER_ASSERT(reporter, resource->wasDestroyed()); |
1282 | 1280 |
1283 // Call all the public methods on resource in the abandoned state. They shou
ldn't crash. | 1281 // Call all the public methods on resource in the abandoned state. They shou
ldn't crash. |
1284 | 1282 |
1285 int foo = 4132; | 1283 int foo = 4132; |
1286 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); | 1284 sk_sp<SkData> data(SkData::MakeWithCopy(&foo, sizeof(foo))); |
1287 resource->setCustomData(data.get()); | 1285 resource->setCustomData(data.get()); |
1288 resource->getCustomData(); | 1286 resource->getCustomData(); |
1289 resource->getUniqueID(); | 1287 resource->getUniqueID(); |
1290 resource->getUniqueKey(); | 1288 resource->getUniqueKey(); |
1291 resource->wasDestroyed(); | 1289 resource->wasDestroyed(); |
1292 resource->gpuMemorySize(); | 1290 resource->gpuMemorySize(); |
1293 resource->getContext(); | 1291 resource->getContext(); |
1294 | 1292 |
1295 resource->abandon(); | 1293 resource->abandon(); |
1296 resource->resourcePriv().getScratchKey(); | 1294 resource->resourcePriv().getScratchKey(); |
(...skipping 21 matching lines...) Expand all Loading... |
1318 test_cache_chained_purge(reporter); | 1316 test_cache_chained_purge(reporter); |
1319 test_resource_size_changed(reporter); | 1317 test_resource_size_changed(reporter); |
1320 test_timestamp_wrap(reporter); | 1318 test_timestamp_wrap(reporter); |
1321 test_flush(reporter); | 1319 test_flush(reporter); |
1322 test_large_resource_count(reporter); | 1320 test_large_resource_count(reporter); |
1323 test_custom_data(reporter); | 1321 test_custom_data(reporter); |
1324 test_abandoned(reporter); | 1322 test_abandoned(reporter); |
1325 } | 1323 } |
1326 | 1324 |
1327 #endif | 1325 #endif |
OLD | NEW |