| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 GrProcessorTestFactory(CreateProc createProc) { | 108 GrProcessorTestFactory(CreateProc createProc) { |
| 109 fCreateProc = createProc; | 109 fCreateProc = createProc; |
| 110 GetFactories()->push_back(this); | 110 GetFactories()->push_back(this); |
| 111 } | 111 } |
| 112 | 112 |
| 113 static Processor* CreateStage(SkRandom* random, | 113 static Processor* CreateStage(SkRandom* random, |
| 114 GrContext* context, | 114 GrContext* context, |
| 115 const GrDrawTargetCaps& caps, | 115 const GrDrawTargetCaps& caps, |
| 116 GrTexture* dummyTextures[]) { | 116 GrTexture* dummyTextures[]) { |
| 117 VerifyFactoryCount(); | 117 VerifyFactoryCount(); |
| 118 SkASSERT(GetFactories()->count()); | 118 int count = GetFactories()->count(); |
| 119 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); | 119 SkASSERT(count); |
| 120 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 120 uint32_t idx = random->nextRangeU(0, count - 1); |
| 121 return factory->fCreateProc(random, context, caps, dummyTextures); | 121 Processor* p = (*GetFactories())[idx]->fCreateProc(random, context, caps
, dummyTextures); |
| 122 if (!p) { |
| 123 // Factory at idx was not supported on this GrContext. Find one that
is. |
| 124 SkSTArray<8, GrProcessorTestFactory<Processor>*, true> localFactorie
s(*GetFactories()); |
| 125 do { |
| 126 count--; |
| 127 SkASSERT(count); |
| 128 SkTSwap(localFactories[idx], localFactories[count]); |
| 129 idx = random->nextRangeU(0, count - 1); |
| 130 } while (!(p = localFactories[idx]->fCreateProc(random, context, cap
s, dummyTextures))); |
| 131 } |
| 132 return p; |
| 122 } | 133 } |
| 123 | 134 |
| 124 /* | 135 /* |
| 125 * A test function which verifies the count of factories. | 136 * A test function which verifies the count of factories. |
| 126 */ | 137 */ |
| 127 static void VerifyFactoryCount(); | 138 static void VerifyFactoryCount(); |
| 128 | 139 |
| 129 private: | 140 private: |
| 130 CreateProc fCreateProc; | 141 CreateProc fCreateProc; |
| 131 | 142 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // its definitions will compile. | 212 // its definitions will compile. |
| 202 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 213 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
| 203 static GrGeometryProcessor* TestCreate(SkRandom*,
\ | 214 static GrGeometryProcessor* TestCreate(SkRandom*,
\ |
| 204 GrContext*,
\ | 215 GrContext*,
\ |
| 205 const GrDrawTargetCaps&,
\ | 216 const GrDrawTargetCaps&,
\ |
| 206 GrTexture* dummyTextures[2]) | 217 GrTexture* dummyTextures[2]) |
| 207 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 218 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
| 208 | 219 |
| 209 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 220 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 210 #endif | 221 #endif |
| OLD | NEW |