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 GrClampedGradientEffect.fp; do not modify. |
10 | **************************************************************************************************/ |
11 | #include "GrClampedGradientEffect.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 GrGLSLClampedGradientEffect : public GrGLSLFragmentProcessor { |
20 | public: |
21 | GrGLSLClampedGradientEffect() {} |
22 | void emitCode(EmitArgs& args) override { |
23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
24 | const GrClampedGradientEffect& _outer = args.fFp.cast<GrClampedGradientEffect>(); |
25 | (void)_outer; |
26 | auto leftBorderColor = _outer.leftBorderColor; |
27 | (void)leftBorderColor; |
28 | auto rightBorderColor = _outer.rightBorderColor; |
29 | (void)rightBorderColor; |
30 | auto makePremul = _outer.makePremul; |
31 | (void)makePremul; |
32 | auto colorsAreOpaque = _outer.colorsAreOpaque; |
33 | (void)colorsAreOpaque; |
34 | leftBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
35 | kHalf4_GrSLType, "leftBorderColor" ); |
36 | rightBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
37 | kHalf4_GrSLType, "rightBorderColor" ); |
38 | SkString _sample1099; |
39 | _sample1099 = this->invokeChild(_outer.gradLayout_index, args); |
40 | fragBuilder->codeAppendf( |
41 | "half4 t = %s;\nif (!%s && t.y < 0.0) {\n %s = half4(0.0);\n} else if (t.x < " |
42 | "0.0) {\n %s = %s;\n} else if (t.x > 1.0) {\n %s = %s;\n} else {" , |
43 | _sample1099.c_str(), |
44 | (_outer.childProcessor(_outer.gradLayout_index).preservesOpaqueInput() ? "true" |
45 | : "false" ), |
46 | args.fOutputColor, args.fOutputColor, |
47 | args.fUniformHandler->getUniformCStr(leftBorderColorVar), args.fOutputColor, |
48 | args.fUniformHandler->getUniformCStr(rightBorderColorVar)); |
49 | SkString _input1767("t" ); |
50 | SkString _sample1767; |
51 | _sample1767 = this->invokeChild(_outer.colorizer_index, _input1767.c_str(), args); |
52 | fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n" , |
53 | args.fOutputColor, _sample1767.c_str(), |
54 | (_outer.makePremul ? "true" : "false" ), args.fOutputColor, |
55 | args.fOutputColor); |
56 | } |
57 | |
58 | private: |
59 | void onSetData(const GrGLSLProgramDataManager& pdman, |
60 | const GrFragmentProcessor& _proc) override { |
61 | const GrClampedGradientEffect& _outer = _proc.cast<GrClampedGradientEffect>(); |
62 | { |
63 | const SkPMColor4f& leftBorderColorValue = _outer.leftBorderColor; |
64 | if (leftBorderColorPrev != leftBorderColorValue) { |
65 | leftBorderColorPrev = leftBorderColorValue; |
66 | pdman.set4fv(leftBorderColorVar, 1, leftBorderColorValue.vec()); |
67 | } |
68 | const SkPMColor4f& rightBorderColorValue = _outer.rightBorderColor; |
69 | if (rightBorderColorPrev != rightBorderColorValue) { |
70 | rightBorderColorPrev = rightBorderColorValue; |
71 | pdman.set4fv(rightBorderColorVar, 1, rightBorderColorValue.vec()); |
72 | } |
73 | } |
74 | } |
75 | SkPMColor4f leftBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}; |
76 | SkPMColor4f rightBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}; |
77 | UniformHandle leftBorderColorVar; |
78 | UniformHandle rightBorderColorVar; |
79 | }; |
80 | GrGLSLFragmentProcessor* GrClampedGradientEffect::onCreateGLSLInstance() const { |
81 | return new GrGLSLClampedGradientEffect(); |
82 | } |
83 | void GrClampedGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
84 | GrProcessorKeyBuilder* b) const { |
85 | b->add32((int32_t)makePremul); |
86 | } |
87 | bool GrClampedGradientEffect::onIsEqual(const GrFragmentProcessor& other) const { |
88 | const GrClampedGradientEffect& that = other.cast<GrClampedGradientEffect>(); |
89 | (void)that; |
90 | if (leftBorderColor != that.leftBorderColor) return false; |
91 | if (rightBorderColor != that.rightBorderColor) return false; |
92 | if (makePremul != that.makePremul) return false; |
93 | if (colorsAreOpaque != that.colorsAreOpaque) return false; |
94 | return true; |
95 | } |
96 | GrClampedGradientEffect::GrClampedGradientEffect(const GrClampedGradientEffect& src) |
97 | : INHERITED(kGrClampedGradientEffect_ClassID, src.optimizationFlags()) |
98 | , colorizer_index(src.colorizer_index) |
99 | , gradLayout_index(src.gradLayout_index) |
100 | , leftBorderColor(src.leftBorderColor) |
101 | , rightBorderColor(src.rightBorderColor) |
102 | , makePremul(src.makePremul) |
103 | , colorsAreOpaque(src.colorsAreOpaque) { |
104 | { |
105 | auto clone = src.childProcessor(colorizer_index).clone(); |
106 | clone->setSampledWithExplicitCoords( |
107 | src.childProcessor(colorizer_index).isSampledWithExplicitCoords()); |
108 | this->registerChildProcessor(std::move(clone)); |
109 | } |
110 | { |
111 | auto clone = src.childProcessor(gradLayout_index).clone(); |
112 | clone->setSampledWithExplicitCoords( |
113 | src.childProcessor(gradLayout_index).isSampledWithExplicitCoords()); |
114 | this->registerChildProcessor(std::move(clone)); |
115 | } |
116 | } |
117 | std::unique_ptr<GrFragmentProcessor> GrClampedGradientEffect::clone() const { |
118 | return std::unique_ptr<GrFragmentProcessor>(new GrClampedGradientEffect(*this)); |
119 | } |
120 | |