| 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 static const Processor* CreateStage(GrProcessorTestData* data) { | 71 /** Pick a random factory function and create a processor. */ |
| 72 static const Processor* Create(GrProcessorTestData* data) { |
| 72 VerifyFactoryCount(); | 73 VerifyFactoryCount(); |
| 73 SkASSERT(GetFactories()->count()); | 74 SkASSERT(GetFactories()->count()); |
| 74 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1)
; | 75 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) { |
| 75 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 84 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
| 76 return factory->fCreateProc(data); | 85 return factory->fCreateProc(data); |
| 77 } | 86 } |
| 78 | 87 |
| 79 /* | 88 /* |
| 80 * A test function which verifies the count of factories. | 89 * A test function which verifies the count of factories. |
| 81 */ | 90 */ |
| 82 static void VerifyFactoryCount(); | 91 static void VerifyFactoryCount(); |
| 83 | 92 |
| 84 private: | 93 private: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 #define GR_DEFINE_XP_FACTORY_TEST(X) | 140 #define GR_DEFINE_XP_FACTORY_TEST(X) |
| 132 | 141 |
| 133 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that | 142 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that |
| 134 // its definitions will compile. | 143 // its definitions will compile. |
| 135 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 144 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
| 136 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 145 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
| 137 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 146 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
| 138 | 147 |
| 139 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 148 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 140 #endif | 149 #endif |
| OLD | NEW |