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 #include "display_manager_adapter_impl.h"
16
17 #include <cmath>
18 #include "display_info.h"
19 #include "nweb_log.h"
20 #include "syspara/parameters.h"
21 #include "oh_display_manager.h"
22 #include "oh_display_info.h"
23
24 using namespace OHOS::Rosen;
25 using namespace OHOS::NWeb;
26
27 namespace OHOS::NWeb {
28 constexpr float EPS = 0.0001f;
29
DisplayListenerAdapterImpl(std::shared_ptr<DisplayListenerAdapter> listener)30 DisplayListenerAdapterImpl::DisplayListenerAdapterImpl(
31 std::shared_ptr<DisplayListenerAdapter> listener) : listener_(listener) {}
32
OnCreate(DisplayId id)33 void DisplayListenerAdapterImpl::OnCreate(DisplayId id)
34 {
35 if (listener_ != nullptr) {
36 listener_->OnCreate(id);
37 }
38 }
39
OnDestroy(DisplayId id)40 void DisplayListenerAdapterImpl::OnDestroy(DisplayId id)
41 {
42 if (listener_ != nullptr) {
43 listener_->OnDestroy(id);
44 }
45 }
46
OnChange(DisplayId id)47 void DisplayListenerAdapterImpl::OnChange(DisplayId id)
48 {
49 if (CheckOnlyRefreshRateDecreased(id)) {
50 return;
51 }
52 if (listener_ != nullptr) {
53 listener_->OnChange(id);
54 }
55 }
56
CheckOnlyRefreshRateDecreased(DisplayId id)57 bool DisplayListenerAdapterImpl::CheckOnlyRefreshRateDecreased(DisplayId id)
58 {
59 if (id != DisplayManager::GetInstance().GetDefaultDisplayId()) {
60 return false;
61 }
62 auto displayPtr = DisplayManager::GetInstance().GetDefaultDisplay();
63 if (!displayPtr) {
64 return false;
65 }
66 auto displayInfo = displayPtr->GetDisplayInfo();
67 if (!displayInfo) {
68 return false;
69 }
70 auto nwebDisplayInfo = ConvertDisplayInfo(*displayInfo);
71 if (nwebDisplayInfo == cachedDisplayedInfo_ &&
72 nwebDisplayInfo.refreshRate_ != cachedDisplayedInfo_.refreshRate_) {
73 WVLOG_I("refresh rate change is intercepted, previous refresh rate: %{public}u, after: %{public}u",
74 cachedDisplayedInfo_.refreshRate_, nwebDisplayInfo.refreshRate_);
75 cachedDisplayedInfo_ = nwebDisplayInfo;
76 return true;
77 }
78 cachedDisplayedInfo_ = nwebDisplayInfo;
79 return false;
80 }
81
ConvertDisplayInfo(const OHOS::Rosen::DisplayInfo & info)82 OHOS::NWeb::DisplayInfo DisplayListenerAdapterImpl::ConvertDisplayInfo(
83 const OHOS::Rosen::DisplayInfo& info)
84 {
85 OHOS::NWeb::DisplayInfo displayInfo = OHOS::NWeb::DisplayInfo{};
86 displayInfo.width_ = info.GetWidth();
87 displayInfo.height_ = info.GetHeight();
88 displayInfo.refreshRate_ = info.GetRefreshRate();
89 displayInfo.virtualPixelRatio_ = info.GetVirtualPixelRatio();
90 displayInfo.xDpi_ = info.GetXDpi();
91 displayInfo.yDpi_ = info.GetYDpi();
92 displayInfo.rotationType_ = info.GetRotation();
93 displayInfo.orientationType_ = info.GetOrientation();
94 displayInfo.displayOrientation_ = info.GetDisplayOrientation();
95 return displayInfo;
96 }
97
FoldStatusListenerAdapterImpl(std::shared_ptr<FoldStatusListenerAdapter> listener)98 FoldStatusListenerAdapterImpl::FoldStatusListenerAdapterImpl(
99 std::shared_ptr<FoldStatusListenerAdapter> listener) : listener_(listener) {}
100
ConvertFoldStatus(NativeDisplayManager_FoldDisplayMode displayMode)101 OHOS::NWeb::FoldStatus FoldStatusListenerAdapterImpl::ConvertFoldStatus(
102 NativeDisplayManager_FoldDisplayMode displayMode)
103 {
104 switch (displayMode) {
105 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_FULL:
106 return OHOS::NWeb::FoldStatus::FULL;
107 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_MAIN:
108 return OHOS::NWeb::FoldStatus::MAIN;
109 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_SUB:
110 return OHOS::NWeb::FoldStatus::SUB;
111 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_COORDINATION:
112 return OHOS::NWeb::FoldStatus::COORDINATION;
113 default:
114 return OHOS::NWeb::FoldStatus::UNKNOWN;
115 }
116 }
117
OnFoldStatusChanged(NativeDisplayManager_FoldDisplayMode displayMode)118 void FoldStatusListenerAdapterImpl::OnFoldStatusChanged(NativeDisplayManager_FoldDisplayMode displayMode)
119 {
120 if (listener_ != nullptr) {
121 listener_->OnFoldStatusChanged(ConvertFoldStatus(displayMode));
122 }
123 }
124
DisplayAdapterImpl(sptr<OHOS::Rosen::Display> display)125 DisplayAdapterImpl::DisplayAdapterImpl(sptr<OHOS::Rosen::Display> display)
126 : display_(display) {}
127
ConvertRotationType(OHOS::Rosen::Rotation type)128 OHOS::NWeb::RotationType DisplayAdapterImpl::ConvertRotationType(OHOS::Rosen::Rotation type)
129 {
130 switch (type) {
131 case OHOS::Rosen::Rotation::ROTATION_0:
132 return OHOS::NWeb::RotationType::ROTATION_0;
133 case OHOS::Rosen::Rotation::ROTATION_90:
134 return OHOS::NWeb::RotationType::ROTATION_90;
135 case OHOS::Rosen::Rotation::ROTATION_180:
136 return OHOS::NWeb::RotationType::ROTATION_180;
137 case OHOS::Rosen::Rotation::ROTATION_270:
138 return OHOS::NWeb::RotationType::ROTATION_270;
139 default:
140 return OHOS::NWeb::RotationType::ROTATION_BUTT;
141 }
142 }
143
ConvertOrientationType(OHOS::Rosen::Orientation type)144 OHOS::NWeb::OrientationType DisplayAdapterImpl::ConvertOrientationType(OHOS::Rosen::Orientation type)
145 {
146 switch (type) {
147 case OHOS::Rosen::Orientation::UNSPECIFIED:
148 return OHOS::NWeb::OrientationType::UNSPECIFIED;
149 case OHOS::Rosen::Orientation::VERTICAL:
150 return OHOS::NWeb::OrientationType::VERTICAL;
151 case OHOS::Rosen::Orientation::HORIZONTAL:
152 return OHOS::NWeb::OrientationType::HORIZONTAL;
153 case OHOS::Rosen::Orientation::REVERSE_VERTICAL:
154 return OHOS::NWeb::OrientationType::REVERSE_VERTICAL;
155 case OHOS::Rosen::Orientation::REVERSE_HORIZONTAL:
156 return OHOS::NWeb::OrientationType::REVERSE_HORIZONTAL;
157 case OHOS::Rosen::Orientation::SENSOR:
158 return OHOS::NWeb::OrientationType::SENSOR;
159 case OHOS::Rosen::Orientation::SENSOR_VERTICAL:
160 return OHOS::NWeb::OrientationType::SENSOR_VERTICAL;
161 case OHOS::Rosen::Orientation::SENSOR_HORIZONTAL:
162 return OHOS::NWeb::OrientationType::SENSOR_HORIZONTAL;
163 default:
164 return OHOS::NWeb::OrientationType::BUTT;
165 }
166 }
167
ConvertDisplayOrientationType(OHOS::Rosen::DisplayOrientation type)168 OHOS::NWeb::DisplayOrientation DisplayAdapterImpl::ConvertDisplayOrientationType(OHOS::Rosen::DisplayOrientation type)
169 {
170 switch (type) {
171 case OHOS::Rosen::DisplayOrientation::PORTRAIT:
172 return OHOS::NWeb::DisplayOrientation::PORTRAIT;
173 case OHOS::Rosen::DisplayOrientation::LANDSCAPE:
174 return OHOS::NWeb::DisplayOrientation::LANDSCAPE;
175 case OHOS::Rosen::DisplayOrientation::PORTRAIT_INVERTED:
176 return OHOS::NWeb::DisplayOrientation::PORTRAIT_INVERTED;
177 case OHOS::Rosen::DisplayOrientation::LANDSCAPE_INVERTED:
178 return OHOS::NWeb::DisplayOrientation::LANDSCAPE_INVERTED;
179 default:
180 return OHOS::NWeb::DisplayOrientation::UNKNOWN;
181 }
182 }
183
184
ConvertFoldStatus(NativeDisplayManager_FoldDisplayMode displayMode)185 OHOS::NWeb::FoldStatus DisplayAdapterImpl::ConvertFoldStatus(NativeDisplayManager_FoldDisplayMode displayMode)
186 {
187 switch (displayMode) {
188 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_FULL:
189 return OHOS::NWeb::FoldStatus::FULL;
190 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_MAIN:
191 return OHOS::NWeb::FoldStatus::MAIN;
192 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_SUB:
193 return OHOS::NWeb::FoldStatus::SUB;
194 case DISPLAY_MANAGER_FOLD_DISPLAY_MODE_COORDINATION:
195 return OHOS::NWeb::FoldStatus::COORDINATION;
196 default:
197 return OHOS::NWeb::FoldStatus::UNKNOWN;
198 }
199 }
200
ConvertDisplayState(OHOS::Rosen::DisplayState state)201 OHOS::NWeb::DisplayState DisplayAdapterImpl::ConvertDisplayState(OHOS::Rosen::DisplayState state)
202 {
203 switch (state) {
204 case OHOS::Rosen::DisplayState::OFF:
205 return OHOS::NWeb::DisplayState::OFF;
206 case OHOS::Rosen::DisplayState::ON:
207 return OHOS::NWeb::DisplayState::ON;
208 case OHOS::Rosen::DisplayState::DOZE:
209 return OHOS::NWeb::DisplayState::DOZE;
210 case OHOS::Rosen::DisplayState::DOZE_SUSPEND:
211 return OHOS::NWeb::DisplayState::DOZE_SUSPEND;
212 case OHOS::Rosen::DisplayState::VR:
213 return OHOS::NWeb::DisplayState::VR;
214 case OHOS::Rosen::DisplayState::ON_SUSPEND:
215 return OHOS::NWeb::DisplayState::ON_SUSPEND;
216 default:
217 return OHOS::NWeb::DisplayState::UNKNOWN;
218 }
219 }
220
ConvertDisplaySourceMode(OHOS::Rosen::DisplaySourceMode mode)221 OHOS::NWeb::DisplaySourceMode DisplayAdapterImpl::ConvertDisplaySourceMode(OHOS::Rosen::DisplaySourceMode mode)
222 {
223 switch (mode) {
224 case OHOS::Rosen::DisplaySourceMode::MAIN:
225 return OHOS::NWeb::DisplaySourceMode::MAIN;
226 case OHOS::Rosen::DisplaySourceMode::MIRROR:
227 return OHOS::NWeb::DisplaySourceMode::MIRROR;
228 case OHOS::Rosen::DisplaySourceMode::EXTEND:
229 return OHOS::NWeb::DisplaySourceMode::EXTEND;
230 case OHOS::Rosen::DisplaySourceMode::ALONE:
231 return OHOS::NWeb::DisplaySourceMode::ALONE;
232 default:
233 return OHOS::NWeb::DisplaySourceMode::NONE;
234 }
235 }
236
GetId()237 DisplayId DisplayAdapterImpl::GetId()
238 {
239 if (display_ != nullptr) {
240 return display_->GetId();
241 }
242 return static_cast<DisplayId>(-1);
243 }
244
GetWidth()245 int32_t DisplayAdapterImpl::GetWidth()
246 {
247 if (display_ != nullptr) {
248 return display_->GetWidth();
249 }
250 return -1;
251 }
252
GetHeight()253 int32_t DisplayAdapterImpl::GetHeight()
254 {
255 if (display_ != nullptr) {
256 return display_->GetHeight();
257 }
258 return -1;
259 }
260
GetVirtualPixelRatio()261 float DisplayAdapterImpl::GetVirtualPixelRatio()
262 {
263 if (display_ != nullptr) {
264 return display_->GetVirtualPixelRatio();
265 }
266 return -1;
267 }
268
GetRotation()269 RotationType DisplayAdapterImpl::GetRotation()
270 {
271 if (display_ != nullptr) {
272 return ConvertRotationType(display_->GetRotation());
273 }
274 return RotationType::ROTATION_BUTT;
275 }
276
GetOrientation()277 OrientationType DisplayAdapterImpl::GetOrientation()
278 {
279 if (display_ != nullptr) {
280 return ConvertOrientationType(display_->GetOrientation());
281 }
282 return OrientationType::BUTT;
283 }
284
GetDpi()285 int32_t DisplayAdapterImpl::GetDpi()
286 {
287 int32_t ppi = -1;
288 if (!display_) {
289 return ppi;
290 }
291 auto displayInfo = display_->GetDisplayInfo();
292 if (!displayInfo) {
293 return ppi;
294 }
295 float xDpi = displayInfo->GetXDpi();
296 float yDpi = displayInfo->GetYDpi();
297 if (xDpi < EPS || yDpi < EPS) {
298 return ppi;
299 }
300
301 auto screenLength = sqrt(pow(displayInfo->GetWidth(), 2) + pow(displayInfo->GetHeight(), 2));
302 auto phyScreenLength = sqrt(pow(displayInfo->GetWidth()/xDpi, 2) +
303 pow(displayInfo->GetHeight()/yDpi, 2));
304 if (phyScreenLength < EPS) {
305 return ppi;
306 }
307 ppi = screenLength / phyScreenLength;
308 WVLOG_D("dpi: %{public}d, xdpi: %{public}f,ydpi: %{public}f, width: %{public}d, height: %{public}d, "\
309 "phyScreenLength: %{public}f", ppi, displayInfo->GetXDpi(), displayInfo->GetYDpi(),
310 displayInfo->GetWidth(), displayInfo->GetHeight(), phyScreenLength);
311
312 return ppi;
313 }
314
GetDisplayOrientation()315 DisplayOrientation DisplayAdapterImpl::GetDisplayOrientation()
316 {
317 if (display_ != nullptr) {
318 auto displayInfo = display_->GetDisplayInfo();
319 if (displayInfo != nullptr) {
320 return ConvertDisplayOrientationType(displayInfo->GetDisplayOrientation());
321 }
322 }
323 return DisplayOrientation::UNKNOWN;
324 }
325
GetFoldStatus()326 FoldStatus DisplayAdapterImpl::GetFoldStatus()
327 {
328 NativeDisplayManager_FoldDisplayMode displayMode =
329 NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_UNKNOWN;
330 OH_NativeDisplayManager_GetFoldDisplayMode(&displayMode);
331 return ConvertFoldStatus(displayMode);
332 }
333
IsFoldable()334 bool DisplayAdapterImpl::IsFoldable()
335 {
336 return OH_NativeDisplayManager_IsFoldable();
337 }
338
GetName()339 std::string DisplayAdapterImpl::GetName()
340 {
341 if (display_ != nullptr) {
342 auto displayInfo = display_->GetDisplayInfo();
343 if (displayInfo != nullptr) {
344 return displayInfo->GetName();
345 }
346 }
347 return "";
348 }
349
GetAvailableWidth()350 int32_t DisplayAdapterImpl::GetAvailableWidth()
351 {
352 if (display_ != nullptr) {
353 auto displayInfo = display_->GetDisplayInfo();
354 if (displayInfo != nullptr) {
355 return displayInfo->GetAvailableWidth();
356 }
357 }
358 return 0;
359 }
360
GetAvailableHeight()361 int32_t DisplayAdapterImpl::GetAvailableHeight()
362 {
363 if (display_ != nullptr) {
364 auto displayInfo = display_->GetDisplayInfo();
365 if (displayInfo != nullptr) {
366 return displayInfo->GetAvailableHeight();
367 }
368 }
369 return 0;
370 }
371
GetAliveStatus()372 bool DisplayAdapterImpl::GetAliveStatus()
373 {
374 if (display_ != nullptr) {
375 auto displayInfo = display_->GetDisplayInfo();
376 if (displayInfo != nullptr) {
377 return displayInfo->GetAliveStatus();
378 }
379 }
380 return true;
381 }
382
GetDisplayState()383 DisplayState DisplayAdapterImpl::GetDisplayState()
384 {
385 if (display_ != nullptr) {
386 auto displayInfo = display_->GetDisplayInfo();
387 if (displayInfo != nullptr) {
388 return ConvertDisplayState(displayInfo->GetDisplayState());
389 }
390 }
391 return DisplayState::UNKNOWN;
392 }
393
GetDensityDpi()394 int32_t DisplayAdapterImpl::GetDensityDpi()
395 {
396 if (display_ != nullptr) {
397 auto displayInfo = display_->GetDisplayInfo();
398 if (displayInfo != nullptr) {
399 return displayInfo->GetDpi();
400 }
401 }
402 return 0;
403 }
404
GetX()405 int32_t DisplayAdapterImpl::GetX()
406 {
407 if (display_ != nullptr) {
408 auto displayInfo = display_->GetDisplayInfo();
409 if (displayInfo != nullptr) {
410 return displayInfo->GetX();
411 }
412 }
413 return 0;
414 }
415
GetY()416 int32_t DisplayAdapterImpl::GetY()
417 {
418 if (display_ != nullptr) {
419 auto displayInfo = display_->GetDisplayInfo();
420 if (displayInfo != nullptr) {
421 return displayInfo->GetY();
422 }
423 }
424 return 0;
425 }
426
GetDisplaySourceMode()427 DisplaySourceMode DisplayAdapterImpl::GetDisplaySourceMode()
428 {
429 if (display_ != nullptr) {
430 auto displayInfo = display_->GetDisplayInfo();
431 if (displayInfo != nullptr) {
432 return ConvertDisplaySourceMode(displayInfo->GetDisplaySourceMode());
433 }
434 }
435 return DisplaySourceMode::NONE;
436 }
437
GetPhysicalWidth()438 int32_t DisplayAdapterImpl::GetPhysicalWidth()
439 {
440 if (display_ != nullptr) {
441 auto displayInfo = display_->GetDisplayInfo();
442 if (displayInfo != nullptr) {
443 return displayInfo->GetPhysicalWidth();
444 }
445 }
446 return 0;
447 }
448
GetPhysicalHeight()449 int32_t DisplayAdapterImpl::GetPhysicalHeight()
450 {
451 if (display_ != nullptr) {
452 auto displayInfo = display_->GetDisplayInfo();
453 if (displayInfo != nullptr) {
454 return displayInfo->GetPhysicalHeight();
455 }
456 }
457 return 0;
458 }
459
GetDefaultVirtualPixelRatio()460 float DisplayAdapterImpl::GetDefaultVirtualPixelRatio()
461 {
462 if (display_ != nullptr) {
463 auto displayInfo = display_->GetDisplayInfo();
464 if (displayInfo != nullptr) {
465 return displayInfo->GetDefaultVirtualPixelRatio();
466 }
467 }
468 return 0;
469 }
470
GetDefaultDisplayId()471 DisplayId DisplayManagerAdapterImpl::GetDefaultDisplayId()
472 {
473 return DisplayManager::GetInstance().GetDefaultDisplayId();
474 }
475
GetDefaultDisplay()476 std::shared_ptr<DisplayAdapter> DisplayManagerAdapterImpl::GetDefaultDisplay()
477 {
478 sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplay();
479 return std::make_shared<DisplayAdapterImpl>(display);
480 }
481
RegisterDisplayListener(std::shared_ptr<DisplayListenerAdapter> listener)482 uint32_t DisplayManagerAdapterImpl::RegisterDisplayListener(
483 std::shared_ptr<DisplayListenerAdapter> listener)
484 {
485 static uint32_t count = 1;
486 sptr<DisplayListenerAdapterImpl> reg =
487 new (std::nothrow) DisplayListenerAdapterImpl(listener);
488 if (reg == nullptr) {
489 return false;
490 }
491
492 uint32_t id = count++;
493 if (count == 0) {
494 count++;
495 }
496
497 reg_.emplace(std::make_pair(id, reg));
498 if (DisplayManager::GetInstance().RegisterDisplayListener(reg) == DMError::DM_OK) {
499 return id;
500 } else {
501 return 0;
502 }
503 }
504
UnregisterDisplayListener(uint32_t id)505 bool DisplayManagerAdapterImpl::UnregisterDisplayListener(uint32_t id)
506 {
507 ListenerMap::iterator iter = reg_.find(id);
508 if (iter == reg_.end()) {
509 return false;
510 }
511 if (DisplayManager::GetInstance().UnregisterDisplayListener(iter->second) == DMError::DM_OK) {
512 reg_.erase(iter);
513 return true;
514 }
515 return false;
516 }
517
IsDefaultPortrait()518 bool DisplayManagerAdapterImpl::IsDefaultPortrait()
519 {
520 std::string deviceType = OHOS::system::GetDeviceType();
521 return deviceType == "phone" || deviceType == "tablet" || deviceType == "default";
522 }
523
524 FoldStatusListenerMap DisplayManagerAdapterImpl::foldStatusReg_;
525 std::mutex DisplayManagerAdapterImpl::foldStatusRegMutex;
526
FoldChangeCallBack(NativeDisplayManager_FoldDisplayMode displayMode)527 void FoldChangeCallBack(NativeDisplayManager_FoldDisplayMode displayMode)
528 {
529 std::lock_guard<std::mutex> lock(DisplayManagerAdapterImpl::foldStatusRegMutex);
530 for (auto& iter : DisplayManagerAdapterImpl::foldStatusReg_) {
531 iter.second->OnFoldStatusChanged(displayMode);
532 }
533 }
534
RegisterFoldStatusListener(std::shared_ptr<FoldStatusListenerAdapter> listener)535 uint32_t DisplayManagerAdapterImpl::RegisterFoldStatusListener(
536 std::shared_ptr<FoldStatusListenerAdapter> listener)
537 {
538 sptr<FoldStatusListenerAdapterImpl> reg =
539 new (std::nothrow) FoldStatusListenerAdapterImpl(listener);
540 if (reg == nullptr) {
541 return 0;
542 }
543
544 std::lock_guard<std::mutex> lock(foldStatusRegMutex);
545 uint32_t id = 1;
546 if (OH_NativeDisplayManager_RegisterFoldDisplayModeChangeListener(FoldChangeCallBack, &id) ==
547 NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
548 foldStatusReg_.emplace(std::make_pair(id, reg));
549 return id;
550 } else {
551 return 0;
552 }
553 }
554
UnregisterFoldStatusListener(uint32_t id)555 bool DisplayManagerAdapterImpl::UnregisterFoldStatusListener(uint32_t id)
556 {
557 std::lock_guard<std::mutex> lock(foldStatusRegMutex);
558 FoldStatusListenerMap::iterator iter = foldStatusReg_.find(id);
559 if (iter == foldStatusReg_.end()) {
560 return false;
561 }
562 if (OH_NativeDisplayManager_UnregisterFoldDisplayModeChangeListener(
563 id) == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
564 foldStatusReg_.erase(iter);
565 return true;
566 }
567 return false;
568 }
569
GetPrimaryDisplay()570 std::shared_ptr<DisplayAdapter> DisplayManagerAdapterImpl::GetPrimaryDisplay()
571 {
572 sptr<Display> display = DisplayManager::GetInstance().GetPrimaryDisplaySync();
573 return std::make_shared<DisplayAdapterImpl>(display);
574 }
575
GetAllDisplays()576 std::vector<std::shared_ptr<DisplayAdapter>> DisplayManagerAdapterImpl::GetAllDisplays()
577 {
578 std::vector<sptr<Display>> displays = DisplayManager::GetInstance().GetAllDisplays();
579 std::vector<std::shared_ptr<DisplayAdapter>> displayAdapterList;
580 for (auto& display : displays) {
581 std::shared_ptr<DisplayAdapterImpl> displayAdapter = std::make_shared<DisplayAdapterImpl>(display);
582 if (!displayAdapter) {
583 WVLOG_E("DisplayManagerAdapterImpl::GetAllDisplays create displayAdapter failed");
584 return displayAdapterList;
585 }
586 displayAdapterList.emplace_back(displayAdapter);
587 }
588 return displayAdapterList;
589 }
590 }