| 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrAlphaThresholdFragmentProcessor.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrAlphaThresholdFragmentProcessor.h" |
| 12 | |
| 13 | #include "src/core/SkUtils.h" |
| 14 | #include "src/gpu/GrTexture.h" |
| 15 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 16 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 17 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
| 18 | #include "src/sksl/SkSLCPP.h" |
| 19 | #include "src/sksl/SkSLUtil.h" |
| 20 | class GrGLSLAlphaThresholdFragmentProcessor : public GrGLSLFragmentProcessor { |
| 21 | public: |
| 22 | GrGLSLAlphaThresholdFragmentProcessor() {} |
| 23 | void emitCode(EmitArgs& args) override { |
| 24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 25 | const GrAlphaThresholdFragmentProcessor& _outer = |
| 26 | args.fFp.cast<GrAlphaThresholdFragmentProcessor>(); |
| 27 | (void)_outer; |
| 28 | auto innerThreshold = _outer.innerThreshold; |
| 29 | (void)innerThreshold; |
| 30 | auto outerThreshold = _outer.outerThreshold; |
| 31 | (void)outerThreshold; |
| 32 | innerThresholdVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 33 | kHalf_GrSLType, "innerThreshold" ); |
| 34 | outerThresholdVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 35 | kHalf_GrSLType, "outerThreshold" ); |
| 36 | SkString _sample515 = this->invokeChild(0, args); |
| 37 | fragBuilder->codeAppendf( |
| 38 | R"SkSL(half4 color = %s;)SkSL" , _sample515.c_str()); |
| 39 | SkString _sample555 = this->invokeChild(1, args); |
| 40 | fragBuilder->codeAppendf( |
| 41 | R"SkSL( |
| 42 | half4 mask_color = %s; |
| 43 | if (mask_color.w < 0.5) { |
| 44 | if (color.w > %s) { |
| 45 | half scale = %s / color.w; |
| 46 | color.xyz *= scale; |
| 47 | color.w = %s; |
| 48 | } |
| 49 | } else if (color.w < %s) { |
| 50 | half scale = %s / max(0.0010000000474974513, color.w); |
| 51 | color.xyz *= scale; |
| 52 | color.w = %s; |
| 53 | } |
| 54 | %s = color; |
| 55 | )SkSL" , |
| 56 | _sample555.c_str(), args.fUniformHandler->getUniformCStr(outerThresholdVar), |
| 57 | args.fUniformHandler->getUniformCStr(outerThresholdVar), |
| 58 | args.fUniformHandler->getUniformCStr(outerThresholdVar), |
| 59 | args.fUniformHandler->getUniformCStr(innerThresholdVar), |
| 60 | args.fUniformHandler->getUniformCStr(innerThresholdVar), |
| 61 | args.fUniformHandler->getUniformCStr(innerThresholdVar), args.fOutputColor); |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 66 | const GrFragmentProcessor& _proc) override { |
| 67 | const GrAlphaThresholdFragmentProcessor& _outer = |
| 68 | _proc.cast<GrAlphaThresholdFragmentProcessor>(); |
| 69 | { |
| 70 | pdman.set1f(innerThresholdVar, (_outer.innerThreshold)); |
| 71 | pdman.set1f(outerThresholdVar, (_outer.outerThreshold)); |
| 72 | } |
| 73 | } |
| 74 | UniformHandle innerThresholdVar; |
| 75 | UniformHandle outerThresholdVar; |
| 76 | }; |
| 77 | GrGLSLFragmentProcessor* GrAlphaThresholdFragmentProcessor::onCreateGLSLInstance() const { |
| 78 | return new GrGLSLAlphaThresholdFragmentProcessor(); |
| 79 | } |
| 80 | void GrAlphaThresholdFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 81 | GrProcessorKeyBuilder* b) const {} |
| 82 | bool GrAlphaThresholdFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { |
| 83 | const GrAlphaThresholdFragmentProcessor& that = other.cast<GrAlphaThresholdFragmentProcessor>(); |
| 84 | (void)that; |
| 85 | if (innerThreshold != that.innerThreshold) return false; |
| 86 | if (outerThreshold != that.outerThreshold) return false; |
| 87 | return true; |
| 88 | } |
| 89 | GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor( |
| 90 | const GrAlphaThresholdFragmentProcessor& src) |
| 91 | : INHERITED(kGrAlphaThresholdFragmentProcessor_ClassID, src.optimizationFlags()) |
| 92 | , innerThreshold(src.innerThreshold) |
| 93 | , outerThreshold(src.outerThreshold) { |
| 94 | this->cloneAndRegisterAllChildProcessors(src); |
| 95 | } |
| 96 | std::unique_ptr<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::clone() const { |
| 97 | return std::make_unique<GrAlphaThresholdFragmentProcessor>(*this); |
| 98 | } |
| 99 | #if GR_TEST_UTILS |
| 100 | SkString GrAlphaThresholdFragmentProcessor::onDumpInfo() const { |
| 101 | return SkStringPrintf("(innerThreshold=%f, outerThreshold=%f)" , innerThreshold, outerThreshold); |
| 102 | } |
| 103 | #endif |
| 104 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrAlphaThresholdFragmentProcessor); |
| 105 | #if GR_TEST_UTILS |
| 106 | std::unique_ptr<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::TestCreate( |
| 107 | GrProcessorTestData* testData) { |
| 108 | // Make the inner and outer thresholds be in [0, 1]. |
| 109 | float outerThresh = testData->fRandom->nextUScalar1(); |
| 110 | float innerThresh = testData->fRandom->nextUScalar1(); |
| 111 | std::unique_ptr<GrFragmentProcessor> inputChild, maskChild; |
| 112 | if (testData->fRandom->nextBool()) { |
| 113 | inputChild = GrProcessorUnitTest::MakeChildFP(testData); |
| 114 | } |
| 115 | maskChild = GrProcessorUnitTest::MakeChildFP(testData); |
| 116 | |
| 117 | return GrAlphaThresholdFragmentProcessor::Make(std::move(inputChild), std::move(maskChild), |
| 118 | innerThresh, outerThresh); |
| 119 | } |
| 120 | #endif |
| 121 | |