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 GrSingleIntervalGradientColorizer.fp; do not modify.
10 **************************************************************************************************/
11 #include "GrSingleIntervalGradientColorizer.h"
12 #include "glsl/GrGLSLFragmentProcessor.h"
13 #include "glsl/GrGLSLFragmentShaderBuilder.h"
14 #include "glsl/GrGLSLProgramBuilder.h"
15 #include "GrTexture.h"
16 #include "SkSLCPP.h"
17 #include "SkSLUtil.h"
18 class GrGLSLSingleIntervalGradientColorizer : public GrGLSLFragmentProcessor {
19 public:
GrGLSLSingleIntervalGradientColorizer()20 GrGLSLSingleIntervalGradientColorizer() {}
emitCode(EmitArgs & args)21 void emitCode(EmitArgs& args) override {
22 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23 const GrSingleIntervalGradientColorizer& _outer =
24 args.fFp.cast<GrSingleIntervalGradientColorizer>();
25 (void)_outer;
26 auto start = _outer.start();
27 (void)start;
28 auto end = _outer.end();
29 (void)end;
30 fStartVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
31 kDefault_GrSLPrecision, "start");
32 fEndVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
33 kDefault_GrSLPrecision, "end");
34 fragBuilder->codeAppendf("half t = %s.x;\n%s = (1.0 - t) * %s + t * %s;\n",
35 args.fInputColor, args.fOutputColor,
36 args.fUniformHandler->getUniformCStr(fStartVar),
37 args.fUniformHandler->getUniformCStr(fEndVar));
38 }
39
40 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)41 void onSetData(const GrGLSLProgramDataManager& pdman,
42 const GrFragmentProcessor& _proc) override {
43 const GrSingleIntervalGradientColorizer& _outer =
44 _proc.cast<GrSingleIntervalGradientColorizer>();
45 {
46 const SkPMColor4f& startValue = _outer.start();
47 if (fStartPrev != startValue) {
48 fStartPrev = startValue;
49 pdman.set4fv(fStartVar, 1, startValue.vec());
50 }
51 const SkPMColor4f& endValue = _outer.end();
52 if (fEndPrev != endValue) {
53 fEndPrev = endValue;
54 pdman.set4fv(fEndVar, 1, endValue.vec());
55 }
56 }
57 }
58 SkPMColor4f fStartPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
59 SkPMColor4f fEndPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
60 UniformHandle fStartVar;
61 UniformHandle fEndVar;
62 };
onCreateGLSLInstance() const63 GrGLSLFragmentProcessor* GrSingleIntervalGradientColorizer::onCreateGLSLInstance() const {
64 return new GrGLSLSingleIntervalGradientColorizer();
65 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const66 void GrSingleIntervalGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
67 GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const68 bool GrSingleIntervalGradientColorizer::onIsEqual(const GrFragmentProcessor& other) const {
69 const GrSingleIntervalGradientColorizer& that = other.cast<GrSingleIntervalGradientColorizer>();
70 (void)that;
71 if (fStart != that.fStart) return false;
72 if (fEnd != that.fEnd) return false;
73 return true;
74 }
GrSingleIntervalGradientColorizer(const GrSingleIntervalGradientColorizer & src)75 GrSingleIntervalGradientColorizer::GrSingleIntervalGradientColorizer(
76 const GrSingleIntervalGradientColorizer& src)
77 : INHERITED(kGrSingleIntervalGradientColorizer_ClassID, src.optimizationFlags())
78 , fStart(src.fStart)
79 , fEnd(src.fEnd) {}
clone() const80 std::unique_ptr<GrFragmentProcessor> GrSingleIntervalGradientColorizer::clone() const {
81 return std::unique_ptr<GrFragmentProcessor>(new GrSingleIntervalGradientColorizer(*this));
82 }
83