blob: 8a49c59e517139e4e4992e4e097f615786fadb5e [file] [log] [blame]
Michael Ludwig4f94ef62018-09-12 15:22:16 -04001/*
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#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"
18class GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
19public:
20 GrGLSLTiledGradientEffect() {}
21 void emitCode(EmitArgs& args) override {
Mike Kleind6ab77a2019-03-21 08:18:24 -050022 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23 const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
Michael Ludwig4f94ef62018-09-12 15:22:16 -040024 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040025 auto mirror = _outer.mirror;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040026 (void)mirror;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040027 auto makePremul = _outer.makePremul;
Michael Ludwigb96cba32018-09-14 13:59:24 -040028 (void)makePremul;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040029 auto colorsAreOpaque = _outer.colorsAreOpaque;
Michael Ludwigb96cba32018-09-14 13:59:24 -040030 (void)colorsAreOpaque;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040031 SkString _child1("_child1");
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040032 this->emitChild(_outer.gradLayout_index, &_child1, args);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040033 fragBuilder->codeAppendf(
Michael Ludwigb96cba32018-09-14 13:59:24 -040034 "half4 t = %s;\nif (!%s && t.y < 0.0) {\n %s = half4(0.0);\n} else {\n @if "
Ethan Nicholase1f55022019-02-05 17:17:40 -050035 "(%s) {\n half t_1 = t.x - 1.0;\n half tiled_t = (t_1 - 2.0 * "
36 "floor(t_1 * 0.5)) - 1.0;\n if (sk_Caps.mustDoOpBetweenFloorAndAbs) {\n "
37 " tiled_t = clamp(tiled_t, -1.0, 1.0);\n }\n t.x = "
38 "abs(tiled_t);\n } else {\n t.x = fract(t.x);\n }",
Michael Ludwigb96cba32018-09-14 13:59:24 -040039 _child1.c_str(),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040040 (_outer.childProcessor(_outer.gradLayout_index).preservesOpaqueInput() ? "true"
41 : "false"),
42 args.fOutputColor, (_outer.mirror ? "true" : "false"));
Michael Ludwig4f94ef62018-09-12 15:22:16 -040043 SkString _input0("t");
44 SkString _child0("_child0");
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040045 this->emitChild(_outer.colorizer_index, _input0.c_str(), &_child0, args);
Michael Ludwigb96cba32018-09-14 13:59:24 -040046 fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n",
Mike Kleind6ab77a2019-03-21 08:18:24 -050047 args.fOutputColor, _child0.c_str(),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040048 (_outer.makePremul ? "true" : "false"), args.fOutputColor,
Michael Ludwigb96cba32018-09-14 13:59:24 -040049 args.fOutputColor);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040050 }
51
52private:
53 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050054 const GrFragmentProcessor& _proc) override {}
Michael Ludwig4f94ef62018-09-12 15:22:16 -040055};
56GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
57 return new GrGLSLTiledGradientEffect();
58}
Mike Kleind6ab77a2019-03-21 08:18:24 -050059void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Michael Ludwig4f94ef62018-09-12 15:22:16 -040060 GrProcessorKeyBuilder* b) const {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040061 b->add32((int32_t)mirror);
62 b->add32((int32_t)makePremul);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040063}
64bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
65 const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
66 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040067 if (mirror != that.mirror) return false;
68 if (makePremul != that.makePremul) return false;
69 if (colorsAreOpaque != that.colorsAreOpaque) return false;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040070 return true;
71}
72GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
Michael Ludwigb96cba32018-09-14 13:59:24 -040073 : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040074 , colorizer_index(src.colorizer_index)
75 , gradLayout_index(src.gradLayout_index)
76 , mirror(src.mirror)
77 , makePremul(src.makePremul)
78 , colorsAreOpaque(src.colorsAreOpaque) {
79 this->registerChildProcessor(src.childProcessor(colorizer_index).clone());
80 this->registerChildProcessor(src.childProcessor(gradLayout_index).clone());
Michael Ludwig4f94ef62018-09-12 15:22:16 -040081}
82std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
83 return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this));
84}