C++11 override should now be supported by all of {bots,Chrome,Android,Mozilla}
[platform/upstream/libSkiaSharp.git] / src / gpu / effects / GrDistanceFieldTextureEffect.h
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #ifndef GrDistanceFieldTextureEffect_DEFINED
9 #define GrDistanceFieldTextureEffect_DEFINED
10
11 #include "GrProcessor.h"
12 #include "GrGeometryProcessor.h"
13
14 class GrGLDistanceFieldTextureEffect;
15 class GrGLDistanceFieldNoGammaTextureEffect;
16 class GrGLDistanceFieldLCDTextureEffect;
17 class GrInvariantOutput;
18
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
26
27     kInvalid_DistanceFieldEffectFlag    = 0x80,   // invalid state (for initialization)
28     
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,
39 };
40
41 /**
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.
46  */
47 class GrDistanceFieldTextureEffect : public GrGeometryProcessor {
48 public:
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,
55                                                         gammaParams, lum,
56                                                         flags, opaqueVertexColors));
57     }
58 #else
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,
63                                                           opaqueVertexColors));
64     }
65 #endif
66
67     virtual ~GrDistanceFieldTextureEffect() {}
68
69     const char* name() const override { return "DistanceFieldTexture"; }
70
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; }
76 #endif
77     uint32_t getFlags() const { return fFlags; }
78
79     virtual void getGLProcessorKey(const GrBatchTracker& bt,
80                                    const GrGLCaps& caps,
81                                    GrProcessorKeyBuilder* b) const override;
82
83     virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
84                                                      const GrGLCaps&) const override;
85
86     void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
87
88     bool onCanMakeEqual(const GrBatchTracker&,
89                         const GrGeometryProcessor&,
90                         const GrBatchTracker&) const override;
91
92 private:
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,
97 #endif
98                                  uint32_t flags, bool opaqueVertexColors);
99
100     bool onIsEqual(const GrGeometryProcessor& other) const override;
101
102     void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override;
103
104     GrTextureAccess    fTextureAccess;
105 #ifdef SK_GAMMA_APPLY_TO_A8
106     GrTextureAccess    fGammaTextureAccess;
107     float              fLuminance;
108 #endif
109     uint32_t           fFlags;
110     const Attribute* fInPosition;
111     const Attribute* fInColor;
112     const Attribute* fInTextureCoords;
113
114     GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
115
116     typedef GrGeometryProcessor INHERITED;
117 };
118
119
120 /**
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.
125 */
126 class GrDistanceFieldNoGammaTextureEffect : public GrGeometryProcessor {
127 public:
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));
133     }
134
135     virtual ~GrDistanceFieldNoGammaTextureEffect() {}
136
137     const char* name() const override { return "DistanceFieldTexture"; }
138
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; }
143
144     virtual void getGLProcessorKey(const GrBatchTracker& bt,
145                                    const GrGLCaps& caps,
146                                    GrProcessorKeyBuilder* b) const override;
147
148     virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
149                                                      const GrGLCaps&) const override;
150
151     void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
152
153     bool onCanMakeEqual(const GrBatchTracker&,
154                         const GrGeometryProcessor&,
155                         const GrBatchTracker&) const override;
156
157 private:
158     GrDistanceFieldNoGammaTextureEffect(GrColor, const SkMatrix& viewMatrix, GrTexture* texture,
159                                         const GrTextureParams& params, uint32_t flags,
160                                         bool opaqueVertexColors);
161
162     bool onIsEqual(const GrGeometryProcessor& other) const override;
163
164     void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override;
165
166     GrTextureAccess    fTextureAccess;
167     uint32_t           fFlags;
168     const Attribute* fInPosition;
169     const Attribute* fInColor;
170     const Attribute* fInTextureCoords;
171
172     GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
173
174     typedef GrGeometryProcessor INHERITED;
175 };
176
177 /**
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.
182  */
183 class GrDistanceFieldLCDTextureEffect : public GrGeometryProcessor {
184 public:
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));
191     }
192
193     virtual ~GrDistanceFieldLCDTextureEffect() {}
194
195     const char* name() const override { return "DistanceFieldLCDTexture"; }
196
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; }
201
202     virtual void getGLProcessorKey(const GrBatchTracker& bt,
203                                    const GrGLCaps& caps,
204                                    GrProcessorKeyBuilder* b) const override;
205
206     virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
207                                                      const GrGLCaps&) const override;
208
209     void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
210
211     bool onCanMakeEqual(const GrBatchTracker&,
212                         const GrGeometryProcessor&,
213                         const GrBatchTracker&) const override;
214
215 private:
216     GrDistanceFieldLCDTextureEffect(GrColor, const SkMatrix& viewMatrix, GrTexture* texture,
217                                     const GrTextureParams& params,
218                                     GrTexture* gamma, const GrTextureParams& gammaParams,
219                                     SkColor textColor, uint32_t flags);
220
221     bool onIsEqual(const GrGeometryProcessor& other) const override;
222
223     void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const override;
224
225     GrTextureAccess    fTextureAccess;
226     GrTextureAccess    fGammaTextureAccess;
227     GrColor            fTextColor;
228     uint32_t           fFlags;
229     const Attribute* fInPosition;
230     const Attribute* fInTextureCoords;
231
232     GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
233
234     typedef GrGeometryProcessor INHERITED;
235 };
236
237 #endif