bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 2 | * Copyright 2017 Google Inc. |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 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 | |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 8 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrSimpleTextureEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 11 | #include "GrSimpleTextureEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | |
| 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 Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 19 | class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor { |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 20 | public: |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 21 | GrGLSLSimpleTextureEffect() {} |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 22 | void emitCode(EmitArgs& args) override { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 24 | const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>(); |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 25 | (void)_outer; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 26 | auto matrix = _outer.matrix; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 27 | (void)matrix; |
Ethan Nicholas | d4efe68 | 2019-08-29 16:10:13 -0400 | [diff] [blame] | 28 | SkString sk_TransformedCoords2D_0 = |
| 29 | fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 30 | fragBuilder->codeAppendf( |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 31 | "%s = %s * sample(%s, %s).%s;\n", args.fOutputColor, args.fInputColor, |
Stephen White | d523a06 | 2019-06-19 13:12:46 -0400 | [diff] [blame] | 32 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
Brian Salomon | bf5c0c0 | 2019-11-11 14:55:28 -0500 | [diff] [blame] | 33 | sk_TransformedCoords2D_0.c_str(), |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 34 | fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str()); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 35 | } |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 36 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 37 | private: |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 38 | void onSetData(const GrGLSLProgramDataManager& pdman, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 39 | const GrFragmentProcessor& _proc) override {} |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 40 | }; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 41 | GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const { |
| 42 | return new GrGLSLSimpleTextureEffect(); |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 43 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 44 | void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 45 | GrProcessorKeyBuilder* b) const {} |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 46 | bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 47 | const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>(); |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 48 | (void)that; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 49 | if (image != that.image) return false; |
| 50 | if (matrix != that.matrix) return false; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 51 | return true; |
| 52 | } |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 53 | GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 54 | : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags()) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 55 | , imageCoordTransform(src.imageCoordTransform) |
| 56 | , image(src.image) |
| 57 | , matrix(src.matrix) { |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 58 | this->setTextureSamplerCnt(1); |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 59 | this->addCoordTransform(&imageCoordTransform); |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 60 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 61 | std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const { |
| 62 | return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this)); |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 63 | } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 64 | const GrFragmentProcessor::TextureSampler& GrSimpleTextureEffect::onTextureSampler( |
| 65 | int index) const { |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 66 | return IthTextureSampler(index, image); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 67 | } |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 68 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect); |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 69 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 70 | std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate( |
| 71 | GrProcessorTestData* testData) { |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 72 | int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 73 | : GrProcessorUnitTest::kAlphaTextureIdx; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 74 | GrSamplerState::WrapMode wrapModes[2]; |
| 75 | GrTest::TestWrapModes(testData->fRandom, wrapModes); |
Robert Phillips | b350f1c | 2017-10-20 17:26:51 -0400 | [diff] [blame] | 76 | 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 Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 83 | GrSamplerState params(wrapModes, testData->fRandom->nextBool() |
| 84 | ? GrSamplerState::Filter::kBilerp |
| 85 | : GrSamplerState::Filter::kNearest); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 86 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 87 | const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom); |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 88 | return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), |
| 89 | testData->textureProxyColorType(texIdx), matrix, params); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 90 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 91 | #endif |