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