From 2d72082f0f6f996558a6a30450211bb6b551deb8 Mon Sep 17 00:00:00 2001 From: njuptkid Date: Wed, 28 Jun 2023 15:38:22 +0800 Subject: [PATCH] add boot animation ipc Change-Id: I78e89556a0d95a0c9d78e18e8a5f283ded677047 Signed-off-by: njuptkid --- .../include/screen_session_manager.h | 6 ++ .../zidl/screen_session_manager_proxy.h | 5 ++ .../src/screen_session_manager.cpp | 68 ++++++++++++++++++ .../src/zidl/screen_session_manager_proxy.cpp | 71 ++++++++++++++++++- .../src/zidl/screen_session_manager_stub.cpp | 15 ++++ 5 files changed, 164 insertions(+), 1 deletion(-) diff --git a/window_scene/session_manager/include/screen_session_manager.h b/window_scene/session_manager/include/screen_session_manager.h index 36e6e146f5..45475eb05e 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 46adb541a4..048a8ac6b5 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 d189507619..56554941b3 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 4b2517eb34..fef7eee89f 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 f93413d7d1..ac8a05d88f 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); -- Gitee