1 /* 2 * Copyright 2017 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 GrBlurredEdgeFragmentProcessor.fp; do not modify. 10 **************************************************************************************************/ 11 #include "GrBlurredEdgeFragmentProcessor.h" 12 #if SK_SUPPORT_GPU 13 #include "glsl/GrGLSLFragmentProcessor.h" 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" 15 #include "glsl/GrGLSLProgramBuilder.h" 16 #include "GrTexture.h" 17 #include "SkSLCPP.h" 18 #include "SkSLUtil.h" 19 class GrGLSLBlurredEdgeFragmentProcessor : public GrGLSLFragmentProcessor { 20 public: 21 GrGLSLBlurredEdgeFragmentProcessor() {} 22 void emitCode(EmitArgs& args) override { 23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 24 const GrBlurredEdgeFragmentProcessor& _outer = 25 args.fFp.cast<GrBlurredEdgeFragmentProcessor>(); 26 (void)_outer; 27 auto mode = _outer.mode(); 28 (void)mode; 29 fragBuilder->codeAppendf( 30 "half factor = half(1.0 - float(%s.w));\n@switch (%d) {\n case 0:\n " 31 "factor = half(exp(float(float(-factor * factor) * 4.0)) - " 32 "0.017999999999999999);\n break;\n case 1:\n factor = " 33 "half(smoothstep(1.0, 0.0, float(factor)));\n break;\n}\n%s = " 34 "half4(factor);\n", 35 args.fInputColor ? args.fInputColor : "half4(1)", (int)_outer.mode(), 36 args.fOutputColor); 37 } 38 39 private: 40 void onSetData(const GrGLSLProgramDataManager& pdman, 41 const GrFragmentProcessor& _proc) override {} 42 }; 43 GrGLSLFragmentProcessor* GrBlurredEdgeFragmentProcessor::onCreateGLSLInstance() const { 44 return new GrGLSLBlurredEdgeFragmentProcessor(); 45 } 46 void GrBlurredEdgeFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, 47 GrProcessorKeyBuilder* b) const { 48 b->add32((int32_t)fMode); 49 } 50 bool GrBlurredEdgeFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { 51 const GrBlurredEdgeFragmentProcessor& that = other.cast<GrBlurredEdgeFragmentProcessor>(); 52 (void)that; 53 if (fMode != that.fMode) return false; 54 return true; 55 } 56 GrBlurredEdgeFragmentProcessor::GrBlurredEdgeFragmentProcessor( 57 const GrBlurredEdgeFragmentProcessor& src) 58 : INHERITED(kGrBlurredEdgeFragmentProcessor_ClassID, src.optimizationFlags()) 59 , fMode(src.fMode) {} 60 std::unique_ptr<GrFragmentProcessor> GrBlurredEdgeFragmentProcessor::clone() const { 61 return std::unique_ptr<GrFragmentProcessor>(new GrBlurredEdgeFragmentProcessor(*this)); 62 } 63 #endif 64