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 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 15 | class GrInvariantOutput; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 16 | |
| 17 | class GrBicubicEffect : public GrSingleTextureEffect { |
| 18 | public: |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 19 | enum { |
| 20 | kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of |
| 21 | // surrounding texels are needed by the kernel in x and y. |
| 22 | }; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 23 | virtual ~GrBicubicEffect(); |
| 24 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 25 | const char* name() const override { return "Bicubic"; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 26 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 27 | const GrTextureDomain& domain() const { return fDomain; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 28 | |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. |
| 31 | */ |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 32 | static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
| 33 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 34 | const SkMatrix& matrix, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 35 | const SkShader::TileMode tileModes[2]) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 36 | return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(colorSpaceXform), |
Brian Osman | 0857527 | 2016-12-21 15:26:37 -0500 | [diff] [blame] | 37 | matrix, tileModes)); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 38 | } |
| 39 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 40 | /** |
| 41 | * Create a Mitchell filter effect with a texture matrix and a domain. |
| 42 | */ |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 43 | static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
| 44 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 45 | const SkMatrix& matrix, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 46 | const SkRect& domain) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 47 | return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(colorSpaceXform), |
Brian Osman | 0857527 | 2016-12-21 15:26:37 -0500 | [diff] [blame] | 48 | matrix, domain)); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 49 | } |
| 50 | |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 51 | /** |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 52 | * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. |
| 53 | */ |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 54 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 55 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 56 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 57 | const SkMatrix& matrix, |
| 58 | const SkShader::TileMode tileModes[2]) { |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 59 | return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy), |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 60 | std::move(colorSpaceXform), |
| 61 | matrix, tileModes)); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Create a Mitchell filter effect with a texture matrix and a domain. |
| 66 | */ |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 67 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 68 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 69 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 70 | const SkMatrix& matrix, |
| 71 | const SkRect& domain) { |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 72 | return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy), |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 73 | std::move(colorSpaceXform), |
| 74 | matrix, domain)); |
| 75 | } |
| 76 | |
| 77 | /** |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 78 | * Determines whether the bicubic effect should be used based on the transformation from the |
| 79 | * 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 result (e.g. when this |
| 81 | * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or |
| 82 | * kNearest). |
| 83 | */ |
| 84 | static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 85 | GrSamplerParams::FilterMode* filterMode); |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 86 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 87 | private: |
Brian Osman | 0857527 | 2016-12-21 15:26:37 -0500 | [diff] [blame] | 88 | GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix &matrix, |
| 89 | const SkShader::TileMode tileModes[2]); |
| 90 | GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix &matrix, |
| 91 | const SkRect& domain); |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 92 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 93 | GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 94 | const SkMatrix &matrix, const SkShader::TileMode tileModes[2]); |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 95 | GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 96 | const SkMatrix &matrix, const SkRect& domain); |
| 97 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 98 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 99 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 100 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 101 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 102 | bool onIsEqual(const GrFragmentProcessor&) const override; |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 103 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 104 | GrTextureDomain fDomain; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 105 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 106 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
skia.committer@gmail.com | c3723db | 2013-09-05 07:01:19 +0000 | [diff] [blame] | 107 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 108 | typedef GrSingleTextureEffect INHERITED; |
| 109 | }; |
| 110 | |
| 111 | #endif |