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

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 1314923002: GLProgramsTest can now randomly create a tree of GrFragmentProcessors instead of a linear pipeline (Closed) Base URL: https://skia.googlesource.com/skia@cs3_testcreate
Patch Set: removed warnings Created 5 years, 3 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 | « src/gpu/effects/GrXfermodeFragmentProcessor.cpp ('k') | no next file » | 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 /* 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
(...skipping 10 matching lines...) Expand all
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 "Test.h" 25 #include "Test.h"
26 26
27 #include "batches/GrDrawBatch.h" 27 #include "batches/GrDrawBatch.h"
28 28
29 #include "effects/GrConfigConversionEffect.h" 29 #include "effects/GrConfigConversionEffect.h"
30 #include "effects/GrPorterDuffXferProcessor.h" 30 #include "effects/GrPorterDuffXferProcessor.h"
31 #include "effects/GrXfermodeFragmentProcessor.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"
35 36
36 /* 37 /*
37 * A dummy processor which just tries to insert a massive key and verify that it can retrieve the 38 * A dummy processor which just tries to insert a massive key and verify that it can retrieve the
38 * whole thing correctly 39 * whole thing correctly
39 */ 40 */
40 static const uint32_t kMaxKeySize = 1024; 41 static const uint32_t kMaxKeySize = 1024;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 130 }
130 return texture ? texture->asRenderTarget() : nullptr; 131 return texture ? texture->asRenderTarget() : nullptr;
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 const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d ,
141 int minLevels, int ma xLevels) {
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 returning a leaf node, make sure that it doesn't have children (e.g. a nother
147 // GrComposeEffect)
148 const float terminateProbability = 0.3f;
149 if (1 == minLevels) {
150 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminatePro bability);
151 if (terminate) {
152 const GrFragmentProcessor* fp;
153 while (true) {
154 fp = GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d) ;
155 SkASSERT(fp);
156 if (0 == fp->numChildProcessors()) {
157 break;
158 }
159 fp->unref();
160 }
161 return fp;
162 }
163 }
164 // If we didn't terminate, choose either the left or right subtree to fulfil l
165 // the minLevels requirement of this tree; the other child can have as few l evels as it wants.
166 // Also choose a random xfer mode that's supported by CreateFrom2Procs().
167 if (minLevels > 1) {
168 --minLevels;
169 }
170 SkAutoTUnref<const GrFragmentProcessor> minLevelsChild(create_random_proc_tr ee(d, minLevels,
171 maxLevels - 1));
172 SkAutoTUnref<const GrFragmentProcessor> otherChild(create_random_proc_tree(d , 1,
173 m axLevels - 1));
174 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU (0,
175 SkXfermode::kLastCoeff Mode));
176 const GrFragmentProcessor* fp;
177 if (d->fRandom->nextF() < 0.5f) {
178 fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(minLevelsChild , otherChild, mode);
179 SkASSERT(fp);
180 } else {
181 fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(otherChild, mi nLevelsChild, mode);
182 SkASSERT(fp);
183 }
184 return fp;
185 }
186
139 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, 187 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder,
140 GrProcessorTestData* d, int maxStag es) { 188 GrProcessorTestData* d, int maxStag es) {
141 int numProcs = d->fRandom->nextULessThan(maxStages + 1); 189 // Randomly choose to either create a linear pipeline of procs or create one proc tree
142 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); 190 const float procTreeProbability = 0.5f;
191 if (d->fRandom->nextF() < procTreeProbability) {
192 // A full tree with 5 levels (31 nodes) may exceed the max allowed lengt h of the gl
193 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive .
194 const int maxTreeLevels = 4;
195 SkAutoTUnref<const GrFragmentProcessor> fp(
196 create_random_proc_tree(d, 2, maxTreeLev els));
197 pipelineBuilder->addColorFragmentProcessor(fp);
198 } else {
199 int numProcs = d->fRandom->nextULessThan(maxStages + 1);
200 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
143 201
144 for (int s = 0; s < numProcs;) { 202 for (int s = 0; s < numProcs;) {
145 SkAutoTUnref<const GrFragmentProcessor> fp( 203 SkAutoTUnref<const GrFragmentProcessor> fp(
146 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); 204 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)) ;
147 SkASSERT(fp); 205 SkASSERT(fp);
148 206
149 // finally add the stage to the correct pipeline in the drawstate 207 // finally add the stage to the correct pipeline in the drawstate
150 if (s < numColorProcs) { 208 if (s < numColorProcs) {
151 pipelineBuilder->addColorFragmentProcessor(fp); 209 pipelineBuilder->addColorFragmentProcessor(fp);
152 } else { 210 } else {
153 pipelineBuilder->addCoverageFragmentProcessor(fp); 211 pipelineBuilder->addCoverageFragmentProcessor(fp);
212 }
213 ++s;
154 } 214 }
155 ++s;
156 } 215 }
157 } 216 }
158 217
159 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) { 218 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) {
160 int state = 0; 219 int state = 0;
161 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { 220 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) {
162 state |= random->nextBool() * i; 221 state |= random->nextBool() * i;
163 } 222 }
164 223
165 // If we don't have an MSAA rendertarget then we have to disable useHWAA 224 // If we don't have an MSAA rendertarget then we have to disable useHWAA
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 362 }
304 #endif 363 #endif
305 GrTestTarget target; 364 GrTestTarget target;
306 context->getTestTarget(&target); 365 context->getTestTarget(&target);
307 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages)); 366 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages));
308 } 367 }
309 } 368 }
310 } 369 }
311 370
312 #endif 371 #endif
OLDNEW
« no previous file with comments | « src/gpu/effects/GrXfermodeFragmentProcessor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698