| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrBicubicTextureEffect_DEFINED | 8 #ifndef GrBicubicTextureEffect_DEFINED |
| 9 #define GrBicubicTextureEffect_DEFINED | 9 #define GrBicubicTextureEffect_DEFINED |
| 10 | 10 |
| 11 #include "GrSingleTextureEffect.h" | 11 #include "GrSingleTextureEffect.h" |
| 12 #include "GrTextureDomain.h" |
| 12 #include "GrDrawEffect.h" | 13 #include "GrDrawEffect.h" |
| 13 #include "gl/GrGLEffect.h" | 14 #include "gl/GrGLEffect.h" |
| 14 #include "GrTBackendEffectFactory.h" | 15 #include "GrTBackendEffectFactory.h" |
| 15 | 16 |
| 16 class GrGLBicubicEffect; | 17 class GrGLBicubicEffect; |
| 17 | 18 |
| 18 class GrBicubicEffect : public GrSingleTextureEffect { | 19 class GrBicubicEffect : public GrSingleTextureEffect { |
| 19 public: | 20 public: |
| 20 enum { | 21 enum { |
| 21 kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this
number of | 22 kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this
number of |
| 22 // surrounding texels are needed by the kernel in x
and y. | 23 // surrounding texels are needed by the kernel in x
and y. |
| 23 }; | 24 }; |
| 24 virtual ~GrBicubicEffect(); | 25 virtual ~GrBicubicEffect(); |
| 25 | 26 |
| 26 static const char* Name() { return "Bicubic"; } | 27 static const char* Name() { return "Bicubic"; } |
| 27 const float* coefficients() const { return fCoefficients; } | 28 const float* coefficients() const { return fCoefficients; } |
| 28 | 29 |
| 29 typedef GrGLBicubicEffect GLEffect; | 30 typedef GrGLBicubicEffect GLEffect; |
| 30 | 31 |
| 31 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 32 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 32 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 33 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 33 | 34 |
| 34 /** | 35 const GrTextureDomain& domain() const { return fDomain; } |
| 35 * Create a simple Mitchell filter effect. | |
| 36 */ | |
| 37 static GrEffectRef* Create(GrTexture* tex) { | |
| 38 return Create(tex, gMitchellCoefficients); | |
| 39 } | |
| 40 | 36 |
| 41 /** | 37 /** |
| 42 * Create a simple filter effect with custom bicubic coefficients. | 38 * Create a simple filter effect with custom bicubic coefficients and option
al domain. |
| 43 */ | 39 */ |
| 44 static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16])
{ | 40 static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], |
| 45 const SkShader::TileMode tm[] = { SkShader::kClamp_TileMode, SkShader::k
Clamp_TileMode }; | 41 const SkRect* domain = NULL) { |
| 46 return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), tm); | 42 if (NULL == domain) { |
| 43 static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_Ti
leMode, |
| 44 SkShader::kClamp_Ti
leMode }; |
| 45 return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), kTil
eModes); |
| 46 } else { |
| 47 AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficient
s, |
| 48 MakeDivByTexture
WHMatrix(tex), |
| 49 *domain))); |
| 50 return CreateEffectRef(effect); |
| 51 } |
| 47 } | 52 } |
| 48 | 53 |
| 49 /** | 54 /** |
| 50 * Create a Mitchell filter effect with specified texture matrix and x/y til
e modes. | 55 * Create a Mitchell filter effect with specified texture matrix and x/y til
e modes. |
| 51 */ | 56 */ |
| 52 static GrEffectRef* Create(GrTexture* tex, | 57 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, |
| 53 const SkMatrix& matrix, | |
| 54 SkShader::TileMode tileModes[2]) { | 58 SkShader::TileMode tileModes[2]) { |
| 55 return Create(tex, gMitchellCoefficients, matrix, tileModes); | 59 return Create(tex, gMitchellCoefficients, matrix, tileModes); |
| 56 } | 60 } |
| 57 | 61 |
| 58 /** | 62 /** |
| 59 * The most general Create method. This allows specification of the bicubic
coefficients, the | 63 * Create a filter effect with custom bicubic coefficients, the texture matr
ix, and the x/y |
| 60 * texture matrix, and the x/y tilemodes. | 64 * tilemodes. |
| 61 */ | 65 */ |
| 62 static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], | 66 static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], |
| 63 const SkMatrix& matrix, | 67 const SkMatrix& matrix, const SkShader::TileMode
tileModes[2]) { |
| 64 const SkShader::TileMode tileModes[2]) { | |
| 65 AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, m
atrix, tileModes))); | 68 AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, m
atrix, tileModes))); |
| 66 return CreateEffectRef(effect); | 69 return CreateEffectRef(effect); |
| 67 } | 70 } |
| 68 | 71 |
| 72 /** |
| 73 * Create a Mitchell filter effect with a texture matrix and a domain. |
| 74 */ |
| 75 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const SkR
ect& domain) { |
| 76 AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, gMitchellCoeffi
cients, matrix, |
| 77 domain))); |
| 78 return CreateEffectRef(effect); |
| 79 } |
| 80 |
| 69 private: | 81 private: |
| 70 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], | 82 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], |
| 71 const SkMatrix &matrix, const SkShader::TileMode tileModes[2
]); | 83 const SkMatrix &matrix, const SkShader::TileMode tileModes[2
]); |
| 84 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], |
| 85 const SkMatrix &matrix, const SkRect& domain); |
| 72 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 86 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 73 float fCoefficients[16]; | 87 |
| 88 float fCoefficients[16]; |
| 89 GrTextureDomain fDomain; |
| 74 | 90 |
| 75 GR_DECLARE_EFFECT_TEST; | 91 GR_DECLARE_EFFECT_TEST; |
| 76 | 92 |
| 77 static const SkScalar gMitchellCoefficients[16]; | 93 static const SkScalar gMitchellCoefficients[16]; |
| 78 | 94 |
| 79 typedef GrSingleTextureEffect INHERITED; | 95 typedef GrSingleTextureEffect INHERITED; |
| 80 }; | 96 }; |
| 81 | 97 |
| 82 #endif | 98 #endif |
| OLD | NEW |