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 |
(...skipping 29 matching lines...) Expand all Loading... |
40 */ | 40 */ |
41 static const uint32_t kMaxKeySize = 1024; | 41 static const uint32_t kMaxKeySize = 1024; |
42 | 42 |
43 class GLBigKeyProcessor : public GrGLFragmentProcessor { | 43 class GLBigKeyProcessor : public GrGLFragmentProcessor { |
44 public: | 44 public: |
45 GLBigKeyProcessor(const GrProcessor&) {} | 45 GLBigKeyProcessor(const GrProcessor&) {} |
46 | 46 |
47 virtual void emitCode(EmitArgs& args) override { | 47 virtual void emitCode(EmitArgs& args) override { |
48 // pass through | 48 // pass through |
49 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); | 49 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); |
50 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor
); | 50 if (args.fInputColor) { |
| 51 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputC
olor); |
| 52 } else { |
| 53 fsBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor); |
| 54 } |
51 } | 55 } |
52 | 56 |
53 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces
sorKeyBuilder* b) { | 57 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces
sorKeyBuilder* b) { |
54 for (uint32_t i = 0; i < kMaxKeySize; i++) { | 58 for (uint32_t i = 0; i < kMaxKeySize; i++) { |
55 b->add32(i); | 59 b->add32(i); |
56 } | 60 } |
57 } | 61 } |
58 | 62 |
59 private: | 63 private: |
60 typedef GrGLFragmentProcessor INHERITED; | 64 typedef GrGLFragmentProcessor INHERITED; |
(...skipping 27 matching lines...) Expand all Loading... |
88 | 92 |
89 typedef GrFragmentProcessor INHERITED; | 93 typedef GrFragmentProcessor INHERITED; |
90 }; | 94 }; |
91 | 95 |
92 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); | 96 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); |
93 | 97 |
94 const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { | 98 const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { |
95 return BigKeyProcessor::Create(); | 99 return BigKeyProcessor::Create(); |
96 } | 100 } |
97 | 101 |
| 102 ////////////////////////////////////////////////////////////////////////////// |
| 103 |
| 104 class BlockInputFragmentProcessor : public GrFragmentProcessor { |
| 105 public: |
| 106 static GrFragmentProcessor* Create(const GrFragmentProcessor* fp) { |
| 107 return new BlockInputFragmentProcessor(fp); |
| 108 } |
| 109 |
| 110 const char* name() const override { return "Block Input"; } |
| 111 |
| 112 GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLFP
; } |
| 113 |
| 114 private: |
| 115 class GLFP : public GrGLFragmentProcessor { |
| 116 public: |
| 117 void emitCode(EmitArgs& args) override { |
| 118 this->emitChild(0, nullptr, args.fOutputColor, args); |
| 119 } |
| 120 |
| 121 private: |
| 122 typedef GrGLFragmentProcessor INHERITED; |
| 123 }; |
| 124 |
| 125 BlockInputFragmentProcessor(const GrFragmentProcessor* child) { |
| 126 this->initClassID<BlockInputFragmentProcessor>(); |
| 127 this->registerChildProcessor(child); |
| 128 } |
| 129 |
| 130 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override {} |
| 131 |
| 132 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 133 |
| 134 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 135 inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE, |
| 136 GrInvariantOutput::kWillNot_ReadInput); |
| 137 this->childProcessor(0).computeInvariantOutput(inout); |
| 138 } |
| 139 |
| 140 typedef GrFragmentProcessor INHERITED; |
| 141 }; |
| 142 |
| 143 ////////////////////////////////////////////////////////////////////////////// |
| 144 |
98 /* | 145 /* |
99 * Begin test code | 146 * Begin test code |
100 */ | 147 */ |
101 static const int kRenderTargetHeight = 1; | 148 static const int kRenderTargetHeight = 1; |
102 static const int kRenderTargetWidth = 1; | 149 static const int kRenderTargetWidth = 1; |
103 | 150 |
104 static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider,
SkRandom* random, | 151 static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider,
SkRandom* random, |
105 const GrCaps* caps) { | 152 const GrCaps* caps) { |
106 // setup render target | 153 // setup render target |
107 GrTextureParams params; | 154 GrTextureParams params; |
(...skipping 17 matching lines...) Expand all Loading... |
125 if (!texture) { | 172 if (!texture) { |
126 texture = textureProvider->createTexture(texDesc, true); | 173 texture = textureProvider->createTexture(texDesc, true); |
127 if (texture) { | 174 if (texture) { |
128 textureProvider->assignUniqueKeyToTexture(key, texture); | 175 textureProvider->assignUniqueKeyToTexture(key, texture); |
129 } | 176 } |
130 } | 177 } |
131 return texture ? texture->asRenderTarget() : nullptr; | 178 return texture ? texture->asRenderTarget() : nullptr; |
132 } | 179 } |
133 | 180 |
134 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa
ta* d) { | 181 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa
ta* d) { |
135 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Cre
ateStage(d)); | 182 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Cre
ate(d)); |
136 SkASSERT(xpf); | 183 SkASSERT(xpf); |
137 pipelineBuilder->setXPFactory(xpf.get()); | 184 pipelineBuilder->setXPFactory(xpf.get()); |
138 } | 185 } |
139 | 186 |
140 static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d
, | 187 static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d
, |
141 int minLevels, int ma
xLevels) { | 188 int minLevels, int ma
xLevels) { |
142 SkASSERT(1 <= minLevels); | 189 SkASSERT(1 <= minLevels); |
143 SkASSERT(minLevels <= maxLevels); | 190 SkASSERT(minLevels <= maxLevels); |
144 | 191 |
145 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate
. | 192 // 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 | 193 // If returning a leaf node, make sure that it doesn't have children (e.g. a
nother |
147 // GrComposeEffect) | 194 // GrComposeEffect) |
148 const float terminateProbability = 0.3f; | 195 const float terminateProbability = 0.3f; |
149 if (1 == minLevels) { | 196 if (1 == minLevels) { |
150 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminatePro
bability); | 197 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminatePro
bability); |
151 if (terminate) { | 198 if (terminate) { |
152 const GrFragmentProcessor* fp; | 199 const GrFragmentProcessor* fp; |
153 while (true) { | 200 while (true) { |
154 fp = GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)
; | 201 fp = GrProcessorTestFactory<GrFragmentProcessor>::Create(d); |
155 SkASSERT(fp); | 202 SkASSERT(fp); |
156 if (0 == fp->numChildProcessors()) { | 203 if (0 == fp->numChildProcessors()) { |
157 break; | 204 break; |
158 } | 205 } |
159 fp->unref(); | 206 fp->unref(); |
160 } | 207 } |
161 return fp; | 208 return fp; |
162 } | 209 } |
163 } | 210 } |
164 // If we didn't terminate, choose either the left or right subtree to fulfil
l | 211 // If we didn't terminate, choose either the left or right subtree to fulfil
l |
(...skipping 29 matching lines...) Expand all Loading... |
194 const int maxTreeLevels = 4; | 241 const int maxTreeLevels = 4; |
195 SkAutoTUnref<const GrFragmentProcessor> fp( | 242 SkAutoTUnref<const GrFragmentProcessor> fp( |
196 create_random_proc_tree(d, 2, maxTreeLev
els)); | 243 create_random_proc_tree(d, 2, maxTreeLev
els)); |
197 pipelineBuilder->addColorFragmentProcessor(fp); | 244 pipelineBuilder->addColorFragmentProcessor(fp); |
198 } else { | 245 } else { |
199 int numProcs = d->fRandom->nextULessThan(maxStages + 1); | 246 int numProcs = d->fRandom->nextULessThan(maxStages + 1); |
200 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); | 247 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); |
201 | 248 |
202 for (int s = 0; s < numProcs;) { | 249 for (int s = 0; s < numProcs;) { |
203 SkAutoTUnref<const GrFragmentProcessor> fp( | 250 SkAutoTUnref<const GrFragmentProcessor> fp( |
204 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d))
; | 251 GrProcessorTestFactory<GrFragmentProcessor>::Create(d)); |
205 SkASSERT(fp); | 252 SkASSERT(fp); |
206 | 253 |
207 // finally add the stage to the correct pipeline in the drawstate | 254 // finally add the stage to the correct pipeline in the drawstate |
208 if (s < numColorProcs) { | 255 if (s < numColorProcs) { |
209 pipelineBuilder->addColorFragmentProcessor(fp); | 256 pipelineBuilder->addColorFragmentProcessor(fp); |
210 } else { | 257 } else { |
211 pipelineBuilder->addCoverageFragmentProcessor(fp); | 258 pipelineBuilder->addCoverageFragmentProcessor(fp); |
212 } | 259 } |
213 ++s; | 260 ++s; |
214 } | 261 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 349 |
303 GrProcessorDataManager procDataManager; | 350 GrProcessorDataManager procDataManager; |
304 GrProcessorTestData ptd(&random, context, &procDataManager, fGpu->caps()
, dummyTextures); | 351 GrProcessorTestData ptd(&random, context, &procDataManager, fGpu->caps()
, dummyTextures); |
305 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); | 352 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); |
306 set_random_xpf(&pipelineBuilder, &ptd); | 353 set_random_xpf(&pipelineBuilder, &ptd); |
307 set_random_state(&pipelineBuilder, &random); | 354 set_random_state(&pipelineBuilder, &random); |
308 set_random_stencil(&pipelineBuilder, &random); | 355 set_random_stencil(&pipelineBuilder, &random); |
309 | 356 |
310 this->drawBatch(pipelineBuilder, batch); | 357 this->drawBatch(pipelineBuilder, batch); |
311 } | 358 } |
312 | |
313 // Flush everything, test passes if flush is successful(ie, no asserts are h
it, no crashes) | 359 // Flush everything, test passes if flush is successful(ie, no asserts are h
it, no crashes) |
314 this->flush(); | 360 this->flush(); |
| 361 |
| 362 // Validate that GrFPs work correctly without an input. |
| 363 GrSurfaceDesc rtDesc; |
| 364 rtDesc.fWidth = kRenderTargetWidth; |
| 365 rtDesc.fHeight = kRenderTargetHeight; |
| 366 rtDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 367 rtDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 368 SkAutoTUnref<GrRenderTarget> rt( |
| 369 fContext->textureProvider()->createTexture(rtDesc, false)->asRenderTarge
t()); |
| 370 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); |
| 371 for (int i = 0; i < fpFactoryCnt; ++i) { |
| 372 // Since FP factories internally randomize, call each 10 times. |
| 373 for (int j = 0; j < 10; ++j) { |
| 374 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context))
; |
| 375 SkASSERT(batch); |
| 376 GrProcessorDataManager procDataManager; |
| 377 GrProcessorTestData ptd(&random, context, &procDataManager, this->ca
ps(), |
| 378 dummyTextures); |
| 379 GrPipelineBuilder builder; |
| 380 builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_
Mode))->unref(); |
| 381 builder.setRenderTarget(rt); |
| 382 builder.setClip(clip); |
| 383 |
| 384 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 385 GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd))
; |
| 386 SkAutoTUnref<const GrFragmentProcessor> blockFP( |
| 387 BlockInputFragmentProcessor::Create(fp)); |
| 388 builder.addColorFragmentProcessor(blockFP); |
| 389 |
| 390 this->drawBatch(builder, batch); |
| 391 this->flush(); |
| 392 } |
| 393 } |
| 394 |
315 return true; | 395 return true; |
316 } | 396 } |
317 | 397 |
318 DEF_GPUTEST(GLPrograms, reporter, factory) { | 398 DEF_GPUTEST(GLPrograms, reporter, factory) { |
319 // Set a locale that would cause shader compilation to fail because of , as
decimal separator. | 399 // Set a locale that would cause shader compilation to fail because of , as
decimal separator. |
320 // skbug 3330 | 400 // skbug 3330 |
321 #ifdef SK_BUILD_FOR_WIN | 401 #ifdef SK_BUILD_FOR_WIN |
322 GrAutoLocaleSetter als("sv-SE"); | 402 GrAutoLocaleSetter als("sv-SE"); |
323 #else | 403 #else |
324 GrAutoLocaleSetter als("sv_SE.UTF-8"); | 404 GrAutoLocaleSetter als("sv_SE.UTF-8"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 442 } |
363 #endif | 443 #endif |
364 GrTestTarget target; | 444 GrTestTarget target; |
365 context->getTestTarget(&target); | 445 context->getTestTarget(&target); |
366 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context,
maxStages)); | 446 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context,
maxStages)); |
367 } | 447 } |
368 } | 448 } |
369 } | 449 } |
370 | 450 |
371 #endif | 451 #endif |
OLD | NEW |