blob: 5f57e2e89f1ef0a250b6e0e80838329a4eebda63 [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]),
Ethan Nicholasd4efe682019-08-29 16:10:13 -040033 _outer.computeLocalCoordsInVertexShader() ? sk_TransformedCoords2D_0.c_str()
34 : "_coords",
Brian Osman2240be92017-10-18 13:15:13 -040035 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
bsalomon@google.com68b58c92013-01-17 16:50:08 +000036 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040037
Ethan Nicholas68990be2017-07-13 09:36:52 -040038private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040039 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050040 const GrFragmentProcessor& _proc) override {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000041};
Ethan Nicholas68990be2017-07-13 09:36:52 -040042GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
43 return new GrGLSLSimpleTextureEffect();
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000044}
Mike Kleind6ab77a2019-03-21 08:18:24 -050045void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Brian Osman2240be92017-10-18 13:15:13 -040046 GrProcessorKeyBuilder* b) const {}
Ethan Nicholas68990be2017-07-13 09:36:52 -040047bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
48 const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040049 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040050 if (image != that.image) return false;
51 if (matrix != that.matrix) return false;
Ethan Nicholas68990be2017-07-13 09:36:52 -040052 return true;
53}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040054GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
Ethan Nicholasabff9562017-10-09 10:54:08 -040055 : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040056 , imageCoordTransform(src.imageCoordTransform)
57 , image(src.image)
58 , matrix(src.matrix) {
Brian Salomonf7dcd762018-07-30 14:48:15 -040059 this->setTextureSamplerCnt(1);
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040060 this->addCoordTransform(&imageCoordTransform);
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040061}
Brian Salomonaff329b2017-08-11 09:40:37 -040062std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const {
63 return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this));
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040064}
Brian Salomonf7dcd762018-07-30 14:48:15 -040065const GrFragmentProcessor::TextureSampler& GrSimpleTextureEffect::onTextureSampler(
66 int index) const {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040067 return IthTextureSampler(index, image);
Brian Salomonf7dcd762018-07-30 14:48:15 -040068}
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000069GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000070#if GR_TEST_UTILS
Brian Salomonaff329b2017-08-11 09:40:37 -040071std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
72 GrProcessorTestData* testData) {
Ethan Nicholas68990be2017-07-13 09:36:52 -040073 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
74 : GrProcessorUnitTest::kAlphaTextureIdx;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040075 GrSamplerState::WrapMode wrapModes[2];
76 GrTest::TestWrapModes(testData->fRandom, wrapModes);
Robert Phillipsb350f1c2017-10-20 17:26:51 -040077 if (!testData->caps()->npotTextureTileSupport()) {
78 // Performing repeat sampling on npot textures will cause asserts on HW
79 // that lacks support.
80 wrapModes[0] = GrSamplerState::WrapMode::kClamp;
81 wrapModes[1] = GrSamplerState::WrapMode::kClamp;
82 }
83
Mike Kleind6ab77a2019-03-21 08:18:24 -050084 GrSamplerState params(wrapModes, testData->fRandom->nextBool()
85 ? GrSamplerState::Filter::kBilerp
86 : GrSamplerState::Filter::kNearest);
bsalomon@google.comc7818882013-03-20 19:19:53 +000087
Ethan Nicholas68990be2017-07-13 09:36:52 -040088 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
Robert Phillips2b2936e2017-10-20 15:11:35 -040089 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000090}
Hal Canary6f6961e2017-01-31 13:50:44 -050091#endif