• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
GrGLSLLinearGradientLayout()20     GrGLSLLinearGradientLayout() {}
emitCode(EmitArgs & args)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]);
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);
30     }
31 
32 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)33     void onSetData(const GrGLSLProgramDataManager& pdman,
34                    const GrFragmentProcessor& _proc) override {}
35 };
onCreateGLSLInstance() const36 GrGLSLFragmentProcessor* GrLinearGradientLayout::onCreateGLSLInstance() const {
37     return new GrGLSLLinearGradientLayout();
38 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const39 void GrLinearGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
40                                                    GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const41 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 }
GrLinearGradientLayout(const GrLinearGradientLayout & src)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 }
clone() const53 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::clone() const {
54     return std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout(*this));
55 }
56 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradientLayout);
57 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * d)58 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::TestCreate(GrProcessorTestData* d) {
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)}};
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
77 
Make(const SkLinearGradient & grad,const GrFPArgs & args)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 }
87