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" |
| 9 | #include "gl/GrGLEffect.h" |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 10 | #include "gl/GrGLShaderBuilder.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 11 | #include "gl/GrGLSL.h" |
| 12 | #include "gl/GrGLTexture.h" |
| 13 | #include "GrTBackendEffectFactory.h" |
| 14 | #include "GrTexture.h" |
| 15 | |
| 16 | class GrGLSimpleTextureEffect : public GrGLEffect { |
| 17 | public: |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 18 | GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 19 | : INHERITED (factory) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 20 | } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 21 | |
| 22 | virtual void emitCode(GrGLShaderBuilder* builder, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 23 | const GrDrawEffect& drawEffect, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 24 | const GrEffectKey& key, |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 25 | const char* outputColor, |
| 26 | const char* inputColor, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 27 | const TransformedCoordsArray& coords, |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 28 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 29 | builder->fsCodeAppendf("\t%s = ", outputColor); |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 30 | builder->fsAppendTextureLookupAndModulate(inputColor, |
| 31 | samplers[0], |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 32 | coords[0].c_str(), |
| 33 | coords[0].type()); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 34 | builder->fsCodeAppend(";\n"); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 35 | } |
| 36 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 37 | private: |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 38 | typedef GrGLEffect INHERITED; |
| 39 | }; |
| 40 | |
| 41 | /////////////////////////////////////////////////////////////////////////////// |
| 42 | |
| 43 | void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
| 44 | this->updateConstantColorComponentsForModulation(color, validFlags); |
| 45 | } |
| 46 | |
| 47 | const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { |
| 48 | return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance(); |
| 49 | } |
| 50 | |
| 51 | /////////////////////////////////////////////////////////////////////////////// |
| 52 | |
| 53 | GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect); |
| 54 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 55 | GrEffect* GrSimpleTextureEffect::TestCreate(SkRandom* random, |
| 56 | GrContext*, |
| 57 | const GrDrawTargetCaps&, |
| 58 | GrTexture* textures[]) { |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 59 | int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 60 | GrEffectUnitTest::kAlphaTextureIdx; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 61 | static const SkShader::TileMode kTileModes[] = { |
| 62 | SkShader::kClamp_TileMode, |
| 63 | SkShader::kRepeat_TileMode, |
| 64 | SkShader::kMirror_TileMode, |
| 65 | }; |
| 66 | SkShader::TileMode tileModes[] = { |
| 67 | kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 68 | kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 69 | }; |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 70 | GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode : |
| 71 | GrTextureParams::kNone_FilterMode); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 72 | |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 73 | static const GrCoordSet kCoordSets[] = { |
| 74 | kLocal_GrCoordSet, |
| 75 | kPosition_GrCoordSet |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 76 | }; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 77 | GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))]; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 78 | |
commit-bot@chromium.org | 76eaf74 | 2013-09-30 18:41:38 +0000 | [diff] [blame] | 79 | const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 80 | return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 81 | } |