blob: ceb665e3b0c8702daf4b831cd69823a3dea8dc4c [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");
Ethan Nicholasd4efe682019-08-29 16:10:13 -040030 SkString _input1278 = SkStringPrintf("%s", args.fInputColor);
Brian Osman978693c2020-01-24 14:52:10 -050031 SkString _sample1278;
32 _sample1278 = this->invokeChild(_outer.fp0_index, _input1278.c_str(), args);
Ethan Nicholas13863662019-07-29 13:05:15 -040033 fragBuilder->codeAppendf("half4 in0 = %s;", _sample1278.c_str());
Ethan Nicholasd4efe682019-08-29 16:10:13 -040034 SkString _input1335 = SkStringPrintf("%s", args.fInputColor);
Brian Osman978693c2020-01-24 14:52:10 -050035 SkString _sample1335;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040036 if (_outer.fp1_index >= 0) {
Brian Osman978693c2020-01-24 14:52:10 -050037 _sample1335 = this->invokeChild(_outer.fp1_index, _input1335.c_str(), args);
Ethan Nicholas6ad52892019-05-03 13:13:42 +000038 } else {
John Stilesd060c9d2020-06-08 11:44:25 -040039 _sample1335 = _input1335;
Florin Malita6041d312019-03-05 15:03:20 +000040 }
Ethan Nicholas6ad52892019-05-03 13:13:42 +000041 fragBuilder->codeAppendf("\nhalf4 in1 = %s ? %s : %s;\n%s = mix(in0, in1, %s);\n",
Ethan Nicholas13863662019-07-29 13:05:15 -040042 _outer.fp1_index >= 0 ? "true" : "false", _sample1335.c_str(),
Ethan Nicholas6ad52892019-05-03 13:13:42 +000043 args.fInputColor, args.fOutputColor,
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040044 args.fUniformHandler->getUniformCStr(weightVar));
Florin Malita6041d312019-03-05 15:03:20 +000045 }
46
47private:
48 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050049 const GrFragmentProcessor& _proc) override {
Florin Malita6041d312019-03-05 15:03:20 +000050 const GrMixerEffect& _outer = _proc.cast<GrMixerEffect>();
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040051 { pdman.set1f(weightVar, (_outer.weight)); }
Florin Malita6041d312019-03-05 15:03:20 +000052 }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040053 UniformHandle weightVar;
Florin Malita6041d312019-03-05 15:03:20 +000054};
55GrGLSLFragmentProcessor* GrMixerEffect::onCreateGLSLInstance() const {
56 return new GrGLSLMixerEffect();
57}
Mike Kleind6ab77a2019-03-21 08:18:24 -050058void GrMixerEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Florin Malita6041d312019-03-05 15:03:20 +000059 GrProcessorKeyBuilder* b) const {}
60bool GrMixerEffect::onIsEqual(const GrFragmentProcessor& other) const {
61 const GrMixerEffect& that = other.cast<GrMixerEffect>();
62 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040063 if (weight != that.weight) return false;
Florin Malita6041d312019-03-05 15:03:20 +000064 return true;
65}
66GrMixerEffect::GrMixerEffect(const GrMixerEffect& src)
John Stiles88183902020-06-10 16:40:38 -040067 : INHERITED(kGrMixerEffect_ClassID, src.optimizationFlags()), weight(src.weight) {
Brian Salomonb243b432020-02-20 14:41:47 -050068 {
John Stiles88183902020-06-10 16:40:38 -040069 auto fp0_clone = src.childProcessor(src.fp0_index).clone();
70 if (src.childProcessor(src.fp0_index).isSampledWithExplicitCoords()) {
71 fp0_clone->setSampledWithExplicitCoords();
Ethan Nicholas58430122020-04-14 09:54:02 -040072 }
John Stiles88183902020-06-10 16:40:38 -040073 fp0_index = this->registerChildProcessor(std::move(fp0_clone));
Brian Salomonb243b432020-02-20 14:41:47 -050074 }
John Stiles88183902020-06-10 16:40:38 -040075 if (src.fp1_index >= 0) {
76 auto fp1_clone = src.childProcessor(src.fp1_index).clone();
77 if (src.childProcessor(src.fp1_index).isSampledWithExplicitCoords()) {
78 fp1_clone->setSampledWithExplicitCoords();
Ethan Nicholas58430122020-04-14 09:54:02 -040079 }
John Stiles88183902020-06-10 16:40:38 -040080 fp1_index = this->registerChildProcessor(std::move(fp1_clone));
Florin Malita6041d312019-03-05 15:03:20 +000081 }
82}
83std::unique_ptr<GrFragmentProcessor> GrMixerEffect::clone() const {
84 return std::unique_ptr<GrFragmentProcessor>(new GrMixerEffect(*this));
85}