1 /*
2 * Copyright (c) 2025 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 #include "fold_screen_controller/super_fold_policy.h"
17 #include "window_manager_hilog.h"
18
19 namespace OHOS::Rosen {
20 WM_IMPLEMENT_SINGLE_INSTANCE(SuperFoldPolicy)
21 namespace {
22 constexpr DisplayId DEFAULT_DISPLAY_ID = 0;
23 constexpr ScreenId SCREEN_ID_DEFAULT = 0;
24 }
25
IsFakeDisplayExist()26 bool SuperFoldPolicy::IsFakeDisplayExist()
27 {
28 return ScreenSessionManager::GetInstance().GetDisplayInfoById(DISPLAY_ID_FAKE) != nullptr;
29 }
30
IsNeedSetSnapshotRect(DisplayId displayId)31 bool SuperFoldPolicy::IsNeedSetSnapshotRect(DisplayId displayId)
32 {
33 return (displayId == DEFAULT_DISPLAY_ID) || (displayId == DISPLAY_ID_FAKE);
34 }
35
GetSnapshotRect(DisplayId displayId)36 Drawing::Rect SuperFoldPolicy::GetSnapshotRect(DisplayId displayId)
37 {
38 Drawing::Rect snapshotRect = {0, 0, 0, 0};
39 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(SCREEN_ID_DEFAULT);
40 auto defaultInfo = ScreenSessionManager::GetInstance().GetDisplayInfoById(DEFAULT_DISPLAY_ID);
41 if (screenSession == nullptr || defaultInfo == nullptr) {
42 TLOGE(WmsLogTag::DMS, "session or display nullptr.");
43 return snapshotRect;
44 }
45 ScreenProperty screenProperty = screenSession->GetScreenProperty();
46 auto screenWidth = screenProperty.GetPhyBounds().rect_.GetWidth();
47 auto screenHeight = screenProperty.GetPhyBounds().rect_.GetHeight();
48 DMRect creaseRect = screenProperty.GetCreaseRect();
49 auto fakeInfo = ScreenSessionManager::GetInstance().GetDisplayInfoById(DISPLAY_ID_FAKE);
50 if (displayId == DISPLAY_ID_FAKE) {
51 if (fakeInfo != nullptr) {
52 snapshotRect = {0, defaultInfo->GetHeight() + static_cast<int32_t>(creaseRect.height_),
53 screenWidth, screenHeight};
54 }
55 } else {
56 SuperFoldStatus status = SuperFoldStateManager::GetInstance().GetCurrentStatus();
57 if (status == SuperFoldStatus::KEYBOARD || fakeInfo != nullptr) {
58 snapshotRect = {0, 0, defaultInfo->GetWidth(), defaultInfo->GetHeight()};
59 } else {
60 snapshotRect = {0, 0, screenWidth, screenHeight};
61 }
62 }
63 std::ostringstream oss;
64 oss << "snapshot displayId: " << static_cast<uint32_t>(displayId)
65 << " left: 0"
66 << " top:" << snapshotRect.top_
67 << " right:" << snapshotRect.right_
68 << " bottom:" << snapshotRect.bottom_;
69 TLOGW(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
70 return snapshotRect;
71 }
72
GetRecordRect(DisplayId displayId)73 DMRect SuperFoldPolicy::GetRecordRect(DisplayId displayId)
74 {
75 DMRect recordRect = {0, 0, 0, 0};
76 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(SCREEN_ID_DEFAULT);
77 auto defaultInfo = ScreenSessionManager::GetInstance().GetDisplayInfoById(DEFAULT_DISPLAY_ID);
78 if (screenSession == nullptr || defaultInfo == nullptr) {
79 TLOGE(WmsLogTag::DMS, "session or display nullptr.");
80 return recordRect;
81 }
82 ScreenProperty screenProperty = screenSession->GetScreenProperty();
83 auto screenWidth = screenProperty.GetPhyBounds().rect_.GetWidth();
84 auto screenHeight = screenProperty.GetPhyBounds().rect_.GetHeight();
85 DMRect creaseRect = screenProperty.GetCreaseRect();
86 auto fakeInfo = ScreenSessionManager::GetInstance().GetDisplayInfoById(DISPLAY_ID_FAKE);
87 if (displayId == DISPLAY_ID_FAKE) {
88 if (fakeInfo != nullptr) {
89 recordRect = {0, defaultInfo->GetHeight() + static_cast<int32_t>(creaseRect.height_),
90 defaultInfo->GetWidth(), fakeInfo->GetHeight()};
91 }
92 } else {
93 SuperFoldStatus status = SuperFoldStateManager::GetInstance().GetCurrentStatus();
94 if (status == SuperFoldStatus::KEYBOARD || fakeInfo != nullptr) {
95 recordRect = {0, 0, defaultInfo->GetWidth(), defaultInfo->GetHeight()};
96 } else {
97 recordRect = {0, 0, screenWidth, screenHeight};
98 }
99 }
100 std::ostringstream oss;
101 oss << "snapshot displayId: " << static_cast<uint32_t>(displayId)
102 << " left: 0"
103 << " top:" << recordRect.posY_
104 << " right:" << recordRect.width_
105 << " bottom:" << recordRect.height_;
106 TLOGW(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
107 return recordRect;
108 }
109
110 } // namespace OHOS::Rosen
111