diff --git a/window_scene/screen_session_manager/src/screen_session_manager_client.cpp b/window_scene/screen_session_manager/src/screen_session_manager_client.cpp index a2bc85d655..335f27fa23 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager_client.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager_client.cpp @@ -100,9 +100,14 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc WLOGFE("There is no need to connect the screen"); return; } - auto screenProperty = screenSessionManager_->GetScreenProperty(screenId); - auto displayNode = screenSessionManager_->GetDisplayNode(screenId); - sptr screenSession = new ScreenSession(screenId, rsId, name, screenProperty, displayNode); + ScreenSessionConfig config = { + .screenId = screenId, + .rsId = rsId, + .name = name, + }; + config.property = screenSessionManager_->GetScreenProperty(screenId); + config.displayNode = screenSessionManager_->GetDisplayNode(screenId); + sptr screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); { std::lock_guard lock(screenSessionMapMutex_); screenSessionMap_.emplace(screenId, screenSession); diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index 582eb97bb7..4f0f18c6be 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -53,9 +53,28 @@ enum class ScreenState : int32_t { DISCONNECTION, }; +struct ScreenSessionConfig { + ScreenId screenId {0}; + ScreenId rsId {0}; + ScreenId defaultScreenId {0}; + ScreenId mirrorNodeId {0}; + std::string name = "UNKNOWN"; + ScreenProperty property; + std::shared_ptr displayNode; +}; + +enum class ScreenSessionReason : int32_t { + CREATE_SESSION_FOR_CLIENT, + CREATE_SESSION_FOR_VIRTUAL, + CREATE_SESSION_FOR_MIRROR, + CREATE_SESSION_FOR_REAL, + INVALID, +}; + class ScreenSession : public RefBase { public: ScreenSession() = default; + ScreenSession(const ScreenSessionConfig& config, ScreenSessionReason reason); ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name, const ScreenProperty& property, const std::shared_ptr& displayNode); ScreenSession(ScreenId screenId, const ScreenProperty& property, ScreenId defaultScreenId); @@ -63,6 +82,7 @@ public: ScreenSession(const std::string& name, ScreenId smsId, ScreenId rsId, ScreenId defaultScreenId); virtual ~ScreenSession() = default; + void CreateDisplayNode(const Rosen::RSDisplayNodeConfig& config); void SetDisplayNodeScreenId(ScreenId screenId); void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener); void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener); diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index 90eb5520b5..81c44127ff 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -27,6 +27,63 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DMS_SCREEN_SESSION, "ScreenSession" }; } +ScreenSession::ScreenSession(const ScreenSessionConfig& config, ScreenSessionReason reason) + : name_(config.name), screenId_(config.screenId), rsId_(config.rsId), defaultScreenId_(config.defaultScreenId), + property_(config.property), displayNode_(config.displayNode) +{ + TLOGI(WmsLogTag::DMS, + "[DPNODE]Create Session, reason: %{public}d, screenId: %{public}" PRIu64", rsId: %{public}" PRIu64"", + reason, screenId_, rsId_); + TLOGI(WmsLogTag::DMS, + "[DPNODE]Config name: %{public}s, defaultId: %{public}" PRIu64", mirrorNodeId: %{public}" PRIu64"", + name_.c_str(), defaultScreenId_, config.mirrorNodeId); + Rosen::RSDisplayNodeConfig rsConfig; + switch (reason) { + case ScreenSessionReason::CREATE_SESSION_FOR_CLIENT: { + TLOGI(WmsLogTag::DMS, "create screen session for client. noting to do."); + return; + } + case ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL: { + // create virtual screen should use rsid + rsConfig.screenId = rsId_; + break; + } + case ScreenSessionReason::CREATE_SESSION_FOR_MIRROR: { + rsConfig.screenId = screenId_; + rsConfig.isMirrored = true; + rsConfig.mirrorNodeId = config.mirrorNodeId; + break; + } + case ScreenSessionReason::CREATE_SESSION_FOR_REAL: { + rsConfig.screenId = screenId_; + break; + } + default : { + TLOGE(WmsLogTag::DMS, "INVALID invalid screen session config."); + break; + } + } + CreateDisplayNode(rsConfig); +} + +void ScreenSession::CreateDisplayNode(const Rosen::RSDisplayNodeConfig& config) +{ + TLOGI(WmsLogTag::DMS, "[DPNODE]config screenId: %{public}d, isMirrored: %{public}d, mirrorNodeId: %{public}d ", + static_cast(config.screenId), + static_cast(config.isMirrored), + static_cast(config.mirrorNodeId)); + displayNode_ = Rosen::RSDisplayNode::Create(config); + if (displayNode_) { + displayNode_->SetFrame(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_, + property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_); + displayNode_->SetBounds(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_, + property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_); + } else { + TLOGE(WmsLogTag::DMS, "Failed to create displayNode, displayNode is null!"); + } + RSTransaction::FlushImplicitTransaction(); +} + ScreenSession::ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name, const ScreenProperty& property, const std::shared_ptr& displayNode) : name_(name), screenId_(screenId), rsId_(rsId), property_(property), displayNode_(displayNode) diff --git a/window_scene/session_manager/src/screen_session_manager.cpp b/window_scene/session_manager/src/screen_session_manager.cpp index 34521b3b3a..53ffc61b87 100644 --- a/window_scene/session_manager/src/screen_session_manager.cpp +++ b/window_scene/session_manager/src/screen_session_manager.cpp @@ -775,7 +775,13 @@ sptr ScreenSessionManager::GetScreenSessionInner(ScreenId screenI nodeId = sIt->second->GetDisplayNode()->GetId(); } WLOGFI("GetScreenSessionInner: nodeId:%{public}" PRIu64 "", nodeId); - session = new ScreenSession(screenId, property, nodeId, defScreenId); + ScreenSessionConfig config = { + .screenId = screenId, + .property = property, + .mirrorNodeId = nodeId, + .defaultScreenId = defScreenId, + }; + session = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_MIRROR); session->SetVirtualScreenFlag(VirtualScreenFlag::CAST); session->SetName("CastEngine"); session->SetScreenCombination(ScreenCombination::SCREEN_MIRROR); @@ -783,7 +789,12 @@ sptr ScreenSessionManager::GetScreenSessionInner(ScreenId screenI isHdmiScreen_ = true; NotifyCaptureStatusChanged(); } else { - session = new ScreenSession(screenId, property, defScreenId); + ScreenSessionConfig config = { + .screenId = screenId, + .property = property, + .defaultScreenId = defScreenId, + }; + session = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_REAL); } return session; } @@ -2413,8 +2424,14 @@ sptr ScreenSessionManager::InitVirtualScreen(ScreenId smsScreenId VirtualScreenOption option) { WLOGFI("InitVirtualScreen: Enter"); + ScreenSessionConfig config = { + .name = option.name_, + .screenId = smsScreenId, + .rsId = rsId, + .defaultScreenId = GetDefaultScreenId(), + }; sptr screenSession = - new(std::nothrow) ScreenSession(option.name_, smsScreenId, rsId, GetDefaultScreenId()); + new(std::nothrow) ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL); sptr info = new(std::nothrow) SupportedScreenModes(); if (screenSession == nullptr || info == nullptr) { WLOGFI("InitVirtualScreen: new screenSession or info failed"); @@ -2477,8 +2494,14 @@ sptr ScreenSessionManager::InitAndGetScreen(ScreenId rsScreenId) RSScreenCapability screenCapability = rsInterface_.GetScreenCapability(rsScreenId); WLOGFI("Screen name is %{public}s, phyWidth is %{public}u, phyHeight is %{public}u", screenCapability.GetName().c_str(), screenCapability.GetPhyWidth(), screenCapability.GetPhyHeight()); + ScreenSessionConfig config = { + .name = screenCapability.GetName(), + .screenId = smsScreenId, + .rsId = rsScreenId, + .defaultScreenId = GetDefaultScreenId(), + }; sptr screenSession = - new(std::nothrow) ScreenSession(screenCapability.GetName(), smsScreenId, rsScreenId, GetDefaultScreenId()); + new(std::nothrow) ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL); if (screenSession == nullptr) { WLOGFE("InitAndGetScreen: screenSession == nullptr."); screenIdManager_.DeleteScreenId(smsScreenId); diff --git a/window_scene/test/unittest/screen_session_test.cpp b/window_scene/test/unittest/screen_session_test.cpp index 7144cfed86..9a641b8ad6 100644 --- a/window_scene/test/unittest/screen_session_test.cpp +++ b/window_scene/test/unittest/screen_session_test.cpp @@ -27,6 +27,23 @@ class ScreenSessionTest : public testing::Test { }; namespace { + +/** + * @tc.name: create ScreenSession + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, ScreenSession, Function | SmallTest | Level2) +{ + ScreenSessionConfig config = { + .screenId = 0, + .rsId = 0, + .name = "OpenHarmony", + }; + sptr screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + EXPECT_NE(nullptr, screenSession); +} + /** * @tc.name: SetDisplayNodeScreenId * @tc.desc: normal function