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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/effects/GrTextureDomain.h" |
| 12 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 13 | |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 14 | class GrInvariantOutput; |
| 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 | |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 23 | enum class Direction { |
| 24 | /** Apply bicubic kernel in local coord x, nearest neighbor in y. */ |
| 25 | kX, |
| 26 | /** Apply bicubic kernel in local coord y, nearest neighbor in x. */ |
| 27 | kY, |
| 28 | /** Apply bicubic in both x and y. */ |
| 29 | kXY |
| 30 | }; |
| 31 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | const char* name() const override { return "Bicubic"; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 33 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 34 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 35 | return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(*this)); |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 36 | } |
| 37 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 38 | const GrTextureDomain& domain() const { return fDomain; } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 39 | |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 40 | Direction direction() const { return fDirection; } |
| 41 | |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 42 | SkAlphaType alphaType() const { return fAlphaType; } |
| 43 | |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 44 | /** |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 45 | * Create a Mitchell filter effect with specified texture matrix with clamp wrap mode. |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 46 | */ |
| 47 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 48 | GrColorType srcColorType, |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 49 | const SkMatrix& matrix, |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 50 | Direction direction, |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 51 | SkAlphaType alphaType) { |
| 52 | static constexpr GrSamplerState::WrapMode kClampClamp[] = { |
| 53 | GrSamplerState::WrapMode::kClamp, GrSamplerState::WrapMode::kClamp}; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 54 | return Make(std::move(proxy), srcColorType, matrix, kClampClamp, |
| 55 | GrTextureDomain::kIgnore_Mode, GrTextureDomain::kIgnore_Mode, direction, |
| 56 | alphaType); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 60 | * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 61 | */ |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 62 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 63 | GrColorType srcColorType, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 64 | const SkMatrix& matrix, |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 65 | const GrSamplerState::WrapMode wrapModes[2], |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 66 | Direction direction, |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 67 | SkAlphaType alphaType) { |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 68 | // Ignore the domain on x and y, since this factory relies solely on the wrap mode of the |
| 69 | // sampler to constrain texture coordinates |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 70 | return Make(std::move(proxy), srcColorType, matrix, wrapModes, |
| 71 | GrTextureDomain::kIgnore_Mode, GrTextureDomain::kIgnore_Mode, direction, |
| 72 | alphaType); |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 76 | * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. This |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 77 | * supports providing modes for the texture domain explicitly, in the event that it should |
| 78 | * override the behavior of the sampler's tile mode (e.g. clamp to border unsupported). |
| 79 | */ |
| 80 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 81 | GrColorType srcColorType, |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 82 | const SkMatrix& matrix, |
| 83 | const GrSamplerState::WrapMode wrapModes[2], |
| 84 | GrTextureDomain::Mode modeX, |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 85 | GrTextureDomain::Mode modeY, |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 86 | Direction direction, |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 87 | SkAlphaType alphaType, |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 88 | const SkRect* domain = nullptr) { |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 89 | SkRect resolvedDomain; |
| 90 | if (domain) { |
| 91 | resolvedDomain = *domain; |
| 92 | } else { |
| 93 | resolvedDomain = GrTextureDomain::MakeTexelDomain( |
| 94 | SkIRect::MakeSize(proxy->dimensions()), modeX, modeY); |
| 95 | } |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 96 | return std::unique_ptr<GrFragmentProcessor>( |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 97 | new GrBicubicEffect(std::move(proxy), srcColorType, matrix, resolvedDomain, |
| 98 | wrapModes, modeX, modeY, direction, alphaType)); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 102 | * Create a Mitchell filter effect with a texture matrix and a domain. |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 103 | */ |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 104 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 105 | GrColorType srcColorType, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 106 | const SkMatrix& matrix, |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 107 | const SkRect& domain, |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 108 | Direction direction, |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 109 | SkAlphaType alphaType) { |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 110 | static const GrSamplerState::WrapMode kClampClamp[] = { |
| 111 | GrSamplerState::WrapMode::kClamp, GrSamplerState::WrapMode::kClamp}; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 112 | return Make(std::move(proxy), srcColorType, matrix, kClampClamp, |
| 113 | GrTextureDomain::kClamp_Mode, GrTextureDomain::kClamp_Mode, direction, |
| 114 | alphaType, &domain); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 118 | * Determines whether the bicubic effect should be used based on the transformation from the |
| 119 | * local coords to the device. Returns true if the bicubic effect should be used. filterMode |
| 120 | * is set to appropriate filtering mode to use regardless of the return result (e.g. when this |
| 121 | * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or |
| 122 | * kNearest). |
| 123 | */ |
| 124 | static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 125 | GrSamplerState::Filter* filterMode); |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 126 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 127 | private: |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 128 | GrBicubicEffect(sk_sp<GrTextureProxy>, GrColorType srcColorType, const SkMatrix& matrix, |
| 129 | const SkRect& domain, const GrSamplerState::WrapMode wrapModes[2], |
| 130 | GrTextureDomain::Mode modeX, GrTextureDomain::Mode modeY, Direction direction, |
| 131 | SkAlphaType alphaType); |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 132 | explicit GrBicubicEffect(const GrBicubicEffect&); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 133 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 134 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 135 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 136 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 137 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 138 | bool onIsEqual(const GrFragmentProcessor&) const override; |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 139 | |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 140 | const TextureSampler& onTextureSampler(int) const override { return fTextureSampler; } |
| 141 | |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 142 | GrCoordTransform fCoordTransform; |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 143 | GrTextureDomain fDomain; |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 144 | TextureSampler fTextureSampler; |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 145 | SkAlphaType fAlphaType; |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 146 | Direction fDirection; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 147 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 148 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
skia.committer@gmail.com | c3723db | 2013-09-05 07:01:19 +0000 | [diff] [blame] | 149 | |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 150 | typedef GrFragmentProcessor INHERITED; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | #endif |