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 10 matching lines...) Expand all Loading... |
21 namespace GrProcessorUnitTest { | 21 namespace GrProcessorUnitTest { |
22 | 22 |
23 // Used to access the dummy textures in TestCreate procs. | 23 // Used to access the dummy textures in TestCreate procs. |
24 enum { | 24 enum { |
25 kSkiaPMTextureIdx = 0, | 25 kSkiaPMTextureIdx = 0, |
26 kAlphaTextureIdx = 1, | 26 kAlphaTextureIdx = 1, |
27 }; | 27 }; |
28 | 28 |
29 /** This allows parent FPs to implement a test create with known leaf children i
n order to avoid | 29 /** This allows parent FPs to implement a test create with known leaf children i
n order to avoid |
30 creating an unbounded FP tree which may overflow various shader limits. */ | 30 creating an unbounded FP tree which may overflow various shader limits. */ |
31 const GrFragmentProcessor* CreateChildFP(GrProcessorTestData*); | 31 sk_sp<GrFragmentProcessor> MakeChildFP(GrProcessorTestData*); |
32 | 32 |
33 } | 33 } |
34 | 34 |
35 /* | 35 /* |
36 * GrProcessorTestData is an argument struct to TestCreate functions | 36 * GrProcessorTestData is an argument struct to TestCreate functions |
37 * fTextures are valid textures that can optionally be used to construct | 37 * fTextures are valid textures that can optionally be used to construct |
38 * GrTextureAccesses. The first texture has config kSkia8888_GrPixelConfig and t
he second has | 38 * GrTextureAccesses. The first texture has config kSkia8888_GrPixelConfig and t
he second has |
39 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition
al textures using | 39 * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create addition
al textures using |
40 * the GrContext. | 40 * the GrContext. |
41 */ | 41 */ |
(...skipping 17 matching lines...) Expand all Loading... |
59 GrTexture* fTextures[2]; | 59 GrTexture* fTextures[2]; |
60 }; | 60 }; |
61 | 61 |
62 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 62 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
63 | 63 |
64 class GrProcessor; | 64 class GrProcessor; |
65 class GrTexture; | 65 class GrTexture; |
66 | 66 |
67 template <class Processor> class GrProcessorTestFactory : SkNoncopyable { | 67 template <class Processor> class GrProcessorTestFactory : SkNoncopyable { |
68 public: | 68 public: |
69 typedef const Processor* (*CreateProc)(GrProcessorTestData*); | 69 typedef sk_sp<Processor> (*MakeProc)(GrProcessorTestData*); |
70 | 70 |
71 GrProcessorTestFactory(CreateProc createProc) { | 71 GrProcessorTestFactory(MakeProc makeProc) { |
72 fCreateProc = createProc; | 72 fMakeProc = makeProc; |
73 GetFactories()->push_back(this); | 73 GetFactories()->push_back(this); |
74 } | 74 } |
75 | 75 |
76 /** Pick a random factory function and create a processor. */ | 76 /** Pick a random factory function and create a processor. */ |
77 static const Processor* Create(GrProcessorTestData* data) { | 77 static sk_sp<Processor> Make(GrProcessorTestData* data) { |
78 VerifyFactoryCount(); | 78 VerifyFactoryCount(); |
79 SkASSERT(GetFactories()->count()); | 79 SkASSERT(GetFactories()->count()); |
80 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1)
; | 80 uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1)
; |
81 return CreateIdx(idx, data); | 81 return MakeIdx(idx, data); |
82 } | 82 } |
83 | 83 |
84 /** Number of registered factory functions */ | 84 /** Number of registered factory functions */ |
85 static int Count() { return GetFactories()->count(); } | 85 static int Count() { return GetFactories()->count(); } |
86 | 86 |
87 /** Use factory function at Index idx to create a processor. */ | 87 /** Use factory function at Index idx to create a processor. */ |
88 static const Processor* CreateIdx(int idx, GrProcessorTestData* data) { | 88 static sk_sp<Processor> MakeIdx(int idx, GrProcessorTestData* data) { |
89 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; | 89 GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx]; |
90 return factory->fCreateProc(data); | 90 return factory->fMakeProc(data); |
91 } | 91 } |
92 | 92 |
93 /* | 93 /* |
94 * A test function which verifies the count of factories. | 94 * A test function which verifies the count of factories. |
95 */ | 95 */ |
96 static void VerifyFactoryCount(); | 96 static void VerifyFactoryCount(); |
97 | 97 |
98 private: | 98 private: |
99 CreateProc fCreateProc; | 99 MakeProc fMakeProc; |
100 | 100 |
101 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); | 101 static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories(); |
102 }; | 102 }; |
103 | 103 |
104 /** GrProcessor subclasses should insert this macro in their declaration to be i
ncluded in the | 104 /** GrProcessor subclasses should insert this macro in their declaration to be i
ncluded in the |
105 * program generation unit test. | 105 * program generation unit test. |
106 */ | 106 */ |
107 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 107 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
108 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED;
\ | 108 static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED;
\ |
109 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 109 static sk_sp<GrGeometryProcessor> TestCreate(GrProcessorTestData*) |
110 | 110 |
111 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ | 111 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ |
112 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED;
\ | 112 static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED;
\ |
113 static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) | 113 static sk_sp<GrFragmentProcessor> TestCreate(GrProcessorTestData*) |
114 | 114 |
115 #define GR_DECLARE_XP_FACTORY_TEST
\ | 115 #define GR_DECLARE_XP_FACTORY_TEST
\ |
116 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED;
\ | 116 static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED;
\ |
117 static const GrXPFactory* TestCreate(GrProcessorTestData*) | 117 static sk_sp<GrXPFactory> TestCreate(GrProcessorTestData*) |
118 | 118 |
119 /** GrProcessor subclasses should insert this macro in their implementation file
. They must then | 119 /** GrProcessor subclasses should insert this macro in their implementation file
. They must then |
120 * also implement this static function: | 120 * also implement this static function: |
121 * GrProcessor* TestCreate(GrProcessorTestData*); | 121 * GrProcessor* TestCreate(GrProcessorTestData*); |
122 */ | 122 */ |
123 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect)
\ | 123 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect)
\ |
124 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect ::
TestCreate) | 124 GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect ::
TestCreate) |
125 | 125 |
126 #define GR_DEFINE_XP_FACTORY_TEST(Factory)
\ | 126 #define GR_DEFINE_XP_FACTORY_TEST(Factory)
\ |
127 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC
reate) | 127 GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestC
reate) |
128 | 128 |
129 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect)
\ | 129 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect)
\ |
130 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect ::
TestCreate) | 130 GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect ::
TestCreate) |
131 | 131 |
132 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 132 #else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
133 | 133 |
134 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that | 134 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that |
135 // its definitions will compile. | 135 // its definitions will compile. |
136 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ | 136 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
\ |
137 static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) | 137 static sk_sp<GrFragmentProcessor> TestCreate(GrProcessorTestData*) |
138 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) | 138 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) |
139 | 139 |
140 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that | 140 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that |
141 // its definitions will compile. | 141 // its definitions will compile. |
142 #define GR_DECLARE_XP_FACTORY_TEST
\ | 142 #define GR_DECLARE_XP_FACTORY_TEST
\ |
143 static const GrXPFactory* TestCreate(GrProcessorTestData*) | 143 static sk_sp<GrXPFactory> TestCreate(GrProcessorTestData*) |
144 #define GR_DEFINE_XP_FACTORY_TEST(X) | 144 #define GR_DEFINE_XP_FACTORY_TEST(X) |
145 | 145 |
146 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that | 146 // The unit test relies on static initializers. Just declare the TestCreate func
tion so that |
147 // its definitions will compile. | 147 // its definitions will compile. |
148 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ | 148 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
\ |
149 static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) | 149 static sk_sp<GrGeometryProcessor> TestCreate(GrProcessorTestData*) |
150 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) | 150 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) |
151 | 151 |
152 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 152 #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
153 #endif | 153 #endif |
OLD | NEW |