OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #ifndef GrProcessorUnitTest_DEFINED | 8 #ifndef GrProcessorUnitTest_DEFINED |
9 #define GrProcessorUnitTest_DEFINED | 9 #define GrProcessorUnitTest_DEFINED |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 class GrProcessorTestFactory : SkNoncopyable { | 61 class GrProcessorTestFactory : SkNoncopyable { |
62 public: | 62 public: |
63 | 63 |
64 typedef const Processor* (*CreateProc)(GrProcessorTestData*); | 64 typedef const Processor* (*CreateProc)(GrProcessorTestData*); |
65 | 65 |
66 GrProcessorTestFactory(CreateProc createProc) { | 66 GrProcessorTestFactory(CreateProc createProc) { |
67 fCreateProc = createProc; | 67 fCreateProc = createProc; |
68 GetFactories()->push_back(this); | 68 GetFactories()->push_back(this); |
69 } | 69 } |
70 | 70 |
71 /** Pick a random factory function and create a processor. */ | 71 static const Processor* CreateStage(GrProcessorTestData* data) { |
72 static const Processor* Create(GrProcessorTestData* data) { | |
73 VerifyFactoryCount(); | 72 VerifyFactoryCount(); |
74 SkASSERT(GetFactories()->count()); | 73 SkASSERT(GetFactories()->count()); |
75 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1)
; | 74 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1)
; |
76 return CreateIdx(idx, data); | |
77 } | |
78 | |
79 /** Number of registered factory functions */ | |
80 static int Count() { return GetFactories()->count(); } | |
81 | |
82 /** Use factory function at Index idx to create a processor. */ | |
83 static const Processor* CreateIdx(int idx, GrProcessorTestData* data) { | |
84 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 75 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
85 return factory->fCreateProc(data); | 76 return factory->fCreateProc(data); |
86 } | 77 } |
87 | 78 |
88 /* | 79 /* |
89 * A test function which verifies the count of factories. | 80 * A test function which verifies the count of factories. |
90 */ | 81 */ |
91 static void VerifyFactoryCount(); | 82 static void VerifyFactoryCount(); |
92 | 83 |
93 private: | 84 private: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 #define GR_DEFINE_XP_FACTORY_TEST(X) | 131 #define GR_DEFINE_XP_FACTORY_TEST(X) |
141 | 132 |
142 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that | 133 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that |
143 // its definitions will compile. | 134 // its definitions will compile. |
144 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 135 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
145 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 136 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
146 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 137 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
147 | 138 |
148 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 139 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
149 #endif | 140 #endif |
OLD | NEW |