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:
GrGLSLLinearGradientLayout()22 GrGLSLLinearGradientLayout() {}
emitCode(EmitArgs & args)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(return half4(half(%s.x) + 9.9999997473787516e-06, 1.0, 0.0, 0.0);
29 )SkSL",
30 args.fSampleCoord);
31 }
32
33 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)34 void onSetData(const GrGLSLProgramDataManager& pdman,
35 const GrFragmentProcessor& _proc) override {}
36 };
onMakeProgramImpl() const37 std::unique_ptr<GrGLSLFragmentProcessor> GrLinearGradientLayout::onMakeProgramImpl() const {
38 return std::make_unique<GrGLSLLinearGradientLayout>();
39 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const40 void GrLinearGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
41 GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const42 bool GrLinearGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
43 const GrLinearGradientLayout& that = other.cast<GrLinearGradientLayout>();
44 (void)that;
45 return true;
46 }
GrLinearGradientLayout(const GrLinearGradientLayout & src)47 GrLinearGradientLayout::GrLinearGradientLayout(const GrLinearGradientLayout& src)
48 : INHERITED(kGrLinearGradientLayout_ClassID, src.optimizationFlags()) {
49 this->cloneAndRegisterAllChildProcessors(src);
50 this->setUsesSampleCoordsDirectly();
51 }
clone() const52 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::clone() const {
53 return std::make_unique<GrLinearGradientLayout>(*this);
54 }
55 #if GR_TEST_UTILS
onDumpInfo() const56 SkString GrLinearGradientLayout::onDumpInfo() const { return SkString(); }
57 #endif
58 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradientLayout);
59 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * d)60 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::TestCreate(GrProcessorTestData* d) {
61 SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
62 SkPoint points[2];
63 points[0].fX = d->fRandom->nextRangeScalar(0.0f, scale);
64 points[0].fY = d->fRandom->nextRangeScalar(0.0f, scale);
65 points[1].fX = d->fRandom->nextRangeScalar(0.0f, scale);
66 points[1].fY = d->fRandom->nextRangeScalar(0.0f, scale);
67
68 GrGradientShader::RandomParams params(d->fRandom);
69 auto shader = params.fUseColors4f ? SkGradientShader::MakeLinear(points,
70 params.fColors4f,
71 params.fColorSpace,
72 params.fStops,
73 params.fColorCount,
74 params.fTileMode)
75 : SkGradientShader::MakeLinear(points,
76 params.fColors,
77 params.fStops,
78 params.fColorCount,
79 params.fTileMode);
80 GrTest::TestAsFPArgs asFPArgs(d);
81 std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
82 SkASSERT_RELEASE(fp);
83 return fp;
84 }
85 #endif
86
Make(const SkLinearGradient & grad,const GrFPArgs & args)87 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::Make(const SkLinearGradient& grad,
88 const GrFPArgs& args) {
89 SkMatrix matrix;
90 if (!grad.totalLocalMatrix(args.fPreLocalMatrix)->invert(&matrix)) {
91 return nullptr;
92 }
93 matrix.postConcat(grad.getGradientMatrix());
94 return GrMatrixEffect::Make(matrix,
95 std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout()));
96 }
97