1 /*
2 * Copyright (c) 2023 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 "session/screen/include/screen_session.h"
17
18 #include "window_manager_hilog.h"
19 #include <transaction/rs_interfaces.h>
20 #include <transaction/rs_transaction.h>
21
22 namespace OHOS::Rosen {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ScreenSession" };
25 }
26
ScreenSession()27 ScreenSession::ScreenSession()
28 {}
29
ScreenSession(ScreenId screenId,const ScreenProperty & property,ScreenId defaultScreenId)30 ScreenSession::ScreenSession(ScreenId screenId, const ScreenProperty& property, ScreenId defaultScreenId)
31 : screenId_(screenId), defaultScreenId_(defaultScreenId), property_(property)
32 {
33 Rosen::RSDisplayNodeConfig config = { .screenId = screenId_ };
34 displayNode_ = Rosen::RSDisplayNode::Create(config);
35 RSTransaction::FlushImplicitTransaction();
36 }
37
ScreenSession(const std::string & name,ScreenId smsId,ScreenId rsId,ScreenId defaultScreenId)38 ScreenSession::ScreenSession(const std::string& name, ScreenId smsId, ScreenId rsId, ScreenId defaultScreenId)
39 : name_(name), screenId_(smsId), rsId_(rsId), defaultScreenId_(defaultScreenId)
40 {
41 (void)rsId_;
42 Rosen::RSDisplayNodeConfig config = { .screenId = screenId_ };
43 displayNode_ = Rosen::RSDisplayNode::Create(config);
44 RSTransaction::FlushImplicitTransaction();
45 }
46
RegisterScreenChangeListener(IScreenChangeListener * screenChangeListener)47 void ScreenSession::RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener)
48 {
49 if (screenChangeListener == nullptr) {
50 WLOGFE("Failed to register screen change listener, listener is null!");
51 return;
52 }
53
54 if (std::find(screenChangeListenerList_.begin(), screenChangeListenerList_.end(), screenChangeListener) !=
55 screenChangeListenerList_.end()) {
56 WLOGFE("Repeat to register screen change listener!");
57 return;
58 }
59
60 screenChangeListenerList_.emplace_back(screenChangeListener);
61 if (screenState_ == ScreenState::CONNECTION) {
62 screenChangeListener->OnConnect();
63 }
64 }
65
UnregisterScreenChangeListener(IScreenChangeListener * screenChangeListener)66 void ScreenSession::UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener)
67 {
68 if (screenChangeListener == nullptr) {
69 WLOGFE("Failed to unregister screen change listener, listener is null!");
70 return;
71 }
72
73 screenChangeListenerList_.erase(
74 std::remove_if(screenChangeListenerList_.begin(), screenChangeListenerList_.end(),
75 [screenChangeListener](IScreenChangeListener* listener) { return screenChangeListener == listener; }),
76 screenChangeListenerList_.end());
77 }
78
ConvertToDisplayInfo()79 sptr<DisplayInfo> ScreenSession::ConvertToDisplayInfo()
80 {
81 sptr<DisplayInfo> displayInfo = new(std::nothrow) DisplayInfo();
82 if (displayInfo == nullptr) {
83 return displayInfo;
84 }
85 displayInfo->name_ = name_;
86 displayInfo->SetWidth(property_.GetBounds().rect_.GetWidth());
87 displayInfo->SetHeight(property_.GetBounds().rect_.GetHeight());
88 displayInfo->SetScreenId(screenId_);
89 displayInfo->SetDisplayId(screenId_);
90 displayInfo->SetRefreshRate(property_.GetRefreshRate());
91 displayInfo->SetVirtualPixelRatio(property_.GetVirtualPixelRatio());
92 displayInfo->SetXDpi(property_.GetXDpi());
93 displayInfo->SetYDpi(property_.GetYDpi());
94 displayInfo->SetDpi(property_.GetVirtualPixelRatio() * DOT_PER_INCH);
95 displayInfo->SetRotation(property_.GetScreenRotation());
96 displayInfo->SetOrientation(property_.GetOrientation());
97 displayInfo->SetOffsetX(property_.GetOffsetX());
98 displayInfo->SetOffsetY(property_.GetOffsetY());
99 displayInfo->SetDisplayOrientation(property_.GetDisplayOrientation());
100 return displayInfo;
101 }
102
GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> & colorGamuts)103 DMError ScreenSession::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts)
104 {
105 auto ret = RSInterfaces::GetInstance().GetScreenSupportedColorGamuts(rsId_, colorGamuts);
106 if (ret != StatusCode::SUCCESS) {
107 WLOGE("SCB: ScreenSession::GetScreenSupportedColorGamuts fail! rsId %{public}" PRIu64"", rsId_);
108 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
109 }
110 WLOGI("SCB: ScreenSession::GetScreenSupportedColorGamuts ok! rsId %{public}" PRIu64", size %{public}u",
111 rsId_, static_cast<uint32_t>(colorGamuts.size()));
112
113 return DMError::DM_OK;
114 }
115
GetScreenId()116 ScreenId ScreenSession::GetScreenId()
117 {
118 return screenId_;
119 }
120
GetScreenProperty() const121 ScreenProperty ScreenSession::GetScreenProperty() const
122 {
123 return property_;
124 }
125
UpdatePropertyByActiveMode()126 void ScreenSession::UpdatePropertyByActiveMode() {
127 sptr<SupportedScreenModes> mode = GetActiveScreenMode();
128 if (mode != nullptr) {
129 auto screeBounds = property_.GetBounds();
130 screeBounds.rect_.width_ = mode->width_;
131 screeBounds.rect_.height_ = mode->height_;
132 property_.SetBounds(screeBounds);
133 }
134 }
135
GetDisplayNode() const136 std::shared_ptr<RSDisplayNode> ScreenSession::GetDisplayNode() const
137 {
138 return displayNode_;
139 }
140
ReleaseDisplayNode()141 void ScreenSession::ReleaseDisplayNode()
142 {
143 displayNode_ = nullptr;
144 }
145
Connect()146 void ScreenSession::Connect()
147 {
148 screenState_ = ScreenState::CONNECTION;
149 for (auto& listener : screenChangeListenerList_) {
150 listener->OnConnect();
151 }
152 }
153
Disconnect()154 void ScreenSession::Disconnect()
155 {
156 screenState_ = ScreenState::DISCONNECTION;
157 for (auto& listener : screenChangeListenerList_) {
158 listener->OnDisconnect();
159 }
160 }
161
PropertyChange(const ScreenProperty & newProperty,ScreenPropertyChangeReason reason)162 void ScreenSession::PropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason)
163 {
164 for (auto& listener : screenChangeListenerList_) {
165 listener->OnPropertyChange(newProperty, reason);
166 }
167 }
168
GetActiveScreenMode() const169 sptr<SupportedScreenModes> ScreenSession::GetActiveScreenMode() const
170 {
171 if (activeIdx_ < 0 || activeIdx_ >= static_cast<int32_t>(modes_.size())) {
172 WLOGE("SCB: ScreenSession::GetActiveScreenMode active mode index is wrong: %{public}d", activeIdx_);
173 return nullptr;
174 }
175 return modes_[activeIdx_];
176 }
177
GetOrientation() const178 Orientation ScreenSession::GetOrientation() const
179 {
180 return property_.GetOrientation();
181 }
182
SetOrientation(Orientation orientation)183 void ScreenSession::SetOrientation(Orientation orientation)
184 {
185 property_.SetOrientation(orientation);
186 }
187
GetRotation() const188 Rotation ScreenSession::GetRotation() const
189 {
190 return property_.GetScreenRotation();
191 }
192
SetRotation(Rotation rotation)193 void ScreenSession::SetRotation(Rotation rotation)
194 {
195 property_.SetScreenRotation(rotation);
196 }
197
SetScreenRequestedOrientation(Orientation orientation)198 void ScreenSession::SetScreenRequestedOrientation(Orientation orientation)
199 {
200 property_.SetScreenRequestedOrientation(orientation);
201 }
202
GetScreenRequestedOrientation() const203 Orientation ScreenSession::GetScreenRequestedOrientation() const
204 {
205 return property_.GetScreenRequestedOrientation();
206 }
207
SetVirtualPixelRatio(float virtualPixelRatio)208 void ScreenSession::SetVirtualPixelRatio(float virtualPixelRatio)
209 {
210 property_.SetVirtualPixelRatio(virtualPixelRatio);
211 }
212
SetScreenType(ScreenType type)213 void ScreenSession::SetScreenType(ScreenType type)
214 {
215 property_.SetScreenType(type);
216 }
217
CalcRotation(Orientation orientation) const218 Rotation ScreenSession::CalcRotation(Orientation orientation) const
219 {
220 sptr<SupportedScreenModes> info = GetActiveScreenMode();
221 if (info == nullptr) {
222 return Rotation::ROTATION_0;
223 }
224 // vertical: phone(Plugin screen); horizontal: pad & external screen
225 bool isVerticalScreen = info->width_ < info->height_;
226 switch (orientation) {
227 case Orientation::UNSPECIFIED: {
228 return Rotation::ROTATION_0;
229 }
230 case Orientation::VERTICAL: {
231 return isVerticalScreen ? Rotation::ROTATION_0 : Rotation::ROTATION_90;
232 }
233 case Orientation::HORIZONTAL: {
234 return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_0;
235 }
236 case Orientation::REVERSE_VERTICAL: {
237 return isVerticalScreen ? Rotation::ROTATION_180 : Rotation::ROTATION_270;
238 }
239 case Orientation::REVERSE_HORIZONTAL: {
240 return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_180;
241 }
242 default: {
243 WLOGE("unknown orientation %{public}u", orientation);
244 return Rotation::ROTATION_0;
245 }
246 }
247 }
248
GetSourceMode() const249 ScreenSourceMode ScreenSession::GetSourceMode() const
250 {
251 if (screenId_ == defaultScreenId_) {
252 return ScreenSourceMode::SCREEN_MAIN;
253 }
254 ScreenCombination combination = GetScreenCombination();
255 switch (combination) {
256 case ScreenCombination::SCREEN_MIRROR: {
257 return ScreenSourceMode::SCREEN_MIRROR;
258 }
259 case ScreenCombination::SCREEN_EXPAND: {
260 return ScreenSourceMode::SCREEN_EXTEND;
261 }
262 case ScreenCombination::SCREEN_ALONE: {
263 return ScreenSourceMode::SCREEN_ALONE;
264 }
265 default: {
266 return ScreenSourceMode::SCREEN_ALONE;
267 }
268 }
269 }
270
SetScreenCombination(ScreenCombination combination)271 void ScreenSession::SetScreenCombination(ScreenCombination combination)
272 {
273 combination_ = combination;
274 }
275
GetScreenCombination() const276 ScreenCombination ScreenSession::GetScreenCombination() const
277 {
278 return combination_;
279 }
280
FillScreenInfo(sptr<ScreenInfo> info) const281 void ScreenSession::FillScreenInfo(sptr<ScreenInfo> info) const
282 {
283 if (info == nullptr) {
284 WLOGE("FillScreenInfo failed! info is nullptr");
285 return;
286 }
287 info->SetScreenId(screenId_);
288 info->SetName(name_);
289 uint32_t width = 0;
290 uint32_t height = 0;
291 sptr<SupportedScreenModes> screenSessionModes = GetActiveScreenMode();
292 if (screenSessionModes != nullptr) {
293 height = screenSessionModes->height_;
294 width = screenSessionModes->width_;
295 }
296 float virtualPixelRatio = property_.GetVirtualPixelRatio();
297 // "< 1e-set6" means virtualPixelRatio is 0.
298 if (fabsf(virtualPixelRatio) < 1e-6) {
299 virtualPixelRatio = 1.0f;
300 }
301 ScreenSourceMode sourceMode = GetSourceMode();
302 info->SetVirtualPixelRatio(property_.GetVirtualPixelRatio());
303 info->SetVirtualHeight(height / virtualPixelRatio);
304 info->SetVirtualWidth(width / virtualPixelRatio);
305 info->SetRotation(property_.GetScreenRotation());
306 info->SetOrientation(property_.GetOrientation());
307 info->SetSourceMode(sourceMode);
308 info->SetType(property_.GetScreenType());
309 info->SetModeId(activeIdx_);
310
311 info->lastParent_ = lastGroupSmsId_;
312 info->parent_ = groupSmsId_;
313 info->isScreenGroup_ = isScreenGroup_;
314 info->modes_ = modes_;
315 }
316
ConvertToScreenInfo() const317 sptr<ScreenInfo> ScreenSession::ConvertToScreenInfo() const
318 {
319 sptr<ScreenInfo> info = new(std::nothrow) ScreenInfo();
320 if (info == nullptr) {
321 return nullptr;
322 }
323 FillScreenInfo(info);
324 return info;
325 }
326
GetScreenColorGamut(ScreenColorGamut & colorGamut)327 DMError ScreenSession::GetScreenColorGamut(ScreenColorGamut& colorGamut)
328 {
329 auto ret = RSInterfaces::GetInstance().GetScreenColorGamut(rsId_, colorGamut);
330 if (ret != StatusCode::SUCCESS) {
331 WLOGE("GetScreenColorGamut fail! rsId %{public}" PRIu64"", rsId_);
332 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
333 }
334 WLOGI("GetScreenColorGamut ok! rsId %{public}" PRIu64", colorGamut %{public}u",
335 rsId_, static_cast<uint32_t>(colorGamut));
336 return DMError::DM_OK;
337 }
338
SetScreenColorGamut(int32_t colorGamutIdx)339 DMError ScreenSession::SetScreenColorGamut(int32_t colorGamutIdx)
340 {
341 std::vector<ScreenColorGamut> colorGamuts;
342 DMError res = GetScreenSupportedColorGamuts(colorGamuts);
343 if (res != DMError::DM_OK) {
344 WLOGE("SetScreenColorGamut fail! rsId %{public}" PRIu64"", rsId_);
345 return res;
346 }
347 if (colorGamutIdx < 0 || colorGamutIdx >= static_cast<int32_t>(colorGamuts.size())) {
348 WLOGE("SetScreenColorGamut fail! rsId %{public}" PRIu64" colorGamutIdx %{public}d invalid.",
349 rsId_, colorGamutIdx);
350 return DMError::DM_ERROR_INVALID_PARAM;
351 }
352 auto ret = RSInterfaces::GetInstance().SetScreenColorGamut(rsId_, colorGamutIdx);
353 if (ret != StatusCode::SUCCESS) {
354 WLOGE("SetScreenColorGamut fail! rsId %{public}" PRIu64"", rsId_);
355 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
356 }
357 WLOGI("SetScreenColorGamut ok! rsId %{public}" PRIu64", colorGamutIdx %{public}u",
358 rsId_, colorGamutIdx);
359 return DMError::DM_OK;
360 }
361
GetScreenGamutMap(ScreenGamutMap & gamutMap)362 DMError ScreenSession::GetScreenGamutMap(ScreenGamutMap& gamutMap)
363 {
364 auto ret = RSInterfaces::GetInstance().GetScreenGamutMap(rsId_, gamutMap);
365 if (ret != StatusCode::SUCCESS) {
366 WLOGE("GetScreenGamutMap fail! rsId %{public}" PRIu64"", rsId_);
367 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
368 }
369 WLOGI("GetScreenGamutMap ok! rsId %{public}" PRIu64", gamutMap %{public}u",
370 rsId_, static_cast<uint32_t>(gamutMap));
371 return DMError::DM_OK;
372 }
373
SetScreenGamutMap(ScreenGamutMap gamutMap)374 DMError ScreenSession::SetScreenGamutMap(ScreenGamutMap gamutMap)
375 {
376 if (gamutMap > GAMUT_MAP_HDR_EXTENSION) {
377 return DMError::DM_ERROR_INVALID_PARAM;
378 }
379 auto ret = RSInterfaces::GetInstance().SetScreenGamutMap(rsId_, gamutMap);
380 if (ret != StatusCode::SUCCESS) {
381 WLOGE("SetScreenGamutMap fail! rsId %{public}" PRIu64"", rsId_);
382 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
383 }
384 WLOGI("SetScreenGamutMap ok! rsId %{public}" PRIu64", gamutMap %{public}u",
385 rsId_, static_cast<uint32_t>(gamutMap));
386 return DMError::DM_OK;
387 }
388
SetScreenColorTransform()389 DMError ScreenSession::SetScreenColorTransform()
390 {
391 WLOGI("SetScreenColorTransform ok! rsId %{public}" PRIu64"", rsId_);
392 return DMError::DM_OK;
393 }
394
GetPrivateSessionCount() const395 int32_t ScreenSession::GetPrivateSessionCount() const
396 {
397 return privateSessionCount_;
398 }
399
SetPrivateSessionCount(int32_t count)400 DMError ScreenSession::SetPrivateSessionCount(int32_t count)
401 {
402 privateSessionCount_ = count;
403 return DMError::DM_OK;
404 }
405
HasPrivateSession() const406 bool ScreenSession::HasPrivateSession() const
407 {
408 return privateSessionCount_ > 0;
409 }
410
InitRSDisplayNode(RSDisplayNodeConfig & config,Point & startPoint)411 void ScreenSession::InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint)
412 {
413 if (displayNode_ != nullptr) {
414 displayNode_->SetDisplayNodeMirrorConfig(config);
415 } else {
416 std::shared_ptr<RSDisplayNode> rsDisplayNode = RSDisplayNode::Create(config);
417 if (rsDisplayNode == nullptr) {
418 WLOGE("fail to add child. create rsDisplayNode fail!");
419 return;
420 }
421 displayNode_ = rsDisplayNode;
422 }
423 WLOGFI("SetDisplayOffset: posX:%{public}d, posY:%{public}d", startPoint.posX_, startPoint.posY_);
424 displayNode_->SetDisplayOffset(startPoint.posX_, startPoint.posY_);
425 uint32_t width = 0;
426 uint32_t height = 0;
427 sptr<SupportedScreenModes> abstractScreenModes = GetActiveScreenMode();
428 if (abstractScreenModes != nullptr) {
429 height = abstractScreenModes->height_;
430 width = abstractScreenModes->width_;
431 }
432 RSScreenType screenType;
433 auto ret = RSInterfaces::GetInstance().GetScreenType(rsId_, screenType);
434 if (ret == StatusCode::SUCCESS && screenType == RSScreenType::VIRTUAL_TYPE_SCREEN) {
435 displayNode_->SetSecurityDisplay(true);
436 WLOGFI("virtualScreen SetSecurityDisplay success");
437 }
438 // If setDisplayOffset is not valid for SetFrame/SetBounds
439 displayNode_->SetFrame(0, 0, width, height);
440 displayNode_->SetBounds(0, 0, width, height);
441 auto transactionProxy = RSTransactionProxy::GetInstance();
442 if (transactionProxy != nullptr) {
443 transactionProxy->FlushImplicitTransaction();
444 }
445 }
446
ScreenSessionGroup(ScreenId screenId,ScreenId rsId,std::string name,ScreenCombination combination)447 ScreenSessionGroup::ScreenSessionGroup(ScreenId screenId, ScreenId rsId,
448 std::string name, ScreenCombination combination) : combination_(combination)
449 {
450 name_ = name;
451 screenId_ = screenId;
452 rsId_ = rsId;
453 SetScreenType(ScreenType::UNDEFINED);
454 isScreenGroup_ = true;
455 }
456
~ScreenSessionGroup()457 ScreenSessionGroup::~ScreenSessionGroup()
458 {
459 ReleaseDisplayNode();
460 screenSessionMap_.clear();
461 }
462
GetRSDisplayNodeConfig(sptr<ScreenSession> & screenSession,struct RSDisplayNodeConfig & config,sptr<ScreenSession> defaultScreenSession)463 bool ScreenSessionGroup::GetRSDisplayNodeConfig(sptr<ScreenSession>& screenSession, struct RSDisplayNodeConfig& config,
464 sptr<ScreenSession> defaultScreenSession)
465 {
466 if (screenSession == nullptr) {
467 WLOGE("screenSession is nullptr.");
468 return false;
469 }
470 config = { screenSession->rsId_ };
471 switch (combination_) {
472 case ScreenCombination::SCREEN_ALONE:
473 [[fallthrough]];
474 case ScreenCombination::SCREEN_EXPAND:
475 break;
476 case ScreenCombination::SCREEN_MIRROR: {
477 if (GetChildCount() == 0 || mirrorScreenId_ == screenSession->screenId_) {
478 WLOGI("AddChild, SCREEN_MIRROR, config is not mirror");
479 break;
480 }
481 std::shared_ptr<RSDisplayNode> displayNode = defaultScreenSession->GetDisplayNode();
482 if (displayNode == nullptr) {
483 WLOGFE("AddChild fail, displayNode is nullptr, cannot get DisplayNode");
484 break;
485 }
486 NodeId nodeId = displayNode->GetId();
487 WLOGI("AddChild, mirrorScreenId_:%{public}" PRIu64", rsId_:%{public}" PRIu64", nodeId:%{public}" PRIu64"",
488 mirrorScreenId_, screenSession->rsId_, nodeId);
489 config = {screenSession->rsId_, true, nodeId};
490 break;
491 }
492 default:
493 WLOGE("fail to add child. invalid group combination:%{public}u", combination_);
494 return false;
495 }
496 return true;
497 }
498
AddChild(sptr<ScreenSession> & smsScreen,Point & startPoint,sptr<ScreenSession> defaultScreenSession)499 bool ScreenSessionGroup::AddChild(sptr<ScreenSession>& smsScreen, Point& startPoint,
500 sptr<ScreenSession> defaultScreenSession)
501 {
502 if (smsScreen == nullptr) {
503 WLOGE("AddChild, smsScreen is nullptr.");
504 return false;
505 }
506 ScreenId screenId = smsScreen->screenId_;
507 auto iter = screenSessionMap_.find(screenId);
508 if (iter != screenSessionMap_.end()) {
509 WLOGE("AddChild, screenSessionMap_ has smsScreen:%{public}" PRIu64"", screenId);
510 return false;
511 }
512 struct RSDisplayNodeConfig config;
513 if (!GetRSDisplayNodeConfig(smsScreen, config, defaultScreenSession)) {
514 return false;
515 }
516 smsScreen->InitRSDisplayNode(config, startPoint);
517 smsScreen->lastGroupSmsId_ = smsScreen->groupSmsId_;
518 smsScreen->groupSmsId_ = screenId_;
519 screenSessionMap_.insert(std::make_pair(screenId, std::make_pair(smsScreen, startPoint)));
520 return true;
521 }
522
AddChildren(std::vector<sptr<ScreenSession>> & smsScreens,std::vector<Point> & startPoints)523 bool ScreenSessionGroup::AddChildren(std::vector<sptr<ScreenSession>>& smsScreens, std::vector<Point>& startPoints)
524 {
525 size_t size = smsScreens.size();
526 if (size != startPoints.size()) {
527 WLOGE("AddChildren, unequal size.");
528 return false;
529 }
530 bool res = true;
531 for (size_t i = 0; i < size; i++) {
532 res = AddChild(smsScreens[i], startPoints[i], nullptr) && res;
533 }
534 return res;
535 }
536
RemoveChild(sptr<ScreenSession> & smsScreen)537 bool ScreenSessionGroup::RemoveChild(sptr<ScreenSession>& smsScreen)
538 {
539 if (smsScreen == nullptr) {
540 WLOGE("RemoveChild, smsScreen is nullptr.");
541 return false;
542 }
543 ScreenId screenId = smsScreen->screenId_;
544 smsScreen->lastGroupSmsId_ = smsScreen->groupSmsId_;
545 smsScreen->groupSmsId_ = SCREEN_ID_INVALID;
546 if (smsScreen->GetDisplayNode() != nullptr) {
547 smsScreen->GetDisplayNode()->SetDisplayOffset(0, 0);
548 smsScreen->GetDisplayNode()->RemoveFromTree();
549 auto transactionProxy = RSTransactionProxy::GetInstance();
550 if (transactionProxy != nullptr) {
551 transactionProxy->FlushImplicitTransaction();
552 }
553 smsScreen->ReleaseDisplayNode();
554 }
555 return screenSessionMap_.erase(screenId);
556 }
557
HasChild(ScreenId childScreen) const558 bool ScreenSessionGroup::HasChild(ScreenId childScreen) const
559 {
560 return screenSessionMap_.find(childScreen) != screenSessionMap_.end();
561 }
562
GetChildren() const563 std::vector<sptr<ScreenSession>> ScreenSessionGroup::GetChildren() const
564 {
565 std::vector<sptr<ScreenSession>> res;
566 for (auto iter = screenSessionMap_.begin(); iter != screenSessionMap_.end(); iter++) {
567 res.push_back(iter->second.first);
568 }
569 return res;
570 }
571
GetChildrenPosition() const572 std::vector<Point> ScreenSessionGroup::GetChildrenPosition() const
573 {
574 std::vector<Point> res;
575 for (auto iter = screenSessionMap_.begin(); iter != screenSessionMap_.end(); iter++) {
576 res.push_back(iter->second.second);
577 }
578 return res;
579 }
580
GetChildPosition(ScreenId screenId) const581 Point ScreenSessionGroup::GetChildPosition(ScreenId screenId) const
582 {
583 Point point;
584 auto iter = screenSessionMap_.find(screenId);
585 if (iter != screenSessionMap_.end()) {
586 point = iter->second.second;
587 }
588 return point;
589 }
590
GetChildCount() const591 size_t ScreenSessionGroup::GetChildCount() const
592 {
593 return screenSessionMap_.size();
594 }
595
GetScreenCombination() const596 ScreenCombination ScreenSessionGroup::GetScreenCombination() const
597 {
598 return combination_;
599 }
600
ConvertToScreenGroupInfo() const601 sptr<ScreenGroupInfo> ScreenSessionGroup::ConvertToScreenGroupInfo() const
602 {
603 sptr<ScreenGroupInfo> screenGroupInfo = new(std::nothrow) ScreenGroupInfo();
604 if (screenGroupInfo == nullptr) {
605 return nullptr;
606 }
607 FillScreenInfo(screenGroupInfo);
608 screenGroupInfo->combination_ = combination_;
609 for (auto iter = screenSessionMap_.begin(); iter != screenSessionMap_.end(); iter++) {
610 screenGroupInfo->children_.push_back(iter->first);
611 }
612 auto positions = GetChildrenPosition();
613 screenGroupInfo->position_.insert(screenGroupInfo->position_.end(), positions.begin(), positions.end());
614 return screenGroupInfo;
615 }
616
SetDisplayBoundary(const RectF & rect,const uint32_t & offsetY)617 void ScreenSession::SetDisplayBoundary(const RectF& rect, const uint32_t& offsetY)
618 {
619 property_.SetOffsetY(offsetY);
620 property_.SetBounds(RRect(rect, 0.0f, 0.0f));
621 }
622 } // namespace OHOS::Rosen
623