Chromium Code Reviews| Index: include/gpu/GrProcessorUnitTest.h |
| diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h |
| index 04ab2d15eb4e574273979b513352973fe2dc7d8e..5fe0c6294838e6a2fb500e91e192b2073d74d230 100644 |
| --- a/include/gpu/GrProcessorUnitTest.h |
| +++ b/include/gpu/GrProcessorUnitTest.h |
| @@ -35,14 +35,24 @@ class GrContext; |
| class GrProcessor; |
| class GrTexture; |
|
robertphillips
2014/10/01 19:45:56
Could we make this SK_ATTRIBUTE_UNUSED and put it
|
| +/* |
| + * To prevent the compiler from throwing out our static initializers, we use the below macro. |
| + * This was taken from gtest |
| + */ |
| +#if defined(__GNUC__) && !defined(COMPILER_ICC) |
| +# define GR_ATTRIBUTE_UNUSED __attribute__ ((unused)) |
| +#else |
| +# define GR_ATTRIBUTE_UNUSED |
| +#endif |
| + |
| template <class Processor> |
| class GrProcessorTestFactory : SkNoncopyable { |
| public: |
| typedef Processor* (*CreateProc)(SkRandom*, |
| - GrContext*, |
| - const GrDrawTargetCaps& caps, |
| - GrTexture* dummyTextures[]); |
| + GrContext*, |
| + const GrDrawTargetCaps& caps, |
| + GrTexture* dummyTextures[]); |
| GrProcessorTestFactory(CreateProc createProc) { |
| fCreateProc = createProc; |
| @@ -50,42 +60,43 @@ public: |
| } |
| static Processor* CreateStage(SkRandom* random, |
| - GrContext* context, |
| - const GrDrawTargetCaps& caps, |
| - GrTexture* dummyTextures[]) { |
| + GrContext* context, |
| + const GrDrawTargetCaps& caps, |
| + GrTexture* dummyTextures[]) { |
| + VerifyFactoryCount(); |
| + SkASSERT(GetFactories()->count()); |
| uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); |
| GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
| return factory->fCreateProc(random, context, caps, dummyTextures); |
| } |
| + /* |
|
robertphillips
2014/10/01 19:45:56
Capital 'A' ?
|
| + * a test function which verifies the count of factories. |
| + */ |
| + static void VerifyFactoryCount(); |
| + |
| private: |
| CreateProc fCreateProc; |
| - #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| - static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories() { |
| - static SkTArray<GrProcessorTestFactory<Processor>*, true> gFactories; |
| - return &gFactories; |
| - } |
| - #endif |
| + static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); |
| }; |
| /** GrProcessor subclasses should insert this macro in their declaration to be included in the |
| * program generation unit test. |
| */ |
| - |
| #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ |
| - static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory; \ |
| + static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory GR_ATTRIBUTE_UNUSED; \ |
| static GrGeometryProcessor* TestCreate(SkRandom*, \ |
| - GrContext*, \ |
| - const GrDrawTargetCaps&, \ |
| - GrTexture* dummyTextures[2]) |
| + GrContext*, \ |
| + const GrDrawTargetCaps&, \ |
| + GrTexture* dummyTextures[2]) |
| #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ |
| - static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory; \ |
| + static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory GR_ATTRIBUTE_UNUSED; \ |
| static GrFragmentProcessor* TestCreate(SkRandom*, \ |
| - GrContext*, \ |
| - const GrDrawTargetCaps&, \ |
| - GrTexture* dummyTextures[2]) |
| + GrContext*, \ |
| + const GrDrawTargetCaps&, \ |
| + GrTexture* dummyTextures[2]) |
| /** GrProcessor subclasses should insert this macro in their implementation file. They must then |
| * also implement this static function: |