Chromium Code Reviews| 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, | |
|
tomhudson
2015/08/25 19:29:24
So what's d really doing here? Looks like it's car
| |
| 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 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 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 GrComposeEffect. | |
| 167 if (minLevels > 1) { | |
| 168 --minLevels; | |
| 169 } | |
| 170 SkAutoTUnref<GrFragmentProcessor> minLevelsChild( | |
| 171 create_random_proc_tree(d, minLevels, maxLevels - 1)); | |
| 172 SkAutoTUnref<GrFragmentProcessor> otherChild( | |
| 173 create_random_proc_tree(d, 1, maxLevels - 1)); | |
| 174 SkXfermode::Mode mode; | |
| 175 do { | |
| 176 mode = static_cast<SkXfermode::Mode>( | |
| 177 d->fRandom->nextRangeU(0, SkXfermode::Mode::kLas tCoeffMode)); | |
| 178 } while (mode == SkXfermode::Mode::kClear_Mode); | |
| 179 | |
| 180 GrFragmentProcessor* fp; | |
| 181 if (d->fRandom->nextF() < 0.5f) { | |
| 182 fp = GrComposeEffect::Create(minLevelsChild, otherChild, mode); | |
| 183 } else { | |
| 184 fp = GrComposeEffect::Create(otherChild, minLevelsChild, mode); | |
| 185 } | |
| 186 return fp; | |
| 187 } | |
| 188 | |
| 139 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, | 189 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, |
| 140 GrProcessorTestData* d, int maxStag es) { | 190 GrProcessorTestData* d, int maxStag es) { |
| 141 int numProcs = d->fRandom->nextULessThan(maxStages + 1); | 191 // Randomly choose to either create a linear pipeline of procs, or create on e proc |
| 142 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); | 192 // tree. |
| 193 const float procTreeProbability = 0.5f; | |
| 194 if (d->fRandom->nextF() < procTreeProbability) { | |
| 195 // A full tree with 5 levels (31 nodes) may exceed the max allowed lengt h of the gl | |
| 196 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive . | |
|
tomhudson
2015/08/25 19:29:24
A one-level tree will just be a leaf node with no
wangyix
2015/08/25 19:48:01
Good point. It may be better to have create_random
| |
| 197 const int maxTreeLevels = 4; | |
| 198 SkAutoTUnref<const GrFragmentProcessor> fp( | |
| 199 create_random_proc_tree(d, 1, maxTreeLev els)); | |
| 200 pipelineBuilder->addColorProcessor(fp); | |
|
tomhudson
2015/08/25 19:29:24
No coverage? Or am I missing something?
| |
| 201 } else { | |
| 202 int numProcs = d->fRandom->nextULessThan(maxStages + 1); | |
| 203 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); | |
| 143 | 204 |
| 144 for (int s = 0; s < numProcs;) { | 205 for (int s = 0; s < numProcs;) { |
| 145 SkAutoTUnref<const GrFragmentProcessor> fp( | 206 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 146 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); | 207 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)) ; |
| 147 SkASSERT(fp); | 208 SkASSERT(fp); |
| 148 | 209 |
| 149 // finally add the stage to the correct pipeline in the drawstate | 210 // finally add the stage to the correct pipeline in the drawstate |
| 150 if (s < numColorProcs) { | 211 if (s < numColorProcs) { |
| 151 pipelineBuilder->addColorProcessor(fp); | 212 pipelineBuilder->addColorProcessor(fp); |
| 152 } else { | 213 } else { |
| 153 pipelineBuilder->addCoverageProcessor(fp); | 214 pipelineBuilder->addCoverageProcessor(fp); |
| 215 } | |
| 216 ++s; | |
| 154 } | 217 } |
| 155 ++s; | |
| 156 } | 218 } |
| 157 } | 219 } |
| 158 | 220 |
| 159 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) { | 221 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) { |
| 160 int state = 0; | 222 int state = 0; |
| 161 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { | 223 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { |
| 162 state |= random->nextBool() * i; | 224 state |= random->nextBool() * i; |
| 163 } | 225 } |
| 164 | 226 |
| 165 // If we don't have an MSAA rendertarget then we have to disable useHWAA | 227 // 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 } | 358 } |
| 297 #endif | 359 #endif |
| 298 GrTestTarget target; | 360 GrTestTarget target; |
| 299 context->getTestTarget(&target); | 361 context->getTestTarget(&target); |
| 300 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages)); | 362 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages)); |
| 301 } | 363 } |
| 302 } | 364 } |
| 303 } | 365 } |
| 304 | 366 |
| 305 #endif | 367 #endif |
| OLD | NEW |