blob: 98e9a4734746e7f593ed3cd210bcfbb7aaa1ee79 [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"
12#include "glsl/GrGLSLFragmentProcessor.h"
13#include "glsl/GrGLSLFragmentShaderBuilder.h"
14#include "glsl/GrGLSLProgramBuilder.h"
15#include "GrTexture.h"
16#include "SkSLCPP.h"
17#include "SkSLUtil.h"
18class GrGLSLMixerEffect : public GrGLSLFragmentProcessor {
19public:
20 GrGLSLMixerEffect() {}
21 void emitCode(EmitArgs& args) override {
22 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Mike Kleind6ab77a2019-03-21 08:18:24 -050023 const GrMixerEffect& _outer = args.fFp.cast<GrMixerEffect>();
Florin Malita6041d312019-03-05 15:03:20 +000024 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040025 auto weight = _outer.weight;
Florin Malita6041d312019-03-05 15:03:20 +000026 (void)weight;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040027 weightVar =
Ethan Nicholas858fecc2019-03-07 13:19:18 -050028 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "weight");
Florin Malita6041d312019-03-05 15:03:20 +000029 SkString _input0 = SkStringPrintf("%s", args.fInputColor);
30 SkString _child0("_child0");
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040031 this->emitChild(_outer.fp0_index, _input0.c_str(), &_child0, args);
Florin Malita6041d312019-03-05 15:03:20 +000032 fragBuilder->codeAppendf("half4 in0 = %s;", _child0.c_str());
33 SkString _input1 = SkStringPrintf("%s", args.fInputColor);
34 SkString _child1("_child1");
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040035 if (_outer.fp1_index >= 0) {
36 this->emitChild(_outer.fp1_index, _input1.c_str(), &_child1, args);
Florin Malita6041d312019-03-05 15:03:20 +000037 } else {
38 fragBuilder->codeAppendf("half4 %s;", _child1.c_str());
39 }
40 fragBuilder->codeAppendf("\nhalf4 in1 = %s ? %s : %s;\n%s = mix(in0, in1, %s);\n",
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040041 _outer.fp1_index >= 0 ? "true" : "false", _child1.c_str(),
Mike Kleind6ab77a2019-03-21 08:18:24 -050042 args.fInputColor, args.fOutputColor,
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040043 args.fUniformHandler->getUniformCStr(weightVar));
Florin Malita6041d312019-03-05 15:03:20 +000044 }
45
46private:
47 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050048 const GrFragmentProcessor& _proc) override {
Florin Malita6041d312019-03-05 15:03:20 +000049 const GrMixerEffect& _outer = _proc.cast<GrMixerEffect>();
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040050 { pdman.set1f(weightVar, (_outer.weight)); }
Florin Malita6041d312019-03-05 15:03:20 +000051 }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040052 UniformHandle weightVar;
Florin Malita6041d312019-03-05 15:03:20 +000053};
54GrGLSLFragmentProcessor* GrMixerEffect::onCreateGLSLInstance() const {
55 return new GrGLSLMixerEffect();
56}
Mike Kleind6ab77a2019-03-21 08:18:24 -050057void GrMixerEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Florin Malita6041d312019-03-05 15:03:20 +000058 GrProcessorKeyBuilder* b) const {}
59bool GrMixerEffect::onIsEqual(const GrFragmentProcessor& other) const {
60 const GrMixerEffect& that = other.cast<GrMixerEffect>();
61 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040062 if (weight != that.weight) return false;
Florin Malita6041d312019-03-05 15:03:20 +000063 return true;
64}
65GrMixerEffect::GrMixerEffect(const GrMixerEffect& src)
66 : INHERITED(kGrMixerEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040067 , fp0_index(src.fp0_index)
68 , fp1_index(src.fp1_index)
69 , weight(src.weight) {
70 this->registerChildProcessor(src.childProcessor(fp0_index).clone());
71 if (fp1_index >= 0) {
72 this->registerChildProcessor(src.childProcessor(fp1_index).clone());
Florin Malita6041d312019-03-05 15:03:20 +000073 }
74}
75std::unique_ptr<GrFragmentProcessor> GrMixerEffect::clone() const {
76 return std::unique_ptr<GrFragmentProcessor>(new GrMixerEffect(*this));
77}