humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 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 GrBicubicTextureEffect_DEFINED |
| 9 | #define GrBicubicTextureEffect_DEFINED |
| 10 | |
| 11 | #include "GrSingleTextureEffect.h" |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 12 | #include "GrTextureDomain.h" |
wangyix | 6af0c93 | 2015-07-22 10:21:17 -0700 | [diff] [blame] | 13 | #include "gl/GrGLFragmentProcessor.h" |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 14 | |
| 15 | class GrGLBicubicEffect; |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 16 | class GrInvariantOutput; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 17 | |
| 18 | class GrBicubicEffect : public GrSingleTextureEffect { |
| 19 | public: |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 20 | enum { |
| 21 | 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 | }; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 24 | virtual ~GrBicubicEffect(); |
| 25 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 26 | const float* coefficients() const { return fCoefficients; } |
| 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | const char* name() const override { return "Bicubic"; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 29 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 30 | const GrTextureDomain& domain() const { return fDomain; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 31 | |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 32 | /** |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 33 | * Create a simple filter effect with custom bicubic coefficients and optional domain. |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 34 | */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 35 | static GrFragmentProcessor* Create(GrTexture* tex, const SkScalar coefficients[16], |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 36 | const SkRect* domain = nullptr) { |
| 37 | if (nullptr == domain) { |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 38 | static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_TileMode, |
| 39 | SkShader::kClamp_TileMode }; |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 40 | return Create(tex, coefficients, GrCoordTransform::MakeDivByTextureWHMatrix(tex), |
| 41 | kTileModes); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 42 | } else { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 43 | return new GrBicubicEffect(tex, coefficients, |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 44 | GrCoordTransform::MakeDivByTextureWHMatrix(tex), *domain); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 45 | } |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. |
| 50 | */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 51 | static GrFragmentProcessor* Create(GrTexture* tex, const SkMatrix& matrix, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 52 | SkShader::TileMode tileModes[2]) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 53 | return Create(tex, gMitchellCoefficients, matrix, tileModes); |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 57 | * Create a filter effect with custom bicubic coefficients, the texture matrix, and the x/y |
| 58 | * tilemodes. |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 59 | */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 60 | static GrFragmentProcessor* Create(GrTexture* tex, const SkScalar coefficients[16], |
| 61 | const SkMatrix& matrix, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 62 | const SkShader::TileMode tileModes[2]) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 63 | return new GrBicubicEffect(tex, coefficients, matrix, tileModes); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 64 | } |
| 65 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 66 | /** |
| 67 | * Create a Mitchell filter effect with a texture matrix and a domain. |
| 68 | */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 69 | static GrFragmentProcessor* Create(GrTexture* tex, const SkMatrix& matrix, |
| 70 | const SkRect& domain) { |
| 71 | return new GrBicubicEffect(tex, gMitchellCoefficients, matrix, domain); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 72 | } |
| 73 | |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 74 | /** |
| 75 | * Determines whether the bicubic effect should be used based on the transformation from the |
| 76 | * local coords to the device. Returns true if the bicubic effect should be used. filterMode |
| 77 | * is set to appropriate filtering mode to use regardless of the return result (e.g. when this |
| 78 | * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or |
| 79 | * kNearest). |
| 80 | */ |
| 81 | static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice, |
| 82 | GrTextureParams::FilterMode* filterMode); |
| 83 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 84 | private: |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 85 | GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], const SkMatrix &matrix, |
| 86 | const SkShader::TileMode tileModes[2]); |
| 87 | GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], const SkMatrix &matrix, |
| 88 | const SkRect& domain); |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 89 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 90 | GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 91 | |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 92 | void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; |
| 93 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 94 | bool onIsEqual(const GrFragmentProcessor&) const override; |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 95 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 96 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 97 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 98 | float fCoefficients[16]; |
| 99 | GrTextureDomain fDomain; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 100 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 101 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
skia.committer@gmail.com | c3723db | 2013-09-05 07:01:19 +0000 | [diff] [blame] | 102 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 103 | static const SkScalar gMitchellCoefficients[16]; |
| 104 | |
| 105 | typedef GrSingleTextureEffect INHERITED; |
| 106 | }; |
| 107 | |
| 108 | #endif |