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 13 #include "include/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 GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor { 20 public: GrGLSLTiledGradientEffect()21 GrGLSLTiledGradientEffect() {} emitCode(EmitArgs & args)22 void emitCode(EmitArgs& args) override { 23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 24 const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>(); 25 (void)_outer; 26 auto mirror = _outer.mirror; 27 (void)mirror; 28 auto makePremul = _outer.makePremul; 29 (void)makePremul; 30 auto colorsAreOpaque = _outer.colorsAreOpaque; 31 (void)colorsAreOpaque; 32 SkString _sample453("_sample453"); 33 this->invokeChild(_outer.gradLayout_index, &_sample453, args); 34 fragBuilder->codeAppendf( 35 "half4 t = %s;\nif (!%s && t.y < 0.0) {\n %s = half4(0.0);\n} else {\n @if " 36 "(%s) {\n half t_1 = t.x - 1.0;\n half tiled_t = (t_1 - 2.0 * " 37 "floor(t_1 * 0.5)) - 1.0;\n if (sk_Caps.mustDoOpBetweenFloorAndAbs) {\n " 38 " tiled_t = clamp(tiled_t, -1.0, 1.0);\n }\n t.x = " 39 "abs(tiled_t);\n } else {\n t.x = fract(t.x);\n }", 40 _sample453.c_str(), 41 (_outer.childProcessor(_outer.gradLayout_index).preservesOpaqueInput() ? "true" 42 : "false"), 43 args.fOutputColor, (_outer.mirror ? "true" : "false")); 44 SkString _input0("t"); 45 SkString _sample1464("_sample1464"); 46 this->invokeChild(_outer.colorizer_index, _input0.c_str(), &_sample1464, args); 47 fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n", 48 args.fOutputColor, _sample1464.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)mirror); 63 b->add32((int32_t)makePremul); 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 (mirror != that.mirror) return false; 69 if (makePremul != that.makePremul) return false; 70 if (colorsAreOpaque != that.colorsAreOpaque) return false; 71 return true; 72 } GrTiledGradientEffect(const GrTiledGradientEffect & src)73 GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src) 74 : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags()) 75 , colorizer_index(src.colorizer_index) 76 , gradLayout_index(src.gradLayout_index) 77 , mirror(src.mirror) 78 , makePremul(src.makePremul) 79 , colorsAreOpaque(src.colorsAreOpaque) { 80 this->registerChildProcessor(src.childProcessor(colorizer_index).clone()); 81 this->registerChildProcessor(src.childProcessor(gradLayout_index).clone()); 82 } clone() const83 std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const { 84 return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this)); 85 } 86