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