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
13 #include "include/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"
19 class GrGLSLSingleIntervalGradientColorizer : public GrGLSLFragmentProcessor {
20 public:
GrGLSLSingleIntervalGradientColorizer()21 GrGLSLSingleIntervalGradientColorizer() {}
emitCode(EmitArgs & args)22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrSingleIntervalGradientColorizer& _outer =
25 args.fFp.cast<GrSingleIntervalGradientColorizer>();
26 (void)_outer;
27 auto start = _outer.start;
28 (void)start;
29 auto end = _outer.end;
30 (void)end;
31 startVar =
32 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "start");
33 endVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "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(startVar),
37 args.fUniformHandler->getUniformCStr(endVar));
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 (startPrev != startValue) {
48 startPrev = startValue;
49 pdman.set4fv(startVar, 1, startValue.vec());
50 }
51 const SkPMColor4f& endValue = _outer.end;
52 if (endPrev != endValue) {
53 endPrev = endValue;
54 pdman.set4fv(endVar, 1, endValue.vec());
55 }
56 }
57 }
58 SkPMColor4f startPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
59 SkPMColor4f endPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
60 UniformHandle startVar;
61 UniformHandle endVar;
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 (start != that.start) return false;
72 if (end != that.end) return false;
73 return true;
74 }
GrSingleIntervalGradientColorizer(const GrSingleIntervalGradientColorizer & src)75 GrSingleIntervalGradientColorizer::GrSingleIntervalGradientColorizer(
76 const GrSingleIntervalGradientColorizer& src)
77 : INHERITED(kGrSingleIntervalGradientColorizer_ClassID, src.optimizationFlags())
78 , start(src.start)
79 , end(src.end) {}
clone() const80 std::unique_ptr<GrFragmentProcessor> GrSingleIntervalGradientColorizer::clone() const {
81 return std::unique_ptr<GrFragmentProcessor>(new GrSingleIntervalGradientColorizer(*this));
82 }
83