| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrBicubicEffect.h" | 8 #include "GrBicubicEffect.h" |
| 9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 11 #include "glsl/GrGLSLProgramBuilder.h" | |
| 12 #include "glsl/GrGLSLProgramDataManager.h" | 11 #include "glsl/GrGLSLProgramDataManager.h" |
| 12 #include "glsl/GrGLSLUniformHandler.h" |
| 13 | 13 |
| 14 #define DS(x) SkDoubleToScalar(x) | 14 #define DS(x) SkDoubleToScalar(x) |
| 15 | 15 |
| 16 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { | 16 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { |
| 17 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), | 17 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), |
| 18 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), | 18 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), |
| 19 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), | 19 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), |
| 20 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), | 20 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), |
| 21 }; | 21 }; |
| 22 | 22 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 45 | 45 |
| 46 typedef GrGLSLFragmentProcessor INHERITED; | 46 typedef GrGLSLFragmentProcessor INHERITED; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 GrGLBicubicEffect::GrGLBicubicEffect(const GrProcessor&) { | 49 GrGLBicubicEffect::GrGLBicubicEffect(const GrProcessor&) { |
| 50 } | 50 } |
| 51 | 51 |
| 52 void GrGLBicubicEffect::emitCode(EmitArgs& args) { | 52 void GrGLBicubicEffect::emitCode(EmitArgs& args) { |
| 53 const GrTextureDomain& domain = args.fFp.cast<GrBicubicEffect>().domain(); | 53 const GrTextureDomain& domain = args.fFp.cast<GrBicubicEffect>().domain(); |
| 54 | 54 |
| 55 fCoefficientsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment
_Visibility, | 55 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 56 kMat44f_GrSLType, kDefault_GrSLPrecis
ion, | 56 fCoefficientsUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragmen
t_Visibility, |
| 57 "Coefficients"); | 57 kMat44f_GrSLType, kDefault_GrS
LPrecision, |
| 58 fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, | 58 "Coefficients"); |
| 59 kVec2f_GrSLType, kDefault_GrSLPreci
sion, | 59 fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragm
ent_Visibility, |
| 60 "ImageIncrement"); | 60 kVec2f_GrSLType, kDefault_Gr
SLPrecision, |
| 61 "ImageIncrement"); |
| 61 | 62 |
| 62 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); | 63 const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); |
| 63 const char* coeff = args.fBuilder->getUniformCStr(fCoefficientsUni); | 64 const char* coeff = uniformHandler->getUniformCStr(fCoefficientsUni); |
| 64 | 65 |
| 65 SkString cubicBlendName; | 66 SkString cubicBlendName; |
| 66 | 67 |
| 67 static const GrGLSLShaderVar gCubicBlendArgs[] = { | 68 static const GrGLSLShaderVar gCubicBlendArgs[] = { |
| 68 GrGLSLShaderVar("coefficients", kMat44f_GrSLType), | 69 GrGLSLShaderVar("coefficients", kMat44f_GrSLType), |
| 69 GrGLSLShaderVar("t", kFloat_GrSLType), | 70 GrGLSLShaderVar("t", kFloat_GrSLType), |
| 70 GrGLSLShaderVar("c0", kVec4f_GrSLType), | 71 GrGLSLShaderVar("c0", kVec4f_GrSLType), |
| 71 GrGLSLShaderVar("c1", kVec4f_GrSLType), | 72 GrGLSLShaderVar("c1", kVec4f_GrSLType), |
| 72 GrGLSLShaderVar("c2", kVec4f_GrSLType), | 73 GrGLSLShaderVar("c2", kVec4f_GrSLType), |
| 73 GrGLSLShaderVar("c3", kVec4f_GrSLType), | 74 GrGLSLShaderVar("c3", kVec4f_GrSLType), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 fragBuilder->codeAppend("\tvec2 f = fract(coord);\n"); | 92 fragBuilder->codeAppend("\tvec2 f = fract(coord);\n"); |
| 92 fragBuilder->codeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc
); | 93 fragBuilder->codeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc
); |
| 93 fragBuilder->codeAppend("\tvec4 rowColors[4];\n"); | 94 fragBuilder->codeAppend("\tvec4 rowColors[4];\n"); |
| 94 for (int y = 0; y < 4; ++y) { | 95 for (int y = 0; y < 4; ++y) { |
| 95 for (int x = 0; x < 4; ++x) { | 96 for (int x = 0; x < 4; ++x) { |
| 96 SkString coord; | 97 SkString coord; |
| 97 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); | 98 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); |
| 98 SkString sampleVar; | 99 SkString sampleVar; |
| 99 sampleVar.printf("rowColors[%d]", x); | 100 sampleVar.printf("rowColors[%d]", x); |
| 100 fDomain.sampleTexture(fragBuilder, | 101 fDomain.sampleTexture(fragBuilder, |
| 102 args.fUniformHandler, |
| 101 args.fGLSLCaps, | 103 args.fGLSLCaps, |
| 102 domain, | 104 domain, |
| 103 sampleVar.c_str(), | 105 sampleVar.c_str(), |
| 104 coord, | 106 coord, |
| 105 args.fSamplers[0]); | 107 args.fSamplers[0]); |
| 106 } | 108 } |
| 107 fragBuilder->codeAppendf( | 109 fragBuilder->codeAppendf( |
| 108 "\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors[1], rowColors[2],
rowColors[3]);\n", | 110 "\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors[1], rowColors[2],
rowColors[3]);\n", |
| 109 y, cubicBlendName.c_str(), coeff); | 111 y, cubicBlendName.c_str(), coeff); |
| 110 } | 112 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // Use bilerp to handle rotation or fractional translation. | 219 // Use bilerp to handle rotation or fractional translation. |
| 218 *filterMode = GrTextureParams::kBilerp_FilterMode; | 220 *filterMode = GrTextureParams::kBilerp_FilterMode; |
| 219 } | 221 } |
| 220 return false; | 222 return false; |
| 221 } | 223 } |
| 222 // When we use the bicubic filtering effect each sample is read from the tex
ture using | 224 // When we use the bicubic filtering effect each sample is read from the tex
ture using |
| 223 // nearest neighbor sampling. | 225 // nearest neighbor sampling. |
| 224 *filterMode = GrTextureParams::kNone_FilterMode; | 226 *filterMode = GrTextureParams::kNone_FilterMode; |
| 225 return true; | 227 return true; |
| 226 } | 228 } |
| OLD | NEW |