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

Side by Side Diff: src/effects/gradients/SkTwoPointConicalGradient.cpp

Issue 24853002: Make GPU coord transforms automatic (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkTwoPointConicalGradient.h" 8 #include "SkTwoPointConicalGradient.h"
9 9
10 static int valid_divide(float numer, float denom, float* ratio) { 10 static int valid_divide(float numer, float denom, float* ratio) {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 public: 340 public:
341 341
342 GrGLConical2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffe ct&); 342 GrGLConical2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffe ct&);
343 virtual ~GrGLConical2Gradient() { } 343 virtual ~GrGLConical2Gradient() { }
344 344
345 virtual void emitCode(GrGLShaderBuilder*, 345 virtual void emitCode(GrGLShaderBuilder*,
346 const GrDrawEffect&, 346 const GrDrawEffect&,
347 EffectKey, 347 EffectKey,
348 const char* outputColor, 348 const char* outputColor,
349 const char* inputColor, 349 const char* inputColor,
350 const TransformedCoordsArray&,
350 const TextureSamplerArray&) SK_OVERRIDE; 351 const TextureSamplerArray&) SK_OVERRIDE;
351 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 352 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
352 353
353 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); 354 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps);
354 355
355 protected: 356 protected:
356 357
357 UniformHandle fVSParamUni; 358 UniformHandle fVSParamUni;
358 UniformHandle fFSParamUni; 359 UniformHandle fFSParamUni;
359 360
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 482
482 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>() ; 483 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>() ;
483 fIsDegenerate = data.isDegenerate(); 484 fIsDegenerate = data.isDegenerate();
484 } 485 }
485 486
486 void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder, 487 void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
487 const GrDrawEffect&, 488 const GrDrawEffect&,
488 EffectKey key, 489 EffectKey key,
489 const char* outputColor, 490 const char* outputColor,
490 const char* inputColor, 491 const char* inputColor,
492 const TransformedCoordsArray& coords,
491 const TextureSamplerArray& samplers) { 493 const TextureSamplerArray& samplers) {
492 SkString fsCoords;
493 SkString vsCoordsVarying;
494 GrSLType coordsVaryingType;
495 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT ype);
496
497 this->emitUniforms(builder, key); 494 this->emitUniforms(builder, key);
498 // 2 copies of uniform array, 1 for each of vertex & fragment shader, 495 // 2 copies of uniform array, 1 for each of vertex & fragment shader,
499 // to work around Xoom bug. Doesn't seem to cause performance decrease 496 // to work around Xoom bug. Doesn't seem to cause performance decrease
500 // in test apps, but need to keep an eye on it. 497 // in test apps, but need to keep an eye on it.
501 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility , 498 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility ,
502 kFloat_GrSLType, "Conical2VSParams", 6); 499 kFloat_GrSLType, "Conical2VSParams", 6);
503 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibili ty, 500 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibili ty,
504 kFloat_GrSLType, "Conical2FSParams", 6); 501 kFloat_GrSLType, "Conical2FSParams", 6);
505 502
506 // For radial gradients without perspective we can pass the linear 503 // For radial gradients without perspective we can pass the linear
507 // part of the quadratic as a varying. 504 // part of the quadratic as a varying.
508 GrGLShaderBuilder::VertexBuilder* vertexBuilder = 505 GrGLShaderBuilder::VertexBuilder* vertexBuilder =
509 (kVec2f_GrSLType == coordsVaryingType) ? builder->getVertexBuilder() : N ULL; 506 (kVec2f_GrSLType == coords[0].type()) ? builder->getVertexBuilder() : NU LL;
510 if (NULL != vertexBuilder) { 507 if (NULL != vertexBuilder) {
511 vertexBuilder->addVarying(kFloat_GrSLType, "Conical2BCoeff", 508 vertexBuilder->addVarying(kFloat_GrSLType, "Conical2BCoeff",
512 &fVSVaryingName, &fFSVaryingName); 509 &fVSVaryingName, &fFSVaryingName);
513 } 510 }
514 511
515 // VS 512 // VS
516 { 513 {
517 SkString p2; // distance between centers 514 SkString p2; // distance between centers
518 SkString p3; // start radius 515 SkString p3; // start radius
519 SkString p5; // difference in radii (r1 - r0) 516 SkString p5; // difference in radii (r1 - r0)
520 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2); 517 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
521 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3); 518 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3);
522 builder->getUniformVariable(fVSParamUni).appendArrayAccess(5, &p5); 519 builder->getUniformVariable(fVSParamUni).appendArrayAccess(5, &p5);
523 520
524 // For radial gradients without perspective we can pass the linear 521 // For radial gradients without perspective we can pass the linear
525 // part of the quadratic as a varying. 522 // part of the quadratic as a varying.
526 if (NULL != vertexBuilder) { 523 if (NULL != vertexBuilder) {
527 // r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5]) 524 // r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5])
528 vertexBuilder->vsCodeAppendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n ", 525 vertexBuilder->vsCodeAppendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n ",
529 fVSVaryingName, p2.c_str(), 526 fVSVaryingName, p2.c_str(),
530 vsCoordsVarying.c_str(), p3.c_str(), p5.c_str()); 527 coords[0].getVSName().c_str(), p3.c_ str(), p5.c_str());
531 } 528 }
532 } 529 }
533 530
534 // FS 531 // FS
535 { 532 {
536 533 SkString coords2D = builder->ensureFSCoords2D(coords, 0);
537 SkString cName("c"); 534 SkString cName("c");
538 SkString ac4Name("ac4"); 535 SkString ac4Name("ac4");
539 SkString dName("d"); 536 SkString dName("d");
540 SkString qName("q"); 537 SkString qName("q");
541 SkString r0Name("r0"); 538 SkString r0Name("r0");
542 SkString r1Name("r1"); 539 SkString r1Name("r1");
543 SkString tName("t"); 540 SkString tName("t");
544 SkString p0; // 4a 541 SkString p0; // 4a
545 SkString p1; // 1/a 542 SkString p1; // 1/a
546 SkString p2; // distance between centers 543 SkString p2; // distance between centers
547 SkString p3; // start radius 544 SkString p3; // start radius
548 SkString p4; // start radius squared 545 SkString p4; // start radius squared
549 SkString p5; // difference in radii (r1 - r0) 546 SkString p5; // difference in radii (r1 - r0)
550 547
551 builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0); 548 builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0);
552 builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1); 549 builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1);
553 builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2); 550 builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2);
554 builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3); 551 builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3);
555 builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4); 552 builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4);
556 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5); 553 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5);
557 554
558 // If we we're able to interpolate the linear component, 555 // If we we're able to interpolate the linear component,
559 // bVar is the varying; otherwise compute it 556 // bVar is the varying; otherwise compute it
560 SkString bVar; 557 SkString bVar;
561 if (NULL != vertexBuilder) { 558 if (NULL != vertexBuilder) {
562 bVar = fFSVaryingName; 559 bVar = fFSVaryingName;
563 } else { 560 } else {
564 bVar = "b"; 561 bVar = "b";
565 builder->fsCodeAppendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n ", 562 builder->fsCodeAppendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n ",
566 bVar.c_str(), p2.c_str(), fsCoords.c_str(), 563 bVar.c_str(), p2.c_str(), coords2D.c_str(),
567 p3.c_str(), p5.c_str()); 564 p3.c_str(), p5.c_str());
568 } 565 }
569 566
570 // output will default to transparent black (we simply won't write anyth ing 567 // output will default to transparent black (we simply won't write anyth ing
571 // else to it if invalid, instead of discarding or returning prematurely ) 568 // else to it if invalid, instead of discarding or returning prematurely )
572 builder->fsCodeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); 569 builder->fsCodeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor);
573 570
574 // c = (x^2)+(y^2) - params[4] 571 // c = (x^2)+(y^2) - params[4]
575 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str() , 572 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str() ,
576 fsCoords.c_str(), fsCoords.c_str(), 573 coords2D.c_str(), coords2D.c_str(),
577 p4.c_str()); 574 p4.c_str());
578 575
579 // Non-degenerate case (quadratic) 576 // Non-degenerate case (quadratic)
580 if (!fIsDegenerate) { 577 if (!fIsDegenerate) {
581 578
582 // ac4 = params[0] * c 579 // ac4 = params[0] * c
583 builder->fsCodeAppendf("\tfloat %s = %s * %s;\n", ac4Name.c_str(), p 0.c_str(), 580 builder->fsCodeAppendf("\tfloat %s = %s * %s;\n", ac4Name.c_str(), p 0.c_str(),
584 cName.c_str()); 581 cName.c_str());
585 582
586 // d = b^2 - ac4 583 // d = b^2 - ac4
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 str->appendScalar(fCenter2.fY); 751 str->appendScalar(fCenter2.fY);
755 str->append(") radius2: "); 752 str->append(") radius2: ");
756 str->appendScalar(fRadius2); 753 str->appendScalar(fRadius2);
757 str->append(" "); 754 str->append(" ");
758 755
759 this->INHERITED::toString(str); 756 this->INHERITED::toString(str);
760 757
761 str->append(")"); 758 str->append(")");
762 } 759 }
763 #endif 760 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkSweepGradient.cpp ('k') | src/effects/gradients/SkTwoPointRadialGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698