| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkMagnifierImageFilter.h" | 9 #include "SkMagnifierImageFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder, | 124 void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder, |
| 125 const GrDrawEffect&, | 125 const GrDrawEffect&, |
| 126 EffectKey key, | 126 EffectKey key, |
| 127 const char* outputColor, | 127 const char* outputColor, |
| 128 const char* inputColor, | 128 const char* inputColor, |
| 129 const TextureSamplerArray& samplers) { | 129 const TextureSamplerArray& samplers) { |
| 130 SkString coords; | 130 SkString coords; |
| 131 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); | 131 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); |
| 132 fOffsetVar = builder->addUniform( | 132 fOffsetVar = builder->addUniform( |
| 133 GrGLShaderBuilder::kFragment_ShaderType | | 133 GrGLShaderBuilder::kFragment_Visibility | |
| 134 GrGLShaderBuilder::kVertex_ShaderType, | 134 GrGLShaderBuilder::kVertex_Visibility, |
| 135 kVec2f_GrSLType, "uOffset"); | 135 kVec2f_GrSLType, "uOffset"); |
| 136 fZoomVar = builder->addUniform( | 136 fZoomVar = builder->addUniform( |
| 137 GrGLShaderBuilder::kFragment_ShaderType | | 137 GrGLShaderBuilder::kFragment_Visibility | |
| 138 GrGLShaderBuilder::kVertex_ShaderType, | 138 GrGLShaderBuilder::kVertex_Visibility, |
| 139 kVec2f_GrSLType, "uZoom"); | 139 kVec2f_GrSLType, "uZoom"); |
| 140 fInsetVar = builder->addUniform( | 140 fInsetVar = builder->addUniform( |
| 141 GrGLShaderBuilder::kFragment_ShaderType | | 141 GrGLShaderBuilder::kFragment_Visibility | |
| 142 GrGLShaderBuilder::kVertex_ShaderType, | 142 GrGLShaderBuilder::kVertex_Visibility, |
| 143 kVec2f_GrSLType, "uInset"); | 143 kVec2f_GrSLType, "uInset"); |
| 144 | 144 |
| 145 builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str()); | 145 builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str()); |
| 146 builder->fsCodeAppendf("\t\tvec2 zoom_coord = %s + %s / %s;\n", | 146 builder->fsCodeAppendf("\t\tvec2 zoom_coord = %s + %s / %s;\n", |
| 147 builder->getUniformCStr(fOffsetVar), | 147 builder->getUniformCStr(fOffsetVar), |
| 148 coords.c_str(), | 148 coords.c_str(), |
| 149 builder->getUniformCStr(fZoomVar)); | 149 builder->getUniformCStr(fZoomVar)); |
| 150 | 150 |
| 151 builder->fsCodeAppend("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\
n"); | 151 builder->fsCodeAppend("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\
n"); |
| 152 | 152 |
| 153 builder->fsCodeAppendf("\t\tdelta = delta / %s;\n", builder->getUniformCStr(
fInsetVar)); | 153 builder->fsCodeAppendf("\t\tdelta = delta / %s;\n", builder->getUniformCStr(
fInsetVar)); |
| 154 | 154 |
| 155 builder->fsCodeAppend("\t\tfloat weight = 0.0;\n"); | 155 builder->fsCodeAppend("\t\tfloat weight = 0.0;\n"); |
| 156 builder->fsCodeAppend("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n"); | 156 builder->fsCodeAppend("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n"); |
| 157 builder->fsCodeAppend("\t\t\tdelta = vec2(2.0, 2.0) - delta;\n"); | 157 builder->fsCodeAppend("\t\t\tdelta = vec2(2.0, 2.0) - delta;\n"); |
| 158 builder->fsCodeAppend("\t\t\tfloat dist = length(delta);\n"); | 158 builder->fsCodeAppend("\t\t\tfloat dist = length(delta);\n"); |
| 159 builder->fsCodeAppend("\t\t\tdist = max(2.0 - dist, 0.0);\n"); | 159 builder->fsCodeAppend("\t\t\tdist = max(2.0 - dist, 0.0);\n"); |
| 160 builder->fsCodeAppend("\t\t\tweight = min(dist * dist, 1.0);\n"); | 160 builder->fsCodeAppend("\t\t\tweight = min(dist * dist, 1.0);\n"); |
| 161 builder->fsCodeAppend("\t\t} else {\n"); | 161 builder->fsCodeAppend("\t\t} else {\n"); |
| 162 builder->fsCodeAppend("\t\t\tvec2 delta_squared = delta * delta;\n"); | 162 builder->fsCodeAppend("\t\t\tvec2 delta_squared = delta * delta;\n"); |
| 163 builder->fsCodeAppend("\t\t\tweight = min(min(delta_squared.s, delta_squared
.y), 1.0);\n"); | 163 builder->fsCodeAppend("\t\t\tweight = min(min(delta_squared.s, delta_squared
.y), 1.0);\n"); |
| 164 builder->fsCodeAppend("\t\t}\n"); | 164 builder->fsCodeAppend("\t\t}\n"); |
| 165 | 165 |
| 166 builder->fsCodeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\
n"); | 166 builder->fsCodeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\
n"); |
| 167 builder->fsCodeAppend("\t\tvec4 output_color = "); | 167 builder->fsCodeAppend("\t\tvec4 output_color = "); |
| 168 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sample
rs[0], "mix_coord"); | 168 builder->fsAppendTextureLookup(samplers[0], "mix_coord"); |
| 169 builder->fsCodeAppend(";\n"); | 169 builder->fsCodeAppend(";\n"); |
| 170 | 170 |
| 171 builder->fsCodeAppendf("\t\t%s = output_color;", outputColor); | 171 builder->fsCodeAppendf("\t\t%s = output_color;", outputColor); |
| 172 SkString modulate; | 172 SkString modulate; |
| 173 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 173 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
| 174 builder->fsCodeAppend(modulate.c_str()); | 174 builder->fsCodeAppend(modulate.c_str()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman, | 177 void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman, |
| 178 const GrDrawEffect& drawEffect) { | 178 const GrDrawEffect& drawEffect) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); | 343 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); |
| 344 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); | 344 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); |
| 345 | 345 |
| 346 *dptr = sptr[y_val * width + x_val]; | 346 *dptr = sptr[y_val * width + x_val]; |
| 347 dptr++; | 347 dptr++; |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 return true; | 350 return true; |
| 351 } | 351 } |
| OLD | NEW |