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/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 GrGLSLLinearGradientLayout : public GrGLSLFragmentProcessor { |
21 | public: |
22 | GrGLSLLinearGradientLayout() {} |
23 | void emitCode(EmitArgs& args) override { |
24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
25 | const GrLinearGradientLayout& _outer = args.fFp.cast<GrLinearGradientLayout>(); |
26 | (void)_outer; |
27 | fragBuilder->codeAppendf( |
28 | R"SkSL(half t = half(%s.x) + 9.9999997473787516e-06; |
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* GrLinearGradientLayout::onCreateGLSLInstance() const { |
39 | return new GrGLSLLinearGradientLayout(); |
40 | } |
41 | void GrLinearGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
42 | GrProcessorKeyBuilder* b) const {} |
43 | bool GrLinearGradientLayout::onIsEqual(const GrFragmentProcessor& other) const { |
44 | const GrLinearGradientLayout& that = other.cast<GrLinearGradientLayout>(); |
45 | (void)that; |
46 | return true; |
47 | } |
48 | GrLinearGradientLayout::GrLinearGradientLayout(const GrLinearGradientLayout& src) |
49 | : INHERITED(kGrLinearGradientLayout_ClassID, src.optimizationFlags()) { |
50 | this->cloneAndRegisterAllChildProcessors(src); |
51 | this->setUsesSampleCoordsDirectly(); |
52 | } |
53 | std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::clone() const { |
54 | return std::make_unique<GrLinearGradientLayout>(*this); |
55 | } |
56 | #if GR_TEST_UTILS |
57 | SkString GrLinearGradientLayout::onDumpInfo() const { return SkString(); } |
58 | #endif |
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 GrMatrixEffect::Make(matrix, |
89 | std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout())); |
90 | } |
91 | |