blob: 344ac4a0922d9209e1a055f0bcffaa4dfbe45f04 [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 Salomon514baff2016-11-17 15:17:07 -050048 * It allows explicit specification of the filtering and wrap modes (GrSamplerParams). 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:
jvanverth2d2a68c2014-06-10 06:42:56 -070053#ifdef SK_GAMMA_APPLY_TO_A8
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040054 static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050055 sk_sp<GrTextureProxy> proxy,
56 const GrSamplerParams& params,
57 float lum, uint32_t flags, bool usesLocalCoords) {
58 return sk_sp<GrGeometryProcessor>(
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040059 new GrDistanceFieldA8TextGeoProc(color, viewMatrix, std::move(proxy),
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050060 params, lum, flags, usesLocalCoords));
61 }
jvanverth2d2a68c2014-06-10 06:42:56 -070062#else
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040063 static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& viewMatrix,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050064 sk_sp<GrTextureProxy> proxy,
65 const GrSamplerParams& params,
66 uint32_t flags, bool usesLocalCoords) {
67 return sk_sp<GrGeometryProcessor>(
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040068 new GrDistanceFieldA8TextGeoProc(color, viewMatrix, std::move(proxy),
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050069 params, flags, usesLocalCoords));
70 }
bsalomon55fad7a2014-07-08 07:34:20 -070071#endif
jvanverth@google.comd830d132013-11-11 20:54:09 +000072
Brian Salomond3b65972017-03-22 12:05:03 -040073 ~GrDistanceFieldA8TextGeoProc() override {}
jvanverth@google.comd830d132013-11-11 20:54:09 +000074
bsalomon32d1e952016-09-15 07:29:52 -070075 const char* name() const override { return "DistanceFieldA8Text"; }
jvanverth@google.comd830d132013-11-11 20:54:09 +000076
joshualitt71c92602015-01-14 08:12:47 -080077 const Attribute* inPosition() const { return fInPosition; }
78 const Attribute* inColor() const { return fInColor; }
79 const Attribute* inTextureCoords() const { return fInTextureCoords; }
joshualitt88c23fc2015-05-13 14:18:07 -070080 GrColor color() const { return fColor; }
joshualitte578a952015-05-14 10:09:13 -070081 const SkMatrix& viewMatrix() const { return fViewMatrix; }
joshualittb8c241a2015-05-19 08:23:30 -070082 bool usesLocalCoords() const { return fUsesLocalCoords; }
jvanverth2d2a68c2014-06-10 06:42:56 -070083#ifdef SK_GAMMA_APPLY_TO_A8
jvanverth21deace2015-04-01 12:43:48 -070084 float getDistanceAdjust() const { return fDistanceAdjust; }
jvanverth2d2a68c2014-06-10 06:42:56 -070085#endif
jvanverth78f07182014-07-30 06:17:59 -070086 uint32_t getFlags() const { return fFlags; }
jvanverth@google.comd830d132013-11-11 20:54:09 +000087
Brian Salomon94efbf52016-11-29 13:43:05 -050088 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
jvanverth@google.comd830d132013-11-11 20:54:09 +000089
Brian Salomon94efbf52016-11-29 13:43:05 -050090 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
jvanverth@google.comd830d132013-11-11 20:54:09 +000091
92private:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040093 GrDistanceFieldA8TextGeoProc(GrColor, const SkMatrix& viewMatrix,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050094 sk_sp<GrTextureProxy> proxy, const GrSamplerParams& params,
95#ifdef SK_GAMMA_APPLY_TO_A8
96 float distanceAdjust,
97#endif
98 uint32_t flags, bool usesLocalCoords);
99
joshualitt88c23fc2015-05-13 14:18:07 -0700100 GrColor fColor;
joshualitte578a952015-05-14 10:09:13 -0700101 SkMatrix fViewMatrix;
Brian Salomon0bbecb22016-11-17 11:38:22 -0500102 TextureSampler fTextureSampler;
jvanverth2d2a68c2014-06-10 06:42:56 -0700103#ifdef SK_GAMMA_APPLY_TO_A8
jvanverth21deace2015-04-01 12:43:48 -0700104 float fDistanceAdjust;
jvanverth2d2a68c2014-06-10 06:42:56 -0700105#endif
jvanverth21deace2015-04-01 12:43:48 -0700106 uint32_t fFlags;
joshualitt71c92602015-01-14 08:12:47 -0800107 const Attribute* fInPosition;
108 const Attribute* fInColor;
109 const Attribute* fInTextureCoords;
joshualittb8c241a2015-05-19 08:23:30 -0700110 bool fUsesLocalCoords;
jvanverth@google.comd830d132013-11-11 20:54:09 +0000111
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400112 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
jvanverth@google.comd830d132013-11-11 20:54:09 +0000113
jvanverthfa38a302014-10-06 05:59:05 -0700114 typedef GrGeometryProcessor INHERITED;
115};
116
117
118/**
119* The output color of this effect is a modulation of the input color and a sample from a
120* distance field texture (using a smoothed step function near 0.5).
Brian Salomon514baff2016-11-17 15:17:07 -0500121* It allows explicit specification of the filtering and wrap modes (GrSamplerParams). The input
jvanverth502286d2015-04-08 12:37:51 -0700122* coords are a custom attribute. No gamma correct blending is applied. Used for paths only.
jvanverthfa38a302014-10-06 05:59:05 -0700123*/
jvanverth502286d2015-04-08 12:37:51 -0700124class GrDistanceFieldPathGeoProc : public GrGeometryProcessor {
jvanverthfa38a302014-10-06 05:59:05 -0700125public:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400126 static sk_sp<GrGeometryProcessor> Make(GrColor color,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500127 const SkMatrix& viewMatrix, sk_sp<GrTextureProxy> proxy,
128 const GrSamplerParams& params,
129 uint32_t flags, bool usesLocalCoords) {
130 return sk_sp<GrGeometryProcessor>(
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400131 new GrDistanceFieldPathGeoProc(color, viewMatrix, std::move(proxy),
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500132 params, flags, usesLocalCoords));
133 }
134
135 ~GrDistanceFieldPathGeoProc() override {}
jvanverthfa38a302014-10-06 05:59:05 -0700136
bsalomon32d1e952016-09-15 07:29:52 -0700137 const char* name() const override { return "DistanceFieldPath"; }
jvanverthfa38a302014-10-06 05:59:05 -0700138
joshualitt71c92602015-01-14 08:12:47 -0800139 const Attribute* inPosition() const { return fInPosition; }
140 const Attribute* inColor() const { return fInColor; }
141 const Attribute* inTextureCoords() const { return fInTextureCoords; }
joshualitt88c23fc2015-05-13 14:18:07 -0700142 GrColor color() const { return fColor; }
joshualitte578a952015-05-14 10:09:13 -0700143 const SkMatrix& viewMatrix() const { return fViewMatrix; }
jvanverthfa38a302014-10-06 05:59:05 -0700144 uint32_t getFlags() const { return fFlags; }
joshualittb8c241a2015-05-19 08:23:30 -0700145 bool usesLocalCoords() const { return fUsesLocalCoords; }
jvanverthfa38a302014-10-06 05:59:05 -0700146
Brian Salomon94efbf52016-11-29 13:43:05 -0500147 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
jvanverthfa38a302014-10-06 05:59:05 -0700148
Brian Salomon94efbf52016-11-29 13:43:05 -0500149 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
jvanverthfa38a302014-10-06 05:59:05 -0700150
151private:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400152 GrDistanceFieldPathGeoProc(GrColor, const SkMatrix& viewMatrix,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500153 sk_sp<GrTextureProxy>, const GrSamplerParams&, uint32_t flags,
154 bool usesLocalCoords);
155
joshualitt88c23fc2015-05-13 14:18:07 -0700156 GrColor fColor;
joshualitte578a952015-05-14 10:09:13 -0700157 SkMatrix fViewMatrix;
Brian Salomon0bbecb22016-11-17 11:38:22 -0500158 TextureSampler fTextureSampler;
joshualitt88c23fc2015-05-13 14:18:07 -0700159 uint32_t fFlags;
joshualitt71c92602015-01-14 08:12:47 -0800160 const Attribute* fInPosition;
161 const Attribute* fInColor;
162 const Attribute* fInTextureCoords;
joshualittb8c241a2015-05-19 08:23:30 -0700163 bool fUsesLocalCoords;
jvanverthfa38a302014-10-06 05:59:05 -0700164
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400165 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
jvanverthfa38a302014-10-06 05:59:05 -0700166
167 typedef GrGeometryProcessor INHERITED;
jvanverth@google.comd830d132013-11-11 20:54:09 +0000168};
169
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000170/**
171 * The output color of this effect is a modulation of the input color and samples from a
172 * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays.
Brian Salomon514baff2016-11-17 15:17:07 -0500173 * It allows explicit specification of the filtering and wrap modes (GrSamplerParams). The input
jvanverth2d2a68c2014-06-10 06:42:56 -0700174 * coords are a custom attribute. Gamma correction is handled via a texture LUT.
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000175 */
jvanverth502286d2015-04-08 12:37:51 -0700176class GrDistanceFieldLCDTextGeoProc : public GrGeometryProcessor {
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000177public:
jvanverth21deace2015-04-01 12:43:48 -0700178 struct DistanceAdjust {
179 SkScalar fR, fG, fB;
180 static DistanceAdjust Make(SkScalar r, SkScalar g, SkScalar b) {
181 DistanceAdjust result;
182 result.fR = r; result.fG = g; result.fB = b;
183 return result;
184 }
185 bool operator==(const DistanceAdjust& wa) const {
186 return (fR == wa.fR && fG == wa.fG && fB == wa.fB);
187 }
188 bool operator!=(const DistanceAdjust& wa) const {
189 return !(*this == wa);
190 }
191 };
192
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400193 static sk_sp<GrGeometryProcessor> Make(GrColor color,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500194 const SkMatrix& viewMatrix,
195 sk_sp<GrTextureProxy> proxy,
196 const GrSamplerParams& params,
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400197 DistanceAdjust distanceAdjust,
198 uint32_t flags,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500199 bool usesLocalCoords) {
200 return sk_sp<GrGeometryProcessor>(
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400201 new GrDistanceFieldLCDTextGeoProc(color, viewMatrix, std::move(proxy),
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500202 params, distanceAdjust,
203 flags, usesLocalCoords));
204 }
205
206 ~GrDistanceFieldLCDTextGeoProc() override {}
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000207
bsalomon32d1e952016-09-15 07:29:52 -0700208 const char* name() const override { return "DistanceFieldLCDText"; }
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000209
joshualitt71c92602015-01-14 08:12:47 -0800210 const Attribute* inPosition() const { return fInPosition; }
joshualittd9d30f72015-12-08 10:47:55 -0800211 const Attribute* inColor() const { return fInColor; }
joshualitt71c92602015-01-14 08:12:47 -0800212 const Attribute* inTextureCoords() const { return fInTextureCoords; }
jvanverth21deace2015-04-01 12:43:48 -0700213 DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; }
joshualitt88c23fc2015-05-13 14:18:07 -0700214 GrColor color() const { return fColor; }
joshualitte578a952015-05-14 10:09:13 -0700215 const SkMatrix& viewMatrix() const { return fViewMatrix; }
jvanverth78f07182014-07-30 06:17:59 -0700216 uint32_t getFlags() const { return fFlags; }
joshualittb8c241a2015-05-19 08:23:30 -0700217 bool usesLocalCoords() const { return fUsesLocalCoords; }
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000218
Brian Salomon94efbf52016-11-29 13:43:05 -0500219 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000220
Brian Salomon94efbf52016-11-29 13:43:05 -0500221 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000222
223private:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400224 GrDistanceFieldLCDTextGeoProc(GrColor, const SkMatrix& viewMatrix,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -0500225 sk_sp<GrTextureProxy> proxy, const GrSamplerParams& params,
226 DistanceAdjust wa, uint32_t flags,
227 bool usesLocalCoords);
228
joshualitt88c23fc2015-05-13 14:18:07 -0700229 GrColor fColor;
joshualitte578a952015-05-14 10:09:13 -0700230 SkMatrix fViewMatrix;
Brian Salomon0bbecb22016-11-17 11:38:22 -0500231 TextureSampler fTextureSampler;
jvanverth21deace2015-04-01 12:43:48 -0700232 DistanceAdjust fDistanceAdjust;
233 uint32_t fFlags;
joshualitt71c92602015-01-14 08:12:47 -0800234 const Attribute* fInPosition;
joshualittd9d30f72015-12-08 10:47:55 -0800235 const Attribute* fInColor;
joshualitt71c92602015-01-14 08:12:47 -0800236 const Attribute* fInTextureCoords;
joshualittb8c241a2015-05-19 08:23:30 -0700237 bool fUsesLocalCoords;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000238
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400239 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000240
jvanverthfa38a302014-10-06 05:59:05 -0700241 typedef GrGeometryProcessor INHERITED;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +0000242};
243
jvanverth@google.comd830d132013-11-11 20:54:09 +0000244#endif