OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 // This is a GPU-backend specific test. It relies on static intializers to work | 9 // This is a GPU-backend specific test. It relies on static intializers to work |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 | 12 |
13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
14 | 14 |
15 #include "GrAutoLocaleSetter.h" | 15 #include "GrAutoLocaleSetter.h" |
16 #include "GrBatchTest.h" | 16 #include "GrBatchTest.h" |
17 #include "GrContextFactory.h" | 17 #include "GrContextFactory.h" |
18 #include "GrInvariantOutput.h" | 18 #include "GrInvariantOutput.h" |
19 #include "GrPipeline.h" | 19 #include "GrPipeline.h" |
20 #include "GrResourceProvider.h" | 20 #include "GrResourceProvider.h" |
21 #include "GrTest.h" | 21 #include "GrTest.h" |
22 #include "GrXferProcessor.h" | 22 #include "GrXferProcessor.h" |
23 #include "SkChecksum.h" | 23 #include "SkChecksum.h" |
24 #include "SkRandom.h" | 24 #include "SkRandom.h" |
25 #include "SkComposeShader.h" | |
25 #include "Test.h" | 26 #include "Test.h" |
26 | 27 |
27 #include "batches/GrDrawBatch.h" | 28 #include "batches/GrDrawBatch.h" |
28 | 29 |
29 #include "effects/GrConfigConversionEffect.h" | 30 #include "effects/GrConfigConversionEffect.h" |
30 #include "effects/GrPorterDuffXferProcessor.h" | 31 #include "effects/GrPorterDuffXferProcessor.h" |
31 | 32 |
32 #include "gl/GrGLGpu.h" | 33 #include "gl/GrGLGpu.h" |
33 #include "gl/GrGLPathRendering.h" | 34 #include "gl/GrGLPathRendering.h" |
34 #include "gl/builders/GrGLProgramBuilder.h" | 35 #include "gl/builders/GrGLProgramBuilder.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 } | 130 } |
130 return texture ? texture->asRenderTarget() : NULL; | 131 return texture ? texture->asRenderTarget() : NULL; |
131 } | 132 } |
132 | 133 |
133 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa ta* d) { | 134 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa ta* d) { |
134 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Cre ateStage(d)); | 135 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Cre ateStage(d)); |
135 SkASSERT(xpf); | 136 SkASSERT(xpf); |
136 pipelineBuilder->setXPFactory(xpf.get()); | 137 pipelineBuilder->setXPFactory(xpf.get()); |
137 } | 138 } |
138 | 139 |
140 static GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d, | |
141 int minLevels, int maxLevels ) { | |
142 SkASSERT(1 <= minLevels); | |
143 SkASSERT(minLevels <= maxLevels); | |
144 | |
145 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate | |
146 if (1 == minLevels) { | |
147 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < 0.3f); | |
joshualitt
2015/08/25 18:17:13
we probably want to make this number and the 0.5f
wangyix
2015/08/25 19:18:52
Done.
| |
148 if (terminate) { | |
149 GrFragmentProcessor* fp; | |
joshualitt
2015/08/25 18:17:13
Can we just use SkAutoTUnref here, and then just r
wangyix
2015/08/25 18:55:05
This fp isn't handed off to someone else within th
joshualitt
2015/08/25 18:56:41
That makes sense, lets leave it as is
wangyix
2015/08/25 19:18:52
Acknowledged.
| |
150 while (true) { | |
151 fp = GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d) ; | |
152 SkASSERT(fp); | |
153 if (0 == fp->numChildProcessors()) { | |
joshualitt
2015/08/25 18:17:13
This seems like it could be a bit wasteful, even i
wangyix
2015/08/25 18:36:21
What do you mean? Here, I'm trying to return a ran
joshualitt
2015/08/25 18:42:29
whoops, I probably should have read this more care
wangyix
2015/08/25 18:55:05
Acknowledged.
| |
154 break; | |
155 } | |
156 fp->unref(); | |
157 } | |
158 return fp; | |
159 } | |
160 } | |
161 // If we didn't terminate, choose either the left or right subtree to fulfil l | |
162 // the minLevels requirement of this tree; the other child can have as few l evels as it wants. | |
163 // Also choose a random xfer mode that's supported by GrComposeEffect. | |
164 if (minLevels > 1) { | |
165 --minLevels; | |
166 } | |
167 GrFragmentProcessor* minLevelsChild = create_random_proc_tree(d, minLevels, maxLevels - 1); | |
joshualitt
2015/08/25 18:17:13
These can just be SkAutoTUnref
wangyix
2015/08/25 19:18:52
Done.
| |
168 GrFragmentProcessor* otherChild = create_random_proc_tree(d, 1, maxLevels - 1); | |
169 SkXfermode::Mode mode; | |
170 do { | |
171 mode = static_cast<SkXfermode::Mode>( | |
172 d->fRandom->nextRangeU(0, SkXfermode::Mode::kLas tCoeffMode)); | |
173 } while (mode == SkXfermode::Mode::kClear_Mode); | |
174 | |
175 GrFragmentProcessor* fp; | |
176 if (d->fRandom->nextF() < 0.5f) { | |
177 fp = GrComposeEffect::Create(minLevelsChild, otherChild, mode); | |
178 } else { | |
179 fp = GrComposeEffect::Create(otherChild, minLevelsChild, mode); | |
180 } | |
181 minLevelsChild->unref(); | |
182 otherChild->unref(); | |
183 return fp; | |
184 } | |
185 | |
139 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, | 186 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, |
140 GrProcessorTestData* d, int maxStag es) { | 187 GrProcessorTestData* d, int maxStag es) { |
141 int numProcs = d->fRandom->nextULessThan(maxStages + 1); | 188 // Randomly choose to either create a linear pipeline of procs, or create on e proc |
142 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); | 189 // tree. |
190 if (d->fRandom->nextF() < 0.5f) { | |
191 int numProcs = d->fRandom->nextULessThan(maxStages + 1); | |
192 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); | |
143 | 193 |
144 for (int s = 0; s < numProcs;) { | 194 for (int s = 0; s < numProcs;) { |
195 SkAutoTUnref<const GrFragmentProcessor> fp( | |
196 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)) ; | |
197 SkASSERT(fp); | |
198 | |
199 // finally add the stage to the correct pipeline in the drawstate | |
200 if (s < numColorProcs) { | |
201 pipelineBuilder->addColorProcessor(fp); | |
202 } else { | |
203 pipelineBuilder->addCoverageProcessor(fp); | |
204 } | |
205 ++s; | |
206 } | |
207 } else { | |
208 // A full tree with 5 levels (31 nodes) may exceed the max allowed lengt h of the gl | |
209 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive . | |
210 const int maxTreeLevels = 4; | |
145 SkAutoTUnref<const GrFragmentProcessor> fp( | 211 SkAutoTUnref<const GrFragmentProcessor> fp( |
146 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); | 212 create_random_proc_tree(d, 1, maxTreeLev els)); |
147 SkASSERT(fp); | 213 pipelineBuilder->addColorProcessor(fp); |
148 | |
149 // finally add the stage to the correct pipeline in the drawstate | |
150 if (s < numColorProcs) { | |
151 pipelineBuilder->addColorProcessor(fp); | |
152 } else { | |
153 pipelineBuilder->addCoverageProcessor(fp); | |
154 } | |
155 ++s; | |
156 } | 214 } |
157 } | 215 } |
158 | 216 |
159 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) { | 217 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) { |
160 int state = 0; | 218 int state = 0; |
161 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { | 219 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { |
162 state |= random->nextBool() * i; | 220 state |= random->nextBool() * i; |
163 } | 221 } |
164 | 222 |
165 // If we don't have an MSAA rendertarget then we have to disable useHWAA | 223 // If we don't have an MSAA rendertarget then we have to disable useHWAA |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 } | 354 } |
297 #endif | 355 #endif |
298 GrTestTarget target; | 356 GrTestTarget target; |
299 context->getTestTarget(&target); | 357 context->getTestTarget(&target); |
300 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages)); | 358 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages)); |
301 } | 359 } |
302 } | 360 } |
303 } | 361 } |
304 | 362 |
305 #endif | 363 #endif |
OLD | NEW |