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

Side by Side Diff: src/effects/SkDisplacementMapEffect.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/SkColorMatrixFilter.cpp ('k') | src/effects/SkLightingImageFilter.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 2013 Google Inc. 2 * Copyright 2013 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 "SkDisplacementMapEffect.h" 8 #include "SkDisplacementMapEffect.h"
9 #include "SkFlattenableBuffers.h" 9 #include "SkFlattenableBuffers.h"
10 #include "SkUnPreMultiply.h" 10 #include "SkUnPreMultiply.h"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 kVec2f_GrSLType, "Scale"); 402 kVec2f_GrSLType, "Scale");
403 const char* scaleUni = builder->getUniformCStr(fScaleUni); 403 const char* scaleUni = builder->getUniformCStr(fScaleUni);
404 404
405 const char* dCoordsIn; 405 const char* dCoordsIn;
406 GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode( 406 GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode(
407 builder, key, vertexCoords, &dCoordsIn, NULL, "D ISPL"); 407 builder, key, vertexCoords, &dCoordsIn, NULL, "D ISPL");
408 const char* cCoordsIn; 408 const char* cCoordsIn;
409 GrSLType cCoordsType = fColorEffectMatrix.emitCode( 409 GrSLType cCoordsType = fColorEffectMatrix.emitCode(
410 builder, key, vertexCoords, &cCoordsIn, NULL, "C OLOR"); 410 builder, key, vertexCoords, &cCoordsIn, NULL, "C OLOR");
411 411
412 SkString* code = &builder->fFSCode;
413 const char* dColor = "dColor"; 412 const char* dColor = "dColor";
414 const char* cCoords = "cCoords"; 413 const char* cCoords = "cCoords";
415 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use 414 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use
416 // a number smaller than that to approximate 0, but 415 // a number smaller than that to approximate 0, but
417 // leave room for 32-bit float GPU rounding e rrors. 416 // leave room for 32-bit float GPU rounding e rrors.
418 417
419 code->appendf("\t\tvec4 %s = ", dColor); 418 builder->fsCodeAppendf("\t\tvec4 %s = ", dColor);
420 builder->appendTextureLookup(code, samplers[0], dCoordsIn, dCoordsType); 419 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
421 code->append(";\n"); 420 samplers[0],
421 dCoordsIn,
422 dCoordsType);
423 builder->fsCodeAppend(";\n");
422 424
423 // Unpremultiply the displacement 425 // Unpremultiply the displacement
424 code->appendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0 .0, 1.0);", 426 builder->fsCodeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
425 dColor, dColor, nearZero, dColor, dColor); 427 dColor, dColor, nearZero, dColor, dColor);
426 428
427 code->appendf("\t\tvec2 %s = %s + %s*(%s.", 429 builder->fsCodeAppendf("\t\tvec2 %s = %s + %s*(%s.",
428 cCoords, cCoordsIn, scaleUni, dColor); 430 cCoords, cCoordsIn, scaleUni, dColor);
429 431
430 switch (fXChannelSelector) { 432 switch (fXChannelSelector) {
431 case SkDisplacementMapEffect::kR_ChannelSelectorType: 433 case SkDisplacementMapEffect::kR_ChannelSelectorType:
432 code->append("r"); 434 builder->fsCodeAppend("r");
433 break; 435 break;
434 case SkDisplacementMapEffect::kG_ChannelSelectorType: 436 case SkDisplacementMapEffect::kG_ChannelSelectorType:
435 code->append("g"); 437 builder->fsCodeAppend("g");
436 break; 438 break;
437 case SkDisplacementMapEffect::kB_ChannelSelectorType: 439 case SkDisplacementMapEffect::kB_ChannelSelectorType:
438 code->append("b"); 440 builder->fsCodeAppend("b");
439 break; 441 break;
440 case SkDisplacementMapEffect::kA_ChannelSelectorType: 442 case SkDisplacementMapEffect::kA_ChannelSelectorType:
441 code->append("a"); 443 builder->fsCodeAppend("a");
442 break; 444 break;
443 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType: 445 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
444 default: 446 default:
445 SkASSERT(!"Unknown X channel selector"); 447 SkASSERT(!"Unknown X channel selector");
446 } 448 }
447 449
448 switch (fYChannelSelector) { 450 switch (fYChannelSelector) {
449 case SkDisplacementMapEffect::kR_ChannelSelectorType: 451 case SkDisplacementMapEffect::kR_ChannelSelectorType:
450 code->append("r"); 452 builder->fsCodeAppend("r");
451 break; 453 break;
452 case SkDisplacementMapEffect::kG_ChannelSelectorType: 454 case SkDisplacementMapEffect::kG_ChannelSelectorType:
453 code->append("g"); 455 builder->fsCodeAppend("g");
454 break; 456 break;
455 case SkDisplacementMapEffect::kB_ChannelSelectorType: 457 case SkDisplacementMapEffect::kB_ChannelSelectorType:
456 code->append("b"); 458 builder->fsCodeAppend("b");
457 break; 459 break;
458 case SkDisplacementMapEffect::kA_ChannelSelectorType: 460 case SkDisplacementMapEffect::kA_ChannelSelectorType:
459 code->append("a"); 461 builder->fsCodeAppend("a");
460 break; 462 break;
461 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType: 463 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
462 default: 464 default:
463 SkASSERT(!"Unknown Y channel selector"); 465 SkASSERT(!"Unknown Y channel selector");
464 } 466 }
465 code->append("-vec2(0.5));\t\t"); 467 builder->fsCodeAppend("-vec2(0.5));\t\t");
466 468
467 // FIXME : This can be achieved with a "clamp to border" texture repeat mode and 469 // FIXME : This can be achieved with a "clamp to border" texture repeat mode and
468 // a 0 border color instead of computing if cCoords is out of bounds here. 470 // a 0 border color instead of computing if cCoords is out of bounds here.
469 code->appendf( 471 builder->fsCodeAppendf(
470 "%s = any(greaterThan(vec4(vec2(0.0), %s), vec4(%s, vec2(1.0)))) ? vec4( 0.0) : ", 472 "%s = any(greaterThan(vec4(vec2(0.0), %s), vec4(%s, vec2(1.0)))) ? vec4( 0.0) : ",
471 outputColor, cCoords, cCoords); 473 outputColor, cCoords, cCoords);
472 builder->appendTextureLookup(code, samplers[1], cCoords, cCoordsType); 474 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
473 code->append(";\n"); 475 samplers[1],
476 cCoords,
477 cCoordsType);
478 builder->fsCodeAppend(";\n");
474 } 479 }
475 480
476 void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, const Gr EffectStage& stage) { 481 void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, const Gr EffectStage& stage) {
477 const GrDisplacementMapEffect& displacementMap = GetEffectFromStage<GrDispla cementMapEffect>(stage); 482 const GrDisplacementMapEffect& displacementMap = GetEffectFromStage<GrDispla cementMapEffect>(stage);
478 GrTexture* displTex = displacementMap.texture(0); 483 GrTexture* displTex = displacementMap.texture(0);
479 GrTexture* colorTex = displacementMap.texture(1); 484 GrTexture* colorTex = displacementMap.texture(1);
480 fDisplacementEffectMatrix.setData(uman, 485 fDisplacementEffectMatrix.setData(uman,
481 GrEffect::MakeDivByTextureWHMatrix(displTex ), 486 GrEffect::MakeDivByTextureWHMatrix(displTex ),
482 stage.getCoordChangeMatrix(), 487 stage.getCoordChangeMatrix(),
483 displTex); 488 displTex);
(...skipping 25 matching lines...) Expand all
509 colorTex); 514 colorTex);
510 515
511 colorKey <<= GrGLEffectMatrix::kKeyBits; 516 colorKey <<= GrGLEffectMatrix::kKeyBits;
512 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits); 517 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits);
513 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits + 518 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits +
514 SkDisplacementMapEff ect::kKeyBits); 519 SkDisplacementMapEff ect::kKeyBits);
515 520
516 return xKey | yKey | displKey | colorKey; 521 return xKey | yKey | displKey | colorKey;
517 } 522 }
518 #endif 523 #endif
OLDNEW
« no previous file with comments | « src/effects/SkColorMatrixFilter.cpp ('k') | src/effects/SkLightingImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698