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 =
31 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "start");
32 fEndVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "end");
33 fragBuilder->codeAppendf("half t = %s.x;\n%s = (1.0 - t) * %s + t * %s;\n",
34 args.fInputColor, args.fOutputColor,
35 args.fUniformHandler->getUniformCStr(fStartVar),
36 args.fUniformHandler->getUniformCStr(fEndVar));
37 }
38
39 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)40 void onSetData(const GrGLSLProgramDataManager& pdman,
41 const GrFragmentProcessor& _proc) override {
42 const GrSingleIntervalGradientColorizer& _outer =
43 _proc.cast<GrSingleIntervalGradientColorizer>();
44 {
45 const SkPMColor4f& startValue = _outer.start();
46 if (fStartPrev != startValue) {
47 fStartPrev = startValue;
48 pdman.set4fv(fStartVar, 1, startValue.vec());
49 }
50 const SkPMColor4f& endValue = _outer.end();
51 if (fEndPrev != endValue) {
52 fEndPrev = endValue;
53 pdman.set4fv(fEndVar, 1, endValue.vec());
54 }
55 }
56 }
57 SkPMColor4f fStartPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
58 SkPMColor4f fEndPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
59 UniformHandle fStartVar;
60 UniformHandle fEndVar;
61 };
onCreateGLSLInstance() const62 GrGLSLFragmentProcessor* GrSingleIntervalGradientColorizer::onCreateGLSLInstance() const {
63 return new GrGLSLSingleIntervalGradientColorizer();
64 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const65 void GrSingleIntervalGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
66 GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const67 bool GrSingleIntervalGradientColorizer::onIsEqual(const GrFragmentProcessor& other) const {
68 const GrSingleIntervalGradientColorizer& that = other.cast<GrSingleIntervalGradientColorizer>();
69 (void)that;
70 if (fStart != that.fStart) return false;
71 if (fEnd != that.fEnd) return false;
72 return true;
73 }
GrSingleIntervalGradientColorizer(const GrSingleIntervalGradientColorizer & src)74 GrSingleIntervalGradientColorizer::GrSingleIntervalGradientColorizer(
75 const GrSingleIntervalGradientColorizer& src)
76 : INHERITED(kGrSingleIntervalGradientColorizer_ClassID, src.optimizationFlags())
77 , fStart(src.fStart)
78 , fEnd(src.fEnd) {}
clone() const79 std::unique_ptr<GrFragmentProcessor> GrSingleIntervalGradientColorizer::clone() const {
80 return std::unique_ptr<GrFragmentProcessor>(new GrSingleIntervalGradientColorizer(*this));
81 }
82