| 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 "gl/builders/GrGLProgramBuilder.h" | 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 11 #include "glsl/GrGLSLProgramBuilder.h" |
| 11 #include "glsl/GrGLSLProgramDataManager.h" | 12 #include "glsl/GrGLSLProgramDataManager.h" |
| 12 | 13 |
| 13 #define DS(x) SkDoubleToScalar(x) | 14 #define DS(x) SkDoubleToScalar(x) |
| 14 | 15 |
| 15 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { | 16 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { |
| 16 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), |
| 17 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), |
| 18 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), |
| 19 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), |
| 20 }; | 21 }; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 typedef GrGLFragmentProcessor INHERITED; | 46 typedef GrGLFragmentProcessor INHERITED; |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 GrGLBicubicEffect::GrGLBicubicEffect(const GrProcessor&) { | 49 GrGLBicubicEffect::GrGLBicubicEffect(const GrProcessor&) { |
| 49 } | 50 } |
| 50 | 51 |
| 51 void GrGLBicubicEffect::emitCode(EmitArgs& args) { | 52 void GrGLBicubicEffect::emitCode(EmitArgs& args) { |
| 52 const GrTextureDomain& domain = args.fFp.cast<GrBicubicEffect>().domain(); | 53 const GrTextureDomain& domain = args.fFp.cast<GrBicubicEffect>().domain(); |
| 53 | 54 |
| 54 fCoefficientsUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_V
isibility, | 55 fCoefficientsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment
_Visibility, |
| 55 kMat44f_GrSLType, kDefault_GrSLPrecis
ion, | 56 kMat44f_GrSLType, kDefault_GrSLPrecis
ion, |
| 56 "Coefficients"); | 57 "Coefficients"); |
| 57 fImageIncrementUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 58 fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, |
| 58 kVec2f_GrSLType, kDefault_GrSLPreci
sion, | 59 kVec2f_GrSLType, kDefault_GrSLPreci
sion, |
| 59 "ImageIncrement"); | 60 "ImageIncrement"); |
| 60 | 61 |
| 61 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); | 62 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); |
| 62 const char* coeff = args.fBuilder->getUniformCStr(fCoefficientsUni); | 63 const char* coeff = args.fBuilder->getUniformCStr(fCoefficientsUni); |
| 63 | 64 |
| 64 SkString cubicBlendName; | 65 SkString cubicBlendName; |
| 65 | 66 |
| 66 static const GrGLSLShaderVar gCubicBlendArgs[] = { | 67 static const GrGLSLShaderVar gCubicBlendArgs[] = { |
| 67 GrGLSLShaderVar("coefficients", kMat44f_GrSLType), | 68 GrGLSLShaderVar("coefficients", kMat44f_GrSLType), |
| 68 GrGLSLShaderVar("t", kFloat_GrSLType), | 69 GrGLSLShaderVar("t", kFloat_GrSLType), |
| 69 GrGLSLShaderVar("c0", kVec4f_GrSLType), | 70 GrGLSLShaderVar("c0", kVec4f_GrSLType), |
| 70 GrGLSLShaderVar("c1", kVec4f_GrSLType), | 71 GrGLSLShaderVar("c1", kVec4f_GrSLType), |
| 71 GrGLSLShaderVar("c2", kVec4f_GrSLType), | 72 GrGLSLShaderVar("c2", kVec4f_GrSLType), |
| 72 GrGLSLShaderVar("c3", kVec4f_GrSLType), | 73 GrGLSLShaderVar("c3", kVec4f_GrSLType), |
| 73 }; | 74 }; |
| 74 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 75 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 75 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 76 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 76 fsBuilder->emitFunction(kVec4f_GrSLType, | 77 fsBuilder->emitFunction(kVec4f_GrSLType, |
| 77 "cubicBlend", | 78 "cubicBlend", |
| 78 SK_ARRAY_COUNT(gCubicBlendArgs), | 79 SK_ARRAY_COUNT(gCubicBlendArgs), |
| 79 gCubicBlendArgs, | 80 gCubicBlendArgs, |
| 80 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" | 81 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" |
| 81 "\tvec4 c = coefficients * ts;\n" | 82 "\tvec4 c = coefficients * ts;\n" |
| 82 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;
\n", | 83 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;
\n", |
| 83 &cubicBlendName); | 84 &cubicBlendName); |
| 84 fsBuilder->codeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c_s
tr(), imgInc); | 85 fsBuilder->codeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c_s
tr(), imgInc); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // Use bilerp to handle rotation or fractional translation. | 209 // Use bilerp to handle rotation or fractional translation. |
| 209 *filterMode = GrTextureParams::kBilerp_FilterMode; | 210 *filterMode = GrTextureParams::kBilerp_FilterMode; |
| 210 } | 211 } |
| 211 return false; | 212 return false; |
| 212 } | 213 } |
| 213 // When we use the bicubic filtering effect each sample is read from the tex
ture using | 214 // When we use the bicubic filtering effect each sample is read from the tex
ture using |
| 214 // nearest neighbor sampling. | 215 // nearest neighbor sampling. |
| 215 *filterMode = GrTextureParams::kNone_FilterMode; | 216 *filterMode = GrTextureParams::kNone_FilterMode; |
| 216 return true; | 217 return true; |
| 217 } | 218 } |
| OLD | NEW |