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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); | 838 REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
839 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); | 839 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
840 | 840 |
841 // Verify that we can find c, then remove its unique key. It should get purg
ed immediately. | 841 // Verify that we can find c, then remove its unique key. It should get purg
ed immediately. |
842 REPORTER_ASSERT(reporter, c == cache->findAndRefUniqueResource(key)); | 842 REPORTER_ASSERT(reporter, c == cache->findAndRefUniqueResource(key)); |
843 c->resourcePriv().removeUniqueKey(); | 843 c->resourcePriv().removeUniqueKey(); |
844 c->unref(); | 844 c->unref(); |
845 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); | 845 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
846 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); | 846 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
847 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); | 847 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 848 |
| 849 { |
| 850 GrUniqueKey key2; |
| 851 make_unique_key<0>(&key2, 0); |
| 852 SkAutoTUnref<TestResource> d(SkNEW_ARGS(TestResource, (context->getGpu()
))); |
| 853 int foo = 4132; |
| 854 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); |
| 855 key2.setCustomData(data.get()); |
| 856 d->resourcePriv().setUniqueKey(key2); |
| 857 } |
| 858 |
| 859 GrUniqueKey key3; |
| 860 make_unique_key<0>(&key3, 0); |
| 861 SkAutoTUnref<GrGpuResource> d2(cache->findAndRefUniqueResource(key3)); |
| 862 REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data()
== 4132); |
848 } | 863 } |
849 | 864 |
850 static void test_purge_invalidated(skiatest::Reporter* reporter) { | 865 static void test_purge_invalidated(skiatest::Reporter* reporter) { |
851 Mock mock(5, 30000); | 866 Mock mock(5, 30000); |
852 GrContext* context = mock.context(); | 867 GrContext* context = mock.context(); |
853 GrResourceCache* cache = mock.cache(); | 868 GrResourceCache* cache = mock.cache(); |
854 | 869 |
855 GrUniqueKey key1, key2, key3; | 870 GrUniqueKey key1, key2, key3; |
856 make_unique_key<0>(&key1, 1); | 871 make_unique_key<0>(&key1, 1); |
857 make_unique_key<0>(&key2, 2); | 872 make_unique_key<0>(&key2, 2); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 for (int i = 0; i < kResourceCnt; ++i) { | 1231 for (int i = 0; i < kResourceCnt; ++i) { |
1217 GrUniqueKey key1, key2; | 1232 GrUniqueKey key1, key2; |
1218 make_unique_key<1>(&key1, i); | 1233 make_unique_key<1>(&key1, i); |
1219 make_unique_key<2>(&key2, i); | 1234 make_unique_key<2>(&key2, i); |
1220 | 1235 |
1221 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); | 1236 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
1222 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); | 1237 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
1223 } | 1238 } |
1224 } | 1239 } |
1225 | 1240 |
| 1241 static void test_custom_data(skiatest::Reporter* reporter) { |
| 1242 GrUniqueKey key1, key2; |
| 1243 make_unique_key<0>(&key1, 1); |
| 1244 make_unique_key<0>(&key2, 2); |
| 1245 int foo = 4132; |
| 1246 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo))); |
| 1247 key1.setCustomData(data.get()); |
| 1248 REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132); |
| 1249 REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); |
| 1250 |
| 1251 // Test that copying a key also takes a ref on its custom data. |
| 1252 GrUniqueKey key3 = key1; |
| 1253 REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); |
| 1254 } |
| 1255 |
1226 //////////////////////////////////////////////////////////////////////////////// | 1256 //////////////////////////////////////////////////////////////////////////////// |
1227 DEF_GPUTEST(ResourceCache, reporter, factory) { | 1257 DEF_GPUTEST(ResourceCache, reporter, factory) { |
1228 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 1258 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
1229 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 1259 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
1230 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 1260 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
1231 continue; | 1261 continue; |
1232 } | 1262 } |
1233 GrContext* context = factory->get(glType); | 1263 GrContext* context = factory->get(glType); |
1234 if (NULL == context) { | 1264 if (NULL == context) { |
1235 continue; | 1265 continue; |
(...skipping 19 matching lines...) Expand all Loading... |
1255 test_duplicate_unique_key(reporter); | 1285 test_duplicate_unique_key(reporter); |
1256 test_duplicate_scratch_key(reporter); | 1286 test_duplicate_scratch_key(reporter); |
1257 test_remove_scratch_key(reporter); | 1287 test_remove_scratch_key(reporter); |
1258 test_scratch_key_consistency(reporter); | 1288 test_scratch_key_consistency(reporter); |
1259 test_purge_invalidated(reporter); | 1289 test_purge_invalidated(reporter); |
1260 test_cache_chained_purge(reporter); | 1290 test_cache_chained_purge(reporter); |
1261 test_resource_size_changed(reporter); | 1291 test_resource_size_changed(reporter); |
1262 test_timestamp_wrap(reporter); | 1292 test_timestamp_wrap(reporter); |
1263 test_flush(reporter); | 1293 test_flush(reporter); |
1264 test_large_resource_count(reporter); | 1294 test_large_resource_count(reporter); |
| 1295 test_custom_data(reporter); |
1265 } | 1296 } |
1266 | 1297 |
1267 #endif | 1298 #endif |
OLD | NEW |