Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 */ | 27 */ |
| 28 const SkMatrix& TestMatrix(SkRandom*); | 28 const SkMatrix& TestMatrix(SkRandom*); |
| 29 | 29 |
| 30 } | 30 } |
| 31 | 31 |
| 32 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 32 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 33 | 33 |
| 34 class GrContext; | 34 class GrContext; |
| 35 class GrProcessor; | 35 class GrProcessor; |
| 36 class GrTexture; | 36 class GrTexture; |
| 37 | 37 |
|
robertphillips
2014/10/01 19:45:56
Could we make this SK_ATTRIBUTE_UNUSED and put it
| |
| 38 /* | |
| 39 * To prevent the compiler from throwing out our static initializers, we use the below macro. | |
| 40 * This was taken from gtest | |
| 41 */ | |
| 42 #if defined(__GNUC__) && !defined(COMPILER_ICC) | |
| 43 # define GR_ATTRIBUTE_UNUSED __attribute__ ((unused)) | |
| 44 #else | |
| 45 # define GR_ATTRIBUTE_UNUSED | |
| 46 #endif | |
| 47 | |
| 38 template <class Processor> | 48 template <class Processor> |
| 39 class GrProcessorTestFactory : SkNoncopyable { | 49 class GrProcessorTestFactory : SkNoncopyable { |
| 40 public: | 50 public: |
| 41 | 51 |
| 42 typedef Processor* (*CreateProc)(SkRandom*, | 52 typedef Processor* (*CreateProc)(SkRandom*, |
| 43 GrContext*, | 53 GrContext*, |
| 44 const GrDrawTargetCaps& caps, | 54 const GrDrawTargetCaps& caps, |
| 45 GrTexture* dummyTextures[]); | 55 GrTexture* dummyTextures[]); |
| 46 | 56 |
| 47 GrProcessorTestFactory(CreateProc createProc) { | 57 GrProcessorTestFactory(CreateProc createProc) { |
| 48 fCreateProc = createProc; | 58 fCreateProc = createProc; |
| 49 GetFactories()->push_back(this); | 59 GetFactories()->push_back(this); |
| 50 } | 60 } |
| 51 | 61 |
| 52 static Processor* CreateStage(SkRandom* random, | 62 static Processor* CreateStage(SkRandom* random, |
| 53 GrContext* context, | 63 GrContext* context, |
| 54 const GrDrawTargetCaps& caps, | 64 const GrDrawTargetCaps& caps, |
| 55 GrTexture* dummyTextures[]) { | 65 GrTexture* dummyTextures[]) { |
| 66 VerifyFactoryCount(); | |
| 67 SkASSERT(GetFactories()->count()); | |
| 56 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); | 68 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); |
| 57 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 69 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
| 58 return factory->fCreateProc(random, context, caps, dummyTextures); | 70 return factory->fCreateProc(random, context, caps, dummyTextures); |
| 59 } | 71 } |
| 60 | 72 |
| 73 /* | |
|
robertphillips
2014/10/01 19:45:56
Capital 'A' ?
| |
| 74 * a test function which verifies the count of factories. | |
| 75 */ | |
| 76 static void VerifyFactoryCount(); | |
| 77 | |
| 61 private: | 78 private: |
| 62 CreateProc fCreateProc; | 79 CreateProc fCreateProc; |
| 63 | 80 |
| 64 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 81 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); |
| 65 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories() { | |
| 66 static SkTArray<GrProcessorTestFactory<Processor>*, true> gFactories; | |
| 67 return &gFactories; | |
| 68 } | |
| 69 #endif | |
| 70 }; | 82 }; |
| 71 | 83 |
| 72 /** GrProcessor subclasses should insert this macro in their declaration to be i ncluded in the | 84 /** GrProcessor subclasses should insert this macro in their declaration to be i ncluded in the |
| 73 * program generation unit test. | 85 * program generation unit test. |
| 74 */ | 86 */ |
| 75 | |
| 76 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ | 87 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ |
| 77 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory; \ | 88 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory GR_ATTRIBUTE _UNUSED; \ |
| 78 static GrGeometryProcessor* TestCreate(SkRandom*, \ | 89 static GrGeometryProcessor* TestCreate(SkRandom*, \ |
| 79 GrContext*, \ | 90 GrContext*, \ |
| 80 const GrDrawTargetCaps&, \ | 91 const GrDrawTargetCaps&, \ |
| 81 GrTexture* dummyTextures[2]) | 92 GrTexture* dummyTextures[2]) |
| 82 | 93 |
| 83 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ | 94 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ |
| 84 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory; \ | 95 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory GR_ATTRIBUTE _UNUSED; \ |
| 85 static GrFragmentProcessor* TestCreate(SkRandom*, \ | 96 static GrFragmentProcessor* TestCreate(SkRandom*, \ |
| 86 GrContext*, \ | 97 GrContext*, \ |
| 87 const GrDrawTargetCaps&, \ | 98 const GrDrawTargetCaps&, \ |
| 88 GrTexture* dummyTextures[2]) | 99 GrTexture* dummyTextures[2]) |
| 89 | 100 |
| 90 /** GrProcessor subclasses should insert this macro in their implementation file . They must then | 101 /** GrProcessor subclasses should insert this macro in their implementation file . They must then |
| 91 * also implement this static function: | 102 * also implement this static function: |
| 92 * GrProcessor* TestCreate(SkRandom*, | 103 * GrProcessor* TestCreate(SkRandom*, |
| 93 * GrContext*, | 104 * GrContext*, |
| 94 * const GrDrawTargetCaps&, | 105 * const GrDrawTargetCaps&, |
| 95 * GrTexture* dummyTextures[2]); | 106 * GrTexture* dummyTextures[2]); |
| 96 * dummyTextures[] are valid textures that can optionally be used to construct G rTextureAccesses. | 107 * dummyTextures[] are valid textures that can optionally be used to construct G rTextureAccesses. |
| 97 * The first texture has config kSkia8888_GrPixelConfig and the second has | 108 * The first texture has config kSkia8888_GrPixelConfig and the second has |
| 98 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition al textures using | 109 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition al textures using |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 119 // its definitions will compile. | 130 // its definitions will compile. |
| 120 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ | 131 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ |
| 121 static GrGeometryProcessor* TestCreate(SkRandom*, \ | 132 static GrGeometryProcessor* TestCreate(SkRandom*, \ |
| 122 GrContext*, \ | 133 GrContext*, \ |
| 123 const GrDrawTargetCaps&, \ | 134 const GrDrawTargetCaps&, \ |
| 124 GrTexture* dummyTextures[2]) | 135 GrTexture* dummyTextures[2]) |
| 125 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 136 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
| 126 | 137 |
| 127 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 138 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 128 #endif | 139 #endif |
| OLD | NEW |