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 #if SK_SUPPORT_GPU | 8 #if SK_SUPPORT_GPU |
9 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 cache->findAndRefUniqueResource(key2))); | 916 cache->findAndRefUniqueResource(key2))); |
917 find2->setSize(201); | 917 find2->setSize(201); |
918 } | 918 } |
919 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); | 919 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
920 | 920 |
921 REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes()); | 921 REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes()); |
922 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); | 922 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
923 } | 923 } |
924 } | 924 } |
925 | 925 |
926 static void test_timestamp_wrap(skiatest::Reporter* reporter) { | |
927 enum { | |
928 kCount = 50, | |
robertphillips
2015/02/19 18:47:33
reosource -> resources
| |
929 kBudgetCnt = kCount / 2, // half the reosource should get purged. | |
930 kLockedFreq = 8, | |
931 kBudgetSize = 0x80000000, // really large, just use the cnt budget | |
932 }; | |
933 | |
934 SkRandom random; | |
935 | |
936 // Run the test 2*kCount times; | |
937 for (int i = 0; i < 2 * kCount; ++i ) { | |
938 Mock mock(kBudgetCnt, kBudgetSize); | |
939 GrContext* context = mock.context(); | |
940 GrResourceCache* cache = mock.cache(); | |
941 | |
942 // Pick a random number of resources to add before the timestamp will wr ap. | |
943 cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1)); | |
944 | |
945 enum { kNumToPurge = kCount - kBudgetCnt }; | |
946 SkTDArray<int> shouldPurgeIdxs; | |
947 int purgeableCnt = 0; | |
948 SkTDArray<GrGpuResource*> resourcesToUnref; | |
949 | |
950 // Add kCount resources, holding onto resources at random so we have a m ix of purgeable and | |
951 // unpurgeable resources. | |
952 for (int j = 0; j < kCount; ++j) { | |
953 GrUniqueKey key; | |
954 make_unique_key<0>(&key, j); | |
955 | |
956 TestResource* r = SkNEW_ARGS(TestResource, (context->getGpu())); | |
957 r->resourcePriv().setUniqueKey(key); | |
958 if (random.nextU() % kLockedFreq) { | |
959 // Make this is purgeable. | |
960 r->unref(); | |
961 ++purgeableCnt; | |
962 if (purgeableCnt <= kNumToPurge) { | |
963 *shouldPurgeIdxs.append() = j; | |
964 } | |
965 } else { | |
966 *resourcesToUnref.append() = r; | |
967 } | |
968 } | |
969 | |
970 // Verify that the correct resources were purged. | |
971 int currShouldPurgeIdx = 0; | |
972 for (int j = 0; j < kCount; ++j) { | |
973 GrUniqueKey key; | |
974 make_unique_key<0>(&key, j); | |
975 GrGpuResource* res = cache->findAndRefUniqueResource(key); | |
976 if (currShouldPurgeIdx < shouldPurgeIdxs.count() && | |
977 shouldPurgeIdxs[currShouldPurgeIdx] == j) { | |
978 ++currShouldPurgeIdx; | |
979 REPORTER_ASSERT(reporter, NULL == res); | |
980 } else { | |
robertphillips
2015/02/19 18:47:33
Can we assert that the time stamps are less than k
bsalomon
2015/02/19 18:52:54
I'd have to expose access to the time stamp here.
| |
981 REPORTER_ASSERT(reporter, NULL != res); | |
982 } | |
983 SkSafeUnref(res); | |
984 } | |
985 | |
986 for (int j = 0; j < resourcesToUnref.count(); ++j) { | |
987 resourcesToUnref[j]->unref(); | |
988 } | |
989 } | |
990 } | |
991 | |
926 static void test_large_resource_count(skiatest::Reporter* reporter) { | 992 static void test_large_resource_count(skiatest::Reporter* reporter) { |
927 // Set the cache size to double the resource count because we're going to cr eate 2x that number | 993 // Set the cache size to double the resource count because we're going to cr eate 2x that number |
928 // resources, using two different key domains. Add a little slop to the byte s because we resize | 994 // resources, using two different key domains. Add a little slop to the byte s because we resize |
929 // down to 1 byte after creating the resource. | 995 // down to 1 byte after creating the resource. |
930 static const int kResourceCnt = 2000; | 996 static const int kResourceCnt = 2000; |
931 | 997 |
932 Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); | 998 Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); |
933 GrContext* context = mock.context(); | 999 GrContext* context = mock.context(); |
934 GrResourceCache* cache = mock.cache(); | 1000 GrResourceCache* cache = mock.cache(); |
935 | 1001 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 for (int i = 0; i < kResourceCnt; ++i) { | 1041 for (int i = 0; i < kResourceCnt; ++i) { |
976 GrUniqueKey key1, key2; | 1042 GrUniqueKey key1, key2; |
977 make_unique_key<1>(&key1, i); | 1043 make_unique_key<1>(&key1, i); |
978 make_unique_key<2>(&key2, i); | 1044 make_unique_key<2>(&key2, i); |
979 | 1045 |
980 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); | 1046 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
981 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); | 1047 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
982 } | 1048 } |
983 } | 1049 } |
984 | 1050 |
985 | |
986 //////////////////////////////////////////////////////////////////////////////// | 1051 //////////////////////////////////////////////////////////////////////////////// |
987 DEF_GPUTEST(ResourceCache, reporter, factory) { | 1052 DEF_GPUTEST(ResourceCache, reporter, factory) { |
988 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 1053 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
989 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); | 1054 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); |
990 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 1055 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
991 continue; | 1056 continue; |
992 } | 1057 } |
993 GrContext* context = factory->get(glType); | 1058 GrContext* context = factory->get(glType); |
994 if (NULL == context) { | 1059 if (NULL == context) { |
995 continue; | 1060 continue; |
(...skipping 15 matching lines...) Expand all Loading... | |
1011 test_budgeting(reporter); | 1076 test_budgeting(reporter); |
1012 test_unbudgeted(reporter); | 1077 test_unbudgeted(reporter); |
1013 test_unbudgeted_to_scratch(reporter); | 1078 test_unbudgeted_to_scratch(reporter); |
1014 test_duplicate_unique_key(reporter); | 1079 test_duplicate_unique_key(reporter); |
1015 test_duplicate_scratch_key(reporter); | 1080 test_duplicate_scratch_key(reporter); |
1016 test_remove_scratch_key(reporter); | 1081 test_remove_scratch_key(reporter); |
1017 test_scratch_key_consistency(reporter); | 1082 test_scratch_key_consistency(reporter); |
1018 test_purge_invalidated(reporter); | 1083 test_purge_invalidated(reporter); |
1019 test_cache_chained_purge(reporter); | 1084 test_cache_chained_purge(reporter); |
1020 test_resource_size_changed(reporter); | 1085 test_resource_size_changed(reporter); |
1086 test_timestamp_wrap(reporter); | |
1021 test_large_resource_count(reporter); | 1087 test_large_resource_count(reporter); |
1022 } | 1088 } |
1023 | 1089 |
1024 #endif | 1090 #endif |
OLD | NEW |