1 /**
2 * Copyright (c) 2024-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 "core/common/display_info_utils.h"
17
18 #include "display_manager.h"
19
20 #include "core/common/display_info.h"
21
22 namespace OHOS::Ace {
GetDisplayInfo()23 RefPtr<DisplayInfo> DisplayInfoUtils::GetDisplayInfo()
24 {
25 auto displayManager = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
26 CHECK_NULL_RETURN(displayManager, nullptr);
27 displayInfo_->SetWidth(displayManager->GetWidth());
28 displayInfo_->SetHeight(displayManager->GetHeight());
29 displayInfo_->SetDisplayId(displayManager->GetId());
30 auto dmRotation = displayManager->GetRotation();
31 displayInfo_->SetRotation(static_cast<Rotation>(static_cast<uint32_t>(dmRotation)));
32 GetIsFoldable();
33 GetCurrentFoldStatus();
34 GetCurrentFoldCreaseRegion();
35 return displayInfo_;
36 }
37
InitIsFoldable()38 void DisplayInfoUtils::InitIsFoldable()
39 {
40 auto isFoldable = Rosen::DisplayManager::GetInstance().IsFoldable();
41 displayInfo_->SetIsFoldable(isFoldable);
42 }
43
GetIsFoldable()44 bool DisplayInfoUtils::GetIsFoldable()
45 {
46 if (hasInitIsFoldable_) {
47 return displayInfo_->GetIsFoldable();
48 }
49 auto isFoldable = Rosen::DisplayManager::GetInstance().IsFoldable();
50 displayInfo_->SetIsFoldable(isFoldable);
51 hasInitIsFoldable_ = true;
52 return isFoldable;
53 }
54
GetCurrentFoldStatus()55 FoldStatus DisplayInfoUtils::GetCurrentFoldStatus()
56 {
57 auto dmFoldStatus = Rosen::DisplayManager::GetInstance().GetFoldStatus();
58 displayInfo_->SetFoldStatus(static_cast<FoldStatus>(static_cast<uint32_t>(dmFoldStatus)));
59 return displayInfo_->GetFoldStatus();
60 }
61
GetCurrentFoldCreaseRegion()62 std::vector<Rect> DisplayInfoUtils::GetCurrentFoldCreaseRegion()
63 {
64 if (hasInitFoldCreaseRegion_) {
65 return displayInfo_->GetCurrentFoldCreaseRegion();
66 }
67 std::vector<Rect> rects;
68 auto foldCreaseRegion = Rosen::DisplayManager::GetInstance().GetCurrentFoldCreaseRegion();
69 if (!foldCreaseRegion) {
70 TAG_LOGW(AceLogTag::ACE_OVERLAY, "failed to get foldCreaseRegion");
71 return rects;
72 }
73
74 auto creaseRects = foldCreaseRegion->GetCreaseRects();
75 if (creaseRects.empty()) {
76 return rects;
77 }
78
79 for (const auto& item : creaseRects) {
80 Rect rect;
81 rect.SetRect(item.posX_, item.posY_, item.width_, item.height_);
82 rects.insert(rects.end(), rect);
83 }
84 displayInfo_->SetCurrentFoldCreaseRegion(rects);
85 hasInitFoldCreaseRegion_ = true;
86 return rects;
87 }
88 } // namespace OHOS::Ace::DisplayInfoUtils
89