• 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 #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_I("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     if (!OH_NativeDisplayManager_IsFoldable()) {
329         return OHOS::NWeb::FoldStatus::UNKNOWN;
330     }
331     NativeDisplayManager_FoldDisplayMode displayMode =
332         NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_UNKNOWN;
333     OH_NativeDisplayManager_GetFoldDisplayMode(&displayMode);
334     return ConvertFoldStatus(displayMode);
335 }
336 
IsFoldable()337 bool DisplayAdapterImpl::IsFoldable()
338 {
339     return OH_NativeDisplayManager_IsFoldable();
340 }
341 
GetName()342 std::string DisplayAdapterImpl::GetName()
343 {
344     if (display_ != nullptr) {
345         auto displayInfo = display_->GetDisplayInfo();
346         if (displayInfo != nullptr) {
347             return displayInfo->GetName();
348         }
349     }
350     return "";
351 }
352 
GetAvailableWidth()353 int32_t DisplayAdapterImpl::GetAvailableWidth()
354 {
355     if (display_ != nullptr) {
356         auto displayInfo = display_->GetDisplayInfo();
357         if (displayInfo != nullptr) {
358             return displayInfo->GetAvailableWidth();
359         }
360     }
361     return 0;
362 }
363 
GetAvailableHeight()364 int32_t DisplayAdapterImpl::GetAvailableHeight()
365 {
366     if (display_ != nullptr) {
367         auto displayInfo = display_->GetDisplayInfo();
368         if (displayInfo != nullptr) {
369             return displayInfo->GetAvailableHeight();
370         }
371     }
372     return 0;
373 }
374 
GetAliveStatus()375 bool DisplayAdapterImpl::GetAliveStatus()
376 {
377     if (display_ != nullptr) {
378         auto displayInfo = display_->GetDisplayInfo();
379         if (displayInfo != nullptr) {
380             return displayInfo->GetAliveStatus();
381         }
382     }
383     return true;
384 }
385 
GetDisplayState()386 DisplayState DisplayAdapterImpl::GetDisplayState()
387 {
388     if (display_ != nullptr) {
389         auto displayInfo = display_->GetDisplayInfo();
390         if (displayInfo != nullptr) {
391             return ConvertDisplayState(displayInfo->GetDisplayState());
392         }
393     }
394     return DisplayState::UNKNOWN;
395 }
396 
GetDensityDpi()397 int32_t DisplayAdapterImpl::GetDensityDpi()
398 {
399     if (display_ != nullptr) {
400         auto displayInfo = display_->GetDisplayInfo();
401         if (displayInfo != nullptr) {
402             return displayInfo->GetDpi();
403         }
404     }
405     return 0;
406 }
407 
GetX()408 int32_t DisplayAdapterImpl::GetX()
409 {
410     if (display_ != nullptr) {
411         auto displayInfo = display_->GetDisplayInfo();
412         if (displayInfo != nullptr) {
413             return displayInfo->GetX();
414         }
415     }
416     return 0;
417 }
418 
GetY()419 int32_t DisplayAdapterImpl::GetY()
420 {
421     if (display_ != nullptr) {
422         auto displayInfo = display_->GetDisplayInfo();
423         if (displayInfo != nullptr) {
424             return displayInfo->GetY();
425         }
426     }
427     return 0;
428 }
429 
GetDisplaySourceMode()430 DisplaySourceMode DisplayAdapterImpl::GetDisplaySourceMode()
431 {
432     if (display_ != nullptr) {
433         auto displayInfo = display_->GetDisplayInfo();
434         if (displayInfo != nullptr) {
435             return ConvertDisplaySourceMode(displayInfo->GetDisplaySourceMode());
436         }
437     }
438     return DisplaySourceMode::NONE;
439 }
440 
GetPhysicalWidth()441 int32_t DisplayAdapterImpl::GetPhysicalWidth()
442 {
443     if (display_ != nullptr) {
444         auto displayInfo = display_->GetDisplayInfo();
445         if (displayInfo != nullptr) {
446             return displayInfo->GetPhysicalWidth();
447         }
448     }
449     return 0;
450 }
451 
GetPhysicalHeight()452 int32_t DisplayAdapterImpl::GetPhysicalHeight()
453 {
454     if (display_ != nullptr) {
455         auto displayInfo = display_->GetDisplayInfo();
456         if (displayInfo != nullptr) {
457             return displayInfo->GetPhysicalHeight();
458         }
459     }
460     return 0;
461 }
462 
GetDefaultVirtualPixelRatio()463 float DisplayAdapterImpl::GetDefaultVirtualPixelRatio()
464 {
465     if (display_ != nullptr) {
466         auto displayInfo = display_->GetDisplayInfo();
467         if (displayInfo != nullptr) {
468             return displayInfo->GetDefaultVirtualPixelRatio();
469         }
470     }
471     return 0;
472 }
473 
GetDefaultDisplayId()474 DisplayId DisplayManagerAdapterImpl::GetDefaultDisplayId()
475 {
476     return DisplayManager::GetInstance().GetDefaultDisplayId();
477 }
478 
GetDefaultDisplay()479 std::shared_ptr<DisplayAdapter> DisplayManagerAdapterImpl::GetDefaultDisplay()
480 {
481     sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplay();
482     return std::make_shared<DisplayAdapterImpl>(display);
483 }
484 
RegisterDisplayListener(std::shared_ptr<DisplayListenerAdapter> listener)485 uint32_t DisplayManagerAdapterImpl::RegisterDisplayListener(
486     std::shared_ptr<DisplayListenerAdapter> listener)
487 {
488     static uint32_t count = 1;
489     sptr<DisplayListenerAdapterImpl> reg =
490         new (std::nothrow) DisplayListenerAdapterImpl(listener);
491     if (reg == nullptr) {
492         return false;
493     }
494 
495     uint32_t id = count++;
496     if (count == 0) {
497         count++;
498     }
499 
500     reg_.emplace(std::make_pair(id, reg));
501     if (DisplayManager::GetInstance().RegisterDisplayListener(reg) == DMError::DM_OK) {
502         return id;
503     } else {
504         return 0;
505     }
506 }
507 
UnregisterDisplayListener(uint32_t id)508 bool DisplayManagerAdapterImpl::UnregisterDisplayListener(uint32_t id)
509 {
510     ListenerMap::iterator iter = reg_.find(id);
511     if (iter == reg_.end()) {
512         return false;
513     }
514     if (DisplayManager::GetInstance().UnregisterDisplayListener(iter->second) == DMError::DM_OK) {
515         reg_.erase(iter);
516         return true;
517     }
518     return false;
519 }
520 
IsDefaultPortrait()521 bool DisplayManagerAdapterImpl::IsDefaultPortrait()
522 {
523     std::string deviceType = OHOS::system::GetDeviceType();
524     return deviceType == "phone" || deviceType == "tablet" || deviceType == "default";
525 }
526 
527 FoldStatusListenerMap DisplayManagerAdapterImpl::foldStatusReg_;
528 
FoldChangeCallBack(NativeDisplayManager_FoldDisplayMode displayMode)529 void FoldChangeCallBack(NativeDisplayManager_FoldDisplayMode displayMode)
530 {
531     for (auto& iter : DisplayManagerAdapterImpl::foldStatusReg_) {
532         iter.second->OnFoldStatusChanged(displayMode);
533     }
534 }
535 
RegisterFoldStatusListener(std::shared_ptr<FoldStatusListenerAdapter> listener)536 uint32_t DisplayManagerAdapterImpl::RegisterFoldStatusListener(
537     std::shared_ptr<FoldStatusListenerAdapter> listener)
538 {
539     sptr<FoldStatusListenerAdapterImpl> reg =
540         new (std::nothrow) FoldStatusListenerAdapterImpl(listener);
541     if (reg == nullptr) {
542         return false;
543     }
544 
545     uint32_t id = 1;
546     if (OH_NativeDisplayManager_RegisterFoldDisplayModeChangeListener(
547         FoldChangeCallBack, &id) == 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     FoldStatusListenerMap::iterator iter = foldStatusReg_.find(id);
558     if (iter == foldStatusReg_.end()) {
559         return false;
560     }
561     if (OH_NativeDisplayManager_UnregisterFoldDisplayModeChangeListener(
562             id) == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
563         foldStatusReg_.erase(iter);
564         return true;
565     }
566     return false;
567 }
568 
GetPrimaryDisplay()569 std::shared_ptr<DisplayAdapter> DisplayManagerAdapterImpl::GetPrimaryDisplay()
570 {
571     sptr<Display> display = DisplayManager::GetInstance().GetPrimaryDisplaySync();
572     return std::make_shared<DisplayAdapterImpl>(display);
573 }
574 
GetAllDisplays()575 std::vector<std::shared_ptr<DisplayAdapter>> DisplayManagerAdapterImpl::GetAllDisplays()
576 {
577     std::vector<sptr<Display>> displays = DisplayManager::GetInstance().GetAllDisplays();
578     std::vector<std::shared_ptr<DisplayAdapter>> displayAdapterList;
579     for (auto& display : displays) {
580         std::shared_ptr<DisplayAdapterImpl> displayAdapter = std::make_shared<DisplayAdapterImpl>(display);
581         if (!displayAdapter) {
582             WVLOG_E("DisplayManagerAdapterImpl::GetAllDisplays create displayAdapter failed");
583             return displayAdapterList;
584         }
585         displayAdapterList.emplace_back(displayAdapter);
586     }
587     return displayAdapterList;
588 }
589 }