Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: src/gpu/effects/GrBicubicEffect.cpp

Issue 1457543003: Add ShaderBuilders to EmitArgs and remove gettings from ProgBuilder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrBezierEffect.cpp ('k') | src/gpu/effects/GrBitmapTextGeoProc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 SkString cubicBlendName; 65 SkString cubicBlendName;
66 66
67 static const GrGLSLShaderVar gCubicBlendArgs[] = { 67 static const GrGLSLShaderVar gCubicBlendArgs[] = {
68 GrGLSLShaderVar("coefficients", kMat44f_GrSLType), 68 GrGLSLShaderVar("coefficients", kMat44f_GrSLType),
69 GrGLSLShaderVar("t", kFloat_GrSLType), 69 GrGLSLShaderVar("t", kFloat_GrSLType),
70 GrGLSLShaderVar("c0", kVec4f_GrSLType), 70 GrGLSLShaderVar("c0", kVec4f_GrSLType),
71 GrGLSLShaderVar("c1", kVec4f_GrSLType), 71 GrGLSLShaderVar("c1", kVec4f_GrSLType),
72 GrGLSLShaderVar("c2", kVec4f_GrSLType), 72 GrGLSLShaderVar("c2", kVec4f_GrSLType),
73 GrGLSLShaderVar("c3", kVec4f_GrSLType), 73 GrGLSLShaderVar("c3", kVec4f_GrSLType),
74 }; 74 };
75 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ; 75 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
76 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); 76 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
77 fsBuilder->emitFunction(kVec4f_GrSLType, 77 fragBuilder->emitFunction(kVec4f_GrSLType,
78 "cubicBlend", 78 "cubicBlend",
79 SK_ARRAY_COUNT(gCubicBlendArgs), 79 SK_ARRAY_COUNT(gCubicBlendArgs),
80 gCubicBlendArgs, 80 gCubicBlendArgs,
81 "\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"
82 "\tvec4 c = coefficients * ts;\n" 82 "\tvec4 c = coefficients * ts;\n"
83 "\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 * c 3;\n",
84 &cubicBlendName); 84 &cubicBlendName);
85 fsBuilder->codeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c_s tr(), imgInc); 85 fragBuilder->codeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c _str(), imgInc);
86 // We unnormalize the coord in order to determine our fractional offset (f) within the texel 86 // We unnormalize the coord in order to determine our fractional offset (f) within the texel
87 // We then snap coord to a texel center and renormalize. The snap prevents c ases where the 87 // We then snap coord to a texel center and renormalize. The snap prevents c ases where the
88 // starting coords are near a texel boundary and accumulations of imgInc wou ld cause us to skip/ 88 // starting coords are near a texel boundary and accumulations of imgInc wou ld cause us to skip/
89 // double hit a texel. 89 // double hit a texel.
90 fsBuilder->codeAppendf("\tcoord /= %s;\n", imgInc); 90 fragBuilder->codeAppendf("\tcoord /= %s;\n", imgInc);
91 fsBuilder->codeAppend("\tvec2 f = fract(coord);\n"); 91 fragBuilder->codeAppend("\tvec2 f = fract(coord);\n");
92 fsBuilder->codeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc); 92 fragBuilder->codeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc );
93 fsBuilder->codeAppend("\tvec4 rowColors[4];\n"); 93 fragBuilder->codeAppend("\tvec4 rowColors[4];\n");
94 for (int y = 0; y < 4; ++y) { 94 for (int y = 0; y < 4; ++y) {
95 for (int x = 0; x < 4; ++x) { 95 for (int x = 0; x < 4; ++x) {
96 SkString coord; 96 SkString coord;
97 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); 97 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1);
98 SkString sampleVar; 98 SkString sampleVar;
99 sampleVar.printf("rowColors[%d]", x); 99 sampleVar.printf("rowColors[%d]", x);
100 fDomain.sampleTexture(fsBuilder, domain, sampleVar.c_str(), coord, a rgs.fSamplers[0]); 100 fDomain.sampleTexture(fragBuilder, domain, sampleVar.c_str(), coord, args.fSamplers[0]);
101 } 101 }
102 fsBuilder->codeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors [1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); 102 fragBuilder->codeAppendf(
103 "\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors[1], rowColors[2], rowColors[3]);\n",
104 y, cubicBlendName.c_str(), coeff);
103 } 105 }
104 SkString bicubicColor; 106 SkString bicubicColor;
105 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c oeff); 107 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c oeff);
106 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,(GrGLSLExpr4(bicubi cColor.c_str()) * 108 fragBuilder->codeAppendf("\t%s = %s;\n",
107 GrGLSLExpr4(args.fInputColor)).c_str()); 109 args.fOutputColor, (GrGLSLExpr4(bicubicColor.c_str( )) *
110 GrGLSLExpr4(args.fInputColor)). c_str());
108 } 111 }
109 112
110 void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, 113 void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman,
111 const GrProcessor& processor) { 114 const GrProcessor& processor) {
112 const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); 115 const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>();
113 const GrTexture& texture = *processor.texture(0); 116 const GrTexture& texture = *processor.texture(0);
114 float imageIncrement[2]; 117 float imageIncrement[2];
115 imageIncrement[0] = 1.0f / texture.width(); 118 imageIncrement[0] = 1.0f / texture.width();
116 imageIncrement[1] = 1.0f / texture.height(); 119 imageIncrement[1] = 1.0f / texture.height();
117 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); 120 pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Use bilerp to handle rotation or fractional translation. 212 // Use bilerp to handle rotation or fractional translation.
210 *filterMode = GrTextureParams::kBilerp_FilterMode; 213 *filterMode = GrTextureParams::kBilerp_FilterMode;
211 } 214 }
212 return false; 215 return false;
213 } 216 }
214 // When we use the bicubic filtering effect each sample is read from the tex ture using 217 // When we use the bicubic filtering effect each sample is read from the tex ture using
215 // nearest neighbor sampling. 218 // nearest neighbor sampling.
216 *filterMode = GrTextureParams::kNone_FilterMode; 219 *filterMode = GrTextureParams::kNone_FilterMode;
217 return true; 220 return true;
218 } 221 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBezierEffect.cpp ('k') | src/gpu/effects/GrBitmapTextGeoProc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698