Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 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 | #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 GrGLSLRadialGradientLayout : public GrGLSLFragmentProcessor { |
| 19 | public: |
| 20 | GrGLSLRadialGradientLayout() {} |
| 21 | void emitCode(EmitArgs& args) override { |
| 22 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 23 | const GrRadialGradientLayout& _outer = args.fFp.cast<GrRadialGradientLayout>(); |
| 24 | (void)_outer; |
| 25 | auto gradientMatrix = _outer.gradientMatrix(); |
| 26 | (void)gradientMatrix; |
| 27 | SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 28 | fragBuilder->codeAppendf("half t = half(length(%s));\n%s = half4(t, 1.0, 0.0, 0.0);\n", |
| 29 | sk_TransformedCoords2D_0.c_str(), args.fOutputColor); |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | private: |
| 33 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 34 | const GrFragmentProcessor& _proc) override {} |
| 35 | }; |
| 36 | GrGLSLFragmentProcessor* GrRadialGradientLayout::onCreateGLSLInstance() const { |
| 37 | return new GrGLSLRadialGradientLayout(); |
| 38 | } |
| 39 | void GrRadialGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 40 | GrProcessorKeyBuilder* b) const {} |
| 41 | bool GrRadialGradientLayout::onIsEqual(const GrFragmentProcessor& other) const { |
| 42 | const GrRadialGradientLayout& that = other.cast<GrRadialGradientLayout>(); |
| 43 | (void)that; |
| 44 | if (fGradientMatrix != that.fGradientMatrix) return false; |
| 45 | return true; |
| 46 | } |
| 47 | GrRadialGradientLayout::GrRadialGradientLayout(const GrRadialGradientLayout& src) |
| 48 | : INHERITED(kGrRadialGradientLayout_ClassID, src.optimizationFlags()) |
| 49 | , fGradientMatrix(src.fGradientMatrix) |
| 50 | , fCoordTransform0(src.fCoordTransform0) { |
| 51 | this->addCoordTransform(&fCoordTransform0); |
| 52 | } |
| 53 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::clone() const { |
| 54 | return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(*this)); |
| 55 | } |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame^] | 56 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradientLayout); |
| 57 | #if GR_TEST_UTILS |
| 58 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::TestCreate(GrProcessorTestData* d) { |
| 59 | sk_sp<SkShader> shader; |
| 60 | do { |
| 61 | GrGradientShader::RandomParams params(d->fRandom); |
| 62 | SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
| 63 | SkScalar radius = d->fRandom->nextUScalar1(); |
| 64 | shader = params.fUseColors4f |
| 65 | ? SkGradientShader::MakeRadial(center, radius, params.fColors4f, |
| 66 | params.fColorSpace, params.fStops, |
| 67 | params.fColorCount, params.fTileMode) |
| 68 | : SkGradientShader::MakeRadial(center, radius, params.fColors, |
| 69 | params.fStops, params.fColorCount, |
| 70 | params.fTileMode); |
| 71 | } while (!shader); |
| 72 | GrTest::TestAsFPArgs asFPArgs(d); |
| 73 | std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args()); |
| 74 | GrAlwaysAssert(fp); |
| 75 | return fp; |
| 76 | } |
| 77 | #endif |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 78 | |
| 79 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::Make(const SkRadialGradient& grad, |
| 80 | const GrFPArgs& args) { |
| 81 | SkMatrix matrix; |
| 82 | if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) { |
| 83 | return nullptr; |
| 84 | } |
| 85 | matrix.postConcat(grad.getGradientMatrix()); |
| 86 | return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(matrix)); |
| 87 | } |