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

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

Issue 1251173002: Added GrGLFragmentProcessor::EmitArgs struct for use with emitCode() (Closed) Base URL: https://skia.googlesource.com/skia@composeshader_gpu
Patch Set: Created 5 years, 5 months 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
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 "gl/builders/GrGLProgramBuilder.h" 10 #include "gl/builders/GrGLProgramBuilder.h"
11 11
12 #define DS(x) SkDoubleToScalar(x) 12 #define DS(x) SkDoubleToScalar(x)
13 13
14 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { 14 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = {
15 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), 15 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0),
16 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), 16 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0),
17 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), 17 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0),
18 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), 18 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0),
19 }; 19 };
20 20
21 21
22 class GrGLBicubicEffect : public GrGLFragmentProcessor { 22 class GrGLBicubicEffect : public GrGLFragmentProcessor {
23 public: 23 public:
24 GrGLBicubicEffect(const GrProcessor&); 24 GrGLBicubicEffect(const GrProcessor&);
25 25
26 virtual void emitCode(GrGLFPBuilder*, 26 virtual void emitCode(EmitArgs&) override;
27 const GrFragmentProcessor&,
28 const char* outputColor,
29 const char* inputColor,
30 const TransformedCoordsArray&,
31 const TextureSamplerArray&) override;
32 27
33 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 28 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
34 29
35 static inline void GenKey(const GrProcessor& effect, const GrGLSLCaps&, 30 static inline void GenKey(const GrProcessor& effect, const GrGLSLCaps&,
36 GrProcessorKeyBuilder* b) { 31 GrProcessorKeyBuilder* b) {
37 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); 32 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain();
38 b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); 33 b->add32(GrTextureDomain::GLDomain::DomainKey(domain));
39 } 34 }
40 35
41 private: 36 private:
42 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 37 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
43 38
44 UniformHandle fCoefficientsUni; 39 UniformHandle fCoefficientsUni;
45 UniformHandle fImageIncrementUni; 40 UniformHandle fImageIncrementUni;
46 GrTextureDomain::GLDomain fDomain; 41 GrTextureDomain::GLDomain fDomain;
47 42
48 typedef GrGLFragmentProcessor INHERITED; 43 typedef GrGLFragmentProcessor INHERITED;
49 }; 44 };
50 45
51 GrGLBicubicEffect::GrGLBicubicEffect(const GrProcessor&) { 46 GrGLBicubicEffect::GrGLBicubicEffect(const GrProcessor&) {
52 } 47 }
53 48
54 void GrGLBicubicEffect::emitCode(GrGLFPBuilder* builder, 49 void GrGLBicubicEffect::emitCode(EmitArgs& args) {
55 const GrFragmentProcessor& effect, 50 const GrTextureDomain& domain = args.fFp.cast<GrBicubicEffect>().domain();
56 const char* outputColor,
57 const char* inputColor,
58 const TransformedCoordsArray& coords,
59 const TextureSamplerArray& samplers) {
60 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain();
61 51
62 fCoefficientsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity, 52 fCoefficientsUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_V isibility,
63 kMat44f_GrSLType, kDefault_GrSLPrecis ion, 53 kMat44f_GrSLType, kDefault_GrSLPrecis ion,
64 "Coefficients"); 54 "Coefficients");
65 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility, 55 fImageIncrementUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment _Visibility,
66 kVec2f_GrSLType, kDefault_GrSLPreci sion, 56 kVec2f_GrSLType, kDefault_GrSLPreci sion,
67 "ImageIncrement"); 57 "ImageIncrement");
68 58
69 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 59 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni);
70 const char* coeff = builder->getUniformCStr(fCoefficientsUni); 60 const char* coeff = args.fBuilder->getUniformCStr(fCoefficientsUni);
71 61
72 SkString cubicBlendName; 62 SkString cubicBlendName;
73 63
74 static const GrGLShaderVar gCubicBlendArgs[] = { 64 static const GrGLShaderVar gCubicBlendArgs[] = {
75 GrGLShaderVar("coefficients", kMat44f_GrSLType), 65 GrGLShaderVar("coefficients", kMat44f_GrSLType),
76 GrGLShaderVar("t", kFloat_GrSLType), 66 GrGLShaderVar("t", kFloat_GrSLType),
77 GrGLShaderVar("c0", kVec4f_GrSLType), 67 GrGLShaderVar("c0", kVec4f_GrSLType),
78 GrGLShaderVar("c1", kVec4f_GrSLType), 68 GrGLShaderVar("c1", kVec4f_GrSLType),
79 GrGLShaderVar("c2", kVec4f_GrSLType), 69 GrGLShaderVar("c2", kVec4f_GrSLType),
80 GrGLShaderVar("c3", kVec4f_GrSLType), 70 GrGLShaderVar("c3", kVec4f_GrSLType),
81 }; 71 };
82 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 72 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
83 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); 73 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
84 fsBuilder->emitFunction(kVec4f_GrSLType, 74 fsBuilder->emitFunction(kVec4f_GrSLType,
85 "cubicBlend", 75 "cubicBlend",
86 SK_ARRAY_COUNT(gCubicBlendArgs), 76 SK_ARRAY_COUNT(gCubicBlendArgs),
87 gCubicBlendArgs, 77 gCubicBlendArgs,
88 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" 78 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n"
89 "\tvec4 c = coefficients * ts;\n" 79 "\tvec4 c = coefficients * ts;\n"
90 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3; \n", 80 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3; \n",
91 &cubicBlendName); 81 &cubicBlendName);
92 fsBuilder->codeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c_s tr(), imgInc); 82 fsBuilder->codeAppendf("\tvec2 coord = %s - %s * vec2(0.5);\n", coords2D.c_s tr(), imgInc);
93 // We unnormalize the coord in order to determine our fractional offset (f) within the texel 83 // We unnormalize the coord in order to determine our fractional offset (f) within the texel
94 // We then snap coord to a texel center and renormalize. The snap prevents c ases where the 84 // We then snap coord to a texel center and renormalize. The snap prevents c ases where the
95 // starting coords are near a texel boundary and accumulations of imgInc wou ld cause us to skip/ 85 // starting coords are near a texel boundary and accumulations of imgInc wou ld cause us to skip/
96 // double hit a texel. 86 // double hit a texel.
97 fsBuilder->codeAppendf("\tcoord /= %s;\n", imgInc); 87 fsBuilder->codeAppendf("\tcoord /= %s;\n", imgInc);
98 fsBuilder->codeAppend("\tvec2 f = fract(coord);\n"); 88 fsBuilder->codeAppend("\tvec2 f = fract(coord);\n");
99 fsBuilder->codeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc); 89 fsBuilder->codeAppendf("\tcoord = (coord - f + vec2(0.5)) * %s;\n", imgInc);
100 fsBuilder->codeAppend("\tvec4 rowColors[4];\n"); 90 fsBuilder->codeAppend("\tvec4 rowColors[4];\n");
101 for (int y = 0; y < 4; ++y) { 91 for (int y = 0; y < 4; ++y) {
102 for (int x = 0; x < 4; ++x) { 92 for (int x = 0; x < 4; ++x) {
103 SkString coord; 93 SkString coord;
104 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); 94 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1);
105 SkString sampleVar; 95 SkString sampleVar;
106 sampleVar.printf("rowColors[%d]", x); 96 sampleVar.printf("rowColors[%d]", x);
107 fDomain.sampleTexture(fsBuilder, domain, sampleVar.c_str(), coord, s amplers[0]); 97 fDomain.sampleTexture(fsBuilder, domain, sampleVar.c_str(), coord, a rgs.fSamplers[0]);
108 } 98 }
109 fsBuilder->codeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors [1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); 99 fsBuilder->codeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors [1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff);
110 } 100 }
111 SkString bicubicColor; 101 SkString bicubicColor;
112 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c oeff); 102 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c oeff);
113 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, (GrGLSLExpr4(bicubicColo r.c_str()) * GrGLSLExpr4(inputColor)).c_str()); 103 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,(GrGLSLExpr4(bicubi cColor.c_str()) *
104 GrGLSLExpr4(args.fInputColor)).c_str());
114 } 105 }
115 106
116 void GrGLBicubicEffect::setData(const GrGLProgramDataManager& pdman, 107 void GrGLBicubicEffect::setData(const GrGLProgramDataManager& pdman,
117 const GrProcessor& processor) { 108 const GrProcessor& processor) {
118 const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); 109 const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>();
119 const GrTexture& texture = *processor.texture(0); 110 const GrTexture& texture = *processor.texture(0);
120 float imageIncrement[2]; 111 float imageIncrement[2];
121 imageIncrement[0] = 1.0f / texture.width(); 112 imageIncrement[0] = 1.0f / texture.width();
122 imageIncrement[1] = 1.0f / texture.height(); 113 imageIncrement[1] = 1.0f / texture.height();
123 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); 114 pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // Use bilerp to handle rotation or fractional translation. 209 // Use bilerp to handle rotation or fractional translation.
219 *filterMode = GrTextureParams::kBilerp_FilterMode; 210 *filterMode = GrTextureParams::kBilerp_FilterMode;
220 } 211 }
221 return false; 212 return false;
222 } 213 }
223 // 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
224 // nearest neighbor sampling. 215 // nearest neighbor sampling.
225 *filterMode = GrTextureParams::kNone_FilterMode; 216 *filterMode = GrTextureParams::kNone_FilterMode;
226 return true; 217 return true;
227 } 218 }
OLDNEW
« no previous file with comments | « src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698