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 |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 const float* coefficients() const { return fCoefficients; } | 26 const float* coefficients() const { return fCoefficients; } |
27 | 27 |
28 const char* name() const override { return "Bicubic"; } | 28 const char* name() const override { return "Bicubic"; } |
29 | 29 |
30 const GrTextureDomain& domain() const { return fDomain; } | 30 const GrTextureDomain& domain() const { return fDomain; } |
31 | 31 |
32 /** | 32 /** |
33 * Create a simple filter effect with custom bicubic coefficients and option
al domain. | 33 * Create a simple filter effect with custom bicubic coefficients and option
al domain. |
34 */ | 34 */ |
35 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, const SkScalar coeffi
cients[16], | 35 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
| 36 sk_sp<GrColorSpaceXform> colorSpaceXf
orm, |
| 37 const SkScalar coefficients[16], |
36 const SkRect* domain = nullptr) { | 38 const SkRect* domain = nullptr) { |
37 if (nullptr == domain) { | 39 if (nullptr == domain) { |
38 static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_Ti
leMode, | 40 static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_Ti
leMode, |
39 SkShader::kClamp_Ti
leMode }; | 41 SkShader::kClamp_Ti
leMode }; |
40 return Make(tex, coefficients, GrCoordTransform::MakeDivByTextureWHM
atrix(tex), | 42 return Make(tex, std::move(colorSpaceXform), coefficients, |
41 kTileModes); | 43 GrCoordTransform::MakeDivByTextureWHMatrix(tex), kTileMo
des); |
42 } else { | 44 } else { |
43 return sk_sp<GrFragmentProcessor>( | 45 return sk_sp<GrFragmentProcessor>( |
44 new GrBicubicEffect(tex, coefficients, | 46 new GrBicubicEffect(tex, std::move(colorSpaceXform), coefficient
s, |
45 GrCoordTransform::MakeDivByTextureWHMatrix(t
ex), *domain)); | 47 GrCoordTransform::MakeDivByTextureWHMatrix(t
ex), *domain)); |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 /** | 51 /** |
50 * Create a Mitchell filter effect with specified texture matrix and x/y til
e modes. | 52 * Create a Mitchell filter effect with specified texture matrix and x/y til
e modes. |
51 */ | 53 */ |
52 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, const SkMatrix& matri
x, | 54 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
| 55 sk_sp<GrColorSpaceXform> colorSpaceXf
orm, |
| 56 const SkMatrix& matrix, |
53 const SkShader::TileMode tileModes[2]
) { | 57 const SkShader::TileMode tileModes[2]
) { |
54 return Make(tex, gMitchellCoefficients, matrix, tileModes); | 58 return Make(tex, std::move(colorSpaceXform), gMitchellCoefficients, matr
ix, tileModes); |
55 } | 59 } |
56 | 60 |
57 /** | 61 /** |
58 * Create a filter effect with custom bicubic coefficients, the texture matr
ix, and the x/y | 62 * Create a filter effect with custom bicubic coefficients, the texture matr
ix, and the x/y |
59 * tilemodes. | 63 * tilemodes. |
60 */ | 64 */ |
61 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, const SkScalar coeffi
cients[16], | 65 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
| 66 sk_sp<GrColorSpaceXform> colorSpaceXf
orm, |
| 67 const SkScalar coefficients[16], |
62 const SkMatrix& matrix, | 68 const SkMatrix& matrix, |
63 const SkShader::TileMode tileModes[2]
) { | 69 const SkShader::TileMode tileModes[2]
) { |
64 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, coefficients,
matrix, | 70 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(col
orSpaceXform), |
65 tileModes)); | 71 coefficients, matr
ix, tileModes)); |
66 } | 72 } |
67 | 73 |
68 /** | 74 /** |
69 * Create a Mitchell filter effect with a texture matrix and a domain. | 75 * Create a Mitchell filter effect with a texture matrix and a domain. |
70 */ | 76 */ |
71 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, const SkMatrix& matri
x, | 77 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
| 78 sk_sp<GrColorSpaceXform> colorSpaceXf
orm, |
| 79 const SkMatrix& matrix, |
72 const SkRect& domain) { | 80 const SkRect& domain) { |
73 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, gMitchellCoef
ficients, matrix, | 81 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(col
orSpaceXform), |
| 82 gMitchellCoefficie
nts, matrix, |
74 domain)); | 83 domain)); |
75 } | 84 } |
76 | 85 |
77 /** | 86 /** |
78 * Determines whether the bicubic effect should be used based on the transfo
rmation from the | 87 * Determines whether the bicubic effect should be used based on the transfo
rmation from the |
79 * local coords to the device. Returns true if the bicubic effect should be
used. filterMode | 88 * local coords to the device. Returns true if the bicubic effect should be
used. filterMode |
80 * is set to appropriate filtering mode to use regardless of the return resu
lt (e.g. when this | 89 * is set to appropriate filtering mode to use regardless of the return resu
lt (e.g. when this |
81 * returns false it may indicate that the best fallback is to use kMipMap, k
Bilerp, or | 90 * returns false it may indicate that the best fallback is to use kMipMap, k
Bilerp, or |
82 * kNearest). | 91 * kNearest). |
83 */ | 92 */ |
84 static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice, | 93 static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice, |
85 GrTextureParams::FilterMode* filterMode); | 94 GrTextureParams::FilterMode* filterMode); |
86 | 95 |
87 private: | 96 private: |
88 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], const SkMatrix
&matrix, | 97 GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkScalar coeffic
ients[16], |
89 const SkShader::TileMode tileModes[2]); | 98 const SkMatrix &matrix, const SkShader::TileMode tileModes[2
]); |
90 GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], const SkMatrix
&matrix, | 99 GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkScalar coeffic
ients[16], |
91 const SkRect& domain); | 100 const SkMatrix &matrix, const SkRect& domain); |
92 | 101 |
93 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 102 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
94 | 103 |
95 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 104 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
96 | 105 |
97 bool onIsEqual(const GrFragmentProcessor&) const override; | 106 bool onIsEqual(const GrFragmentProcessor&) const override; |
98 | 107 |
99 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 108 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
100 | 109 |
101 float fCoefficients[16]; | 110 float fCoefficients[16]; |
102 GrTextureDomain fDomain; | 111 GrTextureDomain fDomain; |
103 | 112 |
104 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 113 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
105 | 114 |
106 static const SkScalar gMitchellCoefficients[16]; | 115 static const SkScalar gMitchellCoefficients[16]; |
107 | 116 |
108 typedef GrSingleTextureEffect INHERITED; | 117 typedef GrSingleTextureEffect INHERITED; |
109 }; | 118 }; |
110 | 119 |
111 #endif | 120 #endif |
OLD | NEW |