1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrDistanceFieldGeoProc_DEFINED
#define GrDistanceFieldGeoProc_DEFINED
#include "GrProcessor.h"
#include "GrGeometryProcessor.h"
class GrGLDistanceFieldA8TextGeoProc;
class GrGLDistanceFieldPathGeoProc;
class GrGLDistanceFieldLCDTextGeoProc;
class GrInvariantOutput;
enum GrDistanceFieldEffectFlags {
kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix
kScaleOnly_DistanceFieldEffectFlag = 0x02, // ctm has only scale and translate
kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text
kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order
kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait mode (not used yet)
kGammaCorrect_DistanceFieldEffectFlag = 0x20, // assume gamma-correct output (linear blending)
kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initialization)
kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
kScaleOnly_DistanceFieldEffectFlag,
// The subset of the flags relevant to GrDistanceFieldA8TextGeoProc
kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
kScaleOnly_DistanceFieldEffectFlag |
kGammaCorrect_DistanceFieldEffectFlag,
// The subset of the flags relevant to GrDistanceFieldLCDTextGeoProc
kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
kScaleOnly_DistanceFieldEffectFlag |
kUseLCD_DistanceFieldEffectFlag |
kBGR_DistanceFieldEffectFlag |
kGammaCorrect_DistanceFieldEffectFlag,
};
/**
* The output color of this effect is a modulation of the input color and a sample from a
* distance field texture (using a smoothed step function near 0.5).
* It allows explicit specification of the filtering and wrap modes (GrSamplerParams). The input
* coords are a custom attribute. Gamma correction is handled via a texture LUT.
*/
class GrDistanceFieldA8TextGeoProc : public GrGeometryProcessor {
public:
#ifdef SK_GAMMA_APPLY_TO_A8
static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
GrTexture* tex, const GrSamplerParams& params,
float lum, uint32_t flags, bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldA8TextGeoProc(color, viewMatrix, tex, params, lum, flags,
usesLocalCoords));
}
static sk_sp<GrGeometryProcessor> Make(GrContext* context,
GrColor color, const SkMatrix& viewMatrix,
sk_sp<GrTextureProxy> proxy,
const GrSamplerParams& params,
float lum, uint32_t flags, bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldA8TextGeoProc(context, color, viewMatrix, std::move(proxy),
params, lum, flags, usesLocalCoords));
}
#else
static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
GrTexture* tex, const GrSamplerParams& params,
uint32_t flags, bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldA8TextGeoProc(color, viewMatrix, tex, params, flags,
usesLocalCoords));
}
static sk_sp<GrGeometryProcessor> Make(GrContext* context,
GrColor color, const SkMatrix& viewMatrix,
sk_sp<GrTextureProxy> proxy,
const GrSamplerParams& params,
uint32_t flags, bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldA8TextGeoProc(context, color, viewMatrix, std::move(proxy),
params, flags, usesLocalCoords));
}
#endif
virtual ~GrDistanceFieldA8TextGeoProc() {}
const char* name() const override { return "DistanceFieldA8Text"; }
const Attribute* inPosition() const { return fInPosition; }
const Attribute* inColor() const { return fInColor; }
const Attribute* inTextureCoords() const { return fInTextureCoords; }
GrColor color() const { return fColor; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
bool usesLocalCoords() const { return fUsesLocalCoords; }
#ifdef SK_GAMMA_APPLY_TO_A8
float getDistanceAdjust() const { return fDistanceAdjust; }
#endif
uint32_t getFlags() const { return fFlags; }
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
private:
GrDistanceFieldA8TextGeoProc(GrColor, const SkMatrix& viewMatrix,
GrTexture* texture, const GrSamplerParams& params,
#ifdef SK_GAMMA_APPLY_TO_A8
float distanceAdjust,
#endif
uint32_t flags, bool usesLocalCoords);
GrDistanceFieldA8TextGeoProc(GrContext*, GrColor, const SkMatrix& viewMatrix,
sk_sp<GrTextureProxy> proxy, const GrSamplerParams& params,
#ifdef SK_GAMMA_APPLY_TO_A8
float distanceAdjust,
#endif
uint32_t flags, bool usesLocalCoords);
GrColor fColor;
SkMatrix fViewMatrix;
TextureSampler fTextureSampler;
#ifdef SK_GAMMA_APPLY_TO_A8
float fDistanceAdjust;
#endif
uint32_t fFlags;
const Attribute* fInPosition;
const Attribute* fInColor;
const Attribute* fInTextureCoords;
bool fUsesLocalCoords;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
typedef GrGeometryProcessor INHERITED;
};
/**
* The output color of this effect is a modulation of the input color and a sample from a
* distance field texture (using a smoothed step function near 0.5).
* It allows explicit specification of the filtering and wrap modes (GrSamplerParams). The input
* coords are a custom attribute. No gamma correct blending is applied. Used for paths only.
*/
class GrDistanceFieldPathGeoProc : public GrGeometryProcessor {
public:
static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
GrTexture* tex, const GrSamplerParams& params,
uint32_t flags, bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldPathGeoProc(color, viewMatrix, tex, params, flags, usesLocalCoords));
}
static sk_sp<GrGeometryProcessor> Make(GrContext* context, GrColor color,
const SkMatrix& viewMatrix, sk_sp<GrTextureProxy> proxy,
const GrSamplerParams& params,
uint32_t flags, bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldPathGeoProc(context, color, viewMatrix, std::move(proxy),
params, flags, usesLocalCoords));
}
~GrDistanceFieldPathGeoProc() override {}
const char* name() const override { return "DistanceFieldPath"; }
const Attribute* inPosition() const { return fInPosition; }
const Attribute* inColor() const { return fInColor; }
const Attribute* inTextureCoords() const { return fInTextureCoords; }
GrColor color() const { return fColor; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
uint32_t getFlags() const { return fFlags; }
bool usesLocalCoords() const { return fUsesLocalCoords; }
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
private:
GrDistanceFieldPathGeoProc(GrColor, const SkMatrix& viewMatrix, GrTexture* texture,
const GrSamplerParams& params, uint32_t flags,
bool usesLocalCoords);
GrDistanceFieldPathGeoProc(GrContext*, GrColor, const SkMatrix& viewMatrix,
sk_sp<GrTextureProxy>, const GrSamplerParams&, uint32_t flags,
bool usesLocalCoords);
GrColor fColor;
SkMatrix fViewMatrix;
TextureSampler fTextureSampler;
uint32_t fFlags;
const Attribute* fInPosition;
const Attribute* fInColor;
const Attribute* fInTextureCoords;
bool fUsesLocalCoords;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
typedef GrGeometryProcessor INHERITED;
};
/**
* The output color of this effect is a modulation of the input color and samples from a
* distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays.
* It allows explicit specification of the filtering and wrap modes (GrSamplerParams). The input
* coords are a custom attribute. Gamma correction is handled via a texture LUT.
*/
class GrDistanceFieldLCDTextGeoProc : public GrGeometryProcessor {
public:
struct DistanceAdjust {
SkScalar fR, fG, fB;
static DistanceAdjust Make(SkScalar r, SkScalar g, SkScalar b) {
DistanceAdjust result;
result.fR = r; result.fG = g; result.fB = b;
return result;
}
bool operator==(const DistanceAdjust& wa) const {
return (fR == wa.fR && fG == wa.fG && fB == wa.fB);
}
bool operator!=(const DistanceAdjust& wa) const {
return !(*this == wa);
}
};
static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
GrTexture* tex, const GrSamplerParams& params,
DistanceAdjust distanceAdjust, uint32_t flags,
bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldLCDTextGeoProc(color, viewMatrix, tex, params, distanceAdjust,
flags, usesLocalCoords));
}
static sk_sp<GrGeometryProcessor> Make(GrContext* context, GrColor color,
const SkMatrix& viewMatrix,
sk_sp<GrTextureProxy> proxy,
const GrSamplerParams& params,
DistanceAdjust distanceAdjust, uint32_t flags,
bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
new GrDistanceFieldLCDTextGeoProc(context, color, viewMatrix, std::move(proxy),
params, distanceAdjust,
flags, usesLocalCoords));
}
~GrDistanceFieldLCDTextGeoProc() override {}
const char* name() const override { return "DistanceFieldLCDText"; }
const Attribute* inPosition() const { return fInPosition; }
const Attribute* inColor() const { return fInColor; }
const Attribute* inTextureCoords() const { return fInTextureCoords; }
DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; }
GrColor color() const { return fColor; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
uint32_t getFlags() const { return fFlags; }
bool usesLocalCoords() const { return fUsesLocalCoords; }
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
private:
GrDistanceFieldLCDTextGeoProc(GrColor, const SkMatrix& viewMatrix,
GrTexture* texture, const GrSamplerParams& params,
DistanceAdjust wa, uint32_t flags,
bool usesLocalCoords);
GrDistanceFieldLCDTextGeoProc(GrContext*, GrColor, const SkMatrix& viewMatrix,
sk_sp<GrTextureProxy> proxy, const GrSamplerParams& params,
DistanceAdjust wa, uint32_t flags,
bool usesLocalCoords);
GrColor fColor;
SkMatrix fViewMatrix;
TextureSampler fTextureSampler;
DistanceAdjust fDistanceAdjust;
uint32_t fFlags;
const Attribute* fInPosition;
const Attribute* fInColor;
const Attribute* fInTextureCoords;
bool fUsesLocalCoords;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
typedef GrGeometryProcessor INHERITED;
};
#endif
|