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 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 11 | #include "GrTextureDomain.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 12 | #include "glsl/GrGLSLFragmentProcessor.h" |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 13 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 14 | class GrInvariantOutput; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 15 | |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 16 | class GrBicubicEffect : public GrFragmentProcessor { |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 17 | public: |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 18 | enum { |
| 19 | kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of |
| 20 | // surrounding texels are needed by the kernel in x and y. |
| 21 | }; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 22 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | const char* name() const override { return "Bicubic"; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 24 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 25 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 26 | return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(*this)); |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 27 | } |
| 28 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 29 | const GrTextureDomain& domain() const { return fDomain; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 30 | |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 31 | /** |
| 32 | * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. |
| 33 | */ |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 34 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 35 | const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 36 | const GrSamplerState::WrapMode wrapModes[2]) { |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 37 | return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix, |
| 38 | wrapModes)); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Create a Mitchell filter effect with a texture matrix and a domain. |
| 43 | */ |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 44 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 45 | const SkMatrix& matrix, |
| 46 | const SkRect& domain) { |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 47 | return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix, |
| 48 | domain)); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 52 | * Determines whether the bicubic effect should be used based on the transformation from the |
| 53 | * local coords to the device. Returns true if the bicubic effect should be used. filterMode |
| 54 | * is set to appropriate filtering mode to use regardless of the return result (e.g. when this |
| 55 | * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or |
| 56 | * kNearest). |
| 57 | */ |
| 58 | static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 59 | GrSamplerState::Filter* filterMode); |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 60 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 61 | private: |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 62 | GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 63 | const GrSamplerState::WrapMode wrapModes[2]); |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 64 | GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix &matrix, const SkRect& domain); |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 65 | explicit GrBicubicEffect(const GrBicubicEffect&); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 66 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 67 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 68 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 69 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 70 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 71 | bool onIsEqual(const GrFragmentProcessor&) const override; |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 72 | |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 73 | const TextureSampler& onTextureSampler(int) const override { return fTextureSampler; } |
| 74 | |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 75 | GrCoordTransform fCoordTransform; |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 76 | GrTextureDomain fDomain; |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 77 | TextureSampler fTextureSampler; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 78 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 79 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
skia.committer@gmail.com | c3723db | 2013-09-05 07:01:19 +0000 | [diff] [blame] | 80 | |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 81 | typedef GrFragmentProcessor INHERITED; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #endif |