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

Side by Side Diff: src/effects/gradients/SkTwoPointRadialGradient.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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkTwoPointRadialGradient.h" 9 #include "SkTwoPointRadialGradient.h"
10 10
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 527
528 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, 528 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
529 const GrDrawEffect& drawEffect, 529 const GrDrawEffect& drawEffect,
530 EffectKey key, 530 EffectKey key,
531 const char* outputColor, 531 const char* outputColor,
532 const char* inputColor, 532 const char* inputColor,
533 const TextureSamplerArray& samplers) { 533 const TextureSamplerArray& samplers) {
534 534
535 this->emitYCoordUniform(builder); 535 this->emitYCoordUniform(builder);
536 const char* fsCoords; 536 SkString fsCoords;
537 const char* vsCoordsVarying; 537 SkString vsCoordsVarying;
538 GrSLType coordsVaryingType; 538 GrSLType coordsVaryingType;
539 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT ype); 539 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT ype);
540 540
541 // 2 copies of uniform array, 1 for each of vertex & fragment shader, 541 // 2 copies of uniform array, 1 for each of vertex & fragment shader,
542 // to work around Xoom bug. Doesn't seem to cause performance decrease 542 // to work around Xoom bug. Doesn't seem to cause performance decrease
543 // in test apps, but need to keep an eye on it. 543 // in test apps, but need to keep an eye on it.
544 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType , 544 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType ,
545 kFloat_GrSLType, "Radial2VSParams", 6 ); 545 kFloat_GrSLType, "Radial2VSParams", 6 );
546 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy pe, 546 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy pe,
547 kFloat_GrSLType, "Radial2FSParams", 6 ); 547 kFloat_GrSLType, "Radial2FSParams", 6 );
(...skipping 10 matching lines...) Expand all
558 SkString p3; 558 SkString p3;
559 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2); 559 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
560 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3); 560 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3);
561 561
562 // For radial gradients without perspective we can pass the linear 562 // For radial gradients without perspective we can pass the linear
563 // part of the quadratic as a varying. 563 // part of the quadratic as a varying.
564 if (kVec2f_GrSLType == coordsVaryingType) { 564 if (kVec2f_GrSLType == coordsVaryingType) {
565 // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3]) 565 // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
566 builder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n", 566 builder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
567 fVSVaryingName, p2.c_str(), 567 fVSVaryingName, p2.c_str(),
568 vsCoordsVarying, p3.c_str()); 568 vsCoordsVarying.c_str(), p3.c_str());
569 } 569 }
570 } 570 }
571 571
572 // FS 572 // FS
573 { 573 {
574 SkString cName("c"); 574 SkString cName("c");
575 SkString ac4Name("ac4"); 575 SkString ac4Name("ac4");
576 SkString rootName("root"); 576 SkString rootName("root");
577 SkString t; 577 SkString t;
578 SkString p0; 578 SkString p0;
(...skipping 10 matching lines...) Expand all
589 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5); 589 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5);
590 590
591 // If we we're able to interpolate the linear component, 591 // If we we're able to interpolate the linear component,
592 // bVar is the varying; otherwise compute it 592 // bVar is the varying; otherwise compute it
593 SkString bVar; 593 SkString bVar;
594 if (kVec2f_GrSLType == coordsVaryingType) { 594 if (kVec2f_GrSLType == coordsVaryingType) {
595 bVar = fFSVaryingName; 595 bVar = fFSVaryingName;
596 } else { 596 } else {
597 bVar = "b"; 597 bVar = "b";
598 builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n", 598 builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
599 bVar.c_str(), p2.c_str(), fsCoords, p3.c_str( )); 599 bVar.c_str(), p2.c_str(), fsCoords.c_str(), p 3.c_str());
600 } 600 }
601 601
602 // c = (x^2)+(y^2) - params[4] 602 // c = (x^2)+(y^2) - params[4]
603 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", 603 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
604 cName.c_str(), 604 cName.c_str(),
605 fsCoords, 605 fsCoords.c_str(),
606 fsCoords, 606 fsCoords.c_str(),
607 p4.c_str()); 607 p4.c_str());
608 608
609 // If we aren't degenerate, emit some extra code, and accept a slightly 609 // If we aren't degenerate, emit some extra code, and accept a slightly
610 // more complex coord. 610 // more complex coord.
611 if (!fIsDegenerate) { 611 if (!fIsDegenerate) {
612 612
613 // ac4 = 4.0 * params[0] * c 613 // ac4 = 4.0 * params[0] * c
614 builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n", 614 builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n",
615 ac4Name.c_str(), p0.c_str(), 615 ac4Name.c_str(), p0.c_str(),
616 cName.c_str()); 616 cName.c_str());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 } 705 }
706 706
707 #else 707 #else
708 708
709 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c onst { 709 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c onst {
710 SkDEBUGFAIL("Should not call in GPU-less build"); 710 SkDEBUGFAIL("Should not call in GPU-less build");
711 return NULL; 711 return NULL;
712 } 712 }
713 713
714 #endif 714 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkTwoPointConicalGradient.cpp ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698