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 #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 GrGLSLClampedGradientEffect : public GrGLSLFragmentProcessor {
19 public:
GrGLSLClampedGradientEffect()20 GrGLSLClampedGradientEffect() {}
emitCode(EmitArgs & args)21 void emitCode(EmitArgs& args) override {
22 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23 const GrClampedGradientEffect& _outer = args.fFp.cast<GrClampedGradientEffect>();
24 (void)_outer;
25 auto leftBorderColor = _outer.leftBorderColor();
26 (void)leftBorderColor;
27 auto rightBorderColor = _outer.rightBorderColor();
28 (void)rightBorderColor;
29 auto makePremul = _outer.makePremul();
30 (void)makePremul;
31 auto colorsAreOpaque = _outer.colorsAreOpaque();
32 (void)colorsAreOpaque;
33 fLeftBorderColorVar = args.fUniformHandler->addUniform(
34 kFragment_GrShaderFlag, kHalf4_GrSLType, kDefault_GrSLPrecision, "leftBorderColor");
35 fRightBorderColorVar =
36 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
37 kDefault_GrSLPrecision, "rightBorderColor");
38 SkString _child1("_child1");
39 this->emitChild(1, &_child1, 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 (float(t.x) > 1.0) {\n %s = %s;\n} else {",
43 _child1.c_str(),
44 (_outer.childProcessor(1).preservesOpaqueInput() ? "true" : "false"),
45 args.fOutputColor, args.fOutputColor,
46 args.fUniformHandler->getUniformCStr(fLeftBorderColorVar), args.fOutputColor,
47 args.fUniformHandler->getUniformCStr(fRightBorderColorVar));
48 SkString _input0("t");
49 SkString _child0("_child0");
50 this->emitChild(0, _input0.c_str(), &_child0, args);
51 fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n",
52 args.fOutputColor, _child0.c_str(),
53 (_outer.makePremul() ? "true" : "false"), args.fOutputColor,
54 args.fOutputColor);
55 }
56
57 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)58 void onSetData(const GrGLSLProgramDataManager& pdman,
59 const GrFragmentProcessor& _proc) override {
60 const GrClampedGradientEffect& _outer = _proc.cast<GrClampedGradientEffect>();
61 {
62 const SkPMColor4f& leftBorderColorValue = _outer.leftBorderColor();
63 if (fLeftBorderColorPrev != leftBorderColorValue) {
64 fLeftBorderColorPrev = leftBorderColorValue;
65 pdman.set4fv(fLeftBorderColorVar, 1, leftBorderColorValue.vec());
66 }
67 const SkPMColor4f& rightBorderColorValue = _outer.rightBorderColor();
68 if (fRightBorderColorPrev != rightBorderColorValue) {
69 fRightBorderColorPrev = rightBorderColorValue;
70 pdman.set4fv(fRightBorderColorVar, 1, rightBorderColorValue.vec());
71 }
72 }
73 }
74 SkPMColor4f fLeftBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
75 SkPMColor4f fRightBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
76 UniformHandle fLeftBorderColorVar;
77 UniformHandle fRightBorderColorVar;
78 };
onCreateGLSLInstance() const79 GrGLSLFragmentProcessor* GrClampedGradientEffect::onCreateGLSLInstance() const {
80 return new GrGLSLClampedGradientEffect();
81 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const82 void GrClampedGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
83 GrProcessorKeyBuilder* b) const {
84 b->add32((int32_t)fMakePremul);
85 }
onIsEqual(const GrFragmentProcessor & other) const86 bool GrClampedGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
87 const GrClampedGradientEffect& that = other.cast<GrClampedGradientEffect>();
88 (void)that;
89 if (fLeftBorderColor != that.fLeftBorderColor) return false;
90 if (fRightBorderColor != that.fRightBorderColor) return false;
91 if (fMakePremul != that.fMakePremul) return false;
92 if (fColorsAreOpaque != that.fColorsAreOpaque) return false;
93 return true;
94 }
GrClampedGradientEffect(const GrClampedGradientEffect & src)95 GrClampedGradientEffect::GrClampedGradientEffect(const GrClampedGradientEffect& src)
96 : INHERITED(kGrClampedGradientEffect_ClassID, src.optimizationFlags())
97 , fLeftBorderColor(src.fLeftBorderColor)
98 , fRightBorderColor(src.fRightBorderColor)
99 , fMakePremul(src.fMakePremul)
100 , fColorsAreOpaque(src.fColorsAreOpaque) {
101 this->registerChildProcessor(src.childProcessor(0).clone());
102 this->registerChildProcessor(src.childProcessor(1).clone());
103 }
clone() const104 std::unique_ptr<GrFragmentProcessor> GrClampedGradientEffect::clone() const {
105 return std::unique_ptr<GrFragmentProcessor>(new GrClampedGradientEffect(*this));
106 }
107