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