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]) { |
Stephen White
2013/12/12 01:50:07
Maybe this variant of the factory function should
bsalomon
2013/12/13 20:53:26
Done.
| |
45 const SkShader::TileMode tm[] = { SkShader::kClamp_TileMode, SkShader::k Clamp_TileMode }; | 41 static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_TileMo de, |
46 return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), tm); | 42 SkShader::kClamp_TileMo de }; |
43 return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), kTileMod es); | |
47 } | 44 } |
48 | 45 |
49 /** | 46 /** |
50 * Create a Mitchell filter effect with specified texture matrix and x/y til e modes. | 47 * Create a Mitchell filter effect with specified texture matrix and x/y til e modes. |
51 */ | 48 */ |
52 static GrEffectRef* Create(GrTexture* tex, | 49 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, |
53 const SkMatrix& matrix, | |
54 SkShader::TileMode tileModes[2]) { | 50 SkShader::TileMode tileModes[2]) { |
55 return Create(tex, gMitchellCoefficients, matrix, tileModes); | 51 return Create(tex, gMitchellCoefficients, matrix, tileModes); |
56 } | 52 } |
57 | 53 |
58 /** | 54 /** |
59 * The most general Create method. This allows specification of the bicubic coefficients, the | 55 * Create a filter effect with custom bicubic coefficients, the texture matr ix, and the x/y |
60 * texture matrix, and the x/y tilemodes. | 56 * tilemodes. |
61 */ | 57 */ |
62 static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], | 58 static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], |
63 const SkMatrix& matrix, | 59 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))); | 60 AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, m atrix, tileModes))); |
66 return CreateEffectRef(effect); | 61 return CreateEffectRef(effect); |
67 } | 62 } |
68 | 63 |
64 /** | |
65 * Create a Mitchell filter effect with a texture matrix and a domain. | |
66 */ | |
67 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const SkR ect& domain) { | |
68 AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, gMitchellCoeffi cients, matrix, | |
69 domain))); | |
70 return CreateEffectRef(effect); | |
71 } | |
72 | |
69 private: | 73 private: |
70 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], | 74 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], |
71 const SkMatrix &matrix, const SkShader::TileMode tileModes[2 ]); | 75 const SkMatrix &matrix, const SkShader::TileMode tileModes[2 ]); |
76 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], | |
77 const SkMatrix &matrix, const SkRect& domain); | |
72 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 78 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
73 float fCoefficients[16]; | 79 |
80 float fCoefficients[16]; | |
81 GrTextureDomain fDomain; | |
74 | 82 |
75 GR_DECLARE_EFFECT_TEST; | 83 GR_DECLARE_EFFECT_TEST; |
76 | 84 |
77 static const SkScalar gMitchellCoefficients[16]; | 85 static const SkScalar gMitchellCoefficients[16]; |
78 | 86 |
79 typedef GrSingleTextureEffect INHERITED; | 87 typedef GrSingleTextureEffect INHERITED; |
80 }; | 88 }; |
81 | 89 |
82 #endif | 90 #endif |
OLD | NEW |