OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |