tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +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 | #ifndef GrSingleTextureEffect_DEFINED |
| 9 | #define GrSingleTextureEffect_DEFINED |
| 10 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 11 | #include "GrEffect.h" |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 12 | #include "SkMatrix.h" |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 13 | |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 14 | class GrGLSingleTextureEffect; |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 15 | class GrTexture; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 16 | |
| 17 | /** |
bsalomon@google.com | 17fc651 | 2012-11-02 21:45:01 +0000 | [diff] [blame] | 18 | * An effect that draws a single texture with a texture matrix; commonly used as a base class. The |
| 19 | * output color is the texture color is modulated against the input color. |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 20 | */ |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 21 | class GrSingleTextureEffect : public GrEffect { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 22 | public: |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame^] | 23 | /* unfiltered, clamp mode */ |
| 24 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) { |
| 25 | SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix))); |
| 26 | return CreateEffectPtr(effect); |
| 27 | } |
bsalomon@google.com | c3a58f3 | 2012-11-01 15:40:47 +0000 | [diff] [blame] | 28 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame^] | 29 | /* clamp mode */ |
| 30 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) { |
| 31 | SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, bilerp))); |
| 32 | return CreateEffectPtr(effect); |
| 33 | } |
| 34 | |
| 35 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) { |
| 36 | SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, p))); |
| 37 | return CreateEffectPtr(effect); |
| 38 | } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 39 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 40 | virtual ~GrSingleTextureEffect(); |
| 41 | |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 42 | static const char* Name() { return "Single Texture"; } |
| 43 | |
bsalomon@google.com | 371e105 | 2013-01-11 21:08:55 +0000 | [diff] [blame] | 44 | /** Note that if this class is sub-classed, the subclass may have to override this function. |
| 45 | */ |
| 46 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| 47 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 48 | const SkMatrix& getMatrix() const { return fMatrix; } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 49 | |
bsalomon@google.com | 422e81a | 2012-10-25 14:11:03 +0000 | [diff] [blame] | 50 | typedef GrGLSingleTextureEffect GLEffect; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 51 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 52 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 53 | |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 54 | virtual bool isEqual(const GrEffect& effect) const SK_OVERRIDE { |
| 55 | const GrSingleTextureEffect& ste = static_cast<const GrSingleTextureEffect&>(effect); |
| 56 | return INHERITED::isEqual(effect) && fMatrix.cheapEqualTo(ste.getMatrix()); |
| 57 | } |
bsalomon@google.com | 17fc651 | 2012-11-02 21:45:01 +0000 | [diff] [blame] | 58 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame^] | 59 | protected: |
| 60 | GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */ |
| 61 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */ |
| 62 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&); |
| 63 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 64 | private: |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame^] | 65 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 66 | GR_DECLARE_EFFECT_TEST; |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 67 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 68 | GrTextureAccess fTextureAccess; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 69 | SkMatrix fMatrix; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 70 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 71 | typedef GrEffect INHERITED; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | #endif |