aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-04-13 12:15:50 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-13 16:48:59 +0000
commit0d63e4e4a8e3df7a9e0ae5d46967513201ef731d (patch)
treeb029a01e8a889670ffcb2458b434c990c294111e /src/effects
parentf71b33846a1529776f59964dd8b0b599009f7712 (diff)
Use a simpler method for calculating atan
Change-Id: I675851350c02c85f3f212c214766b3e8a6761dc9 Reviewed-on: https://skia-review.googlesource.com/13402 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index 79013b3322..06b9f210da 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -7,6 +7,8 @@
#include "SkSweepGradient.h"
+#include <algorithm>
+
static SkMatrix translate(SkScalar dx, SkScalar dy) {
SkMatrix matrix;
matrix.setTranslate(dx, dy);
@@ -56,6 +58,7 @@ SkSweepGradient::SweepGradientContext::SweepGradientContext(
: INHERITED(shader, rec) {}
// returns angle in a circle [0..2PI) -> [0..255]
+#ifdef SK_LEGACY_SWEEP_GRADIENT
static unsigned SkATan2_255(float y, float x) {
// static const float g255Over2PI = 255 / (2 * SK_ScalarPI);
static const float g255Over2PI = 40.584510488433314f;
@@ -74,6 +77,26 @@ static unsigned SkATan2_255(float y, float x) {
SkASSERT(ir >= 0 && ir <= 255);
return ir;
}
+#else
+static unsigned SkATan2_255(float y, float x) {
+ if (y == 0 && x == 0) return 0;
+ float yabs = sk_float_abs(y),
+ xabs = sk_float_abs(x);
+ float little, big;
+ std::tie(little, big) = std::minmax(yabs, xabs);
+ float a = little/big;
+ float s = a * a;
+ float r = a*(40.57589784014689f
+ + s*(-13.222755844396332f + s*(6.314046289038564f - s*1.7989502668982151f)));
+ r = xabs < yabs ? 255/4.0f - r : r;
+ r = x < 0.0f ? 255/2.0f - r : r;
+ r = y < 0.0f ? 255 - r : r;
+
+ int ir = (int)r;
+ SkASSERT(ir >= 0 && ir <= 255);
+ return ir;
+}
+#endif
void SkSweepGradient::SweepGradientContext::shadeSpan(int x, int y, SkPMColor* SK_RESTRICT dstC,
int count) {