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