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/core/SkUtils.h" |
14 | #include "src/gpu/GrTexture.h" |
15 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
16 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
17 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
18 | #include "src/sksl/SkSLCPP.h" |
19 | #include "src/sksl/SkSLUtil.h" |
20 | class GrGLSLClampedGradientEffect : public GrGLSLFragmentProcessor { |
21 | public: |
22 | GrGLSLClampedGradientEffect() {} |
23 | void emitCode(EmitArgs& args) override { |
24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
25 | const GrClampedGradientEffect& _outer = args.fFp.cast<GrClampedGradientEffect>(); |
26 | (void)_outer; |
27 | auto leftBorderColor = _outer.leftBorderColor; |
28 | (void)leftBorderColor; |
29 | auto rightBorderColor = _outer.rightBorderColor; |
30 | (void)rightBorderColor; |
31 | auto makePremul = _outer.makePremul; |
32 | (void)makePremul; |
33 | auto colorsAreOpaque = _outer.colorsAreOpaque; |
34 | (void)colorsAreOpaque; |
35 | leftBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
36 | kHalf4_GrSLType, "leftBorderColor" ); |
37 | rightBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
38 | kHalf4_GrSLType, "rightBorderColor" ); |
39 | SkString _sample1102 = this->invokeChild(1, args); |
40 | fragBuilder->codeAppendf( |
41 | R"SkSL(half4 t = %s; |
42 | if (!%s && t.y < 0.0) { |
43 | %s = half4(0.0); |
44 | } else if (t.x < 0.0) { |
45 | %s = %s; |
46 | } else if (t.x > 1.0) { |
47 | %s = %s; |
48 | } else {)SkSL" , |
49 | _sample1102.c_str(), |
50 | (_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false" ), |
51 | args.fOutputColor, args.fOutputColor, |
52 | args.fUniformHandler->getUniformCStr(leftBorderColorVar), args.fOutputColor, |
53 | args.fUniformHandler->getUniformCStr(rightBorderColorVar)); |
54 | SkString _coords1871("float2(half2(t.x, 0))" ); |
55 | SkString _sample1871 = this->invokeChild(0, args, _coords1871.c_str()); |
56 | fragBuilder->codeAppendf( |
57 | R"SkSL( |
58 | %s = %s; |
59 | } |
60 | @if (%s) { |
61 | %s.xyz *= %s.w; |
62 | } |
63 | )SkSL" , |
64 | args.fOutputColor, _sample1871.c_str(), (_outer.makePremul ? "true" : "false" ), |
65 | args.fOutputColor, args.fOutputColor); |
66 | } |
67 | |
68 | private: |
69 | void onSetData(const GrGLSLProgramDataManager& pdman, |
70 | const GrFragmentProcessor& _proc) override { |
71 | const GrClampedGradientEffect& _outer = _proc.cast<GrClampedGradientEffect>(); |
72 | { |
73 | const SkPMColor4f& leftBorderColorValue = _outer.leftBorderColor; |
74 | if (leftBorderColorPrev != leftBorderColorValue) { |
75 | leftBorderColorPrev = leftBorderColorValue; |
76 | pdman.set4fv(leftBorderColorVar, 1, leftBorderColorValue.vec()); |
77 | } |
78 | const SkPMColor4f& rightBorderColorValue = _outer.rightBorderColor; |
79 | if (rightBorderColorPrev != rightBorderColorValue) { |
80 | rightBorderColorPrev = rightBorderColorValue; |
81 | pdman.set4fv(rightBorderColorVar, 1, rightBorderColorValue.vec()); |
82 | } |
83 | } |
84 | } |
85 | SkPMColor4f leftBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}; |
86 | SkPMColor4f rightBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}; |
87 | UniformHandle leftBorderColorVar; |
88 | UniformHandle rightBorderColorVar; |
89 | }; |
90 | GrGLSLFragmentProcessor* GrClampedGradientEffect::onCreateGLSLInstance() const { |
91 | return new GrGLSLClampedGradientEffect(); |
92 | } |
93 | void GrClampedGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
94 | GrProcessorKeyBuilder* b) const { |
95 | b->add32((uint32_t)makePremul); |
96 | } |
97 | bool GrClampedGradientEffect::onIsEqual(const GrFragmentProcessor& other) const { |
98 | const GrClampedGradientEffect& that = other.cast<GrClampedGradientEffect>(); |
99 | (void)that; |
100 | if (leftBorderColor != that.leftBorderColor) return false; |
101 | if (rightBorderColor != that.rightBorderColor) return false; |
102 | if (makePremul != that.makePremul) return false; |
103 | if (colorsAreOpaque != that.colorsAreOpaque) return false; |
104 | return true; |
105 | } |
106 | GrClampedGradientEffect::GrClampedGradientEffect(const GrClampedGradientEffect& src) |
107 | : INHERITED(kGrClampedGradientEffect_ClassID, src.optimizationFlags()) |
108 | , leftBorderColor(src.leftBorderColor) |
109 | , rightBorderColor(src.rightBorderColor) |
110 | , makePremul(src.makePremul) |
111 | , colorsAreOpaque(src.colorsAreOpaque) { |
112 | this->cloneAndRegisterAllChildProcessors(src); |
113 | } |
114 | std::unique_ptr<GrFragmentProcessor> GrClampedGradientEffect::clone() const { |
115 | return std::make_unique<GrClampedGradientEffect>(*this); |
116 | } |
117 | #if GR_TEST_UTILS |
118 | SkString GrClampedGradientEffect::onDumpInfo() const { |
119 | return SkStringPrintf( |
120 | "(leftBorderColor=half4(%f, %f, %f, %f), rightBorderColor=half4(%f, %f, %f, %f), " |
121 | "makePremul=%s, colorsAreOpaque=%s)" , |
122 | leftBorderColor.fR, leftBorderColor.fG, leftBorderColor.fB, leftBorderColor.fA, |
123 | rightBorderColor.fR, rightBorderColor.fG, rightBorderColor.fB, rightBorderColor.fA, |
124 | (makePremul ? "true" : "false" ), (colorsAreOpaque ? "true" : "false" )); |
125 | } |
126 | #endif |
127 | |