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/GrGLProcessor.h" | 9 #include "gl/GrGLProcessor.h" |
10 #include "gl/GrGLTexture.h" | 10 #include "gl/GrGLTexture.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 78 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
79 | 79 |
80 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); | 80 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); |
81 | 81 |
82 // Manually unroll loop because some drivers don't; yields 20-30% speedup. | 82 // Manually unroll loop because some drivers don't; yields 20-30% speedup. |
83 for (int i = 0; i < width; i++) { | 83 for (int i = 0; i < width; i++) { |
84 SkString index; | 84 SkString index; |
85 SkString kernelIndex; | 85 SkString kernelIndex; |
86 index.appendS32(i); | 86 index.appendS32(i); |
87 kernel.appendArrayAccess(index.c_str(), &kernelIndex); | 87 kernel.appendArrayAccess(index.c_str(), &kernelIndex); |
| 88 |
| 89 if (this->useBounds()) { |
| 90 // We used to compute a bool indicating whether we're in bounds or n
ot, cast it to a |
| 91 // float, and then mul weight*texture_sample by the float. However,
the Adreno 430 seems |
| 92 // to have a bug that caused corruption. |
| 93 const char* bounds = builder->getUniformCStr(fBoundsUni); |
| 94 const char* component = this->direction() == Gr1DKernelEffect::kY_Di
rection ? "y" : "x"; |
| 95 fsBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {"
, |
| 96 component, bounds, component, bounds); |
| 97 } |
88 fsBuilder->codeAppendf("\t\t%s += ", outputColor); | 98 fsBuilder->codeAppendf("\t\t%s += ", outputColor); |
89 fsBuilder->appendTextureLookup(samplers[0], "coord"); | 99 fsBuilder->appendTextureLookup(samplers[0], "coord"); |
| 100 fsBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str()); |
90 if (this->useBounds()) { | 101 if (this->useBounds()) { |
91 const char* bounds = builder->getUniformCStr(fBoundsUni); | 102 fsBuilder->codeAppend("}"); |
92 const char* component = this->direction() == Gr1DKernelEffect::kY_Di
rection ? "y" : "x"; | |
93 fsBuilder->codeAppendf(" * float(coord.%s >= %s.x && coord.%s <= %s.
y)", | |
94 component, bounds, component, bounds); | |
95 } | 103 } |
96 fsBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str()); | |
97 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc); | 104 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc); |
98 } | 105 } |
99 | 106 |
100 SkString modulate; | 107 SkString modulate; |
101 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); | 108 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); |
102 fsBuilder->codeAppend(modulate.c_str()); | 109 fsBuilder->codeAppend(modulate.c_str()); |
103 } | 110 } |
104 | 111 |
105 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman, | 112 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman, |
106 const GrProcessor& processor) { | 113 const GrProcessor& processor) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 242 } |
236 | 243 |
237 bool useBounds = random->nextBool(); | 244 bool useBounds = random->nextBool(); |
238 return GrConvolutionEffect::Create(textures[texIdx], | 245 return GrConvolutionEffect::Create(textures[texIdx], |
239 dir, | 246 dir, |
240 radius, | 247 radius, |
241 kernel, | 248 kernel, |
242 useBounds, | 249 useBounds, |
243 bounds); | 250 bounds); |
244 } | 251 } |
OLD | NEW |