OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrSingleTextureEffect_DEFINED | 8 #ifndef GrSingleTextureEffect_DEFINED |
9 #define GrSingleTextureEffect_DEFINED | 9 #define GrSingleTextureEffect_DEFINED |
10 | 10 |
11 #include "GrEffect.h" | 11 #include "GrEffect.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 | 13 |
14 class GrTexture; | 14 class GrTexture; |
15 | 15 |
16 /** | 16 /** |
17 * A base class for effects that draw a single texture with a texture matrix. | 17 * A base class for effects that draw a single texture with a texture matrix. Th
is effect has no |
| 18 * backend implementations. One must be provided by the subclass. |
18 */ | 19 */ |
19 class GrSingleTextureEffect : public GrEffect { | 20 class GrSingleTextureEffect : public GrEffect { |
20 public: | 21 public: |
21 virtual ~GrSingleTextureEffect(); | 22 virtual ~GrSingleTextureEffect(); |
22 | 23 |
23 const SkMatrix& getMatrix() const { return fMatrix; } | 24 const SkMatrix& getMatrix() const { return fMatrix; } |
24 | 25 |
| 26 /** Indicates whether the matrix operates on local coords or positions */ |
| 27 CoordsType coordsType() const { return fCoordsType; } |
| 28 |
25 protected: | 29 protected: |
26 GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mod
e */ | 30 /** unfiltered, clamp mode */ |
27 GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mo
de */ | 31 GrSingleTextureEffect(GrTexture*, const SkMatrix&, CoordsType = kLocal_Coord
sType); |
28 GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&); | 32 /** clamp mode */ |
| 33 GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp, CoordsType =
kLocal_CoordsType); |
| 34 GrSingleTextureEffect(GrTexture*, |
| 35 const SkMatrix&, |
| 36 const GrTextureParams&, |
| 37 CoordsType = kLocal_CoordsType); |
29 | 38 |
30 /** | 39 /** |
31 * Helper for subclass onIsEqual() functions. | 40 * Helper for subclass onIsEqual() functions. |
32 */ | 41 */ |
33 bool hasSameTextureParamsAndMatrix(const GrSingleTextureEffect& other) const
{ | 42 bool hasSameTextureParamsMatrixAndCoordsType(const GrSingleTextureEffect& ot
her) const { |
34 const GrTextureAccess& otherAccess = other.fTextureAccess; | 43 const GrTextureAccess& otherAccess = other.fTextureAccess; |
35 // We don't have to check the accesses' swizzles because they are inferr
ed from the texture. | 44 // We don't have to check the accesses' swizzles because they are inferr
ed from the texture. |
36 return fTextureAccess.getTexture() == otherAccess.getTexture() && | 45 return fTextureAccess.getTexture() == otherAccess.getTexture() && |
37 fTextureAccess.getParams() == otherAccess.getParams() && | 46 fTextureAccess.getParams() == otherAccess.getParams() && |
38 this->getMatrix().cheapEqualTo(other.getMatrix()); | 47 this->getMatrix().cheapEqualTo(other.getMatrix()) && |
| 48 fCoordsType == other.fCoordsType; |
39 } | 49 } |
40 | 50 |
41 /** | 51 /** |
42 * Can be used as a helper to implement subclass getConstantColorComponents(
). It assumes that | 52 * 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 | 53 * the subclass output color will be a modulation of the input color with a
value read from the |
44 * texture. | 54 * texture. |
45 */ | 55 */ |
46 void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* va
lidFlags) const { | 56 void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* va
lidFlags) const { |
47 if ((*validFlags & kA_ValidComponentFlag) && 0xFF == GrColorUnpackA(*col
or) && | 57 if ((*validFlags & kA_ValidComponentFlag) && 0xFF == GrColorUnpackA(*col
or) && |
48 GrPixelConfigIsOpaque(this->texture(0)->config())) { | 58 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
49 *validFlags = kA_ValidComponentFlag; | 59 *validFlags = kA_ValidComponentFlag; |
50 } else { | 60 } else { |
51 *validFlags = 0; | 61 *validFlags = 0; |
52 } | 62 } |
53 } | 63 } |
54 | 64 |
55 private: | 65 private: |
56 GrTextureAccess fTextureAccess; | 66 GrTextureAccess fTextureAccess; |
57 SkMatrix fMatrix; | 67 SkMatrix fMatrix; |
| 68 CoordsType fCoordsType; |
58 | 69 |
59 typedef GrEffect INHERITED; | 70 typedef GrEffect INHERITED; |
60 }; | 71 }; |
61 | 72 |
62 #endif | 73 #endif |
OLD | NEW |