| 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/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 GrGLSLRadialGradientLayout : public GrGLSLFragmentProcessor { | 
|---|
| 20 | public: | 
|---|
| 21 | GrGLSLRadialGradientLayout() {} | 
|---|
| 22 | void emitCode(EmitArgs& args) override { | 
|---|
| 23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 
|---|
| 24 | const GrRadialGradientLayout& _outer = args.fFp.cast<GrRadialGradientLayout>(); | 
|---|
| 25 | (void)_outer; | 
|---|
| 26 | auto gradientMatrix = _outer.gradientMatrix; | 
|---|
| 27 | (void)gradientMatrix; | 
|---|
| 28 | SkString sk_TransformedCoords2D_0 = | 
|---|
| 29 | fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); | 
|---|
| 30 | fragBuilder->codeAppendf( "half t = half(length(%s));\n%s = half4(t, 1.0, 0.0, 0.0);\n", | 
|---|
| 31 | sk_TransformedCoords2D_0.c_str(), 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 | if (gradientMatrix != that.gradientMatrix) return false; | 
|---|
| 47 | return true; | 
|---|
| 48 | } | 
|---|
| 49 | GrRadialGradientLayout::GrRadialGradientLayout(const GrRadialGradientLayout& src) | 
|---|
| 50 | : INHERITED(kGrRadialGradientLayout_ClassID, src.optimizationFlags()) | 
|---|
| 51 | , fCoordTransform0(src.fCoordTransform0) | 
|---|
| 52 | , gradientMatrix(src.gradientMatrix) { | 
|---|
| 53 | this->addCoordTransform(&fCoordTransform0); | 
|---|
| 54 | } | 
|---|
| 55 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::clone() const { | 
|---|
| 56 | return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(*this)); | 
|---|
| 57 | } | 
|---|
| 58 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradientLayout); | 
|---|
| 59 | #if GR_TEST_UTILS | 
|---|
| 60 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::TestCreate(GrProcessorTestData* d) { | 
|---|
| 61 | SkScalar scale = GrGradientShader::RandomParams::kGradientScale; | 
|---|
| 62 | std::unique_ptr<GrFragmentProcessor> fp; | 
|---|
| 63 | GrTest::TestAsFPArgs asFPArgs(d); | 
|---|
| 64 | do { | 
|---|
| 65 | GrGradientShader::RandomParams params(d->fRandom); | 
|---|
| 66 | SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale), | 
|---|
| 67 | d->fRandom->nextRangeScalar(0.0f, scale)}; | 
|---|
| 68 | SkScalar radius = d->fRandom->nextRangeScalar(0.0f, scale); | 
|---|
| 69 | sk_sp<SkShader> shader = | 
|---|
| 70 | params.fUseColors4f | 
|---|
| 71 | ? SkGradientShader::MakeRadial(center, radius, params.fColors4f, | 
|---|
| 72 | params.fColorSpace, params.fStops, | 
|---|
| 73 | params.fColorCount, params.fTileMode) | 
|---|
| 74 | : SkGradientShader::MakeRadial(center, radius, params.fColors, | 
|---|
| 75 | params.fStops, params.fColorCount, | 
|---|
| 76 | params.fTileMode); | 
|---|
| 77 | // Degenerate params can create an Empty (non-null) shader, where fp will be nullptr | 
|---|
| 78 | fp = shader ? as_SB(shader)->asFragmentProcessor(asFPArgs.args()) : nullptr; | 
|---|
| 79 | } while (!fp); | 
|---|
| 80 | return fp; | 
|---|
| 81 | } | 
|---|
| 82 | #endif | 
|---|
| 83 |  | 
|---|
| 84 | std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::Make(const SkRadialGradient& grad, | 
|---|
| 85 | const GrFPArgs& args) { | 
|---|
| 86 | SkMatrix matrix; | 
|---|
| 87 | if (!grad.totalLocalMatrix(args.fPreLocalMatrix)->invert(&matrix)) { | 
|---|
| 88 | return nullptr; | 
|---|
| 89 | } | 
|---|
| 90 | matrix.postConcat(grad.getGradientMatrix()); | 
|---|
| 91 | return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(matrix)); | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|