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
30namespace OHOS {
31namespace Rosen {
32enum 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
43class RemoteAnimation : public RefBase {
44public:
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);
80    static inline bool IsAnimationFirst()
81    {
82        return animationFirst_;
83    }
84    static bool isRemoteAnimationEnable_;
85
86private:
87    static sptr<RSWindowAnimationTarget> CreateWindowAnimationTarget(sptr<WindowTransitionInfo> info,
88        const sptr<WindowNode>& windowNode);
89    static WMError NotifyAnimationStartApp(sptr<WindowTransitionInfo> srcInfo,
90        const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode,
91        sptr<RSWindowAnimationTarget>& dstTarget, sptr<RSWindowAnimationFinishedCallback>& finishedCallback);
92    static sptr<RSWindowAnimationFinishedCallback> CreateShowAnimationFinishedCallback(
93        const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode, bool needMinimizeSrcNode);
94    static sptr<RSWindowAnimationFinishedCallback> CreateHideAnimationFinishedCallback(
95        const sptr<WindowNode>& srcNode, TransitionEvent event);
96    static void ProcessNodeStateTask(sptr<WindowNode>& node);
97    static void GetExpectRect(const sptr<WindowNode>& dstNode, const sptr<RSWindowAnimationTarget>& dstTarget);
98    static void PostProcessShowCallback(const sptr<WindowNode>& node);
99    static void ExecuteFinalStateTask(sptr<WindowNode>& node);
100    static void GetAnimationTargetsForHome(std::vector<sptr<RSWindowAnimationTarget>>& animationTargets,
101        std::vector<wptr<WindowNode>> needMinimizeAppNodes);
102    static sptr<RSWindowAnimationFinishedCallback> GetTransitionFinishedCallback(
103        const sptr<WindowNode>& srcNode, const sptr<WindowNode>& dstNode);
104
105    static sptr<RSIWindowAnimationController> windowAnimationController_;
106    static wptr<WindowRoot> windowRoot_;
107    static std::weak_ptr<AppExecFwk::EventHandler> wmsTaskHandler_;
108    static wptr<WindowController> windowController_;
109    static bool animationFirst_;
110    static std::atomic<uint32_t> allocationId_;
111};
112} // Rosen
113} // OHOS
114#endif // OHOS_ROSEN_REMOTE_ANIMATION_H
115