blob: 235b9d42d3abaac05eeb5c1c4f960bb24b2091d9 [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
John Stiles45f5b032020-07-27 17:31:29 -040013#include "src/core/SkUtils.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000014#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#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"
Michael Ludwig4f94ef62018-09-12 15:22:16 -040020class GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
21public:
22 GrGLSLTiledGradientEffect() {}
23 void emitCode(EmitArgs& args) override {
Mike Kleind6ab77a2019-03-21 08:18:24 -050024 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
25 const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
Michael Ludwig4f94ef62018-09-12 15:22:16 -040026 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040027 auto mirror = _outer.mirror;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040028 (void)mirror;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040029 auto makePremul = _outer.makePremul;
Michael Ludwigb96cba32018-09-14 13:59:24 -040030 (void)makePremul;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040031 auto colorsAreOpaque = _outer.colorsAreOpaque;
Michael Ludwigb96cba32018-09-14 13:59:24 -040032 (void)colorsAreOpaque;
Brian Osman12c5d292020-07-13 16:11:35 -040033 SkString _sample453 = this->invokeChild(1, args);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040034 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -040035 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",
Ethan Nicholas13863662019-07-29 13:05:15 -040049 _sample453.c_str(),
Brian Osman12c5d292020-07-13 16:11:35 -040050 (_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040051 args.fOutputColor, (_outer.mirror ? "true" : "false"));
John Stilesfada8bd2020-07-31 15:49:28 -040052 SkString _coords1451("float2(half2(t.x, 0))");
53 SkString _sample1451 = this->invokeChild(0, args, _coords1451.c_str());
John Stiles50819422020-06-18 13:00:38 -040054 fragBuilder->codeAppendf(
55 R"SkSL(
56 %s = %s;
57}
58@if (%s) {
59 %s.xyz *= %s.w;
60}
61)SkSL",
John Stilesfada8bd2020-07-31 15:49:28 -040062 args.fOutputColor, _sample1451.c_str(), (_outer.makePremul ? "true" : "false"),
John Stiles50819422020-06-18 13:00:38 -040063 args.fOutputColor, args.fOutputColor);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040064 }
65
66private:
67 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050068 const GrFragmentProcessor& _proc) override {}
Michael Ludwig4f94ef62018-09-12 15:22:16 -040069};
70GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
71 return new GrGLSLTiledGradientEffect();
72}
Mike Kleind6ab77a2019-03-21 08:18:24 -050073void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Michael Ludwig4f94ef62018-09-12 15:22:16 -040074 GrProcessorKeyBuilder* b) const {
John Stiles45f5b032020-07-27 17:31:29 -040075 b->add32((uint32_t)mirror);
76 b->add32((uint32_t)makePremul);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040077}
78bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
79 const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
80 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040081 if (mirror != that.mirror) return false;
82 if (makePremul != that.makePremul) return false;
83 if (colorsAreOpaque != that.colorsAreOpaque) return false;
Michael Ludwig4f94ef62018-09-12 15:22:16 -040084 return true;
85}
86GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
Michael Ludwigb96cba32018-09-14 13:59:24 -040087 : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040088 , mirror(src.mirror)
89 , makePremul(src.makePremul)
90 , colorsAreOpaque(src.colorsAreOpaque) {
Brian Osman12c5d292020-07-13 16:11:35 -040091 this->cloneAndRegisterAllChildProcessors(src);
Michael Ludwig4f94ef62018-09-12 15:22:16 -040092}
93std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
94 return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this));
95}