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" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLFragmentProcessor.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 | 8515377 | 2015-11-05 09:35:01 -0800 | [diff] [blame] | 35 | static const GrFragmentProcessor* Create(GrTexture* tex, const SkScalar coefficients[16], |
| 36 | const SkRect* domain = nullptr) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 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 | 8515377 | 2015-11-05 09:35:01 -0800 | [diff] [blame] | 51 | static const GrFragmentProcessor* Create(GrTexture* tex, const SkMatrix& matrix, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 52 | const 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 | 8515377 | 2015-11-05 09:35:01 -0800 | [diff] [blame] | 60 | static const GrFragmentProcessor* Create(GrTexture* tex, const SkScalar coefficients[16], |
| 61 | const SkMatrix& matrix, |
| 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 | 8515377 | 2015-11-05 09:35:01 -0800 | [diff] [blame] | 69 | static const GrFragmentProcessor* Create(GrTexture* tex, const SkMatrix& matrix, |
| 70 | const SkRect& domain) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 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 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 90 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 91 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 92 | void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 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 |