| 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 GrRadialGradientLayout.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrRadialGradientLayout.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 GrGLSLRadialGradientLayout : public GrGLSLFragmentProcessor { |
| 21 | public: |
| 22 | GrGLSLRadialGradientLayout() {} |
| 23 | void emitCode(EmitArgs& args) override { |
| 24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 25 | const GrRadialGradientLayout& _outer = args.fFp.cast<GrRadialGradientLayout>(); |
| 26 | (void)_outer; |
| 27 | fragBuilder->codeAppendf( |
| 28 | R"SkSL(half t = half(length(%s)); |
| 29 | %s = half4(t, 1.0, 0.0, 0.0); |
| 30 | )SkSL" , |
| 31 | args.fSampleCoord, args.fOutputColor); |
| 32 | } |
| 33 | |
| 34 | private: |
| 35 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 36 | const GrFragmentProcessor& _proc) override {} |
| 37 | }; |
| 38 | GrGLSLFragmentProcessor* GrRadialGradientLayout::onCreateGLSLInstance() const { |
| 39 | return new GrGLSLRadialGradientLayout(); |
| 40 | } |
| 41 | void GrRadialGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 42 | GrProcessorKeyBuilder* b) const {} |
| 43 | bool GrRadialGradientLayout::onIsEqual(const GrFragmentProcessor& other) const { |
| 44 | const GrRadialGradientLayout& that = other.cast<GrRadialGradientLayout>(); |
| 45 | (void)that; |
| 46 | return true; |
| 47 | } |
| 48 | GrRadialGradientLayout::GrRadialGradientLayout(const GrRadialGradientLayout& src) |
| 49 | : INHERITED(kGrRadialGradientLayout_ClassID, src.optimizationFlags()) { |
| 50 | this->cloneAndRegisterAllChildProcessors(src); |
| 51 | this->setUsesSampleCoordsDirectly(); |
| 52 | } |
| 53 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::clone() const { |
| 54 | return std::make_unique<GrRadialGradientLayout>(*this); |
| 55 | } |
| 56 | #if GR_TEST_UTILS |
| 57 | SkString GrRadialGradientLayout::onDumpInfo() const { return SkString(); } |
| 58 | #endif |
| 59 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradientLayout); |
| 60 | #if GR_TEST_UTILS |
| 61 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::TestCreate(GrProcessorTestData* d) { |
| 62 | SkScalar scale = GrGradientShader::RandomParams::kGradientScale; |
| 63 | std::unique_ptr<GrFragmentProcessor> fp; |
| 64 | GrTest::TestAsFPArgs asFPArgs(d); |
| 65 | do { |
| 66 | GrGradientShader::RandomParams params(d->fRandom); |
| 67 | SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale), |
| 68 | d->fRandom->nextRangeScalar(0.0f, scale)}; |
| 69 | SkScalar radius = d->fRandom->nextRangeScalar(0.0f, scale); |
| 70 | sk_sp<SkShader> shader = |
| 71 | params.fUseColors4f |
| 72 | ? SkGradientShader::MakeRadial(center, radius, params.fColors4f, |
| 73 | params.fColorSpace, params.fStops, |
| 74 | params.fColorCount, params.fTileMode) |
| 75 | : SkGradientShader::MakeRadial(center, radius, params.fColors, |
| 76 | params.fStops, params.fColorCount, |
| 77 | params.fTileMode); |
| 78 | // Degenerate params can create an Empty (non-null) shader, where fp will be nullptr |
| 79 | fp = shader ? as_SB(shader)->asFragmentProcessor(asFPArgs.args()) : nullptr; |
| 80 | } while (!fp); |
| 81 | return fp; |
| 82 | } |
| 83 | #endif |
| 84 | |
| 85 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::Make(const SkRadialGradient& grad, |
| 86 | const GrFPArgs& args) { |
| 87 | SkMatrix matrix; |
| 88 | if (!grad.totalLocalMatrix(args.fPreLocalMatrix)->invert(&matrix)) { |
| 89 | return nullptr; |
| 90 | } |
| 91 | matrix.postConcat(grad.getGradientMatrix()); |
| 92 | return GrMatrixEffect::Make(matrix, |
| 93 | std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout())); |
| 94 | } |
| 95 | |