OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 | 9 |
10 #include "SkClampRange.h" | 10 #include "SkClampRange.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } else { | 43 } else { |
44 fCount2 = 1; | 44 fCount2 = 1; |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 void SkClampRange::init(SkFixed fx0, SkFixed dx0, int count, int v0, int v1) { | 48 void SkClampRange::init(SkFixed fx0, SkFixed dx0, int count, int v0, int v1) { |
49 SkASSERT(count > 0); | 49 SkASSERT(count > 0); |
50 | 50 |
51 fV0 = v0; | 51 fV0 = v0; |
52 fV1 = v1; | 52 fV1 = v1; |
53 fOverflowed = false; | |
54 | 53 |
55 // special case 1 == count, as it is slightly common for skia | 54 // special case 1 == count, as it is slightly common for skia |
56 // and avoids us ever calling divide or 64bit multiply | 55 // and avoids us ever calling divide or 64bit multiply |
57 if (1 == count) { | 56 if (1 == count) { |
58 this->initFor1(fx0); | 57 this->initFor1(fx0); |
59 return; | 58 return; |
60 } | 59 } |
61 | 60 |
62 int64_t fx = fx0; | 61 int64_t fx = fx0; |
63 int64_t dx = dx0; | 62 int64_t dx = dx0; |
64 // start with ex equal to the last computed value | 63 // start with ex equal to the last computed value |
65 int64_t ex = fx + (count - 1) * dx; | 64 int64_t ex = fx + (count - 1) * dx; |
66 fOverflowed = overflows_fixed(ex); | |
67 | 65 |
68 if ((uint64_t)(fx | ex) <= 0xFFFF) { | 66 if ((uint64_t)(fx | ex) <= 0xFFFF) { |
69 fCount0 = fCount2 = 0; | 67 fCount0 = fCount2 = 0; |
70 fCount1 = count; | 68 fCount1 = count; |
71 fFx1 = fx0; | 69 fFx1 = fx0; |
72 return; | 70 return; |
73 } | 71 } |
74 if (fx <= 0 && ex <= 0) { | 72 if (fx <= 0 && ex <= 0) { |
75 fCount1 = fCount2 = 0; | 73 fCount1 = fCount2 = 0; |
76 fCount0 = count; | 74 fCount0 = count; |
77 return; | 75 return; |
78 } | 76 } |
79 if (fx >= 0xFFFF && ex >= 0xFFFF) { | 77 if (fx >= 0xFFFF && ex >= 0xFFFF) { |
80 fCount0 = fCount1 = 0; | 78 fCount0 = fCount1 = 0; |
81 fCount2 = count; | 79 fCount2 = count; |
82 return; | 80 return; |
83 } | 81 } |
84 | 82 |
85 int extraCount = 0; | 83 int extraCount = 0; |
86 | 84 |
87 // now make ex be 1 past the last computed value | 85 // now make ex be 1 past the last computed value |
88 ex += dx; | 86 ex += dx; |
89 fOverflowed = overflows_fixed(ex); | |
90 // now check for over/under flow | 87 // now check for over/under flow |
91 if (fOverflowed) { | 88 if (overflows_fixed(ex)) { |
92 int originalCount = count; | 89 int originalCount = count; |
93 int64_t ccount; | 90 int64_t ccount; |
94 bool swap = dx < 0; | 91 bool swap = dx < 0; |
95 if (swap) { | 92 if (swap) { |
96 dx = -dx; | 93 dx = -dx; |
97 fx = -fx; | 94 fx = -fx; |
98 } | 95 } |
99 ccount = (SK_FixedMax - fx + dx - 1) / dx; | 96 ccount = (SK_FixedMax - fx + dx - 1) / dx; |
100 if (swap) { | 97 if (swap) { |
101 dx = -dx; | 98 dx = -dx; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if (fCount1 > 0) { | 153 if (fCount1 > 0) { |
157 fFx1 = fx0 + fCount0 * (int)dx; | 154 fFx1 = fx0 + fCount0 * (int)dx; |
158 } | 155 } |
159 | 156 |
160 if (dx > 0) { | 157 if (dx > 0) { |
161 fCount2 += extraCount; | 158 fCount2 += extraCount; |
162 } else { | 159 } else { |
163 fCount0 += extraCount; | 160 fCount0 += extraCount; |
164 } | 161 } |
165 } | 162 } |
OLD | NEW |