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