blob: 8fa986f456fd4008493d13c56792a76661d22cb1 [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
Greg Daniel456f9b52020-03-05 19:14:18 +000013#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#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;
Brian Osman12c5d292020-07-13 16:11:35 -040032 SkString _sample453 = this->invokeChild(1, args);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040033 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -040034 R"SkSL(half4 t = %s;
35if (!%s && t.y < 0.0) {
36 %s = half4(0.0);
37} else {
38 @if (%s) {
39 half t_1 = t.x - 1.0;
40 half tiled_t = (t_1 - 2.0 * floor(t_1 * 0.5)) - 1.0;
41 if (sk_Caps.mustDoOpBetweenFloorAndAbs) {
42 tiled_t = clamp(tiled_t, -1.0, 1.0);
43 }
44 t.x = abs(tiled_t);
45 } else {
46 t.x = fract(t.x);
47 })SkSL",
Ethan Nicholas13863662019-07-29 13:05:15 -040048 _sample453.c_str(),
Brian Osman12c5d292020-07-13 16:11:35 -040049 (_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040050 args.fOutputColor, (_outer.mirror ? "true" : "false"));
Ethan Nicholasd4efe682019-08-29 16:10:13 -040051 SkString _input1464("t");
Brian Osman12c5d292020-07-13 16:11:35 -040052 SkString _sample1464 = this->invokeChild(0, _input1464.c_str(), args);
John Stiles50819422020-06-18 13:00:38 -040053 fragBuilder->codeAppendf(
54 R"SkSL(
55 %s = %s;
56}
57@if (%s) {
58 %s.xyz *= %s.w;
59}
60)SkSL",
61 args.fOutputColor, _sample1464.c_str(), (_outer.makePremul ? "true" : "false"),
62 args.fOutputColor, args.fOutputColor);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040063 }
64
65private:
66 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050067 const GrFragmentProcessor& _proc) override {}
Michael Ludwig4f94ef62018-09-12 15:22:16 -040068};
69GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
70 return new GrGLSLTiledGradientEffect();
71}
Mike Kleind6ab77a2019-03-21 08:18:24 -050072void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Michael Ludwig4f94ef62018-09-12 15:22:16 -040073 GrProcessorKeyBuilder* b) const {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040074 b->add32((int32_t)mirror);
75 b->add32((int32_t)makePremul);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040076}
77bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
78 const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
79 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040080 if (mirror != that.mirror) return false;
81 if (makePremul != that.makePremul) return false;
82 if (colorsAreOpaque != that.colorsAreOpaque) return false;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040083 return true;
84}
85GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
Michael Ludwigb96cba32018-09-14 13:59:24 -040086 : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040087 , mirror(src.mirror)
88 , makePremul(src.makePremul)
89 , colorsAreOpaque(src.colorsAreOpaque) {
Brian Osman12c5d292020-07-13 16:11:35 -040090 this->cloneAndRegisterAllChildProcessors(src);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040091}
92std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
93 return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this));
94}