• 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 GrRadialGradientLayout.fp; do not modify.
10  **************************************************************************************************/
11 #include "GrRadialGradientLayout.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 GrGLSLRadialGradientLayout : public GrGLSLFragmentProcessor {
19 public:
GrGLSLRadialGradientLayout()20     GrGLSLRadialGradientLayout() {}
emitCode(EmitArgs & args)21     void emitCode(EmitArgs& args) override {
22         GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23         const GrRadialGradientLayout& _outer = args.fFp.cast<GrRadialGradientLayout>();
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(length(%s));\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* GrRadialGradientLayout::onCreateGLSLInstance() const {
37     return new GrGLSLRadialGradientLayout();
38 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const39 void GrRadialGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
40                                                    GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const41 bool GrRadialGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
42     const GrRadialGradientLayout& that = other.cast<GrRadialGradientLayout>();
43     (void)that;
44     if (fGradientMatrix != that.fGradientMatrix) return false;
45     return true;
46 }
GrRadialGradientLayout(const GrRadialGradientLayout & src)47 GrRadialGradientLayout::GrRadialGradientLayout(const GrRadialGradientLayout& src)
48         : INHERITED(kGrRadialGradientLayout_ClassID, src.optimizationFlags())
49         , fGradientMatrix(src.fGradientMatrix)
50         , fCoordTransform0(src.fCoordTransform0) {
51     this->addCoordTransform(&fCoordTransform0);
52 }
clone() const53 std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::clone() const {
54     return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(*this));
55 }
56 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradientLayout);
57 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * d)58 std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::TestCreate(GrProcessorTestData* d) {
59     SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
60     sk_sp<SkShader> shader;
61     do {
62         GrGradientShader::RandomParams params(d->fRandom);
63         SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale),
64                           d->fRandom->nextRangeScalar(0.0f, scale)};
65         SkScalar radius = d->fRandom->nextRangeScalar(0.0f, scale);
66         shader = params.fUseColors4f
67                          ? SkGradientShader::MakeRadial(center, radius, params.fColors4f,
68                                                         params.fColorSpace, params.fStops,
69                                                         params.fColorCount, params.fTileMode)
70                          : SkGradientShader::MakeRadial(center, radius, params.fColors,
71                                                         params.fStops, params.fColorCount,
72                                                         params.fTileMode);
73     } while (!shader);
74     GrTest::TestAsFPArgs asFPArgs(d);
75     std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
76     GrAlwaysAssert(fp);
77     return fp;
78 }
79 #endif
80 
Make(const SkRadialGradient & grad,const GrFPArgs & args)81 std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::Make(const SkRadialGradient& grad,
82                                                                   const GrFPArgs& args) {
83     SkMatrix matrix;
84     if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) {
85         return nullptr;
86     }
87     matrix.postConcat(grad.getGradientMatrix());
88     return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(matrix));
89 }
90