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 *** NOTE: This was generated in origin/master and cherry-picked to android/next-release.
11 *** The .fp file that generated it relies on SkSL .fp features that are not present in
12 *** in android/next-release and thus were not cherry-picked.
13 **************************************************************************************************/
14 #include "GrOverrideInputFragmentProcessor.h"
15 #include "glsl/GrGLSLFragmentProcessor.h"
16 #include "glsl/GrGLSLFragmentShaderBuilder.h"
17 #include "glsl/GrGLSLProgramBuilder.h"
18 #include "GrTexture.h"
19 #include "SkSLCPP.h"
20 #include "SkSLUtil.h"
21 class GrGLSLOverrideInputFragmentProcessor : public GrGLSLFragmentProcessor {
22 public:
GrGLSLOverrideInputFragmentProcessor()23 GrGLSLOverrideInputFragmentProcessor() {}
emitCode(EmitArgs & args)24 void emitCode(EmitArgs& args) override {
25 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
26 const GrOverrideInputFragmentProcessor& _outer =
27 args.fFp.cast<GrOverrideInputFragmentProcessor>();
28 (void)_outer;
29 auto useUniform = _outer.useUniform;
30 (void)useUniform;
31 auto uniformColor = _outer.uniformColor;
32 (void)uniformColor;
33 auto literalColor = _outer.literalColor;
34 (void)literalColor;
35 if (useUniform) {
36 uniformColorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
37 kHalf4_GrSLType, "uniformColor");
38 }
39 fragBuilder->codeAppendf(
40 "half4 constColor;\n@if (%s) {\n constColor = %s;\n} else {\n constColor = "
41 "half4(%f, %f, %f, %f);\n}",
42 (_outer.useUniform ? "true" : "false"),
43 uniformColorVar.isValid() ? args.fUniformHandler->getUniformCStr(uniformColorVar)
44 : "half4(0)",
45 _outer.literalColor.fR, _outer.literalColor.fG, _outer.literalColor.fB,
46 _outer.literalColor.fA);
47 SkString _input0("constColor");
48 SkString _child0("_child0");
49 this->emitChild(_outer.fp_index, _input0.c_str(), &_child0, args);
50 fragBuilder->codeAppendf("\n%s = %s;\n", args.fOutputColor, _child0.c_str());
51 }
52
53 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)54 void onSetData(const GrGLSLProgramDataManager& pdman,
55 const GrFragmentProcessor& _proc) override {
56 const GrOverrideInputFragmentProcessor& _outer =
57 _proc.cast<GrOverrideInputFragmentProcessor>();
58 {
59 if (uniformColorVar.isValid()) {
60 pdman.set4fv(uniformColorVar, 1, (_outer.uniformColor).vec());
61 }
62 }
63 }
64 UniformHandle uniformColorVar;
65 };
onCreateGLSLInstance() const66 GrGLSLFragmentProcessor* GrOverrideInputFragmentProcessor::onCreateGLSLInstance() const {
67 return new GrGLSLOverrideInputFragmentProcessor();
68 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const69 void GrOverrideInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
70 GrProcessorKeyBuilder* b) const {
71 b->add32((int32_t)useUniform);
72 if (!useUniform) {
73 uint16_t red = SkFloatToHalf(literalColor.fR);
74 uint16_t green = SkFloatToHalf(literalColor.fG);
75 uint16_t blue = SkFloatToHalf(literalColor.fB);
76 uint16_t alpha = SkFloatToHalf(literalColor.fA);
77 b->add32(((uint32_t)red << 16) | green);
78 b->add32(((uint32_t)blue << 16) | alpha);
79 }
80 }
onIsEqual(const GrFragmentProcessor & other) const81 bool GrOverrideInputFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
82 const GrOverrideInputFragmentProcessor& that = other.cast<GrOverrideInputFragmentProcessor>();
83 (void)that;
84 if (useUniform != that.useUniform) return false;
85 if (uniformColor != that.uniformColor) return false;
86 if (literalColor != that.literalColor) return false;
87 return true;
88 }
GrOverrideInputFragmentProcessor(const GrOverrideInputFragmentProcessor & src)89 GrOverrideInputFragmentProcessor::GrOverrideInputFragmentProcessor(
90 const GrOverrideInputFragmentProcessor& src)
91 : INHERITED(kGrOverrideInputFragmentProcessor_ClassID, src.optimizationFlags())
92 , fp_index(src.fp_index)
93 , useUniform(src.useUniform)
94 , uniformColor(src.uniformColor)
95 , literalColor(src.literalColor) {
96 this->registerChildProcessor(src.childProcessor(fp_index).clone());
97 }
clone() const98 std::unique_ptr<GrFragmentProcessor> GrOverrideInputFragmentProcessor::clone() const {
99 return std::unique_ptr<GrFragmentProcessor>(new GrOverrideInputFragmentProcessor(*this));
100 }
101