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