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 GrTiledGradientEffect.fp; do not modify.
10  **************************************************************************************************/
11 #include "GrTiledGradientEffect.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 GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
19 public:
GrGLSLTiledGradientEffect()20     GrGLSLTiledGradientEffect() {}
emitCode(EmitArgs & args)21     void emitCode(EmitArgs& args) override {
22         GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23         const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
24         (void)_outer;
25         auto mirror = _outer.mirror();
26         (void)mirror;
27         auto makePremul = _outer.makePremul();
28         (void)makePremul;
29         auto colorsAreOpaque = _outer.colorsAreOpaque();
30         (void)colorsAreOpaque;
31         SkString _child1("_child1");
32         this->emitChild(_outer.gradLayout_index(), &_child1, args);
33         fragBuilder->codeAppendf(
34                 "half4 t = %s;\nif (!%s && t.y < 0.0) {\n    %s = half4(0.0);\n} else {\n    @if "
35                 "(%s) {\n        half t_1 = t.x - 1.0;\n        half tiled_t = (t_1 - 2.0 * "
36                 "floor(t_1 * 0.5)) - 1.0;\n        if (sk_Caps.mustDoOpBetweenFloorAndAbs) {\n     "
37                 "       tiled_t = clamp(tiled_t, -1.0, 1.0);\n        }\n        t.x = "
38                 "abs(tiled_t);\n    } else {\n        t.x = fract(t.x);\n    }",
39                 _child1.c_str(),
40                 (_outer.childProcessor(_outer.gradLayout_index()).preservesOpaqueInput() ? "true"
41                                                                                          : "false"),
42                 args.fOutputColor, (_outer.mirror() ? "true" : "false"));
43         SkString _input0("t");
44         SkString _child0("_child0");
45         this->emitChild(_outer.colorizer_index(), _input0.c_str(), &_child0, args);
46         fragBuilder->codeAppendf("\n    %s = %s;\n}\n@if (%s) {\n    %s.xyz *= %s.w;\n}\n",
47                                  args.fOutputColor, _child0.c_str(),
48                                  (_outer.makePremul() ? "true" : "false"), args.fOutputColor,
49                                  args.fOutputColor);
50     }
51 
52 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)53     void onSetData(const GrGLSLProgramDataManager& pdman,
54                    const GrFragmentProcessor& _proc) override {}
55 };
onCreateGLSLInstance() const56 GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
57     return new GrGLSLTiledGradientEffect();
58 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const59 void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
60                                                   GrProcessorKeyBuilder* b) const {
61     b->add32((int32_t)fMirror);
62     b->add32((int32_t)fMakePremul);
63 }
onIsEqual(const GrFragmentProcessor & other) const64 bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
65     const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
66     (void)that;
67     if (fMirror != that.fMirror) return false;
68     if (fMakePremul != that.fMakePremul) return false;
69     if (fColorsAreOpaque != that.fColorsAreOpaque) return false;
70     return true;
71 }
GrTiledGradientEffect(const GrTiledGradientEffect & src)72 GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
73         : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
74         , fColorizer_index(src.fColorizer_index)
75         , fGradLayout_index(src.fGradLayout_index)
76         , fMirror(src.fMirror)
77         , fMakePremul(src.fMakePremul)
78         , fColorsAreOpaque(src.fColorsAreOpaque) {
79     this->registerChildProcessor(src.childProcessor(fColorizer_index).clone());
80     this->registerChildProcessor(src.childProcessor(fGradLayout_index).clone());
81 }
clone() const82 std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
83     return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this));
84 }
85