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