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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/effects/GrBicubicEffect.h" |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 9 | |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 10 | #include "src/core/SkMatrixPriv.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 11 | #include "src/gpu/GrTexture.h" |
Michael Ludwig | b5bd1b3 | 2020-06-26 10:23:23 -0400 | [diff] [blame] | 12 | #include "src/gpu/effects/GrMatrixEffect.h" |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 13 | #include "src/gpu/effects/GrTextureEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 15 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 16 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
Brian Salomon | f990b6a | 2020-07-13 10:44:22 -0400 | [diff] [blame] | 17 | #include <cmath> |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 18 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 19 | class GrBicubicEffect::Impl : public GrFragmentProcessor::ProgramImpl { |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 20 | public: |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 21 | Impl() : fKernel{-1, -1} {} |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 22 | void emitCode(EmitArgs&) override; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 23 | |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 24 | protected: |
| 25 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
| 26 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 27 | private: |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 28 | SkImage::CubicResampler fKernel; |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 29 | UniformHandle fCoefficientUni; |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 30 | using INHERITED = ProgramImpl; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 33 | void GrBicubicEffect::Impl::emitCode(EmitArgs& args) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 34 | const GrBicubicEffect& bicubicEffect = args.fFp.cast<GrBicubicEffect>(); |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 35 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 36 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Brian Osman | a3fa2ef | 2017-01-06 16:13:06 +0000 | [diff] [blame] | 37 | |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 38 | const char* coeffs; |
| 39 | fCoefficientUni = args.fUniformHandler->addUniform(&args.fFp, kFragment_GrShaderFlag, |
| 40 | kHalf4x4_GrSLType, "coefficients", &coeffs); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 41 | // We determine our fractional offset (f) within the texel. We then snap coord to a texel |
| 42 | // center. The snap prevents cases where the starting coords are near a texel boundary and |
| 43 | // offsets with imperfect precision would cause us to skip/double hit a texel. |
| 44 | // The use of "texel" above is somewhat abstract as we're sampling a child processor. It is |
| 45 | // assumed the child processor represents something akin to a nearest neighbor sampled texture. |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 46 | if (bicubicEffect.fDirection == GrBicubicEffect::Direction::kXY) { |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 47 | fragBuilder->codeAppendf("float2 coord = %s - float2(0.5);", args.fSampleCoord); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 48 | fragBuilder->codeAppend("half2 f = half2(fract(coord));"); |
| 49 | fragBuilder->codeAppend("coord += 0.5 - f;"); |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 50 | fragBuilder->codeAppendf("half4 wx = %s * half4(1.0, f.x, f.x * f.x, f.x * f.x * f.x);", |
| 51 | coeffs); |
| 52 | fragBuilder->codeAppendf("half4 wy = %s * half4(1.0, f.y, f.y * f.y, f.y * f.y * f.y);", |
| 53 | coeffs); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 54 | fragBuilder->codeAppend("half4 rowColors[4];"); |
| 55 | for (int y = 0; y < 4; ++y) { |
| 56 | for (int x = 0; x < 4; ++x) { |
| 57 | SkString coord; |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 58 | coord.printf("coord + float2(%d, %d)", x - 1, y - 1); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 59 | auto childStr = |
| 60 | this->invokeChild(0, args, SkSL::String(coord.c_str(), coord.size())); |
| 61 | fragBuilder->codeAppendf("rowColors[%d] = %s;", x, childStr.c_str()); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 62 | } |
| 63 | fragBuilder->codeAppendf( |
| 64 | "half4 s%d = wx.x * rowColors[0] + wx.y * rowColors[1] + wx.z * rowColors[2] + " |
| 65 | "wx.w * rowColors[3];", |
| 66 | y); |
| 67 | } |
| 68 | fragBuilder->codeAppend( |
| 69 | "half4 bicubicColor = wy.x * s0 + wy.y * s1 + wy.z * s2 + wy.w * s3;"); |
| 70 | } else { |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 71 | const char* d = bicubicEffect.fDirection == Direction::kX ? "x" : "y"; |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 72 | fragBuilder->codeAppendf("float coord = %s.%s - 0.5;", args.fSampleCoord, d); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 73 | fragBuilder->codeAppend("half f = half(fract(coord));"); |
| 74 | fragBuilder->codeAppend("coord += 0.5 - f;"); |
| 75 | fragBuilder->codeAppend("half f2 = f * f;"); |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 76 | fragBuilder->codeAppendf("half4 w = %s * half4(1.0, f, f2, f2 * f);", coeffs); |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 77 | fragBuilder->codeAppend("half4 c[4];"); |
| 78 | for (int i = 0; i < 4; ++i) { |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 79 | SkString coord; |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 80 | if (bicubicEffect.fDirection == Direction::kX) { |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 81 | coord.printf("float2(coord + %d, %s.y)", i - 1, args.fSampleCoord); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 82 | } else { |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 83 | coord.printf("float2(%s.x, coord + %d)", args.fSampleCoord, i - 1); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 84 | } |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 85 | auto childStr = this->invokeChild(0, args, SkSL::String(coord.c_str(), coord.size())); |
| 86 | fragBuilder->codeAppendf("c[%d] = %s;", i, childStr.c_str()); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 87 | } |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 88 | fragBuilder->codeAppend( |
| 89 | "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] | 90 | } |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 91 | // Bicubic can send colors out of range, so clamp to get them back in (source) gamut. |
| 92 | // The kind of clamp we have to do depends on the alpha type. |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 93 | switch (bicubicEffect.fClamp) { |
| 94 | case Clamp::kUnpremul: |
| 95 | fragBuilder->codeAppend("bicubicColor = saturate(bicubicColor);"); |
| 96 | break; |
| 97 | case Clamp::kPremul: |
| 98 | fragBuilder->codeAppend( |
| 99 | "bicubicColor.rgb = max(half3(0.0), min(bicubicColor.rgb, bicubicColor.aaa));"); |
| 100 | break; |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 101 | } |
John Stiles | 4bdc121 | 2020-12-14 18:04:13 -0500 | [diff] [blame] | 102 | fragBuilder->codeAppendf("return bicubicColor;"); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 105 | #include "src/shaders/SkImageShader.h" |
| 106 | |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 107 | void GrBicubicEffect::Impl::onSetData(const GrGLSLProgramDataManager& pdm, |
| 108 | const GrFragmentProcessor& fp) { |
| 109 | auto& bicubicEffect = fp.cast<GrBicubicEffect>(); |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 110 | |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 111 | if (fKernel.B != bicubicEffect.fKernel.B || fKernel.C != bicubicEffect.fKernel.C) { |
| 112 | fKernel = bicubicEffect.fKernel; |
| 113 | pdm.setSkM44(fCoefficientUni, SkImageShader::CubicResamplerMatrix(fKernel.B, fKernel.C)); |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 117 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::Make(GrSurfaceProxyView view, |
| 118 | SkAlphaType alphaType, |
| 119 | const SkMatrix& matrix, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 120 | SkImage::CubicResampler kernel, |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 121 | Direction direction) { |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 122 | auto fp = GrTextureEffect::Make(std::move(view), alphaType, SkMatrix::I()); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 123 | auto clamp = kPremul_SkAlphaType == alphaType ? Clamp::kPremul : Clamp::kUnpremul; |
Michael Ludwig | b5bd1b3 | 2020-06-26 10:23:23 -0400 | [diff] [blame] | 124 | return GrMatrixEffect::Make(matrix, std::unique_ptr<GrFragmentProcessor>( |
| 125 | new GrBicubicEffect(std::move(fp), kernel, direction, clamp))); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::Make(GrSurfaceProxyView view, |
| 129 | SkAlphaType alphaType, |
| 130 | const SkMatrix& matrix, |
| 131 | const GrSamplerState::WrapMode wrapX, |
| 132 | const GrSamplerState::WrapMode wrapY, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 133 | SkImage::CubicResampler kernel, |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 134 | Direction direction, |
| 135 | const GrCaps& caps) { |
| 136 | GrSamplerState sampler(wrapX, wrapY, GrSamplerState::Filter::kNearest); |
| 137 | std::unique_ptr<GrFragmentProcessor> fp; |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 138 | fp = GrTextureEffect::Make(std::move(view), alphaType, SkMatrix::I(), sampler, caps); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 139 | auto clamp = kPremul_SkAlphaType == alphaType ? Clamp::kPremul : Clamp::kUnpremul; |
Michael Ludwig | b5bd1b3 | 2020-06-26 10:23:23 -0400 | [diff] [blame] | 140 | return GrMatrixEffect::Make(matrix, std::unique_ptr<GrFragmentProcessor>( |
| 141 | new GrBicubicEffect(std::move(fp), kernel, direction, clamp))); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::MakeSubset( |
| 145 | GrSurfaceProxyView view, |
| 146 | SkAlphaType alphaType, |
| 147 | const SkMatrix& matrix, |
| 148 | const GrSamplerState::WrapMode wrapX, |
| 149 | const GrSamplerState::WrapMode wrapY, |
| 150 | const SkRect& subset, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 151 | SkImage::CubicResampler kernel, |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 152 | Direction direction, |
| 153 | const GrCaps& caps) { |
| 154 | GrSamplerState sampler(wrapX, wrapY, GrSamplerState::Filter::kNearest); |
| 155 | std::unique_ptr<GrFragmentProcessor> fp; |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 156 | fp = GrTextureEffect::MakeSubset( |
| 157 | std::move(view), alphaType, SkMatrix::I(), sampler, subset, caps); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 158 | auto clamp = kPremul_SkAlphaType == alphaType ? Clamp::kPremul : Clamp::kUnpremul; |
Michael Ludwig | b5bd1b3 | 2020-06-26 10:23:23 -0400 | [diff] [blame] | 159 | return GrMatrixEffect::Make(matrix, std::unique_ptr<GrFragmentProcessor>( |
| 160 | new GrBicubicEffect(std::move(fp), kernel, direction, clamp))); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Brian Salomon | f990b6a | 2020-07-13 10:44:22 -0400 | [diff] [blame] | 163 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::MakeSubset( |
| 164 | GrSurfaceProxyView view, |
| 165 | SkAlphaType alphaType, |
| 166 | const SkMatrix& matrix, |
| 167 | const GrSamplerState::WrapMode wrapX, |
| 168 | const GrSamplerState::WrapMode wrapY, |
| 169 | const SkRect& subset, |
| 170 | const SkRect& domain, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 171 | SkImage::CubicResampler kernel, |
Brian Salomon | f990b6a | 2020-07-13 10:44:22 -0400 | [diff] [blame] | 172 | Direction direction, |
| 173 | const GrCaps& caps) { |
| 174 | auto lowerBound = [](float x) { return std::floor(x - 1.5f) + 0.5f; }; |
| 175 | auto upperBound = [](float x) { return std::floor(x + 1.5f) - 0.5f; }; |
| 176 | SkRect expandedDomain { |
| 177 | lowerBound(domain.fLeft) , |
| 178 | upperBound(domain.fRight) , |
| 179 | lowerBound(domain.fTop) , |
| 180 | upperBound(domain.fBottom) |
| 181 | }; |
| 182 | GrSamplerState sampler(wrapX, wrapY, GrSamplerState::Filter::kNearest); |
| 183 | std::unique_ptr<GrFragmentProcessor> fp; |
| 184 | fp = GrTextureEffect::MakeSubset( |
| 185 | std::move(view), alphaType, SkMatrix::I(), sampler, subset, expandedDomain, caps); |
| 186 | auto clamp = kPremul_SkAlphaType == alphaType ? Clamp::kPremul : Clamp::kUnpremul; |
| 187 | return GrMatrixEffect::Make(matrix, std::unique_ptr<GrFragmentProcessor>( |
| 188 | new GrBicubicEffect(std::move(fp), kernel, direction, clamp))); |
| 189 | } |
| 190 | |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 191 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::Make(std::unique_ptr<GrFragmentProcessor> fp, |
| 192 | SkAlphaType alphaType, |
| 193 | const SkMatrix& matrix, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 194 | SkImage::CubicResampler kernel, |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 195 | Direction direction) { |
| 196 | auto clamp = kPremul_SkAlphaType == alphaType ? Clamp::kPremul : Clamp::kUnpremul; |
Michael Ludwig | b5bd1b3 | 2020-06-26 10:23:23 -0400 | [diff] [blame] | 197 | return GrMatrixEffect::Make(matrix, std::unique_ptr<GrFragmentProcessor>( |
| 198 | new GrBicubicEffect(std::move(fp), kernel, direction, clamp))); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | GrBicubicEffect::GrBicubicEffect(std::unique_ptr<GrFragmentProcessor> fp, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 202 | SkImage::CubicResampler kernel, |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 203 | Direction direction, |
| 204 | Clamp clamp) |
John Stiles | de240ac | 2020-08-07 17:52:42 +0000 | [diff] [blame] | 205 | : INHERITED(kGrBicubicEffect_ClassID, ProcessorOptimizationFlags(fp.get())) |
Brian Salomon | 1af72d1 | 2020-06-25 10:47:26 -0400 | [diff] [blame] | 206 | , fKernel(kernel) |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 207 | , fDirection(direction) |
| 208 | , fClamp(clamp) { |
Michael Ludwig | b5bd1b3 | 2020-06-26 10:23:23 -0400 | [diff] [blame] | 209 | this->setUsesSampleCoordsDirectly(); |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 210 | this->registerChild(std::move(fp), SkSL::SampleUsage::Explicit()); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 211 | } |
| 212 | |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 213 | GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that) |
John Stiles | 307f8f5 | 2021-08-09 15:36:59 -0400 | [diff] [blame^] | 214 | : INHERITED(that) |
Brian Salomon | 1af72d1 | 2020-06-25 10:47:26 -0400 | [diff] [blame] | 215 | , fKernel(that.fKernel) |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 216 | , fDirection(that.fDirection) |
John Stiles | 307f8f5 | 2021-08-09 15:36:59 -0400 | [diff] [blame^] | 217 | , fClamp(that.fClamp) {} |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 218 | |
Brian Salomon | 13b2873 | 2021-08-06 15:33:58 -0400 | [diff] [blame] | 219 | void GrBicubicEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { |
Brian Salomon | 2e66ade | 2020-07-21 16:27:29 -0400 | [diff] [blame] | 220 | uint32_t key = (static_cast<uint32_t>(fDirection) << 0) | (static_cast<uint32_t>(fClamp) << 2); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 221 | b->add32(key); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 224 | std::unique_ptr<GrFragmentProcessor::ProgramImpl> GrBicubicEffect::onMakeProgramImpl() const { |
Brian Salomon | 18ab203 | 2021-02-23 10:07:05 -0500 | [diff] [blame] | 225 | return std::make_unique<Impl>(); |
| 226 | } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 227 | |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 228 | bool GrBicubicEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 229 | const auto& that = other.cast<GrBicubicEffect>(); |
Brian Salomon | c3622f4 | 2020-12-21 14:41:48 -0500 | [diff] [blame] | 230 | return fDirection == that.fDirection && |
| 231 | fClamp == that.fClamp && |
| 232 | fKernel.B == that.fKernel.B && |
| 233 | fKernel.C == that.fKernel.C; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 236 | SkPMColor4f GrBicubicEffect::constantOutputForConstantInput(const SkPMColor4f& input) const { |
| 237 | return GrFragmentProcessor::ConstantOutputForConstantInput(this->childProcessor(0), input); |
| 238 | } |
| 239 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 240 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 241 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 242 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 243 | std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) { |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 244 | Direction direction = Direction::kX; |
| 245 | switch (d->fRandom->nextULessThan(3)) { |
| 246 | case 0: |
| 247 | direction = Direction::kX; |
| 248 | break; |
| 249 | case 1: |
| 250 | direction = Direction::kY; |
| 251 | break; |
| 252 | case 2: |
| 253 | direction = Direction::kXY; |
| 254 | break; |
| 255 | } |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 256 | auto kernel = d->fRandom->nextBool() ? GrBicubicEffect::gMitchell |
| 257 | : GrBicubicEffect::gCatmullRom; |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 258 | auto m = GrTest::TestMatrix(d->fRandom); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 259 | switch (d->fRandom->nextULessThan(3)) { |
| 260 | case 0: { |
| 261 | auto [view, ct, at] = d->randomView(); |
| 262 | GrSamplerState::WrapMode wm[2]; |
| 263 | GrTest::TestWrapModes(d->fRandom, wm); |
Greg Daniel | ba51d68 | 2020-02-05 13:12:13 -0500 | [diff] [blame] | 264 | |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 265 | if (d->fRandom->nextBool()) { |
| 266 | SkRect subset; |
| 267 | subset.fLeft = d->fRandom->nextSScalar1() * view.width(); |
| 268 | subset.fTop = d->fRandom->nextSScalar1() * view.height(); |
| 269 | subset.fRight = d->fRandom->nextSScalar1() * view.width(); |
| 270 | subset.fBottom = d->fRandom->nextSScalar1() * view.height(); |
| 271 | subset.sort(); |
Brian Salomon | 1af72d1 | 2020-06-25 10:47:26 -0400 | [diff] [blame] | 272 | return MakeSubset(std::move(view), |
| 273 | at, |
| 274 | m, |
| 275 | wm[0], |
| 276 | wm[1], |
| 277 | subset, |
| 278 | kernel, |
| 279 | direction, |
| 280 | *d->caps()); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 281 | } |
Brian Salomon | 1af72d1 | 2020-06-25 10:47:26 -0400 | [diff] [blame] | 282 | return Make(std::move(view), at, m, wm[0], wm[1], kernel, direction, *d->caps()); |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 283 | } |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 284 | case 1: { |
| 285 | auto [view, ct, at] = d->randomView(); |
Brian Salomon | 1af72d1 | 2020-06-25 10:47:26 -0400 | [diff] [blame] | 286 | return Make(std::move(view), at, m, kernel, direction); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 287 | } |
| 288 | default: { |
| 289 | SkAlphaType at; |
| 290 | do { |
| 291 | at = static_cast<SkAlphaType>(d->fRandom->nextULessThan(kLastEnum_SkAlphaType + 1)); |
Brian Osman | 609f159 | 2020-07-01 15:14:39 -0400 | [diff] [blame] | 292 | } while (at == kUnknown_SkAlphaType); |
| 293 | return Make(GrProcessorUnitTest::MakeChildFP(d), at, m, kernel, direction); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame] | 294 | } |
Brian Salomon | d0d033a | 2020-02-18 16:59:28 -0500 | [diff] [blame] | 295 | } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 296 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 297 | #endif |