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

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

Issue 23706003: Fix case where GrGLEffectMatrix gives back a dangling ptr for the coords var name. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Rob's comments Created 7 years, 3 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/SkBicubicImageFilter.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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 EffectKey key, 406 EffectKey key,
407 const char* outputColor, 407 const char* outputColor,
408 const char* inputColor, 408 const char* inputColor,
409 const TextureSamplerArray& samplers) { 409 const TextureSamplerArray& samplers) {
410 sk_ignore_unused_variable(inputColor); 410 sk_ignore_unused_variable(inputColor);
411 411
412 fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 412 fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
413 kVec2f_GrSLType, "Scale"); 413 kVec2f_GrSLType, "Scale");
414 const char* scaleUni = builder->getUniformCStr(fScaleUni); 414 const char* scaleUni = builder->getUniformCStr(fScaleUni);
415 415
416 const char* dCoordsIn; 416 SkString dCoordsIn;
417 GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode( 417 GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode(
418 builder, key, &dCoordsIn, NULL, "DISPL"); 418 builder, key, &dCoordsIn, NULL, "DISPL");
419 const char* cCoordsIn; 419 SkString cCoordsIn;
420 GrSLType cCoordsType = fColorEffectMatrix.emitCode( 420 GrSLType cCoordsType = fColorEffectMatrix.emitCode(
421 builder, key, &cCoordsIn, NULL, "COLOR"); 421 builder, key, &cCoordsIn, NULL, "COLOR");
422 422
423 const char* dColor = "dColor"; 423 const char* dColor = "dColor";
424 const char* cCoords = "cCoords"; 424 const char* cCoords = "cCoords";
425 const char* outOfBounds = "outOfBounds"; 425 const char* outOfBounds = "outOfBounds";
426 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use 426 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use
427 // a number smaller than that to approximate 0, but 427 // a number smaller than that to approximate 0, but
428 // leave room for 32-bit float GPU rounding e rrors. 428 // leave room for 32-bit float GPU rounding e rrors.
429 429
430 builder->fsCodeAppendf("\t\tvec4 %s = ", dColor); 430 builder->fsCodeAppendf("\t\tvec4 %s = ", dColor);
431 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, 431 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
432 samplers[0], 432 samplers[0],
433 dCoordsIn, 433 dCoordsIn.c_str(),
434 dCoordsType); 434 dCoordsType);
435 builder->fsCodeAppend(";\n"); 435 builder->fsCodeAppend(";\n");
436 436
437 // Unpremultiply the displacement 437 // Unpremultiply the displacement
438 builder->fsCodeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);", 438 builder->fsCodeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
439 dColor, dColor, nearZero, dColor, dColor); 439 dColor, dColor, nearZero, dColor, dColor);
440 440
441 builder->fsCodeAppendf("\t\tvec2 %s = %s + %s*(%s.", 441 builder->fsCodeAppendf("\t\tvec2 %s = %s + %s*(%s.",
442 cCoords, cCoordsIn, scaleUni, dColor); 442 cCoords, cCoordsIn.c_str(), scaleUni, dColor);
443 443
444 switch (fXChannelSelector) { 444 switch (fXChannelSelector) {
445 case SkDisplacementMapEffect::kR_ChannelSelectorType: 445 case SkDisplacementMapEffect::kR_ChannelSelectorType:
446 builder->fsCodeAppend("r"); 446 builder->fsCodeAppend("r");
447 break; 447 break;
448 case SkDisplacementMapEffect::kG_ChannelSelectorType: 448 case SkDisplacementMapEffect::kG_ChannelSelectorType:
449 builder->fsCodeAppend("g"); 449 builder->fsCodeAppend("g");
450 break; 450 break;
451 case SkDisplacementMapEffect::kB_ChannelSelectorType: 451 case SkDisplacementMapEffect::kB_ChannelSelectorType:
452 builder->fsCodeAppend("b"); 452 builder->fsCodeAppend("b");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 colorTex); 532 colorTex);
533 533
534 colorKey <<= GrGLEffectMatrix::kKeyBits; 534 colorKey <<= GrGLEffectMatrix::kKeyBits;
535 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits); 535 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits);
536 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits + 536 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix ::kKeyBits +
537 SkDisplacementMapEff ect::kKeyBits); 537 SkDisplacementMapEff ect::kKeyBits);
538 538
539 return xKey | yKey | displKey | colorKey; 539 return xKey | yKey | displKey | colorKey;
540 } 540 }
541 #endif 541 #endif
OLDNEW
« no previous file with comments | « src/effects/SkBicubicImageFilter.cpp ('k') | src/effects/SkLightingImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698