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 |
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 class GrContext; |
| 18 struct GrProcessorTestData; |
18 | 19 |
19 namespace GrProcessorUnitTest { | 20 namespace GrProcessorUnitTest { |
| 21 |
20 // Used to access the dummy textures in TestCreate procs. | 22 // Used to access the dummy textures in TestCreate procs. |
21 enum { | 23 enum { |
22 kSkiaPMTextureIdx = 0, | 24 kSkiaPMTextureIdx = 0, |
23 kAlphaTextureIdx = 1, | 25 kAlphaTextureIdx = 1, |
24 }; | 26 }; |
25 | 27 |
| 28 /** This allows parent FPs to implement a test create with known leaf children i
n order to avoid |
| 29 creating an unbounded FP tree which may overflow various shader limits. */ |
| 30 const GrFragmentProcessor* CreateChildFP(GrProcessorTestData*); |
| 31 |
26 } | 32 } |
27 | 33 |
28 /* | 34 /* |
29 * GrProcessorTestData is an argument struct to TestCreate functions | 35 * GrProcessorTestData is an argument struct to TestCreate functions |
30 * fTextures are valid textures that can optionally be used to construct | 36 * 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 | 37 * 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 | 38 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition
al textures using |
33 * the GrContext. | 39 * the GrContext. |
34 */ | 40 */ |
35 struct GrProcessorTestData { | 41 struct GrProcessorTestData { |
(...skipping 14 matching lines...) Expand all Loading... |
50 GrProcessorDataManager* fProcDataManager; | 56 GrProcessorDataManager* fProcDataManager; |
51 const GrCaps* fCaps; | 57 const GrCaps* fCaps; |
52 GrTexture* fTextures[2]; | 58 GrTexture* fTextures[2]; |
53 }; | 59 }; |
54 | 60 |
55 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 61 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
56 | 62 |
57 class GrProcessor; | 63 class GrProcessor; |
58 class GrTexture; | 64 class GrTexture; |
59 | 65 |
60 template <class Processor> | 66 template <class Processor> class GrProcessorTestFactory : SkNoncopyable { |
61 class GrProcessorTestFactory : SkNoncopyable { | |
62 public: | 67 public: |
63 | |
64 typedef const Processor* (*CreateProc)(GrProcessorTestData*); | 68 typedef const Processor* (*CreateProc)(GrProcessorTestData*); |
65 | 69 |
66 GrProcessorTestFactory(CreateProc createProc) { | 70 GrProcessorTestFactory(CreateProc createProc) { |
67 fCreateProc = createProc; | 71 fCreateProc = createProc; |
68 GetFactories()->push_back(this); | 72 GetFactories()->push_back(this); |
69 } | 73 } |
70 | 74 |
71 /** Pick a random factory function and create a processor. */ | 75 /** Pick a random factory function and create a processor. */ |
72 static const Processor* Create(GrProcessorTestData* data) { | 76 static const Processor* Create(GrProcessorTestData* data) { |
73 VerifyFactoryCount(); | 77 VerifyFactoryCount(); |
(...skipping 30 matching lines...) Expand all Loading... |
104 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 108 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
105 | 109 |
106 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ | 110 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ |
107 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED;
\ | 111 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED;
\ |
108 static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) | 112 static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) |
109 | 113 |
110 #define GR_DECLARE_XP_FACTORY_TEST
\ | 114 #define GR_DECLARE_XP_FACTORY_TEST
\ |
111 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED;
\ | 115 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED;
\ |
112 static const GrXPFactory* TestCreate(GrProcessorTestData*) | 116 static const GrXPFactory* TestCreate(GrProcessorTestData*) |
113 | 117 |
114 | |
115 /** GrProcessor subclasses should insert this macro in their implementation file
. They must then | 118 /** GrProcessor subclasses should insert this macro in their implementation file
. They must then |
116 * also implement this static function: | 119 * also implement this static function: |
117 * GrProcessor* TestCreate(GrProcessorTestData*); | 120 * GrProcessor* TestCreate(GrProcessorTestData*); |
118 */ | 121 */ |
119 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect)
\ | 122 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect)
\ |
120 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect ::
TestCreate) | 123 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect ::
TestCreate) |
121 | 124 |
122 #define GR_DEFINE_XP_FACTORY_TEST(Factory)
\ | 125 #define GR_DEFINE_XP_FACTORY_TEST(Factory)
\ |
123 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC
reate) | 126 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC
reate) |
124 | 127 |
(...skipping 15 matching lines...) Expand all Loading... |
140 #define GR_DEFINE_XP_FACTORY_TEST(X) | 143 #define GR_DEFINE_XP_FACTORY_TEST(X) |
141 | 144 |
142 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that | 145 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that |
143 // its definitions will compile. | 146 // its definitions will compile. |
144 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 147 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
145 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 148 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) |
146 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 149 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
147 | 150 |
148 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 151 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
149 #endif | 152 #endif |
OLD | NEW |