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