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 | |
| 11 | #include "GrEffect.h" |
| 12 | #include "GrVertexEffect.h" |
| 13 | |
| 14 | class GrGLDistanceFieldTextureEffect; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 15 | class GrGLDistanceFieldLCDTextureEffect; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 16 | |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 17 | enum GrDistanceFieldEffectFlags { |
| 18 | kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix |
| 19 | kRectToRect_DistanceFieldEffectFlag = 0x02, // ctm maps rects to rects |
| 20 | kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text |
| 21 | kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order |
| 22 | kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait mode (not used yet) |
| 23 | |
| 24 | kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag | |
| 25 | kRectToRect_DistanceFieldEffectFlag, |
| 26 | // The subset of the flags relevant to GrDistanceFieldTextureEffect |
| 27 | kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag, |
| 28 | // The subset of the flags relevant to GrDistanceFieldLCDTextureEffect |
| 29 | kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag | |
| 30 | kRectToRect_DistanceFieldEffectFlag | |
| 31 | kUseLCD_DistanceFieldEffectFlag | |
| 32 | kBGR_DistanceFieldEffectFlag, |
| 33 | }; |
| 34 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 35 | /** |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 36 | * 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] | 37 | * distance field texture (using a smoothed step function near 0.5). |
| 38 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 39 | * 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] | 40 | */ |
| 41 | class GrDistanceFieldTextureEffect : public GrVertexEffect { |
| 42 | public: |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 43 | #ifdef SK_GAMMA_APPLY_TO_A8 |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 44 | static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, |
| 45 | GrTexture* gamma, const GrTextureParams& gammaParams, float lum, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 46 | uint32_t flags) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 47 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, gamma, gammaParams, lum, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 48 | flags)); |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 49 | } |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 50 | #else |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 51 | static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 52 | uint32_t flags) { |
| 53 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, flags)); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 54 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 55 | #endif |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 56 | |
| 57 | virtual ~GrDistanceFieldTextureEffect() {} |
| 58 | |
commit-bot@chromium.org | 6c89c34 | 2014-02-14 21:48:29 +0000 | [diff] [blame] | 59 | static const char* Name() { return "DistanceFieldTexture"; } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 60 | |
| 61 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 62 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 63 | float getLuminance() const { return fLuminance; } |
| 64 | #endif |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 65 | uint32_t getFlags() const { return fFlags; } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 66 | |
| 67 | typedef GrGLDistanceFieldTextureEffect GLEffect; |
| 68 | |
| 69 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 70 | |
| 71 | private: |
skia.committer@gmail.com | a3b5327 | 2014-02-15 03:02:15 +0000 | [diff] [blame] | 72 | GrDistanceFieldTextureEffect(GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 73 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 74 | GrTexture* gamma, const GrTextureParams& gammaParams, float lum, |
| 75 | #endif |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 76 | uint32_t flags); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 77 | |
| 78 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 79 | |
| 80 | GrTextureAccess fTextureAccess; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 81 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 82 | GrTextureAccess fGammaTextureAccess; |
| 83 | float fLuminance; |
| 84 | #endif |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 85 | uint32_t fFlags; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 86 | |
| 87 | GR_DECLARE_EFFECT_TEST; |
| 88 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 89 | typedef GrEffect INHERITED; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 92 | /** |
| 93 | * The output color of this effect is a modulation of the input color and samples from a |
| 94 | * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays. |
| 95 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 96 | * 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] | 97 | */ |
| 98 | class GrDistanceFieldLCDTextureEffect : public GrVertexEffect { |
| 99 | public: |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 100 | static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, |
| 101 | GrTexture* gamma, const GrTextureParams& gammaParams, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 102 | SkColor textColor, uint32_t flags) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 103 | return SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 104 | (tex, params, gamma, gammaParams, textColor, flags)); |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | virtual ~GrDistanceFieldLCDTextureEffect() {} |
| 108 | |
| 109 | static const char* Name() { return "DistanceFieldLCDTexture"; } |
| 110 | |
| 111 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 112 | GrColor getTextColor() const { return fTextColor; } |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 113 | uint32_t getFlags() const { return fFlags; } |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 114 | |
| 115 | typedef GrGLDistanceFieldLCDTextureEffect GLEffect; |
| 116 | |
| 117 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 118 | |
| 119 | private: |
| 120 | GrDistanceFieldLCDTextureEffect(GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 121 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 122 | SkColor textColor, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 123 | uint32_t flags); |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 124 | |
| 125 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 126 | |
| 127 | GrTextureAccess fTextureAccess; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 128 | GrTextureAccess fGammaTextureAccess; |
| 129 | GrColor fTextColor; |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 130 | uint32_t fFlags; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 131 | |
| 132 | GR_DECLARE_EFFECT_TEST; |
| 133 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 134 | typedef GrEffect INHERITED; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 137 | #endif |