OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrDistanceFieldTextureEffect_DEFINED | 8 #ifndef GrDistanceFieldTextureEffect_DEFINED |
9 #define GrDistanceFieldTextureEffect_DEFINED | 9 #define GrDistanceFieldTextureEffect_DEFINED |
10 | 10 |
11 #include "GrEffect.h" | 11 #include "GrEffect.h" |
12 #include "GrVertexEffect.h" | 12 #include "GrVertexEffect.h" |
13 | 13 |
14 class GrGLDistanceFieldTextureEffect; | 14 class GrGLDistanceFieldTextureEffect; |
15 class GrGLDistanceFieldLCDTextureEffect; | 15 class GrGLDistanceFieldLCDTextureEffect; |
16 | 16 |
17 /** | 17 /** |
18 * The output color of this effect is a modulation of the input color and a samp
le from a | 18 * The output color of this effect is a modulation of the input color and a samp
le from a |
19 * distance field texture (using a smoothed step function near 0.5). | 19 * distance field texture (using a smoothed step function near 0.5). |
20 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input | 20 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input |
21 * coords are a custom attribute. | 21 * coords are a custom attribute. Gamma correction is handled via a texture LUT. |
22 */ | 22 */ |
23 class GrDistanceFieldTextureEffect : public GrVertexEffect { | 23 class GrDistanceFieldTextureEffect : public GrVertexEffect { |
24 public: | 24 public: |
25 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, bo
ol similarity) { | 25 #ifdef SK_GAMMA_APPLY_TO_A8 |
26 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, pa
rams, similarity))); | 26 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, |
| 27 GrTexture* gamma, const GrTextureParams& gammaPar
ams, float lum, |
| 28 bool similarity) { |
| 29 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, pa
rams, |
| 30 gamma,
gammaParams, lum, |
| 31 similar
ity))); |
| 32 #else |
| 33 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, |
| 34 bool similarity) { |
| 35 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, pa
rams, |
| 36 similar
ity))); |
| 37 #endif |
27 return CreateEffectRef(effect); | 38 return CreateEffectRef(effect); |
28 } | 39 } |
29 | 40 |
30 virtual ~GrDistanceFieldTextureEffect() {} | 41 virtual ~GrDistanceFieldTextureEffect() {} |
31 | 42 |
32 static const char* Name() { return "DistanceFieldTexture"; } | 43 static const char* Name() { return "DistanceFieldTexture"; } |
33 | 44 |
34 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 45 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 46 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 47 float getLuminance() const { return fLuminance; } |
| 48 #endif |
35 bool isSimilarity() const { return fIsSimilarity; } | 49 bool isSimilarity() const { return fIsSimilarity; } |
36 | 50 |
37 typedef GrGLDistanceFieldTextureEffect GLEffect; | 51 typedef GrGLDistanceFieldTextureEffect GLEffect; |
38 | 52 |
39 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 53 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
40 | 54 |
41 private: | 55 private: |
42 GrDistanceFieldTextureEffect(GrTexture* texture, const GrTextureParams& para
ms, | 56 GrDistanceFieldTextureEffect(GrTexture* texture, const GrTextureParams& para
ms, |
| 57 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 58 GrTexture* gamma, const GrTextureParams& gammaP
arams, float lum, |
| 59 #endif |
43 bool uniformScale); | 60 bool uniformScale); |
44 | 61 |
45 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 62 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
46 | 63 |
47 GrTextureAccess fTextureAccess; | 64 GrTextureAccess fTextureAccess; |
| 65 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 66 GrTextureAccess fGammaTextureAccess; |
| 67 float fLuminance; |
| 68 #endif |
48 bool fIsSimilarity; | 69 bool fIsSimilarity; |
49 | 70 |
50 GR_DECLARE_EFFECT_TEST; | 71 GR_DECLARE_EFFECT_TEST; |
51 | 72 |
52 typedef GrVertexEffect INHERITED; | 73 typedef GrVertexEffect INHERITED; |
53 }; | 74 }; |
54 | 75 |
55 /** | 76 /** |
56 * The output color of this effect is a modulation of the input color and sample
s from a | 77 * The output color of this effect is a modulation of the input color and sample
s from a |
57 * distance field texture (using a smoothed step function near 0.5), adjusted fo
r LCD displays. | 78 * distance field texture (using a smoothed step function near 0.5), adjusted fo
r LCD displays. |
58 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input | 79 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input |
59 * coords are a custom attribute. | 80 * coords are a custom attribute. Gamma correction is handled via a texture LUT. |
60 */ | 81 */ |
61 class GrDistanceFieldLCDTextureEffect : public GrVertexEffect { | 82 class GrDistanceFieldLCDTextureEffect : public GrVertexEffect { |
62 public: | 83 public: |
63 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, | 84 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, |
| 85 GrTexture* gamma, const GrTextureParams& gammaPar
ams, |
| 86 SkColor textColor, |
64 bool uniformScale, bool useBGR) { | 87 bool uniformScale, bool useBGR) { |
65 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, | 88 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, |
66 (tex, params, uniformScale, useBGR))); | 89 (tex, params, gamma, gammaParams, text
Color, uniformScale, |
| 90 useBGR))); |
67 return CreateEffectRef(effect); | 91 return CreateEffectRef(effect); |
68 } | 92 } |
69 | 93 |
70 virtual ~GrDistanceFieldLCDTextureEffect() {} | 94 virtual ~GrDistanceFieldLCDTextureEffect() {} |
71 | 95 |
72 static const char* Name() { return "DistanceFieldLCDTexture"; } | 96 static const char* Name() { return "DistanceFieldLCDTexture"; } |
73 | 97 |
74 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 98 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 99 GrColor getTextColor() const { return fTextColor; } |
75 bool isUniformScale() const { return fUniformScale; } | 100 bool isUniformScale() const { return fUniformScale; } |
76 bool useBGR() const { return fUseBGR; } | 101 bool useBGR() const { return fUseBGR; } |
77 | 102 |
78 typedef GrGLDistanceFieldLCDTextureEffect GLEffect; | 103 typedef GrGLDistanceFieldLCDTextureEffect GLEffect; |
79 | 104 |
80 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 105 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
81 | 106 |
82 private: | 107 private: |
83 GrDistanceFieldLCDTextureEffect(GrTexture* texture, const GrTextureParams& p
arams, | 108 GrDistanceFieldLCDTextureEffect(GrTexture* texture, const GrTextureParams& p
arams, |
| 109 GrTexture* gamma, const GrTextureParams& gam
maParams, |
| 110 SkColor textColor, |
84 bool uniformScale, bool useBGR); | 111 bool uniformScale, bool useBGR); |
85 | 112 |
86 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 113 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
87 | 114 |
88 GrTextureAccess fTextureAccess; | 115 GrTextureAccess fTextureAccess; |
| 116 GrTextureAccess fGammaTextureAccess; |
| 117 GrColor fTextColor; |
89 bool fUniformScale; | 118 bool fUniformScale; |
90 bool fUseBGR; | 119 bool fUseBGR; |
91 | 120 |
92 GR_DECLARE_EFFECT_TEST; | 121 GR_DECLARE_EFFECT_TEST; |
93 | 122 |
94 typedef GrVertexEffect INHERITED; | 123 typedef GrVertexEffect INHERITED; |
95 }; | 124 }; |
96 | 125 |
97 | |
98 #endif | 126 #endif |
OLD | NEW |