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_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
24 namespace OHOS {
25 namespace Rosen {
26
27 #define START_CURVE_ANIMATION(RSRenderCommand, Type) \
28 RSPropertyAnimation<Type>::OnStart(); \
29 auto target = GetTarget().lock(); \
30 if (target == nullptr) { \
31 ROSEN_LOGE("Failed to start curve animation, target is null!"); \
32 return; \
33 } \
34 auto interpolator = timingCurve_.GetInterpolator(GetDuration()); \
35 auto animation = std::make_shared<RSRenderCurveAnimation<Type>>(GetId(), GetProperty(), \
36 RSPropertyAnimation<Type>::originValue_, RSPropertyAnimation<Type>::startValue_, \
37 RSPropertyAnimation<Type>::endValue_); \
38 animation->SetDuration(GetDuration()); \
39 animation->SetStartDelay(GetStartDelay()); \
40 animation->SetRepeatCount(GetRepeatCount()); \
41 animation->SetAutoReverse(GetAutoReverse()); \
42 animation->SetSpeed(GetSpeed()); \
43 animation->SetDirection(GetDirection()); \
44 animation->SetFillMode(GetFillMode()); \
45 animation->SetInterpolator(interpolator); \
46 std::unique_ptr<RSCommand> command = std::make_unique<RSRenderCommand>(target->GetId(), animation); \
47 auto transactionProxy = RSTransactionProxy::GetInstance(); \
48 if (transactionProxy != nullptr) { \
49 transactionProxy->AddCommand(command, target->IsRenderServiceNode()); \
50 if (target->NeedForcedSendToRemote()) { \
51 std::unique_ptr<RSCommand> commandForRemote = \
52 std::make_unique<RSRenderCommand>(target->GetId(), animation); \
53 transactionProxy->AddCommand(commandForRemote, true); \
54 } \
55 }
56
57 template<>
OnStart()58 void RSCurveAnimation<int>::OnStart()
59 {
60 START_CURVE_ANIMATION(RSAnimationCreateCurveInt, int);
61 }
62
63 template<>
OnStart()64 void RSCurveAnimation<float>::OnStart()
65 {
66 START_CURVE_ANIMATION(RSAnimationCreateCurveFloat, float);
67 }
68
69 template<>
OnStart()70 void RSCurveAnimation<Color>::OnStart()
71 {
72 START_CURVE_ANIMATION(RSAnimationCreateCurveColor, Color);
73 }
74
75 template<>
OnStart()76 void RSCurveAnimation<Matrix3f>::OnStart()
77 {
78 START_CURVE_ANIMATION(RSAnimationCreateCurveMatrix3f, Matrix3f);
79 }
80
81 template<>
OnStart()82 void RSCurveAnimation<Vector2f>::OnStart()
83 {
84 START_CURVE_ANIMATION(RSAnimationCreateCurveVec2f, Vector2f);
85 }
86
87 template<>
OnStart()88 void RSCurveAnimation<Vector4f>::OnStart()
89 {
90 START_CURVE_ANIMATION(RSAnimationCreateCurveVec4f, Vector4f);
91 }
92
93 template<>
OnStart()94 void RSCurveAnimation<Quaternion>::OnStart()
95 {
96 START_CURVE_ANIMATION(RSAnimationCreateCurveQuaternion, Quaternion);
97 }
98
99 template<>
OnStart()100 void RSCurveAnimation<std::shared_ptr<RSFilter>>::OnStart()
101 {
102 // START_CURVE_ANIMATION(RSAnimationCreateCurveFilter, std::shared_ptr<RSFilter>);
103 }
104 } // namespace Rosen
105 } // namespace OHOS
106