blob: 279ea5dbd3633b6bd00e21dc9321ba7f82ee2384 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012
13#include "include/gpu/GrTexture.h"
14#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"
Ethan Nicholas68990be2017-07-13 09:36:52 -040019class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000020public:
Ethan Nicholas68990be2017-07-13 09:36:52 -040021 GrGLSLSimpleTextureEffect() {}
robertphillips9cdb9922016-02-03 12:25:40 -080022 void emitCode(EmitArgs& args) override {
Mike Kleind6ab77a2019-03-21 08:18:24 -050023 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040025 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040026 auto matrix = _outer.matrix;
Ethan Nicholas82399462017-10-16 12:35:44 -040027 (void)matrix;
Ethan Nicholasd4efe682019-08-29 16:10:13 -040028 SkString sk_TransformedCoords2D_0 =
29 fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040030 fragBuilder->codeAppendf(
Ethan Nicholas13863662019-07-29 13:05:15 -040031 "%s = %s * sample(%s, %s).%s;\n", args.fOutputColor, args.fInputColor,
Stephen Whited523a062019-06-19 13:12:46 -040032 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]),
Brian Salomonbf5c0c02019-11-11 14:55:28 -050033 sk_TransformedCoords2D_0.c_str(),
Brian Osman2240be92017-10-18 13:15:13 -040034 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
bsalomon@google.com68b58c92013-01-17 16:50:08 +000035 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040036
Ethan Nicholas68990be2017-07-13 09:36:52 -040037private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040038 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050039 const GrFragmentProcessor& _proc) override {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000040};
Ethan Nicholas68990be2017-07-13 09:36:52 -040041GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
42 return new GrGLSLSimpleTextureEffect();
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000043}
Mike Kleind6ab77a2019-03-21 08:18:24 -050044void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Brian Osman2240be92017-10-18 13:15:13 -040045 GrProcessorKeyBuilder* b) const {}
Ethan Nicholas68990be2017-07-13 09:36:52 -040046bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
47 const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040048 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040049 if (image != that.image) return false;
50 if (matrix != that.matrix) return false;
Ethan Nicholas68990be2017-07-13 09:36:52 -040051 return true;
52}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040053GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
Ethan Nicholasabff9562017-10-09 10:54:08 -040054 : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040055 , imageCoordTransform(src.imageCoordTransform)
56 , image(src.image)
57 , matrix(src.matrix) {
Brian Salomonf7dcd762018-07-30 14:48:15 -040058 this->setTextureSamplerCnt(1);
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040059 this->addCoordTransform(&imageCoordTransform);
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040060}
Brian Salomonaff329b2017-08-11 09:40:37 -040061std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const {
62 return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this));
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040063}
Brian Salomonf7dcd762018-07-30 14:48:15 -040064const GrFragmentProcessor::TextureSampler& GrSimpleTextureEffect::onTextureSampler(
65 int index) const {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040066 return IthTextureSampler(index, image);
Brian Salomonf7dcd762018-07-30 14:48:15 -040067}
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000068GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000069#if GR_TEST_UTILS
Brian Salomonaff329b2017-08-11 09:40:37 -040070std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
71 GrProcessorTestData* testData) {
Ethan Nicholas68990be2017-07-13 09:36:52 -040072 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
73 : GrProcessorUnitTest::kAlphaTextureIdx;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040074 GrSamplerState::WrapMode wrapModes[2];
75 GrTest::TestWrapModes(testData->fRandom, wrapModes);
Robert Phillipsb350f1c2017-10-20 17:26:51 -040076 if (!testData->caps()->npotTextureTileSupport()) {
77 // Performing repeat sampling on npot textures will cause asserts on HW
78 // that lacks support.
79 wrapModes[0] = GrSamplerState::WrapMode::kClamp;
80 wrapModes[1] = GrSamplerState::WrapMode::kClamp;
81 }
82
Mike Kleind6ab77a2019-03-21 08:18:24 -050083 GrSamplerState params(wrapModes, testData->fRandom->nextBool()
84 ? GrSamplerState::Filter::kBilerp
85 : GrSamplerState::Filter::kNearest);
bsalomon@google.comc7818882013-03-20 19:19:53 +000086
Ethan Nicholas68990be2017-07-13 09:36:52 -040087 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
Brian Salomon078e8fa2019-11-22 04:10:18 +000088 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx),
89 testData->textureProxyColorType(texIdx), matrix, params);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000090}
Hal Canary6f6961e2017-01-31 13:50:44 -050091#endif