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 | |
| 17 | /** |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 18 | * 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] | 19 | * distance field texture (using a smoothed step function near 0.5). |
| 20 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 21 | * 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] | 22 | */ |
| 23 | class GrDistanceFieldTextureEffect : public GrVertexEffect { |
| 24 | public: |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 25 | #ifdef SK_GAMMA_APPLY_TO_A8 |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame^] | 26 | static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, |
| 27 | GrTexture* gamma, const GrTextureParams& gammaParams, float lum, |
| 28 | bool similarity) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 29 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, gamma, gammaParams, lum, |
| 30 | similarity)); |
| 31 | } |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 32 | #else |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame^] | 33 | static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, |
| 34 | bool similarity) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 35 | return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, similarity)); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 36 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 37 | #endif |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 38 | |
| 39 | virtual ~GrDistanceFieldTextureEffect() {} |
| 40 | |
commit-bot@chromium.org | 6c89c34 | 2014-02-14 21:48:29 +0000 | [diff] [blame] | 41 | static const char* Name() { return "DistanceFieldTexture"; } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 42 | |
| 43 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 44 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 45 | float getLuminance() const { return fLuminance; } |
| 46 | #endif |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 47 | bool isSimilarity() const { return fIsSimilarity; } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 48 | |
| 49 | typedef GrGLDistanceFieldTextureEffect GLEffect; |
| 50 | |
| 51 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 52 | |
| 53 | private: |
skia.committer@gmail.com | a3b5327 | 2014-02-15 03:02:15 +0000 | [diff] [blame] | 54 | GrDistanceFieldTextureEffect(GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 55 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 56 | GrTexture* gamma, const GrTextureParams& gammaParams, float lum, |
| 57 | #endif |
commit-bot@chromium.org | 4362a38 | 2014-03-26 19:49:03 +0000 | [diff] [blame] | 58 | bool uniformScale); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 59 | |
| 60 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 61 | |
| 62 | GrTextureAccess fTextureAccess; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 63 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 64 | GrTextureAccess fGammaTextureAccess; |
| 65 | float fLuminance; |
| 66 | #endif |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 67 | bool fIsSimilarity; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 68 | |
| 69 | GR_DECLARE_EFFECT_TEST; |
| 70 | |
| 71 | typedef GrVertexEffect INHERITED; |
| 72 | }; |
| 73 | |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 74 | /** |
| 75 | * The output color of this effect is a modulation of the input color and samples from a |
| 76 | * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays. |
| 77 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 78 | * 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] | 79 | */ |
| 80 | class GrDistanceFieldLCDTextureEffect : public GrVertexEffect { |
| 81 | public: |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame^] | 82 | static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, |
| 83 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 84 | SkColor textColor, bool uniformScale, bool useBGR) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 85 | return SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, |
| 86 | (tex, params, gamma, gammaParams, textColor, uniformScale, useBGR)); |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | virtual ~GrDistanceFieldLCDTextureEffect() {} |
| 90 | |
| 91 | static const char* Name() { return "DistanceFieldLCDTexture"; } |
| 92 | |
| 93 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 94 | GrColor getTextColor() const { return fTextColor; } |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 95 | bool isUniformScale() const { return fUniformScale; } |
| 96 | bool useBGR() const { return fUseBGR; } |
| 97 | |
| 98 | typedef GrGLDistanceFieldLCDTextureEffect GLEffect; |
| 99 | |
| 100 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 101 | |
| 102 | private: |
| 103 | GrDistanceFieldLCDTextureEffect(GrTexture* texture, const GrTextureParams& params, |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 104 | GrTexture* gamma, const GrTextureParams& gammaParams, |
| 105 | SkColor textColor, |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 106 | bool uniformScale, bool useBGR); |
| 107 | |
| 108 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 109 | |
| 110 | GrTextureAccess fTextureAccess; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 111 | GrTextureAccess fGammaTextureAccess; |
| 112 | GrColor fTextColor; |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 113 | bool fUniformScale; |
| 114 | bool fUseBGR; |
| 115 | |
| 116 | GR_DECLARE_EFFECT_TEST; |
| 117 | |
| 118 | typedef GrVertexEffect INHERITED; |
| 119 | }; |
| 120 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 121 | #endif |