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(
29 "half t = half(%s.x) + 1.0000000000000001e-05;\n%s = half4(t, 1.0, 0.0, 0.0);\n",
30 sk_TransformedCoords2D_0.c_str(),
31 args.fOutputColor);
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 if (fGradientMatrix != that.fGradientMatrix) return false;
47 return true;
48 }
GrLinearGradientLayout(const GrLinearGradientLayout & src)49 GrLinearGradientLayout::GrLinearGradientLayout(const GrLinearGradientLayout& src)
50 : INHERITED(kGrLinearGradientLayout_ClassID, src.optimizationFlags())
51 , fGradientMatrix(src.fGradientMatrix)
52 , fCoordTransform0(src.fCoordTransform0) {
53 this->addCoordTransform(&fCoordTransform0);
54 }
clone() const55 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::clone() const {
56 return std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout(*this));
57 }
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[] = {
63 {d->fRandom->nextRangeScalar(0.0f, scale), d->fRandom->nextRangeScalar(0.0f, scale)},
64 {d->fRandom->nextRangeScalar(0.0f, scale), d->fRandom->nextRangeScalar(0.0f, scale)}};
65
66 GrGradientShader::RandomParams params(d->fRandom);
67 auto shader = params.fUseColors4f
68 ? SkGradientShader::MakeLinear(points, params.fColors4f,
69 params.fColorSpace, params.fStops,
70 params.fColorCount, params.fTileMode)
71 : SkGradientShader::MakeLinear(points, params.fColors, params.fStops,
72 params.fColorCount, params.fTileMode);
73 GrTest::TestAsFPArgs asFPArgs(d);
74 std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
75 GrAlwaysAssert(fp);
76 return fp;
77 }
78 #endif
79
Make(const SkLinearGradient & grad,const GrFPArgs & args)80 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::Make(const SkLinearGradient& grad,
81 const GrFPArgs& args) {
82 SkMatrix matrix;
83 if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) {
84 return nullptr;
85 }
86 matrix.postConcat(grad.getGradientMatrix());
87 return std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout(matrix));
88 }
89