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