• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_curve_animation.h"
17 
18 #include "animation/rs_animation_common.h"
19 #include "animation/rs_render_curve_animation.h"
20 #include "command/rs_animation_command.h"
21 #include "platform/common/rs_log.h"
22 #include "transaction/rs_transaction_proxy.h"
23 #include "ui/rs_node.h"
24 #include "modifier/rs_property.h"
25 
26 namespace OHOS {
27 namespace Rosen {
RSCurveAnimation(std::shared_ptr<RSPropertyBase> property,const std::shared_ptr<RSPropertyBase> & byValue)28 RSCurveAnimation::RSCurveAnimation(std::shared_ptr<RSPropertyBase> property,
29     const std::shared_ptr<RSPropertyBase>& byValue) : RSPropertyAnimation(property)
30 {
31     isDelta_ = true;
32     byValue_ = byValue;
33 }
34 
RSCurveAnimation(std::shared_ptr<RSPropertyBase> property,const std::shared_ptr<RSPropertyBase> & startValue,const std::shared_ptr<RSPropertyBase> & endValue)35 RSCurveAnimation::RSCurveAnimation(std::shared_ptr<RSPropertyBase> property,
36     const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue)
37     : RSPropertyAnimation(property)
38 {
39     isDelta_ = false;
40     startValue_ = startValue;
41     endValue_ = endValue;
42 }
43 
SetTimingCurve(const RSAnimationTimingCurve & timingCurve)44 void RSCurveAnimation::SetTimingCurve(const RSAnimationTimingCurve& timingCurve)
45 {
46     if (timingCurve.type_ != RSAnimationTimingCurve::CurveType::INTERPOLATING) {
47         ROSEN_LOGE("RSCurveAnimation::SetTimingCurve: invalid timing curve type");
48         return;
49     }
50     timingCurve_ = timingCurve;
51 }
52 
GetTimingCurve() const53 const RSAnimationTimingCurve& RSCurveAnimation::GetTimingCurve() const
54 {
55     return timingCurve_;
56 }
57 
StartRenderAnimation(const std::shared_ptr<RSRenderCurveAnimation> & animation)58 void RSCurveAnimation::StartRenderAnimation(const std::shared_ptr<RSRenderCurveAnimation>& animation)
59 {
60     auto target = GetTarget().lock();
61     if (target == nullptr) {
62         ROSEN_LOGE("Failed to start curve animation, target is null!");
63         return;
64     }
65     std::unique_ptr<RSCommand> command = std::make_unique<RSAnimationCreateCurve>(target->GetId(), animation);
66     target->AddCommand(command, target->IsRenderServiceNode(), target->GetFollowType(), target->GetId());
67 }
68 
StartUIAnimation(const std::shared_ptr<RSRenderCurveAnimation> & animation)69 void RSCurveAnimation::StartUIAnimation(const std::shared_ptr<RSRenderCurveAnimation>& animation)
70 {
71     StartCustomAnimation(animation);
72 }
73 
OnStart()74 void RSCurveAnimation::OnStart()
75 {
76     RSPropertyAnimation::OnStart();
77     auto interpolator = timingCurve_.GetInterpolator(GetDuration());
78     auto animation = std::make_shared<RSRenderCurveAnimation>(GetId(), GetPropertyId(),
79         originValue_->GetRenderProperty(), startValue_->GetRenderProperty(), endValue_->GetRenderProperty());
80     animation->SetInterpolator(interpolator);
81     animation->SetAdditive(GetAdditive());
82     UpdateParamToRenderAnimation(animation);
83     if (isCustom_) {
84         animation->AttachRenderProperty(property_->GetRenderProperty());
85         StartUIAnimation(animation);
86     } else {
87         StartRenderAnimation(animation);
88     }
89 }
90 
IsSupportInteractiveAnimator()91 bool RSCurveAnimation::IsSupportInteractiveAnimator()
92 {
93     auto interpolator = timingCurve_.GetInterpolator(GetDuration());
94     if (interpolator == nullptr) {
95         ROSEN_LOGD("RSCurveAnimation::IsSupportInteractiveAnimator, interpolator is null!");
96         return false;
97     }
98 
99     if (interpolator->GetType() == InterpolatorType::CUSTOM || interpolator->GetType() == InterpolatorType::STEPS) {
100         return false;
101     }
102     return true;
103 }
104 } // namespace Rosen
105 } // namespace OHOS
106