blob: 1d6d2b4a41f8f523aee47bc35829ec2bfb0b5e65 [file] [log] [blame]
jvanverth@google.comd830d132013-11-11 20:54:09 +00001/*
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
jvanverth502286d2015-04-08 12:37:51 -07008#ifndef GrDistanceFieldGeoProc_DEFINED
9#define GrDistanceFieldGeoProc_DEFINED
jvanverth@google.comd830d132013-11-11 20:54:09 +000010
joshualittb0a8a372014-09-23 09:50:21 -070011#include "GrProcessor.h"
joshualitt249af152014-09-15 11:41:13 -070012#include "GrGeometryProcessor.h"
jvanverth@google.comd830d132013-11-11 20:54:09 +000013
jvanverth502286d2015-04-08 12:37:51 -070014class GrGLDistanceFieldA8TextGeoProc;
15class GrGLDistanceFieldPathGeoProc;
16class GrGLDistanceFieldLCDTextGeoProc;
egdaniel605dd0f2014-11-12 08:35:25 -080017class GrInvariantOutput;
jvanverth@google.comd830d132013-11-11 20:54:09 +000018
jvanverth78f07182014-07-30 06:17:59 -070019enum GrDistanceFieldEffectFlags {
brianosmanb461d342016-04-13 13:10:14 -070020 kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix
21 kScaleOnly_DistanceFieldEffectFlag = 0x02, // ctm has only scale and translate
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 kGammaCorrect_DistanceFieldEffectFlag = 0x20, // assume gamma-correct output (linear blending)
Jim Van Verth90e89b32017-07-06 16:36:55 -040026 kAliased_DistanceFieldEffectFlag = 0x40, // monochrome output
jvanverth6d22eca2014-10-28 11:10:48 -070027
28 kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initialization)
halcanary9d524f22016-03-29 09:03:52 -070029
jvanverth78f07182014-07-30 06:17:59 -070030 kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
jvanverthcf371bb2016-03-10 11:10:43 -080031 kScaleOnly_DistanceFieldEffectFlag,
jvanverth502286d2015-04-08 12:37:51 -070032 // The subset of the flags relevant to GrDistanceFieldA8TextGeoProc
jvanverthcf371bb2016-03-10 11:10:43 -080033 kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
brianosman0586f5c2016-04-12 12:48:21 -070034 kScaleOnly_DistanceFieldEffectFlag |
Jim Van Verth90e89b32017-07-06 16:36:55 -040035 kGammaCorrect_DistanceFieldEffectFlag |
36 kAliased_DistanceFieldEffectFlag,
jvanverth502286d2015-04-08 12:37:51 -070037 // The subset of the flags relevant to GrDistanceFieldLCDTextGeoProc
jvanverth78f07182014-07-30 06:17:59 -070038 kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
jvanverthcf371bb2016-03-10 11:10:43 -080039 kScaleOnly_DistanceFieldEffectFlag |
jvanverth78f07182014-07-30 06:17:59 -070040 kUseLCD_DistanceFieldEffectFlag |
brianosman0586f5c2016-04-12 12:48:21 -070041 kBGR_DistanceFieldEffectFlag |
brianosmanb461d342016-04-13 13:10:14 -070042 kGammaCorrect_DistanceFieldEffectFlag,
jvanverth78f07182014-07-30 06:17:59 -070043};
44
jvanverth@google.comd830d132013-11-11 20:54:09 +000045/**
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000046 * The output color of this effect is a modulation of the input color and a sample from a
jvanverth@google.comd830d132013-11-11 20:54:09 +000047 * distance field texture (using a smoothed step function near 0.5).
Brian Salomon2bbdcc42017-09-07 12:36:34 -040048 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
jvanverth2d2a68c2014-06-10 06:42:56 -070049 * coords are a custom attribute. Gamma correction is handled via a texture LUT.
jvanverth@google.comd830d132013-11-11 20:54:09 +000050 */
jvanverth502286d2015-04-08 12:37:51 -070051class GrDistanceFieldA8TextGeoProc : public GrGeometryProcessor {
jvanverth@google.comd830d132013-11-11 20:54:09 +000052public:
Jim Van Vertha950b632017-09-12 11:54:11 -040053 static constexpr int kMaxTextures = 4;
54
jvanverth2d2a68c2014-06-10 06:42:56 -070055#ifdef SK_GAMMA_APPLY_TO_A8
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040056 static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
Jim Van Vertha950b632017-09-12 11:54:11 -040057 const sk_sp<GrTextureProxy> proxies[kMaxTextures],
Brian Salomon2bbdcc42017-09-07 12:36:34 -040058 const GrSamplerState& params, float lum, uint32_t flags,
59 bool usesLocalCoords) {
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050060 return sk_sp<GrGeometryProcessor>(
Jim Van Vertha950b632017-09-12 11:54:11 -040061 new GrDistanceFieldA8TextGeoProc(color, viewMatrix, proxies,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050062 params, lum, flags, usesLocalCoords));
63 }
jvanverth2d2a68c2014-06-10 06:42:56 -070064#else
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040065 static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
Jim Van Vertha950b632017-09-12 11:54:11 -040066 const sk_sp<GrTextureProxy> proxies[kMaxTextures],
Brian Salomon2bbdcc42017-09-07 12:36:34 -040067 const GrSamplerState& params, uint32_t flags,
68 bool usesLocalCoords) {
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050069 return sk_sp<GrGeometryProcessor>(
Jim Van Vertha950b632017-09-12 11:54:11 -040070 new GrDistanceFieldA8TextGeoProc(color, viewMatrix, proxies,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050071 params, flags, usesLocalCoords));
72 }
bsalomon55fad7a2014-07-08 07:34:20 -070073#endif
jvanverth@google.comd830d132013-11-11 20:54:09 +000074
Brian Salomond3b65972017-03-22 12:05:03 -040075 ~GrDistanceFieldA8TextGeoProc() override {}
jvanverth@google.comd830d132013-11-11 20:54:09 +000076
bsalomon32d1e952016-09-15 07:29:52 -070077 const char* name() const override { return "DistanceFieldA8Text"; }
jvanverth@google.comd830d132013-11-11 20:54:09 +000078
joshualitt71c92602015-01-14 08:12:47 -080079 const Attribute* inPosition() const { return fInPosition; }
80 const Attribute* inColor() const { return fInColor; }
81 const Attribute* inTextureCoords() const { return fInTextureCoords; }
joshualitt88c23fc2015-05-13 14:18:07 -070082 GrColor color() const { return fColor; }
joshualitte578a952015-05-14 10:09:13 -070083 const SkMatrix& viewMatrix() const { return fViewMatrix; }
joshualittb8c241a2015-05-19 08:23:30 -070084 bool usesLocalCoords() const { return fUsesLocalCoords; }
jvanverth2d2a68c2014-06-10 06:42:56 -070085#ifdef SK_GAMMA_APPLY_TO_A8
jvanverth21deace2015-04-01 12:43:48 -070086 float getDistanceAdjust() const { return fDistanceAdjust; }
jvanverth2d2a68c2014-06-10 06:42:56 -070087#endif
jvanverth78f07182014-07-30 06:17:59 -070088 uint32_t getFlags() const { return fFlags; }
jvanverth@google.comd830d132013-11-11 20:54:09 +000089
Jim Van Vertheafa64b2017-09-18 10:05:00 -040090 void addNewProxies(const sk_sp<GrTextureProxy> proxies[kMaxTextures], const GrSamplerState& p);
91
Brian Salomon94efbf52016-11-29 13:43:05 -050092 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
jvanverth@google.comd830d132013-11-11 20:54:09 +000093
Brian Salomon94efbf52016-11-29 13:43:05 -050094 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
jvanverth@google.comd830d132013-11-11 20:54:09 +000095
96private:
Jim Van Vertha950b632017-09-12 11:54:11 -040097 GrDistanceFieldA8TextGeoProc(GrColor, const SkMatrix& viewMatrix,
98 const sk_sp<GrTextureProxy> proxies[kMaxTextures],
Brian Salomon2bbdcc42017-09-07 12:36:34 -040099 const GrSamplerState& params,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500100#ifdef SK_GAMMA_APPLY_TO_A8
101 float distanceAdjust,
102#endif
103 uint32_t flags, bool usesLocalCoords);
104
joshualitt88c23fc2015-05-13 14:18:07 -0700105 GrColor fColor;
joshualitte578a952015-05-14 10:09:13 -0700106 SkMatrix fViewMatrix;
Jim Van Vertha950b632017-09-12 11:54:11 -0400107 TextureSampler fTextureSamplers[kMaxTextures];
jvanverth2d2a68c2014-06-10 06:42:56 -0700108#ifdef SK_GAMMA_APPLY_TO_A8
jvanverth21deace2015-04-01 12:43:48 -0700109 float fDistanceAdjust;
jvanverth2d2a68c2014-06-10 06:42:56 -0700110#endif
jvanverth21deace2015-04-01 12:43:48 -0700111 uint32_t fFlags;
joshualitt71c92602015-01-14 08:12:47 -0800112 const Attribute* fInPosition;
113 const Attribute* fInColor;
114 const Attribute* fInTextureCoords;
joshualittb8c241a2015-05-19 08:23:30 -0700115 bool fUsesLocalCoords;
jvanverth@google.comd830d132013-11-11 20:54:09 +0000116
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400117 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
jvanverth@google.comd830d132013-11-11 20:54:09 +0000118
jvanverthfa38a302014-10-06 05:59:05 -0700119 typedef GrGeometryProcessor INHERITED;
120};
121
jvanverthfa38a302014-10-06 05:59:05 -0700122/**
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400123 * The output color of this effect is a modulation of the input color and a sample from a
124 * distance field texture (using a smoothed step function near 0.5).
125 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
126 * coords are a custom attribute. No gamma correct blending is applied. Used for paths only.
127 */
jvanverth502286d2015-04-08 12:37:51 -0700128class GrDistanceFieldPathGeoProc : public GrGeometryProcessor {
jvanverthfa38a302014-10-06 05:59:05 -0700129public:
Jim Van Vertha950b632017-09-12 11:54:11 -0400130 static constexpr int kMaxTextures = 4;
131
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400132 static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
Jim Van Vertha950b632017-09-12 11:54:11 -0400133 const sk_sp<GrTextureProxy> proxies[kMaxTextures],
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400134 const GrSamplerState& params, uint32_t flags,
135 bool usesLocalCoords) {
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500136 return sk_sp<GrGeometryProcessor>(
Jim Van Vertha950b632017-09-12 11:54:11 -0400137 new GrDistanceFieldPathGeoProc(color, viewMatrix, proxies,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500138 params, flags, usesLocalCoords));
139 }
140
141 ~GrDistanceFieldPathGeoProc() override {}
jvanverthfa38a302014-10-06 05:59:05 -0700142
bsalomon32d1e952016-09-15 07:29:52 -0700143 const char* name() const override { return "DistanceFieldPath"; }
jvanverthfa38a302014-10-06 05:59:05 -0700144
joshualitt71c92602015-01-14 08:12:47 -0800145 const Attribute* inPosition() const { return fInPosition; }
146 const Attribute* inColor() const { return fInColor; }
147 const Attribute* inTextureCoords() const { return fInTextureCoords; }
joshualitt88c23fc2015-05-13 14:18:07 -0700148 GrColor color() const { return fColor; }
joshualitte578a952015-05-14 10:09:13 -0700149 const SkMatrix& viewMatrix() const { return fViewMatrix; }
jvanverthfa38a302014-10-06 05:59:05 -0700150 uint32_t getFlags() const { return fFlags; }
joshualittb8c241a2015-05-19 08:23:30 -0700151 bool usesLocalCoords() const { return fUsesLocalCoords; }
jvanverthfa38a302014-10-06 05:59:05 -0700152
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400153 void addNewProxies(const sk_sp<GrTextureProxy> proxies[kMaxTextures], const GrSamplerState& p);
154
Brian Salomon94efbf52016-11-29 13:43:05 -0500155 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
jvanverthfa38a302014-10-06 05:59:05 -0700156
Brian Salomon94efbf52016-11-29 13:43:05 -0500157 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
jvanverthfa38a302014-10-06 05:59:05 -0700158
159private:
Jim Van Vertha950b632017-09-12 11:54:11 -0400160 GrDistanceFieldPathGeoProc(GrColor, const SkMatrix& viewMatrix,
161 const sk_sp<GrTextureProxy> proxies[kMaxTextures],
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400162 const GrSamplerState&, uint32_t flags, bool usesLocalCoords);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500163
joshualitt88c23fc2015-05-13 14:18:07 -0700164 GrColor fColor;
joshualitte578a952015-05-14 10:09:13 -0700165 SkMatrix fViewMatrix;
Jim Van Vertha950b632017-09-12 11:54:11 -0400166 TextureSampler fTextureSamplers[kMaxTextures];
joshualitt88c23fc2015-05-13 14:18:07 -0700167 uint32_t fFlags;
joshualitt71c92602015-01-14 08:12:47 -0800168 const Attribute* fInPosition;
169 const Attribute* fInColor;
170 const Attribute* fInTextureCoords;
joshualittb8c241a2015-05-19 08:23:30 -0700171 bool fUsesLocalCoords;
jvanverthfa38a302014-10-06 05:59:05 -0700172
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400173 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
jvanverthfa38a302014-10-06 05:59:05 -0700174
175 typedef GrGeometryProcessor INHERITED;
jvanverth@google.comd830d132013-11-11 20:54:09 +0000176};
177
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000178/**
179 * The output color of this effect is a modulation of the input color and samples from a
180 * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays.
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400181 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
jvanverth2d2a68c2014-06-10 06:42:56 -0700182 * coords are a custom attribute. Gamma correction is handled via a texture LUT.
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000183 */
jvanverth502286d2015-04-08 12:37:51 -0700184class GrDistanceFieldLCDTextGeoProc : public GrGeometryProcessor {
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000185public:
jvanverth21deace2015-04-01 12:43:48 -0700186 struct DistanceAdjust {
187 SkScalar fR, fG, fB;
188 static DistanceAdjust Make(SkScalar r, SkScalar g, SkScalar b) {
189 DistanceAdjust result;
190 result.fR = r; result.fG = g; result.fB = b;
191 return result;
192 }
193 bool operator==(const DistanceAdjust& wa) const {
194 return (fR == wa.fR && fG == wa.fG && fB == wa.fB);
195 }
196 bool operator!=(const DistanceAdjust& wa) const {
197 return !(*this == wa);
198 }
199 };
200
Jim Van Vertha950b632017-09-12 11:54:11 -0400201 static constexpr int kMaxTextures = 4;
202
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400203 static sk_sp<GrGeometryProcessor> Make(GrColor color,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500204 const SkMatrix& viewMatrix,
Jim Van Vertha950b632017-09-12 11:54:11 -0400205 const sk_sp<GrTextureProxy> proxies[kMaxTextures],
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400206 const GrSamplerState& params,
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400207 DistanceAdjust distanceAdjust,
208 uint32_t flags,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500209 bool usesLocalCoords) {
210 return sk_sp<GrGeometryProcessor>(
Jim Van Vertha950b632017-09-12 11:54:11 -0400211 new GrDistanceFieldLCDTextGeoProc(color, viewMatrix, proxies,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500212 params, distanceAdjust,
213 flags, usesLocalCoords));
214 }
215
216 ~GrDistanceFieldLCDTextGeoProc() override {}
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000217
bsalomon32d1e952016-09-15 07:29:52 -0700218 const char* name() const override { return "DistanceFieldLCDText"; }
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000219
joshualitt71c92602015-01-14 08:12:47 -0800220 const Attribute* inPosition() const { return fInPosition; }
joshualittd9d30f72015-12-08 10:47:55 -0800221 const Attribute* inColor() const { return fInColor; }
joshualitt71c92602015-01-14 08:12:47 -0800222 const Attribute* inTextureCoords() const { return fInTextureCoords; }
jvanverth21deace2015-04-01 12:43:48 -0700223 DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; }
joshualitt88c23fc2015-05-13 14:18:07 -0700224 GrColor color() const { return fColor; }
joshualitte578a952015-05-14 10:09:13 -0700225 const SkMatrix& viewMatrix() const { return fViewMatrix; }
jvanverth78f07182014-07-30 06:17:59 -0700226 uint32_t getFlags() const { return fFlags; }
joshualittb8c241a2015-05-19 08:23:30 -0700227 bool usesLocalCoords() const { return fUsesLocalCoords; }
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000228
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400229 void addNewProxies(const sk_sp<GrTextureProxy> proxies[kMaxTextures], const GrSamplerState& p);
230
Brian Salomon94efbf52016-11-29 13:43:05 -0500231 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000232
Brian Salomon94efbf52016-11-29 13:43:05 -0500233 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000234
235private:
Jim Van Vertha950b632017-09-12 11:54:11 -0400236 GrDistanceFieldLCDTextGeoProc(GrColor, const SkMatrix& viewMatrix,
237 const sk_sp<GrTextureProxy> proxies[kMaxTextures],
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400238 const GrSamplerState& params, DistanceAdjust wa, uint32_t flags,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500239 bool usesLocalCoords);
240
joshualitt88c23fc2015-05-13 14:18:07 -0700241 GrColor fColor;
joshualitte578a952015-05-14 10:09:13 -0700242 SkMatrix fViewMatrix;
Jim Van Vertha950b632017-09-12 11:54:11 -0400243 TextureSampler fTextureSamplers[kMaxTextures];
jvanverth21deace2015-04-01 12:43:48 -0700244 DistanceAdjust fDistanceAdjust;
245 uint32_t fFlags;
joshualitt71c92602015-01-14 08:12:47 -0800246 const Attribute* fInPosition;
joshualittd9d30f72015-12-08 10:47:55 -0800247 const Attribute* fInColor;
joshualitt71c92602015-01-14 08:12:47 -0800248 const Attribute* fInTextureCoords;
joshualittb8c241a2015-05-19 08:23:30 -0700249 bool fUsesLocalCoords;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000250
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400251 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000252
jvanverthfa38a302014-10-06 05:59:05 -0700253 typedef GrGeometryProcessor INHERITED;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000254};
255
jvanverth@google.comd830d132013-11-11 20:54:09 +0000256#endif