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

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

Issue 374923002: Goodbye GrEffectRef. (Closed) Base URL: https://skia.googlesource.com/skia.git@noref3
Patch Set: Address comments Created 6 years, 5 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
« no previous file with comments | « src/effects/gradients/SkLinearGradient.cpp ('k') | src/effects/gradients/SkSweepGradient.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 /* 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 "SkRadialGradient.h" 9 #include "SkRadialGradient.h"
10 #include "SkRadialGradient_Table.h" 10 #include "SkRadialGradient_Table.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 private: 482 private:
483 483
484 typedef GrGLGradientEffect INHERITED; 484 typedef GrGLGradientEffect INHERITED;
485 485
486 }; 486 };
487 487
488 ///////////////////////////////////////////////////////////////////// 488 /////////////////////////////////////////////////////////////////////
489 489
490 class GrRadialGradient : public GrGradientEffect { 490 class GrRadialGradient : public GrGradientEffect {
491 public: 491 public:
492 static GrEffectRef* Create(GrContext* ctx, 492 static GrEffect* Create(GrContext* ctx,
493 const SkRadialGradient& shader, 493 const SkRadialGradient& shader,
494 const SkMatrix& matrix, 494 const SkMatrix& matrix,
495 SkShader::TileMode tm) { 495 SkShader::TileMode tm) {
496 return SkNEW_ARGS(GrRadialGradient, (ctx, shader, matrix, tm)); 496 return SkNEW_ARGS(GrRadialGradient, (ctx, shader, matrix, tm));
497 } 497 }
498 498
499 virtual ~GrRadialGradient() { } 499 virtual ~GrRadialGradient() { }
500 500
501 static const char* Name() { return "Radial Gradient"; } 501 static const char* Name() { return "Radial Gradient"; }
502 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 502 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
503 return GrTBackendEffectFactory<GrRadialGradient>::getInstance(); 503 return GrTBackendEffectFactory<GrRadialGradient>::getInstance();
504 } 504 }
505 505
506 typedef GrGLRadialGradient GLEffect; 506 typedef GrGLRadialGradient GLEffect;
507 507
508 private: 508 private:
509 GrRadialGradient(GrContext* ctx, 509 GrRadialGradient(GrContext* ctx,
510 const SkRadialGradient& shader, 510 const SkRadialGradient& shader,
511 const SkMatrix& matrix, 511 const SkMatrix& matrix,
512 SkShader::TileMode tm) 512 SkShader::TileMode tm)
513 : INHERITED(ctx, shader, matrix, tm) { 513 : INHERITED(ctx, shader, matrix, tm) {
514 } 514 }
515 515
516 GR_DECLARE_EFFECT_TEST; 516 GR_DECLARE_EFFECT_TEST;
517 517
518 typedef GrGradientEffect INHERITED; 518 typedef GrGradientEffect INHERITED;
519 }; 519 };
520 520
521 ///////////////////////////////////////////////////////////////////// 521 /////////////////////////////////////////////////////////////////////
522 522
523 GR_DEFINE_EFFECT_TEST(GrRadialGradient); 523 GR_DEFINE_EFFECT_TEST(GrRadialGradient);
524 524
525 GrEffectRef* GrRadialGradient::TestCreate(SkRandom* random, 525 GrEffect* GrRadialGradient::TestCreate(SkRandom* random,
526 GrContext* context, 526 GrContext* context,
527 const GrDrawTargetCaps&, 527 const GrDrawTargetCaps&,
528 GrTexture**) { 528 GrTexture**) {
529 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; 529 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()};
530 SkScalar radius = random->nextUScalar1(); 530 SkScalar radius = random->nextUScalar1();
531 531
532 SkColor colors[kMaxRandomGradientColors]; 532 SkColor colors[kMaxRandomGradientColors];
533 SkScalar stopsArray[kMaxRandomGradientColors]; 533 SkScalar stopsArray[kMaxRandomGradientColors];
534 SkScalar* stops = stopsArray; 534 SkScalar* stops = stopsArray;
535 SkShader::TileMode tm; 535 SkShader::TileMode tm;
536 int colorCount = RandomGradientParams(random, colors, &stops, &tm); 536 int colorCount = RandomGradientParams(random, colors, &stops, &tm);
537 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, 537 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius,
538 colors, stops, colorCount, 538 colors, stops, colorCount,
539 tm)); 539 tm));
540 SkPaint paint; 540 SkPaint paint;
541 GrColor grColor; 541 GrColor paintColor;
542 GrEffectRef* effect; 542 GrEffect* effect;
543 shader->asNewEffect(context, paint, NULL, &grColor, &effect); 543 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec t));
544 return effect; 544 return effect;
545 } 545 }
546 546
547 ///////////////////////////////////////////////////////////////////// 547 /////////////////////////////////////////////////////////////////////
548 548
549 void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder, 549 void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
550 const GrDrawEffect&, 550 const GrDrawEffect&,
551 EffectKey key, 551 EffectKey key,
552 const char* outputColor, 552 const char* outputColor,
553 const char* inputColor, 553 const char* inputColor,
554 const TransformedCoordsArray& coords, 554 const TransformedCoordsArray& coords,
555 const TextureSamplerArray& samplers) { 555 const TextureSamplerArray& samplers) {
556 this->emitUniforms(builder, key); 556 this->emitUniforms(builder, key);
557 SkString t("length("); 557 SkString t("length(");
558 t.append(builder->ensureFSCoords2D(coords, 0)); 558 t.append(builder->ensureFSCoords2D(coords, 0));
559 t.append(")"); 559 t.append(")");
560 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); 560 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers);
561 } 561 }
562 562
563 ///////////////////////////////////////////////////////////////////// 563 /////////////////////////////////////////////////////////////////////
564 564
565 bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint, 565 bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint,
566 const SkMatrix* localMatrix, GrColor* grColor , 566 const SkMatrix* localMatrix, GrColor* paintCo lor,
567 GrEffectRef** grEffect) const { 567 GrEffect** effect) const {
568 SkASSERT(NULL != context); 568 SkASSERT(NULL != context);
569 569
570 SkMatrix matrix; 570 SkMatrix matrix;
571 if (!this->getLocalMatrix().invert(&matrix)) { 571 if (!this->getLocalMatrix().invert(&matrix)) {
572 return false; 572 return false;
573 } 573 }
574 if (localMatrix) { 574 if (localMatrix) {
575 SkMatrix inv; 575 SkMatrix inv;
576 if (!localMatrix->invert(&inv)) { 576 if (!localMatrix->invert(&inv)) {
577 return false; 577 return false;
578 } 578 }
579 matrix.postConcat(inv); 579 matrix.postConcat(inv);
580 } 580 }
581 matrix.postConcat(fPtsToUnit); 581 matrix.postConcat(fPtsToUnit);
582 582
583 *grColor = SkColor2GrColorJustAlpha(paint.getColor()); 583 *paintColor = SkColor2GrColorJustAlpha(paint.getColor());
584 *grEffect = GrRadialGradient::Create(context, *this, matrix, fTileMode); 584 *effect = GrRadialGradient::Create(context, *this, matrix, fTileMode);
585 585
586 return true; 586 return true;
587 } 587 }
588 588
589 #else 589 #else
590 590
591 bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint, 591 bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint,
592 const SkMatrix* localMatrix, GrColor* grColor , 592 const SkMatrix* localMatrix, GrColor* paintCo lor,
593 GrEffect** grEffect) const { 593 GrEffect** effect) const {
594 SkDEBUGFAIL("Should not call in GPU-less build"); 594 SkDEBUGFAIL("Should not call in GPU-less build");
595 return false; 595 return false;
596 } 596 }
597 597
598 #endif 598 #endif
599 599
600 #ifndef SK_IGNORE_TO_STRING 600 #ifndef SK_IGNORE_TO_STRING
601 void SkRadialGradient::toString(SkString* str) const { 601 void SkRadialGradient::toString(SkString* str) const {
602 str->append("SkRadialGradient: ("); 602 str->append("SkRadialGradient: (");
603 603
604 str->append("center: ("); 604 str->append("center: (");
605 str->appendScalar(fCenter.fX); 605 str->appendScalar(fCenter.fX);
606 str->append(", "); 606 str->append(", ");
607 str->appendScalar(fCenter.fY); 607 str->appendScalar(fCenter.fY);
608 str->append(") radius: "); 608 str->append(") radius: ");
609 str->appendScalar(fRadius); 609 str->appendScalar(fRadius);
610 str->append(" "); 610 str->append(" ");
611 611
612 this->INHERITED::toString(str); 612 this->INHERITED::toString(str);
613 613
614 str->append(")"); 614 str->append(")");
615 } 615 }
616 #endif 616 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkLinearGradient.cpp ('k') | src/effects/gradients/SkSweepGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698