2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrDistanceFieldTextureEffect_DEFINED
9 #define GrDistanceFieldTextureEffect_DEFINED
11 #include "GrProcessor.h"
12 #include "GrGeometryProcessor.h"
14 class GrGLDistanceFieldTextureEffect;
15 class GrGLDistanceFieldNoGammaTextureEffect;
16 class GrGLDistanceFieldLCDTextureEffect;
17 class GrInvariantOutput;
19 enum GrDistanceFieldEffectFlags {
20 kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix
21 kRectToRect_DistanceFieldEffectFlag = 0x02, // ctm maps rects to rects
22 kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text
23 kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order
24 kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait mode (not used yet)
25 kColorAttr_DistanceFieldEffectFlag = 0x20, // color vertex attribute
27 kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initialization)
29 kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
30 kRectToRect_DistanceFieldEffectFlag,
31 // The subset of the flags relevant to GrDistanceFieldTextureEffect
32 kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
33 kColorAttr_DistanceFieldEffectFlag,
34 // The subset of the flags relevant to GrDistanceFieldLCDTextureEffect
35 kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
36 kRectToRect_DistanceFieldEffectFlag |
37 kUseLCD_DistanceFieldEffectFlag |
38 kBGR_DistanceFieldEffectFlag,
42 * The output color of this effect is a modulation of the input color and a sample from a
43 * distance field texture (using a smoothed step function near 0.5).
44 * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input
45 * coords are a custom attribute. Gamma correction is handled via a texture LUT.
47 class GrDistanceFieldTextureEffect : public GrGeometryProcessor {
49 #ifdef SK_GAMMA_APPLY_TO_A8
50 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, GrTexture* tex,
51 const GrTextureParams& params,
52 GrTexture* gamma, const GrTextureParams& gammaParams,
53 float lum, uint32_t flags, bool opaqueVertexColors) {
54 return SkNEW_ARGS(GrDistanceFieldTextureEffect, (color, viewMatrix, tex, params, gamma,
56 flags, opaqueVertexColors));
59 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, GrTexture* tex,
60 const GrTextureParams& params,
61 uint32_t flags, bool opaqueVertexColors) {
62 return SkNEW_ARGS(GrDistanceFieldTextureEffect, (color, viewMatrix, tex, params, flags,
67 virtual ~GrDistanceFieldTextureEffect() {}
69 const char* name() const override { return "DistanceFieldTexture"; }
71 const Attribute* inPosition() const { return fInPosition; }
72 const Attribute* inColor() const { return fInColor; }
73 const Attribute* inTextureCoords() const { return fInTextureCoords; }
74 #ifdef SK_GAMMA_APPLY_TO_A8
75 float getLuminance() const { return fLuminance; }
77 uint32_t getFlags() const { return fFlags; }
79 virtual void getGLProcessorKey(const GrBatchTracker& bt,
81 GrProcessorKeyBuilder* b) const override;
83 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
84 const GrGLCaps&) const override;
86 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
88 bool onCanMakeEqual(const GrBatchTracker&,
89 const GrGeometryProcessor&,
90 const GrBatchTracker&) const override;
93 GrDistanceFieldTextureEffect(GrColor, const SkMatrix& viewMatrix, GrTexture* texture,
94 const GrTextureParams& params,
95 #ifdef SK_GAMMA_APPLY_TO_A8
96 GrTexture* gamma, const GrTextureParams& gammaParams, float lum,
98 uint32_t flags, bool opaqueVertexColors);
100 bool onIsEqual(const GrGeometryProcessor& other) const override;
102 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override;
104 GrTextureAccess fTextureAccess;
105 #ifdef SK_GAMMA_APPLY_TO_A8
106 GrTextureAccess fGammaTextureAccess;
110 const Attribute* fInPosition;
111 const Attribute* fInColor;
112 const Attribute* fInTextureCoords;
114 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
116 typedef GrGeometryProcessor INHERITED;
121 * The output color of this effect is a modulation of the input color and a sample from a
122 * distance field texture (using a smoothed step function near 0.5).
123 * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input
124 * coords are a custom attribute. No gamma correct blending is applied.
126 class GrDistanceFieldNoGammaTextureEffect : public GrGeometryProcessor {
128 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, GrTexture* tex,
129 const GrTextureParams& params,
130 uint32_t flags, bool opaqueVertexColors) {
131 return SkNEW_ARGS(GrDistanceFieldNoGammaTextureEffect, (color, viewMatrix, tex, params,
132 flags, opaqueVertexColors));
135 virtual ~GrDistanceFieldNoGammaTextureEffect() {}
137 const char* name() const override { return "DistanceFieldTexture"; }
139 const Attribute* inPosition() const { return fInPosition; }
140 const Attribute* inColor() const { return fInColor; }
141 const Attribute* inTextureCoords() const { return fInTextureCoords; }
142 uint32_t getFlags() const { return fFlags; }
144 virtual void getGLProcessorKey(const GrBatchTracker& bt,
145 const GrGLCaps& caps,
146 GrProcessorKeyBuilder* b) const override;
148 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
149 const GrGLCaps&) const override;
151 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
153 bool onCanMakeEqual(const GrBatchTracker&,
154 const GrGeometryProcessor&,
155 const GrBatchTracker&) const override;
158 GrDistanceFieldNoGammaTextureEffect(GrColor, const SkMatrix& viewMatrix, GrTexture* texture,
159 const GrTextureParams& params, uint32_t flags,
160 bool opaqueVertexColors);
162 bool onIsEqual(const GrGeometryProcessor& other) const override;
164 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override;
166 GrTextureAccess fTextureAccess;
168 const Attribute* fInPosition;
169 const Attribute* fInColor;
170 const Attribute* fInTextureCoords;
172 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
174 typedef GrGeometryProcessor INHERITED;
178 * The output color of this effect is a modulation of the input color and samples from a
179 * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays.
180 * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input
181 * coords are a custom attribute. Gamma correction is handled via a texture LUT.
183 class GrDistanceFieldLCDTextureEffect : public GrGeometryProcessor {
185 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, GrTexture* tex,
186 const GrTextureParams& params, GrTexture* gamma,
187 const GrTextureParams& gammaParams,
188 SkColor textColor, uint32_t flags) {
189 return SkNEW_ARGS(GrDistanceFieldLCDTextureEffect,
190 (color, viewMatrix, tex, params, gamma, gammaParams, textColor, flags));
193 virtual ~GrDistanceFieldLCDTextureEffect() {}
195 const char* name() const override { return "DistanceFieldLCDTexture"; }
197 const Attribute* inPosition() const { return fInPosition; }
198 const Attribute* inTextureCoords() const { return fInTextureCoords; }
199 GrColor getTextColor() const { return fTextColor; }
200 uint32_t getFlags() const { return fFlags; }
202 virtual void getGLProcessorKey(const GrBatchTracker& bt,
203 const GrGLCaps& caps,
204 GrProcessorKeyBuilder* b) const override;
206 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
207 const GrGLCaps&) const override;
209 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
211 bool onCanMakeEqual(const GrBatchTracker&,
212 const GrGeometryProcessor&,
213 const GrBatchTracker&) const override;
216 GrDistanceFieldLCDTextureEffect(GrColor, const SkMatrix& viewMatrix, GrTexture* texture,
217 const GrTextureParams& params,
218 GrTexture* gamma, const GrTextureParams& gammaParams,
219 SkColor textColor, uint32_t flags);
221 bool onIsEqual(const GrGeometryProcessor& other) const override;
223 void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override;
225 GrTextureAccess fTextureAccess;
226 GrTextureAccess fGammaTextureAccess;
229 const Attribute* fInPosition;
230 const Attribute* fInTextureCoords;
232 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
234 typedef GrGeometryProcessor INHERITED;