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

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: added macros to check for gpu support 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
« no previous file with comments | « src/effects/gradients/SkTwoPointRadialGradient.h ('k') | src/gpu/SkGpuDevice.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 "SkTwoPointRadialGradient.h" 9 #include "SkTwoPointRadialGradient.h"
10 10
11 /* Two-point radial gradients are specified by two circles, each with a center 11 /* Two-point radial gradients are specified by two circles, each with a center
12 point and radius. The gradient can be considered to be a series of 12 point and radius. The gradient can be considered to be a series of
13 concentric circles, with the color interpolated from the start circle 13 concentric circles, with the color interpolated from the start circle
14 (at t=0) to the end circle (at t=1). 14 (at t=0) to the end circle (at t=1).
15 15
16 For each point (x, y) in the span, we want to find the 16 For each point (x, y) in the span, we want to find the
17 interpolated circle that intersects that point. The center 17 interpolated circle that intersects that point. The center
18 of the desired circle (Cx, Cy) falls at some distance t 18 of the desired circle (Cx, Cy) falls at some distance t
19 along the line segment between the start point (Sx, Sy) and 19 along the line segment between the start point (Sx, Sy) and
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 376
377 fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY); 377 fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY);
378 fPtsToUnit.postScale(inv, inv); 378 fPtsToUnit.postScale(inv, inv);
379 } 379 }
380 380
381 ///////////////////////////////////////////////////////////////////// 381 /////////////////////////////////////////////////////////////////////
382 382
383 #if SK_SUPPORT_GPU 383 #if SK_SUPPORT_GPU
384 384
385 #include "GrTBackendEffectFactory.h" 385 #include "GrTBackendEffectFactory.h"
386 #include "SkGr.h"
386 387
387 // For brevity 388 // For brevity
388 typedef GrGLUniformManager::UniformHandle UniformHandle; 389 typedef GrGLUniformManager::UniformHandle UniformHandle;
389 390
390 class GrGLRadial2Gradient : public GrGLGradientEffect { 391 class GrGLRadial2Gradient : public GrGLGradientEffect {
391 392
392 public: 393 public:
393 394
394 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec t&); 395 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec t&);
395 virtual ~GrGLRadial2Gradient() { } 396 virtual ~GrGLRadial2Gradient() { }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 SkColor colors[kMaxRandomGradientColors]; 524 SkColor colors[kMaxRandomGradientColors];
524 SkScalar stopsArray[kMaxRandomGradientColors]; 525 SkScalar stopsArray[kMaxRandomGradientColors];
525 SkScalar* stops = stopsArray; 526 SkScalar* stops = stopsArray;
526 SkShader::TileMode tm; 527 SkShader::TileMode tm;
527 int colorCount = RandomGradientParams(random, colors, &stops, &tm); 528 int colorCount = RandomGradientParams(random, colors, &stops, &tm);
528 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointRadial(center1 , radius1, 529 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointRadial(center1 , radius1,
529 center2 , radius2, 530 center2 , radius2,
530 colors, stops, colorCount, 531 colors, stops, colorCount,
531 tm)); 532 tm));
532 SkPaint paint; 533 SkPaint paint;
533 return shader->asNewEffect(context, paint, NULL); 534 GrEffectRef* effect;
535 GrColor grColor;
536 shader->asNewEffect(context, paint, NULL, &grColor, &effect);
537 return effect;
534 } 538 }
535 539
536 ///////////////////////////////////////////////////////////////////// 540 /////////////////////////////////////////////////////////////////////
537 541
538 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, 542 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory,
539 const GrDrawEffect& drawEffect) 543 const GrDrawEffect& drawEffect)
540 : INHERITED(factory) 544 : INHERITED(factory)
541 , fVSVaryingName(NULL) 545 , fVSVaryingName(NULL)
542 , fFSVaryingName(NULL) 546 , fFSVaryingName(NULL)
543 , fCachedCenter(SK_ScalarMax) 547 , fCachedCenter(SK_ScalarMax)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 667
664 EffectKey key = GenBaseGradientKey(drawEffect); 668 EffectKey key = GenBaseGradientKey(drawEffect);
665 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) { 669 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) {
666 key |= kIsDegenerate; 670 key |= kIsDegenerate;
667 } 671 }
668 return key; 672 return key;
669 } 673 }
670 674
671 ///////////////////////////////////////////////////////////////////// 675 /////////////////////////////////////////////////////////////////////
672 676
673 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkP aint&, 677 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa int,
674 const SkMatrix* localMatrix) const { 678 const SkMatrix* localMatrix, GrColor* grColor,
679 GrEffectRef** grEffect) const {
675 SkASSERT(NULL != context); 680 SkASSERT(NULL != context);
681
676 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis. 682 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis.
677 SkMatrix matrix; 683 SkMatrix matrix;
678 if (!this->getLocalMatrix().invert(&matrix)) { 684 if (!this->getLocalMatrix().invert(&matrix)) {
679 return NULL; 685 return false;
680 } 686 }
681 if (localMatrix) { 687 if (localMatrix) {
682 SkMatrix inv; 688 SkMatrix inv;
683 if (!localMatrix->invert(&inv)) { 689 if (!localMatrix->invert(&inv)) {
684 return NULL; 690 return false;
685 } 691 }
686 matrix.postConcat(inv); 692 matrix.postConcat(inv);
687 } 693 }
688 matrix.postConcat(fPtsToUnit); 694 matrix.postConcat(fPtsToUnit);
689 695
690 SkScalar diffLen = fDiff.length(); 696 SkScalar diffLen = fDiff.length();
691 if (0 != diffLen) { 697 if (0 != diffLen) {
692 SkScalar invDiffLen = SkScalarInvert(diffLen); 698 SkScalar invDiffLen = SkScalarInvert(diffLen);
693 SkMatrix rot; 699 SkMatrix rot;
694 rot.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY), 700 rot.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY),
695 SkScalarMul(invDiffLen, fDiff.fX)); 701 SkScalarMul(invDiffLen, fDiff.fX));
696 matrix.postConcat(rot); 702 matrix.postConcat(rot);
697 } 703 }
698 704
699 return GrRadial2Gradient::Create(context, *this, matrix, fTileMode); 705 *grColor = SkColor2GrColorJustAlpha(paint.getColor());
706 *grEffect = GrRadial2Gradient::Create(context, *this, matrix, fTileMode);
707
708 return true;
700 } 709 }
701 710
702 #else 711 #else
703 712
704 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&, 713 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa int,
705 const SkMatrix*) const { 714 const SkMatrix* localMatrix, GrColor* grColor,
715 GrEffectRef** grEffect) const {
706 SkDEBUGFAIL("Should not call in GPU-less build"); 716 SkDEBUGFAIL("Should not call in GPU-less build");
707 return NULL; 717 return false;
708 } 718 }
709 719
710 #endif 720 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkTwoPointRadialGradient.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698