1 /*
2 * Copyright (c) 2021-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_manager_service.h"
17
18 #include <cinttypes>
19 #include <iservice_registry.h>
20 #include <system_ability_definition.h>
21
22 #include "display_manager_agent_controller.h"
23 #include "transaction/rs_interfaces.h"
24 #include "window_manager_hilog.h"
25 #include "wm_trace.h"
26
27 namespace OHOS::Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerService"};
30 }
31 WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService)
32 const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<DisplayManagerService>());
33
34 #define CHECK_SCREEN_AND_RETURN(ret) \
35 do { \
36 if (screenId == SCREEN_ID_INVALID) { \
37 WLOGFE("screenId invalid"); \
38 return ret; \
39 } \
40 } while (false)
41
DisplayManagerService()42 DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true),
43 abstractDisplayController_(new AbstractDisplayController(mutex_,
44 std::bind(&DisplayManagerService::NotifyDisplayStateChange, this, std::placeholders::_1, std::placeholders::_2))),
45 abstractScreenController_(new AbstractScreenController(mutex_)),
46 displayPowerController_(new DisplayPowerController(mutex_,
47 std::bind(&DisplayManagerService::NotifyDisplayStateChange, this, std::placeholders::_1, std::placeholders::_2)))
48 {
49 }
50
OnStart()51 void DisplayManagerService::OnStart()
52 {
53 WLOGFI("DisplayManagerService::OnStart start");
54 if (!Init()) {
55 WLOGFW("Init failed");
56 return;
57 }
58 }
59
Init()60 bool DisplayManagerService::Init()
61 {
62 WLOGFI("DisplayManagerService::Init start");
63 bool ret = Publish(this);
64 if (!ret) {
65 WLOGFW("DisplayManagerService::Init failed");
66 return false;
67 }
68 abstractScreenController_->Init();
69 abstractDisplayController_->Init(abstractScreenController_);
70 WLOGFI("DisplayManagerService::Init success");
71 return true;
72 }
73
RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)74 void DisplayManagerService::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
75 {
76 displayChangeListener_ = listener;
77 WLOGFI("IDisplayChangeListener registered");
78 }
79
NotifyDisplayStateChange(DisplayId id,DisplayStateChangeType type)80 void DisplayManagerService::NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type)
81 {
82 WLOGFI("DisplayId %{public}" PRIu64"", id);
83 if (displayChangeListener_ != nullptr) {
84 displayChangeListener_->OnDisplayStateChange(id, type);
85 }
86 }
87
GetDefaultDisplayId()88 DisplayId DisplayManagerService::GetDefaultDisplayId()
89 {
90 ScreenId dmsScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
91 WLOGFI("GetDefaultDisplayId %{public}" PRIu64"", dmsScreenId);
92 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplayByScreen(dmsScreenId);
93 if (display == nullptr) {
94 WLOGFE("fail to get displayInfo by id: invalid display");
95 return DISPLAY_ID_INVALID;
96 }
97 return display->GetId();
98 }
99
GetDisplayInfoById(DisplayId displayId)100 sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
101 {
102 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplay(displayId);
103 if (display == nullptr) {
104 WLOGFE("fail to get displayInfo by id: invalid display");
105 return nullptr;
106 }
107 return display->ConvertToDisplayInfo();
108 }
109
GetDisplayInfoByScreen(ScreenId screenId)110 sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoByScreen(ScreenId screenId)
111 {
112 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplayByScreen(screenId);
113 if (display == nullptr) {
114 WLOGFE("fail to get displayInfo by screenId: invalid display");
115 return nullptr;
116 }
117 return display->ConvertToDisplayInfo();
118 }
119
CreateVirtualScreen(VirtualScreenOption option)120 ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option)
121 {
122 WM_SCOPED_TRACE("dms:CreateVirtualScreen(%s)", option.name_.c_str());
123 ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option);
124 CHECK_SCREEN_AND_RETURN(SCREEN_ID_INVALID);
125
126 WLOGFI("DumpScreenInfo after Create VirtualScreen");
127 abstractScreenController_->DumpScreenInfo();
128 return screenId;
129 }
130
DestroyVirtualScreen(ScreenId screenId)131 DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId)
132 {
133 WLOGFI("DestroyVirtualScreen::ScreenId: %{public}" PRIu64 "", screenId);
134 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
135
136 WM_SCOPED_TRACE("dms:DestroyVirtualScreen(%" PRIu64")", screenId);
137 auto rsScreenId = abstractScreenController_->ConvertToRsScreenId(screenId);
138 std::map<ScreenId, std::shared_ptr<RSDisplayNode>>::iterator iter = displayNodeMap_.find(rsScreenId);
139 if (iter == displayNodeMap_.end()) {
140 WLOGFE("DisplayManagerService: displayNode is nullptr");
141 return abstractScreenController_->DestroyVirtualScreen(screenId);
142 }
143 displayNodeMap_[rsScreenId]->RemoveFromTree();
144 WLOGFE("DisplayManagerService: displayNode remove from tree");
145 displayNodeMap_.erase(rsScreenId);
146 auto transactionProxy = RSTransactionProxy::GetInstance();
147 if (transactionProxy != nullptr) {
148 transactionProxy->FlushImplicitTransaction();
149 }
150 return abstractScreenController_->DestroyVirtualScreen(screenId);
151 }
152
SetVirtualScreenSurface(ScreenId screenId,sptr<Surface> surface)153 DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface)
154 {
155 WLOGFI("SetVirtualScreenSurface::ScreenId: %{public}" PRIu64 "", screenId);
156 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
157
158 WM_SCOPED_TRACE("dms:SetVirtualScreenSurface(%" PRIu64")", screenId);
159 return abstractScreenController_->SetVirtualScreenSurface(screenId, surface);
160 }
161
SetOrientation(ScreenId screenId,Orientation orientation)162 bool DisplayManagerService::SetOrientation(ScreenId screenId, Orientation orientation)
163 {
164 WM_SCOPED_TRACE("dms:SetOrientation(%" PRIu64")", screenId);
165 return abstractScreenController_->SetOrientation(screenId, orientation, false);
166 }
167
SetOrientationFromWindow(ScreenId screenId,Orientation orientation)168 bool DisplayManagerService::SetOrientationFromWindow(ScreenId screenId, Orientation orientation)
169 {
170 WM_SCOPED_TRACE("dms:SetOrientationFromWindow(%" PRIu64")", screenId);
171 return abstractScreenController_->SetOrientation(screenId, orientation, true);
172 }
173
GetDisplaySnapshot(DisplayId displayId)174 std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDisplaySnapshot(DisplayId displayId)
175 {
176 WM_SCOPED_TRACE("dms:GetDisplaySnapshot(%" PRIu64")", displayId);
177 std::shared_ptr<Media::PixelMap> screenSnapshot
178 = abstractDisplayController_->GetScreenSnapshot(displayId);
179 return screenSnapshot;
180 }
181
GetRSScreenId(DisplayId displayId) const182 ScreenId DisplayManagerService::GetRSScreenId(DisplayId displayId) const
183 {
184 ScreenId dmsScreenId = GetScreenIdByDisplayId(displayId);
185 return abstractScreenController_->ConvertToRsScreenId(dmsScreenId);
186 }
187
GetScreenSupportedColorGamuts(ScreenId screenId,std::vector<ScreenColorGamut> & colorGamuts)188 DMError DisplayManagerService::GetScreenSupportedColorGamuts(ScreenId screenId,
189 std::vector<ScreenColorGamut>& colorGamuts)
190 {
191 WLOGFI("GetScreenSupportedColorGamuts::ScreenId: %{public}" PRIu64 "", screenId);
192 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
193
194 WM_SCOPED_TRACE("dms:GetScreenSupportedColorGamuts(%" PRIu64")", screenId);
195
196 return abstractScreenController_->GetScreenSupportedColorGamuts(screenId, colorGamuts);
197 }
198
GetScreenColorGamut(ScreenId screenId,ScreenColorGamut & colorGamut)199 DMError DisplayManagerService::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
200 {
201 WLOGFI("GetScreenColorGamut::ScreenId: %{public}" PRIu64 "", screenId);
202 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
203
204 WM_SCOPED_TRACE("dms:GetScreenColorGamut(%" PRIu64")", screenId);
205
206 return abstractScreenController_->GetScreenColorGamut(screenId, colorGamut);
207 }
208
SetScreenColorGamut(ScreenId screenId,int32_t colorGamutIdx)209 DMError DisplayManagerService::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
210 {
211 WLOGFI("SetScreenColorGamut::ScreenId: %{public}" PRIu64 ", colorGamutIdx %{public}d", screenId, colorGamutIdx);
212 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
213
214 WM_SCOPED_TRACE("dms:SetScreenColorGamut(%" PRIu64")", screenId);
215
216 return abstractScreenController_->SetScreenColorGamut(screenId, colorGamutIdx);
217 }
218
GetScreenGamutMap(ScreenId screenId,ScreenGamutMap & gamutMap)219 DMError DisplayManagerService::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
220 {
221 WLOGFI("GetScreenGamutMap::ScreenId: %{public}" PRIu64 "", screenId);
222 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
223
224 WM_SCOPED_TRACE("dms:GetScreenGamutMap(%" PRIu64")", screenId);
225
226 return abstractScreenController_->GetScreenGamutMap(screenId, gamutMap);
227 }
228
SetScreenGamutMap(ScreenId screenId,ScreenGamutMap gamutMap)229 DMError DisplayManagerService::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
230 {
231 WLOGFI("SetScreenGamutMap::ScreenId: %{public}" PRIu64 ", ScreenGamutMap %{public}u",
232 screenId, static_cast<uint32_t>(gamutMap));
233 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
234
235 WM_SCOPED_TRACE("dms:SetScreenGamutMap(%" PRIu64")", screenId);
236
237 return abstractScreenController_->SetScreenGamutMap(screenId, gamutMap);
238 }
239
SetScreenColorTransform(ScreenId screenId)240 DMError DisplayManagerService::SetScreenColorTransform(ScreenId screenId)
241 {
242 WLOGFI("SetScreenColorTransform::ScreenId: %{public}" PRIu64 "", screenId);
243 CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
244
245 WM_SCOPED_TRACE("dms:SetScreenColorTransform(%" PRIu64")", screenId);
246
247 return abstractScreenController_->SetScreenColorTransform(screenId);
248 }
249
250
OnStop()251 void DisplayManagerService::OnStop()
252 {
253 WLOGFI("ready to stop display service.");
254 }
255
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)256 bool DisplayManagerService::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
257 DisplayManagerAgentType type)
258 {
259 if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
260 WLOGFE("displayManagerAgent invalid");
261 return false;
262 }
263 return DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type);
264 }
265
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)266 bool DisplayManagerService::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
267 DisplayManagerAgentType type)
268 {
269 if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
270 WLOGFE("displayManagerAgent invalid");
271 return false;
272 }
273 return DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type);
274 }
275
WakeUpBegin(PowerStateChangeReason reason)276 bool DisplayManagerService::WakeUpBegin(PowerStateChangeReason reason)
277 {
278 WM_SCOPED_TRACE("dms:WakeUpBegin(%u)", reason);
279 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP,
280 EventStatus::BEGIN);
281 }
282
WakeUpEnd()283 bool DisplayManagerService::WakeUpEnd()
284 {
285 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP,
286 EventStatus::END);
287 }
288
SuspendBegin(PowerStateChangeReason reason)289 bool DisplayManagerService::SuspendBegin(PowerStateChangeReason reason)
290 {
291 WM_SCOPED_TRACE("dms:SuspendBegin(%u)", reason);
292 displayPowerController_->SuspendBegin(reason);
293 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP,
294 EventStatus::BEGIN);
295 }
296
SuspendEnd()297 bool DisplayManagerService::SuspendEnd()
298 {
299 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP,
300 EventStatus::END);
301 }
302
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)303 bool DisplayManagerService::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
304 {
305 WLOGFI("SetScreenPowerForAll");
306 return abstractScreenController_->SetScreenPowerForAll(state, reason);
307 }
308
GetScreenPower(ScreenId dmsScreenId)309 ScreenPowerState DisplayManagerService::GetScreenPower(ScreenId dmsScreenId)
310 {
311 return abstractScreenController_->GetScreenPower(dmsScreenId);
312 }
313
SetDisplayState(DisplayState state)314 bool DisplayManagerService::SetDisplayState(DisplayState state)
315 {
316 std::lock_guard<std::recursive_mutex> lock(mutex_);
317 ScreenId dmsScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
318 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplayByScreen(dmsScreenId);
319 if (display != nullptr) {
320 display->SetDisplayState(state);
321 }
322 return displayPowerController_->SetDisplayState(state);
323 }
324
GetScreenIdByDisplayId(DisplayId displayId) const325 ScreenId DisplayManagerService::GetScreenIdByDisplayId(DisplayId displayId) const
326 {
327 sptr<AbstractDisplay> abstractDisplay = abstractDisplayController_->GetAbstractDisplay(displayId);
328 if (abstractDisplay == nullptr) {
329 WLOGFE("GetScreenIdByDisplayId: GetAbstarctDisplay failed");
330 return SCREEN_ID_INVALID;
331 }
332 return abstractDisplay->GetAbstractScreenId();
333 }
334
GetDisplayState(DisplayId displayId)335 DisplayState DisplayManagerService::GetDisplayState(DisplayId displayId)
336 {
337 std::lock_guard<std::recursive_mutex> lock(mutex_);
338 return displayPowerController_->GetDisplayState(displayId);
339 }
340
NotifyDisplayEvent(DisplayEvent event)341 void DisplayManagerService::NotifyDisplayEvent(DisplayEvent event)
342 {
343 displayPowerController_->NotifyDisplayEvent(event);
344 }
345
SetFreeze(std::vector<DisplayId> displayIds,bool isFreeze)346 bool DisplayManagerService::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
347 {
348 abstractDisplayController_->SetFreeze(displayIds, isFreeze);
349 return true;
350 }
351
GetRSDisplayNodeByDisplayId(DisplayId displayId) const352 std::shared_ptr<RSDisplayNode> DisplayManagerService::GetRSDisplayNodeByDisplayId(DisplayId displayId) const
353 {
354 ScreenId screenId = GetScreenIdByDisplayId(displayId);
355 CHECK_SCREEN_AND_RETURN(nullptr);
356
357 return abstractScreenController_->GetRSDisplayNodeByScreenId(screenId);
358 }
359
SetShotScreen(ScreenId mainScreenId,std::vector<ScreenId> shotScreenIds)360 void DisplayManagerService::SetShotScreen(ScreenId mainScreenId, std::vector<ScreenId> shotScreenIds)
361 {
362 WLOGFI("SetShotScreen. mainScreenId: %{public}" PRIu64"", mainScreenId);
363 if (shotScreenIds.empty()) {
364 WLOGFI("shotScreenIds is empty");
365 return;
366 }
367 std::shared_ptr<RSDisplayNode> displayNode = abstractScreenController_->GetRSDisplayNodeByScreenId(mainScreenId);
368 if (displayNode == nullptr) {
369 WLOGFE("SetShotScreen error, cannot get DisplayNode");
370 return;
371 }
372 NodeId nodeId = displayNode->GetId();
373 WLOGI("SetShotScreen, mainScreen nodeId:%{public}" PRIu64"", nodeId);
374 for (ScreenId shotScreenId : shotScreenIds) {
375 shotScreenId = abstractScreenController_->ConvertToRsScreenId(shotScreenId);
376 if (shotScreenId == INVALID_SCREEN_ID) {
377 continue;
378 }
379 struct RSDisplayNodeConfig config = {shotScreenId, true, nodeId};
380 displayNodeMap_[shotScreenId] = RSDisplayNode::Create(config);
381 }
382 auto transactionProxy = RSTransactionProxy::GetInstance();
383 if (transactionProxy != nullptr) {
384 transactionProxy->FlushImplicitTransaction();
385 }
386 }
387
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenIds)388 ScreenId DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds)
389 {
390 WLOGFI("MakeMirror. mainScreenId :%{public}" PRIu64"", mainScreenId);
391 auto shotScreenIds = abstractScreenController_->GetShotScreenIds(mirrorScreenIds);
392 auto iter = std::find(shotScreenIds.begin(), shotScreenIds.end(), mainScreenId);
393 if (iter != shotScreenIds.end()) {
394 shotScreenIds.erase(iter);
395 }
396 auto allMirrorScreenIds = abstractScreenController_->GetAllExpandOrMirrorScreenIds(mirrorScreenIds);
397 iter = std::find(allMirrorScreenIds.begin(), allMirrorScreenIds.end(), mainScreenId);
398 if (iter != allMirrorScreenIds.end()) {
399 allMirrorScreenIds.erase(iter);
400 }
401 if (mainScreenId == SCREEN_ID_INVALID || (shotScreenIds.empty() && allMirrorScreenIds.empty())) {
402 WLOGFI("create mirror fail, screen is invalid. Screen :%{public}" PRIu64"", mainScreenId);
403 return SCREEN_ID_INVALID;
404 }
405 SetShotScreen(mainScreenId, shotScreenIds);
406 WM_SCOPED_TRACE("dms:MakeMirror");
407 if (!allMirrorScreenIds.empty() && !abstractScreenController_->MakeMirror(mainScreenId, allMirrorScreenIds)) {
408 WLOGFE("make mirror failed.");
409 return SCREEN_ID_INVALID;
410 }
411 abstractScreenController_->DumpScreenInfo();
412 auto screen = abstractScreenController_->GetAbstractScreen(mainScreenId);
413 if (screen == nullptr || abstractScreenController_->GetAbstractScreenGroup(screen->groupDmsId_) == nullptr) {
414 WLOGFE("get screen group failed.");
415 return SCREEN_ID_INVALID;
416 }
417 return screen->groupDmsId_;
418 }
419
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)420 void DisplayManagerService::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
421 {
422 abstractScreenController_->RemoveVirtualScreenFromGroup(screens);
423 }
424
UpdateRSTree(DisplayId displayId,std::shared_ptr<RSSurfaceNode> & surfaceNode,bool isAdd)425 void DisplayManagerService::UpdateRSTree(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode,
426 bool isAdd)
427 {
428 WLOGI("UpdateRSTree");
429 ScreenId screenId = GetScreenIdByDisplayId(displayId);
430 CHECK_SCREEN_AND_RETURN();
431
432 abstractScreenController_->UpdateRSTree(screenId, surfaceNode, isAdd);
433 }
434
GetScreenInfoById(ScreenId screenId)435 sptr<ScreenInfo> DisplayManagerService::GetScreenInfoById(ScreenId screenId)
436 {
437 auto screen = abstractScreenController_->GetAbstractScreen(screenId);
438 if (screen == nullptr) {
439 WLOGE("cannot find screenInfo: %{public}" PRIu64"", screenId);
440 return nullptr;
441 }
442 return screen->ConvertToScreenInfo();
443 }
444
GetScreenGroupInfoById(ScreenId screenId)445 sptr<ScreenGroupInfo> DisplayManagerService::GetScreenGroupInfoById(ScreenId screenId)
446 {
447 auto screenGroup = abstractScreenController_->GetAbstractScreenGroup(screenId);
448 if (screenGroup == nullptr) {
449 WLOGE("cannot find screenGroupInfo: %{public}" PRIu64"", screenId);
450 return nullptr;
451 }
452 return screenGroup->ConvertToScreenGroupInfo();
453 }
454
GetAllDisplayIds()455 std::vector<DisplayId> DisplayManagerService::GetAllDisplayIds()
456 {
457 return abstractDisplayController_->GetAllDisplayIds();
458 }
459
GetAllScreenInfos()460 std::vector<sptr<ScreenInfo>> DisplayManagerService::GetAllScreenInfos()
461 {
462 std::vector<ScreenId> screenIds = abstractScreenController_->GetAllScreenIds();
463 std::vector<sptr<ScreenInfo>> screenInfos;
464 for (auto screenId: screenIds) {
465 auto screenInfo = GetScreenInfoById(screenId);
466 if (screenInfo == nullptr) {
467 WLOGE("cannot find screenInfo: %{public}" PRIu64"", screenId);
468 continue;
469 }
470 screenInfos.emplace_back(screenInfo);
471 }
472 return screenInfos;
473 }
474
MakeExpand(std::vector<ScreenId> expandScreenIds,std::vector<Point> startPoints)475 ScreenId DisplayManagerService::MakeExpand(std::vector<ScreenId> expandScreenIds, std::vector<Point> startPoints)
476 {
477 WLOGI("MakeExpand");
478 if (expandScreenIds.empty() || startPoints.empty() || expandScreenIds.size() != startPoints.size()) {
479 WLOGFI("create expand fail, input params is invalid. "
480 "screenId vector size :%{public}ud, startPoint vector size :%{public}ud",
481 static_cast<uint32_t>(expandScreenIds.size()), static_cast<uint32_t>(startPoints.size()));
482 return SCREEN_ID_INVALID;
483 }
484 ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
485 WLOGI("MakeExpand, defaultScreenId:%{public}" PRIu64"", defaultScreenId);
486 auto shotScreenIds = abstractScreenController_->GetShotScreenIds(expandScreenIds);
487 auto iter = std::find(shotScreenIds.begin(), shotScreenIds.end(), defaultScreenId);
488 if (iter != shotScreenIds.end()) {
489 shotScreenIds.erase(iter);
490 }
491 auto allExpandScreenIds = abstractScreenController_->GetAllExpandOrMirrorScreenIds(expandScreenIds);
492 iter = std::find(allExpandScreenIds.begin(), allExpandScreenIds.end(), defaultScreenId);
493 if (iter != allExpandScreenIds.end()) {
494 allExpandScreenIds.erase(iter);
495 }
496 SetShotScreen(defaultScreenId, shotScreenIds);
497 WM_SCOPED_TRACE("dms:MakeExpand");
498 if (!allExpandScreenIds.empty() && !abstractScreenController_->MakeExpand(allExpandScreenIds, startPoints)) {
499 WLOGFE("make expand failed.");
500 return SCREEN_ID_INVALID;
501 }
502 abstractScreenController_->DumpScreenInfo();
503 auto screen = abstractScreenController_->GetAbstractScreen(allExpandScreenIds[0]);
504 if (screen == nullptr || abstractScreenController_->GetAbstractScreenGroup(screen->groupDmsId_) == nullptr) {
505 WLOGFE("get screen group failed.");
506 return SCREEN_ID_INVALID;
507 }
508 return screen->groupDmsId_;
509 }
510
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)511 bool DisplayManagerService::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
512 {
513 WM_SCOPED_TRACE("dms:SetScreenActiveMode(%" PRIu64", %u)", screenId, modeId);
514 return abstractScreenController_->SetScreenActiveMode(screenId, modeId);
515 }
516 } // namespace OHOS::Rosen