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 43 matching lines...) Loading... |
54 | 54 |
55 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 55 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
56 | 56 |
57 class GrProcessor; | 57 class GrProcessor; |
58 class GrTexture; | 58 class GrTexture; |
59 | 59 |
60 template <class Processor> | 60 template <class Processor> |
61 class GrProcessorTestFactory : SkNoncopyable { | 61 class GrProcessorTestFactory : SkNoncopyable { |
62 public: | 62 public: |
63 | 63 |
64 typedef Processor* (*CreateProc)(GrProcessorTestData*); | 64 typedef const Processor* (*CreateProc)(GrProcessorTestData*); |
65 | 65 |
66 GrProcessorTestFactory(CreateProc createProc) { | 66 GrProcessorTestFactory(CreateProc createProc) { |
67 fCreateProc = createProc; | 67 fCreateProc = createProc; |
68 GetFactories()->push_back(this); | 68 GetFactories()->push_back(this); |
69 } | 69 } |
70 | 70 |
71 static Processor* CreateStage(GrProcessorTestData* data) { | 71 static const Processor* CreateStage(GrProcessorTestData* data) { |
72 VerifyFactoryCount(); | 72 VerifyFactoryCount(); |
73 SkASSERT(GetFactories()->count()); | 73 SkASSERT(GetFactories()->count()); |
74 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1)
; | 74 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1)
; |
75 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 75 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
76 return factory->fCreateProc(data); | 76 return factory->fCreateProc(data); |
77 } | 77 } |
78 | 78 |
79 /* | 79 /* |
80 * A test function which verifies the count of factories. | 80 * A test function which verifies the count of factories. |
81 */ | 81 */ |
82 static void VerifyFactoryCount(); | 82 static void VerifyFactoryCount(); |
83 | 83 |
84 private: | 84 private: |
85 CreateProc fCreateProc; | 85 CreateProc fCreateProc; |
86 | 86 |
87 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); | 87 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); |
88 }; | 88 }; |
89 | 89 |
90 /** 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 |
91 * program generation unit test. | 91 * program generation unit test. |
92 */ | 92 */ |
93 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 93 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
94 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED;
\ | 94 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED;
\ |
95 static GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 95 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
96 | 96 |
97 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ | 97 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ |
98 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED;
\ | 98 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED;
\ |
99 static GrFragmentProcessor* TestCreate(GrProcessorTestData*) | 99 static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) |
100 | 100 |
101 #define GR_DECLARE_XP_FACTORY_TEST
\ | 101 #define GR_DECLARE_XP_FACTORY_TEST
\ |
102 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED;
\ | 102 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED;
\ |
103 static GrXPFactory* TestCreate(GrProcessorTestData*) | 103 static const GrXPFactory* TestCreate(GrProcessorTestData*) |
104 | 104 |
105 | 105 |
106 /** 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 |
107 * also implement this static function: | 107 * also implement this static function: |
108 * GrProcessor* TestCreate(GrProcessorTestData*); | 108 * GrProcessor* TestCreate(GrProcessorTestData*); |
109 */ | 109 */ |
110 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect)
\ | 110 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect)
\ |
111 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect ::
TestCreate) | 111 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect ::
TestCreate) |
112 | 112 |
113 #define GR_DEFINE_XP_FACTORY_TEST(Factory)
\ | 113 #define GR_DEFINE_XP_FACTORY_TEST(Factory)
\ |
114 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC
reate) | 114 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC
reate) |
115 | 115 |
116 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect)
\ | 116 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect)
\ |
117 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect ::
TestCreate) | 117 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect ::
TestCreate) |
118 | 118 |
119 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 119 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
120 | 120 |
121 // 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 |
122 // its definitions will compile. | 122 // its definitions will compile. |
123 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ | 123 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ |
124 static GrFragmentProcessor* TestCreate(GrProcessorTestData*) | 124 static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) |
125 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) | 125 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) |
126 | 126 |
127 // 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 |
128 // its definitions will compile. | 128 // its definitions will compile. |
129 #define GR_DECLARE_XP_FACTORY_TEST
\ | 129 #define GR_DECLARE_XP_FACTORY_TEST
\ |
130 static GrXPFactory* TestCreate(GrProcessorTestData*) | 130 static const GrXPFactory* TestCreate(GrProcessorTestData*) |
131 #define GR_DEFINE_XP_FACTORY_TEST(X) | 131 #define GR_DEFINE_XP_FACTORY_TEST(X) |
132 | 132 |
133 // 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 |
134 // its definitions will compile. | 134 // its definitions will compile. |
135 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 135 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
136 static GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 136 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
137 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 137 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
138 | 138 |
139 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 139 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
140 #endif | 140 #endif |
OLD | NEW |