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,bool isCaptureFullOfScreen)36 Drawing::Rect SuperFoldPolicy::GetSnapshotRect(DisplayId displayId, bool isCaptureFullOfScreen)
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 && !isCaptureFullOfScreen) {
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 bool isSystemKeyboardOn = SuperFoldStateManager::GetInstance().GetSystemKeyboardStatus();
58 if (status == SuperFoldStatus::KEYBOARD ||
59 (fakeInfo != nullptr && !isCaptureFullOfScreen)|| isSystemKeyboardOn) {
60 snapshotRect = {0, 0, defaultInfo->GetWidth(), defaultInfo->GetHeight()};
61 } else {
62 snapshotRect = {0, 0, screenWidth, screenHeight};
63 }
64 }
65 std::ostringstream oss;
66 oss << "snapshot displayId: " << static_cast<uint32_t>(displayId)
67 << " left: 0"
68 << " top:" << snapshotRect.top_
69 << " right:" << snapshotRect.right_
70 << " bottom:" << snapshotRect.bottom_
71 << " isCaptureFullOfScreen:" << isCaptureFullOfScreen;
72 TLOGW(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
73 return snapshotRect;
74 }
75
GetRecordRect(DisplayId displayId)76 DMRect SuperFoldPolicy::GetRecordRect(DisplayId displayId)
77 {
78 DMRect recordRect = {0, 0, 0, 0};
79 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(SCREEN_ID_DEFAULT);
80 auto defaultInfo = ScreenSessionManager::GetInstance().GetDisplayInfoById(DEFAULT_DISPLAY_ID);
81 if (screenSession == nullptr || defaultInfo == nullptr) {
82 TLOGE(WmsLogTag::DMS, "session or display nullptr.");
83 return recordRect;
84 }
85 ScreenProperty screenProperty = screenSession->GetScreenProperty();
86 DMRect creaseRect = screenProperty.GetCreaseRect();
87 auto fakeInfo = ScreenSessionManager::GetInstance().GetDisplayInfoById(DISPLAY_ID_FAKE);
88 if (displayId == DISPLAY_ID_FAKE) {
89 if (fakeInfo != nullptr) {
90 recordRect = {0, defaultInfo->GetHeight() + static_cast<int32_t>(creaseRect.height_),
91 defaultInfo->GetWidth(), fakeInfo->GetHeight()};
92 }
93 } else {
94 SuperFoldStatus status = SuperFoldStateManager::GetInstance().GetCurrentStatus();
95 bool isSystemKeyboardOn = SuperFoldStateManager::GetInstance().GetSystemKeyboardStatus();
96 if (status == SuperFoldStatus::KEYBOARD || fakeInfo != nullptr || isSystemKeyboardOn) {
97 recordRect = {0, 0, defaultInfo->GetWidth(), defaultInfo->GetHeight()};
98 } else {
99 recordRect = {0, 0, 0, 0};
100 }
101 }
102 std::ostringstream oss;
103 oss << "snapshot displayId: " << static_cast<uint32_t>(displayId)
104 << " left: 0"
105 << " top:" << recordRect.posY_
106 << " right:" << recordRect.width_
107 << " bottom:" << recordRect.height_;
108 TLOGW(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
109 return recordRect;
110 }
111
112 } // namespace OHOS::Rosen
113