• 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_ONBOOTANIMATION_TASK_NUM = 1;
27 const uint32_t FOLD_TO_EXPAND_TASK_NUM = 3;
28 constexpr uint32_t SECONDARY_FOLD_TO_EXPAND_TASK_NUM = 2;
29 
30 enum class DisplayModeChangeReason : uint32_t {
31     DEFAULT = 0,
32     RECOVER,
33     INVALID,
34 };
35 
36 class FoldScreenPolicy : public RefBase {
37 public:
38     FoldScreenPolicy();
39     virtual ~FoldScreenPolicy();
40 
41     virtual void ChangeScreenDisplayMode(FoldDisplayMode displayMode,
42         DisplayModeChangeReason reason = DisplayModeChangeReason::DEFAULT);
43     virtual void SendSensorResult(FoldStatus foldStatus);
44     virtual ScreenId GetCurrentScreenId();
45     virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion();
46     virtual void LockDisplayStatus(bool locked);
47     virtual void SetOnBootAnimation(bool onBootAnimation);
48     virtual void UpdateForPhyScreenPropertyChange();
49     virtual void ExitCoordination();
50     virtual void AddOrRemoveDisplayNodeToTree(ScreenId screenId, int32_t command);
GetModeMatchStatus()51     virtual FoldDisplayMode GetModeMatchStatus() { return FoldDisplayMode::UNKNOWN; }
BootAnimationFinishPowerInit()52     virtual void BootAnimationFinishPowerInit() {};
53     virtual void ChangeOnTentMode(FoldStatus currentState);
54     virtual void ChangeOffTentMode();
55     virtual void SetScreenSnapshotRect(RSSurfaceCaptureConfig& config);
56     virtual void SetMainScreenRegion(DMRect& mainScreenRegion);
57     void ClearState();
58     FoldDisplayMode GetScreenDisplayMode();
59     FoldStatus GetFoldStatus();
60     void SetFoldStatus(FoldStatus foldStatus);
61 
62     ScreenId screenId_ { SCREEN_ID_INVALID };
63     ScreenProperty screenProperty_;
64     mutable std::recursive_mutex displayModeMutex_;
65     FoldDisplayMode currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
66     FoldStatus currentFoldStatus_ = FoldStatus::UNKNOWN;
67     FoldDisplayMode lastDisplayMode_ = FoldDisplayMode::UNKNOWN;
68     FoldStatus lastFoldStatus_ = FoldStatus::UNKNOWN;
69     sptr<FoldCreaseRegion> currentFoldCreaseRegion_ = nullptr;
70     bool lockDisplayStatus_ = false;
71     bool onBootAnimation_ = false;
72     std::vector<uint32_t> screenParams_ = {};
73     /*
74      *    Avoid fold to expand process queues public interface
75      */
76     bool GetModeChangeRunningStatus();
77     virtual void SetdisplayModeChangeStatus(bool status, bool isOnBootAnimation = false){};
SetSecondaryDisplayModeChangeStatus(bool status)78     virtual void SetSecondaryDisplayModeChangeStatus(bool status){};
79     bool GetdisplayModeRunningStatus();
80     FoldDisplayMode GetLastCacheDisplayMode();
GetScreenParams()81     virtual std::vector<uint32_t> GetScreenParams() { return screenParams_; };
82 
83 protected:
84     /*
85      *    Avoid fold to expand process queues private variable
86      */
87     std::atomic<int> pengdingTask_{FOLD_TO_EXPAND_TASK_NUM};
88     std::atomic<int> secondaryPengdingTask_{SECONDARY_FOLD_TO_EXPAND_TASK_NUM};
89     std::atomic<bool> displayModeChangeRunning_ = false;
90     std::atomic<FoldDisplayMode> lastCachedisplayMode_ = FoldDisplayMode::UNKNOWN;
91     std::chrono::steady_clock::time_point startTimePoint_ = std::chrono::steady_clock::now();
92     std::chrono::steady_clock::time_point endTimePoint_ = std::chrono::steady_clock::now();
93     void SetLastCacheDisplayMode(FoldDisplayMode mode);
94     int64_t getFoldingElapsedMs();
95 };
96 } // namespace OHOS::Rosen
97 #endif //OHOS_ROSEN_WINDOW_SCENE_FOLD_SCREEN_POLICY_H