From cef57bd91df1045b507319670de283f3b9cc3644 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Tue, 22 Feb 2022 16:44:19 +0800 Subject: [PATCH] modify the makemirror reture para type Signed-off-by: xiaojianfeng Change-Id: Ib5cd6d5a3927d200be1ec3f987d25e09238aa245 --- dm/include/display_manager_adapter.h | 4 +-- dm/src/display_manager_adapter.cpp | 8 +++--- dm/src/screen_manager.cpp | 17 ++++++----- .../unittest/mock_display_manager_adapter.h | 4 +-- dm/test/unittest/screen_manager_test.cpp | 2 +- dmserver/include/display_manager_interface.h | 4 +-- dmserver/include/display_manager_proxy.h | 4 +-- dmserver/include/display_manager_service.h | 4 +-- dmserver/src/display_manager_proxy.cpp | 28 +++++++++---------- dmserver/src/display_manager_service.cpp | 26 +++++++++++------ dmserver/src/display_manager_stub.cpp | 8 +++--- 11 files changed, 59 insertions(+), 50 deletions(-) diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 19fe9849..54a80632 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -84,8 +84,8 @@ public: virtual sptr GetScreenById(ScreenId screenId); virtual sptr GetScreenGroupById(ScreenId screenId); virtual std::vector> GetAllScreens(); - virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); - virtual DMError MakeExpand(std::vector screenId, std::vector startPoint); + virtual ScreenId MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); + virtual ScreenId MakeExpand(std::vector screenId, std::vector startPoint); virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); virtual void UpdateScreenInfo(ScreenId); diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 2e58f1d6..0976d9a8 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -373,11 +373,11 @@ void BaseAdapter::Clear() displayManagerServiceProxy_ = nullptr; } -DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) +ScreenId ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { - return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; + return SCREEN_ID_INVALID; } return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId); } @@ -495,11 +495,11 @@ std::vector> ScreenManagerAdapter::GetAllScreens() return screens; } -DMError ScreenManagerAdapter::MakeExpand(std::vector screenId, std::vector startPoint) +ScreenId ScreenManagerAdapter::MakeExpand(std::vector screenId, std::vector startPoint) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { - return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; + return SCREEN_ID_INVALID; } return displayManagerServiceProxy_->MakeExpand(screenId, startPoint); } diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index b81e640e..324d0d1a 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -172,23 +172,22 @@ ScreenId ScreenManager::MakeExpand(const std::vector& options) screenIds.emplace_back(option.screenId_); startPoints.emplace_back(Point(option.startX_, option.startY_)); } - DMError result = SingletonContainer::Get().MakeExpand(screenIds, startPoints); - if (result != DMError::DM_OK) { - return SCREEN_ID_INVALID; + ScreenId group = SingletonContainer::Get().MakeExpand(screenIds, startPoints); + if (group == SCREEN_ID_INVALID) { + WLOGFI("make expand failed"); } - WLOGFI("make expand success"); - return screenIds.front(); // default main screenId is the first element of screenIds + return group; } ScreenId ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) { WLOGFI("create mirror for screen: %{public}" PRIu64"", mainScreenId); // TODO: "record screen" should use another function, "MakeMirror" should return group id. - DMError result = SingletonContainer::Get().MakeMirror(mainScreenId, mirrorScreenId); - if (result == DMError::DM_OK) { - WLOGFI("create mirror success"); + ScreenId group = SingletonContainer::Get().MakeMirror(mainScreenId, mirrorScreenId); + if (group == SCREEN_ID_INVALID) { + WLOGFI("create mirror failed"); } - return SCREEN_ID_INVALID; + return group; } ScreenId ScreenManager::CreateVirtualScreen(VirtualScreenOption option) diff --git a/dm/test/unittest/mock_display_manager_adapter.h b/dm/test/unittest/mock_display_manager_adapter.h index 46ee9bc5..a2e66521 100644 --- a/dm/test/unittest/mock_display_manager_adapter.h +++ b/dm/test/unittest/mock_display_manager_adapter.h @@ -57,8 +57,8 @@ public: MOCK_METHOD1(GetScreenById, sptr(ScreenId screenId)); MOCK_METHOD1(GetScreenGroupById, sptr(ScreenId screenId)); MOCK_METHOD0(GetAllScreens, std::vector>()); - MOCK_METHOD2(MakeMirror, DMError(ScreenId mainScreenId, std::vector mirrorScreenId)); - MOCK_METHOD2(MakeExpand, DMError(std::vector screenId, std::vector startPoint)); + MOCK_METHOD2(MakeMirror, ScreenId(ScreenId mainScreenId, std::vector mirrorScreenId)); + MOCK_METHOD2(MakeExpand, ScreenId(std::vector screenId, std::vector startPoint)); MOCK_METHOD2(SetScreenActiveMode, bool(ScreenId screenId, uint32_t modeId)); MOCK_METHOD1(UpdateScreenInfo, void(ScreenId screenId)); diff --git a/dm/test/unittest/screen_manager_test.cpp b/dm/test/unittest/screen_manager_test.cpp index eeafc8b3..76056531 100644 --- a/dm/test/unittest/screen_manager_test.cpp +++ b/dm/test/unittest/screen_manager_test.cpp @@ -105,7 +105,7 @@ HWTEST_F(ScreenManagerTest, MakeExpand_001, Function | SmallTest | Level1) std::unique_ptr m = std::make_unique(); EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(virtualScreenId)); EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK)); - EXPECT_CALL(m->Mock(), MakeExpand(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); + EXPECT_CALL(m->Mock(), MakeExpand(_, _)).Times(1).WillOnce(Return(0)); ScreenId vScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); std::vector options = {{validId, 0, 0}, {vScreenId, defaultWidth_, 0}}; ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options); diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 9e9c40f6..0af471f2 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -99,8 +99,8 @@ public: virtual sptr GetScreenInfoById(ScreenId screenId) = 0; virtual sptr GetScreenGroupInfoById(ScreenId screenId) = 0; virtual std::vector> GetAllScreenInfos() = 0; - virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) = 0; - virtual DMError MakeExpand(std::vector screenId, std::vector startPoint) = 0; + virtual ScreenId MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) = 0; + virtual ScreenId MakeExpand(std::vector screenId, std::vector startPoint) = 0; virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) = 0; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index 28d98a68..746f7229 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -60,11 +60,11 @@ public: bool SetDisplayState(DisplayState state) override; DisplayState GetDisplayState(DisplayId displayId) override; void NotifyDisplayEvent(DisplayEvent event) override; - DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) override; + ScreenId MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) override; sptr GetScreenInfoById(ScreenId screenId) override; sptr GetScreenGroupInfoById(ScreenId screenId) override; std::vector> GetAllScreenInfos() override; - DMError MakeExpand(std::vector screenId, std::vector startPoint) override; + ScreenId MakeExpand(std::vector screenId, std::vector startPoint) override; bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override; private: diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 356521ba..bac8580b 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -82,11 +82,11 @@ public: sptr GetAbstractDisplay(DisplayId displayId); sptr GetAbstractScreenController(); sptr GetDisplayByDisplayId(DisplayId displayId) const; - DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) override; + ScreenId MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) override; sptr GetScreenInfoById(ScreenId screenId) override; sptr GetScreenGroupInfoById(ScreenId screenId) override; std::vector> GetAllScreenInfos() override; - DMError MakeExpand(std::vector screenId, std::vector startPoint) override; + ScreenId MakeExpand(std::vector screenId, std::vector startPoint) override; bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override; private: diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index ec2a00a0..d050ca2b 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -625,12 +625,12 @@ void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event) } } -DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) +ScreenId DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("create mirror fail: remote is null"); - return DMError::DM_ERROR_REMOTE_CREATE_FAILED; + return SCREEN_ID_INVALID; } MessageParcel data; @@ -638,19 +638,19 @@ DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector(mainScreenId)) && data.WriteUInt64Vector(mirrorScreenId); if (!res) { WLOGFE("create mirror fail: data write failed"); - return DMError::DM_ERROR_WRITE_DATA_FAILED; + return SCREEN_ID_INVALID; } if (remote->SendRequest(TRANS_ID_SCREEN_MAKE_MIRROR, data, reply, option) != ERR_NONE) { WLOGFW("create mirror fail: SendRequest failed"); - return DMError::DM_ERROR_IPC_FAILED; + return SCREEN_ID_INVALID; } - return static_cast(reply.ReadInt32()); + return static_cast(reply.ReadUint64()); } sptr DisplayManagerProxy::GetScreenInfoById(ScreenId screenId) @@ -750,12 +750,12 @@ std::vector> DisplayManagerProxy::GetAllScreenInfos() return screenInfos; } -DMError DisplayManagerProxy::MakeExpand(std::vector screenId, std::vector startPoint) +ScreenId DisplayManagerProxy::MakeExpand(std::vector screenId, std::vector startPoint) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("MakeExpand: remote is null"); - return DMError::DM_ERROR_REMOTE_CREATE_FAILED; + return SCREEN_ID_INVALID; } MessageParcel data; @@ -763,28 +763,28 @@ DMError DisplayManagerProxy::MakeExpand(std::vector screenId, std::vec MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("MakeExpand: WriteInterfaceToken failed"); - return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + return SCREEN_ID_INVALID; } if (!data.WriteUInt64Vector(screenId)) { WLOGFE("MakeExpand: write screenId failed"); - return DMError::DM_ERROR_WRITE_DATA_FAILED; + return SCREEN_ID_INVALID; } uint32_t num = startPoint.size(); if (!data.WriteUint32(num)) { WLOGFE("MakeExpand: write startPoint size failed"); - return DMError::DM_ERROR_WRITE_DATA_FAILED; + return SCREEN_ID_INVALID; } for (auto point: startPoint) { if (!(data.WriteInt32(point.posX_) && data.WriteInt32(point.posY_))) { WLOGFE("MakeExpand: write startPoint failed"); - return DMError::DM_ERROR_WRITE_DATA_FAILED; + return SCREEN_ID_INVALID; } } if (remote->SendRequest(TRANS_ID_SCREEN_MAKE_EXPAND, data, reply, option) != ERR_NONE) { WLOGFE("MakeExpand: SendRequest failed"); - return DMError::DM_ERROR_IPC_FAILED; + return SCREEN_ID_INVALID; } - return static_cast(reply.ReadInt32()); + return static_cast(reply.ReadUint64()); } bool DisplayManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 047dbfee..902280a4 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -380,7 +380,7 @@ void DisplayManagerService::SetShotScreen(ScreenId mainScreenId, std::vectorFlushImplicitTransaction(); } -DMError DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds) +ScreenId DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds) { WLOGFI("MakeMirror. mainScreenId :%{public}" PRIu64"", mainScreenId); abstractScreenController_->DumpScreenInfo(); @@ -396,16 +396,21 @@ DMError DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vectorMakeMirror(mainScreenId, allMirrorScreenIds)) { WLOGFE("make mirror failed."); - return DMError::DM_ERROR_NULLPTR; + return SCREEN_ID_INVALID; } abstractScreenController_->DumpScreenInfo(); - return DMError::DM_OK; + auto screen = abstractScreenController_->GetAbstractScreen(mainScreenId); + if (screen == nullptr || abstractScreenController_->GetAbstractScreenGroup(screen->groupDmsId_) == nullptr) { + WLOGFE("get screen group failed."); + return SCREEN_ID_INVALID; + } + return screen->groupDmsId_; } void DisplayManagerService::UpdateRSTree(DisplayId displayId, std::shared_ptr& surfaceNode, @@ -454,14 +459,14 @@ std::vector> DisplayManagerService::GetAllScreenInfos() return screenInfos; } -DMError DisplayManagerService::MakeExpand(std::vector expandScreenIds, std::vector startPoints) +ScreenId DisplayManagerService::MakeExpand(std::vector expandScreenIds, std::vector startPoints) { WLOGI("MakeExpand"); if (expandScreenIds.empty() || startPoints.empty() || expandScreenIds.size() != startPoints.size()) { WLOGFI("create expand fail, input params is invalid. " "screenId vector size :%{public}ud, startPoint vector size :%{public}ud", static_cast(expandScreenIds.size()), static_cast(startPoints.size())); - return DMError::DM_ERROR_INVALID_PARAM; + return SCREEN_ID_INVALID; } abstractScreenController_->DumpScreenInfo(); ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId(); @@ -484,10 +489,15 @@ DMError DisplayManagerService::MakeExpand(std::vector expandScreenIds, WM_SCOPED_TRACE("dms:MakeExpand"); if (!allExpandScreenIds.empty() && !abstractScreenController_->MakeExpand(allExpandScreenIds, startPoints)) { WLOGFE("make expand failed."); - return DMError::DM_ERROR_NULLPTR; + return SCREEN_ID_INVALID; } abstractScreenController_->DumpScreenInfo(); - return DMError::DM_OK; + auto screen = abstractScreenController_->GetAbstractScreen(allExpandScreenIds[0]); + if (screen == nullptr || abstractScreenController_->GetAbstractScreenGroup(screen->groupDmsId_) == nullptr) { + WLOGFE("get screen group failed."); + return SCREEN_ID_INVALID; + } + return screen->groupDmsId_; } bool DisplayManagerService::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index b76f231f..ca880198 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -159,8 +159,8 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, WLOGE("fail to receive mirror screen in stub. screen:%{public}" PRIu64"", mainScreenId); break; } - DMError result = MakeMirror(mainScreenId, mirrorScreenId); - reply.WriteInt32(static_cast(result)); + ScreenId result = MakeMirror(mainScreenId, mirrorScreenId); + reply.WriteUint64(static_cast(result)); break; } case TRANS_ID_GET_SCREEN_INFO_BY_ID: { @@ -200,8 +200,8 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Point point { data.ReadInt32(), data.ReadInt32() }; startPoint.push_back(point); } - DMError result = MakeExpand(screenId, startPoint); - reply.WriteInt32(static_cast(result)); + ScreenId result = MakeExpand(screenId, startPoint); + reply.WriteUint64(static_cast(result)); break; } case TRANS_ID_SET_SCREEN_ACTIVE_MODE: {