diff options
author | 2015-09-14 12:26:33 -0700 | |
---|---|---|
committer | 2015-09-14 12:26:34 -0700 | |
commit | b5b603241aaa99e07dc4e12ca9f2661aa85e5f74 (patch) | |
tree | 7a36d748255d694e4de95b7d12ea0c7cfab309d7 /tests | |
parent | 0faed58bc781adc8f21786943ffada1a0fc69b5a (diff) |
Test that GrFragmentProcessors work without input colors.
Committed: https://skia.googlesource.com/skia/+/72c58e7052af2a0855412ce4b249f977069db751
Review URL: https://codereview.chromium.org/1341853002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/GLProgramsTest.cpp | 90 |
1 files changed, 85 insertions, 5 deletions
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index ce86c9bf38..ba64a7c9cb 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -47,7 +47,11 @@ public: virtual void emitCode(EmitArgs& args) override { // pass through GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); - fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor); + if (args.fInputColor) { + fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor); + } else { + fsBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor); + } } static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) { @@ -95,6 +99,49 @@ const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { return BigKeyProcessor::Create(); } +////////////////////////////////////////////////////////////////////////////// + +class BlockInputFragmentProcessor : public GrFragmentProcessor { +public: + static GrFragmentProcessor* Create(const GrFragmentProcessor* fp) { + return new BlockInputFragmentProcessor(fp); + } + + const char* name() const override { return "Block Input"; } + + GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLFP; } + +private: + class GLFP : public GrGLFragmentProcessor { + public: + void emitCode(EmitArgs& args) override { + this->emitChild(0, nullptr, args.fOutputColor, args); + } + + private: + typedef GrGLFragmentProcessor INHERITED; + }; + + BlockInputFragmentProcessor(const GrFragmentProcessor* child) { + this->initClassID<BlockInputFragmentProcessor>(); + this->registerChildProcessor(child); + } + + void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {} + + bool onIsEqual(const GrFragmentProcessor&) const override { return true; } + + void onComputeInvariantOutput(GrInvariantOutput* inout) const override { + inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE, + GrInvariantOutput::kWillNot_ReadInput); + this->childProcessor(0).computeInvariantOutput(inout); + } + + typedef GrFragmentProcessor INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + /* * Begin test code */ @@ -132,7 +179,7 @@ static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider, } static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestData* d) { - SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::CreateStage(d)); + SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Create(d)); SkASSERT(xpf); pipelineBuilder->setXPFactory(xpf.get()); } @@ -151,7 +198,7 @@ static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d if (terminate) { const GrFragmentProcessor* fp; while (true) { - fp = GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d); + fp = GrProcessorTestFactory<GrFragmentProcessor>::Create(d); SkASSERT(fp); if (0 == fp->numChildProcessors()) { break; @@ -201,7 +248,7 @@ static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, for (int s = 0; s < numProcs;) { SkAutoTUnref<const GrFragmentProcessor> fp( - GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); + GrProcessorTestFactory<GrFragmentProcessor>::Create(d)); SkASSERT(fp); // finally add the stage to the correct pipeline in the drawstate @@ -309,9 +356,42 @@ bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) { this->drawBatch(pipelineBuilder, batch); } - // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) this->flush(); + + // Validate that GrFPs work correctly without an input. + GrSurfaceDesc rtDesc; + rtDesc.fWidth = kRenderTargetWidth; + rtDesc.fHeight = kRenderTargetHeight; + rtDesc.fFlags = kRenderTarget_GrSurfaceFlag; + rtDesc.fConfig = kRGBA_8888_GrPixelConfig; + SkAutoTUnref<GrRenderTarget> rt( + fContext->textureProvider()->createTexture(rtDesc, false)->asRenderTarget()); + int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); + for (int i = 0; i < fpFactoryCnt; ++i) { + // Since FP factories internally randomize, call each 10 times. + for (int j = 0; j < 10; ++j) { + SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); + SkASSERT(batch); + GrProcessorDataManager procDataManager; + GrProcessorTestData ptd(&random, context, &procDataManager, this->caps(), + dummyTextures); + GrPipelineBuilder builder; + builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); + builder.setRenderTarget(rt); + builder.setClip(clip); + + SkAutoTUnref<const GrFragmentProcessor> fp( + GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd)); + SkAutoTUnref<const GrFragmentProcessor> blockFP( + BlockInputFragmentProcessor::Create(fp)); + builder.addColorFragmentProcessor(blockFP); + + this->drawBatch(builder, batch); + this->flush(); + } + } + return true; } |