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

Unified Diff: src/effects/gradients/SkTwoPointRadialGradient.cpp

Issue 793763003: Gradient shaders: make fPtsToUnit const, pre-cache getType(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/gradients/SkTwoPointRadialGradient.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkTwoPointRadialGradient.cpp
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 4fb2996226f145efb638087232f105f7604e1469..3a3921d14ccc0459fc6b5ef57c67ab3ec8e2b679 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -167,16 +167,33 @@ void shadeSpan_twopoint_repeat(SkScalar fx, SkScalar dx,
/////////////////////////////////////////////////////////////////////
+static SkMatrix pts_to_unit(const SkPoint& start, SkScalar diffRadius) {
+ SkScalar inv = diffRadius ? SkScalarInvert(diffRadius) : 0;
+ SkMatrix matrix;
+ matrix.setTranslate(-start.fX, -start.fY);
+ matrix.postScale(inv, inv);
+ return matrix;
+}
+
SkTwoPointRadialGradient::SkTwoPointRadialGradient(const SkPoint& start, SkScalar startRadius,
const SkPoint& end, SkScalar endRadius,
const Descriptor& desc)
- : SkGradientShaderBase(desc)
+ : SkGradientShaderBase(desc, pts_to_unit(start, endRadius - startRadius))
, fCenter1(start)
, fCenter2(end)
, fRadius1(startRadius)
, fRadius2(endRadius)
{
- init();
+ fDiff = fCenter1 - fCenter2;
+ fDiffRadius = fRadius2 - fRadius1;
+ // hack to avoid zero-divide for now
+ SkScalar inv = fDiffRadius ? SkScalarInvert(fDiffRadius) : 0;
+ fDiff.fX = SkScalarMul(fDiff.fX, inv);
+ fDiff.fY = SkScalarMul(fDiff.fY, inv);
+ fStartRadius = SkScalarMul(fRadius1, inv);
+ fSr2D2 = SkScalarSquare(fStartRadius);
+ fA = SkScalarSquare(fDiff.fX) + SkScalarSquare(fDiff.fY) - SK_Scalar1;
+ fOneOverTwoA = fA ? SkScalarInvert(fA * 2) : 0;
}
SkShader::BitmapType SkTwoPointRadialGradient::asABitmap(
@@ -366,22 +383,6 @@ void SkTwoPointRadialGradient::flatten(
buffer.writeScalar(fRadius2);
}
-void SkTwoPointRadialGradient::init() {
- fDiff = fCenter1 - fCenter2;
- fDiffRadius = fRadius2 - fRadius1;
- // hack to avoid zero-divide for now
- SkScalar inv = fDiffRadius ? SkScalarInvert(fDiffRadius) : 0;
- fDiff.fX = SkScalarMul(fDiff.fX, inv);
- fDiff.fY = SkScalarMul(fDiff.fY, inv);
- fStartRadius = SkScalarMul(fRadius1, inv);
- fSr2D2 = SkScalarSquare(fStartRadius);
- fA = SkScalarSquare(fDiff.fX) + SkScalarSquare(fDiff.fY) - SK_Scalar1;
- fOneOverTwoA = fA ? SkScalarInvert(fA * 2) : 0;
-
- fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY);
- fPtsToUnit.postScale(inv, inv);
-}
-
/////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
« no previous file with comments | « src/effects/gradients/SkTwoPointRadialGradient.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698