Index: tests/GLProgramsTest.cpp |
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp |
index 16745e5669d673dd0ddc18d0b3772e0de69e7297..8d864f4327de4b4f805fa4c63490a9d565e74567 100644 |
--- a/tests/GLProgramsTest.cpp |
+++ b/tests/GLProgramsTest.cpp |
@@ -22,6 +22,7 @@ |
#include "GrXferProcessor.h" |
#include "SkChecksum.h" |
#include "SkRandom.h" |
+#include "SkComposeShader.h" |
#include "Test.h" |
#include "batches/GrDrawBatch.h" |
@@ -136,23 +137,80 @@ static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa |
pipelineBuilder->setXPFactory(xpf.get()); |
} |
+static GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d, |
+ int minLevels, int maxLevels) { |
+ SkASSERT(1 <= minLevels); |
+ SkASSERT(minLevels <= maxLevels); |
+ |
+ // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate |
+ if (1 == minLevels) { |
+ 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.
|
+ if (terminate) { |
+ 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.
|
+ while (true) { |
+ fp = GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d); |
+ SkASSERT(fp); |
+ 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.
|
+ break; |
+ } |
+ fp->unref(); |
+ } |
+ return fp; |
+ } |
+ } |
+ // If we didn't terminate, choose either the left or right subtree to fulfill |
+ // the minLevels requirement of this tree; the other child can have as few levels as it wants. |
+ // Also choose a random xfer mode that's supported by GrComposeEffect. |
+ if (minLevels > 1) { |
+ --minLevels; |
+ } |
+ 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.
|
+ GrFragmentProcessor* otherChild = create_random_proc_tree(d, 1, maxLevels - 1); |
+ SkXfermode::Mode mode; |
+ do { |
+ mode = static_cast<SkXfermode::Mode>( |
+ d->fRandom->nextRangeU(0, SkXfermode::Mode::kLastCoeffMode)); |
+ } while (mode == SkXfermode::Mode::kClear_Mode); |
+ |
+ GrFragmentProcessor* fp; |
+ if (d->fRandom->nextF() < 0.5f) { |
+ fp = GrComposeEffect::Create(minLevelsChild, otherChild, mode); |
+ } else { |
+ fp = GrComposeEffect::Create(otherChild, minLevelsChild, mode); |
+ } |
+ minLevelsChild->unref(); |
+ otherChild->unref(); |
+ return fp; |
+} |
+ |
static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, |
GrProcessorTestData* d, int maxStages) { |
- int numProcs = d->fRandom->nextULessThan(maxStages + 1); |
- int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); |
- |
- for (int s = 0; s < numProcs;) { |
- SkAutoTUnref<const GrFragmentProcessor> fp( |
- GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); |
- SkASSERT(fp); |
- |
- // finally add the stage to the correct pipeline in the drawstate |
- if (s < numColorProcs) { |
- pipelineBuilder->addColorProcessor(fp); |
- } else { |
- pipelineBuilder->addCoverageProcessor(fp); |
+ // Randomly choose to either create a linear pipeline of procs, or create one proc |
+ // tree. |
+ if (d->fRandom->nextF() < 0.5f) { |
+ int numProcs = d->fRandom->nextULessThan(maxStages + 1); |
+ int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); |
+ |
+ for (int s = 0; s < numProcs;) { |
+ SkAutoTUnref<const GrFragmentProcessor> fp( |
+ GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); |
+ SkASSERT(fp); |
+ |
+ // finally add the stage to the correct pipeline in the drawstate |
+ if (s < numColorProcs) { |
+ pipelineBuilder->addColorProcessor(fp); |
+ } else { |
+ pipelineBuilder->addCoverageProcessor(fp); |
+ } |
+ ++s; |
} |
- ++s; |
+ } else { |
+ // A full tree with 5 levels (31 nodes) may exceed the max allowed length of the gl |
+ // processor key; maxTreeLevels should be a number from 1 to 4 inclusive. |
+ const int maxTreeLevels = 4; |
+ SkAutoTUnref<const GrFragmentProcessor> fp( |
+ create_random_proc_tree(d, 1, maxTreeLevels)); |
+ pipelineBuilder->addColorProcessor(fp); |
} |
} |