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 GrSweepGradientLayout.fp; do not modify.
10 **************************************************************************************************/
11 #include "GrSweepGradientLayout.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 GrGLSLSweepGradientLayout : public GrGLSLFragmentProcessor {
20 public:
GrGLSLSweepGradientLayout()21 GrGLSLSweepGradientLayout() {}
emitCode(EmitArgs & args)22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrSweepGradientLayout& _outer = args.fFp.cast<GrSweepGradientLayout>();
25 (void)_outer;
26 auto gradientMatrix = _outer.gradientMatrix;
27 (void)gradientMatrix;
28 auto bias = _outer.bias;
29 (void)bias;
30 auto scale = _outer.scale;
31 (void)scale;
32 biasVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "bias");
33 scaleVar =
34 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "scale");
35 SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
36 fragBuilder->codeAppendf(
37 "half angle;\nif (sk_Caps.atan2ImplementedAsAtanYOverX) {\n angle = half(2.0 * "
38 "atan(-%s.y, length(%s) - %s.x));\n} else {\n angle = half(atan(-%s.y, "
39 "-%s.x));\n}\nhalf t = ((angle * 0.15915493667125702 + 0.5) + %s) * %s;\n%s = "
40 "half4(t, 1.0, 0.0, 0.0);\n",
41 sk_TransformedCoords2D_0.c_str(), sk_TransformedCoords2D_0.c_str(),
42 sk_TransformedCoords2D_0.c_str(), sk_TransformedCoords2D_0.c_str(),
43 sk_TransformedCoords2D_0.c_str(), args.fUniformHandler->getUniformCStr(biasVar),
44 args.fUniformHandler->getUniformCStr(scaleVar), args.fOutputColor);
45 }
46
47 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)48 void onSetData(const GrGLSLProgramDataManager& pdman,
49 const GrFragmentProcessor& _proc) override {
50 const GrSweepGradientLayout& _outer = _proc.cast<GrSweepGradientLayout>();
51 {
52 float biasValue = _outer.bias;
53 if (biasPrev != biasValue) {
54 biasPrev = biasValue;
55 pdman.set1f(biasVar, biasValue);
56 }
57 float scaleValue = _outer.scale;
58 if (scalePrev != scaleValue) {
59 scalePrev = scaleValue;
60 pdman.set1f(scaleVar, scaleValue);
61 }
62 }
63 }
64 float biasPrev = SK_FloatNaN;
65 float scalePrev = SK_FloatNaN;
66 UniformHandle biasVar;
67 UniformHandle scaleVar;
68 };
onCreateGLSLInstance() const69 GrGLSLFragmentProcessor* GrSweepGradientLayout::onCreateGLSLInstance() const {
70 return new GrGLSLSweepGradientLayout();
71 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const72 void GrSweepGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
73 GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const74 bool GrSweepGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
75 const GrSweepGradientLayout& that = other.cast<GrSweepGradientLayout>();
76 (void)that;
77 if (gradientMatrix != that.gradientMatrix) return false;
78 if (bias != that.bias) return false;
79 if (scale != that.scale) return false;
80 return true;
81 }
GrSweepGradientLayout(const GrSweepGradientLayout & src)82 GrSweepGradientLayout::GrSweepGradientLayout(const GrSweepGradientLayout& src)
83 : INHERITED(kGrSweepGradientLayout_ClassID, src.optimizationFlags())
84 , fCoordTransform0(src.fCoordTransform0)
85 , gradientMatrix(src.gradientMatrix)
86 , bias(src.bias)
87 , scale(src.scale) {
88 this->addCoordTransform(&fCoordTransform0);
89 }
clone() const90 std::unique_ptr<GrFragmentProcessor> GrSweepGradientLayout::clone() const {
91 return std::unique_ptr<GrFragmentProcessor>(new GrSweepGradientLayout(*this));
92 }
93 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradientLayout);
94 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * d)95 std::unique_ptr<GrFragmentProcessor> GrSweepGradientLayout::TestCreate(GrProcessorTestData* d) {
96 SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
97 SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale),
98 d->fRandom->nextRangeScalar(0.0f, scale)};
99
100 GrGradientShader::RandomParams params(d->fRandom);
101 auto shader = params.fUseColors4f
102 ? SkGradientShader::MakeSweep(center.fX, center.fY, params.fColors4f,
103 params.fColorSpace, params.fStops,
104 params.fColorCount)
105 : SkGradientShader::MakeSweep(center.fX, center.fY, params.fColors,
106 params.fStops, params.fColorCount);
107 GrTest::TestAsFPArgs asFPArgs(d);
108 std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
109 GrAlwaysAssert(fp);
110 return fp;
111 }
112 #endif
113
Make(const SkSweepGradient & grad,const GrFPArgs & args)114 std::unique_ptr<GrFragmentProcessor> GrSweepGradientLayout::Make(const SkSweepGradient& grad,
115 const GrFPArgs& args) {
116 SkMatrix matrix;
117 if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) {
118 return nullptr;
119 }
120 matrix.postConcat(grad.getGradientMatrix());
121 return std::unique_ptr<GrFragmentProcessor>(
122 new GrSweepGradientLayout(matrix, grad.getTBias(), grad.getTScale()));
123 }
124