• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "animation/rs_value_estimator.h"
17 
18 #include "common/rs_common_def.h"
19 #include "platform/common/rs_log.h"
20 #include "modifier/rs_render_property.h"
21 #include "render/rs_material_filter.h"
22 
23 namespace OHOS {
24 namespace Rosen {
Estimate(float fraction,const Quaternion & startValue,const Quaternion & endValue)25 Quaternion RSValueEstimator::Estimate(float fraction,
26     const Quaternion& startValue, const Quaternion& endValue)
27 {
28     auto value = startValue;
29     return value.Slerp(endValue, fraction);
30 }
31 
32 template<>
EstimateFraction(const std::shared_ptr<RSInterpolator> & interpolator)33 float RSCurveValueEstimator<float>::EstimateFraction(const std::shared_ptr<RSInterpolator>& interpolator)
34 {
35     if (interpolator == nullptr) {
36         ROSEN_LOGD("Interpolator is null, return FRACTION_MIN.");
37         return FRACTION_MIN;
38     }
39     float start = FRACTION_MIN;
40     float end = FRACTION_MAX;
41     auto byValue = endValue_ - startValue_;
42     while (end > start + EPSILON) {
43         float mid = (start + end) / 2.0f;
44         float fraction = interpolator->Interpolate(mid);
45         auto interpolationValue = startValue_ * (1.0f - fraction) + endValue_ * fraction;
46         if (lastValue_ < interpolationValue) {
47             (byValue > 0) ? (end = mid) : (start = mid);
48         } else {
49             (byValue > 0) ? (start = mid) : (end = mid);
50         }
51 
52         if (std::abs(lastValue_ - interpolationValue) <= EPSILON) {
53             return mid;
54         }
55     }
56 
57     return FRACTION_MIN;
58 }
59 
60 template class RSCurveValueEstimator<float>;
61 } // namespace Rosen
62 } // namespace OHOS
63