• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(1, &_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 = (float(t_1) - 2.0 * "
36                 "floor(float(float(t_1) * 0.5))) - 1.0;\n        if "
37                 "(sk_Caps.mustDoOpBetweenFloorAndAbs) {\n            tiled_t = "
38                 "half(clamp(float(tiled_t), -1.0, 1.0));\n        }\n        t.x = "
39                 "half(abs(float(tiled_t)));\n    } else {\n        t.x = "
40                 "half(fract(float(t.x)));\n    }",
41                 _child1.c_str(),
42                 (_outer.childProcessor(1).preservesOpaqueInput() ? "true" : "false"),
43                 args.fOutputColor, (_outer.mirror() ? "true" : "false"));
44         SkString _input0("t");
45         SkString _child0("_child0");
46         this->emitChild(0, _input0.c_str(), &_child0, args);
47         fragBuilder->codeAppendf("\n    %s = %s;\n}\n@if (%s) {\n    %s.xyz *= %s.w;\n}\n",
48                                  args.fOutputColor, _child0.c_str(),
49                                  (_outer.makePremul() ? "true" : "false"), args.fOutputColor,
50                                  args.fOutputColor);
51     }
52 
53 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)54     void onSetData(const GrGLSLProgramDataManager& pdman,
55                    const GrFragmentProcessor& _proc) override {}
56 };
onCreateGLSLInstance() const57 GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
58     return new GrGLSLTiledGradientEffect();
59 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const60 void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
61                                                   GrProcessorKeyBuilder* b) const {
62     b->add32((int32_t)fMirror);
63     b->add32((int32_t)fMakePremul);
64 }
onIsEqual(const GrFragmentProcessor & other) const65 bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
66     const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
67     (void)that;
68     if (fMirror != that.fMirror) return false;
69     if (fMakePremul != that.fMakePremul) return false;
70     if (fColorsAreOpaque != that.fColorsAreOpaque) return false;
71     return true;
72 }
GrTiledGradientEffect(const GrTiledGradientEffect & src)73 GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
74         : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
75         , fMirror(src.fMirror)
76         , fMakePremul(src.fMakePremul)
77         , fColorsAreOpaque(src.fColorsAreOpaque) {
78     this->registerChildProcessor(src.childProcessor(0).clone());
79     this->registerChildProcessor(src.childProcessor(1).clone());
80 }
clone() const81 std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
82     return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this));
83 }
84