From: wangyix Date: Tue, 8 Sep 2015 22:23:34 +0000 (-0700) Subject: Added TestCreate for SkComposeShader; will pick two random child procs that don... X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~953 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=036fd8e6f66b53cf87a5f91083cae82f0aeb3635;p=platform%2Fupstream%2FlibSkiaSharp.git Added TestCreate for SkComposeShader; will pick two random child procs that don't have children of their own. This prevents creating an arbitrarily large tree of procs. Also, it will choose a random coefficient mode for the xfermode. BUG=skia:4182 Review URL: https://codereview.chromium.org/1306163002 --- diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp index 50fc6aa..d3e29be 100644 --- a/src/core/SkComposeShader.cpp +++ b/src/core/SkComposeShader.cpp @@ -198,9 +198,9 @@ void SkComposeShader::ComposeShaderContext::shadeSpan(int x, int y, SkPMColor re #include "SkGr.h" #include "GrProcessor.h" +#include "effects/GrConstColorProcessor.h" #include "gl/GrGLBlend.h" #include "gl/builders/GrGLProgramBuilder.h" -#include "effects/GrConstColorProcessor.h" ///////////////////////////////////////////////////////////////////// @@ -235,6 +235,8 @@ private: SkXfermode::Mode fMode; + GR_DECLARE_FRAGMENT_PROCESSOR_TEST; + typedef GrFragmentProcessor INHERITED; }; @@ -250,6 +252,35 @@ private: typedef GrGLFragmentProcessor INHERITED; }; +///////////////////////////////////////////////////////////////////// + +GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrComposeEffect); + +const GrFragmentProcessor* GrComposeEffect::TestCreate(GrProcessorTestData* d) { +#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS + // Create two random frag procs. + // For now, we'll prevent either children from being a shader with children to prevent the + // possibility of an arbitrarily large tree of procs. + SkAutoTUnref fpA; + do { + fpA.reset(GrProcessorTestFactory::CreateStage(d)); + SkASSERT(fpA); + } while (fpA->numChildProcessors() != 0); + SkAutoTUnref fpB; + do { + fpB.reset(GrProcessorTestFactory::CreateStage(d)); + SkASSERT(fpB); + } while (fpB->numChildProcessors() != 0); + + SkXfermode::Mode mode = static_cast( + d->fRandom->nextRangeU(0, SkXfermode::kLastCoeffMode)); + return SkNEW_ARGS(GrComposeEffect, (fpA, fpB, mode)); +#else + SkFAIL("Should not be called if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS"); + return nullptr; +#endif +} + bool GrComposeEffect::onIsEqual(const GrFragmentProcessor& other) const { const GrComposeEffect& cs = other.cast(); return fMode == cs.fMode; diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp index 4f6d878..e324baa 100644 --- a/src/gpu/GrProcessor.cpp +++ b/src/gpu/GrProcessor.cpp @@ -50,7 +50,7 @@ GrProcessorTestFactory::GetFactories() { * we verify the count is as expected. If a new factory is added, then these numbers must be * manually adjusted. */ -static const int kFPFactoryCount = 37; +static const int kFPFactoryCount = 38; static const int kGPFactoryCount = 14; static const int kXPFactoryCount = 5;