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 12 matching lines...) Expand all Loading... | |
23 }; | 23 }; |
24 | 24 |
25 } | 25 } |
26 | 26 |
27 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 27 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
28 | 28 |
29 class GrContext; | 29 class GrContext; |
30 class GrProcessor; | 30 class GrProcessor; |
31 class GrTexture; | 31 class GrTexture; |
32 | 32 |
33 /* | |
34 * GrProcessorTestData is an argument struct to TestCreate functions | |
bsalomon
2015/07/08 19:46:35
update comment? I see no dummyextures.
Maybe use
| |
35 * dummyTextures[] are valid textures that can optionally be used to construct G rTextureAccesses. | |
36 * The first texture has config kSkia8888_GrPixelConfig and the second has | |
37 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition al textures using | |
38 * the GrContext. | |
39 */ | |
40 struct GrProcessorTestData { | |
41 GrProcessorTestData(SkRandom* random, | |
42 GrContext* context, | |
43 GrShaderDataManager* shaderDataManager, | |
44 const GrCaps* caps, | |
45 GrTexture** textures) | |
46 : fRandom(random) | |
47 , fContext(context) | |
48 , fShaderDataManager(shaderDataManager) | |
49 , fCaps(caps) | |
50 , fTextures(textures) {} | |
51 SkRandom* fRandom; | |
52 GrContext* fContext; | |
53 GrShaderDataManager* fShaderDataManager; | |
54 const GrCaps* fCaps; | |
55 GrTexture** fTextures; | |
56 }; | |
57 | |
33 template <class Processor> | 58 template <class Processor> |
34 class GrProcessorTestFactory : SkNoncopyable { | 59 class GrProcessorTestFactory : SkNoncopyable { |
35 public: | 60 public: |
36 | 61 |
37 typedef Processor* (*CreateProc)(SkRandom*, | 62 typedef Processor* (*CreateProc)(GrProcessorTestData*); |
38 GrContext*, | |
39 const GrCaps& caps, | |
40 GrTexture* dummyTextures[]); | |
41 | 63 |
42 GrProcessorTestFactory(CreateProc createProc) { | 64 GrProcessorTestFactory(CreateProc createProc) { |
43 fCreateProc = createProc; | 65 fCreateProc = createProc; |
44 GetFactories()->push_back(this); | 66 GetFactories()->push_back(this); |
45 } | 67 } |
46 | 68 |
47 static Processor* CreateStage(SkRandom* random, | 69 static Processor* CreateStage(GrProcessorTestData* data) { |
48 GrContext* context, | |
49 const GrCaps& caps, | |
50 GrTexture* dummyTextures[]) { | |
51 VerifyFactoryCount(); | 70 VerifyFactoryCount(); |
52 SkASSERT(GetFactories()->count()); | 71 SkASSERT(GetFactories()->count()); |
53 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); | 72 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1) ; |
54 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 73 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
55 return factory->fCreateProc(random, context, caps, dummyTextures); | 74 return factory->fCreateProc(data); |
56 } | 75 } |
57 | 76 |
58 /* | 77 /* |
59 * A test function which verifies the count of factories. | 78 * A test function which verifies the count of factories. |
60 */ | 79 */ |
61 static void VerifyFactoryCount(); | 80 static void VerifyFactoryCount(); |
62 | 81 |
63 private: | 82 private: |
64 CreateProc fCreateProc; | 83 CreateProc fCreateProc; |
65 | 84 |
66 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); | 85 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); |
67 }; | 86 }; |
68 | 87 |
69 /** GrProcessor subclasses should insert this macro in their declaration to be i ncluded in the | 88 /** GrProcessor subclasses should insert this macro in their declaration to be i ncluded in the |
70 * program generation unit test. | 89 * program generation unit test. |
71 */ | 90 */ |
72 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ | 91 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ |
73 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \ | 92 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \ |
74 static GrGeometryProcessor* TestCreate(SkRandom*, \ | 93 static GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
75 GrContext*, \ | |
76 const GrCaps&, \ | |
77 GrTexture* dummyTextures[2]) | |
78 | 94 |
79 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ | 95 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ |
80 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \ | 96 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \ |
81 static GrFragmentProcessor* TestCreate(SkRandom*, \ | 97 static GrFragmentProcessor* TestCreate(GrProcessorTestData*) |
82 GrContext*, \ | |
83 const GrCaps&, \ | |
84 GrTexture* dummyTextures[2]) | |
85 | 98 |
86 #define GR_DECLARE_XP_FACTORY_TEST \ | 99 #define GR_DECLARE_XP_FACTORY_TEST \ |
87 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \ | 100 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \ |
88 static GrXPFactory* TestCreate(SkRandom*, \ | 101 static GrXPFactory* TestCreate(GrProcessorTestData*) |
89 GrContext*, \ | |
90 const GrCaps&, \ | |
91 GrTexture* dummyTextures[2]) | |
92 | 102 |
93 | 103 |
94 /** GrProcessor subclasses should insert this macro in their implementation file . They must then | 104 /** GrProcessor subclasses should insert this macro in their implementation file . They must then |
95 * also implement this static function: | 105 * also implement this static function: |
96 * GrProcessor* TestCreate(SkRandom*, | 106 * GrProcessor* TestCreate(GrProcessorTestData*); |
97 * GrContext*, | |
98 * const GrCaps&, | |
99 * GrTexture* dummyTextures[2]); | |
100 * dummyTextures[] are valid textures that can optionally be used to construct G rTextureAccesses. | |
101 * The first texture has config kSkia8888_GrPixelConfig and the second has | |
102 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition al textures using | |
103 * the GrContext. | |
104 */ | 107 */ |
105 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \ | 108 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \ |
106 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect :: TestCreate) | 109 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect :: TestCreate) |
107 | 110 |
108 #define GR_DEFINE_XP_FACTORY_TEST(Factory) \ | 111 #define GR_DEFINE_XP_FACTORY_TEST(Factory) \ |
109 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC reate) | 112 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC reate) |
110 | 113 |
111 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \ | 114 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \ |
112 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect :: TestCreate) | 115 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect :: TestCreate) |
113 | 116 |
114 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 117 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
115 | 118 |
116 // The unit test relies on static initializers. Just declare the TestCreate func tion so that | 119 // The unit test relies on static initializers. Just declare the TestCreate func tion so that |
117 // its definitions will compile. | 120 // its definitions will compile. |
118 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ | 121 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ |
119 static GrFragmentProcessor* TestCreate(SkRandom*, \ | 122 static GrFragmentProcessor* TestCreate(GrProcessorTestData*) |
120 GrContext*, \ | |
121 const GrCaps&, \ | |
122 GrTexture* dummyTextures[2]) | |
123 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) | 123 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) |
124 | 124 |
125 // The unit test relies on static initializers. Just declare the TestCreate func tion so that | 125 // The unit test relies on static initializers. Just declare the TestCreate func tion so that |
126 // its definitions will compile. | 126 // its definitions will compile. |
127 #define GR_DECLARE_XP_FACTORY_TEST \ | 127 #define GR_DECLARE_XP_FACTORY_TEST \ |
128 static GrXPFactory* TestCreate(SkRandom*, \ | 128 static GrXPFactory* TestCreate(GrProcessorTestData*) |
129 GrContext*, \ | |
130 const GrCaps&, \ | |
131 GrTexture* dummyTextures[2]) | |
132 #define GR_DEFINE_XP_FACTORY_TEST(X) | 129 #define GR_DEFINE_XP_FACTORY_TEST(X) |
133 | 130 |
134 // The unit test relies on static initializers. Just declare the TestCreate func tion so that | 131 // The unit test relies on static initializers. Just declare the TestCreate func tion so that |
135 // its definitions will compile. | 132 // its definitions will compile. |
136 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ | 133 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ |
137 static GrGeometryProcessor* TestCreate(SkRandom*, \ | 134 static GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
138 GrContext*, \ | |
139 const GrCaps&, \ | |
140 GrTexture* dummyTextures[2]) | |
141 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 135 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
142 | 136 |
143 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 137 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
144 #endif | 138 #endif |
OLD | NEW |