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" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 9 | #include "GrInvariantOutput.h" |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 10 | #include "glsl/GrGLSLColorSpaceXformHelper.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 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 15 | #define DS(x) SkDoubleToScalar(x) |
| 16 | |
| 17 | const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { |
| 18 | DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), |
| 19 | DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), |
| 20 | DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), |
| 21 | DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), |
| 22 | }; |
| 23 | |
| 24 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 25 | class GrGLBicubicEffect : public GrGLSLFragmentProcessor { |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 26 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 27 | void emitCode(EmitArgs&) override; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 28 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 29 | static inline void GenKey(const GrProcessor& effect, const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 30 | GrProcessorKeyBuilder* b) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 31 | const GrBicubicEffect& bicubicEffect = effect.cast<GrBicubicEffect>(); |
| 32 | b->add32(GrTextureDomain::GLDomain::DomainKey(bicubicEffect.domain())); |
brianosman | 77320db | 2016-09-07 08:09:10 -0700 | [diff] [blame] | 33 | b->add32(GrColorSpaceXform::XformKey(bicubicEffect.colorSpaceXform())); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 34 | } |
| 35 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 36 | protected: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 37 | void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 38 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 39 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 40 | typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 41 | |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 42 | UniformHandle fCoefficientsUni; |
| 43 | UniformHandle fImageIncrementUni; |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 44 | UniformHandle fColorSpaceXformUni; |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 45 | GrTextureDomain::GLDomain fDomain; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 46 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 47 | typedef GrGLSLFragmentProcessor INHERITED; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 50 | void GrGLBicubicEffect::emitCode(EmitArgs& args) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 51 | const GrBicubicEffect& bicubicEffect = args.fFp.cast<GrBicubicEffect>(); |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 52 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 53 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 54 | fCoefficientsUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 55 | kMat44f_GrSLType, kDefault_GrSLPrecision, |
| 56 | "Coefficients"); |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 57 | fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 58 | kVec2f_GrSLType, kDefault_GrSLPrecision, |
| 59 | "ImageIncrement"); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 60 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 61 | const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); |
| 62 | const char* coeff = uniformHandler->getUniformCStr(fCoefficientsUni); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 63 | |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 64 | GrGLSLColorSpaceXformHelper colorSpaceHelper(uniformHandler, bicubicEffect.colorSpaceXform(), |
| 65 | &fColorSpaceXformUni); |
| 66 | |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 67 | SkString cubicBlendName; |
| 68 | |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 69 | static const GrGLSLShaderVar gCubicBlendArgs[] = { |
| 70 | GrGLSLShaderVar("coefficients", kMat44f_GrSLType), |
| 71 | GrGLSLShaderVar("t", kFloat_GrSLType), |
| 72 | GrGLSLShaderVar("c0", kVec4f_GrSLType), |
| 73 | GrGLSLShaderVar("c1", kVec4f_GrSLType), |
| 74 | GrGLSLShaderVar("c2", kVec4f_GrSLType), |
| 75 | GrGLSLShaderVar("c3", kVec4f_GrSLType), |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 76 | }; |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 77 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | 1a1aa93 | 2016-09-12 09:30:36 -0700 | [diff] [blame] | 78 | SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 79 | fragBuilder->emitFunction(kVec4f_GrSLType, |
| 80 | "cubicBlend", |
| 81 | SK_ARRAY_COUNT(gCubicBlendArgs), |
| 82 | gCubicBlendArgs, |
| 83 | "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" |
| 84 | "\tvec4 c = coefficients * ts;\n" |
| 85 | "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n", |
| 86 | &cubicBlendName); |
| 87 | fragBuilder->codeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c_str(), imgInc); |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 88 | // We unnormalize the coord in order to determine our fractional offset (f) within the texel |
| 89 | // We then snap coord to a texel center and renormalize. The snap prevents cases where the |
| 90 | // starting coords are near a texel boundary and accumulations of imgInc would cause us to skip/ |
| 91 | // double hit a texel. |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 92 | fragBuilder->codeAppendf("\tcoord /= %s;\n", imgInc); |
| 93 | fragBuilder->codeAppend("\tvec2 f = fract(coord);\n"); |
| 94 | fragBuilder->codeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc); |
| 95 | fragBuilder->codeAppend("\tvec4 rowColors[4];\n"); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 96 | for (int y = 0; y < 4; ++y) { |
| 97 | for (int x = 0; x < 4; ++x) { |
| 98 | SkString coord; |
| 99 | coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 100 | SkString sampleVar; |
| 101 | sampleVar.printf("rowColors[%d]", x); |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 102 | fDomain.sampleTexture(fragBuilder, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 103 | args.fUniformHandler, |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 104 | args.fGLSLCaps, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 105 | bicubicEffect.domain(), |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 106 | sampleVar.c_str(), |
| 107 | coord, |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 108 | args.fTexSamplers[0]); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 109 | } |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 110 | fragBuilder->codeAppendf( |
| 111 | "\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors[1], rowColors[2], rowColors[3]);\n", |
| 112 | y, cubicBlendName.c_str(), coeff); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 113 | } |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 114 | SkString bicubicColor; |
| 115 | bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), coeff); |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 116 | if (colorSpaceHelper.getXformMatrix()) { |
brianosman | 77320db | 2016-09-07 08:09:10 -0700 | [diff] [blame] | 117 | SkString xformedColor; |
| 118 | fragBuilder->appendColorGamutXform(&xformedColor, bicubicColor.c_str(), &colorSpaceHelper); |
| 119 | bicubicColor.swap(xformedColor); |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 120 | } |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 121 | fragBuilder->codeAppendf("\t%s = %s;\n", |
| 122 | args.fOutputColor, (GrGLSLExpr4(bicubicColor.c_str()) * |
| 123 | GrGLSLExpr4(args.fInputColor)).c_str()); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 124 | } |
| 125 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 126 | void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 127 | const GrProcessor& processor) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 128 | const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame^] | 129 | GrTexture* texture = processor.textureSampler(0).getTexture(); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 130 | float imageIncrement[2]; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame^] | 131 | imageIncrement[0] = 1.0f / texture->width(); |
| 132 | imageIncrement[1] = 1.0f / texture->height(); |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 133 | pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 134 | pdman.setMatrix4f(fCoefficientsUni, bicubicEffect.coefficients()); |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame^] | 135 | fDomain.setData(pdman, bicubicEffect.domain(), texture->origin()); |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 136 | if (SkToBool(bicubicEffect.colorSpaceXform())) { |
brianosman | 5192475 | 2016-09-12 08:50:19 -0700 | [diff] [blame] | 137 | pdman.setSkMatrix44(fColorSpaceXformUni, bicubicEffect.colorSpaceXform()->srcToDst()); |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 138 | } |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static inline void convert_row_major_scalar_coeffs_to_column_major_floats(float dst[16], |
| 142 | const SkScalar src[16]) { |
| 143 | for (int y = 0; y < 4; y++) { |
| 144 | for (int x = 0; x < 4; x++) { |
| 145 | dst[x * 4 + y] = SkScalarToFloat(src[y * 4 + x]); |
| 146 | } |
| 147 | } |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 148 | } |
| 149 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 150 | GrBicubicEffect::GrBicubicEffect(GrTexture* texture, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 151 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 152 | const SkScalar coefficients[16], |
| 153 | const SkMatrix &matrix, |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 154 | const SkShader::TileMode tileModes[2]) |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 155 | : INHERITED(texture, nullptr, matrix, |
| 156 | GrTextureParams(tileModes, GrTextureParams::kNone_FilterMode)) |
| 157 | , fDomain(GrTextureDomain::IgnoredDomain()) |
| 158 | , fColorSpaceXform(std::move(colorSpaceXform)) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 159 | this->initClassID<GrBicubicEffect>(); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 160 | convert_row_major_scalar_coeffs_to_column_major_floats(fCoefficients, coefficients); |
| 161 | } |
| 162 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 163 | GrBicubicEffect::GrBicubicEffect(GrTexture* texture, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 164 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 165 | const SkScalar coefficients[16], |
| 166 | const SkMatrix &matrix, |
| 167 | const SkRect& domain) |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 168 | : INHERITED(texture, nullptr, matrix, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 169 | GrTextureParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode)) |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 170 | , fDomain(domain, GrTextureDomain::kClamp_Mode) |
| 171 | , fColorSpaceXform(std::move(colorSpaceXform)) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 172 | this->initClassID<GrBicubicEffect>(); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 173 | convert_row_major_scalar_coeffs_to_column_major_floats(fCoefficients, coefficients); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | GrBicubicEffect::~GrBicubicEffect() { |
| 177 | } |
| 178 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 179 | void GrBicubicEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 180 | GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 181 | GrGLBicubicEffect::GenKey(*this, caps, b); |
| 182 | } |
| 183 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 184 | GrGLSLFragmentProcessor* GrBicubicEffect::onCreateGLSLInstance() const { |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 185 | return new GrGLBicubicEffect; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 186 | } |
| 187 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 188 | bool GrBicubicEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 189 | const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 190 | return !memcmp(fCoefficients, s.coefficients(), 16) && |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 191 | fDomain == s.fDomain; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 192 | } |
| 193 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 194 | void GrBicubicEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 195 | // FIXME: Perhaps we can do better. |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 196 | inout->mulByUnknownSingleComponent(); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 197 | } |
| 198 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 199 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 200 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 201 | sk_sp<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 202 | int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 203 | GrProcessorUnitTest::kAlphaTextureIdx; |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 204 | SkScalar coefficients[16]; |
| 205 | for (int i = 0; i < 16; i++) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 206 | coefficients[i] = d->fRandom->nextSScalar1(); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 207 | } |
Brian Osman | e2f732f | 2016-10-03 14:23:50 -0400 | [diff] [blame] | 208 | auto colorSpaceXform = GrTest::TestColorXform(d->fRandom); |
| 209 | return GrBicubicEffect::Make(d->fTextures[texIdx], colorSpaceXform, coefficients); |
humper@google.com | 3aad3b0 | 2013-09-04 19:23:53 +0000 | [diff] [blame] | 210 | } |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 211 | |
| 212 | ////////////////////////////////////////////////////////////////////////////// |
| 213 | |
| 214 | bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix, |
| 215 | GrTextureParams::FilterMode* filterMode) { |
| 216 | if (matrix.isIdentity()) { |
| 217 | *filterMode = GrTextureParams::kNone_FilterMode; |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | SkScalar scales[2]; |
| 222 | if (!matrix.getMinMaxScales(scales) || scales[0] < SK_Scalar1) { |
| 223 | // Bicubic doesn't handle arbitrary minimization well, as src texels can be skipped |
| 224 | // entirely, |
| 225 | *filterMode = GrTextureParams::kMipMap_FilterMode; |
| 226 | return false; |
| 227 | } |
| 228 | // At this point if scales[1] == SK_Scalar1 then the matrix doesn't do any scaling. |
| 229 | if (scales[1] == SK_Scalar1) { |
| 230 | if (matrix.rectStaysRect() && SkScalarIsInt(matrix.getTranslateX()) && |
| 231 | SkScalarIsInt(matrix.getTranslateY())) { |
| 232 | *filterMode = GrTextureParams::kNone_FilterMode; |
| 233 | } else { |
| 234 | // Use bilerp to handle rotation or fractional translation. |
| 235 | *filterMode = GrTextureParams::kBilerp_FilterMode; |
| 236 | } |
| 237 | return false; |
| 238 | } |
| 239 | // When we use the bicubic filtering effect each sample is read from the texture using |
| 240 | // nearest neighbor sampling. |
| 241 | *filterMode = GrTextureParams::kNone_FilterMode; |
| 242 | return true; |
| 243 | } |