bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | #ifndef GrSimpleTextureEffect_DEFINED |
| 9 | #define GrSimpleTextureEffect_DEFINED |
| 10 | |
| 11 | #include "GrSingleTextureEffect.h" |
| 12 | |
| 13 | class GrGLSimpleTextureEffect; |
| 14 | |
| 15 | /** |
| 16 | * The output color of this effect is a modulation of the input color and a sample from a texture. |
reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame^] | 17 | * The coord to sample the texture is determine by a matrix. It allows explicit specification of |
| 18 | * the filtering and wrap modes (GrTextureParams). |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 19 | */ |
| 20 | class GrSimpleTextureEffect : public GrSingleTextureEffect { |
| 21 | public: |
| 22 | /* unfiltered, clamp mode */ |
reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame^] | 23 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) { |
| 24 | AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix))); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 25 | return CreateEffectRef(effect); |
| 26 | } |
| 27 | |
| 28 | /* clamp mode */ |
reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame^] | 29 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) { |
| 30 | AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, bilerp))); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 31 | return CreateEffectRef(effect); |
| 32 | } |
| 33 | |
reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame^] | 34 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) { |
| 35 | AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p))); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 36 | return CreateEffectRef(effect); |
| 37 | } |
| 38 | |
| 39 | virtual ~GrSimpleTextureEffect() {} |
| 40 | |
| 41 | static const char* Name() { return "Texture"; } |
| 42 | |
| 43 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| 44 | |
| 45 | typedef GrGLSimpleTextureEffect GLEffect; |
| 46 | |
| 47 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 48 | |
| 49 | private: |
reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame^] | 50 | GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix) |
| 51 | : GrSingleTextureEffect(texture, matrix) {} |
| 52 | GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, bool bilerp) |
| 53 | : GrSingleTextureEffect(texture, matrix, bilerp) {} |
| 54 | GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, const GrTextureParams& params) |
| 55 | : GrSingleTextureEffect(texture, matrix, params) {} |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 56 | |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 57 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 58 | const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(other); |
reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame^] | 59 | return this->hasSameTextureParamsAndMatrix(ste); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | GR_DECLARE_EFFECT_TEST; |
| 63 | |
| 64 | typedef GrSingleTextureEffect INHERITED; |
| 65 | }; |
| 66 | |
| 67 | #endif |