blob: f48b2e6ac892cb9bd6779aa6fe3e49c3ae395a1e [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 Stiles894ddb02020-07-07 14:59:32 -040030 SkString _input1335(args.fInputColor);
31 SkString _sample1335;
32 if (_outer.inputFP_index >= 0) {
33 _sample1335 = this->invokeChild(_outer.inputFP_index, _input1335.c_str(), args);
Ethan Nicholas6ad52892019-05-03 13:13:42 +000034 } else {
John Stiles894ddb02020-07-07 14:59:32 -040035 _sample1335.swap(_input1335);
Florin Malita6041d312019-03-05 15:03:20 +000036 }
John Stiles50819422020-06-18 13:00:38 -040037 fragBuilder->codeAppendf(
John Stiles894ddb02020-07-07 14:59:32 -040038 R"SkSL(half4 inColor = %s;)SkSL", _sample1335.c_str());
39 SkString _input1386("inColor");
40 SkString _sample1386;
41 _sample1386 = this->invokeChild(_outer.fp0_index, _input1386.c_str(), args);
42 SkString _input1408("inColor");
43 SkString _sample1408;
44 if (_outer.fp1_index >= 0) {
45 _sample1408 = this->invokeChild(_outer.fp1_index, _input1408.c_str(), args);
46 } else {
47 _sample1408.swap(_input1408);
48 }
49 fragBuilder->codeAppendf(
50 R"SkSL(
51%s = mix(%s, %s, %s);
John Stiles50819422020-06-18 13:00:38 -040052)SkSL",
John Stiles894ddb02020-07-07 14:59:32 -040053 args.fOutputColor, _sample1386.c_str(), _sample1408.c_str(),
John Stilesc05b2de2020-07-06 11:45:20 -040054 args.fUniformHandler->getUniformCStr(weightVar));
Florin Malita6041d312019-03-05 15:03:20 +000055 }
56
57private:
58 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050059 const GrFragmentProcessor& _proc) override {
Florin Malita6041d312019-03-05 15:03:20 +000060 const GrMixerEffect& _outer = _proc.cast<GrMixerEffect>();
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040061 { pdman.set1f(weightVar, (_outer.weight)); }
Florin Malita6041d312019-03-05 15:03:20 +000062 }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040063 UniformHandle weightVar;
Florin Malita6041d312019-03-05 15:03:20 +000064};
65GrGLSLFragmentProcessor* GrMixerEffect::onCreateGLSLInstance() const {
66 return new GrGLSLMixerEffect();
67}
Mike Kleind6ab77a2019-03-21 08:18:24 -050068void GrMixerEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Florin Malita6041d312019-03-05 15:03:20 +000069 GrProcessorKeyBuilder* b) const {}
70bool GrMixerEffect::onIsEqual(const GrFragmentProcessor& other) const {
71 const GrMixerEffect& that = other.cast<GrMixerEffect>();
72 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040073 if (weight != that.weight) return false;
Florin Malita6041d312019-03-05 15:03:20 +000074 return true;
75}
76GrMixerEffect::GrMixerEffect(const GrMixerEffect& src)
John Stiles88183902020-06-10 16:40:38 -040077 : INHERITED(kGrMixerEffect_ClassID, src.optimizationFlags()), weight(src.weight) {
John Stiles894ddb02020-07-07 14:59:32 -040078 if (src.inputFP_index >= 0) {
79 inputFP_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.inputFP_index));
80 }
John Stiles3779f442020-06-15 10:48:49 -040081 { fp0_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.fp0_index)); }
John Stiles88183902020-06-10 16:40:38 -040082 if (src.fp1_index >= 0) {
John Stiles3779f442020-06-15 10:48:49 -040083 fp1_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.fp1_index));
Florin Malita6041d312019-03-05 15:03:20 +000084 }
85}
86std::unique_ptr<GrFragmentProcessor> GrMixerEffect::clone() const {
87 return std::unique_ptr<GrFragmentProcessor>(new GrMixerEffect(*this));
88}