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"
20class GrGLSLAlphaThresholdFragmentProcessor : public GrGLSLFragmentProcessor {
21public:
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(
42half4 mask_color = %s;
43if (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
64private:
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};
77GrGLSLFragmentProcessor* GrAlphaThresholdFragmentProcessor::onCreateGLSLInstance() const {
78 return new GrGLSLAlphaThresholdFragmentProcessor();
79}
80void GrAlphaThresholdFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
81 GrProcessorKeyBuilder* b) const {}
82bool 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}
89GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor(
90 const GrAlphaThresholdFragmentProcessor& src)
91 : INHERITED(kGrAlphaThresholdFragmentProcessor_ClassID, src.optimizationFlags())
92 , innerThreshold(src.innerThreshold)
93 , outerThreshold(src.outerThreshold) {
94 this->cloneAndRegisterAllChildProcessors(src);
95}
96std::unique_ptr<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::clone() const {
97 return std::make_unique<GrAlphaThresholdFragmentProcessor>(*this);
98}
99#if GR_TEST_UTILS
100SkString GrAlphaThresholdFragmentProcessor::onDumpInfo() const {
101 return SkStringPrintf("(innerThreshold=%f, outerThreshold=%f)", innerThreshold, outerThreshold);
102}
103#endif
104GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrAlphaThresholdFragmentProcessor);
105#if GR_TEST_UTILS
106std::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