OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrConvolutionEffect.h" | 8 #include "GrConvolutionEffect.h" |
9 #include "gl/GrGLEffect.h" | 9 #include "gl/GrGLEffect.h" |
10 #include "gl/GrGLEffectMatrix.h" | 10 #include "gl/GrGLEffectMatrix.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 | 58 |
59 void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, | 59 void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, |
60 const GrDrawEffect&, | 60 const GrDrawEffect&, |
61 EffectKey key, | 61 EffectKey key, |
62 const char* outputColor, | 62 const char* outputColor, |
63 const char* inputColor, | 63 const char* inputColor, |
64 const TextureSamplerArray& samplers) { | 64 const TextureSamplerArray& samplers) { |
65 SkString coords; | 65 SkString coords; |
66 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); | 66 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); |
67 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader
Type, | 67 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, |
68 kVec2f_GrSLType, "ImageIncrement"); | 68 kVec2f_GrSLType, "ImageIncrement"); |
69 if (this->useBounds()) { | 69 if (this->useBounds()) { |
70 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType
, | 70 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, |
71 kVec2f_GrSLType, "Bounds"); | 71 kVec2f_GrSLType, "Bounds"); |
72 } | 72 } |
73 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTyp
e, | 73 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibilit
y, |
74 kFloat_GrSLType, "Kernel", this->width
()); | 74 kFloat_GrSLType, "Kernel", this->width
()); |
75 | 75 |
76 builder->fsCodeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); | 76 builder->fsCodeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); |
77 | 77 |
78 int width = this->width(); | 78 int width = this->width(); |
79 const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni); | 79 const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni); |
80 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 80 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
81 | 81 |
82 builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords.c_str(),
fRadius, imgInc); | 82 builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords.c_str(),
fRadius, imgInc); |
83 | 83 |
84 // Manually unroll loop because some drivers don't; yields 20-30% speedup. | 84 // Manually unroll loop because some drivers don't; yields 20-30% speedup. |
85 for (int i = 0; i < width; i++) { | 85 for (int i = 0; i < width; i++) { |
86 SkString index; | 86 SkString index; |
87 SkString kernelIndex; | 87 SkString kernelIndex; |
88 index.appendS32(i); | 88 index.appendS32(i); |
89 kernel.appendArrayAccess(index.c_str(), &kernelIndex); | 89 kernel.appendArrayAccess(index.c_str(), &kernelIndex); |
90 builder->fsCodeAppendf("\t\t%s += ", outputColor); | 90 builder->fsCodeAppendf("\t\t%s += ", outputColor); |
91 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sa
mplers[0], "coord"); | 91 builder->fsAppendTextureLookup(samplers[0], "coord"); |
92 if (this->useBounds()) { | 92 if (this->useBounds()) { |
93 const char* bounds = builder->getUniformCStr(fBoundsUni); | 93 const char* bounds = builder->getUniformCStr(fBoundsUni); |
94 const char* component = this->direction() == Gr1DKernelEffect::kY_Di
rection ? "y" : "x"; | 94 const char* component = this->direction() == Gr1DKernelEffect::kY_Di
rection ? "y" : "x"; |
95 builder->fsCodeAppendf(" * float(coord.%s >= %s.x && coord.%s <= %s.
y)", | 95 builder->fsCodeAppendf(" * float(coord.%s >= %s.x && coord.%s <= %s.
y)", |
96 component, bounds, component, bounds); | 96 component, bounds, component, bounds); |
97 } | 97 } |
98 builder->fsCodeAppendf(" * %s;\n", kernelIndex.c_str()); | 98 builder->fsCodeAppendf(" * %s;\n", kernelIndex.c_str()); |
99 builder->fsCodeAppendf("\t\tcoord += %s;\n", imgInc); | 99 builder->fsCodeAppendf("\t\tcoord += %s;\n", imgInc); |
100 } | 100 } |
101 | 101 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 237 } |
238 | 238 |
239 bool useBounds = random->nextBool(); | 239 bool useBounds = random->nextBool(); |
240 return GrConvolutionEffect::Create(textures[texIdx], | 240 return GrConvolutionEffect::Create(textures[texIdx], |
241 dir, | 241 dir, |
242 radius, | 242 radius, |
243 kernel, | 243 kernel, |
244 useBounds, | 244 useBounds, |
245 bounds); | 245 bounds); |
246 } | 246 } |
OLD | NEW |