• 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 namespace OHOS {
26 namespace Rosen {
27 namespace {
28     using StateTask = std::function<void()>;
29 }
30 enum class WindowNodeState : uint32_t {
31     INITIAL,
32     STARTING_CREATED,
33     SHOW_ANIMATION_PLAYING,
34     SHOW_ANIMATION_DONE,
35     HIDE_ANIMATION_PLAYING,
36     HIDE_ANIMATION_DONE,
37     SHOWN,
38     HIDDEN,
39     DESTROYED
40 };
41 
42 class WindowNodeStateMachine {
43 public:
44     WindowNodeStateMachine();
45 
46     ~WindowNodeStateMachine();
47 
48     void TransitionTo(WindowNodeState state);
49 
50     void UpdateAnimationTaskCount(bool isAdd);
51 
52     int32_t GetAnimationCount();
53 
54     bool IsWindowNodeShownOrShowing();
55 
56     bool IsRemoteAnimationPlaying();
57 
58     bool IsWindowNodeHiddenOrHiding();
59 
60     WindowNodeState GetCurrentState();
61 
62     bool IsShowAnimationPlaying();
63 
64     bool IsHideAnimationPlaying();
65 
66     void SetDestroyTaskParam(bool onlySelf);
67 
68     bool GetDestroyTaskParam();
69 
70     void SetDestroyTask(StateTask task);
71 
72     bool GetDestroyTask(StateTask& task);
73 
74     void ResetAnimationTaskCount(int32_t taskCount);
75 
76     std::string GenStateMachineInfo();
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