blob: 1dbf8ecabecb9c6b51a2c3a5571dd89b7912ce68 [file] [log] [blame]
Florin Malita6041d312019-03-05 15:03:20 +00001/*
2 * Copyright 2019 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 GrMixerEffect.fp; do not modify.
10 **************************************************************************************************/
11#include "GrMixerEffect.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"
Florin Malita6041d312019-03-05 15:03:20 +000019class GrGLSLMixerEffect : public GrGLSLFragmentProcessor {
20public:
21 GrGLSLMixerEffect() {}
22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Mike Kleind6ab77a2019-03-21 08:18:24 -050024 const GrMixerEffect& _outer = args.fFp.cast<GrMixerEffect>();
Florin Malita6041d312019-03-05 15:03:20 +000025 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040026 auto weight = _outer.weight;
Florin Malita6041d312019-03-05 15:03:20 +000027 (void)weight;
Ethan Nicholas16464c32020-04-06 13:53:05 -040028 weightVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
29 kHalf_GrSLType, "weight");
John Stiles50819422020-06-18 13:00:38 -040030 SkString _input1278(args.fInputColor);
Brian Osman978693c2020-01-24 14:52:10 -050031 SkString _sample1278;
32 _sample1278 = this->invokeChild(_outer.fp0_index, _input1278.c_str(), args);
John Stiles50819422020-06-18 13:00:38 -040033 fragBuilder->codeAppendf(
34 R"SkSL(half4 in0 = %s;)SkSL", _sample1278.c_str());
35 SkString _input1335(args.fInputColor);
Brian Osman978693c2020-01-24 14:52:10 -050036 SkString _sample1335;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040037 if (_outer.fp1_index >= 0) {
Brian Osman978693c2020-01-24 14:52:10 -050038 _sample1335 = this->invokeChild(_outer.fp1_index, _input1335.c_str(), args);
Ethan Nicholas6ad52892019-05-03 13:13:42 +000039 } else {
John Stiles50819422020-06-18 13:00:38 -040040 _sample1335.swap(_input1335);
Florin Malita6041d312019-03-05 15:03:20 +000041 }
John Stiles50819422020-06-18 13:00:38 -040042 fragBuilder->codeAppendf(
43 R"SkSL(
44half4 in1 = %s ? %s : %s;
45%s = mix(in0, in1, %s);
46)SkSL",
47 _outer.fp1_index >= 0 ? "true" : "false", _sample1335.c_str(), args.fInputColor,
48 args.fOutputColor, args.fUniformHandler->getUniformCStr(weightVar));
Florin Malita6041d312019-03-05 15:03:20 +000049 }
50
51private:
52 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050053 const GrFragmentProcessor& _proc) override {
Florin Malita6041d312019-03-05 15:03:20 +000054 const GrMixerEffect& _outer = _proc.cast<GrMixerEffect>();
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040055 { pdman.set1f(weightVar, (_outer.weight)); }
Florin Malita6041d312019-03-05 15:03:20 +000056 }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040057 UniformHandle weightVar;
Florin Malita6041d312019-03-05 15:03:20 +000058};
59GrGLSLFragmentProcessor* GrMixerEffect::onCreateGLSLInstance() const {
60 return new GrGLSLMixerEffect();
61}
Mike Kleind6ab77a2019-03-21 08:18:24 -050062void GrMixerEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Florin Malita6041d312019-03-05 15:03:20 +000063 GrProcessorKeyBuilder* b) const {}
64bool GrMixerEffect::onIsEqual(const GrFragmentProcessor& other) const {
65 const GrMixerEffect& that = other.cast<GrMixerEffect>();
66 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040067 if (weight != that.weight) return false;
Florin Malita6041d312019-03-05 15:03:20 +000068 return true;
69}
70GrMixerEffect::GrMixerEffect(const GrMixerEffect& src)
John Stiles88183902020-06-10 16:40:38 -040071 : INHERITED(kGrMixerEffect_ClassID, src.optimizationFlags()), weight(src.weight) {
John Stiles3779f442020-06-15 10:48:49 -040072 { fp0_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.fp0_index)); }
John Stiles88183902020-06-10 16:40:38 -040073 if (src.fp1_index >= 0) {
John Stiles3779f442020-06-15 10:48:49 -040074 fp1_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.fp1_index));
Florin Malita6041d312019-03-05 15:03:20 +000075 }
76}
77std::unique_ptr<GrFragmentProcessor> GrMixerEffect::clone() const {
78 return std::unique_ptr<GrFragmentProcessor>(new GrMixerEffect(*this));
79}