diff --git a/window_scene/session_manager/include/screen_session_manager.h b/window_scene/session_manager/include/screen_session_manager.h index 36e6e146f523052ebf0b52e12793a268caa06cff..45475eb05e934696129293165ba4f9dd5ed0d68e 100644 --- a/window_scene/session_manager/include/screen_session_manager.h +++ b/window_scene/session_manager/include/screen_session_manager.h @@ -97,6 +97,12 @@ public: DMError IsScreenRotationLocked(bool& isLocked) override; DMError SetScreenRotationLocked(bool isLocked) override; + virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode, bool onTop = true) override; + + virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode) override; + std::vector GetAllScreenIds() const; const std::shared_ptr& GetRSDisplayNodeByScreenId(ScreenId smsScreenId) const; std::shared_ptr GetScreenSnapshot(DisplayId displayId); diff --git a/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h b/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h index 46adb541a4d2f0fa7541223ee64f229aed508a97..048a8ac6b55ddb884a21ef6a07c8ea5b40f35ae2 100644 --- a/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h @@ -84,6 +84,11 @@ public: virtual DMError SetScreenRotationLocked(bool isLocked) override; virtual DMError IsScreenRotationLocked(bool& isLocked) override; virtual sptr GetCutoutInfo(DisplayId displayId) override; + virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode, bool onTop = true) override; + + virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode) override; virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow) override; private: diff --git a/window_scene/session_manager/src/screen_session_manager.cpp b/window_scene/session_manager/src/screen_session_manager.cpp index d189507619b3d04b6d0fc91a9737be066d242722..56554941b3ce4ff5eda1fc8f434a18c3c7ea4a20 100644 --- a/window_scene/session_manager/src/screen_session_manager.cpp +++ b/window_scene/session_manager/src/screen_session_manager.cpp @@ -28,6 +28,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ScreenSessionManager" }; const std::string SCREEN_SESSION_MANAGER_THREAD = "ScreenSessionManager"; const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN"; +const float MAX_ZORDER = 10000.0f; } // namespace WM_IMPLEMENT_SINGLE_INSTANCE(ScreenSessionManager) @@ -1460,4 +1461,71 @@ sptr ScreenSessionManager::GetCutoutInfo(DisplayId displayId) { return screenCutoutController_ ? screenCutoutController_->GetScreenCutoutInfo() : nullptr; } + +DMError ScreenSessionManager::AddSurfaceNodeToDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode, bool onTop) +{ + WLOGFI("DisplayId: %{public}" PRIu64"", displayId); + if (surfaceNode == nullptr) { + WLOGFW("Surface is null"); + return DMError::DM_ERROR_NULLPTR; + } + + auto it = screenSessionMap_.find(displayId); + if (it == screenSessionMap_.end()) { + WLOGFE("Display not in screenSessionMap, displayId: %{public}llu", displayId); + return DMError::DM_ERROR_NULLPTR; + } + + if (!it->second || !it->second->GetDisplayNode()) { + WLOGFE("screen session or display node is null."); + return DMError::DM_ERROR_NULLPTR; + } + + auto displayNode = it->second->GetDisplayNode(); + + surfaceNode->SetVisible(true); + if (onTop) { + displayNode->AddChild(surfaceNode, -1); + surfaceNode->SetPositionZ(MAX_ZORDER); + } else { + displayNode->AddChild(surfaceNode, -1); + } + + auto transactionProxy = RSTransactionProxy::GetInstance(); + if (transactionProxy != nullptr) { + transactionProxy->FlushImplicitTransaction(); + } + return DMError::DM_OK; +} + +DMError ScreenSessionManager::RemoveSurfaceNodeFromDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode) +{ + WLOGFI("DisplayId: %{public}" PRIu64"", displayId); + if (surfaceNode == nullptr) { + WLOGFW("Surface is null"); + return DMError::DM_ERROR_NULLPTR; + } + + auto it = screenSessionMap_.find(displayId); + if (it == screenSessionMap_.end()) { + WLOGFE("Display not in screenSessionMap, displayId: %{public}llu", displayId); + return DMError::DM_ERROR_NULLPTR; + } + if (!it->second || !it->second->GetDisplayNode()) { + WLOGFE("screen session or display node is null."); + return DMError::DM_ERROR_NULLPTR; + } + + auto displayNode = it->second->GetDisplayNode(); + + displayNode->RemoveChild(surfaceNode); + auto transactionProxy = RSTransactionProxy::GetInstance(); + if (transactionProxy != nullptr) { + transactionProxy->FlushImplicitTransaction(); + } + return DMError::DM_OK; +} + } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp index 4b2517eb34852aadf75c9645a44fdb9143cccc98..fef7eee89fc748486d3212a495a1e51abc03c69d 100644 --- a/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp @@ -15,6 +15,7 @@ #include "zidl/screen_session_manager_proxy.h" #include "marshalling_helper.h" +#include "ui/rs_surface_node.h" namespace OHOS::Rosen { namespace { @@ -510,7 +511,7 @@ ScreenPowerState OHOS::Rosen::ScreenSessionManagerProxy::GetScreenPower(ScreenId WLOGFE("GetScreenPower remote is nullptr"); return ScreenPowerState::INVALID_STATE; } - + MessageParcel data; MessageParcel reply; MessageOption option; @@ -1019,6 +1020,7 @@ sptr ScreenSessionManagerProxy::GetCutoutInfo(DisplayId displayId) WLOGFW("get cutout info : remote is null"); return nullptr; } + MessageParcel data; MessageParcel reply; MessageOption option; @@ -1038,6 +1040,7 @@ sptr ScreenSessionManagerProxy::GetCutoutInfo(DisplayId displayId) sptr info = reply.ReadParcelable(); return info; } + DMError OHOS::Rosen::ScreenSessionManagerProxy::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow) { sptr remote = Remote(); @@ -1067,4 +1070,70 @@ DMError OHOS::Rosen::ScreenSessionManagerProxy::HasPrivateWindow(DisplayId displ hasPrivateWindow = reply.ReadBool(); return ret; } + +DMError ScreenSessionManagerProxy::AddSurfaceNodeToDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode, bool onTop) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("remote is null"); + return DMError::DM_ERROR_NULLPTR; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteUint64(displayId)) { + WLOGFE("write displayId failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) { + WLOGFE("Write windowProperty failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE), + data, reply, option) != ERR_NONE) { + WLOGFW("Send request failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + DMError ret = static_cast(reply.ReadUint32()); + return ret; +} + +DMError ScreenSessionManagerProxy::RemoveSurfaceNodeFromDisplay(DisplayId displayId, + std::shared_ptr& surfaceNode) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("remote is null"); + return DMError::DM_ERROR_NULLPTR; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteUint64(displayId)) { + WLOGFE("write displayId failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) { + WLOGFE("Write windowProperty failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE), + data, reply, option) != ERR_NONE) { + WLOGFW("Send request failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + DMError ret = static_cast(reply.ReadUint32()); + return ret; +} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp index f93413d7d19c17671b33738e4155900ab2915a54..ac8a05d88f2860d542dd561fb98bc7a6f3818c83 100644 --- a/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp @@ -17,6 +17,7 @@ #include #include "marshalling_helper.h" +#include "ui/rs_surface_node.h" namespace OHOS::Rosen { namespace { @@ -310,6 +311,20 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& reply.WriteBool(hasPrivateWindow); break; } + case DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE: { + DisplayId displayId = static_cast(data.ReadUint64()); + std::shared_ptr surfaceNode = RSSurfaceNode::Unmarshalling(data); + auto ret = AddSurfaceNodeToDisplay(displayId, surfaceNode, true); + reply.WriteUint32(static_cast(ret)); + break; + } + case DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE: { + DisplayId displayId = static_cast(data.ReadUint64()); + std::shared_ptr surfaceNode = RSSurfaceNode::Unmarshalling(data); + auto ret = RemoveSurfaceNodeFromDisplay(displayId, surfaceNode); + reply.WriteUint32(static_cast(ret)); + break; + } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option);