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 #include "GrCoordTransform.h" |
13 | 14 |
14 class GrTexture; | 15 class GrTexture; |
15 | 16 |
16 /** | 17 /** |
17 * A base class for effects that draw a single texture with a texture matrix. Th
is effect has no | 18 * 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. | 19 * backend implementations. One must be provided by the subclass. |
19 */ | 20 */ |
20 class GrSingleTextureEffect : public GrEffect { | 21 class GrSingleTextureEffect : public GrEffect { |
21 public: | 22 public: |
22 virtual ~GrSingleTextureEffect(); | 23 virtual ~GrSingleTextureEffect(); |
23 | 24 |
24 const SkMatrix& getMatrix() const { return fMatrix; } | |
25 | |
26 /** Indicates whether the matrix operates on local coords or positions */ | |
27 CoordsType coordsType() const { return fCoordsType; } | |
28 | |
29 protected: | 25 protected: |
30 /** unfiltered, clamp mode */ | 26 /** unfiltered, clamp mode */ |
31 GrSingleTextureEffect(GrTexture*, const SkMatrix&, CoordsType = kLocal_Coord
sType); | 27 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoo
rdSet); |
32 /** clamp mode */ | 28 /** clamp mode */ |
33 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMo
de filterMode, | 29 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMo
de filterMode, |
34 CoordsType = kLocal_CoordsType); | 30 GrCoordSet = kLocal_GrCoordSet); |
35 GrSingleTextureEffect(GrTexture*, | 31 GrSingleTextureEffect(GrTexture*, |
36 const SkMatrix&, | 32 const SkMatrix&, |
37 const GrTextureParams&, | 33 const GrTextureParams&, |
38 CoordsType = kLocal_CoordsType); | 34 GrCoordSet = kLocal_GrCoordSet); |
39 | 35 |
40 /** | 36 /** |
41 * Helper for subclass onIsEqual() functions. | 37 * Helper for subclass onIsEqual() functions. |
42 */ | 38 */ |
43 bool hasSameTextureParamsMatrixAndCoordsType(const GrSingleTextureEffect& ot
her) const { | 39 bool hasSameTextureParamsMatrixAndSourceCoords(const GrSingleTextureEffect&
other) const { |
44 // We don't have to check the accesses' swizzles because they are inferr
ed from the texture. | 40 // We don't have to check the accesses' swizzles because they are inferr
ed from the texture. |
45 return fTextureAccess == other.fTextureAccess && | 41 return fTextureAccess == other.fTextureAccess && |
46 this->getMatrix().cheapEqualTo(other.getMatrix()) && | 42 fCoordTransform.getMatrix().cheapEqualTo(other.fCoordTransform.ge
tMatrix()) && |
47 fCoordsType == other.fCoordsType; | 43 fCoordTransform.sourceCoords() == other.fCoordTransform.sourceCoo
rds(); |
48 } | 44 } |
49 | 45 |
50 /** | 46 /** |
51 * Can be used as a helper to implement subclass getConstantColorComponents(
). It assumes that | 47 * Can be used as a helper to implement subclass getConstantColorComponents(
). It assumes that |
52 * the subclass output color will be a modulation of the input color with a
value read from the | 48 * the subclass output color will be a modulation of the input color with a
value read from the |
53 * texture. | 49 * texture. |
54 */ | 50 */ |
55 void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* va
lidFlags) const { | 51 void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* va
lidFlags) const { |
56 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*c
olor) && | 52 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*c
olor) && |
57 GrPixelConfigIsOpaque(this->texture(0)->config())) { | 53 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
58 *validFlags = kA_GrColorComponentFlag; | 54 *validFlags = kA_GrColorComponentFlag; |
59 } else { | 55 } else { |
60 *validFlags = 0; | 56 *validFlags = 0; |
61 } | 57 } |
62 } | 58 } |
63 | 59 |
64 private: | 60 private: |
65 GrTextureAccess fTextureAccess; | 61 GrCoordTransform fCoordTransform; |
66 SkMatrix fMatrix; | 62 GrTextureAccess fTextureAccess; |
67 CoordsType fCoordsType; | |
68 | 63 |
69 typedef GrEffect INHERITED; | 64 typedef GrEffect INHERITED; |
70 }; | 65 }; |
71 | 66 |
72 #endif | 67 #endif |
OLD | NEW |