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 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 14 | class GrTexture; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 15 | |
| 16 | /** |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 17 | * A base class for effects that draw a single texture with a texture matrix. |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 18 | */ |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 19 | class GrSingleTextureEffect : public GrEffect { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 20 | public: |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 21 | virtual ~GrSingleTextureEffect(); |
| 22 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 23 | const SkMatrix& getMatrix() const { return fMatrix; } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 25 | protected: |
| 26 | GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */ |
| 27 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */ |
| 28 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&); |
| 29 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 30 | /** |
| 31 | * Helper for subclass onIsEqual() functions. |
| 32 | */ |
| 33 | bool hasSameTextureParamsAndMatrix(const GrSingleTextureEffect& other) const { |
| 34 | const GrTextureAccess& otherAccess = other.fTextureAccess; |
| 35 | // We don't have to check the accesses' swizzles because they are inferred from the texture. |
| 36 | return fTextureAccess.getTexture() == otherAccess.getTexture() && |
| 37 | fTextureAccess.getParams() == otherAccess.getParams() && |
| 38 | this->getMatrix().cheapEqualTo(other.getMatrix()); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that |
| 43 | * the subclass output color will be a modulation of the input color with a value read from the |
| 44 | * texture. |
| 45 | */ |
| 46 | void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const { |
| 47 | if ((*validFlags & kA_ValidComponentFlag) && 0xFF == GrColorUnpackA(*color) && |
| 48 | GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 49 | *validFlags = kA_ValidComponentFlag; |
| 50 | } else { |
| 51 | *validFlags = 0; |
| 52 | } |
| 53 | } |
| 54 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 55 | private: |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 56 | GrTextureAccess fTextureAccess; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 57 | SkMatrix fMatrix; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 58 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 59 | typedef GrEffect INHERITED; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | #endif |