bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 8 | #include "GrBicubicEffect.h" |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 9 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 10 | #include "GrTexture.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 11 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 12 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLUniformHandler.h" |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 14 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 15 | class GrGLBicubicEffect : public GrGLSLFragmentProcessor { |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 16 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 17 | void emitCode(EmitArgs&) override; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 18 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 19 | static inline void GenKey(const GrProcessor& effect, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 20 | GrProcessorKeyBuilder* b) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 21 | const GrBicubicEffect& bicubicEffect = effect.cast<GrBicubicEffect>(); |
| 22 | b->add32(GrTextureDomain::GLDomain::DomainKey(bicubicEffect.domain())); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 23 | } |
| 24 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 25 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 26 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 27 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 28 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 29 | typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 30 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 31 | UniformHandle fImageIncrementUni; |
| 32 | GrTextureDomain::GLDomain fDomain; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 33 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 34 | typedef GrGLSLFragmentProcessor INHERITED; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 37 | void GrGLBicubicEffect::emitCode(EmitArgs& args) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 38 | const GrBicubicEffect& bicubicEffect = args.fFp.cast<GrBicubicEffect>(); |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 39 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 40 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 41 | fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 42 | "ImageIncrement"); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 43 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 44 | const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 45 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 46 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | 1a1aa93 | 2016-09-12 09:30:36 -0700 | [diff] [blame] | 47 | SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
Brian Osman | a3fa2ef | 2017-01-06 16:13:06 +0000 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Filter weights come from Don Mitchell & Arun Netravali's 'Reconstruction Filters in Computer |
| 51 | * Graphics', ACM SIGGRAPH Computer Graphics 22, 4 (Aug. 1988). |
| 52 | * ACM DL: http://dl.acm.org/citation.cfm?id=378514 |
| 53 | * Free : http://www.cs.utexas.edu/users/fussell/courses/cs384g/lectures/mitchell/Mitchell.pdf |
| 54 | * |
| 55 | * The authors define a family of cubic filters with two free parameters (B and C): |
| 56 | * |
| 57 | * { (12 - 9B - 6C)|x|^3 + (-18 + 12B + 6C)|x|^2 + (6 - 2B) if |x| < 1 |
| 58 | * k(x) = 1/6 { (-B - 6C)|x|^3 + (6B + 30C)|x|^2 + (-12B - 48C)|x| + (8B + 24C) if 1 <= |x| < 2 |
| 59 | * { 0 otherwise |
| 60 | * |
| 61 | * Various well-known cubic splines can be generated, and the authors select (1/3, 1/3) as their |
| 62 | * favorite overall spline - this is now commonly known as the Mitchell filter, and is the |
| 63 | * source of the specific weights below. |
| 64 | * |
| 65 | * This is GLSL, so the matrix is column-major (transposed from standard matrix notation). |
| 66 | */ |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 67 | fragBuilder->codeAppend("half4x4 kMitchellCoefficients = half4x4(" |
Brian Osman | a3fa2ef | 2017-01-06 16:13:06 +0000 | [diff] [blame] | 68 | " 1.0 / 18.0, 16.0 / 18.0, 1.0 / 18.0, 0.0 / 18.0," |
| 69 | "-9.0 / 18.0, 0.0 / 18.0, 9.0 / 18.0, 0.0 / 18.0," |
| 70 | "15.0 / 18.0, -36.0 / 18.0, 27.0 / 18.0, -6.0 / 18.0," |
| 71 | "-7.0 / 18.0, 21.0 / 18.0, -21.0 / 18.0, 7.0 / 18.0);"); |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 72 | fragBuilder->codeAppendf("float2 coord = %s - %s * float2(0.5);", coords2D.c_str(), imgInc); |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 73 | // We unnormalize the coord in order to determine our fractional offset (f) within the texel |
| 74 | // We then snap coord to a texel center and renormalize. The snap prevents cases where the |
| 75 | // starting coords are near a texel boundary and accumulations of imgInc would cause us to skip/ |
| 76 | // double hit a texel. |
Brian Osman | a3fa2ef | 2017-01-06 16:13:06 +0000 | [diff] [blame] | 77 | fragBuilder->codeAppendf("coord /= %s;", imgInc); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 78 | fragBuilder->codeAppend("half2 f = half2(fract(coord));"); |
| 79 | fragBuilder->codeAppendf("coord = (coord - f + half2(0.5)) * %s;", imgInc); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 80 | fragBuilder->codeAppend("half4 wx = kMitchellCoefficients * half4(1.0, f.x, f.x * f.x, f.x * f.x * f.x);"); |
| 81 | fragBuilder->codeAppend("half4 wy = kMitchellCoefficients * half4(1.0, f.y, f.y * f.y, f.y * f.y * f.y);"); |
| 82 | fragBuilder->codeAppend("half4 rowColors[4];"); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 83 | for (int y = 0; y < 4; ++y) { |
| 84 | for (int x = 0; x < 4; ++x) { |
| 85 | SkString coord; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 86 | coord.printf("coord + %s * float2(%d, %d)", imgInc, x - 1, y - 1); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 87 | SkString sampleVar; |
| 88 | sampleVar.printf("rowColors[%d]", x); |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 89 | fDomain.sampleTexture(fragBuilder, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 90 | args.fUniformHandler, |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 91 | args.fShaderCaps, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 92 | bicubicEffect.domain(), |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 93 | sampleVar.c_str(), |
| 94 | coord, |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 95 | args.fTexSamplers[0]); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 96 | } |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 97 | fragBuilder->codeAppendf( |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 98 | "half4 s%d = wx.x * rowColors[0] + wx.y * rowColors[1] + wx.z * rowColors[2] + wx.w * rowColors[3];", |
Brian Osman | a3fa2ef | 2017-01-06 16:13:06 +0000 | [diff] [blame] | 99 | y); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 100 | } |
Brian Osman | a3fa2ef | 2017-01-06 16:13:06 +0000 | [diff] [blame] | 101 | SkString bicubicColor("(wy.x * s0 + wy.y * s1 + wy.z * s2 + wy.w * s3)"); |
Ethan Nicholas | 2983f40 | 2017-05-08 09:36:08 -0400 | [diff] [blame] | 102 | fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, bicubicColor.c_str(), |
| 103 | args.fInputColor); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 104 | } |
| 105 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 106 | void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 107 | const GrFragmentProcessor& processor) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 108 | const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); |
Brian Salomon | 7da2fc7 | 2018-12-10 13:40:07 -0500 | [diff] [blame] | 109 | GrTextureProxy* proxy = processor.textureSampler(0).proxy(); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 110 | GrTexture* texture = proxy->peekTexture(); |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 111 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 112 | float imageIncrement[2]; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 113 | imageIncrement[0] = 1.0f / texture->width(); |
| 114 | imageIncrement[1] = 1.0f / texture->height(); |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 115 | pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 116 | fDomain.setData(pdman, bicubicEffect.domain(), proxy, |
| 117 | processor.textureSampler(0).samplerState()); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 120 | GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 121 | const SkMatrix& matrix, |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 122 | const GrSamplerState::WrapMode wrapModes[2], |
| 123 | GrTextureDomain::Mode modeX, GrTextureDomain::Mode modeY) |
Michael Ludwig | 257a03d | 2018-12-13 14:07:07 -0500 | [diff] [blame] | 124 | : INHERITED{kGrBicubicEffect_ClassID, |
| 125 | ModulateForSamplerOptFlags(proxy->config(), |
| 126 | GrTextureDomain::IsDecalSampled(wrapModes, modeX,modeY))} |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 127 | , fCoordTransform(matrix, proxy.get()) |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 128 | , fDomain(proxy.get(), |
| 129 | GrTextureDomain::MakeTexelDomain( |
| 130 | SkIRect::MakeWH(proxy->width(), proxy->height()), modeX, modeY), |
| 131 | modeX, modeY) |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 132 | , fTextureSampler(std::move(proxy), |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 133 | GrSamplerState(wrapModes, GrSamplerState::Filter::kNearest)) { |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 134 | this->addCoordTransform(&fCoordTransform); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 135 | this->setTextureSamplerCnt(1); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 136 | } |
| 137 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 138 | GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 139 | const SkMatrix& matrix, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 140 | const SkRect& domain) |
Michael Ludwig | 257a03d | 2018-12-13 14:07:07 -0500 | [diff] [blame] | 141 | : INHERITED(kGrBicubicEffect_ClassID, ModulateForClampedSamplerOptFlags(proxy->config())) |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 142 | , fCoordTransform(matrix, proxy.get()) |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 143 | , fDomain(proxy.get(), domain, GrTextureDomain::kClamp_Mode, GrTextureDomain::kClamp_Mode) |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 144 | , fTextureSampler(std::move(proxy)) { |
Michael Ludwig | 257a03d | 2018-12-13 14:07:07 -0500 | [diff] [blame] | 145 | // Make sure the sampler's ctor uses the clamp wrap mode |
| 146 | SkASSERT(fTextureSampler.samplerState().wrapModeX() == GrSamplerState::WrapMode::kClamp && |
| 147 | fTextureSampler.samplerState().wrapModeY() == GrSamplerState::WrapMode::kClamp); |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 148 | this->addCoordTransform(&fCoordTransform); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 149 | this->setTextureSamplerCnt(1); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 152 | GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 153 | : INHERITED(kGrBicubicEffect_ClassID, that.optimizationFlags()) |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 154 | , fCoordTransform(that.fCoordTransform) |
| 155 | , fDomain(that.fDomain) |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 156 | , fTextureSampler(that.fTextureSampler) { |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 157 | this->addCoordTransform(&fCoordTransform); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 158 | this->setTextureSamplerCnt(1); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 161 | void GrBicubicEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 162 | GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 163 | GrGLBicubicEffect::GenKey(*this, caps, b); |
| 164 | } |
| 165 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 166 | GrGLSLFragmentProcessor* GrBicubicEffect::onCreateGLSLInstance() const { |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 167 | return new GrGLBicubicEffect; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 168 | } |
| 169 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 170 | bool GrBicubicEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 171 | const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); |
Brian Osman | 0857527 | 2016-12-21 15:26:37 -0500 | [diff] [blame] | 172 | return fDomain == s.fDomain; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 173 | } |
| 174 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 175 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 176 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 177 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 178 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) { |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 179 | int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 180 | : GrProcessorUnitTest::kAlphaTextureIdx; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 181 | static const GrSamplerState::WrapMode kClampClamp[] = {GrSamplerState::WrapMode::kClamp, |
| 182 | GrSamplerState::WrapMode::kClamp}; |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 183 | return GrBicubicEffect::Make(d->textureProxy(texIdx), SkMatrix::I(), kClampClamp); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 184 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 185 | #endif |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 186 | |
| 187 | ////////////////////////////////////////////////////////////////////////////// |
| 188 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 189 | bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix, GrSamplerState::Filter* filterMode) { |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 190 | if (matrix.isIdentity()) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 191 | *filterMode = GrSamplerState::Filter::kNearest; |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 192 | return false; |
| 193 | } |
| 194 | |
| 195 | SkScalar scales[2]; |
| 196 | if (!matrix.getMinMaxScales(scales) || scales[0] < SK_Scalar1) { |
| 197 | // Bicubic doesn't handle arbitrary minimization well, as src texels can be skipped |
| 198 | // entirely, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 199 | *filterMode = GrSamplerState::Filter::kMipMap; |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 200 | return false; |
| 201 | } |
| 202 | // At this point if scales[1] == SK_Scalar1 then the matrix doesn't do any scaling. |
| 203 | if (scales[1] == SK_Scalar1) { |
| 204 | if (matrix.rectStaysRect() && SkScalarIsInt(matrix.getTranslateX()) && |
| 205 | SkScalarIsInt(matrix.getTranslateY())) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 206 | *filterMode = GrSamplerState::Filter::kNearest; |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 207 | } else { |
| 208 | // Use bilerp to handle rotation or fractional translation. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 209 | *filterMode = GrSamplerState::Filter::kBilerp; |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 210 | } |
| 211 | return false; |
| 212 | } |
| 213 | // When we use the bicubic filtering effect each sample is read from the texture using |
| 214 | // nearest neighbor sampling. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 215 | *filterMode = GrSamplerState::Filter::kNearest; |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 216 | return true; |
| 217 | } |