OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
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 "SkInterpolator.h" | 10 #include "SkInterpolator.h" |
11 #include "SkMath.h" | 11 #include "SkMath.h" |
12 #include "SkTSearch.h" | 12 #include "SkTSearch.h" |
13 | 13 |
14 SkInterpolatorBase::SkInterpolatorBase() { | 14 SkInterpolatorBase::SkInterpolatorBase() { |
15 fStorage = NULL; | 15 fStorage = nullptr; |
16 fTimes = NULL; | 16 fTimes = nullptr; |
17 SkDEBUGCODE(fTimesArray = NULL;) | 17 SkDEBUGCODE(fTimesArray = nullptr;) |
18 } | 18 } |
19 | 19 |
20 SkInterpolatorBase::~SkInterpolatorBase() { | 20 SkInterpolatorBase::~SkInterpolatorBase() { |
21 if (fStorage) { | 21 if (fStorage) { |
22 sk_free(fStorage); | 22 sk_free(fStorage); |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 void SkInterpolatorBase::reset(int elemCount, int frameCount) { | 26 void SkInterpolatorBase::reset(int elemCount, int frameCount) { |
27 fFlags = 0; | 27 fFlags = 0; |
28 fElemCount = SkToU8(elemCount); | 28 fElemCount = SkToU8(elemCount); |
29 fFrameCount = SkToS16(frameCount); | 29 fFrameCount = SkToS16(frameCount); |
30 fRepeat = SK_Scalar1; | 30 fRepeat = SK_Scalar1; |
31 if (fStorage) { | 31 if (fStorage) { |
32 sk_free(fStorage); | 32 sk_free(fStorage); |
33 fStorage = NULL; | 33 fStorage = nullptr; |
34 fTimes = NULL; | 34 fTimes = nullptr; |
35 SkDEBUGCODE(fTimesArray = NULL); | 35 SkDEBUGCODE(fTimesArray = nullptr); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 /* Each value[] run is formated as: | 39 /* Each value[] run is formated as: |
40 <time (in msec)> | 40 <time (in msec)> |
41 <blend> | 41 <blend> |
42 <data[fElemCount]> | 42 <data[fElemCount]> |
43 | 43 |
44 Totaling fElemCount+2 entries per keyframe | 44 Totaling fElemCount+2 entries per keyframe |
45 */ | 45 */ |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 *T = ComputeRelativeT(time, prevT, nextT, nextTime[-1].fBlend); | 122 *T = ComputeRelativeT(time, prevT, nextT, nextTime[-1].fBlend); |
123 } | 123 } |
124 *indexPtr = index; | 124 *indexPtr = index; |
125 *exactPtr = exact; | 125 *exactPtr = exact; |
126 return result; | 126 return result; |
127 } | 127 } |
128 | 128 |
129 | 129 |
130 SkInterpolator::SkInterpolator() { | 130 SkInterpolator::SkInterpolator() { |
131 INHERITED::reset(0, 0); | 131 INHERITED::reset(0, 0); |
132 fValues = NULL; | 132 fValues = nullptr; |
133 SkDEBUGCODE(fScalarsArray = NULL;) | 133 SkDEBUGCODE(fScalarsArray = nullptr;) |
134 } | 134 } |
135 | 135 |
136 SkInterpolator::SkInterpolator(int elemCount, int frameCount) { | 136 SkInterpolator::SkInterpolator(int elemCount, int frameCount) { |
137 SkASSERT(elemCount > 0); | 137 SkASSERT(elemCount > 0); |
138 this->reset(elemCount, frameCount); | 138 this->reset(elemCount, frameCount); |
139 } | 139 } |
140 | 140 |
141 void SkInterpolator::reset(int elemCount, int frameCount) { | 141 void SkInterpolator::reset(int elemCount, int frameCount) { |
142 INHERITED::reset(elemCount, frameCount); | 142 INHERITED::reset(elemCount, frameCount); |
143 fStorage = sk_malloc_throw((sizeof(SkScalar) * elemCount + | 143 fStorage = sk_malloc_throw((sizeof(SkScalar) * elemCount + |
144 sizeof(SkTimeCode)) * frameCount); | 144 sizeof(SkTimeCode)) * frameCount); |
145 fTimes = (SkTimeCode*) fStorage; | 145 fTimes = (SkTimeCode*) fStorage; |
146 fValues = (SkScalar*) ((char*) fStorage + sizeof(SkTimeCode) * frameCount); | 146 fValues = (SkScalar*) ((char*) fStorage + sizeof(SkTimeCode) * frameCount); |
147 #ifdef SK_DEBUG | 147 #ifdef SK_DEBUG |
148 fTimesArray = (SkTimeCode(*)[10]) fTimes; | 148 fTimesArray = (SkTimeCode(*)[10]) fTimes; |
149 fScalarsArray = (SkScalar(*)[10]) fValues; | 149 fScalarsArray = (SkScalar(*)[10]) fValues; |
150 #endif | 150 #endif |
151 } | 151 } |
152 | 152 |
153 #define SK_Fixed1Third (SK_Fixed1/3) | 153 #define SK_Fixed1Third (SK_Fixed1/3) |
154 #define SK_Fixed2Third (SK_Fixed1*2/3) | 154 #define SK_Fixed2Third (SK_Fixed1*2/3) |
155 | 155 |
156 static const SkScalar gIdentityBlend[4] = { | 156 static const SkScalar gIdentityBlend[4] = { |
157 0.33333333f, 0.33333333f, 0.66666667f, 0.66666667f | 157 0.33333333f, 0.33333333f, 0.66666667f, 0.66666667f |
158 }; | 158 }; |
159 | 159 |
160 bool SkInterpolator::setKeyFrame(int index, SkMSec time, | 160 bool SkInterpolator::setKeyFrame(int index, SkMSec time, |
161 const SkScalar values[], const SkScalar blend[4]) { | 161 const SkScalar values[], const SkScalar blend[4]) { |
162 SkASSERT(values != NULL); | 162 SkASSERT(values != nullptr); |
163 | 163 |
164 if (blend == NULL) { | 164 if (blend == nullptr) { |
165 blend = gIdentityBlend; | 165 blend = gIdentityBlend; |
166 } | 166 } |
167 | 167 |
168 bool success = ~index == SkTSearch<SkMSec>(&fTimes->fTime, index, time, | 168 bool success = ~index == SkTSearch<SkMSec>(&fTimes->fTime, index, time, |
169 sizeof(SkTimeCode)); | 169 sizeof(SkTimeCode)); |
170 SkASSERT(success); | 170 SkASSERT(success); |
171 if (success) { | 171 if (success) { |
172 SkTimeCode* timeCode = &fTimes[index]; | 172 SkTimeCode* timeCode = &fTimes[index]; |
173 timeCode->fTime = time; | 173 timeCode->fTime = time; |
174 memcpy(timeCode->fBlend, blend, sizeof(timeCode->fBlend)); | 174 memcpy(timeCode->fBlend, blend, sizeof(timeCode->fBlend)); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 261 } |
262 | 262 |
263 // Now we have t, so compute the coeff for Y and evaluate | 263 // Now we have t, so compute the coeff for Y and evaluate |
264 b = pin_and_convert(by); | 264 b = pin_and_convert(by); |
265 c = pin_and_convert(cy); | 265 c = pin_and_convert(cy); |
266 A = 3*b; | 266 A = 3*b; |
267 B = 3*(c - 2*b); | 267 B = 3*(c - 2*b); |
268 C = 3*(b - c) + Dot14_ONE; | 268 C = 3*(b - c) + Dot14_ONE; |
269 return SkFixedToScalar(eval_cubic(t, A, B, C) << 2); | 269 return SkFixedToScalar(eval_cubic(t, A, B, C) << 2); |
270 } | 270 } |
OLD | NEW |