• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef OHOS_ROSEN_WINDOW_SCENE_FOLD_SCREEN_POLICY_H
16 #define OHOS_ROSEN_WINDOW_SCENE_FOLD_SCREEN_POLICY_H
17 
18 #include <refbase.h>
19 #include <mutex>
20 
21 #include "dm_common.h"
22 #include "session/screen/include/screen_property.h"
23 #include "fold_screen_info.h"
24 
25 namespace OHOS::Rosen {
26 const uint32_t FOLD_TO_EXPAND_TASK_NUM = 3;
27 
28 enum class DisplayModeChangeReason : uint32_t {
29     DEFAULT = 0,
30     RECOVER,
31     INVALID,
32 };
33 
34 class FoldScreenPolicy : public RefBase {
35 public:
36     FoldScreenPolicy();
37     virtual ~FoldScreenPolicy();
38 
39     virtual void ChangeScreenDisplayMode(FoldDisplayMode displayMode,
40         DisplayModeChangeReason reason = DisplayModeChangeReason::DEFAULT);
41     virtual void SendSensorResult(FoldStatus foldStatus);
42     virtual ScreenId GetCurrentScreenId();
43     virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion();
44     virtual void LockDisplayStatus(bool locked);
45     virtual void SetOnBootAnimation(bool onBootAnimation);
46     virtual void UpdateForPhyScreenPropertyChange();
47     virtual void ExitCoordination();
48     virtual void AddOrRemoveDisplayNodeToTree(ScreenId screenId, int32_t command);
GetModeMatchStatus()49     virtual FoldDisplayMode GetModeMatchStatus() { return FoldDisplayMode::UNKNOWN; }
50     void ClearState();
51     FoldDisplayMode GetScreenDisplayMode();
52     FoldStatus GetFoldStatus();
53     void SetFoldStatus(FoldStatus foldStatus);
54 
55     ScreenId screenId_ { SCREEN_ID_INVALID };
56     ScreenProperty screenProperty_;
57     mutable std::recursive_mutex displayModeMutex_;
58     FoldDisplayMode currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
59     FoldStatus currentFoldStatus_ = FoldStatus::UNKNOWN;
60     FoldDisplayMode lastDisplayMode_ = FoldDisplayMode::UNKNOWN;
61     FoldStatus lastFoldStatus_ = FoldStatus::UNKNOWN;
62     sptr<FoldCreaseRegion> currentFoldCreaseRegion_ = nullptr;
63     bool lockDisplayStatus_ = false;
64     bool onBootAnimation_ = false;
65     /*
66      *    Avoid fold to expand process queues public interface
67      */
68     bool GetModeChangeRunningStatus();
SetdisplayModeChangeStatus(bool status)69     virtual void SetdisplayModeChangeStatus(bool status){};
70     bool GetdisplayModeRunningStatus();
71     FoldDisplayMode GetLastCacheDisplayMode();
72 
73 protected:
74     /*
75      *    Avoid fold to expand process queues private variable
76      */
77     std::atomic<int> pengdingTask_{FOLD_TO_EXPAND_TASK_NUM};
78     std::atomic<bool> displayModeChangeRunning_ = false;
79     std::atomic<FoldDisplayMode> lastCachedisplayMode_ = FoldDisplayMode::UNKNOWN;
80     std::chrono::steady_clock::time_point startTimePoint_ = std::chrono::steady_clock::now();
81     std::chrono::steady_clock::time_point endTimePoint_ = std::chrono::steady_clock::now();
82     void SetLastCacheDisplayMode(FoldDisplayMode mode);
83     int64_t getFoldingElapsedMs();
84 };
85 } // namespace OHOS::Rosen
86 #endif //OHOS_ROSEN_WINDOW_SCENE_FOLD_SCREEN_POLICY_H