1 | /* |
2 | * Copyright 2020 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 GrArithmeticProcessor.fp; do not modify. |
10 | **************************************************************************************************/ |
11 | #include "GrArithmeticProcessor.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 GrGLSLArithmeticProcessor : public GrGLSLFragmentProcessor { |
21 | public: |
22 | GrGLSLArithmeticProcessor() {} |
23 | void emitCode(EmitArgs& args) override { |
24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
25 | const GrArithmeticProcessor& _outer = args.fFp.cast<GrArithmeticProcessor>(); |
26 | (void)_outer; |
27 | auto k = _outer.k; |
28 | (void)k; |
29 | auto enforcePMColor = _outer.enforcePMColor; |
30 | (void)enforcePMColor; |
31 | kVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kFloat4_GrSLType, |
32 | "k" ); |
33 | SkString _sample385 = this->invokeChild(0, args); |
34 | fragBuilder->codeAppendf( |
35 | R"SkSL(half4 src = %s;)SkSL" , _sample385.c_str()); |
36 | SkString _sample416 = this->invokeChild(1, args); |
37 | fragBuilder->codeAppendf( |
38 | R"SkSL( |
39 | half4 dst = %s; |
40 | %s = clamp((((half(%s.x) * src) * dst + half(%s.y) * src) + half(%s.z) * dst) + half(%s.w), 0.0, 1.0); |
41 | @if (%s) { |
42 | %s.xyz = min(%s.xyz, %s.w); |
43 | } |
44 | )SkSL" , |
45 | _sample416.c_str(), args.fOutputColor, args.fUniformHandler->getUniformCStr(kVar), |
46 | args.fUniformHandler->getUniformCStr(kVar), |
47 | args.fUniformHandler->getUniformCStr(kVar), |
48 | args.fUniformHandler->getUniformCStr(kVar), |
49 | (_outer.enforcePMColor ? "true" : "false" ), args.fOutputColor, args.fOutputColor, |
50 | args.fOutputColor); |
51 | } |
52 | |
53 | private: |
54 | void onSetData(const GrGLSLProgramDataManager& pdman, |
55 | const GrFragmentProcessor& _proc) override { |
56 | const GrArithmeticProcessor& _outer = _proc.cast<GrArithmeticProcessor>(); |
57 | { pdman.set4fv(kVar, 1, (_outer.k).ptr()); } |
58 | } |
59 | UniformHandle kVar; |
60 | }; |
61 | GrGLSLFragmentProcessor* GrArithmeticProcessor::onCreateGLSLInstance() const { |
62 | return new GrGLSLArithmeticProcessor(); |
63 | } |
64 | void GrArithmeticProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
65 | GrProcessorKeyBuilder* b) const { |
66 | b->add32((uint32_t)enforcePMColor); |
67 | } |
68 | bool GrArithmeticProcessor::onIsEqual(const GrFragmentProcessor& other) const { |
69 | const GrArithmeticProcessor& that = other.cast<GrArithmeticProcessor>(); |
70 | (void)that; |
71 | if (k != that.k) return false; |
72 | if (enforcePMColor != that.enforcePMColor) return false; |
73 | return true; |
74 | } |
75 | GrArithmeticProcessor::GrArithmeticProcessor(const GrArithmeticProcessor& src) |
76 | : INHERITED(kGrArithmeticProcessor_ClassID, src.optimizationFlags()) |
77 | , k(src.k) |
78 | , enforcePMColor(src.enforcePMColor) { |
79 | this->cloneAndRegisterAllChildProcessors(src); |
80 | } |
81 | std::unique_ptr<GrFragmentProcessor> GrArithmeticProcessor::clone() const { |
82 | return std::make_unique<GrArithmeticProcessor>(*this); |
83 | } |
84 | #if GR_TEST_UTILS |
85 | SkString GrArithmeticProcessor::onDumpInfo() const { |
86 | return SkStringPrintf("(k=float4(%f, %f, %f, %f), enforcePMColor=%s)" , k.x, k.y, k.z, k.w, |
87 | (enforcePMColor ? "true" : "false" )); |
88 | } |
89 | #endif |
90 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticProcessor); |
91 | #if GR_TEST_UTILS |
92 | std::unique_ptr<GrFragmentProcessor> GrArithmeticProcessor::TestCreate(GrProcessorTestData* d) { |
93 | return GrArithmeticProcessor::Make( |
94 | GrProcessorUnitTest::MakeChildFP(d), GrProcessorUnitTest::MakeChildFP(d), |
95 | ArithmeticFPInputs{d->fRandom->nextF(), d->fRandom->nextF(), d->fRandom->nextF(), |
96 | d->fRandom->nextF(), d->fRandom->nextBool()}); |
97 | } |
98 | #endif |
99 | |