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 <hitrace_meter.h>
20 #include <surface_capture_future.h>
21 #include <transaction/rs_interfaces.h>
22 #include <transaction/rs_transaction.h>
23 #include "dm_common.h"
24
25 namespace OHOS::Rosen {
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ScreenSession" };
28 }
29
ScreenSession(ScreenId screenId,ScreenId rsId,const std::string & name,const ScreenProperty & property,const std::shared_ptr<RSDisplayNode> & displayNode)30 ScreenSession::ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name,
31 const ScreenProperty& property, const std::shared_ptr<RSDisplayNode>& displayNode)
32 : name_(name), screenId_(screenId), rsId_(rsId), property_(property), displayNode_(displayNode)
33 {}
34
ScreenSession(ScreenId screenId,const ScreenProperty & property,ScreenId defaultScreenId)35 ScreenSession::ScreenSession(ScreenId screenId, const ScreenProperty& property, ScreenId defaultScreenId)
36 : screenId_(screenId), defaultScreenId_(defaultScreenId), property_(property)
37 {
38 Rosen::RSDisplayNodeConfig config = { .screenId = screenId_ };
39 displayNode_ = Rosen::RSDisplayNode::Create(config);
40 if (displayNode_) {
41 WLOGI("Success to create displayNode in constructor_1, screenid is %{public}" PRIu64"", screenId_);
42 displayNode_->SetFrame(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
43 property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
44 displayNode_->SetBounds(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
45 property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
46 } else {
47 WLOGFE("Failed to create displayNode, displayNode is null!");
48 }
49 RSTransaction::FlushImplicitTransaction();
50 }
51
ScreenSession(ScreenId screenId,const ScreenProperty & property,NodeId nodeId,ScreenId defaultScreenId)52 ScreenSession::ScreenSession(ScreenId screenId, const ScreenProperty& property,
53 NodeId nodeId, ScreenId defaultScreenId)
54 : screenId_(screenId), defaultScreenId_(defaultScreenId), property_(property)
55 {
56 rsId_ = screenId;
57 Rosen::RSDisplayNodeConfig config = { .screenId = screenId_, .isMirrored = true, .mirrorNodeId = nodeId};
58 displayNode_ = Rosen::RSDisplayNode::Create(config);
59 if (displayNode_) {
60 WLOGI("Success to create displayNode in constructor_2, screenid is %{public}" PRIu64"", screenId_);
61 displayNode_->SetFrame(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
62 property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
63 displayNode_->SetBounds(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
64 property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
65 } else {
66 WLOGFE("Failed to create displayNode, displayNode is null!");
67 }
68 RSTransaction::FlushImplicitTransaction();
69 }
70
ScreenSession(const std::string & name,ScreenId smsId,ScreenId rsId,ScreenId defaultScreenId)71 ScreenSession::ScreenSession(const std::string& name, ScreenId smsId, ScreenId rsId, ScreenId defaultScreenId)
72 : name_(name), screenId_(smsId), rsId_(rsId), defaultScreenId_(defaultScreenId)
73 {
74 (void)rsId_;
75 Rosen::RSDisplayNodeConfig config = { .screenId = screenId_ };
76 displayNode_ = Rosen::RSDisplayNode::Create(config);
77 if (displayNode_) {
78 WLOGI("Success to create displayNode in constructor_3, screenid is %{public}" PRIu64"", screenId_);
79 displayNode_->SetFrame(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
80 property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
81 displayNode_->SetBounds(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
82 property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
83 } else {
84 WLOGFE("Failed to create displayNode, displayNode is null!");
85 }
86 RSTransaction::FlushImplicitTransaction();
87 }
88
SetDisplayNodeScreenId(ScreenId screenId)89 void ScreenSession::SetDisplayNodeScreenId(ScreenId screenId)
90 {
91 if (displayNode_ != nullptr) {
92 WLOGFI("SetDisplayNodeScreenId %{public}" PRIu64"", screenId);
93 displayNode_->SetScreenId(screenId);
94 }
95 }
96
RegisterScreenChangeListener(IScreenChangeListener * screenChangeListener)97 void ScreenSession::RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener)
98 {
99 if (screenChangeListener == nullptr) {
100 WLOGFE("Failed to register screen change listener, listener is null!");
101 return;
102 }
103
104 if (std::find(screenChangeListenerList_.begin(), screenChangeListenerList_.end(), screenChangeListener) !=
105 screenChangeListenerList_.end()) {
106 WLOGFI("Repeat to register screen change listener!");
107 return;
108 }
109
110 screenChangeListenerList_.emplace_back(screenChangeListener);
111 if (screenState_ == ScreenState::CONNECTION) {
112 screenChangeListener->OnConnect(screenId_);
113 }
114 }
115
UnregisterScreenChangeListener(IScreenChangeListener * screenChangeListener)116 void ScreenSession::UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener)
117 {
118 if (screenChangeListener == nullptr) {
119 WLOGFE("Failed to unregister screen change listener, listener is null!");
120 return;
121 }
122
123 screenChangeListenerList_.erase(
124 std::remove_if(screenChangeListenerList_.begin(), screenChangeListenerList_.end(),
125 [screenChangeListener](IScreenChangeListener* listener) { return screenChangeListener == listener; }),
126 screenChangeListenerList_.end());
127 }
128
ConvertToDisplayInfo()129 sptr<DisplayInfo> ScreenSession::ConvertToDisplayInfo()
130 {
131 sptr<DisplayInfo> displayInfo = new(std::nothrow) DisplayInfo();
132 if (displayInfo == nullptr) {
133 return displayInfo;
134 }
135 displayInfo->name_ = name_;
136 displayInfo->SetWidth(property_.GetBounds().rect_.GetWidth());
137 displayInfo->SetHeight(property_.GetBounds().rect_.GetHeight());
138 displayInfo->SetPhysicalWidth(property_.GetPhyBounds().rect_.GetWidth());
139 displayInfo->SetPhysicalHeight(property_.GetPhyBounds().rect_.GetHeight());
140 displayInfo->SetScreenId(screenId_);
141 displayInfo->SetDisplayId(screenId_);
142 displayInfo->SetRefreshRate(property_.GetRefreshRate());
143 displayInfo->SetVirtualPixelRatio(property_.GetVirtualPixelRatio());
144 displayInfo->SetDensityInCurResolution(property_.GetDensityInCurResolution());
145 displayInfo->SetXDpi(property_.GetXDpi());
146 displayInfo->SetYDpi(property_.GetYDpi());
147 displayInfo->SetDpi(property_.GetVirtualPixelRatio() * DOT_PER_INCH);
148 displayInfo->SetRotation(property_.GetScreenRotation());
149 displayInfo->SetOrientation(property_.GetOrientation());
150 displayInfo->SetOffsetX(property_.GetOffsetX());
151 displayInfo->SetOffsetY(property_.GetOffsetY());
152 displayInfo->SetDisplayOrientation(property_.GetDisplayOrientation());
153 displayInfo->SetHdrFormats(hdrFormats_);
154 displayInfo->SetColorSpaces(colorSpaces_);
155 return displayInfo;
156 }
157
GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> & colorGamuts)158 DMError ScreenSession::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts)
159 {
160 auto ret = RSInterfaces::GetInstance().GetScreenSupportedColorGamuts(rsId_, colorGamuts);
161 if (ret != StatusCode::SUCCESS) {
162 WLOGE("SCB: ScreenSession::GetScreenSupportedColorGamuts fail! rsId %{public}" PRIu64", ret:%{public}d",
163 rsId_, ret);
164 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
165 }
166 WLOGI("SCB: ScreenSession::GetScreenSupportedColorGamuts ok! rsId %{public}" PRIu64", size %{public}u",
167 rsId_, static_cast<uint32_t>(colorGamuts.size()));
168
169 return DMError::DM_OK;
170 }
171
GetName()172 std::string ScreenSession::GetName()
173 {
174 return name_;
175 }
176
SetName(std::string name)177 void ScreenSession::SetName(std::string name)
178 {
179 name_ = name;
180 }
181
GetScreenId()182 ScreenId ScreenSession::GetScreenId()
183 {
184 return screenId_;
185 }
186
GetRSScreenId()187 ScreenId ScreenSession::GetRSScreenId()
188 {
189 return rsId_;
190 }
191
GetScreenProperty() const192 ScreenProperty ScreenSession::GetScreenProperty() const
193 {
194 return property_;
195 }
196
UpdatePropertyByActiveMode()197 void ScreenSession::UpdatePropertyByActiveMode()
198 {
199 sptr<SupportedScreenModes> mode = GetActiveScreenMode();
200 if (mode != nullptr) {
201 auto screeBounds = property_.GetBounds();
202 screeBounds.rect_.width_ = mode->width_;
203 screeBounds.rect_.height_ = mode->height_;
204 property_.SetBounds(screeBounds);
205 }
206 }
207
UpdatePropertyByFoldControl(RRect bounds,RRect phyBounds)208 void ScreenSession::UpdatePropertyByFoldControl(RRect bounds, RRect phyBounds)
209 {
210 property_.SetBounds(bounds);
211 property_.SetPhyBounds(phyBounds);
212 }
213
UpdateRefreshRate(uint32_t refreshRate)214 void ScreenSession::UpdateRefreshRate(uint32_t refreshRate)
215 {
216 property_.SetRefreshRate(refreshRate);
217 }
218
UpdatePropertyByResolution(uint32_t width,uint32_t height)219 void ScreenSession::UpdatePropertyByResolution(uint32_t width, uint32_t height)
220 {
221 auto screenBounds = property_.GetBounds();
222 screenBounds.rect_.width_ = width;
223 screenBounds.rect_.height_ = height;
224 property_.SetBounds(screenBounds);
225 }
226
GetDisplayNode() const227 std::shared_ptr<RSDisplayNode> ScreenSession::GetDisplayNode() const
228 {
229 return displayNode_;
230 }
231
ReleaseDisplayNode()232 void ScreenSession::ReleaseDisplayNode()
233 {
234 displayNode_ = nullptr;
235 }
236
Connect()237 void ScreenSession::Connect()
238 {
239 screenState_ = ScreenState::CONNECTION;
240 for (auto& listener : screenChangeListenerList_) {
241 listener->OnConnect(screenId_);
242 }
243 }
244
Disconnect()245 void ScreenSession::Disconnect()
246 {
247 screenState_ = ScreenState::DISCONNECTION;
248 for (auto& listener : screenChangeListenerList_) {
249 if (!listener) {
250 continue;
251 }
252 listener->OnDisconnect(screenId_);
253 }
254 }
255
PropertyChange(const ScreenProperty & newProperty,ScreenPropertyChangeReason reason)256 void ScreenSession::PropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason)
257 {
258 property_ = newProperty;
259 for (auto& listener : screenChangeListenerList_) {
260 if (!listener) {
261 continue;
262 }
263 listener->OnPropertyChange(newProperty, reason, screenId_);
264 }
265 }
266
PowerStatusChange(DisplayPowerEvent event,EventStatus status,PowerStateChangeReason reason)267 void ScreenSession::PowerStatusChange(DisplayPowerEvent event, EventStatus status, PowerStateChangeReason reason)
268 {
269 for (auto& listener : screenChangeListenerList_) {
270 if (!listener) {
271 continue;
272 }
273 listener->OnPowerStatusChange(event, status, reason);
274 }
275 }
276
ConvertRotationToFloat(Rotation sensorRotation)277 float ScreenSession::ConvertRotationToFloat(Rotation sensorRotation)
278 {
279 float rotation = 0.f;
280 switch (sensorRotation) {
281 case Rotation::ROTATION_90:
282 rotation = 90.f; // degree 90
283 break;
284 case Rotation::ROTATION_180:
285 rotation = 180.f; // degree 180
286 break;
287 case Rotation::ROTATION_270:
288 rotation = 270.f; // degree 270
289 break;
290 default:
291 rotation = 0.f;
292 break;
293 }
294 return rotation;
295 }
296
HandleSensorRotation(float sensorRotation)297 void ScreenSession::HandleSensorRotation(float sensorRotation)
298 {
299 SensorRotationChange(sensorRotation);
300 }
301
SensorRotationChange(Rotation sensorRotation)302 void ScreenSession::SensorRotationChange(Rotation sensorRotation)
303 {
304 float rotation = ConvertRotationToFloat(sensorRotation);
305 SensorRotationChange(rotation);
306 }
307
SensorRotationChange(float sensorRotation)308 void ScreenSession::SensorRotationChange(float sensorRotation)
309 {
310 for (auto& listener : screenChangeListenerList_) {
311 listener->OnSensorRotationChange(sensorRotation, screenId_);
312 }
313 }
314
ScreenOrientationChange(Orientation orientation,FoldDisplayMode foldDisplayMode)315 void ScreenSession::ScreenOrientationChange(Orientation orientation, FoldDisplayMode foldDisplayMode)
316 {
317 Rotation rotationAfter = CalcRotation(orientation, foldDisplayMode);
318 float screenRotation = ConvertRotationToFloat(rotationAfter);
319 ScreenOrientationChange(screenRotation);
320 }
321
ScreenOrientationChange(float orientation)322 void ScreenSession::ScreenOrientationChange(float orientation)
323 {
324 for (auto& listener : screenChangeListenerList_) {
325 listener->OnScreenOrientationChange(orientation, screenId_);
326 }
327 }
328
ConvertIntToRotation(int rotation)329 Rotation ScreenSession::ConvertIntToRotation(int rotation)
330 {
331 Rotation targetRotation = Rotation::ROTATION_0;
332 switch (rotation) {
333 case 90: // Rotation 90 degree
334 targetRotation = Rotation::ROTATION_90;
335 break;
336 case 180: // Rotation 180 degree
337 targetRotation = Rotation::ROTATION_180;
338 break;
339 case 270: // Rotation 270 degree
340 targetRotation = Rotation::ROTATION_270;
341 break;
342 default:
343 targetRotation = Rotation::ROTATION_0;
344 break;
345 }
346 return targetRotation;
347 }
348
SetUpdateToInputManagerCallback(std::function<void (float)> updateToInputManagerCallback)349 void ScreenSession::SetUpdateToInputManagerCallback(std::function<void(float)> updateToInputManagerCallback)
350 {
351 updateToInputManagerCallback_ = updateToInputManagerCallback;
352 }
353
UpdateToInputManager(RRect bounds,int rotation,FoldDisplayMode foldDisplayMode)354 void ScreenSession::UpdateToInputManager(RRect bounds, int rotation, FoldDisplayMode foldDisplayMode)
355 {
356 bool needUpdateToInputManager = false;
357 if (foldDisplayMode == FoldDisplayMode::FULL &&
358 property_.GetBounds() == bounds && property_.GetRotation() != static_cast<float>(rotation)) {
359 needUpdateToInputManager = true;
360 }
361 Rotation targetRotation = ConvertIntToRotation(rotation);
362 DisplayOrientation displayOrientation = CalcDisplayOrientation(targetRotation, foldDisplayMode);
363 property_.SetBounds(bounds);
364 property_.SetRotation(static_cast<float>(rotation));
365 property_.UpdateScreenRotation(targetRotation);
366 property_.SetDisplayOrientation(displayOrientation);
367 if (needUpdateToInputManager && updateToInputManagerCallback_ != nullptr) {
368 // fold phone need fix 90 degree by remainder 360 degree
369 int foldRotation = (rotation + 90) % 360;
370 updateToInputManagerCallback_(static_cast<float>(foldRotation));
371 WLOGFI("updateToInputManagerCallback_:%{public}d", foldRotation);
372 }
373 }
374
UpdatePropertyAfterRotation(RRect bounds,int rotation,FoldDisplayMode foldDisplayMode)375 void ScreenSession::UpdatePropertyAfterRotation(RRect bounds, int rotation, FoldDisplayMode foldDisplayMode)
376 {
377 Rotation targetRotation = ConvertIntToRotation(rotation);
378 DisplayOrientation displayOrientation = CalcDisplayOrientation(targetRotation, foldDisplayMode);
379 property_.SetBounds(bounds);
380 property_.SetRotation(static_cast<float>(rotation));
381 property_.UpdateScreenRotation(targetRotation);
382 property_.SetDisplayOrientation(displayOrientation);
383 if (!displayNode_) {
384 WLOGFI("update failed since null display node with rotation:%{public}d displayOrientation:%{public}u",
385 rotation, displayOrientation);
386 return;
387 }
388 auto transactionProxy = RSTransactionProxy::GetInstance();
389 if (transactionProxy != nullptr) {
390 transactionProxy->Begin();
391 displayNode_->SetScreenRotation(static_cast<uint32_t>(targetRotation));
392 transactionProxy->Commit();
393 } else {
394 displayNode_->SetScreenRotation(static_cast<uint32_t>(targetRotation));
395 }
396 WLOGFI("bounds:[%{public}f %{public}f %{public}f %{public}f],rotation:%{public}d,displayOrientation:%{public}u",
397 property_.GetBounds().rect_.GetLeft(), property_.GetBounds().rect_.GetTop(),
398 property_.GetBounds().rect_.GetWidth(), property_.GetBounds().rect_.GetHeight(),
399 rotation, displayOrientation);
400 }
401
GetActiveScreenMode() const402 sptr<SupportedScreenModes> ScreenSession::GetActiveScreenMode() const
403 {
404 if (activeIdx_ < 0 || activeIdx_ >= static_cast<int32_t>(modes_.size())) {
405 WLOGW("SCB: ScreenSession::GetActiveScreenMode active mode index is wrong: %{public}d", activeIdx_);
406 return nullptr;
407 }
408 return modes_[activeIdx_];
409 }
410
GetOrientation() const411 Orientation ScreenSession::GetOrientation() const
412 {
413 return property_.GetOrientation();
414 }
415
SetOrientation(Orientation orientation)416 void ScreenSession::SetOrientation(Orientation orientation)
417 {
418 property_.SetOrientation(orientation);
419 }
420
GetRotation() const421 Rotation ScreenSession::GetRotation() const
422 {
423 return property_.GetScreenRotation();
424 }
425
SetRotation(Rotation rotation)426 void ScreenSession::SetRotation(Rotation rotation)
427 {
428 property_.SetScreenRotation(rotation);
429 }
430
SetScreenRequestedOrientation(Orientation orientation)431 void ScreenSession::SetScreenRequestedOrientation(Orientation orientation)
432 {
433 property_.SetScreenRequestedOrientation(orientation);
434 }
435
SetScreenRotationLocked(bool isLocked)436 void ScreenSession::SetScreenRotationLocked(bool isLocked)
437 {
438 {
439 std::lock_guard<std::recursive_mutex> lock(mutex_);
440 isScreenLocked_ = isLocked;
441 }
442 for (auto& listener : screenChangeListenerList_) {
443 if (!listener) {
444 continue;
445 }
446 listener->OnScreenRotationLockedChange(isLocked, screenId_);
447 }
448 }
449
SetScreenRotationLockedFromJs(bool isLocked)450 void ScreenSession::SetScreenRotationLockedFromJs(bool isLocked)
451 {
452 std::lock_guard<std::recursive_mutex> lock(mutex_);
453 isScreenLocked_ = isLocked;
454 }
455
IsScreenRotationLocked()456 bool ScreenSession::IsScreenRotationLocked()
457 {
458 std::lock_guard<std::recursive_mutex> lock(mutex_);
459 return isScreenLocked_;
460 }
461
GetScreenRequestedOrientation() const462 Orientation ScreenSession::GetScreenRequestedOrientation() const
463 {
464 return property_.GetScreenRequestedOrientation();
465 }
466
SetVirtualPixelRatio(float virtualPixelRatio)467 void ScreenSession::SetVirtualPixelRatio(float virtualPixelRatio)
468 {
469 property_.SetVirtualPixelRatio(virtualPixelRatio);
470 }
471
SetDensityInCurResolution(float densityInCurResolution)472 void ScreenSession::SetDensityInCurResolution(float densityInCurResolution)
473 {
474 property_.SetDensityInCurResolution(densityInCurResolution);
475 }
476
SetScreenType(ScreenType type)477 void ScreenSession::SetScreenType(ScreenType type)
478 {
479 property_.SetScreenType(type);
480 }
481
CalcRotation(Orientation orientation,FoldDisplayMode foldDisplayMode) const482 Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode foldDisplayMode) const
483 {
484 sptr<SupportedScreenModes> info = GetActiveScreenMode();
485 if (info == nullptr) {
486 return Rotation::ROTATION_0;
487 }
488 // vertical: phone(Plugin screen); horizontal: pad & external screen
489 bool isVerticalScreen = info->width_ < info->height_;
490 if (foldDisplayMode != FoldDisplayMode::UNKNOWN) {
491 isVerticalScreen = info->width_ > info->height_;
492 }
493 switch (orientation) {
494 case Orientation::UNSPECIFIED: {
495 return Rotation::ROTATION_0;
496 }
497 case Orientation::VERTICAL: {
498 return isVerticalScreen ? Rotation::ROTATION_0 : Rotation::ROTATION_90;
499 }
500 case Orientation::HORIZONTAL: {
501 return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_0;
502 }
503 case Orientation::REVERSE_VERTICAL: {
504 return isVerticalScreen ? Rotation::ROTATION_180 : Rotation::ROTATION_270;
505 }
506 case Orientation::REVERSE_HORIZONTAL: {
507 return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_180;
508 }
509 default: {
510 WLOGE("unknown orientation %{public}u", orientation);
511 return Rotation::ROTATION_0;
512 }
513 }
514 }
515
CalcDisplayOrientation(Rotation rotation,FoldDisplayMode foldDisplayMode) const516 DisplayOrientation ScreenSession::CalcDisplayOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode) const
517 {
518 sptr<SupportedScreenModes> info = GetActiveScreenMode();
519 if (info == nullptr) {
520 return DisplayOrientation::UNKNOWN;
521 }
522 // vertical: phone(Plugin screen); horizontal: pad & external screen
523 bool isVerticalScreen = info->width_ < info->height_;
524 if (foldDisplayMode != FoldDisplayMode::UNKNOWN) {
525 isVerticalScreen = info->width_ > info->height_;
526 }
527 switch (rotation) {
528 case Rotation::ROTATION_0: {
529 return isVerticalScreen ? DisplayOrientation::PORTRAIT : DisplayOrientation::LANDSCAPE;
530 }
531 case Rotation::ROTATION_90: {
532 return isVerticalScreen ? DisplayOrientation::LANDSCAPE : DisplayOrientation::PORTRAIT;
533 }
534 case Rotation::ROTATION_180: {
535 return isVerticalScreen ? DisplayOrientation::PORTRAIT_INVERTED : DisplayOrientation::LANDSCAPE_INVERTED;
536 }
537 case Rotation::ROTATION_270: {
538 return isVerticalScreen ? DisplayOrientation::LANDSCAPE_INVERTED : DisplayOrientation::PORTRAIT_INVERTED;
539 }
540 default: {
541 WLOGE("unknown rotation %{public}u", rotation);
542 return DisplayOrientation::UNKNOWN;
543 }
544 }
545 }
546
GetSourceMode() const547 ScreenSourceMode ScreenSession::GetSourceMode() const
548 {
549 if (screenId_ == defaultScreenId_) {
550 return ScreenSourceMode::SCREEN_MAIN;
551 }
552 ScreenCombination combination = GetScreenCombination();
553 switch (combination) {
554 case ScreenCombination::SCREEN_MIRROR: {
555 return ScreenSourceMode::SCREEN_MIRROR;
556 }
557 case ScreenCombination::SCREEN_EXPAND: {
558 return ScreenSourceMode::SCREEN_EXTEND;
559 }
560 case ScreenCombination::SCREEN_ALONE: {
561 return ScreenSourceMode::SCREEN_ALONE;
562 }
563 default: {
564 return ScreenSourceMode::SCREEN_ALONE;
565 }
566 }
567 }
568
SetScreenCombination(ScreenCombination combination)569 void ScreenSession::SetScreenCombination(ScreenCombination combination)
570 {
571 combination_ = combination;
572 }
573
GetScreenCombination() const574 ScreenCombination ScreenSession::GetScreenCombination() const
575 {
576 return combination_;
577 }
578
FillScreenInfo(sptr<ScreenInfo> info) const579 void ScreenSession::FillScreenInfo(sptr<ScreenInfo> info) const
580 {
581 if (info == nullptr) {
582 WLOGE("FillScreenInfo failed! info is nullptr");
583 return;
584 }
585 info->SetScreenId(screenId_);
586 info->SetName(name_);
587 uint32_t width = 0;
588 uint32_t height = 0;
589 sptr<SupportedScreenModes> screenSessionModes = GetActiveScreenMode();
590 if (screenSessionModes != nullptr) {
591 height = screenSessionModes->height_;
592 width = screenSessionModes->width_;
593 }
594 float virtualPixelRatio = property_.GetVirtualPixelRatio();
595 // "< 1e-set6" means virtualPixelRatio is 0.
596 if (fabsf(virtualPixelRatio) < 1e-6) {
597 virtualPixelRatio = 1.0f;
598 }
599 ScreenSourceMode sourceMode = GetSourceMode();
600 info->SetVirtualPixelRatio(property_.GetVirtualPixelRatio());
601 info->SetVirtualHeight(height / virtualPixelRatio);
602 info->SetVirtualWidth(width / virtualPixelRatio);
603 info->SetRotation(property_.GetScreenRotation());
604 info->SetOrientation(static_cast<Orientation>(property_.GetDisplayOrientation()));
605 info->SetSourceMode(sourceMode);
606 info->SetType(property_.GetScreenType());
607 info->SetModeId(activeIdx_);
608
609 info->lastParent_ = lastGroupSmsId_;
610 info->parent_ = groupSmsId_;
611 info->isScreenGroup_ = isScreenGroup_;
612 info->modes_ = modes_;
613 }
614
ConvertToScreenInfo() const615 sptr<ScreenInfo> ScreenSession::ConvertToScreenInfo() const
616 {
617 sptr<ScreenInfo> info = new(std::nothrow) ScreenInfo();
618 if (info == nullptr) {
619 return nullptr;
620 }
621 FillScreenInfo(info);
622 return info;
623 }
624
GetScreenColorGamut(ScreenColorGamut & colorGamut)625 DMError ScreenSession::GetScreenColorGamut(ScreenColorGamut& colorGamut)
626 {
627 auto ret = RSInterfaces::GetInstance().GetScreenColorGamut(rsId_, colorGamut);
628 if (ret != StatusCode::SUCCESS) {
629 WLOGE("GetScreenColorGamut fail! rsId %{public}" PRIu64"", rsId_);
630 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
631 }
632 WLOGI("GetScreenColorGamut ok! rsId %{public}" PRIu64", colorGamut %{public}u",
633 rsId_, static_cast<uint32_t>(colorGamut));
634 return DMError::DM_OK;
635 }
636
SetScreenColorGamut(int32_t colorGamutIdx)637 DMError ScreenSession::SetScreenColorGamut(int32_t colorGamutIdx)
638 {
639 std::vector<ScreenColorGamut> colorGamuts;
640 DMError res = GetScreenSupportedColorGamuts(colorGamuts);
641 if (res != DMError::DM_OK) {
642 WLOGE("SetScreenColorGamut fail! rsId %{public}" PRIu64"", rsId_);
643 return res;
644 }
645 if (colorGamutIdx < 0 || colorGamutIdx >= static_cast<int32_t>(colorGamuts.size())) {
646 WLOGE("SetScreenColorGamut fail! rsId %{public}" PRIu64" colorGamutIdx %{public}d invalid.",
647 rsId_, colorGamutIdx);
648 return DMError::DM_ERROR_INVALID_PARAM;
649 }
650 auto ret = RSInterfaces::GetInstance().SetScreenColorGamut(rsId_, colorGamutIdx);
651 if (ret != StatusCode::SUCCESS) {
652 WLOGE("SetScreenColorGamut fail! rsId %{public}" PRIu64"", rsId_);
653 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
654 }
655 WLOGI("SetScreenColorGamut ok! rsId %{public}" PRIu64", colorGamutIdx %{public}u",
656 rsId_, colorGamutIdx);
657 return DMError::DM_OK;
658 }
659
GetScreenGamutMap(ScreenGamutMap & gamutMap)660 DMError ScreenSession::GetScreenGamutMap(ScreenGamutMap& gamutMap)
661 {
662 auto ret = RSInterfaces::GetInstance().GetScreenGamutMap(rsId_, gamutMap);
663 if (ret != StatusCode::SUCCESS) {
664 WLOGE("GetScreenGamutMap fail! rsId %{public}" PRIu64"", rsId_);
665 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
666 }
667 WLOGI("GetScreenGamutMap ok! rsId %{public}" PRIu64", gamutMap %{public}u",
668 rsId_, static_cast<uint32_t>(gamutMap));
669 return DMError::DM_OK;
670 }
671
SetScreenGamutMap(ScreenGamutMap gamutMap)672 DMError ScreenSession::SetScreenGamutMap(ScreenGamutMap gamutMap)
673 {
674 if (gamutMap > GAMUT_MAP_HDR_EXTENSION) {
675 return DMError::DM_ERROR_INVALID_PARAM;
676 }
677 auto ret = RSInterfaces::GetInstance().SetScreenGamutMap(rsId_, gamutMap);
678 if (ret != StatusCode::SUCCESS) {
679 WLOGE("SetScreenGamutMap fail! rsId %{public}" PRIu64"", rsId_);
680 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
681 }
682 WLOGI("SetScreenGamutMap ok! rsId %{public}" PRIu64", gamutMap %{public}u",
683 rsId_, static_cast<uint32_t>(gamutMap));
684 return DMError::DM_OK;
685 }
686
SetScreenColorTransform()687 DMError ScreenSession::SetScreenColorTransform()
688 {
689 WLOGI("SetScreenColorTransform ok! rsId %{public}" PRIu64"", rsId_);
690 return DMError::DM_OK;
691 }
692
GetPixelFormat(GraphicPixelFormat & pixelFormat)693 DMError ScreenSession::GetPixelFormat(GraphicPixelFormat& pixelFormat)
694 {
695 auto ret = RSInterfaces::GetInstance().GetPixelFormat(rsId_, pixelFormat);
696 if (ret != StatusCode::SUCCESS) {
697 WLOGE("GetPixelFormat fail! rsId %{public}" PRIu64, rsId_);
698 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
699 }
700 WLOGI("GetPixelFormat ok! rsId %{public}" PRIu64 ", pixelFormat %{public}u",
701 rsId_, static_cast<uint32_t>(pixelFormat));
702 return DMError::DM_OK;
703 }
704
SetPixelFormat(GraphicPixelFormat pixelFormat)705 DMError ScreenSession::SetPixelFormat(GraphicPixelFormat pixelFormat)
706 {
707 if (pixelFormat > GRAPHIC_PIXEL_FMT_VENDER_MASK) {
708 return DMError::DM_ERROR_INVALID_PARAM;
709 }
710 auto ret = RSInterfaces::GetInstance().SetPixelFormat(rsId_, pixelFormat);
711 if (ret != StatusCode::SUCCESS) {
712 WLOGE("SetPixelFormat fail! rsId %{public}" PRIu64, rsId_);
713 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
714 }
715 WLOGI("SetPixelFormat ok! rsId %{public}" PRIu64 ", gamutMap %{public}u",
716 rsId_, static_cast<uint32_t>(pixelFormat));
717 return DMError::DM_OK;
718 }
719
GetSupportedHDRFormats(std::vector<ScreenHDRFormat> & hdrFormats)720 DMError ScreenSession::GetSupportedHDRFormats(std::vector<ScreenHDRFormat>& hdrFormats)
721 {
722 auto ret = RSInterfaces::GetInstance().GetScreenSupportedHDRFormats(rsId_, hdrFormats);
723 if (ret != StatusCode::SUCCESS) {
724 WLOGE("SCB: ScreenSession::GetSupportedHDRFormats fail! rsId %{public}" PRIu64 ", ret:%{public}d",
725 rsId_, ret);
726 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
727 }
728 WLOGI("SCB: ScreenSession::GetSupportedHDRFormats ok! rsId %{public}" PRIu64 ", size %{public}u",
729 rsId_, static_cast<uint32_t>(hdrFormats.size()));
730
731 return DMError::DM_OK;
732 }
733
GetScreenHDRFormat(ScreenHDRFormat & hdrFormat)734 DMError ScreenSession::GetScreenHDRFormat(ScreenHDRFormat& hdrFormat)
735 {
736 auto ret = RSInterfaces::GetInstance().GetScreenHDRFormat(rsId_, hdrFormat);
737 if (ret != StatusCode::SUCCESS) {
738 WLOGE("GetScreenHDRFormat fail! rsId %{public}" PRIu64, rsId_);
739 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
740 }
741 WLOGI("GetScreenHDRFormat ok! rsId %{public}" PRIu64 ", colorSpace %{public}u",
742 rsId_, static_cast<uint32_t>(hdrFormat));
743 return DMError::DM_OK;
744 }
745
SetScreenHDRFormat(int32_t modeIdx)746 DMError ScreenSession::SetScreenHDRFormat(int32_t modeIdx)
747 {
748 std::vector<ScreenHDRFormat> hdrFormats;
749 DMError res = GetSupportedHDRFormats(hdrFormats);
750 if (res != DMError::DM_OK) {
751 WLOGE("SetScreenHDRFormat fail! rsId %{public}" PRIu64, rsId_);
752 return res;
753 }
754 if (modeIdx < 0 || modeIdx >= static_cast<int32_t>(hdrFormats.size())) {
755 WLOGE("SetScreenHDRFormat fail! rsId %{public}" PRIu64 " modeIdx %{public}d invalid.",
756 rsId_, modeIdx);
757 return DMError::DM_ERROR_INVALID_PARAM;
758 }
759 auto ret = RSInterfaces::GetInstance().SetScreenHDRFormat(rsId_, modeIdx);
760 if (ret != StatusCode::SUCCESS) {
761 WLOGE("SetScreenHDRFormat fail! rsId %{public}" PRIu64, rsId_);
762 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
763 }
764 WLOGI("SetScreenHDRFormat ok! rsId %{public}" PRIu64 ", modeIdx %{public}u",
765 rsId_, modeIdx);
766 return DMError::DM_OK;
767 }
768
GetSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType> & colorSpaces)769 DMError ScreenSession::GetSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType>& colorSpaces)
770 {
771 auto ret = RSInterfaces::GetInstance().GetScreenSupportedColorSpaces(rsId_, colorSpaces);
772 if (ret != StatusCode::SUCCESS) {
773 WLOGE("SCB: ScreenSession::GetSupportedColorSpaces fail! rsId %{public}" PRIu64 ", ret:%{public}d",
774 rsId_, ret);
775 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
776 }
777 WLOGI("SCB: ScreenSession::GetSupportedColorSpaces ok! rsId %{public}" PRIu64 ", size %{public}u",
778 rsId_, static_cast<uint32_t>(colorSpaces.size()));
779 return DMError::DM_OK;
780 }
781
GetScreenColorSpace(GraphicCM_ColorSpaceType & colorSpace)782 DMError ScreenSession::GetScreenColorSpace(GraphicCM_ColorSpaceType& colorSpace)
783 {
784 auto ret = RSInterfaces::GetInstance().GetScreenColorSpace(rsId_, colorSpace);
785 if (ret != StatusCode::SUCCESS) {
786 WLOGE("GetScreenColorSpace fail! rsId %{public}" PRIu64, rsId_);
787 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
788 }
789 WLOGI("GetScreenColorSpace ok! rsId %{public}" PRIu64 ", colorSpace %{public}u",
790 rsId_, static_cast<uint32_t>(colorSpace));
791 return DMError::DM_OK;
792 }
793
SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace)794 DMError ScreenSession::SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace)
795 {
796 std::vector<GraphicCM_ColorSpaceType> colorSpaces;
797 DMError res = GetSupportedColorSpaces(colorSpaces);
798 if (res != DMError::DM_OK) {
799 WLOGE("SetScreenColorSpace fail! rsId %{public}" PRIu64, rsId_);
800 return res;
801 }
802 if (colorSpace < 0 || static_cast<int32_t>(colorSpace) >= static_cast<int32_t>(colorSpaces.size())) {
803 WLOGE("SetScreenColorSpace fail! rsId %{public}" PRIu64 " colorSpace %{public}d invalid.",
804 rsId_, colorSpace);
805 return DMError::DM_ERROR_INVALID_PARAM;
806 }
807 auto ret = RSInterfaces::GetInstance().SetScreenColorSpace(rsId_, colorSpace);
808 if (ret != StatusCode::SUCCESS) {
809 WLOGE("SetScreenColorSpace fail! rsId %{public}" PRIu64, rsId_);
810 return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
811 }
812 WLOGI("SetScreenColorSpace ok! rsId %{public}" PRIu64 ", colorSpace %{public}u",
813 rsId_, colorSpace);
814 return DMError::DM_OK;
815 }
816
HasPrivateSessionForeground() const817 bool ScreenSession::HasPrivateSessionForeground() const
818 {
819 return hasPrivateWindowForeground_;
820 }
821
SetPrivateSessionForeground(bool hasPrivate)822 void ScreenSession::SetPrivateSessionForeground(bool hasPrivate)
823 {
824 hasPrivateWindowForeground_ = hasPrivate;
825 }
826
InitRSDisplayNode(RSDisplayNodeConfig & config,Point & startPoint)827 void ScreenSession::InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint)
828 {
829 if (displayNode_ != nullptr) {
830 displayNode_->SetDisplayNodeMirrorConfig(config);
831 if (screenId_ == 0 && isFold_) {
832 WLOGFI("Return InitRSDisplayNode flodScreen0");
833 return;
834 }
835 } else {
836 std::shared_ptr<RSDisplayNode> rsDisplayNode = RSDisplayNode::Create(config);
837 if (rsDisplayNode == nullptr) {
838 WLOGE("fail to add child. create rsDisplayNode fail!");
839 return;
840 }
841 displayNode_ = rsDisplayNode;
842 }
843 WLOGFI("SetDisplayOffset: posX:%{public}d, posY:%{public}d", startPoint.posX_, startPoint.posY_);
844 displayNode_->SetDisplayOffset(startPoint.posX_, startPoint.posY_);
845 uint32_t width = 0;
846 uint32_t height = 0;
847 sptr<SupportedScreenModes> abstractScreenModes = GetActiveScreenMode();
848 if (abstractScreenModes != nullptr) {
849 height = abstractScreenModes->height_;
850 width = abstractScreenModes->width_;
851 }
852 RSScreenType screenType;
853 auto ret = RSInterfaces::GetInstance().GetScreenType(rsId_, screenType);
854 if (ret == StatusCode::SUCCESS && screenType == RSScreenType::VIRTUAL_TYPE_SCREEN) {
855 displayNode_->SetSecurityDisplay(true);
856 WLOGFI("virtualScreen SetSecurityDisplay success");
857 }
858 // If setDisplayOffset is not valid for SetFrame/SetBounds
859 WLOGFI("InitRSDisplayNode screnId:%{public}" PRIu64" width:%{public}u height:%{public}u", screenId_, width, height);
860 displayNode_->SetFrame(0, 0, width, height);
861 displayNode_->SetBounds(0, 0, width, height);
862 auto transactionProxy = RSTransactionProxy::GetInstance();
863 if (transactionProxy != nullptr) {
864 transactionProxy->FlushImplicitTransaction();
865 }
866 }
867
ScreenSessionGroup(ScreenId screenId,ScreenId rsId,std::string name,ScreenCombination combination)868 ScreenSessionGroup::ScreenSessionGroup(ScreenId screenId, ScreenId rsId,
869 std::string name, ScreenCombination combination) : combination_(combination)
870 {
871 name_ = name;
872 screenId_ = screenId;
873 rsId_ = rsId;
874 SetScreenType(ScreenType::UNDEFINED);
875 isScreenGroup_ = true;
876 }
877
~ScreenSessionGroup()878 ScreenSessionGroup::~ScreenSessionGroup()
879 {
880 ReleaseDisplayNode();
881 screenSessionMap_.clear();
882 }
883
GetRSDisplayNodeConfig(sptr<ScreenSession> & screenSession,struct RSDisplayNodeConfig & config,sptr<ScreenSession> defaultScreenSession)884 bool ScreenSessionGroup::GetRSDisplayNodeConfig(sptr<ScreenSession>& screenSession, struct RSDisplayNodeConfig& config,
885 sptr<ScreenSession> defaultScreenSession)
886 {
887 if (screenSession == nullptr) {
888 WLOGE("screenSession is nullptr.");
889 return false;
890 }
891 config = { screenSession->rsId_ };
892 switch (combination_) {
893 case ScreenCombination::SCREEN_ALONE:
894 [[fallthrough]];
895 case ScreenCombination::SCREEN_EXPAND:
896 break;
897 case ScreenCombination::SCREEN_UNIQUE:
898 break;
899 case ScreenCombination::SCREEN_MIRROR: {
900 if (GetChildCount() == 0 || mirrorScreenId_ == screenSession->screenId_) {
901 WLOGI("AddChild, SCREEN_MIRROR, config is not mirror");
902 break;
903 }
904 if (defaultScreenSession == nullptr) {
905 WLOGFE("AddChild fail, defaultScreenSession is nullptr");
906 break;
907 }
908 std::shared_ptr<RSDisplayNode> displayNode = defaultScreenSession->GetDisplayNode();
909 if (displayNode == nullptr) {
910 WLOGFE("AddChild fail, displayNode is nullptr, cannot get DisplayNode");
911 break;
912 }
913 NodeId nodeId = displayNode->GetId();
914 WLOGI("AddChild, mirrorScreenId_:%{public}" PRIu64", rsId_:%{public}" PRIu64", nodeId:%{public}" PRIu64"",
915 mirrorScreenId_, screenSession->rsId_, nodeId);
916 config = {screenSession->rsId_, true, nodeId};
917 break;
918 }
919 default:
920 WLOGE("fail to add child. invalid group combination:%{public}u", combination_);
921 return false;
922 }
923 return true;
924 }
925
AddChild(sptr<ScreenSession> & smsScreen,Point & startPoint,sptr<ScreenSession> defaultScreenSession)926 bool ScreenSessionGroup::AddChild(sptr<ScreenSession>& smsScreen, Point& startPoint,
927 sptr<ScreenSession> defaultScreenSession)
928 {
929 if (smsScreen == nullptr) {
930 WLOGE("AddChild, smsScreen is nullptr.");
931 return false;
932 }
933 ScreenId screenId = smsScreen->screenId_;
934 auto iter = screenSessionMap_.find(screenId);
935 if (iter != screenSessionMap_.end()) {
936 WLOGE("AddChild, screenSessionMap_ has smsScreen:%{public}" PRIu64"", screenId);
937 return false;
938 }
939 struct RSDisplayNodeConfig config;
940 if (!GetRSDisplayNodeConfig(smsScreen, config, defaultScreenSession)) {
941 return false;
942 }
943 smsScreen->InitRSDisplayNode(config, startPoint);
944 smsScreen->lastGroupSmsId_ = smsScreen->groupSmsId_;
945 smsScreen->groupSmsId_ = screenId_;
946 screenSessionMap_.insert(std::make_pair(screenId, std::make_pair(smsScreen, startPoint)));
947 return true;
948 }
949
AddChildren(std::vector<sptr<ScreenSession>> & smsScreens,std::vector<Point> & startPoints)950 bool ScreenSessionGroup::AddChildren(std::vector<sptr<ScreenSession>>& smsScreens, std::vector<Point>& startPoints)
951 {
952 size_t size = smsScreens.size();
953 if (size != startPoints.size()) {
954 WLOGE("AddChildren, unequal size.");
955 return false;
956 }
957 bool res = true;
958 for (size_t i = 0; i < size; i++) {
959 res = AddChild(smsScreens[i], startPoints[i], nullptr) && res;
960 }
961 return res;
962 }
963
RemoveChild(sptr<ScreenSession> & smsScreen)964 bool ScreenSessionGroup::RemoveChild(sptr<ScreenSession>& smsScreen)
965 {
966 if (smsScreen == nullptr) {
967 WLOGE("RemoveChild, smsScreen is nullptr.");
968 return false;
969 }
970 ScreenId screenId = smsScreen->screenId_;
971 smsScreen->lastGroupSmsId_ = smsScreen->groupSmsId_;
972 smsScreen->groupSmsId_ = SCREEN_ID_INVALID;
973 if (smsScreen->GetDisplayNode() != nullptr) {
974 smsScreen->GetDisplayNode()->SetDisplayOffset(0, 0);
975 smsScreen->GetDisplayNode()->RemoveFromTree();
976 auto transactionProxy = RSTransactionProxy::GetInstance();
977 if (transactionProxy != nullptr) {
978 transactionProxy->FlushImplicitTransaction();
979 }
980 smsScreen->ReleaseDisplayNode();
981 }
982 return screenSessionMap_.erase(screenId);
983 }
984
HasChild(ScreenId childScreen) const985 bool ScreenSessionGroup::HasChild(ScreenId childScreen) const
986 {
987 return screenSessionMap_.find(childScreen) != screenSessionMap_.end();
988 }
989
GetChildren() const990 std::vector<sptr<ScreenSession>> ScreenSessionGroup::GetChildren() const
991 {
992 std::vector<sptr<ScreenSession>> res;
993 for (auto iter = screenSessionMap_.begin(); iter != screenSessionMap_.end(); iter++) {
994 res.push_back(iter->second.first);
995 }
996 return res;
997 }
998
GetChildrenPosition() const999 std::vector<Point> ScreenSessionGroup::GetChildrenPosition() const
1000 {
1001 std::vector<Point> res;
1002 for (auto iter = screenSessionMap_.begin(); iter != screenSessionMap_.end(); iter++) {
1003 res.push_back(iter->second.second);
1004 }
1005 return res;
1006 }
1007
GetChildPosition(ScreenId screenId) const1008 Point ScreenSessionGroup::GetChildPosition(ScreenId screenId) const
1009 {
1010 Point point;
1011 auto iter = screenSessionMap_.find(screenId);
1012 if (iter != screenSessionMap_.end()) {
1013 point = iter->second.second;
1014 }
1015 return point;
1016 }
1017
GetChildCount() const1018 size_t ScreenSessionGroup::GetChildCount() const
1019 {
1020 return screenSessionMap_.size();
1021 }
1022
GetScreenCombination() const1023 ScreenCombination ScreenSessionGroup::GetScreenCombination() const
1024 {
1025 return combination_;
1026 }
1027
ConvertToScreenGroupInfo() const1028 sptr<ScreenGroupInfo> ScreenSessionGroup::ConvertToScreenGroupInfo() const
1029 {
1030 sptr<ScreenGroupInfo> screenGroupInfo = new(std::nothrow) ScreenGroupInfo();
1031 if (screenGroupInfo == nullptr) {
1032 return nullptr;
1033 }
1034 FillScreenInfo(screenGroupInfo);
1035 screenGroupInfo->combination_ = combination_;
1036 for (auto iter = screenSessionMap_.begin(); iter != screenSessionMap_.end(); iter++) {
1037 screenGroupInfo->children_.push_back(iter->first);
1038 }
1039 auto positions = GetChildrenPosition();
1040 screenGroupInfo->position_.insert(screenGroupInfo->position_.end(), positions.begin(), positions.end());
1041 return screenGroupInfo;
1042 }
1043
SetDisplayBoundary(const RectF & rect,const uint32_t & offsetY)1044 void ScreenSession::SetDisplayBoundary(const RectF& rect, const uint32_t& offsetY)
1045 {
1046 property_.SetOffsetY(offsetY);
1047 property_.SetBounds(RRect(rect, 0.0f, 0.0f));
1048 }
1049
Resize(uint32_t width,uint32_t height)1050 void ScreenSession::Resize(uint32_t width, uint32_t height)
1051 {
1052 sptr<SupportedScreenModes> screenMode = GetActiveScreenMode();
1053 if (screenMode != nullptr) {
1054 screenMode->width_ = width;
1055 screenMode->height_ = height;
1056 UpdatePropertyByActiveMode();
1057 }
1058 }
1059
UpdateAvailableArea(DMRect area)1060 bool ScreenSession::UpdateAvailableArea(DMRect area)
1061 {
1062 if (property_.GetAvailableArea() == area) {
1063 return false;
1064 }
1065 property_.SetAvailableArea(area);
1066 return true;
1067 }
1068
SetAvailableArea(DMRect area)1069 void ScreenSession::SetAvailableArea(DMRect area)
1070 {
1071 property_.SetAvailableArea(area);
1072 }
1073
GetAvailableArea()1074 DMRect ScreenSession::GetAvailableArea()
1075 {
1076 return property_.GetAvailableArea();
1077 }
1078
SetFoldScreen(bool isFold)1079 void ScreenSession::SetFoldScreen(bool isFold)
1080 {
1081 WLOGFI("SetFoldScreen %{public}u", isFold);
1082 isFold_ = isFold;
1083 }
1084
SetHdrFormats(std::vector<uint32_t> && hdrFormats)1085 void ScreenSession::SetHdrFormats(std::vector<uint32_t>&& hdrFormats)
1086 {
1087 hdrFormats_ = std::move(hdrFormats);
1088 }
1089
SetColorSpaces(std::vector<uint32_t> && colorSpaces)1090 void ScreenSession::SetColorSpaces(std::vector<uint32_t>&& colorSpaces)
1091 {
1092 colorSpaces_ = std::move(colorSpaces);
1093 }
1094
GetScreenSnapshot(float scaleX,float scaleY)1095 std::shared_ptr<Media::PixelMap> ScreenSession::GetScreenSnapshot(float scaleX, float scaleY)
1096 {
1097 if (displayNode_ == nullptr) {
1098 WLOGFE("get screen snapshot displayNode_ is null");
1099 return nullptr;
1100 }
1101
1102 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ss:GetScreenSnapshot");
1103 auto callback = std::make_shared<SurfaceCaptureFuture>();
1104 bool ret = RSInterfaces::GetInstance().TakeSurfaceCapture(displayNode_, callback, scaleX, scaleY);
1105 if (!ret) {
1106 WLOGFE("get screen snapshot TakeSurfaceCapture failed");
1107 return nullptr;
1108 }
1109
1110 auto pixelMap = callback->GetResult(2000);
1111 if (pixelMap != nullptr) {
1112 WLOGFD("save pixelMap WxH = %{public}dx%{public}d", pixelMap->GetWidth(), pixelMap->GetHeight());
1113 } else {
1114 WLOGFE("failed to get pixelMap, return nullptr");
1115 }
1116 return pixelMap;
1117 }
1118 } // namespace OHOS::Rosen
1119