bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 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 | |
| 8 | #include "GrSimpleTextureEffect.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 9 | #include "GrInvariantOutput.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 10 | #include "GrTexture.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 11 | #include "gl/GrGLCaps.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 12 | #include "gl/GrGLProcessor.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 13 | #include "gl/GrGLSL.h" |
| 14 | #include "gl/GrGLTexture.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 15 | #include "gl/builders/GrGLProgramBuilder.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 16 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 17 | class GrGLSimpleTextureEffect : public GrGLFragmentProcessor { |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 18 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 19 | GrGLSimpleTextureEffect(const GrProcessor&) {} |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 20 | |
joshualitt | 1598899 | 2014-10-09 15:04:05 -0700 | [diff] [blame] | 21 | virtual void emitCode(GrGLFPBuilder* builder, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 22 | const GrFragmentProcessor& fp, |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 23 | const char* outputColor, |
| 24 | const char* inputColor, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 25 | const TransformedCoordsArray& coords, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | const TextureSamplerArray& samplers) override { |
joshualitt | 1598899 | 2014-10-09 15:04:05 -0700 | [diff] [blame] | 27 | GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 28 | fsBuilder->codeAppendf("\t%s = ", outputColor); |
| 29 | fsBuilder->appendTextureLookupAndModulate(inputColor, |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 30 | samplers[0], |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 31 | coords[0].c_str(), |
joshualitt | 23e280d | 2014-09-18 12:26:38 -0700 | [diff] [blame] | 32 | coords[0].getType()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 33 | fsBuilder->codeAppend(";\n"); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 34 | } |
| 35 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 36 | private: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 37 | typedef GrGLFragmentProcessor INHERITED; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 42 | void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 43 | this->updateInvariantOutputForModulation(inout); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 44 | } |
| 45 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 46 | void GrSimpleTextureEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 47 | GrProcessorKeyBuilder* b) const { |
| 48 | GrGLSimpleTextureEffect::GenKey(*this, caps, b); |
| 49 | } |
| 50 | |
| 51 | GrGLFragmentProcessor* GrSimpleTextureEffect::createGLInstance() const { |
| 52 | return SkNEW_ARGS(GrGLSimpleTextureEffect, (*this)); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /////////////////////////////////////////////////////////////////////////////// |
| 56 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 57 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 58 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 59 | GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(SkRandom* random, |
| 60 | GrContext*, |
| 61 | const GrDrawTargetCaps&, |
| 62 | GrTexture* textures[]) { |
| 63 | int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 64 | GrProcessorUnitTest::kAlphaTextureIdx; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 65 | static const SkShader::TileMode kTileModes[] = { |
| 66 | SkShader::kClamp_TileMode, |
| 67 | SkShader::kRepeat_TileMode, |
| 68 | SkShader::kMirror_TileMode, |
| 69 | }; |
| 70 | SkShader::TileMode tileModes[] = { |
| 71 | kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 72 | kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 73 | }; |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 74 | GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode : |
| 75 | GrTextureParams::kNone_FilterMode); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 76 | |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 77 | static const GrCoordSet kCoordSets[] = { |
| 78 | kLocal_GrCoordSet, |
bsalomon | 309d4d5 | 2014-12-18 10:17:44 -0800 | [diff] [blame] | 79 | kDevice_GrCoordSet |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 80 | }; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 81 | GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))]; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 82 | |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 83 | const SkMatrix& matrix = GrTest::TestMatrix(random); |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 84 | return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 85 | } |