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

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

Issue 1506913002: Pin result in SkATan2_255 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Take 2 Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | 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 "SkSweepGradient.h" 9 #include "SkSweepGradient.h"
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 SkSweepGradient::SweepGradientContext::SweepGradientContext( 56 SkSweepGradient::SweepGradientContext::SweepGradientContext(
57 const SkSweepGradient& shader, const ContextRec& rec) 57 const SkSweepGradient& shader, const ContextRec& rec)
58 : INHERITED(shader, rec) {} 58 : INHERITED(shader, rec) {}
59 59
60 // returns angle in a circle [0..2PI) -> [0..255] 60 // returns angle in a circle [0..2PI) -> [0..255]
61 static unsigned SkATan2_255(float y, float x) { 61 static unsigned SkATan2_255(float y, float x) {
62 // static const float g255Over2PI = 255 / (2 * SK_ScalarPI); 62 // static const float g255Over2PI = 255 / (2 * SK_ScalarPI);
63 static const float g255Over2PI = 40.584510488433314f; 63 static const float g255Over2PI = 40.584510488433314f;
64 64
65 float result = sk_float_atan2(y, x); 65 float result = sk_float_atan2(y, x);
66 if (!SkScalarIsFinite(result)) {
67 return 0;
68 }
66 if (result < 0) { 69 if (result < 0) {
67 result += 2 * SK_ScalarPI; 70 result += 2 * SK_ScalarPI;
68 } 71 }
69 SkASSERT(result >= 0); 72 SkASSERT(result >= 0);
70 // since our value is always >= 0, we can cast to int, which is faster than 73 // since our value is always >= 0, we can cast to int, which is faster than
71 // calling floorf() 74 // calling floorf()
72 int ir = (int)(result * g255Over2PI); 75 int ir = (int)(result * g255Over2PI);
73 SkASSERT(ir >= 0 && ir <= 255); 76 SkASSERT(ir >= 0 && ir <= 255);
74 return ir; 77 return ir;
75 } 78 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 str->appendScalar(fCenter.fX); 309 str->appendScalar(fCenter.fX);
307 str->append(", "); 310 str->append(", ");
308 str->appendScalar(fCenter.fY); 311 str->appendScalar(fCenter.fY);
309 str->append(") "); 312 str->append(") ");
310 313
311 this->INHERITED::toString(str); 314 this->INHERITED::toString(str);
312 315
313 str->append(")"); 316 str->append(")");
314 } 317 }
315 #endif 318 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698