Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -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 GrLinearGradientLayout.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrLinearGradientLayout.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 GrGLSLLinearGradientLayout : public GrGLSLFragmentProcessor { |
| 19 | public: |
| 20 | GrGLSLLinearGradientLayout() {} |
| 21 | void emitCode(EmitArgs& args) override { |
| 22 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 23 | const GrLinearGradientLayout& _outer = args.fFp.cast<GrLinearGradientLayout>(); |
| 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(%s.x);\n%s = half4(t, 1.0, 0.0, 0.0);\n", |
| 29 | sk_TransformedCoords2D_0.c_str(), args.fOutputColor); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | private: |
| 33 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 34 | const GrFragmentProcessor& _proc) override {} |
| 35 | }; |
| 36 | GrGLSLFragmentProcessor* GrLinearGradientLayout::onCreateGLSLInstance() const { |
| 37 | return new GrGLSLLinearGradientLayout(); |
| 38 | } |
| 39 | void GrLinearGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 40 | GrProcessorKeyBuilder* b) const {} |
| 41 | bool GrLinearGradientLayout::onIsEqual(const GrFragmentProcessor& other) const { |
| 42 | const GrLinearGradientLayout& that = other.cast<GrLinearGradientLayout>(); |
| 43 | (void)that; |
| 44 | if (fGradientMatrix != that.fGradientMatrix) return false; |
| 45 | return true; |
| 46 | } |
| 47 | GrLinearGradientLayout::GrLinearGradientLayout(const GrLinearGradientLayout& src) |
| 48 | : INHERITED(kGrLinearGradientLayout_ClassID, src.optimizationFlags()) |
| 49 | , fGradientMatrix(src.fGradientMatrix) |
| 50 | , fCoordTransform0(src.fCoordTransform0) { |
| 51 | this->addCoordTransform(&fCoordTransform0); |
| 52 | } |
| 53 | std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::clone() const { |
| 54 | return std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout(*this)); |
| 55 | } |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 56 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradientLayout); |
| 57 | #if GR_TEST_UTILS |
| 58 | std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::TestCreate(GrProcessorTestData* d) { |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 59 | SkScalar scale = GrGradientShader::RandomParams::kGradientScale; |
| 60 | SkPoint points[] = { |
| 61 | {d->fRandom->nextRangeScalar(0.0f, scale), d->fRandom->nextRangeScalar(0.0f, scale)}, |
| 62 | {d->fRandom->nextRangeScalar(0.0f, scale), d->fRandom->nextRangeScalar(0.0f, scale)}}; |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 63 | |
| 64 | GrGradientShader::RandomParams params(d->fRandom); |
| 65 | auto shader = params.fUseColors4f |
| 66 | ? SkGradientShader::MakeLinear(points, params.fColors4f, |
| 67 | params.fColorSpace, params.fStops, |
| 68 | params.fColorCount, params.fTileMode) |
| 69 | : SkGradientShader::MakeLinear(points, params.fColors, params.fStops, |
| 70 | params.fColorCount, params.fTileMode); |
| 71 | GrTest::TestAsFPArgs asFPArgs(d); |
| 72 | std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args()); |
| 73 | GrAlwaysAssert(fp); |
| 74 | return fp; |
| 75 | } |
| 76 | #endif |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 77 | |
| 78 | std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::Make(const SkLinearGradient& grad, |
| 79 | const GrFPArgs& args) { |
| 80 | SkMatrix matrix; |
| 81 | if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) { |
| 82 | return nullptr; |
| 83 | } |
| 84 | matrix.postConcat(grad.getGradientMatrix()); |
| 85 | return std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout(matrix)); |
| 86 | } |