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; 15 class GrGLDistanceFieldLCDTextureEffect; 16 17 /** 18 * The output color of this effect is a modulation of the input color and a sample from a 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 21 * coords are a custom attribute. Gamma correction is handled via a texture LUT. 22 */ 23 class GrDistanceFieldTextureEffect : public GrVertexEffect { 24 public: 25 #ifdef SK_GAMMA_APPLY_TO_A8 Create(GrTexture * tex,const GrTextureParams & params,GrTexture * gamma,const GrTextureParams & gammaParams,float lum,bool similarity)26 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, 27 GrTexture* gamma, const GrTextureParams& gammaParams, float lum, 28 bool similarity) { 29 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, 30 gamma, gammaParams, lum, 31 similarity))); 32 #else 33 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, 34 bool similarity) { 35 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, 36 similarity))); 37 #endif 38 return CreateEffectRef(effect); 39 } 40 41 virtual ~GrDistanceFieldTextureEffect() {} 42 43 static const char* Name() { return "DistanceFieldTexture"; } 44 45 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; 46 #ifdef SK_GAMMA_APPLY_TO_A8 47 float getLuminance() const { return fLuminance; } 48 #endif 49 bool isSimilarity() const { return fIsSimilarity; } 50 51 typedef GrGLDistanceFieldTextureEffect GLEffect; 52 53 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 54 55 private: 56 GrDistanceFieldTextureEffect(GrTexture* texture, const GrTextureParams& params, 57 #ifdef SK_GAMMA_APPLY_TO_A8 58 GrTexture* gamma, const GrTextureParams& gammaParams, float lum, 59 #endif 60 bool uniformScale); 61 62 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 63 64 GrTextureAccess fTextureAccess; 65 #ifdef SK_GAMMA_APPLY_TO_A8 66 GrTextureAccess fGammaTextureAccess; 67 float fLuminance; 68 #endif 69 bool fIsSimilarity; 70 71 GR_DECLARE_EFFECT_TEST; 72 73 typedef GrVertexEffect INHERITED; 74 }; 75 76 /** 77 * The output color of this effect is a modulation of the input color and samples from a 78 * distance field texture (using a smoothed step function near 0.5), adjusted for LCD displays. 79 * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input 80 * coords are a custom attribute. Gamma correction is handled via a texture LUT. 81 */ 82 class GrDistanceFieldLCDTextureEffect : public GrVertexEffect { 83 public: Create(GrTexture * tex,const GrTextureParams & params,GrTexture * gamma,const GrTextureParams & gammaParams,SkColor textColor,bool uniformScale,bool useBGR)84 static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& params, 85 GrTexture* gamma, const GrTextureParams& gammaParams, 86 SkColor textColor, 87 bool uniformScale, bool useBGR) { 88 AutoEffectUnref effect(SkNEW_ARGS(GrDistanceFieldLCDTextureEffect, 89 (tex, params, gamma, gammaParams, textColor, uniformScale, 90 useBGR))); 91 return CreateEffectRef(effect); 92 } 93 ~GrDistanceFieldLCDTextureEffect()94 virtual ~GrDistanceFieldLCDTextureEffect() {} 95 Name()96 static const char* Name() { return "DistanceFieldLCDTexture"; } 97 98 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; getTextColor()99 GrColor getTextColor() const { return fTextColor; } isUniformScale()100 bool isUniformScale() const { return fUniformScale; } useBGR()101 bool useBGR() const { return fUseBGR; } 102 103 typedef GrGLDistanceFieldLCDTextureEffect GLEffect; 104 105 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 106 107 private: 108 GrDistanceFieldLCDTextureEffect(GrTexture* texture, const GrTextureParams& params, 109 GrTexture* gamma, const GrTextureParams& gammaParams, 110 SkColor textColor, 111 bool uniformScale, bool useBGR); 112 113 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 114 115 GrTextureAccess fTextureAccess; 116 GrTextureAccess fGammaTextureAccess; 117 GrColor fTextColor; 118 bool fUniformScale; 119 bool fUseBGR; 120 121 GR_DECLARE_EFFECT_TEST; 122 123 typedef GrVertexEffect INHERITED; 124 }; 125 126 #endif 127