OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "Test.h" | 8 #include "Test.h" |
9 // This is a GPU-backend specific test | 9 // This is a GPU-backend specific test |
10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 29 matching lines...) Expand all Loading... |
40 void operator delete(void* p) { | 40 void operator delete(void* p) { |
41 if (!gPool.get()) { | 41 if (!gPool.get()) { |
42 ::operator delete(p); | 42 ::operator delete(p); |
43 } else { | 43 } else { |
44 return gPool->release(p); | 44 return gPool->release(p); |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 SK_DECLARE_INST_COUNT_ROOT(A); | 48 SK_DECLARE_INST_COUNT_ROOT(A); |
49 | 49 |
50 static A* Create(SkMWCRandom* r); | 50 static A* Create(SkRandom* r); |
51 | 51 |
52 static void SetAllocator(size_t preallocSize, size_t minAllocSize) { | 52 static void SetAllocator(size_t preallocSize, size_t minAllocSize) { |
53 #if SK_ENABLE_INST_COUNT | 53 #if SK_ENABLE_INST_COUNT |
54 SkASSERT(0 == GetInstanceCount()); | 54 SkASSERT(0 == GetInstanceCount()); |
55 #endif | 55 #endif |
56 GrMemoryPool* pool = new GrMemoryPool(preallocSize, minAllocSize); | 56 GrMemoryPool* pool = new GrMemoryPool(preallocSize, minAllocSize); |
57 gPool.reset(pool); | 57 gPool.reset(pool); |
58 } | 58 } |
59 | 59 |
60 static void ResetAllocator() { | 60 static void ResetAllocator() { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 return ok && this->INHERITED::checkValues(v); | 154 return ok && this->INHERITED::checkValues(v); |
155 } | 155 } |
156 virtual ~E() {} | 156 virtual ~E() {} |
157 private: | 157 private: |
158 int fIntArray[20]; | 158 int fIntArray[20]; |
159 | 159 |
160 typedef A INHERITED; | 160 typedef A INHERITED; |
161 }; | 161 }; |
162 | 162 |
163 A* A::Create(SkMWCRandom* r) { | 163 A* A::Create(SkRandom* r) { |
164 switch (r->nextRangeU(0, 4)) { | 164 switch (r->nextRangeU(0, 4)) { |
165 case 0: | 165 case 0: |
166 return new A; | 166 return new A; |
167 case 1: | 167 case 1: |
168 return new B; | 168 return new B; |
169 case 2: | 169 case 2: |
170 return new C; | 170 return new C; |
171 case 3: | 171 case 3: |
172 return new D; | 172 return new D; |
173 case 4: | 173 case 4: |
(...skipping 20 matching lines...) Expand all Loading... |
194 {1, 100 * sizeof(A)}, | 194 {1, 100 * sizeof(A)}, |
195 }; | 195 }; |
196 // different percentages of creation vs deletion | 196 // different percentages of creation vs deletion |
197 static const float gCreateFraction[] = {1.f, .95f, 0.75f, .5f}; | 197 static const float gCreateFraction[] = {1.f, .95f, 0.75f, .5f}; |
198 // number of create/destroys per test | 198 // number of create/destroys per test |
199 static const int kNumIters = 20000; | 199 static const int kNumIters = 20000; |
200 // check that all the values stored in A objects are correct after this | 200 // check that all the values stored in A objects are correct after this |
201 // number of iterations | 201 // number of iterations |
202 static const int kCheckPeriod = 500; | 202 static const int kCheckPeriod = 500; |
203 | 203 |
204 SkMWCRandom r; | 204 SkRandom r; |
205 for (size_t s = 0; s < SK_ARRAY_COUNT(gSizes); ++s) { | 205 for (size_t s = 0; s < SK_ARRAY_COUNT(gSizes); ++s) { |
206 A::SetAllocator(gSizes[s][0], gSizes[s][1]); | 206 A::SetAllocator(gSizes[s][0], gSizes[s][1]); |
207 for (size_t c = 0; c < SK_ARRAY_COUNT(gCreateFraction); ++c) { | 207 for (size_t c = 0; c < SK_ARRAY_COUNT(gCreateFraction); ++c) { |
208 SkTDArray<Rec> instanceRecs; | 208 SkTDArray<Rec> instanceRecs; |
209 for (int i = 0; i < kNumIters; ++i) { | 209 for (int i = 0; i < kNumIters; ++i) { |
210 float createOrDestroy = r.nextUScalar1(); | 210 float createOrDestroy = r.nextUScalar1(); |
211 if (createOrDestroy < gCreateFraction[c] || | 211 if (createOrDestroy < gCreateFraction[c] || |
212 0 == instanceRecs.count()) { | 212 0 == instanceRecs.count()) { |
213 Rec* rec = instanceRecs.append(); | 213 Rec* rec = instanceRecs.append(); |
214 rec->fInstance = A::Create(&r); | 214 rec->fInstance = A::Create(&r); |
(...skipping 22 matching lines...) Expand all Loading... |
237 REPORTER_ASSERT(reporter, !A::GetInstanceCount()); | 237 REPORTER_ASSERT(reporter, !A::GetInstanceCount()); |
238 #endif | 238 #endif |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 #include "TestClassDef.h" | 243 #include "TestClassDef.h" |
244 DEFINE_TESTCLASS("GrMemoryPool", GrMemoryPoolClass, test_memory_pool) | 244 DEFINE_TESTCLASS("GrMemoryPool", GrMemoryPoolClass, test_memory_pool) |
245 | 245 |
246 #endif | 246 #endif |
OLD | NEW |