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 | |
Mike Reed | d2f4be3 | 2019-08-01 13:52:38 -0400 | [diff] [blame] | 8 | #include "src/core/SkMatrixPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/effects/GrBicubicEffect.h" |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrTexture.h" |
| 12 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 13 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 14 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 15 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 16 | class GrGLBicubicEffect : public GrGLSLFragmentProcessor { |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 17 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 18 | void emitCode(EmitArgs&) override; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 19 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 20 | static inline void GenKey(const GrProcessor& effect, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 21 | GrProcessorKeyBuilder* b) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 22 | const GrBicubicEffect& bicubicEffect = effect.cast<GrBicubicEffect>(); |
| 23 | b->add32(GrTextureDomain::GLDomain::DomainKey(bicubicEffect.domain())); |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 24 | uint32_t bidir = bicubicEffect.direction() == GrBicubicEffect::Direction::kXY ? 1 : 0; |
| 25 | b->add32(bidir | (bicubicEffect.alphaType() << 1)); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 26 | } |
| 27 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 28 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 29 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 30 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 31 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 32 | typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 33 | |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 34 | UniformHandle fDimensions; |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 35 | GrTextureDomain::GLDomain fDomain; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 36 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 37 | typedef GrGLSLFragmentProcessor INHERITED; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 40 | void GrGLBicubicEffect::emitCode(EmitArgs& args) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 41 | const GrBicubicEffect& bicubicEffect = args.fFp.cast<GrBicubicEffect>(); |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 42 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 43 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 44 | fDimensions = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "Dimensions"); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 45 | |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 46 | const char* dims = uniformHandler->getUniformCStr(fDimensions); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 47 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 48 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Ethan Nicholas | d4efe68 | 2019-08-29 16:10:13 -0400 | [diff] [blame] | 49 | SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint); |
Brian Osman | a3fa2ef | 2017-01-06 16:13:06 +0000 | [diff] [blame] | 50 | |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 51 | /* |
| 52 | * Filter weights come from Don Mitchell & Arun Netravali's 'Reconstruction Filters in Computer |
| 53 | * Graphics', ACM SIGGRAPH Computer Graphics 22, 4 (Aug. 1988). |
| 54 | * ACM DL: http://dl.acm.org/citation.cfm?id=378514 |
| 55 | * Free : http://www.cs.utexas.edu/users/fussell/courses/cs384g/lectures/mitchell/Mitchell.pdf |
| 56 | * |
| 57 | * The authors define a family of cubic filters with two free parameters (B and C): |
| 58 | * |
| 59 | * { (12 - 9B - 6C)|x|^3 + (-18 + 12B + 6C)|x|^2 + (6 - 2B) if |x| < 1 |
| 60 | * k(x) = 1/6 { (-B - 6C)|x|^3 + (6B + 30C)|x|^2 + (-12B - 48C)|x| + (8B + 24C) if 1 <= |x| < 2 |
| 61 | * { 0 otherwise |
| 62 | * |
| 63 | * Various well-known cubic splines can be generated, and the authors select (1/3, 1/3) as their |
| 64 | * favorite overall spline - this is now commonly known as the Mitchell filter, and is the |
| 65 | * source of the specific weights below. |
| 66 | * |
| 67 | * This is GLSL, so the matrix is column-major (transposed from standard matrix notation). |
| 68 | */ |
| 69 | fragBuilder->codeAppend("half4x4 kMitchellCoefficients = half4x4(" |
| 70 | " 1.0 / 18.0, 16.0 / 18.0, 1.0 / 18.0, 0.0 / 18.0," |
| 71 | "-9.0 / 18.0, 0.0 / 18.0, 9.0 / 18.0, 0.0 / 18.0," |
| 72 | "15.0 / 18.0, -36.0 / 18.0, 27.0 / 18.0, -6.0 / 18.0," |
| 73 | "-7.0 / 18.0, 21.0 / 18.0, -21.0 / 18.0, 7.0 / 18.0);"); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 74 | fragBuilder->codeAppendf("float2 coord = %s - %s.xy * float2(0.5);", coords2D.c_str(), dims); |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 75 | // We unnormalize the coord in order to determine our fractional offset (f) within the texel |
| 76 | // We then snap coord to a texel center and renormalize. The snap prevents cases where the |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 77 | // starting coords are near a texel boundary and accumulations of dims would cause us to skip/ |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 78 | // double hit a texel. |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 79 | fragBuilder->codeAppendf("half2 f = half2(fract(coord * %s.zw));", dims); |
| 80 | fragBuilder->codeAppendf("coord = coord + (half2(0.5) - f) * %s.xy;", dims); |
| 81 | if (bicubicEffect.direction() == GrBicubicEffect::Direction::kXY) { |
| 82 | fragBuilder->codeAppend( |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 83 | "half4 wx = kMitchellCoefficients * half4(1.0, f.x, f.x * f.x, f.x * f.x * f.x);"); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 84 | fragBuilder->codeAppend( |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 85 | "half4 wy = kMitchellCoefficients * half4(1.0, f.y, f.y * f.y, f.y * f.y * f.y);"); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 86 | fragBuilder->codeAppend("half4 rowColors[4];"); |
| 87 | for (int y = 0; y < 4; ++y) { |
| 88 | for (int x = 0; x < 4; ++x) { |
| 89 | SkString coord; |
| 90 | coord.printf("coord + %s.xy * float2(%d, %d)", dims, x - 1, y - 1); |
| 91 | SkString sampleVar; |
| 92 | sampleVar.printf("rowColors[%d]", x); |
| 93 | fDomain.sampleTexture(fragBuilder, |
| 94 | args.fUniformHandler, |
| 95 | args.fShaderCaps, |
| 96 | bicubicEffect.domain(), |
| 97 | sampleVar.c_str(), |
| 98 | coord, |
| 99 | args.fTexSamplers[0]); |
| 100 | } |
| 101 | fragBuilder->codeAppendf( |
| 102 | "half4 s%d = wx.x * rowColors[0] + wx.y * rowColors[1] + wx.z * rowColors[2] + " |
| 103 | "wx.w * rowColors[3];", |
| 104 | y); |
| 105 | } |
| 106 | fragBuilder->codeAppend( |
| 107 | "half4 bicubicColor = wy.x * s0 + wy.y * s1 + wy.z * s2 + wy.w * s3;"); |
| 108 | } else { |
| 109 | // One of the dims.xy values will be zero. So v here selects the nonzero value of f. |
| 110 | fragBuilder->codeAppend("half v = f.x + f.y;"); |
| 111 | fragBuilder->codeAppend("half v2 = v * v;"); |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 112 | fragBuilder->codeAppend("half4 w = kMitchellCoefficients * half4(1.0, v, v2, v2 * v);"); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 113 | fragBuilder->codeAppend("half4 c[4];"); |
| 114 | for (int i = 0; i < 4; ++i) { |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 115 | SkString coord; |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 116 | coord.printf("coord + %s.xy * half(%d)", dims, i - 1); |
| 117 | SkString samplerVar; |
| 118 | samplerVar.printf("c[%d]", i); |
| 119 | // With added complexity we could apply the domain once in X or Y depending on |
| 120 | // direction rather than for each of the four lookups, but then we might not be |
| 121 | // be able to share code for Direction::kX and ::kY. |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 122 | fDomain.sampleTexture(fragBuilder, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 123 | args.fUniformHandler, |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 124 | args.fShaderCaps, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 125 | bicubicEffect.domain(), |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 126 | samplerVar.c_str(), |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 127 | coord, |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 128 | args.fTexSamplers[0]); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 129 | } |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 130 | fragBuilder->codeAppend( |
| 131 | "half4 bicubicColor = c[0] * w.x + c[1] * w.y + c[2] * w.z + c[3] * w.w;"); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 132 | } |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 133 | // Bicubic can send colors out of range, so clamp to get them back in (source) gamut. |
| 134 | // The kind of clamp we have to do depends on the alpha type. |
| 135 | if (kPremul_SkAlphaType == bicubicEffect.alphaType()) { |
| 136 | fragBuilder->codeAppend("bicubicColor.a = saturate(bicubicColor.a);"); |
| 137 | fragBuilder->codeAppend( |
| 138 | "bicubicColor.rgb = max(half3(0.0), min(bicubicColor.rgb, bicubicColor.aaa));"); |
| 139 | } else { |
| 140 | fragBuilder->codeAppend("bicubicColor = saturate(bicubicColor);"); |
| 141 | } |
| 142 | fragBuilder->codeAppendf("%s = bicubicColor * %s;", args.fOutputColor, args.fInputColor); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 143 | } |
| 144 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 145 | void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 146 | const GrFragmentProcessor& processor) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 147 | const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); |
Brian Salomon | 7da2fc7 | 2018-12-10 13:40:07 -0500 | [diff] [blame] | 148 | GrTextureProxy* proxy = processor.textureSampler(0).proxy(); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 149 | GrTexture* texture = proxy->peekTexture(); |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 150 | |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 151 | float dims[4] = {0, 0, 0, 0}; |
| 152 | if (bicubicEffect.direction() != GrBicubicEffect::Direction::kY) { |
| 153 | dims[0] = 1.0f / texture->width(); |
| 154 | dims[2] = texture->width(); |
| 155 | } |
| 156 | if (bicubicEffect.direction() != GrBicubicEffect::Direction::kX) { |
| 157 | dims[1] = 1.0f / texture->height(); |
| 158 | dims[3] = texture->height(); |
| 159 | } |
| 160 | pdman.set4fv(fDimensions, 1, dims); |
Michael Ludwig | be315a2 | 2018-12-17 09:50:51 -0500 | [diff] [blame] | 161 | fDomain.setData(pdman, bicubicEffect.domain(), proxy, |
| 162 | processor.textureSampler(0).samplerState()); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 165 | GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy, GrColorType srcColorType, |
| 166 | const SkMatrix& matrix, const SkRect& domain, |
| 167 | const GrSamplerState::WrapMode wrapModes[2], |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 168 | GrTextureDomain::Mode modeX, GrTextureDomain::Mode modeY, |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 169 | Direction direction, SkAlphaType alphaType) |
Michael Ludwig | 257a03d | 2018-12-13 14:07:07 -0500 | [diff] [blame] | 170 | : INHERITED{kGrBicubicEffect_ClassID, |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 171 | ModulateForSamplerOptFlags( |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 172 | srcColorType, |
| 173 | GrTextureDomain::IsDecalSampled(wrapModes, modeX, modeY))} |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 174 | , fCoordTransform(matrix, proxy.get()) |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 175 | , fDomain(proxy.get(), domain, modeX, modeY) |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 176 | , fTextureSampler(std::move(proxy), |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 177 | GrSamplerState(wrapModes, GrSamplerState::Filter::kNearest)) |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 178 | , fAlphaType(alphaType) |
| 179 | , fDirection(direction) { |
Brian Salomon | 6cd51b5 | 2017-07-26 19:07:15 -0400 | [diff] [blame] | 180 | this->addCoordTransform(&fCoordTransform); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 181 | this->setTextureSamplerCnt(1); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 182 | } |
| 183 | |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 184 | GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 185 | : INHERITED(kGrBicubicEffect_ClassID, that.optimizationFlags()) |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 186 | , fCoordTransform(that.fCoordTransform) |
| 187 | , fDomain(that.fDomain) |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 188 | , fTextureSampler(that.fTextureSampler) |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 189 | , fAlphaType(that.fAlphaType) |
| 190 | , fDirection(that.fDirection) { |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 191 | this->addCoordTransform(&fCoordTransform); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 192 | this->setTextureSamplerCnt(1); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 195 | void GrBicubicEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 196 | GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 197 | GrGLBicubicEffect::GenKey(*this, caps, b); |
| 198 | } |
| 199 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 200 | GrGLSLFragmentProcessor* GrBicubicEffect::onCreateGLSLInstance() const { |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 201 | return new GrGLBicubicEffect; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 202 | } |
| 203 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 204 | bool GrBicubicEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 205 | const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 206 | return fDomain == s.fDomain && fDirection == s.fDirection && fAlphaType == s.fAlphaType; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 207 | } |
| 208 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 209 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 210 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 211 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 212 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) { |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 213 | int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 214 | : GrProcessorUnitTest::kAlphaTextureIdx; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 215 | static const GrSamplerState::WrapMode kClampClamp[] = {GrSamplerState::WrapMode::kClamp, |
| 216 | GrSamplerState::WrapMode::kClamp}; |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 217 | SkAlphaType alphaType = d->fRandom->nextBool() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 218 | Direction direction = Direction::kX; |
| 219 | switch (d->fRandom->nextULessThan(3)) { |
| 220 | case 0: |
| 221 | direction = Direction::kX; |
| 222 | break; |
| 223 | case 1: |
| 224 | direction = Direction::kY; |
| 225 | break; |
| 226 | case 2: |
| 227 | direction = Direction::kXY; |
| 228 | break; |
| 229 | } |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 230 | return GrBicubicEffect::Make(d->textureProxy(texIdx), d->textureProxyColorType(texIdx), |
| 231 | SkMatrix::I(), kClampClamp, direction, alphaType); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 232 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 233 | #endif |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 234 | |
| 235 | ////////////////////////////////////////////////////////////////////////////// |
| 236 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 237 | bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix, GrSamplerState::Filter* filterMode) { |
Mike Reed | b2e3c64 | 2019-08-02 11:57:10 -0400 | [diff] [blame] | 238 | switch (SkMatrixPriv::AdjustHighQualityFilterLevel(matrix)) { |
Mike Reed | d2f4be3 | 2019-08-01 13:52:38 -0400 | [diff] [blame] | 239 | case kNone_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 240 | *filterMode = GrSamplerState::Filter::kNearest; |
Mike Reed | d2f4be3 | 2019-08-01 13:52:38 -0400 | [diff] [blame] | 241 | break; |
| 242 | case kLow_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 243 | *filterMode = GrSamplerState::Filter::kBilerp; |
Mike Reed | d2f4be3 | 2019-08-01 13:52:38 -0400 | [diff] [blame] | 244 | break; |
| 245 | case kMedium_SkFilterQuality: |
| 246 | *filterMode = GrSamplerState::Filter::kMipMap; |
| 247 | break; |
| 248 | case kHigh_SkFilterQuality: |
| 249 | // When we use the bicubic filtering effect each sample is read from the texture using |
| 250 | // nearest neighbor sampling. |
| 251 | *filterMode = GrSamplerState::Filter::kNearest; |
| 252 | return true; |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 253 | } |
Mike Reed | d2f4be3 | 2019-08-01 13:52:38 -0400 | [diff] [blame] | 254 | return false; |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 255 | } |