• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WINDOW_NODE_STATE_MACHINE_H
17 #define OHOS_ROSEN_WINDOW_NODE_STATE_MACHINE_H
18 
19 #include <atomic>
20 #include <deque>
21 #include <functional>
22 #include <mutex>
23 #include <vector>
24 #include "wm_common.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29     using StateTask = std::function<void()>;
30 }
31 enum class WindowNodeState : uint32_t {
32     INITIAL,
33     STARTING_CREATED,
34     SHOW_ANIMATION_PLAYING,
35     SHOW_ANIMATION_DONE,
36     HIDE_ANIMATION_PLAYING,
37     HIDE_ANIMATION_DONE,
38     SHOWN,
39     HIDDEN,
40     DESTROYED
41 };
42 
43 class WindowNodeStateMachine {
44 public:
45     WindowNodeStateMachine();
46 
47     ~WindowNodeStateMachine();
48 
49     void TransitionTo(WindowNodeState state);
50 
51     void UpdateAnimationTaskCount(bool isAdd);
52 
53     int32_t GetAnimationCount();
54 
55     bool IsWindowNodeShownOrShowing();
56 
57     bool IsRemoteAnimationPlaying();
58 
59     bool IsWindowNodeHiddenOrHiding();
60 
61     WindowNodeState GetCurrentState();
62 
63     bool IsShowAnimationPlaying();
64 
65     bool IsHideAnimationPlaying();
66 
67     void SetDestroyTaskParam(bool onlySelf);
68 
69     bool GetDestroyTaskParam();
70 
71     void SetDestroyTask(StateTask task);
72 
73     bool GetDestroyTask(StateTask& task);
74 
75     void ResetAnimationTaskCount(int32_t taskCount);
76 
77     // test
SetWindowId(uint32_t id)78     void SetWindowId(uint32_t id)
79     {
80         windowId_ = id;
81     }
82 
SetWindowType(WindowType type)83     void SetWindowType(WindowType type)
84     {
85         type_ = type;
86     }
87 
88 private:
89     std::deque<std::pair<std::string, StateTask>> stateTaskQ_;
90     WindowNodeState currState_ = WindowNodeState::INITIAL;
91     int32_t taskCount_ = 0;
92     std::recursive_mutex mutex_;
93     bool destroyOnlySelf_ = true;
94     // just for test
95     uint32_t windowId_ = 0;
96     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
97     uint32_t count1 = 0;
98     uint32_t count2 = 0;
99     StateTask destroyTask_;
100 };
101 } // namespace Rosen
102 } // namespace OHOS
103 #endif