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/gpu/GrTexture.h"
14#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
15#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
16#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
17#include "src/sksl/SkSLCPP.h"
18#include "src/sksl/SkSLUtil.h"
19class GrGLSLOverrideInputFragmentProcessor : public GrGLSLFragmentProcessor {
20public:
21 GrGLSLOverrideInputFragmentProcessor() {}
22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrOverrideInputFragmentProcessor& _outer =
25 args.fFp.cast<GrOverrideInputFragmentProcessor>();
26 (void)_outer;
27 auto useUniform = _outer.useUniform;
28 (void)useUniform;
29 auto uniformColor = _outer.uniformColor;
30 (void)uniformColor;
31 auto literalColor = _outer.literalColor;
32 (void)literalColor;
33 if (useUniform) {
34 uniformColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
35 kHalf4_GrSLType, "uniformColor");
36 }
37 fragBuilder->codeAppendf(
38 "half4 constColor;\n@if (%s) {\n constColor = %s;\n} else {\n constColor = "
39 "half4(%f, %f, %f, %f);\n}",
40 (_outer.useUniform ? "true" : "false"),
41 uniformColorVar.isValid() ? args.fUniformHandler->getUniformCStr(uniformColorVar)
42 : "half4(0)",
43 _outer.literalColor.fR, _outer.literalColor.fG, _outer.literalColor.fB,
44 _outer.literalColor.fA);
45 SkString _input1992("constColor");
46 SkString _sample1992;
47 _sample1992 = this->invokeChild(_outer.fp_index, _input1992.c_str(), args);
48 fragBuilder->codeAppendf("\n%s = %s;\n", args.fOutputColor, _sample1992.c_str());
49 }
50
51private:
52 void onSetData(const GrGLSLProgramDataManager& pdman,
53 const GrFragmentProcessor& _proc) override {
54 const GrOverrideInputFragmentProcessor& _outer =
55 _proc.cast<GrOverrideInputFragmentProcessor>();
56 {
57 if (uniformColorVar.isValid()) {
58 pdman.set4fv(uniformColorVar, 1, (_outer.uniformColor).vec());
59 }
60 }
61 }
62 UniformHandle uniformColorVar;
63};
64GrGLSLFragmentProcessor* GrOverrideInputFragmentProcessor::onCreateGLSLInstance() const {
65 return new GrGLSLOverrideInputFragmentProcessor();
66}
67void GrOverrideInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
68 GrProcessorKeyBuilder* b) const {
69 b->add32((int32_t)useUniform);
70 if (!useUniform) {
71 uint16_t red = SkFloatToHalf(literalColor.fR);
72 uint16_t green = SkFloatToHalf(literalColor.fG);
73 uint16_t blue = SkFloatToHalf(literalColor.fB);
74 uint16_t alpha = SkFloatToHalf(literalColor.fA);
75 b->add32(((uint32_t)red << 16) | green);
76 b->add32(((uint32_t)blue << 16) | alpha);
77 }
78}
79bool GrOverrideInputFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
80 const GrOverrideInputFragmentProcessor& that = other.cast<GrOverrideInputFragmentProcessor>();
81 (void)that;
82 if (useUniform != that.useUniform) return false;
83 if (uniformColor != that.uniformColor) return false;
84 if (literalColor != that.literalColor) return false;
85 return true;
86}
87GrOverrideInputFragmentProcessor::GrOverrideInputFragmentProcessor(
88 const GrOverrideInputFragmentProcessor& src)
89 : INHERITED(kGrOverrideInputFragmentProcessor_ClassID, src.optimizationFlags())
90 , fp_index(src.fp_index)
91 , useUniform(src.useUniform)
92 , uniformColor(src.uniformColor)
93 , literalColor(src.literalColor) {
94 {
95 auto clone = src.childProcessor(fp_index).clone();
96 clone->setSampledWithExplicitCoords(
97 src.childProcessor(fp_index).isSampledWithExplicitCoords());
98 this->registerChildProcessor(std::move(clone));
99 }
100}
101std::unique_ptr<GrFragmentProcessor> GrOverrideInputFragmentProcessor::clone() const {
102 return std::unique_ptr<GrFragmentProcessor>(new GrOverrideInputFragmentProcessor(*this));
103}
104