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 GrDistanceFieldGeoProc_DEFINED |
9 #define GrDistanceFieldTextureEffect_DEFINED | 9 #define GrDistanceFieldGeoProc_DEFINED |
10 | 10 |
11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
12 #include "GrGeometryProcessor.h" | 12 #include "GrGeometryProcessor.h" |
13 | 13 |
14 class GrGLDistanceFieldTextureEffect; | 14 class GrGLDistanceFieldA8TextGeoProc; |
15 class GrGLDistanceFieldNoGammaTextureEffect; | 15 class GrGLDistanceFieldPathGeoProc; |
16 class GrGLDistanceFieldLCDTextureEffect; | 16 class GrGLDistanceFieldLCDTextGeoProc; |
17 class GrInvariantOutput; | 17 class GrInvariantOutput; |
18 | 18 |
19 enum GrDistanceFieldEffectFlags { | 19 enum GrDistanceFieldEffectFlags { |
20 kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix | 20 kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix |
21 kRectToRect_DistanceFieldEffectFlag = 0x02, // ctm maps rects to rects | 21 kRectToRect_DistanceFieldEffectFlag = 0x02, // ctm maps rects to rects |
22 kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text | 22 kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text |
23 kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order | 23 kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order |
24 kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait
mode (not used yet) | 24 kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait
mode (not used yet) |
25 kColorAttr_DistanceFieldEffectFlag = 0x20, // color vertex attribute | 25 kColorAttr_DistanceFieldEffectFlag = 0x20, // color vertex attribute |
26 | 26 |
27 kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initiali
zation) | 27 kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initiali
zation) |
28 | 28 |
29 kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag
| | 29 kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag
| |
30 kRectToRect_DistanceFieldEffectFlag, | 30 kRectToRect_DistanceFieldEffectFlag, |
31 // The subset of the flags relevant to GrDistanceFieldTextureEffect | 31 // The subset of the flags relevant to GrDistanceFieldA8TextGeoProc |
32 kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag
| | 32 kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag
| |
33 kColorAttr_DistanceFieldEffectFlag, | 33 kColorAttr_DistanceFieldEffectFlag, |
34 // The subset of the flags relevant to GrDistanceFieldLCDTextureEffect | 34 // The subset of the flags relevant to GrDistanceFieldLCDTextGeoProc |
35 kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag
| | 35 kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag
| |
36 kRectToRect_DistanceFieldEffectFlag
| | 36 kRectToRect_DistanceFieldEffectFlag
| |
37 kUseLCD_DistanceFieldEffectFlag | | 37 kUseLCD_DistanceFieldEffectFlag | |
38 kBGR_DistanceFieldEffectFlag, | 38 kBGR_DistanceFieldEffectFlag, |
39 }; | 39 }; |
40 | 40 |
41 /** | 41 /** |
42 * The output color of this effect is a modulation of the input color and a samp
le from a | 42 * The output color of this effect is a modulation of the input color and a samp
le from a |
43 * distance field texture (using a smoothed step function near 0.5). | 43 * distance field texture (using a smoothed step function near 0.5). |
44 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input | 44 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input |
45 * coords are a custom attribute. Gamma correction is handled via a texture LUT. | 45 * coords are a custom attribute. Gamma correction is handled via a texture LUT. |
46 */ | 46 */ |
47 class GrDistanceFieldTextureEffect : public GrGeometryProcessor { | 47 class GrDistanceFieldA8TextGeoProc : public GrGeometryProcessor { |
48 public: | 48 public: |
49 #ifdef SK_GAMMA_APPLY_TO_A8 | 49 #ifdef SK_GAMMA_APPLY_TO_A8 |
50 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, | 50 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, |
51 const SkMatrix& localMatrix, | 51 const SkMatrix& localMatrix, |
52 GrTexture* tex, const GrTextureParams& pa
rams, | 52 GrTexture* tex, const GrTextureParams& pa
rams, |
53 float lum, uint32_t flags, bool opaqueVer
texColors) { | 53 float lum, uint32_t flags, bool opaqueVer
texColors) { |
54 return SkNEW_ARGS(GrDistanceFieldTextureEffect, (color, viewMatrix, loca
lMatrix, tex, | 54 return SkNEW_ARGS(GrDistanceFieldA8TextGeoProc, (color, viewMatrix, loca
lMatrix, tex, |
55 params, lum, flags, opa
queVertexColors)); | 55 params, lum, flags, opa
queVertexColors)); |
56 } | 56 } |
57 #else | 57 #else |
58 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, | 58 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, |
59 const SkMatrix& localMatrix, | 59 const SkMatrix& localMatrix, |
60 GrTexture* tex, const GrTextureParams& pa
rams, | 60 GrTexture* tex, const GrTextureParams& pa
rams, |
61 uint32_t flags, bool opaqueVertexColors)
{ | 61 uint32_t flags, bool opaqueVertexColors)
{ |
62 return SkNEW_ARGS(GrDistanceFieldTextureEffect, (color, viewMatrix, loca
lMatrix, tex, | 62 return SkNEW_ARGS(GrDistanceFieldA8TextGeoProc, (color, viewMatrix, loca
lMatrix, tex, |
63 params, flags, opaqueVe
rtexColors)); | 63 params, flags, opaqueVe
rtexColors)); |
64 } | 64 } |
65 #endif | 65 #endif |
66 | 66 |
67 virtual ~GrDistanceFieldTextureEffect() {} | 67 virtual ~GrDistanceFieldA8TextGeoProc() {} |
68 | 68 |
69 const char* name() const override { return "DistanceFieldTexture"; } | 69 const char* name() const override { return "DistanceFieldTexture"; } |
70 | 70 |
71 const Attribute* inPosition() const { return fInPosition; } | 71 const Attribute* inPosition() const { return fInPosition; } |
72 const Attribute* inColor() const { return fInColor; } | 72 const Attribute* inColor() const { return fInColor; } |
73 const Attribute* inTextureCoords() const { return fInTextureCoords; } | 73 const Attribute* inTextureCoords() const { return fInTextureCoords; } |
74 #ifdef SK_GAMMA_APPLY_TO_A8 | 74 #ifdef SK_GAMMA_APPLY_TO_A8 |
75 float getDistanceAdjust() const { return fDistanceAdjust; } | 75 float getDistanceAdjust() const { return fDistanceAdjust; } |
76 #endif | 76 #endif |
77 uint32_t getFlags() const { return fFlags; } | 77 uint32_t getFlags() const { return fFlags; } |
78 | 78 |
79 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 79 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
80 const GrGLCaps& caps, | 80 const GrGLCaps& caps, |
81 GrProcessorKeyBuilder* b) const override; | 81 GrProcessorKeyBuilder* b) const override; |
82 | 82 |
83 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 83 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
84 const GrGLCaps&) const over
ride; | 84 const GrGLCaps&) const over
ride; |
85 | 85 |
86 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override; | 86 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override; |
87 | 87 |
88 bool onCanMakeEqual(const GrBatchTracker&, | 88 bool onCanMakeEqual(const GrBatchTracker&, |
89 const GrGeometryProcessor&, | 89 const GrGeometryProcessor&, |
90 const GrBatchTracker&) const override; | 90 const GrBatchTracker&) const override; |
91 | 91 |
92 private: | 92 private: |
93 GrDistanceFieldTextureEffect(GrColor, const SkMatrix& viewMatrix, const SkMa
trix& localMatrix, | 93 GrDistanceFieldA8TextGeoProc(GrColor, const SkMatrix& viewMatrix, const SkMa
trix& localMatrix, |
94 GrTexture* texture, const GrTextureParams& para
ms, | 94 GrTexture* texture, const GrTextureParams& para
ms, |
95 #ifdef SK_GAMMA_APPLY_TO_A8 | 95 #ifdef SK_GAMMA_APPLY_TO_A8 |
96 float distanceAdjust, | 96 float distanceAdjust, |
97 #endif | 97 #endif |
98 uint32_t flags, bool opaqueVertexColors); | 98 uint32_t flags, bool opaqueVertexColors); |
99 | 99 |
100 bool onIsEqual(const GrGeometryProcessor& other) const override; | 100 bool onIsEqual(const GrGeometryProcessor& other) const override; |
101 | 101 |
102 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override; | 102 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override; |
103 | 103 |
104 GrTextureAccess fTextureAccess; | 104 GrTextureAccess fTextureAccess; |
105 #ifdef SK_GAMMA_APPLY_TO_A8 | 105 #ifdef SK_GAMMA_APPLY_TO_A8 |
106 float fDistanceAdjust; | 106 float fDistanceAdjust; |
107 #endif | 107 #endif |
108 uint32_t fFlags; | 108 uint32_t fFlags; |
109 const Attribute* fInPosition; | 109 const Attribute* fInPosition; |
110 const Attribute* fInColor; | 110 const Attribute* fInColor; |
111 const Attribute* fInTextureCoords; | 111 const Attribute* fInTextureCoords; |
112 | 112 |
113 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 113 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
114 | 114 |
115 typedef GrGeometryProcessor INHERITED; | 115 typedef GrGeometryProcessor INHERITED; |
116 }; | 116 }; |
117 | 117 |
118 | 118 |
119 /** | 119 /** |
120 * The output color of this effect is a modulation of the input color and a sampl
e from a | 120 * The output color of this effect is a modulation of the input color and a sampl
e from a |
121 * distance field texture (using a smoothed step function near 0.5). | 121 * distance field texture (using a smoothed step function near 0.5). |
122 * It allows explicit specification of the filtering and wrap modes (GrTexturePar
ams). The input | 122 * It allows explicit specification of the filtering and wrap modes (GrTexturePar
ams). The input |
123 * coords are a custom attribute. No gamma correct blending is applied. | 123 * coords are a custom attribute. No gamma correct blending is applied. Used for
paths only. |
124 */ | 124 */ |
125 class GrDistanceFieldNoGammaTextureEffect : public GrGeometryProcessor { | 125 class GrDistanceFieldPathGeoProc : public GrGeometryProcessor { |
126 public: | 126 public: |
127 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, GrTexture* tex, | 127 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, GrTexture* tex, |
128 const GrTextureParams& params, | 128 const GrTextureParams& params, |
129 uint32_t flags, bool opaqueVertexColors)
{ | 129 uint32_t flags, bool opaqueVertexColors)
{ |
130 return SkNEW_ARGS(GrDistanceFieldNoGammaTextureEffect, (color, viewMatri
x, tex, params, | 130 return SkNEW_ARGS(GrDistanceFieldPathGeoProc, (color, viewMatrix, tex, p
arams, |
131 flags, opaqueVer
texColors)); | 131 flags, opaqueVertexColors
)); |
132 } | 132 } |
133 | 133 |
134 virtual ~GrDistanceFieldNoGammaTextureEffect() {} | 134 virtual ~GrDistanceFieldPathGeoProc() {} |
135 | 135 |
136 const char* name() const override { return "DistanceFieldTexture"; } | 136 const char* name() const override { return "DistanceFieldTexture"; } |
137 | 137 |
138 const Attribute* inPosition() const { return fInPosition; } | 138 const Attribute* inPosition() const { return fInPosition; } |
139 const Attribute* inColor() const { return fInColor; } | 139 const Attribute* inColor() const { return fInColor; } |
140 const Attribute* inTextureCoords() const { return fInTextureCoords; } | 140 const Attribute* inTextureCoords() const { return fInTextureCoords; } |
141 uint32_t getFlags() const { return fFlags; } | 141 uint32_t getFlags() const { return fFlags; } |
142 | 142 |
143 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 143 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
144 const GrGLCaps& caps, | 144 const GrGLCaps& caps, |
145 GrProcessorKeyBuilder* b) const override; | 145 GrProcessorKeyBuilder* b) const override; |
146 | 146 |
147 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 147 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
148 const GrGLCaps&) const over
ride; | 148 const GrGLCaps&) const over
ride; |
149 | 149 |
150 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override; | 150 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override; |
151 | 151 |
152 bool onCanMakeEqual(const GrBatchTracker&, | 152 bool onCanMakeEqual(const GrBatchTracker&, |
153 const GrGeometryProcessor&, | 153 const GrGeometryProcessor&, |
154 const GrBatchTracker&) const override; | 154 const GrBatchTracker&) const override; |
155 | 155 |
156 private: | 156 private: |
157 GrDistanceFieldNoGammaTextureEffect(GrColor, const SkMatrix& viewMatrix, GrT
exture* texture, | 157 GrDistanceFieldPathGeoProc(GrColor, const SkMatrix& viewMatrix, GrTexture* t
exture, |
158 const GrTextureParams& params, uint32_t
flags, | 158 const GrTextureParams& params, uint32_t flags, |
159 bool opaqueVertexColors); | 159 bool opaqueVertexColors); |
160 | 160 |
161 bool onIsEqual(const GrGeometryProcessor& other) const override; | 161 bool onIsEqual(const GrGeometryProcessor& other) const override; |
162 | 162 |
163 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override; | 163 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override; |
164 | 164 |
165 GrTextureAccess fTextureAccess; | 165 GrTextureAccess fTextureAccess; |
166 uint32_t fFlags; | 166 uint32_t fFlags; |
167 const Attribute* fInPosition; | 167 const Attribute* fInPosition; |
168 const Attribute* fInColor; | 168 const Attribute* fInColor; |
169 const Attribute* fInTextureCoords; | 169 const Attribute* fInTextureCoords; |
170 | 170 |
171 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 171 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
172 | 172 |
173 typedef GrGeometryProcessor INHERITED; | 173 typedef GrGeometryProcessor INHERITED; |
174 }; | 174 }; |
175 | 175 |
176 /** | 176 /** |
177 * The output color of this effect is a modulation of the input color and sample
s from a | 177 * The output color of this effect is a modulation of the input color and sample
s from a |
178 * distance field texture (using a smoothed step function near 0.5), adjusted fo
r LCD displays. | 178 * distance field texture (using a smoothed step function near 0.5), adjusted fo
r LCD displays. |
179 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input | 179 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). The input |
180 * coords are a custom attribute. Gamma correction is handled via a texture LUT. | 180 * coords are a custom attribute. Gamma correction is handled via a texture LUT. |
181 */ | 181 */ |
182 class GrDistanceFieldLCDTextureEffect : public GrGeometryProcessor { | 182 class GrDistanceFieldLCDTextGeoProc : public GrGeometryProcessor { |
183 public: | 183 public: |
184 struct DistanceAdjust { | 184 struct DistanceAdjust { |
185 SkScalar fR, fG, fB; | 185 SkScalar fR, fG, fB; |
186 static DistanceAdjust Make(SkScalar r, SkScalar g, SkScalar b) { | 186 static DistanceAdjust Make(SkScalar r, SkScalar g, SkScalar b) { |
187 DistanceAdjust result; | 187 DistanceAdjust result; |
188 result.fR = r; result.fG = g; result.fB = b; | 188 result.fR = r; result.fG = g; result.fB = b; |
189 return result; | 189 return result; |
190 } | 190 } |
191 bool operator==(const DistanceAdjust& wa) const { | 191 bool operator==(const DistanceAdjust& wa) const { |
192 return (fR == wa.fR && fG == wa.fG && fB == wa.fB); | 192 return (fR == wa.fR && fG == wa.fG && fB == wa.fB); |
193 } | 193 } |
194 bool operator!=(const DistanceAdjust& wa) const { | 194 bool operator!=(const DistanceAdjust& wa) const { |
195 return !(*this == wa); | 195 return !(*this == wa); |
196 } | 196 } |
197 }; | 197 }; |
198 | 198 |
199 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, | 199 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, |
200 const SkMatrix& localMatrix, | 200 const SkMatrix& localMatrix, |
201 GrTexture* tex, const GrTextureParams& pa
rams, | 201 GrTexture* tex, const GrTextureParams& pa
rams, |
202 DistanceAdjust distanceAdjust, uint32_t f
lags) { | 202 DistanceAdjust distanceAdjust, uint32_t f
lags) { |
203 return SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, | 203 return SkNEW_ARGS(GrDistanceFieldLCDTextGeoProc, |
204 (color, viewMatrix, localMatrix, tex, params, distance
Adjust, flags)); | 204 (color, viewMatrix, localMatrix, tex, params, distance
Adjust, flags)); |
205 } | 205 } |
206 | 206 |
207 virtual ~GrDistanceFieldLCDTextureEffect() {} | 207 virtual ~GrDistanceFieldLCDTextGeoProc() {} |
208 | 208 |
209 const char* name() const override { return "DistanceFieldLCDTexture"; } | 209 const char* name() const override { return "DistanceFieldLCDTexture"; } |
210 | 210 |
211 const Attribute* inPosition() const { return fInPosition; } | 211 const Attribute* inPosition() const { return fInPosition; } |
212 const Attribute* inTextureCoords() const { return fInTextureCoords; } | 212 const Attribute* inTextureCoords() const { return fInTextureCoords; } |
213 DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; } | 213 DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; } |
214 uint32_t getFlags() const { return fFlags; } | 214 uint32_t getFlags() const { return fFlags; } |
215 | 215 |
216 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 216 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
217 const GrGLCaps& caps, | 217 const GrGLCaps& caps, |
218 GrProcessorKeyBuilder* b) const override; | 218 GrProcessorKeyBuilder* b) const override; |
219 | 219 |
220 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 220 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
221 const GrGLCaps&) const over
ride; | 221 const GrGLCaps&) const over
ride; |
222 | 222 |
223 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override; | 223 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override; |
224 | 224 |
225 bool onCanMakeEqual(const GrBatchTracker&, | 225 bool onCanMakeEqual(const GrBatchTracker&, |
226 const GrGeometryProcessor&, | 226 const GrGeometryProcessor&, |
227 const GrBatchTracker&) const override; | 227 const GrBatchTracker&) const override; |
228 | 228 |
229 private: | 229 private: |
230 GrDistanceFieldLCDTextureEffect(GrColor, const SkMatrix& viewMatrix, | 230 GrDistanceFieldLCDTextGeoProc(GrColor, const SkMatrix& viewMatrix, |
231 const SkMatrix& localMatrix, | 231 const SkMatrix& localMatrix, |
232 GrTexture* texture, const GrTextureParams& p
arams, | 232 GrTexture* texture, const GrTextureParams& par
ams, |
233 DistanceAdjust wa, uint32_t flags); | 233 DistanceAdjust wa, uint32_t flags); |
234 | 234 |
235 bool onIsEqual(const GrGeometryProcessor& other) const override; | 235 bool onIsEqual(const GrGeometryProcessor& other) const override; |
236 | 236 |
237 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override; | 237 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override; |
238 | 238 |
239 GrTextureAccess fTextureAccess; | 239 GrTextureAccess fTextureAccess; |
240 DistanceAdjust fDistanceAdjust; | 240 DistanceAdjust fDistanceAdjust; |
241 uint32_t fFlags; | 241 uint32_t fFlags; |
242 const Attribute* fInPosition; | 242 const Attribute* fInPosition; |
243 const Attribute* fInTextureCoords; | 243 const Attribute* fInTextureCoords; |
244 | 244 |
245 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 245 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
246 | 246 |
247 typedef GrGeometryProcessor INHERITED; | 247 typedef GrGeometryProcessor INHERITED; |
248 }; | 248 }; |
249 | 249 |
250 #endif | 250 #endif |
OLD | NEW |