jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 11 | #include "GrProcessor.h" |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 13 | |
| 14 | class GrGLDistanceFieldTextureEffect; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 15 | class GrGLDistanceFieldNoGammaTextureEffect; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 16 | class GrGLDistanceFieldLCDTextureEffect; |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 17 | class GrInvariantOutput; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 18 | |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 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) |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 25 | kColorAttr_DistanceFieldEffectFlag = 0x20, // color vertex attribute |
jvanverth | 6d22eca | 2014-10-28 11:10:48 -0700 | [diff] [blame] | 26 | |
| 27 | kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initialization) |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 28 | |
| 29 | kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag | |
| 30 | kRectToRect_DistanceFieldEffectFlag, |
| 31 | // The subset of the flags relevant to GrDistanceFieldTextureEffect |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 32 | kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag | |
| 33 | kColorAttr_DistanceFieldEffectFlag, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 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 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 41 | /** |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 42 | * The output color of this effect is a modulation of the input color and a sample from a |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 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 |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 45 | * coords are a custom attribute. Gamma correction is handled via a texture LUT. |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 46 | */ |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 47 | class GrDistanceFieldTextureEffect : public GrGeometryProcessor { |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 48 | public: |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 49 | #ifdef SK_GAMMA_APPLY_TO_A8 |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 50 | static GrGeometryProcessor* Create(GrTexture* tex, const GrTextureParams& params, |
| 51 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 52 | float lum, uint32_t flags) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 53 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, gamma, gammaParams, lum, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 54 | flags)); |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 55 | } |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 56 | #else |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 57 | static GrGeometryProcessor* Create(GrTexture* tex, const GrTextureParams& params, |
| 58 | uint32_t flags) { |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 59 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, flags)); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 60 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 61 | #endif |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 62 | |
| 63 | virtual ~GrDistanceFieldTextureEffect() {} |
| 64 | |
commit-bot@chromium.org | 6c89c34 | 2014-02-14 21:48:29 +0000 | [diff] [blame] | 65 | static const char* Name() { return "DistanceFieldTexture"; } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 66 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 67 | const GrAttribute* inPosition() const { return fInPosition; } |
| 68 | const GrAttribute* inColor() const { return fInColor; } |
| 69 | const GrAttribute* inTextureCoords() const { return fInTextureCoords; } |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 70 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 71 | float getLuminance() const { return fLuminance; } |
| 72 | #endif |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 73 | uint32_t getFlags() const { return fFlags; } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 74 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 75 | typedef GrGLDistanceFieldTextureEffect GLProcessor; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 76 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 77 | virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 78 | |
| 79 | private: |
skia.committer@gmail.com | a3b5327 | 2014-02-15 03:02:15 +0000 | [diff] [blame] | 80 | GrDistanceFieldTextureEffect(GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 81 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 82 | GrTexture* gamma, const GrTextureParams& gammaParams, float lum, |
| 83 | #endif |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 84 | uint32_t flags); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 85 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 86 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 87 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 88 | virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 89 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 90 | GrTextureAccess fTextureAccess; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 91 | #ifdef SK_GAMMA_APPLY_TO_A8 |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 92 | GrTextureAccess fGammaTextureAccess; |
| 93 | float fLuminance; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 94 | #endif |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 95 | uint32_t fFlags; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 96 | const GrAttribute* fInPosition; |
| 97 | const GrAttribute* fInColor; |
| 98 | const GrAttribute* fInTextureCoords; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 99 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 100 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 101 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 102 | typedef GrGeometryProcessor INHERITED; |
| 103 | }; |
| 104 | |
| 105 | |
| 106 | /** |
| 107 | * The output color of this effect is a modulation of the input color and a sample from a |
| 108 | * distance field texture (using a smoothed step function near 0.5). |
| 109 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
| 110 | * coords are a custom attribute. No gamma correct blending is applied. |
| 111 | */ |
| 112 | class GrDistanceFieldNoGammaTextureEffect : public GrGeometryProcessor { |
| 113 | public: |
| 114 | static GrGeometryProcessor* Create(GrTexture* tex, const GrTextureParams& params, |
| 115 | uint32_t flags) { |
| 116 | return SkNEW_ARGS(GrDistanceFieldNoGammaTextureEffect, (tex, params, flags)); |
| 117 | } |
| 118 | |
| 119 | virtual ~GrDistanceFieldNoGammaTextureEffect() {} |
| 120 | |
| 121 | static const char* Name() { return "DistanceFieldTexture"; } |
| 122 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 123 | const GrAttribute* inPosition() const { return fInPosition; } |
| 124 | const GrAttribute* inColor() const { return fInColor; } |
| 125 | const GrAttribute* inTextureCoords() const { return fInTextureCoords; } |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 126 | uint32_t getFlags() const { return fFlags; } |
| 127 | |
| 128 | typedef GrGLDistanceFieldNoGammaTextureEffect GLProcessor; |
| 129 | |
| 130 | virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE; |
| 131 | |
| 132 | private: |
| 133 | GrDistanceFieldNoGammaTextureEffect(GrTexture* texture, const GrTextureParams& params, |
| 134 | uint32_t flags); |
| 135 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 136 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 137 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 138 | virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 139 | |
| 140 | GrTextureAccess fTextureAccess; |
| 141 | uint32_t fFlags; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 142 | const GrAttribute* fInPosition; |
| 143 | const GrAttribute* fInColor; |
| 144 | const GrAttribute* fInTextureCoords; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 145 | |
| 146 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 147 | |
| 148 | typedef GrGeometryProcessor INHERITED; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 151 | /** |
| 152 | * The output color of this effect is a modulation of the input color and samples from a |
| 153 | * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays. |
| 154 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 155 | * coords are a custom attribute. Gamma correction is handled via a texture LUT. |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 156 | */ |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 157 | class GrDistanceFieldLCDTextureEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 158 | public: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 159 | static GrGeometryProcessor* Create(GrTexture* tex, const GrTextureParams& params, |
| 160 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 161 | SkColor textColor, uint32_t flags) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 162 | return SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 163 | (tex, params, gamma, gammaParams, textColor, flags)); |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | virtual ~GrDistanceFieldLCDTextureEffect() {} |
| 167 | |
| 168 | static const char* Name() { return "DistanceFieldLCDTexture"; } |
| 169 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 170 | const GrAttribute* inPosition() const { return fInPosition; } |
| 171 | const GrAttribute* inTextureCoords() const { return fInTextureCoords; } |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 172 | GrColor getTextColor() const { return fTextColor; } |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 173 | uint32_t getFlags() const { return fFlags; } |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 174 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 175 | typedef GrGLDistanceFieldLCDTextureEffect GLProcessor; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 176 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 177 | virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 178 | |
| 179 | private: |
| 180 | GrDistanceFieldLCDTextureEffect(GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 181 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 182 | SkColor textColor, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 183 | uint32_t flags); |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 184 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 185 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 186 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 187 | virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 188 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 189 | GrTextureAccess fTextureAccess; |
| 190 | GrTextureAccess fGammaTextureAccess; |
| 191 | GrColor fTextColor; |
| 192 | uint32_t fFlags; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame^] | 193 | const GrAttribute* fInPosition; |
| 194 | const GrAttribute* fInTextureCoords; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 195 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 196 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 197 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 198 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 201 | #endif |