• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "display_group_info.h"
17 
18 #include <cinttypes>
19 #include "window_manager_hilog.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 namespace {
24     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "DisplayGroupInfo"};
25 }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayGroupInfo)26 WM_IMPLEMENT_SINGLE_INSTANCE(DisplayGroupInfo)
27 
28 void DisplayGroupInfo::Init(ScreenId displayGroupId, const sptr<DisplayInfo>& displayInfo)
29 {
30     displayGroupId_ = displayGroupId;
31     AddDisplayInfo(displayInfo);
32 }
33 
AddDisplayInfo(const sptr<DisplayInfo> & displayInfo)34 void DisplayGroupInfo::AddDisplayInfo(const sptr<DisplayInfo>& displayInfo)
35 {
36     DisplayId displayId = displayInfo->GetDisplayId();
37     if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) {
38         WLOGFE("current display is exits, displayId: %{public}" PRIu64"", displayId);
39         return;
40     }
41     displayInfosMap_.insert(std::make_pair(displayId, displayInfo));
42 }
43 
RemoveDisplayInfo(DisplayId displayId)44 void DisplayGroupInfo::RemoveDisplayInfo(DisplayId displayId)
45 {
46     if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) {
47         WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId);
48         return;
49     }
50     displayInfosMap_.erase(displayId);
51 }
52 
UpdateLeftAndRightDisplayId()53 void DisplayGroupInfo::UpdateLeftAndRightDisplayId()
54 {
55     auto displayRectMap = GetAllDisplayRects();
56     leftDisplayId_ = displayRectMap.begin()->first;
57     rightDisplayId_ = displayRectMap.begin()->first;
58     for (auto& elem : displayRectMap) {
59         auto& curDisplayRect = elem.second;
60         if (curDisplayRect.posX_ < displayRectMap[leftDisplayId_].posX_) {
61             leftDisplayId_ = elem.first;
62         }
63         if ((curDisplayRect.posX_ + static_cast<int32_t>(curDisplayRect.width_)) >
64             (displayRectMap[rightDisplayId_].posX_ + static_cast<int32_t>(displayRectMap[rightDisplayId_].width_))) {
65             rightDisplayId_ = elem.first;
66         }
67     }
68     WLOGI("max posX displayId: %{public}" PRIu64", min posX displayId: %{public}" PRIu64"",
69         rightDisplayId_, leftDisplayId_);
70 }
71 
SetDisplayRotation(DisplayId displayId,Rotation rotation)72 void DisplayGroupInfo::SetDisplayRotation(DisplayId displayId, Rotation rotation)
73 {
74     if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) {
75         WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId);
76         return;
77     }
78     displayInfosMap_[displayId]->SetRotation(rotation);
79 }
80 
SetDisplayOrientation(DisplayId displayId,DisplayOrientation orientation)81 void DisplayGroupInfo::SetDisplayOrientation(DisplayId displayId, DisplayOrientation orientation)
82 {
83     if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) {
84         WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId);
85         return;
86     }
87     displayInfosMap_[displayId]->SetDisplayOrientation(orientation);
88 }
89 
SetDisplayStateChangeType(DisplayId displayId,DisplayStateChangeType changeType)90 void DisplayGroupInfo::SetDisplayStateChangeType(DisplayId displayId, DisplayStateChangeType changeType)
91 {
92     if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) {
93         WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId);
94         return;
95     }
96     displayInfosMap_[displayId]->SetDisplayStateChangeType(changeType);
97 }
98 
SetDisplayVirtualPixelRatio(DisplayId displayId,float vpr)99 void DisplayGroupInfo::SetDisplayVirtualPixelRatio(DisplayId displayId, float vpr)
100 {
101     if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) {
102         WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId);
103         return;
104     }
105     displayInfosMap_[displayId]->SetVirtualPixelRatio(vpr);
106 }
107 
SetDisplayRect(DisplayId displayId,Rect displayRect)108 void DisplayGroupInfo::SetDisplayRect(DisplayId displayId, Rect displayRect)
109 {
110     if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) {
111         WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId);
112         return;
113     }
114     auto& displayInfo = displayInfosMap_[displayId];
115     displayInfo->SetOffsetX(displayRect.posX_);
116     displayInfo->SetOffsetY(displayRect.posY_);
117     displayInfo->SetWidth(displayRect.width_);
118     displayInfo->SetHeight(displayRect.height_);
119 }
120 
SetDefaultDisplayId(DisplayId defaultDisplayId)121 void DisplayGroupInfo::SetDefaultDisplayId(DisplayId defaultDisplayId)
122 {
123     defaultDisplayId_ = defaultDisplayId;
124 }
125 
GetDisplayRotation(DisplayId displayId) const126 Rotation DisplayGroupInfo::GetDisplayRotation(DisplayId displayId) const
127 {
128     Rotation rotation = Rotation::ROTATION_0;
129     if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) {
130         auto& displayInfo = displayInfosMap_[displayId];
131         rotation = displayInfo->GetRotation();
132     }
133     return rotation;
134 }
135 
GetDisplayStateChangeType(DisplayId displayId) const136 DisplayStateChangeType DisplayGroupInfo::GetDisplayStateChangeType(DisplayId displayId) const
137 {
138     DisplayStateChangeType type = DisplayStateChangeType::UNKNOWN;
139     if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) {
140         auto& displayInfo = displayInfosMap_[displayId];
141         type = displayInfo->GetDisplayStateChangeType();
142     }
143     return type;
144 }
145 
GetDisplayVirtualPixelRatio(DisplayId displayId) const146 float DisplayGroupInfo::GetDisplayVirtualPixelRatio(DisplayId displayId) const
147 {
148     float vpr = 1.0;
149     if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) {
150         auto& displayInfo = displayInfosMap_[displayId];
151         vpr = displayInfo->GetVirtualPixelRatio();
152     }
153     return vpr;
154 }
155 
GetAllDisplayRects() const156 std::map<DisplayId, Rect> DisplayGroupInfo::GetAllDisplayRects() const
157 {
158     std::map<DisplayId, Rect> displayRectMap;
159     for (auto elem : displayInfosMap_) {
160         auto& displayInfo = elem.second;
161         Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(),
162             displayInfo->GetWidth(), displayInfo->GetHeight() };
163         displayRectMap.insert(std::make_pair(elem.first, displayRect));
164     }
165     return displayRectMap;
166 }
167 
GetDisplayRect(DisplayId displayId) const168 Rect DisplayGroupInfo::GetDisplayRect(DisplayId displayId) const
169 {
170     Rect rect;
171     if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) {
172         auto& displayInfo = displayInfosMap_[displayId];
173         rect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(),
174             displayInfo->GetWidth(), displayInfo->GetHeight() };
175     }
176     return rect;
177 }
178 
GetDisplayInfo(DisplayId displayId) const179 sptr<DisplayInfo> DisplayGroupInfo::GetDisplayInfo(DisplayId displayId) const
180 {
181     if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) {
182         return displayInfosMap_[displayId];
183     }
184     return nullptr;
185 }
186 
GetDefaultDisplayInfo() const187 sptr<DisplayInfo> DisplayGroupInfo::GetDefaultDisplayInfo() const
188 {
189     if (displayInfosMap_.find(defaultDisplayId_) != displayInfosMap_.end()) {
190         return displayInfosMap_[defaultDisplayId_];
191     }
192     return nullptr;
193 }
194 
UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const195 void DisplayGroupInfo::UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const
196 {
197     DisplayId displayId = displayInfo->GetDisplayId();
198     if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) {
199         displayInfosMap_[displayId] = displayInfo;
200         WLOGFD("Update displayInfo");
201     }
202 }
203 
GetAllDisplayInfo() const204 std::vector<sptr<DisplayInfo>> DisplayGroupInfo::GetAllDisplayInfo() const
205 {
206     std::vector<sptr<DisplayInfo>> displayInfos;
207     for (auto& iter : displayInfosMap_) {
208         displayInfos.push_back(iter.second);
209     }
210     return displayInfos;
211 }
212 
GetAllDisplayIds() const213 std::vector<DisplayId> DisplayGroupInfo::GetAllDisplayIds() const
214 {
215     std::vector<DisplayId> displayIds;
216     for (auto& iter : displayInfosMap_) {
217         displayIds.push_back(iter.first);
218     }
219     return displayIds;
220 }
221 
GetLeftDisplayId() const222 DisplayId DisplayGroupInfo::GetLeftDisplayId() const
223 {
224     return leftDisplayId_;
225 }
226 
GetRightDisplayId() const227 DisplayId DisplayGroupInfo::GetRightDisplayId() const
228 {
229     return rightDisplayId_;
230 }
231 
GetDefaultDisplayId() const232 DisplayId DisplayGroupInfo::GetDefaultDisplayId() const
233 {
234     return defaultDisplayId_;
235 }
236 } // namespace Rosen
237 } // namespace OHOS
238