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 |
11 #include "GrMemoryPool.h" | 11 #include "GrMemoryPool.h" |
12 #include "SkInstCnt.h" | |
13 #include "SkRandom.h" | 12 #include "SkRandom.h" |
14 #include "SkTDArray.h" | 13 #include "SkTDArray.h" |
15 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
16 | 15 |
17 // A is the top of an inheritance tree of classes that overload op new and | 16 // A is the top of an inheritance tree of classes that overload op new and |
18 // and delete to use a GrMemoryPool. The objects have values of different types | 17 // and delete to use a GrMemoryPool. The objects have values of different types |
19 // that can be set and checked. | 18 // that can be set and checked. |
20 class A { | 19 class A { |
21 public: | 20 public: |
22 A() {}; | 21 A() {}; |
(...skipping 14 matching lines...) Expand all Loading... |
37 } | 36 } |
38 | 37 |
39 void operator delete(void* p) { | 38 void operator delete(void* p) { |
40 if (!gPool.get()) { | 39 if (!gPool.get()) { |
41 ::operator delete(p); | 40 ::operator delete(p); |
42 } else { | 41 } else { |
43 return gPool->release(p); | 42 return gPool->release(p); |
44 } | 43 } |
45 } | 44 } |
46 | 45 |
47 SK_DECLARE_INST_COUNT(A); | |
48 | |
49 static A* Create(SkRandom* r); | 46 static A* Create(SkRandom* r); |
50 | 47 |
51 static void SetAllocator(size_t preallocSize, size_t minAllocSize) { | 48 static void SetAllocator(size_t preallocSize, size_t minAllocSize) { |
52 #if SK_ENABLE_INST_COUNT | |
53 SkASSERT(0 == GetInstanceCount()); | |
54 #endif | |
55 GrMemoryPool* pool = new GrMemoryPool(preallocSize, minAllocSize); | 49 GrMemoryPool* pool = new GrMemoryPool(preallocSize, minAllocSize); |
56 gPool.reset(pool); | 50 gPool.reset(pool); |
57 } | 51 } |
58 | 52 |
59 static void ResetAllocator() { | 53 static void ResetAllocator() { |
60 #if SK_ENABLE_INST_COUNT | |
61 SkASSERT(0 == GetInstanceCount()); | |
62 #endif | |
63 gPool.reset(NULL); | 54 gPool.reset(NULL); |
64 } | 55 } |
65 | 56 |
66 private: | 57 private: |
67 static SkAutoTDelete<GrMemoryPool> gPool; | 58 static SkAutoTDelete<GrMemoryPool> gPool; |
68 char fChar; | 59 char fChar; |
69 }; | 60 }; |
70 | 61 |
71 SkAutoTDelete<GrMemoryPool> A::gPool; | 62 SkAutoTDelete<GrMemoryPool> A::gPool; |
72 | 63 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 Rec& rec = instanceRecs[r]; | 216 Rec& rec = instanceRecs[r]; |
226 REPORTER_ASSERT(reporter, rec.fInstance->checkValues(rec
.fValue)); | 217 REPORTER_ASSERT(reporter, rec.fInstance->checkValues(rec
.fValue)); |
227 } | 218 } |
228 } | 219 } |
229 } | 220 } |
230 for (int i = 0; i < instanceRecs.count(); ++i) { | 221 for (int i = 0; i < instanceRecs.count(); ++i) { |
231 Rec& rec = instanceRecs[i]; | 222 Rec& rec = instanceRecs[i]; |
232 REPORTER_ASSERT(reporter, rec.fInstance->checkValues(rec.fValue)
); | 223 REPORTER_ASSERT(reporter, rec.fInstance->checkValues(rec.fValue)
); |
233 delete rec.fInstance; | 224 delete rec.fInstance; |
234 } | 225 } |
235 #if SK_ENABLE_INST_COUNT | |
236 REPORTER_ASSERT(reporter, !A::GetInstanceCount()); | |
237 #endif | |
238 } | 226 } |
239 } | 227 } |
240 } | 228 } |
241 | 229 |
242 #endif | 230 #endif |
OLD | NEW |