| 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 | |
| 13 | #include "src/core/SkUtils.h" |
| 14 | #include "src/gpu/GrTexture.h" |
| 15 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 16 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 17 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
| 18 | #include "src/sksl/SkSLCPP.h" |
| 19 | #include "src/sksl/SkSLUtil.h" |
| 20 | class GrGLSLBlurredEdgeFragmentProcessor : public GrGLSLFragmentProcessor { |
| 21 | public: |
| 22 | GrGLSLBlurredEdgeFragmentProcessor() {} |
| 23 | void emitCode(EmitArgs& args) override { |
| 24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 25 | const GrBlurredEdgeFragmentProcessor& _outer = |
| 26 | args.fFp.cast<GrBlurredEdgeFragmentProcessor>(); |
| 27 | (void)_outer; |
| 28 | auto mode = _outer.mode; |
| 29 | (void)mode; |
| 30 | SkString _sample308 = this->invokeChild(0, args); |
| 31 | fragBuilder->codeAppendf( |
| 32 | R"SkSL(half inputAlpha = %s.w; |
| 33 | half factor = 1.0 - inputAlpha; |
| 34 | @switch (%d) { |
| 35 | case 0: |
| 36 | factor = exp((-factor * factor) * 4.0) - 0.017999999225139618; |
| 37 | break; |
| 38 | case 1: |
| 39 | factor = smoothstep(1.0, 0.0, factor); |
| 40 | break; |
| 41 | } |
| 42 | %s = half4(factor); |
| 43 | )SkSL" , |
| 44 | _sample308.c_str(), (int)_outer.mode, args.fOutputColor); |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 49 | const GrFragmentProcessor& _proc) override {} |
| 50 | }; |
| 51 | GrGLSLFragmentProcessor* GrBlurredEdgeFragmentProcessor::onCreateGLSLInstance() const { |
| 52 | return new GrGLSLBlurredEdgeFragmentProcessor(); |
| 53 | } |
| 54 | void GrBlurredEdgeFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 55 | GrProcessorKeyBuilder* b) const { |
| 56 | b->add32((uint32_t)mode); |
| 57 | } |
| 58 | bool GrBlurredEdgeFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { |
| 59 | const GrBlurredEdgeFragmentProcessor& that = other.cast<GrBlurredEdgeFragmentProcessor>(); |
| 60 | (void)that; |
| 61 | if (mode != that.mode) return false; |
| 62 | return true; |
| 63 | } |
| 64 | GrBlurredEdgeFragmentProcessor::GrBlurredEdgeFragmentProcessor( |
| 65 | const GrBlurredEdgeFragmentProcessor& src) |
| 66 | : INHERITED(kGrBlurredEdgeFragmentProcessor_ClassID, src.optimizationFlags()) |
| 67 | , mode(src.mode) { |
| 68 | this->cloneAndRegisterAllChildProcessors(src); |
| 69 | } |
| 70 | std::unique_ptr<GrFragmentProcessor> GrBlurredEdgeFragmentProcessor::clone() const { |
| 71 | return std::make_unique<GrBlurredEdgeFragmentProcessor>(*this); |
| 72 | } |
| 73 | #if GR_TEST_UTILS |
| 74 | SkString GrBlurredEdgeFragmentProcessor::onDumpInfo() const { |
| 75 | return SkStringPrintf("(mode=%d)" , (int)mode); |
| 76 | } |
| 77 | #endif |
| 78 | |