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 GrTiledGradientEffect.fp; do not modify.
10 **************************************************************************************************/
11#include "GrTiledGradientEffect.h"
12
13#include "src/core/SkUtils.h"
14#include "src/gpu/GrTexture.h"
15#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
16#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
17#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
18#include "src/sksl/SkSLCPP.h"
19#include "src/sksl/SkSLUtil.h"
20class GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
21public:
22 GrGLSLTiledGradientEffect() {}
23 void emitCode(EmitArgs& args) override {
24 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
25 const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
26 (void)_outer;
27 auto mirror = _outer.mirror;
28 (void)mirror;
29 auto makePremul = _outer.makePremul;
30 (void)makePremul;
31 auto colorsAreOpaque = _outer.colorsAreOpaque;
32 (void)colorsAreOpaque;
33 SkString _sample453 = this->invokeChild(1, args);
34 fragBuilder->codeAppendf(
35 R"SkSL(half4 t = %s;
36if (!%s && t.y < 0.0) {
37 %s = half4(0.0);
38} else {
39 @if (%s) {
40 half t_1 = t.x - 1.0;
41 half tiled_t = (t_1 - 2.0 * floor(t_1 * 0.5)) - 1.0;
42 if (sk_Caps.mustDoOpBetweenFloorAndAbs) {
43 tiled_t = clamp(tiled_t, -1.0, 1.0);
44 }
45 t.x = abs(tiled_t);
46 } else {
47 t.x = fract(t.x);
48 })SkSL",
49 _sample453.c_str(),
50 (_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"),
51 args.fOutputColor, (_outer.mirror ? "true" : "false"));
52 SkString _coords1451("float2(half2(t.x, 0))");
53 SkString _sample1451 = this->invokeChild(0, args, _coords1451.c_str());
54 fragBuilder->codeAppendf(
55 R"SkSL(
56 %s = %s;
57}
58@if (%s) {
59 %s.xyz *= %s.w;
60}
61)SkSL",
62 args.fOutputColor, _sample1451.c_str(), (_outer.makePremul ? "true" : "false"),
63 args.fOutputColor, args.fOutputColor);
64 }
65
66private:
67 void onSetData(const GrGLSLProgramDataManager& pdman,
68 const GrFragmentProcessor& _proc) override {}
69};
70GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
71 return new GrGLSLTiledGradientEffect();
72}
73void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
74 GrProcessorKeyBuilder* b) const {
75 b->add32((uint32_t)mirror);
76 b->add32((uint32_t)makePremul);
77}
78bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
79 const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
80 (void)that;
81 if (mirror != that.mirror) return false;
82 if (makePremul != that.makePremul) return false;
83 if (colorsAreOpaque != that.colorsAreOpaque) return false;
84 return true;
85}
86GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
87 : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
88 , mirror(src.mirror)
89 , makePremul(src.makePremul)
90 , colorsAreOpaque(src.colorsAreOpaque) {
91 this->cloneAndRegisterAllChildProcessors(src);
92}
93std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
94 return std::make_unique<GrTiledGradientEffect>(*this);
95}
96#if GR_TEST_UTILS
97SkString GrTiledGradientEffect::onDumpInfo() const {
98 return SkStringPrintf("(mirror=%s, makePremul=%s, colorsAreOpaque=%s)",
99 (mirror ? "true" : "false"), (makePremul ? "true" : "false"),
100 (colorsAreOpaque ? "true" : "false"));
101}
102#endif
103