• 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 
13 #include "include/gpu/GrTexture.h"
14 #include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
15 #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
16 #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
17 #include "src/sksl/SkSLCPP.h"
18 #include "src/sksl/SkSLUtil.h"
19 class GrGLSLRadialGradientLayout : public GrGLSLFragmentProcessor {
20 public:
GrGLSLRadialGradientLayout()21     GrGLSLRadialGradientLayout() {}
emitCode(EmitArgs & args)22     void emitCode(EmitArgs& args) override {
23         GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24         const GrRadialGradientLayout& _outer = args.fFp.cast<GrRadialGradientLayout>();
25         (void)_outer;
26         auto gradientMatrix = _outer.gradientMatrix;
27         (void)gradientMatrix;
28         SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
29         fragBuilder->codeAppendf("half t = half(length(%s));\n%s = half4(t, 1.0, 0.0, 0.0);\n",
30                                  sk_TransformedCoords2D_0.c_str(), args.fOutputColor);
31     }
32 
33 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)34     void onSetData(const GrGLSLProgramDataManager& pdman,
35                    const GrFragmentProcessor& _proc) override {}
36 };
onCreateGLSLInstance() const37 GrGLSLFragmentProcessor* GrRadialGradientLayout::onCreateGLSLInstance() const {
38     return new GrGLSLRadialGradientLayout();
39 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const40 void GrRadialGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
41                                                    GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const42 bool GrRadialGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
43     const GrRadialGradientLayout& that = other.cast<GrRadialGradientLayout>();
44     (void)that;
45     if (gradientMatrix != that.gradientMatrix) return false;
46     return true;
47 }
GrRadialGradientLayout(const GrRadialGradientLayout & src)48 GrRadialGradientLayout::GrRadialGradientLayout(const GrRadialGradientLayout& src)
49         : INHERITED(kGrRadialGradientLayout_ClassID, src.optimizationFlags())
50         , fCoordTransform0(src.fCoordTransform0)
51         , gradientMatrix(src.gradientMatrix) {
52     this->addCoordTransform(&fCoordTransform0);
53 }
clone() const54 std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::clone() const {
55     return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(*this));
56 }
57 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradientLayout);
58 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * d)59 std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::TestCreate(GrProcessorTestData* d) {
60     SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
61     std::unique_ptr<GrFragmentProcessor> fp;
62     GrTest::TestAsFPArgs asFPArgs(d);
63     do {
64         GrGradientShader::RandomParams params(d->fRandom);
65         SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale),
66                           d->fRandom->nextRangeScalar(0.0f, scale)};
67         SkScalar radius = d->fRandom->nextRangeScalar(0.0f, scale);
68         sk_sp<SkShader> shader =
69                 params.fUseColors4f
70                         ? SkGradientShader::MakeRadial(center, radius, params.fColors4f,
71                                                        params.fColorSpace, params.fStops,
72                                                        params.fColorCount, params.fTileMode)
73                         : SkGradientShader::MakeRadial(center, radius, params.fColors,
74                                                        params.fStops, params.fColorCount,
75                                                        params.fTileMode);
76         // Degenerate params can create an Empty (non-null) shader, where fp will be nullptr
77         fp = shader ? as_SB(shader)->asFragmentProcessor(asFPArgs.args()) : nullptr;
78     } while (!fp);
79     return fp;
80 }
81 #endif
82 
Make(const SkRadialGradient & grad,const GrFPArgs & args)83 std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::Make(const SkRadialGradient& grad,
84                                                                   const GrFPArgs& args) {
85     SkMatrix matrix;
86     if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) {
87         return nullptr;
88     }
89     matrix.postConcat(grad.getGradientMatrix());
90     return std::unique_ptr<GrFragmentProcessor>(new GrRadialGradientLayout(matrix));
91 }
92