1 /*
2  * Copyright (c) 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 #ifndef OHOS_ROSEN_REMOTE_ANIMATION_H
17 #define OHOS_ROSEN_REMOTE_ANIMATION_H
18 
19 #include <refbase.h>
20 #include <rs_iwindow_animation_controller.h>
21 #include <rs_window_animation_finished_callback.h>
22 #include <rs_window_animation_target.h>
23 
24 #include "wm_common.h"
25 #include "window_controller.h"
26 #include "window_node.h"
27 #include "window_root.h"
28 #include "window_transition_info.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 enum class TransitionEvent : uint32_t {
33     APP_TRANSITION,
34     HOME,
35     MINIMIZE,
36     CLOSE,
37     BACK_TRANSITION,
38     CLOSE_BUTTON,
39     BACKGROUND_TRANSITION,
40     UNKNOWN,
41 };
42 
43 class RemoteAnimation : public RefBase {
44 public:
45     RemoteAnimation() = delete;
46     ~RemoteAnimation() = default;
47 
48     static bool CheckTransition(sptr<WindowTransitionInfo> srcInfo, const sptr<WindowNode>& srcNode,
49         sptr<WindowTransitionInfo> dstInfo, const sptr<WindowNode>& dstNode);
50     static TransitionEvent GetTransitionEvent(sptr<WindowTransitionInfo> srcInfo,
51         sptr<WindowTransitionInfo> dstInfo, const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode);
52     static WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller);
53     static WMError NotifyAnimationTransition(sptr<WindowTransitionInfo> srcInfo, sptr<WindowTransitionInfo> dstInfo,
54         const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode);
55     static WMError NotifyAnimationMinimize(sptr<WindowTransitionInfo> srcInfo, const sptr<WindowNode>& srcNode);
56     static WMError NotifyAnimationClose(sptr<WindowTransitionInfo> srcInfo, const sptr<WindowNode>& srcNode,
57         TransitionEvent event);
58     static WMError NotifyAnimationBackTransition(sptr<WindowTransitionInfo> srcInfo,
59         sptr<WindowTransitionInfo> dstInfo, const sptr<WindowNode>& srcNode,
60         const sptr<WindowNode>& dstNode, const TransitionEvent event);
61     static void NotifyAnimationUpdateWallpaper(sptr<WindowNode> node);
62     static void OnRemoteDie(const sptr<IRemoteObject>& remoteObject);
63     static bool CheckAnimationController();
64     static bool CheckRemoteAnimationEnabled(DisplayId displayId);
65     static void NotifyAnimationAbilityDied(sptr<WindowTransitionInfo> info);
66     static WMError NotifyAnimationByHome();
67     static WMError NotifyAnimationScreenUnlock(std::function<void(void)> callback, sptr<WindowNode> node);
68     static void SetMainTaskHandler(std::shared_ptr<AppExecFwk::EventHandler> handler);
69     static void NotifyAnimationTargetsUpdate(std::vector<uint32_t>& fullScreenWinIds,
70         std::vector<uint32_t>& floatWinIds);
71     static void SetAnimationFirst(bool animationFirst);
72     static void SetWindowControllerAndRoot(const sptr<WindowController>& windowController,
73     const sptr<WindowRoot>& windowRoot);
74     static bool IsRemoteAnimationEnabledAndFirst(DisplayId displayId = 0);
75     static void CallbackTimeOutProcess();
76     static sptr<RSWindowAnimationFinishedCallback> CreateAnimationFinishedCallback(
77         const std::function<void(void)>& callback, sptr<WindowNode> windowNode);
78     static WMError GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
79         std::vector<sptr<RSWindowAnimationTarget>>& targets);
IsAnimationFirst()80     static inline bool IsAnimationFirst()
81     {
82         return animationFirst_;
83     }
84     static bool isRemoteAnimationEnable_;
85 private:
86     static sptr<RSWindowAnimationTarget> CreateWindowAnimationTarget(sptr<WindowTransitionInfo> info,
87         const sptr<WindowNode>& windowNode);
88     static WMError NotifyAnimationStartApp(sptr<WindowTransitionInfo> srcInfo,
89         const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode,
90         sptr<RSWindowAnimationTarget>& dstTarget, sptr<RSWindowAnimationFinishedCallback>& finishedCallback);
91     static sptr<RSWindowAnimationFinishedCallback> CreateShowAnimationFinishedCallback(
92         const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode, bool needMinimizeSrcNode);
93     static sptr<RSWindowAnimationFinishedCallback> CreateHideAnimationFinishedCallback(
94         const sptr<WindowNode>& srcNode, TransitionEvent event);
95     static void ProcessNodeStateTask(sptr<WindowNode>& node);
96     static void GetExpectRect(const sptr<WindowNode>& dstNode, const sptr<RSWindowAnimationTarget>& dstTarget);
97     static void PostProcessShowCallback(const sptr<WindowNode>& node);
98     static void ExecuteFinalStateTask(sptr<WindowNode>& node);
99     static void GetAnimationTargetsForHome(std::vector<sptr<RSWindowAnimationTarget>>& animationTargets,
100         std::vector<wptr<WindowNode>> needMinimizeAppNodes);
101     static sptr<RSWindowAnimationFinishedCallback> GetTransitionFinishedCallback(
102         const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode);
103 
104     static sptr<RSIWindowAnimationController> windowAnimationController_;
105     static wptr<WindowRoot> windowRoot_;
106     static std::weak_ptr<AppExecFwk::EventHandler> wmsTaskHandler_;
107     static wptr<WindowController> windowController_;
108     static bool animationFirst_;
109     static std::atomic<uint32_t> allocationId_;
110 };
111 } // Rosen
112 } // OHOS
113 #endif // OHOS_ROSEN_REMOTE_ANIMATION_H
114