Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: include/gpu/GrProcessorUnitTest.h

Issue 1213623022: fix up test create functions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/effects/SkAlphaThresholdFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "GrTestUtils.h" 11 #include "GrTestUtils.h"
12 #include "SkTArray.h" 12 #include "SkTArray.h"
13 #include "SkTypes.h" 13 #include "SkTypes.h"
14 14
15 class SkMatrix; 15 class SkMatrix;
16 class GrCaps; 16 class GrCaps;
17 class GrContext;
17 18
18 namespace GrProcessorUnitTest { 19 namespace GrProcessorUnitTest {
19 // Used to access the dummy textures in TestCreate procs. 20 // Used to access the dummy textures in TestCreate procs.
20 enum { 21 enum {
21 kSkiaPMTextureIdx = 0, 22 kSkiaPMTextureIdx = 0,
22 kAlphaTextureIdx = 1, 23 kAlphaTextureIdx = 1,
23 }; 24 };
24 25
25 } 26 }
26 27
28 /*
29 * GrProcessorTestData is an argument struct to TestCreate functions
30 * fTextures are valid textures that can optionally be used to construct
31 * GrTextureAccesses. The first texture has config kSkia8888_GrPixelConfig and t he second has
32 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition al textures using
33 * the GrContext.
34 */
35 struct GrProcessorTestData {
36 GrProcessorTestData(SkRandom* random,
37 GrContext* context,
38 GrShaderDataManager* shaderDataManager,
39 const GrCaps* caps,
40 GrTexture* textures[2])
41 : fRandom(random)
42 , fContext(context)
43 , fShaderDataManager(shaderDataManager)
44 , fCaps(caps) {
45 fTextures[0] = textures[0];
46 fTextures[1] = textures[1];
47 }
48 SkRandom* fRandom;
49 GrContext* fContext;
50 GrShaderDataManager* fShaderDataManager;
51 const GrCaps* fCaps;
52 GrTexture* fTextures[2];
53 };
54
27 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 55 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
28 56
29 class GrContext;
30 class GrProcessor; 57 class GrProcessor;
31 class GrTexture; 58 class GrTexture;
32 59
33 template <class Processor> 60 template <class Processor>
34 class GrProcessorTestFactory : SkNoncopyable { 61 class GrProcessorTestFactory : SkNoncopyable {
35 public: 62 public:
36 63
37 typedef Processor* (*CreateProc)(SkRandom*, 64 typedef Processor* (*CreateProc)(GrProcessorTestData*);
38 GrContext*,
39 const GrCaps& caps,
40 GrTexture* dummyTextures[]);
41 65
42 GrProcessorTestFactory(CreateProc createProc) { 66 GrProcessorTestFactory(CreateProc createProc) {
43 fCreateProc = createProc; 67 fCreateProc = createProc;
44 GetFactories()->push_back(this); 68 GetFactories()->push_back(this);
45 } 69 }
46 70
47 static Processor* CreateStage(SkRandom* random, 71 static Processor* CreateStage(GrProcessorTestData* data) {
48 GrContext* context,
49 const GrCaps& caps,
50 GrTexture* dummyTextures[]) {
51 VerifyFactoryCount(); 72 VerifyFactoryCount();
52 SkASSERT(GetFactories()->count()); 73 SkASSERT(GetFactories()->count());
53 uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); 74 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1) ;
54 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; 75 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx];
55 return factory->fCreateProc(random, context, caps, dummyTextures); 76 return factory->fCreateProc(data);
56 } 77 }
57 78
58 /* 79 /*
59 * A test function which verifies the count of factories. 80 * A test function which verifies the count of factories.
60 */ 81 */
61 static void VerifyFactoryCount(); 82 static void VerifyFactoryCount();
62 83
63 private: 84 private:
64 CreateProc fCreateProc; 85 CreateProc fCreateProc;
65 86
66 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); 87 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories();
67 }; 88 };
68 89
69 /** GrProcessor subclasses should insert this macro in their declaration to be i ncluded in the 90 /** GrProcessor subclasses should insert this macro in their declaration to be i ncluded in the
70 * program generation unit test. 91 * program generation unit test.
71 */ 92 */
72 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ 93 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
73 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \ 94 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \
74 static GrGeometryProcessor* TestCreate(SkRandom*, \ 95 static GrGeometryProcessor* TestCreate(GrProcessorTestData*)
75 GrContext*, \
76 const GrCaps&, \
77 GrTexture* dummyTextures[2])
78 96
79 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ 97 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
80 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \ 98 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \
81 static GrFragmentProcessor* TestCreate(SkRandom*, \ 99 static GrFragmentProcessor* TestCreate(GrProcessorTestData*)
82 GrContext*, \
83 const GrCaps&, \
84 GrTexture* dummyTextures[2])
85 100
86 #define GR_DECLARE_XP_FACTORY_TEST \ 101 #define GR_DECLARE_XP_FACTORY_TEST \
87 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \ 102 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \
88 static GrXPFactory* TestCreate(SkRandom*, \ 103 static GrXPFactory* TestCreate(GrProcessorTestData*)
89 GrContext*, \
90 const GrCaps&, \
91 GrTexture* dummyTextures[2])
92 104
93 105
94 /** GrProcessor subclasses should insert this macro in their implementation file . They must then 106 /** GrProcessor subclasses should insert this macro in their implementation file . They must then
95 * also implement this static function: 107 * also implement this static function:
96 * GrProcessor* TestCreate(SkRandom*, 108 * 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 */ 109 */
105 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \ 110 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \
106 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect :: TestCreate) 111 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect :: TestCreate)
107 112
108 #define GR_DEFINE_XP_FACTORY_TEST(Factory) \ 113 #define GR_DEFINE_XP_FACTORY_TEST(Factory) \
109 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC reate) 114 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC reate)
110 115
111 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \ 116 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \
112 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect :: TestCreate) 117 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect :: TestCreate)
113 118
114 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 119 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
115 120
116 // The unit test relies on static initializers. Just declare the TestCreate func tion so that 121 // The unit test relies on static initializers. Just declare the TestCreate func tion so that
117 // its definitions will compile. 122 // its definitions will compile.
118 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ 123 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
119 static GrFragmentProcessor* TestCreate(SkRandom*, \ 124 static GrFragmentProcessor* TestCreate(GrProcessorTestData*)
120 GrContext*, \
121 const GrCaps&, \
122 GrTexture* dummyTextures[2])
123 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) 125 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X)
124 126
125 // The unit test relies on static initializers. Just declare the TestCreate func tion so that 127 // The unit test relies on static initializers. Just declare the TestCreate func tion so that
126 // its definitions will compile. 128 // its definitions will compile.
127 #define GR_DECLARE_XP_FACTORY_TEST \ 129 #define GR_DECLARE_XP_FACTORY_TEST \
128 static GrXPFactory* TestCreate(SkRandom*, \ 130 static GrXPFactory* TestCreate(GrProcessorTestData*)
129 GrContext*, \
130 const GrCaps&, \
131 GrTexture* dummyTextures[2])
132 #define GR_DEFINE_XP_FACTORY_TEST(X) 131 #define GR_DEFINE_XP_FACTORY_TEST(X)
133 132
134 // The unit test relies on static initializers. Just declare the TestCreate func tion so that 133 // The unit test relies on static initializers. Just declare the TestCreate func tion so that
135 // its definitions will compile. 134 // its definitions will compile.
136 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ 135 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
137 static GrGeometryProcessor* TestCreate(SkRandom*, \ 136 static GrGeometryProcessor* TestCreate(GrProcessorTestData*)
138 GrContext*, \
139 const GrCaps&, \
140 GrTexture* dummyTextures[2])
141 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) 137 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X)
142 138
143 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 139 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
144 #endif 140 #endif
OLDNEW
« no previous file with comments | « no previous file | src/effects/SkAlphaThresholdFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698