blob: 5b70a3edefacba18f2554f691f6755678ee6c5cb [file] [log] [blame]
bsalomon@google.com68b58c92013-01-17 16:50:08 +00001/*
Ethan Nicholas68990be2017-07-13 09:36:52 -04002 * Copyright 2017 Google Inc.
bsalomon@google.com68b58c92013-01-17 16:50:08 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Ethan Nicholas130fb3f2018-02-01 12:14:34 -05008/**************************************************************************************************
9 *** This file was autogenerated from GrSimpleTextureEffect.fp; do not modify.
10 **************************************************************************************************/
bsalomon@google.com68b58c92013-01-17 16:50:08 +000011#include "GrSimpleTextureEffect.h"
egdaniel64c47282015-11-13 06:54:19 -080012#include "glsl/GrGLSLFragmentProcessor.h"
egdaniel2d721d32015-11-11 13:06:05 -080013#include "glsl/GrGLSLFragmentShaderBuilder.h"
Ethan Nicholas68990be2017-07-13 09:36:52 -040014#include "glsl/GrGLSLProgramBuilder.h"
Ethan Nicholas2d5f9b32017-12-13 14:36:14 -050015#include "GrTexture.h"
Ethan Nicholas68990be2017-07-13 09:36:52 -040016#include "SkSLCPP.h"
17#include "SkSLUtil.h"
18class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000019public:
Ethan Nicholas68990be2017-07-13 09:36:52 -040020 GrGLSLSimpleTextureEffect() {}
robertphillips9cdb9922016-02-03 12:25:40 -080021 void emitCode(EmitArgs& args) override {
Mike Kleind6ab77a2019-03-21 08:18:24 -050022 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23 const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040024 (void)_outer;
Ethan Nicholas82399462017-10-16 12:35:44 -040025 auto matrix = _outer.matrix();
26 (void)matrix;
Brian Osman72a37be2017-08-15 09:19:53 -040027 SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040028 fragBuilder->codeAppendf(
Mike Kleind6ab77a2019-03-21 08:18:24 -050029 "%s = %s * texture(%s, %s).%s;\n", args.fOutputColor, args.fInputColor,
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040030 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
31 sk_TransformedCoords2D_0.c_str(),
Brian Osman2240be92017-10-18 13:15:13 -040032 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
bsalomon@google.com68b58c92013-01-17 16:50:08 +000033 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040034
Ethan Nicholas68990be2017-07-13 09:36:52 -040035private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040036 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050037 const GrFragmentProcessor& _proc) override {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000038};
Ethan Nicholas68990be2017-07-13 09:36:52 -040039GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
40 return new GrGLSLSimpleTextureEffect();
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000041}
Mike Kleind6ab77a2019-03-21 08:18:24 -050042void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Brian Osman2240be92017-10-18 13:15:13 -040043 GrProcessorKeyBuilder* b) const {}
Ethan Nicholas68990be2017-07-13 09:36:52 -040044bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
45 const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040046 (void)that;
Mike Kleind6ab77a2019-03-21 08:18:24 -050047 if (fImage != that.fImage) return false;
48 if (fMatrix != that.fMatrix) return false;
Ethan Nicholas68990be2017-07-13 09:36:52 -040049 return true;
50}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040051GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
Ethan Nicholasabff9562017-10-09 10:54:08 -040052 : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags())
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040053 , fImage(src.fImage)
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040054 , fMatrix(src.fMatrix)
55 , fImageCoordTransform(src.fImageCoordTransform) {
Brian Salomonf7dcd762018-07-30 14:48:15 -040056 this->setTextureSamplerCnt(1);
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040057 this->addCoordTransform(&fImageCoordTransform);
58}
Brian Salomonaff329b2017-08-11 09:40:37 -040059std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const {
60 return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this));
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040061}
Brian Salomonf7dcd762018-07-30 14:48:15 -040062const GrFragmentProcessor::TextureSampler& GrSimpleTextureEffect::onTextureSampler(
63 int index) const {
64 return IthTextureSampler(index, fImage);
65}
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000066GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000067#if GR_TEST_UTILS
Brian Salomonaff329b2017-08-11 09:40:37 -040068std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
69 GrProcessorTestData* testData) {
Ethan Nicholas68990be2017-07-13 09:36:52 -040070 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
71 : GrProcessorUnitTest::kAlphaTextureIdx;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040072 GrSamplerState::WrapMode wrapModes[2];
73 GrTest::TestWrapModes(testData->fRandom, wrapModes);
Robert Phillipsb350f1c2017-10-20 17:26:51 -040074 if (!testData->caps()->npotTextureTileSupport()) {
75 // Performing repeat sampling on npot textures will cause asserts on HW
76 // that lacks support.
77 wrapModes[0] = GrSamplerState::WrapMode::kClamp;
78 wrapModes[1] = GrSamplerState::WrapMode::kClamp;
79 }
80
Mike Kleind6ab77a2019-03-21 08:18:24 -050081 GrSamplerState params(wrapModes, testData->fRandom->nextBool()
82 ? GrSamplerState::Filter::kBilerp
83 : GrSamplerState::Filter::kNearest);
bsalomon@google.comc7818882013-03-20 19:19:53 +000084
Ethan Nicholas68990be2017-07-13 09:36:52 -040085 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
Robert Phillips2b2936e2017-10-20 15:11:35 -040086 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000087}
Hal Canary6f6961e2017-01-31 13:50:44 -050088#endif