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 | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 50 | static GrGeometryProcessor* Create(GrColor color, GrTexture* tex, const GrTextureParams& params, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 51 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 52 | float lum, uint32_t flags) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 53 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (color, 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 | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 57 | static GrGeometryProcessor* Create(GrColor color, GrTexture* tex, const GrTextureParams& params, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 58 | uint32_t flags) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 59 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (color, 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 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 65 | virtual const char* name() const SK_OVERRIDE { 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 | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 75 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 76 | const GrGLCaps& caps, |
| 77 | GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 78 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 79 | virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) const SK_OVERRIDE; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 80 | |
| 81 | private: |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 82 | GrDistanceFieldTextureEffect(GrColor, GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 83 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 84 | GrTexture* gamma, const GrTextureParams& gammaParams, float lum, |
| 85 | #endif |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 86 | uint32_t flags); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 87 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 88 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 89 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 90 | virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 91 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 92 | GrTextureAccess fTextureAccess; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 93 | #ifdef SK_GAMMA_APPLY_TO_A8 |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 94 | GrTextureAccess fGammaTextureAccess; |
| 95 | float fLuminance; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 96 | #endif |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 97 | uint32_t fFlags; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 98 | const GrAttribute* fInPosition; |
| 99 | const GrAttribute* fInColor; |
| 100 | const GrAttribute* fInTextureCoords; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 101 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 102 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 103 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 104 | typedef GrGeometryProcessor INHERITED; |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * The output color of this effect is a modulation of the input color and a sample from a |
| 110 | * distance field texture (using a smoothed step function near 0.5). |
| 111 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
| 112 | * coords are a custom attribute. No gamma correct blending is applied. |
| 113 | */ |
| 114 | class GrDistanceFieldNoGammaTextureEffect : public GrGeometryProcessor { |
| 115 | public: |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 116 | static GrGeometryProcessor* Create(GrColor color, GrTexture* tex, const GrTextureParams& params, |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 117 | uint32_t flags) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 118 | return SkNEW_ARGS(GrDistanceFieldNoGammaTextureEffect, (color, tex, params, flags)); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | virtual ~GrDistanceFieldNoGammaTextureEffect() {} |
| 122 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 123 | virtual const char* name() const SK_OVERRIDE { return "DistanceFieldTexture"; } |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 124 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 125 | const GrAttribute* inPosition() const { return fInPosition; } |
| 126 | const GrAttribute* inColor() const { return fInColor; } |
| 127 | const GrAttribute* inTextureCoords() const { return fInTextureCoords; } |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 128 | uint32_t getFlags() const { return fFlags; } |
| 129 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 130 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 131 | const GrGLCaps& caps, |
| 132 | GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 133 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 134 | virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) const SK_OVERRIDE; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 135 | |
| 136 | private: |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 137 | GrDistanceFieldNoGammaTextureEffect(GrColor, GrTexture* texture, const GrTextureParams& params, |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 138 | uint32_t flags); |
| 139 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 140 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 141 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 142 | virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 143 | |
| 144 | GrTextureAccess fTextureAccess; |
| 145 | uint32_t fFlags; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 146 | const GrAttribute* fInPosition; |
| 147 | const GrAttribute* fInColor; |
| 148 | const GrAttribute* fInTextureCoords; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 149 | |
| 150 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 151 | |
| 152 | typedef GrGeometryProcessor INHERITED; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 155 | /** |
| 156 | * The output color of this effect is a modulation of the input color and samples from a |
| 157 | * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays. |
| 158 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 159 | * 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] | 160 | */ |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 161 | class GrDistanceFieldLCDTextureEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 162 | public: |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 163 | static GrGeometryProcessor* Create(GrColor color, GrTexture* tex, const GrTextureParams& params, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 164 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 165 | SkColor textColor, uint32_t flags) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 166 | return SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 167 | (color, tex, params, gamma, gammaParams, textColor, flags)); |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | virtual ~GrDistanceFieldLCDTextureEffect() {} |
| 171 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 172 | virtual const char* name() const SK_OVERRIDE { return "DistanceFieldLCDTexture"; } |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 173 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 174 | const GrAttribute* inPosition() const { return fInPosition; } |
| 175 | const GrAttribute* inTextureCoords() const { return fInTextureCoords; } |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 176 | GrColor getTextColor() const { return fTextColor; } |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 177 | uint32_t getFlags() const { return fFlags; } |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 178 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 179 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 180 | const GrGLCaps& caps, |
| 181 | GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 182 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 183 | virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) const SK_OVERRIDE; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 184 | |
| 185 | private: |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 186 | GrDistanceFieldLCDTextureEffect(GrColor, GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 187 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 188 | SkColor textColor, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 189 | uint32_t flags); |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 190 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 191 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 192 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 193 | virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 194 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 195 | GrTextureAccess fTextureAccess; |
| 196 | GrTextureAccess fGammaTextureAccess; |
| 197 | GrColor fTextColor; |
| 198 | uint32_t fFlags; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 199 | const GrAttribute* fInPosition; |
| 200 | const GrAttribute* fInTextureCoords; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 201 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 202 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 203 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 204 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 207 | #endif |