| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 class GrContext; | 34 class GrContext; |
| 35 class GrProcessor; | 35 class GrProcessor; |
| 36 class GrTexture; | 36 class GrTexture; |
| 37 | 37 |
| 38 template <class Processor> | 38 template <class Processor> |
| 39 class GrProcessorTestFactory : SkNoncopyable { | 39 class GrProcessorTestFactory : SkNoncopyable { |
| 40 public: | 40 public: |
| 41 | 41 |
| 42 typedef Processor* (*CreateProc)(SkRandom*, | 42 typedef Processor* (*CreateProc)(SkRandom*, |
| 43 GrContext*, | 43 GrContext*, |
| 44 const GrDrawTargetCaps& caps, | 44 const GrDrawTargetCaps& caps, |
| 45 GrTexture* dummyTextures[]); | 45 GrTexture* dummyTextures[]); |
| 46 | 46 |
| 47 GrProcessorTestFactory(CreateProc createProc) { | 47 GrProcessorTestFactory(CreateProc createProc) { |
| 48 fCreateProc = createProc; | 48 fCreateProc = createProc; |
| 49 GetFactories()->push_back(this); | 49 GetFactories()->push_back(this); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static Processor* CreateStage(SkRandom* random, | 52 static Processor* CreateStage(SkRandom* random, |
| 53 GrContext* context, | 53 GrContext* context, |
| 54 const GrDrawTargetCaps& caps, | 54 const GrDrawTargetCaps& caps, |
| 55 GrTexture* dummyTextures[]) { | 55 GrTexture* dummyTextures[]) { |
| 56 VerifyFactoryCount(); |
| 57 SkASSERT(GetFactories()->count()); |
| 56 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); | 58 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); |
| 57 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 59 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
| 58 return factory->fCreateProc(random, context, caps, dummyTextures); | 60 return factory->fCreateProc(random, context, caps, dummyTextures); |
| 59 } | 61 } |
| 60 | 62 |
| 63 /* |
| 64 * A test function which verifies the count of factories. |
| 65 */ |
| 66 static void VerifyFactoryCount(); |
| 67 |
| 61 private: | 68 private: |
| 62 CreateProc fCreateProc; | 69 CreateProc fCreateProc; |
| 63 | 70 |
| 64 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 71 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 }; | 72 }; |
| 71 | 73 |
| 72 /** GrProcessor subclasses should insert this macro in their declaration to be i
ncluded in the | 74 /** GrProcessor subclasses should insert this macro in their declaration to be i
ncluded in the |
| 73 * program generation unit test. | 75 * program generation unit test. |
| 74 */ | 76 */ |
| 75 | |
| 76 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 77 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
| 77 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory;
\ | 78 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED;
\ |
| 78 static GrGeometryProcessor* TestCreate(SkRandom*,
\ | 79 static GrGeometryProcessor* TestCreate(SkRandom*,
\ |
| 79 GrContext*,
\ | 80 GrContext*,
\ |
| 80 const GrDrawTargetCaps&,
\ | 81 const GrDrawTargetCaps&,
\ |
| 81 GrTexture* dummyTextures[2]) | 82 GrTexture* dummyTextures[2]) |
| 82 | 83 |
| 83 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ | 84 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ |
| 84 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory;
\ | 85 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED;
\ |
| 85 static GrFragmentProcessor* TestCreate(SkRandom*,
\ | 86 static GrFragmentProcessor* TestCreate(SkRandom*,
\ |
| 86 GrContext*,
\ | 87 GrContext*,
\ |
| 87 const GrDrawTargetCaps&,
\ | 88 const GrDrawTargetCaps&,
\ |
| 88 GrTexture* dummyTextures[2]) | 89 GrTexture* dummyTextures[2]) |
| 89 | 90 |
| 90 /** GrProcessor subclasses should insert this macro in their implementation file
. They must then | 91 /** GrProcessor subclasses should insert this macro in their implementation file
. They must then |
| 91 * also implement this static function: | 92 * also implement this static function: |
| 92 * GrProcessor* TestCreate(SkRandom*, | 93 * GrProcessor* TestCreate(SkRandom*, |
| 93 * GrContext*, | 94 * GrContext*, |
| 94 * const GrDrawTargetCaps&, | 95 * const GrDrawTargetCaps&, |
| 95 * GrTexture* dummyTextures[2]); | 96 * GrTexture* dummyTextures[2]); |
| 96 * dummyTextures[] are valid textures that can optionally be used to construct G
rTextureAccesses. | 97 * 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 | 98 * 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 | 99 * 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. | 120 // its definitions will compile. |
| 120 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 121 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
| 121 static GrGeometryProcessor* TestCreate(SkRandom*,
\ | 122 static GrGeometryProcessor* TestCreate(SkRandom*,
\ |
| 122 GrContext*,
\ | 123 GrContext*,
\ |
| 123 const GrDrawTargetCaps&,
\ | 124 const GrDrawTargetCaps&,
\ |
| 124 GrTexture* dummyTextures[2]) | 125 GrTexture* dummyTextures[2]) |
| 125 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 126 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
| 126 | 127 |
| 127 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 128 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 128 #endif | 129 #endif |
| OLD | NEW |