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

Side by Side Diff: src/effects/SkMorphologyImageFilter.cpp

Issue 12547012: Make GrGLEffects use an interface to append their code. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | src/effects/SkTableColorFilter.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 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 "SkMorphologyImageFilter.h" 8 #include "SkMorphologyImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 EffectKey key, 317 EffectKey key,
318 const char* vertexCoords, 318 const char* vertexCoords,
319 const char* outputColor, 319 const char* outputColor,
320 const char* inputColor, 320 const char* inputColor,
321 const TextureSamplerArray& samplers) { 321 const TextureSamplerArray& samplers) {
322 const char* coords; 322 const char* coords;
323 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords); 323 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
324 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader Type, 324 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader Type,
325 kVec2f_GrSLType, "ImageIncrement"); 325 kVec2f_GrSLType, "ImageIncrement");
326 326
327 SkString* code = &builder->fFSCode;
328
329 const char* func; 327 const char* func;
330 switch (fType) { 328 switch (fType) {
331 case GrMorphologyEffect::kErode_MorphologyType: 329 case GrMorphologyEffect::kErode_MorphologyType:
332 code->appendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor); 330 builder->fsCodeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor);
333 func = "min"; 331 func = "min";
334 break; 332 break;
335 case GrMorphologyEffect::kDilate_MorphologyType: 333 case GrMorphologyEffect::kDilate_MorphologyType:
336 code->appendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); 334 builder->fsCodeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor);
337 func = "max"; 335 func = "max";
338 break; 336 break;
339 default: 337 default:
340 GrCrash("Unexpected type"); 338 GrCrash("Unexpected type");
341 func = ""; // suppress warning 339 func = ""; // suppress warning
342 break; 340 break;
343 } 341 }
344 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 342 const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
345 343
346 code->appendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords, fRadius, imgInc) ; 344 builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords, fRadius , imgInc);
347 code->appendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width()); 345 builder->fsCodeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width() );
348 code->appendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor); 346 builder->fsCodeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor) ;
349 builder->appendTextureLookup(&builder->fFSCode, samplers[0], "coord"); 347 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sample rs[0], "coord");
350 code->appendf(");\n"); 348 builder->fsCodeAppend(");\n");
351 code->appendf("\t\t\tcoord += %s;\n", imgInc); 349 builder->fsCodeAppendf("\t\t\tcoord += %s;\n", imgInc);
352 code->appendf("\t\t}\n"); 350 builder->fsCodeAppend("\t\t}\n");
353 GrGLSLMulVarBy4f(code, 2, outputColor, inputColor); 351 SkString modulate;
352 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
353 builder->fsCodeAppend(modulate.c_str());
354 } 354 }
355 355
356 GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) { 356 GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
357 const GrMorphologyEffect& m = GetEffectFromStage<GrMorphologyEffect>(s); 357 const GrMorphologyEffect& m = GetEffectFromStage<GrMorphologyEffect>(s);
358 EffectKey key = static_cast<EffectKey>(m.radius()); 358 EffectKey key = static_cast<EffectKey>(m.radius());
359 key |= (m.type() << 8); 359 key |= (m.type() << 8);
360 key <<= GrGLEffectMatrix::kKeyBits; 360 key <<= GrGLEffectMatrix::kKeyBits;
361 EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(), 361 EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
362 s.getCoordChangeMatrix(), 362 s.getCoordChangeMatrix(),
363 m.texture(0)); 363 m.texture(0));
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 512 }
513 GrTexture* input = (GrTexture*) inputBM.getTexture(); 513 GrTexture* input = (GrTexture*) inputBM.getTexture();
514 SkIRect bounds; 514 SkIRect bounds;
515 src.getBounds(&bounds); 515 src.getBounds(&bounds);
516 SkAutoTUnref<GrTexture> resultTex(apply_morphology(input, bounds, 516 SkAutoTUnref<GrTexture> resultTex(apply_morphology(input, bounds,
517 GrMorphologyEffect::kErode_MorphologyType, radius())); 517 GrMorphologyEffect::kErode_MorphologyType, radius()));
518 return SkImageFilterUtils::WrapTexture(resultTex, src.width(), src.height(), result); 518 return SkImageFilterUtils::WrapTexture(resultTex, src.width(), src.height(), result);
519 } 519 }
520 520
521 #endif 521 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | src/effects/SkTableColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698