blob: cf5d5831ac33dd7229b8febafa6be6d282b1cbdc [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012
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"
Michael Ludwig4f94ef62018-09-12 15:22:16 -040019class GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
20public:
21 GrGLSLTiledGradientEffect() {}
22 void emitCode(EmitArgs& args) override {
Mike Kleind6ab77a2019-03-21 08:18:24 -050023 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
Michael Ludwig4f94ef62018-09-12 15:22:16 -040025 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040026 auto mirror = _outer.mirror;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040027 (void)mirror;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040028 auto makePremul = _outer.makePremul;
Michael Ludwigb96cba32018-09-14 13:59:24 -040029 (void)makePremul;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040030 auto colorsAreOpaque = _outer.colorsAreOpaque;
Michael Ludwigb96cba32018-09-14 13:59:24 -040031 (void)colorsAreOpaque;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040032 SkString _child1("_child1");
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040033 this->emitChild(_outer.gradLayout_index, &_child1, args);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040034 fragBuilder->codeAppendf(
Michael Ludwigb96cba32018-09-14 13:59:24 -040035 "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 -050036 "(%s) {\n half t_1 = t.x - 1.0;\n half tiled_t = (t_1 - 2.0 * "
37 "floor(t_1 * 0.5)) - 1.0;\n if (sk_Caps.mustDoOpBetweenFloorAndAbs) {\n "
38 " tiled_t = clamp(tiled_t, -1.0, 1.0);\n }\n t.x = "
39 "abs(tiled_t);\n } else {\n t.x = fract(t.x);\n }",
Michael Ludwigb96cba32018-09-14 13:59:24 -040040 _child1.c_str(),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040041 (_outer.childProcessor(_outer.gradLayout_index).preservesOpaqueInput() ? "true"
42 : "false"),
43 args.fOutputColor, (_outer.mirror ? "true" : "false"));
Michael Ludwig4f94ef62018-09-12 15:22:16 -040044 SkString _input0("t");
45 SkString _child0("_child0");
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040046 this->emitChild(_outer.colorizer_index, _input0.c_str(), &_child0, args);
Michael Ludwigb96cba32018-09-14 13:59:24 -040047 fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n",
Mike Kleind6ab77a2019-03-21 08:18:24 -050048 args.fOutputColor, _child0.c_str(),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040049 (_outer.makePremul ? "true" : "false"), args.fOutputColor,
Michael Ludwigb96cba32018-09-14 13:59:24 -040050 args.fOutputColor);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040051 }
52
53private:
54 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050055 const GrFragmentProcessor& _proc) override {}
Michael Ludwig4f94ef62018-09-12 15:22:16 -040056};
57GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
58 return new GrGLSLTiledGradientEffect();
59}
Mike Kleind6ab77a2019-03-21 08:18:24 -050060void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Michael Ludwig4f94ef62018-09-12 15:22:16 -040061 GrProcessorKeyBuilder* b) const {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040062 b->add32((int32_t)mirror);
63 b->add32((int32_t)makePremul);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040064}
65bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
66 const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
67 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040068 if (mirror != that.mirror) return false;
69 if (makePremul != that.makePremul) return false;
70 if (colorsAreOpaque != that.colorsAreOpaque) return false;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040071 return true;
72}
73GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
Michael Ludwigb96cba32018-09-14 13:59:24 -040074 : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040075 , colorizer_index(src.colorizer_index)
76 , gradLayout_index(src.gradLayout_index)
77 , mirror(src.mirror)
78 , makePremul(src.makePremul)
79 , colorsAreOpaque(src.colorsAreOpaque) {
80 this->registerChildProcessor(src.childProcessor(colorizer_index).clone());
81 this->registerChildProcessor(src.childProcessor(gradLayout_index).clone());
Michael Ludwig4f94ef62018-09-12 15:22:16 -040082}
83std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
84 return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this));
85}