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