• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_keyframe_animation.h"
17 
18 #include "animation/rs_render_keyframe_animation.h"
19 #include "command/rs_animation_command.h"
20 #include "transaction/rs_transaction_proxy.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 
25 #define START_KEYFRAME_ANIMATION(Command, Type)                                                            \
26     RSPropertyAnimation::OnStart();                                                                        \
27     auto target = GetTarget().lock();                                                                      \
28     if (target == nullptr) {                                                                               \
29         ROSEN_LOGE("Failed to start keyframe animation, target is null!");                                 \
30         return;                                                                                            \
31     }                                                                                                      \
32     if (keyframes_.empty()) {                                                                              \
33         ROSEN_LOGE("Failed to start keyframe animation, keyframes is null!");                              \
34         return;                                                                                            \
35     }                                                                                                      \
36     auto animation = std::make_shared<RSRenderKeyframeAnimation<Type>>(                                    \
37         GetId(), GetProperty(), RSPropertyAnimation<Type>::originValue_);                                  \
38     for (const auto& [fraction, value, curve] : keyframes_) {                                              \
39         animation->AddKeyframe(fraction, value, curve.GetInterpolator(GetDuration()));                     \
40     }                                                                                                      \
41     animation->SetDuration(GetDuration());                                                                 \
42     animation->SetStartDelay(GetStartDelay());                                                             \
43     animation->SetRepeatCount(GetRepeatCount());                                                           \
44     animation->SetAutoReverse(GetAutoReverse());                                                           \
45     animation->SetSpeed(GetSpeed());                                                                       \
46     animation->SetFillMode(GetFillMode());                                                                 \
47     animation->SetDirection(GetDirection());                                                               \
48     std::unique_ptr<RSCommand> command = std::make_unique<Command>(target->GetId(), animation);            \
49     auto transactionProxy = RSTransactionProxy::GetInstance();                                             \
50     if (transactionProxy != nullptr) {                                                                     \
51         transactionProxy->AddCommand(command, target->IsRenderServiceNode());                              \
52         if (target->NeedForcedSendToRemote()) {                                                            \
53             std::unique_ptr<RSCommand> commandForRemote =                                                  \
54                 std::make_unique<Command>(target->GetId(), animation);                                     \
55             transactionProxy->AddCommand(commandForRemote, true);                                          \
56         }                                                                                                  \
57     }
58 
59 template<>
OnStart()60 void RSKeyframeAnimation<int>::OnStart()
61 {
62     START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeInt, int);
63 }
64 
65 template<>
OnStart()66 void RSKeyframeAnimation<float>::OnStart()
67 {
68     START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeFloat, float);
69 }
70 
71 template<>
OnStart()72 void RSKeyframeAnimation<Color>::OnStart()
73 {
74     START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeColor, Color);
75 }
76 
77 template<>
OnStart()78 void RSKeyframeAnimation<Matrix3f>::OnStart()
79 {
80     START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeMatrix3f, Matrix3f);
81 }
82 
83 template<>
OnStart()84 void RSKeyframeAnimation<Vector2f>::OnStart()
85 {
86     START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeVec2f, Vector2f);
87 }
88 
89 template<>
OnStart()90 void RSKeyframeAnimation<Vector4f>::OnStart()
91 {
92     START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeVec4f, Vector4f);
93 }
94 
95 template<>
OnStart()96 void RSKeyframeAnimation<Quaternion>::OnStart()
97 {
98     START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeQuaternion, Quaternion);
99 }
100 
101 template<>
OnStart()102 void RSKeyframeAnimation<std::shared_ptr<RSFilter>>::OnStart()
103 {
104     // START_KEYFRAME_ANIMATION(RSAnimationCreateKeyframeFilter, std::shared_ptr<RSFilter>);
105 }
106 } // namespace Rosen
107 } // namespace OHOS
108