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