1 | /* |
2 | * Copyright 2019 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 GrOverrideInputFragmentProcessor.fp; do not modify. |
10 | **************************************************************************************************/ |
11 | #include "GrOverrideInputFragmentProcessor.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 GrGLSLOverrideInputFragmentProcessor : public GrGLSLFragmentProcessor { |
21 | public: |
22 | GrGLSLOverrideInputFragmentProcessor() {} |
23 | void emitCode(EmitArgs& args) override { |
24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
25 | const GrOverrideInputFragmentProcessor& _outer = |
26 | args.fFp.cast<GrOverrideInputFragmentProcessor>(); |
27 | (void)_outer; |
28 | auto useUniform = _outer.useUniform; |
29 | (void)useUniform; |
30 | auto uniformColor = _outer.uniformColor; |
31 | (void)uniformColor; |
32 | auto literalColor = _outer.literalColor; |
33 | (void)literalColor; |
34 | if (useUniform) { |
35 | uniformColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
36 | kHalf4_GrSLType, "uniformColor" ); |
37 | } |
38 | fragBuilder->codeAppendf( |
39 | R"SkSL(half4 constColor; |
40 | @if (%s) { |
41 | constColor = %s; |
42 | } else { |
43 | constColor = half4(%f, %f, %f, %f); |
44 | })SkSL" , |
45 | (_outer.useUniform ? "true" : "false" ), |
46 | uniformColorVar.isValid() ? args.fUniformHandler->getUniformCStr(uniformColorVar) |
47 | : "half4(0)" , |
48 | _outer.literalColor.fR, _outer.literalColor.fG, _outer.literalColor.fB, |
49 | _outer.literalColor.fA); |
50 | SkString _input1992("constColor" ); |
51 | SkString _sample1992 = this->invokeChild(0, _input1992.c_str(), args); |
52 | fragBuilder->codeAppendf( |
53 | R"SkSL( |
54 | %s = %s; |
55 | )SkSL" , |
56 | args.fOutputColor, _sample1992.c_str()); |
57 | } |
58 | |
59 | private: |
60 | void onSetData(const GrGLSLProgramDataManager& pdman, |
61 | const GrFragmentProcessor& _proc) override { |
62 | const GrOverrideInputFragmentProcessor& _outer = |
63 | _proc.cast<GrOverrideInputFragmentProcessor>(); |
64 | { |
65 | if (uniformColorVar.isValid()) { |
66 | pdman.set4fv(uniformColorVar, 1, (_outer.uniformColor).vec()); |
67 | } |
68 | } |
69 | } |
70 | UniformHandle uniformColorVar; |
71 | }; |
72 | GrGLSLFragmentProcessor* GrOverrideInputFragmentProcessor::onCreateGLSLInstance() const { |
73 | return new GrGLSLOverrideInputFragmentProcessor(); |
74 | } |
75 | void GrOverrideInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
76 | GrProcessorKeyBuilder* b) const { |
77 | b->add32((uint32_t)useUniform); |
78 | if (!useUniform) { |
79 | uint16_t red = SkFloatToHalf(literalColor.fR); |
80 | uint16_t green = SkFloatToHalf(literalColor.fG); |
81 | uint16_t blue = SkFloatToHalf(literalColor.fB); |
82 | uint16_t alpha = SkFloatToHalf(literalColor.fA); |
83 | b->add32(((uint32_t)red << 16) | green); |
84 | b->add32(((uint32_t)blue << 16) | alpha); |
85 | } |
86 | } |
87 | bool GrOverrideInputFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { |
88 | const GrOverrideInputFragmentProcessor& that = other.cast<GrOverrideInputFragmentProcessor>(); |
89 | (void)that; |
90 | if (useUniform != that.useUniform) return false; |
91 | if (uniformColor != that.uniformColor) return false; |
92 | if (literalColor != that.literalColor) return false; |
93 | return true; |
94 | } |
95 | GrOverrideInputFragmentProcessor::GrOverrideInputFragmentProcessor( |
96 | const GrOverrideInputFragmentProcessor& src) |
97 | : INHERITED(kGrOverrideInputFragmentProcessor_ClassID, src.optimizationFlags()) |
98 | , useUniform(src.useUniform) |
99 | , uniformColor(src.uniformColor) |
100 | , literalColor(src.literalColor) { |
101 | this->cloneAndRegisterAllChildProcessors(src); |
102 | } |
103 | std::unique_ptr<GrFragmentProcessor> GrOverrideInputFragmentProcessor::clone() const { |
104 | return std::make_unique<GrOverrideInputFragmentProcessor>(*this); |
105 | } |
106 | #if GR_TEST_UTILS |
107 | SkString GrOverrideInputFragmentProcessor::onDumpInfo() const { |
108 | return SkStringPrintf( |
109 | "(useUniform=%s, uniformColor=half4(%f, %f, %f, %f), literalColor=half4(%f, %f, %f, " |
110 | "%f))" , |
111 | (useUniform ? "true" : "false" ), uniformColor.fR, uniformColor.fG, uniformColor.fB, |
112 | uniformColor.fA, literalColor.fR, literalColor.fG, literalColor.fB, literalColor.fA); |
113 | } |
114 | #endif |
115 | |