diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index f32756f339..bc1e6377db 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -41,6 +41,7 @@ public: virtual ScreenId CreateVirtualScreen(VirtualScreenOption option); virtual DMError DestroyVirtualScreen(ScreenId screenId); + virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); virtual bool RequestRotation(ScreenId screenId, Rotation rotation); virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId); diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index c3e16c37b5..357f16deba 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -206,6 +206,15 @@ DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId) return displayManagerServiceProxy_->DestroyVirtualScreen(screenId); } +DMError DisplayManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr surface) +{ + if (!InitDMSProxyLocked()) { + return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; + } + WLOGFI("DisplayManagerAdapter::SetVirtualScreenSurface"); + return displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface); +} + bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index 45a0f64236..7998a06632 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -195,4 +195,9 @@ DMError ScreenManager::DestroyVirtualScreen(ScreenId screenId) { return SingletonContainer::Get().DestroyVirtualScreen(screenId); } + +DMError ScreenManager::SetVirtualScreenSurface(ScreenId screenId, sptr surface) +{ + return SingletonContainer::Get().SetVirtualScreenSurface(screenId, surface); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index 72183e9606..0db2a3deeb 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -53,6 +53,7 @@ public: void RegisterAbstractScreenCallback(sptr cb); ScreenId CreateVirtualScreen(VirtualScreenOption option); DMError DestroyVirtualScreen(ScreenId screenId); + DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); bool RequestRotation(ScreenId screenId, Rotation rotation); void OnScreenRotate(ScreenId dmsScreenId, Rotation before, Rotation after); diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 7f2e1a0d3e..c4cb521bcd 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -49,6 +49,7 @@ public: TRANS_ID_SCREEN_BASE = 1000, TRANS_ID_CREATE_VIRTUAL_SCREEN = TRANS_ID_SCREEN_BASE, TRANS_ID_DESTROY_VIRTUAL_SCREEN, + TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE, TRANS_ID_GET_SCREEN_INFO_BY_ID, TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID, TRANS_ID_SET_SCREEN_ACTIVE_MODE, @@ -71,6 +72,7 @@ public: virtual ScreenId CreateVirtualScreen(VirtualScreenOption option) = 0; virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0; + virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) = 0; virtual bool RequestRotation(ScreenId screenId, Rotation rotation) = 0; virtual std::shared_ptr GetDispalySnapshot(DisplayId displayId) = 0; diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index d750fce18a..0d30ce4c77 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -36,6 +36,7 @@ public: ScreenId CreateVirtualScreen(VirtualScreenOption option) override; DMError DestroyVirtualScreen(ScreenId screenId) override; + DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) override; bool RequestRotation(ScreenId screenId, Rotation rotation) override; std::shared_ptr GetDispalySnapshot(DisplayId displayId) override; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index a627bc6cad..f35ee8fc3e 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -48,6 +48,7 @@ public: void OnStop() override; ScreenId CreateVirtualScreen(VirtualScreenOption option) override; DMError DestroyVirtualScreen(ScreenId screenId) override; + DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) override; DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 589a96e388..8e1e697b30 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -474,6 +474,17 @@ DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId) return DMError::DM_OK; } +DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, sptr surface) +{ + WLOGFI("AbstractScreenController::SetVirtualScreenSurface"); + int32_t res = rsInterface_.SetVirtualScreenSurface(screenId, surface); + if (res != 0) { + WLOGE("SetVirtualScreenSurface failed in RenderService"); + return DMError::DM_ERROR_RENDER_SERVICE_FAILED; + } + return DMError::DM_OK; +} + bool AbstractScreenController::RequestRotation(ScreenId screenId, Rotation rotation) { WLOGD("request rotation: screen %{public}" PRIu64"", screenId); diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index 146b93cc42..d878c009e5 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -143,6 +143,33 @@ DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId) return static_cast(reply.ReadInt32()); } +DMError DisplayManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sptr surface) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("SetVirtualScreenSurface: remote is nullptr"); + return DMError::DM_ERROR_REMOTE_CREATE_FAILED; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("SetVirtualScreenSurface: WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteUint64(static_cast(screenId)) || + !data.WriteRemoteObject(surface->GetProducer()->AsObject())) { + WLOGFW("SetVirtualScreenSurface: Write screenId/surface failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE, data, reply, option) != ERR_NONE) { + WLOGFW("SetVirtualScreenSurface: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} + bool DisplayManagerProxy::RequestRotation(ScreenId screenId, Rotation rotation) { sptr remote = Remote(); diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index d17d4ca03a..5ddd7fac18 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -148,6 +148,17 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) return abstractScreenController_->DestroyVirtualScreen(screenId); } +DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptr surface) +{ + WLOGFI("SetVirtualScreenSurface::ScreenId: %{public}" PRIu64 "", screenId); + if (screenId == SCREEN_ID_INVALID) { + WLOGFE("SetVirtualScreenSurface: virtualScreenId is invalid"); + return DMError::DM_ERROR_INVALID_PARAM; + } + WM_SCOPED_TRACE("dms:SetVirtualScreenSurface(%" PRIu64")", screenId); + return abstractScreenController_->SetVirtualScreenSurface(screenId, surface); +} + bool DisplayManagerService::RequestRotation(ScreenId screenId, Rotation rotation) { WM_SCOPED_TRACE("dms:RequestRotation(%" PRIu64")", screenId); diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 659db53119..6d220d5bbe 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -77,6 +77,15 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteInt32(static_cast(result)); break; } + case TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE: { + ScreenId screenId = static_cast(data.ReadUint64()); + sptr surfaceObject = data.ReadRemoteObject(); + sptr bp = iface_cast(surfaceObject); + sptr surface = Surface::CreateSurfaceAsProducer(bp); + DMError result = SetVirtualScreenSurface(screenId, surface); + reply.WriteInt32(static_cast(result)); + break; + } case TRANS_ID_REQUEST_ROTATION: { ScreenId screenId = static_cast(data.ReadUint64()); Rotation rotation = static_cast(data.ReadUint32()); diff --git a/interfaces/innerkits/dm/screen_manager.h b/interfaces/innerkits/dm/screen_manager.h index 8ffe674a46..d83c36b739 100644 --- a/interfaces/innerkits/dm/screen_manager.h +++ b/interfaces/innerkits/dm/screen_manager.h @@ -44,6 +44,7 @@ public: ScreenId MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); ScreenId CreateVirtualScreen(VirtualScreenOption option); DMError DestroyVirtualScreen(ScreenId screenId); + DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); private: ScreenManager();