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

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

Issue 318923005: SkShader::asNewEffect Refactoring (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkColorShader refactor and fix Created 6 years, 6 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
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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 SkColor colors[kMaxRandomGradientColors]; 523 SkColor colors[kMaxRandomGradientColors];
524 SkScalar stopsArray[kMaxRandomGradientColors]; 524 SkScalar stopsArray[kMaxRandomGradientColors];
525 SkScalar* stops = stopsArray; 525 SkScalar* stops = stopsArray;
526 SkShader::TileMode tm; 526 SkShader::TileMode tm;
527 int colorCount = RandomGradientParams(random, colors, &stops, &tm); 527 int colorCount = RandomGradientParams(random, colors, &stops, &tm);
528 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointRadial(center1 , radius1, 528 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointRadial(center1 , radius1,
529 center2 , radius2, 529 center2 , radius2,
530 colors, stops, colorCount, 530 colors, stops, colorCount,
531 tm)); 531 tm));
532 SkPaint paint; 532 SkPaint paint;
533 return shader->asNewEffect(context, paint, NULL); 533 GrEffectRef* effect;
534 GrColor grColor;
535 shader->asNewEffect(context, paint, NULL, &grColor, &effect);
536 return effect;
534 } 537 }
535 538
536 ///////////////////////////////////////////////////////////////////// 539 /////////////////////////////////////////////////////////////////////
537 540
538 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, 541 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory,
539 const GrDrawEffect& drawEffect) 542 const GrDrawEffect& drawEffect)
540 : INHERITED(factory) 543 : INHERITED(factory)
541 , fVSVaryingName(NULL) 544 , fVSVaryingName(NULL)
542 , fFSVaryingName(NULL) 545 , fFSVaryingName(NULL)
543 , fCachedCenter(SK_ScalarMax) 546 , fCachedCenter(SK_ScalarMax)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 666
664 EffectKey key = GenBaseGradientKey(drawEffect); 667 EffectKey key = GenBaseGradientKey(drawEffect);
665 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) { 668 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) {
666 key |= kIsDegenerate; 669 key |= kIsDegenerate;
667 } 670 }
668 return key; 671 return key;
669 } 672 }
670 673
671 ///////////////////////////////////////////////////////////////////// 674 /////////////////////////////////////////////////////////////////////
672 675
673 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkP aint&, 676 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa int,
674 const SkMatrix* localMatrix) const { 677 const SkMatrix* localMatrix, GrColor* grColor,
678 GrEffectRef** grEffect) const {
675 SkASSERT(NULL != context); 679 SkASSERT(NULL != context);
680
681 *grColor = this->getColorAsAlpha(paint);
682
676 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis. 683 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis.
677 SkMatrix matrix; 684 SkMatrix matrix;
678 if (!this->getLocalMatrix().invert(&matrix)) { 685 if (!this->getLocalMatrix().invert(&matrix)) {
679 return NULL; 686 return false;
680 } 687 }
681 if (localMatrix) { 688 if (localMatrix) {
682 SkMatrix inv; 689 SkMatrix inv;
683 if (!localMatrix->invert(&inv)) { 690 if (!localMatrix->invert(&inv)) {
684 return NULL; 691 return false;
685 } 692 }
686 matrix.postConcat(inv); 693 matrix.postConcat(inv);
687 } 694 }
688 matrix.postConcat(fPtsToUnit); 695 matrix.postConcat(fPtsToUnit);
689 696
690 SkScalar diffLen = fDiff.length(); 697 SkScalar diffLen = fDiff.length();
691 if (0 != diffLen) { 698 if (0 != diffLen) {
692 SkScalar invDiffLen = SkScalarInvert(diffLen); 699 SkScalar invDiffLen = SkScalarInvert(diffLen);
693 SkMatrix rot; 700 SkMatrix rot;
694 rot.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY), 701 rot.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY),
695 SkScalarMul(invDiffLen, fDiff.fX)); 702 SkScalarMul(invDiffLen, fDiff.fX));
696 matrix.postConcat(rot); 703 matrix.postConcat(rot);
697 } 704 }
698 705
699 return GrRadial2Gradient::Create(context, *this, matrix, fTileMode); 706 *grEffect = GrRadial2Gradient::Create(context, *this, matrix, fTileMode);
707 return NULL != *grEffect;
700 } 708 }
701 709
702 #else 710 #else
703 711
704 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&, 712 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa int,
705 const SkMatrix*) const { 713 const SkMatrix* localMatrix, GrColor* grColor,
714 GrEffectRef** grEffect) const {
706 SkDEBUGFAIL("Should not call in GPU-less build"); 715 SkDEBUGFAIL("Should not call in GPU-less build");
707 return NULL; 716 return false;
708 } 717 }
709 718
710 #endif 719 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698