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 static const int kCount = 50; |
| 928 static const int kBudgetCnt = kCount / 2; |
| 929 static const int kLockedFreq = 8; |
| 930 static const int kBudgetSize = 0x80000000; |
| 931 |
| 932 SkRandom random; |
| 933 |
| 934 // Run the test 2*kCount times; |
| 935 for (int i = 0; i < 2 * kCount; ++i ) { |
| 936 Mock mock(kBudgetCnt, kBudgetSize); |
| 937 GrContext* context = mock.context(); |
| 938 GrResourceCache* cache = mock.cache(); |
| 939 |
| 940 // Pick a random number of resources to add before the timestamp will wr
ap. |
| 941 cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1)); |
| 942 |
| 943 static const int kNumToPurge = kCount - kBudgetCnt; |
| 944 |
| 945 SkTDArray<int> shouldPurgeIdxs; |
| 946 int purgeableCnt = 0; |
| 947 SkTDArray<GrGpuResource*> resourcesToUnref; |
| 948 |
| 949 // Add kCount resources, holding onto resources at random so we have a m
ix of purgeable and |
| 950 // unpurgeable resources. |
| 951 for (int j = 0; j < kCount; ++j) { |
| 952 GrUniqueKey key; |
| 953 make_unique_key<0>(&key, j); |
| 954 |
| 955 TestResource* r = SkNEW_ARGS(TestResource, (context->getGpu())); |
| 956 r->resourcePriv().setUniqueKey(key); |
| 957 if (random.nextU() % kLockedFreq) { |
| 958 // Make this is purgeable. |
| 959 r->unref(); |
| 960 ++purgeableCnt; |
| 961 if (purgeableCnt <= kNumToPurge) { |
| 962 *shouldPurgeIdxs.append() = j; |
| 963 } |
| 964 } else { |
| 965 *resourcesToUnref.append() = r; |
| 966 } |
| 967 } |
| 968 |
| 969 // Verify that the correct resources were purged. |
| 970 int currShouldPurgeIdx = 0; |
| 971 for (int j = 0; j < kCount; ++j) { |
| 972 GrUniqueKey key; |
| 973 make_unique_key<0>(&key, j); |
| 974 GrGpuResource* res = cache->findAndRefUniqueResource(key); |
| 975 if (currShouldPurgeIdx < shouldPurgeIdxs.count() && |
| 976 shouldPurgeIdxs[currShouldPurgeIdx] == j) { |
| 977 ++currShouldPurgeIdx; |
| 978 REPORTER_ASSERT(reporter, NULL == res); |
| 979 } else { |
| 980 REPORTER_ASSERT(reporter, NULL != res); |
| 981 } |
| 982 SkSafeUnref(res); |
| 983 } |
| 984 |
| 985 for (int j = 0; j < resourcesToUnref.count(); ++j) { |
| 986 resourcesToUnref[j]->unref(); |
| 987 } |
| 988 } |
| 989 } |
| 990 |
926 static void test_large_resource_count(skiatest::Reporter* reporter) { | 991 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 | 992 // 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 | 993 // 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. | 994 // down to 1 byte after creating the resource. |
930 static const int kResourceCnt = 2000; | 995 static const int kResourceCnt = 2000; |
931 | 996 |
932 Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); | 997 Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); |
933 GrContext* context = mock.context(); | 998 GrContext* context = mock.context(); |
934 GrResourceCache* cache = mock.cache(); | 999 GrResourceCache* cache = mock.cache(); |
935 | 1000 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 for (int i = 0; i < kResourceCnt; ++i) { | 1040 for (int i = 0; i < kResourceCnt; ++i) { |
976 GrUniqueKey key1, key2; | 1041 GrUniqueKey key1, key2; |
977 make_unique_key<1>(&key1, i); | 1042 make_unique_key<1>(&key1, i); |
978 make_unique_key<2>(&key2, i); | 1043 make_unique_key<2>(&key2, i); |
979 | 1044 |
980 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); | 1045 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
981 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); | 1046 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
982 } | 1047 } |
983 } | 1048 } |
984 | 1049 |
985 | |
986 //////////////////////////////////////////////////////////////////////////////// | 1050 //////////////////////////////////////////////////////////////////////////////// |
987 DEF_GPUTEST(ResourceCache, reporter, factory) { | 1051 DEF_GPUTEST(ResourceCache, reporter, factory) { |
988 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 1052 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
989 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 1053 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
990 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 1054 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
991 continue; | 1055 continue; |
992 } | 1056 } |
993 GrContext* context = factory->get(glType); | 1057 GrContext* context = factory->get(glType); |
994 if (NULL == context) { | 1058 if (NULL == context) { |
995 continue; | 1059 continue; |
(...skipping 15 matching lines...) Expand all Loading... |
1011 test_budgeting(reporter); | 1075 test_budgeting(reporter); |
1012 test_unbudgeted(reporter); | 1076 test_unbudgeted(reporter); |
1013 test_unbudgeted_to_scratch(reporter); | 1077 test_unbudgeted_to_scratch(reporter); |
1014 test_duplicate_unique_key(reporter); | 1078 test_duplicate_unique_key(reporter); |
1015 test_duplicate_scratch_key(reporter); | 1079 test_duplicate_scratch_key(reporter); |
1016 test_remove_scratch_key(reporter); | 1080 test_remove_scratch_key(reporter); |
1017 test_scratch_key_consistency(reporter); | 1081 test_scratch_key_consistency(reporter); |
1018 test_purge_invalidated(reporter); | 1082 test_purge_invalidated(reporter); |
1019 test_cache_chained_purge(reporter); | 1083 test_cache_chained_purge(reporter); |
1020 test_resource_size_changed(reporter); | 1084 test_resource_size_changed(reporter); |
| 1085 test_timestamp_wrap(reporter); |
1021 test_large_resource_count(reporter); | 1086 test_large_resource_count(reporter); |
1022 } | 1087 } |
1023 | 1088 |
1024 #endif | 1089 #endif |
OLD | NEW |