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 | 68990be | 2017-07-13 09:36:52 -0400 | [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" |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 12 | #if SK_SUPPORT_GPU |
brianosman | 77320db | 2016-09-07 08:09:10 -0700 | [diff] [blame] | 13 | #include "glsl/GrGLSLColorSpaceXformHelper.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLFragmentProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 15 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 16 | #include "glsl/GrGLSLProgramBuilder.h" |
| 17 | #include "SkSLCPP.h" |
| 18 | #include "SkSLUtil.h" |
| 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 { |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 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 | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 26 | fColorSpaceHelper.emitCode(args.fUniformHandler, _outer.colorXform().get()); |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 27 | SkSL::String sk_TransformedCoords2D_0 = |
| 28 | fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
| 29 | fragBuilder->codeAppendf( |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 30 | "float4 _tmpVar1;%s = %s * %stexture(%s, %s).%s%s;\n", args.fOutputColor, |
| 31 | args.fInputColor ? args.fInputColor : "float4(1)", |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 32 | fColorSpaceHelper.isValid() ? "(_tmpVar1 = " : "", |
| 33 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), |
| 34 | sk_TransformedCoords2D_0.c_str(), |
| 35 | fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), |
| 36 | fColorSpaceHelper.isValid() |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 37 | ? SkStringPrintf(", float4(clamp((%s * float4(_tmpVar1.rgb, 1.0)).rgb, " |
| 38 | "0.0, _tmpVar1.a), _tmpVar1.a))", |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 39 | args.fUniformHandler->getUniformCStr( |
| 40 | fColorSpaceHelper.gamutXformUniform())) |
| 41 | .c_str() |
| 42 | : ""); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 43 | } |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 44 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 45 | private: |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 46 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 47 | const GrFragmentProcessor& _proc) override { |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 48 | const GrSimpleTextureEffect& _outer = _proc.cast<GrSimpleTextureEffect>(); |
| 49 | { |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 50 | if (fColorSpaceHelper.isValid()) { |
| 51 | fColorSpaceHelper.setData(pdman, _outer.colorXform().get()); |
| 52 | } |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 55 | UniformHandle fImageVar; |
Brian Osman | c624d9d | 2017-03-08 11:42:02 -0500 | [diff] [blame] | 56 | GrGLSLColorSpaceXformHelper fColorSpaceHelper; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 57 | }; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 58 | GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const { |
| 59 | return new GrGLSLSimpleTextureEffect(); |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 60 | } |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 61 | void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 62 | GrProcessorKeyBuilder* b) const { |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 63 | b->add32(GrColorSpaceXform::XformKey(fColorXform.get())); |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 64 | } |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 65 | bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 66 | const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>(); |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 67 | (void)that; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 68 | if (fImage != that.fImage) return false; |
| 69 | if (fColorXform != that.fColorXform) return false; |
| 70 | if (fMatrix != that.fMatrix) return false; |
| 71 | return true; |
| 72 | } |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 73 | GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src) |
| 74 | : INHERITED(src.optimizationFlags()) |
| 75 | , fImage(src.fImage) |
| 76 | , fColorXform(src.fColorXform) |
| 77 | , fMatrix(src.fMatrix) |
| 78 | , fImageCoordTransform(src.fImageCoordTransform) { |
| 79 | this->initClassID<GrSimpleTextureEffect>(); |
| 80 | this->addTextureSampler(&fImage); |
| 81 | this->addCoordTransform(&fImageCoordTransform); |
| 82 | } |
| 83 | sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::clone() const { |
| 84 | return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(*this)); |
| 85 | } |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 86 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect); |
Ethan Nicholas | baf981f | 2017-07-12 13:51:34 +0000 | [diff] [blame] | 87 | #if GR_TEST_UTILS |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 88 | sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(GrProcessorTestData* testData) { |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 89 | int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 90 | : GrProcessorUnitTest::kAlphaTextureIdx; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 91 | static const SkShader::TileMode kTileModes[] = { |
Ethan Nicholas | 480c90a | 2017-07-25 16:45:15 -0400 | [diff] [blame] | 92 | SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 93 | }; |
| 94 | SkShader::TileMode tileModes[] = { |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 95 | kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 96 | kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 97 | }; |
Ethan Nicholas | b9f6afb | 2017-07-27 16:02:37 -0400 | [diff] [blame] | 98 | GrSamplerParams params(tileModes, testData->fRandom->nextBool() |
| 99 | ? GrSamplerParams::kBilerp_FilterMode |
| 100 | : GrSamplerParams::kNone_FilterMode); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 101 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 102 | const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom); |
| 103 | sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(testData->fRandom); |
| 104 | return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), std::move(colorSpaceXform), |
| 105 | matrix); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 106 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 107 | #endif |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 108 | #endif |