diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 666f0ac0d2adf34aad4015401ae1b77b9815b668..c59de7b8a4b98fb62f4f9bd14ff571319cee9869 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -20,6 +20,8 @@ #include #include "display.h" +#include "screen.h" +#include "dm_common.h" #include "display_manager_interface.h" #include "singleton_delegator.h" @@ -34,9 +36,9 @@ WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); public: DisplayId GetDefaultDisplayId(); sptr GetDisplayById(DisplayId displayId); - DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface); - bool DestroyVirtualDisplay(DisplayId displayId); + + ScreenId CreateVirtualScreen(VirtualScreenOption option); + DMError DestroyVirtualScreen(ScreenId screenId); std::shared_ptr GetDisplaySnapshot(DisplayId displayId); void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -51,7 +53,7 @@ public: bool SetDisplayState(DisplayState state, DisplayStateCallback callback); DisplayState GetDisplayState(uint64_t displayId); void NotifyDisplayEvent(DisplayEvent event); - + DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); void Clear(); private: diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 43a63319dba73e719817d619724e0a22896a560e..faca0d8dcd10f07cc566f44bdcbb8859ac2377a7 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -154,20 +154,6 @@ std::vector> DisplayManager::GetAllDisplays() return res; } -DisplayId DisplayManager::CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, - sptr surface, DisplayId displayIdToMirror, int32_t flags) -{ - WLOGFI("DisplayManager::CreateVirtualDisplay multi params"); - VirtualDisplayInfo info(name, width, height, displayIdToMirror, flags); - return SingletonContainer::Get().CreateVirtualDisplay(info, surface); -} - -bool DisplayManager::DestroyVirtualDisplay(DisplayId displayId) -{ - WLOGFI("DisplayManager::DestroyVirtualDisplay override params"); - return SingletonContainer::Get().DestroyVirtualDisplay(displayId); -} - void DisplayManager::RegisterDisplayPowerEventListener(sptr listener) { if (listener == nullptr) { diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index bd804d7b0294367d7686c43ecca672f6844403ef..2e81963a8f01c76c8f10c92ad72a83ff94723feb 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -78,23 +78,22 @@ std::shared_ptr DisplayManagerAdapter::GetDisplaySnapshot(Displ return dispalySnapshot; } -DisplayId DisplayManagerAdapter::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) +ScreenId DisplayManagerAdapter::CreateVirtualScreen(VirtualScreenOption option) { if (!InitDMSProxyLocked()) { - return DISPLAY_ID_INVALD; + return SCREEN_ID_INVALD; } - WLOGFI("DisplayManagerAdapter::CreateVirtualDisplay"); - return displayManagerServiceProxy_->CreateVirtualDisplay(virtualDisplayInfo, surface); + WLOGFI("DisplayManagerAdapter::CreateVirtualScreen"); + return displayManagerServiceProxy_->CreateVirtualScreen(option); } -bool DisplayManagerAdapter::DestroyVirtualDisplay(DisplayId displayId) +DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId) { if (!InitDMSProxyLocked()) { - return false; + return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; } - WLOGFI("DisplayManagerAdapter::DestroyVirtualDisplay"); - return displayManagerServiceProxy_->DestroyVirtualDisplay(displayId); + WLOGFI("DisplayManagerAdapter::DestroyVirtualScreen"); + return displayManagerServiceProxy_->DestroyVirtualScreen(screenId); } void DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -265,4 +264,14 @@ void DisplayManagerAdapter::Clear() } displayManagerServiceProxy_ = nullptr; } + +DMError DisplayManagerAdapter::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) +{ + if (!InitDMSProxyLocked()) { + WLOGFE("DisplayManagerAdapter::AddMirror: InitDMSProxyLocked failed"); + return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; + } + WLOGFI("DisplayManagerAdapter::AddMirror"); + return displayManagerServiceProxy_->AddMirror(mainScreenId, mirrorScreenId); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index d13344a94544ad07c4d74f1607b568f525a6c747..5981a1aa825bf3f9c070fe8198028eb0276424e8 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -14,11 +14,17 @@ */ #include "screen_manager.h" +#include "window_manager_hilog.h" +#include "display_manager_adapter.h" + #include #include namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenManager"}; +} class ScreenManager::Impl : public RefBase { friend class ScreenManager; private: @@ -53,18 +59,32 @@ void ScreenManager::RegisterScreenChangeListener(sptr lis { } -sptr ScreenManager::makeExpand(std::vector screenId, std::vector startPoint) +sptr ScreenManager::MakeExpand(std::vector screenId, std::vector startPoint) { return nullptr; } -sptr ScreenManager::makeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) +sptr ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) { return nullptr; } -sptr ScreenManager::createVirtualScreen(VirtualScreenOption option) +sptr ScreenManager::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) { + DMError result = SingletonContainer::Get().AddMirror(mainScreenId, mirrorScreenId); + if (result == DMError::DM_OK) { + WLOGFI("AddMirror::Successful"); + } return nullptr; } + +ScreenId ScreenManager::CreateVirtualScreen(VirtualScreenOption option) +{ + return SingletonContainer::Get().CreateVirtualScreen(option); +} + +DMError ScreenManager::DestroyVirtualScreen(ScreenId screenId) +{ + return SingletonContainer::Get().DestroyVirtualScreen(screenId); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/include/abstract_display_controller.h b/dmserver/include/abstract_display_controller.h index 3d588e7210e712d4ffd9825b00f4596c62bf314b..5f1b11362907e2459cae52f7c951b25fef0c66ed 100644 --- a/dmserver/include/abstract_display_controller.h +++ b/dmserver/include/abstract_display_controller.h @@ -16,15 +16,16 @@ #ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_CONTROLLER_H #define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_CONTROLLER_H +#include "abstract_screen_controller.h" + #include #include #include #include +#include "screen.h" #include "abstract_display.h" -#include "abstract_screen_controller.h" #include "transaction/rs_interfaces.h" -#include "virtual_display_info.h" namespace OHOS::Rosen { class AbstractDisplayController : public RefBase { @@ -35,8 +36,7 @@ public: void Init(sptr abstractScreenController); ScreenId GetDefaultScreenId(); RSScreenModeInfo GetScreenActiveMode(ScreenId id); - ScreenId CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface); - bool DestroyVirtualScreen(ScreenId screenId); + std::shared_ptr GetScreenSnapshot(DisplayId displayId, ScreenId screenId); private: diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index 9b9a0c3e602ca5b416ed44b60b358384671e8777..517ccbb9479904a146b5e03c56260a6824611cfc 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -16,19 +16,16 @@ #ifndef FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H #define FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H -#include +#include #include #include +#include "screen.h" + namespace OHOS::Rosen { constexpr static ScreenId SCREEN_ID_INVALID = INVALID_SCREEN_ID; -struct Point { - int32_t posX_; - int32_t posY_; -}; - enum class ScreenCombination : uint32_t { SCREEN_ALONE, SCREEN_EXPAND, diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index b0c041fccc4cd75ec26eeec62820f9820602efc1..13996ebffa6c01b8796bd57d1d1286472994b989 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -23,6 +23,8 @@ #include #include +#include "screen.h" +#include "dm_common.h" #include "abstract_screen.h" namespace OHOS::Rosen { @@ -45,6 +47,8 @@ public: ScreenId ConvertToRsScreenId(ScreenId dmsScreenId); ScreenId ConvertToDmsScreenId(ScreenId rsScreenId); void RegisterAbstractScreenCallback(sptr cb); + ScreenId CreateVirtualScreen(VirtualScreenOption option); + DMError DestroyVirtualScreen(ScreenId screenId); std::map> abstractDisplayMap_; @@ -56,7 +60,7 @@ private: void AddAsSuccedentScreenLocked(sptr newScreen); std::recursive_mutex& mutex_; - RSInterfaces& rsInterface_; + OHOS::Rosen::RSInterfaces *rsInterface_; std::atomic dmsScreenCount_; // No AbstractScreenGroup std::map rs2DmsScreenIdMap_; diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 6834d9c2e93989d9782151b7b048e0432c35ea2b..4c889daf3c909a6d824a0eee512b636dfc33f12d 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -21,8 +21,8 @@ #include #include "dm_common.h" +#include "screen.h" #include "display_info.h" -#include "virtual_display_info.h" #include "zidl/display_manager_agent_interface.h" namespace OHOS::Rosen { @@ -33,8 +33,6 @@ public: enum { TRANS_ID_GET_DEFAULT_DISPLAY_ID = 0, TRANS_ID_GET_DISPLAY_BY_ID, - TRANS_ID_CREATE_VIRTUAL_DISPLAY, - TRANS_ID_DESTROY_VIRTUAL_DISPLAY, TRANS_ID_GET_DISPLAY_SNAPSHOT, TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT, TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT, @@ -46,14 +44,16 @@ public: TRANS_ID_SET_DISPLAY_STATE, TRANS_ID_GET_DISPLAY_STATE, TRANS_ID_NOTIFY_DISPLAY_EVENT, + TRANS_ID_CREATE_VIRTUAL_SCREEN = 100000, + TRANS_ID_DESTROY_VIRTUAL_SCREEN, + TRANS_ID_ADD_MIRROR, }; virtual DisplayId GetDefaultDisplayId() = 0; virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; - virtual DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) = 0; - virtual bool DestroyVirtualDisplay(DisplayId displayId) = 0; + virtual ScreenId CreateVirtualScreen(VirtualScreenOption option) = 0; + virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0; virtual std::shared_ptr GetDispalySnapshot(DisplayId displayId) = 0; virtual void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -68,6 +68,7 @@ public: virtual bool SetDisplayState(DisplayState state) = 0; virtual DisplayState GetDisplayState(uint64_t displayId) = 0; virtual void NotifyDisplayEvent(DisplayEvent event) = 0; + virtual DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) = 0; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index cc4fa0c8ce68c912bd634775408c107f7abb0e5f..dd1232fba019ff93691132ab0535c92f7e5c13ba 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -18,6 +18,10 @@ #include "display_manager_interface.h" +#include "dm_common.h" + +#include "screen.h" + #include namespace OHOS::Rosen { @@ -30,9 +34,8 @@ public: DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; - DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) override; - bool DestroyVirtualDisplay(DisplayId displayId) override; + ScreenId CreateVirtualScreen(VirtualScreenOption option) override; + DMError DestroyVirtualScreen(ScreenId screenId) override; std::shared_ptr GetDispalySnapshot(DisplayId displayId) override; void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -47,6 +50,7 @@ public: bool SetDisplayState(DisplayState state) override; DisplayState GetDisplayState(uint64_t displayId) override; void NotifyDisplayEvent(DisplayEvent event) override; + DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) override; private: static inline BrokerDelegator delegator_; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 1ea7380dcbea107a5ce4f3b870bbe1ab5c961cc7..fbbefa7ae33464928202eaa96607093034581db5 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -22,6 +22,8 @@ #include #include +#include "dm_common.h" +#include "screen.h" #include "abstract_display.h" #include "abstract_display_controller.h" #include "abstract_screen_controller.h" @@ -50,9 +52,8 @@ WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); public: void OnStart() override; void OnStop() override; - DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) override; - bool DestroyVirtualDisplay(DisplayId displayId) override; + ScreenId CreateVirtualScreen(VirtualScreenOption option) override; + DMError DestroyVirtualScreen(ScreenId screenId) override; DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; @@ -71,8 +72,8 @@ public: DisplayState GetDisplayState(uint64_t displayId) override; void NotifyDisplayEvent(DisplayEvent event) override; bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); - sptr GetAbstractScreenController(); + DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) override; private: DisplayManagerService(); @@ -101,6 +102,7 @@ private: std::map> > displayManagerAgentMap_; sptr dmAgentDeath_ = new DMAgentDeathRecipient( std::bind(&DisplayManagerService::RemoveDisplayManagerAgent, this, std::placeholders::_1)); + std::map> displayNodeMap_; }; } // namespace OHOS::Rosen diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index 0304b9e348e7669e04e78174b7627cd86ffdebdd..cc4e7908970b376f144d303c659f66818b354e47 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -70,28 +70,6 @@ RSScreenModeInfo AbstractDisplayController::GetScreenActiveMode(ScreenId id) return rsInterface_->GetScreenActiveMode(id); } -ScreenId AbstractDisplayController::CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) -{ - if (rsInterface_ == nullptr) { - return SCREEN_ID_INVALID; - } - ScreenId result = rsInterface_->CreateVirtualScreen(virtualDisplayInfo.name_, virtualDisplayInfo.width_, - virtualDisplayInfo.height_, surface, virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); - WLOGFI("AbstractDisplayController::CreateVirtualDisplay id: %{public}" PRIu64"", result); - return result; -} - -bool AbstractDisplayController::DestroyVirtualScreen(ScreenId screenId) -{ - if (rsInterface_ == nullptr) { - return false; - } - WLOGFI("AbstractDisplayController::DestroyVirtualScreen"); - rsInterface_->RemoveVirtualScreen(screenId); - return true; -} - std::shared_ptr AbstractDisplayController::GetScreenSnapshot(DisplayId displayId, ScreenId screenId) { if (rsInterface_ == nullptr) { diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index fb3d8a3f2162d45a69c336f318f28072ba4ce238..52c0515e41afc09407ca19ceeb4264c6d88f4581 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -29,7 +29,7 @@ namespace { } AbstractScreenController::AbstractScreenController(std::recursive_mutex& mutex) - : mutex_(mutex), rsInterface_(RSInterfaces::GetInstance()) + : mutex_(mutex), rsInterface_(&(RSInterfaces::GetInstance())) { } @@ -41,8 +41,12 @@ void AbstractScreenController::Init() { WLOGFD("screen controller init"); dmsScreenCount_ = 0; - rsInterface_.SetScreenChangeCallback( - std::bind(&AbstractScreenController::OnRsScreenChange, this, std::placeholders::_1, std::placeholders::_2)); + if (rsInterface_ != nullptr) { + WLOGFE("rsInterface_ is nullptr, init failed"); + } else { + rsInterface_->SetScreenChangeCallback( + std::bind(&AbstractScreenController::OnRsScreenChange, this, std::placeholders::_1, std::placeholders::_2)); + } } std::vector AbstractScreenController::GetAllScreenIds() @@ -125,7 +129,11 @@ void AbstractScreenController::OnRsScreenChange(ScreenId rsScreenId, ScreenEvent bool AbstractScreenController::FillAbstractScreen(sptr& absScreen, ScreenId rsScreenId) { - std::vector allModes = rsInterface_.GetScreenSupportedModes(rsScreenId); + if (rsInterface_ == nullptr) { + WLOGFE("rsInterface_ is nullptr, FillAbstractScreen failed"); + return false; + } + std::vector allModes = rsInterface_->GetScreenSupportedModes(rsScreenId); if (allModes.size() == 0) { WLOGE("supported screen mode is 0, screenId=%{public}" PRIu64"", rsScreenId); return false; @@ -138,7 +146,7 @@ bool AbstractScreenController::FillAbstractScreen(sptr& absScree absScreen->infos_.push_back(info); WLOGD("fill screen w/h:%{public}d/%{public}d", info->width_, info->height_); } - int32_t activeModeId = rsInterface_.GetScreenActiveMode(rsScreenId).GetScreenModeId(); + int32_t activeModeId = rsInterface_->GetScreenActiveMode(rsScreenId).GetScreenModeId(); WLOGD("fill screen activeModeId:%{public}d", activeModeId); if (activeModeId >= allModes.size()) { WLOGE("activeModeId exceed, screenId=%{public}" PRIu64", activeModeId:%{public}d/%{public}ud", @@ -184,4 +192,25 @@ void AbstractScreenController::AddAsSuccedentScreenLocked(sptr n { // TODO: Mirror to default screen } + +ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption option) +{ + if (rsInterface_ == nullptr) { + return SCREEN_ID_INVALID; + } + ScreenId result = rsInterface_->CreateVirtualScreen(option.name_, option.width_, + option.height_, option.surface_, INVALID_SCREEN_ID, option.flags_); + WLOGFI("AbstractScreenController::CreateVirtualScreen id: %{public}" PRIu64"", result); + return result; +} + +DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId) +{ + if (rsInterface_ == nullptr) { + return DMError::DM_ERROR_NULLPTR; + } + WLOGFI("AbstractScreenController::DestroyVirtualScreen"); + rsInterface_->RemoveVirtualScreen(screenId); + return DMError::DM_OK; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index c69c99c2181213aa2b4163a300976fd4636bda36..b8d3906bcd95bdbb14d3b48507bbb377c0e545a9 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -81,58 +81,60 @@ DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) return *info; } -DisplayId DisplayManagerProxy::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) +ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOption) { sptr remote = Remote(); if (remote == nullptr) { - WLOGFW("create virtual display: remote is nullptr"); - return DISPLAY_ID_INVALD; + WLOGFW("DisplayManagerProxy::CreateVirtualScreen: remote is nullptr"); + return SCREEN_ID_INVALD; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("create virtual display: WriteInterfaceToken failed"); - return DISPLAY_ID_INVALD; + WLOGFE("DisplayManagerProxy::CreateVirtualScreen: WriteInterfaceToken failed"); + return SCREEN_ID_INVALD; } - bool res = data.WriteParcelable(&virtualDisplayInfo) && - data.WriteRemoteObject(surface->GetProducer()->AsObject()); + bool res = data.WriteString(virtualOption.name_) && data.WriteUint32(virtualOption.width_) && + data.WriteUint32(virtualOption.height_) && data.WriteFloat(virtualOption.density_) && + data.WriteRemoteObject(virtualOption.surface_->GetProducer()->AsObject()) && + data.WriteInt32(virtualOption.flags_); if (!res) { - return DISPLAY_ID_INVALD; + WLOGFE("DisplayManagerProxy::Write data failed"); + return SCREEN_ID_INVALD; } - if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { - WLOGFW("create virtual display: SendRequest failed"); - return DISPLAY_ID_INVALD; + if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_SCREEN, data, reply, option) != ERR_NONE) { + WLOGFW("DisplayManagerProxy::CreateVirtualScreen: SendRequest failed"); + return SCREEN_ID_INVALD; } - DisplayId displayId = reply.ReadUint64(); - WLOGFI("DisplayManagerProxy::CreateVirtualDisplay %" PRIu64"", displayId); - return displayId; + ScreenId screenId = static_cast(reply.ReadUint64()); + WLOGFI("DisplayManagerProxy::CreateVirtualScreen %" PRIu64"", screenId); + return screenId; } -bool DisplayManagerProxy::DestroyVirtualDisplay(DisplayId displayId) +DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId) { sptr remote = Remote(); if (remote == nullptr) { - WLOGFW("destroy virtual display: remote is nullptr"); - return false; + WLOGFW("DisplayManagerProxy::DestroyVirtualScreen: remote is nullptr"); + return DMError::DM_ERROR_REMOTE_CREATE_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("destroy virtual display: WriteInterfaceToken failed"); - return false; + WLOGFE("DisplayManagerProxy::DestroyVirtualScreen: WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } - data.WriteUint64(static_cast(displayId)); - if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { - WLOGFW("destroy virtual display: SendRequest failed"); - return false; + data.WriteUint64(static_cast(screenId)); + if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_SCREEN, data, reply, option) != ERR_NONE) { + WLOGFW("DisplayManagerProxy::DestroyVirtualScreen: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } std::shared_ptr DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId) @@ -375,4 +377,33 @@ void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event) return; } } + +DMError DisplayManagerProxy::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("DisplayManagerProxy::AddMirror: remote is nullptr"); + return DMError::DM_ERROR_REMOTE_CREATE_FAILED; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("DisplayManagerProxy::AddMirror: WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + bool res = data.WriteUint64(static_cast(mainScreenId)) && + data.WriteUint64(static_cast(mirrorScreenId)); + if (!res) { + WLOGFE("DisplayManagerProxy::AddMirror: data write failed"); + return DMError::DM_ERROR_WRITE_DATA_FAILED; + } + if (remote->SendRequest(TRANS_ID_ADD_MIRROR, data, reply, option) != ERR_NONE) { + WLOGFW("DisplayManagerProxy::AddMirror: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + WLOGFI("DisplayManagerProxy::AddMirror"); + return static_cast(reply.ReadInt32()); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index f9a609c3de17b06a76fe32e4c86fa295a8b52308..8c9e58bbd7581d0a926308daba4f4e67d8d7cb36 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -14,6 +14,7 @@ */ #include "display_manager_service.h" +#include "window_manager_service.h" #include #include @@ -24,6 +25,8 @@ #include "window_manager_hilog.h" +#include "transaction/rs_interfaces.h" + namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; @@ -88,21 +91,31 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) return displayInfo; } -DisplayId DisplayManagerService::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) +ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option) { - WLOGFI("name %{public}s, width %{public}u, height %{public}u, mirrotId %{public}" PRIu64", flags %{public}d", - virtualDisplayInfo.name_.c_str(), virtualDisplayInfo.width_, virtualDisplayInfo.height_, - virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); - ScreenId screenId = abstractDisplayController_->CreateVirtualScreen(virtualDisplayInfo, surface); - return GetDisplayIdFromScreenId(screenId); + ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option); + if (screenId == SCREEN_ID_INVALD) { + WLOGFE("DisplayManagerService::CreateVirtualScreen: Get virtualScreenId failed"); + return SCREEN_ID_INVALD; + } + return screenId; } -bool DisplayManagerService::DestroyVirtualDisplay(DisplayId displayId) +DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) { - WLOGFI("DisplayManagerService::DestroyVirtualDisplay"); - ScreenId screenId = GetScreenIdFromDisplayId(displayId); - return abstractDisplayController_->DestroyVirtualScreen(screenId); + WLOGFI("DisplayManagerService::DestroyVirtualScreen"); + if (screenId == SCREEN_ID_INVALID) { + WLOGFE("DisplayManagerService: virtualScreenId is invalid"); + return DMError::DM_ERROR_INVALID_PARAM; + } + std::map>::iterator iter = displayNodeMap_.find(screenId); + if (iter == displayNodeMap_.end()) { + WLOGFE("DisplayManagerService: displayNode is nullptr"); + return abstractScreenController_->DestroyVirtualScreen(screenId); + } + displayNodeMap_[screenId]->RemoveFromTree(); + displayNodeMap_.erase(screenId); + return abstractScreenController_->DestroyVirtualScreen(screenId); } std::shared_ptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) @@ -259,4 +272,25 @@ void DMAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFI("call OnRemoteDied callback"); callback_(object); } + +DMError DisplayManagerService::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) +{ + if (mainScreenId == SCREEN_ID_INVALID) { + return DMError::DM_ERROR_INVALID_PARAM; + } + std::shared_ptr displayNode = + SingletonContainer::Get().GetDisplayNode(mainScreenId); + if (displayNode == nullptr) { + WLOGFE("DisplayManagerService::AddMirror: GetDisplayNode failed, displayNode is nullptr"); + return DMError::DM_ERROR_NULLPTR; + } + NodeId nodeId = displayNode->GetId(); + + struct RSDisplayNodeConfig config = {mirrorScreenId, true, nodeId}; + displayNodeMap_[mainScreenId] = RSDisplayNode::Create(config); + auto transactionProxy = RSTransactionProxy::GetInstance(); + transactionProxy->FlushImplicitTransaction(); + WLOGFI("DisplayManagerService::AddMirror: NodeId: %{public}" PRIu64 "", nodeId >> 32); + return DMError::DM_OK; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index b0232b6cd4c7b2a3e242cd851bf902952ae16995..7e089ace0bf69c64990193200adb70532c14a397 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -15,6 +15,8 @@ #include "display_manager_stub.h" +#include "dm_common.h" + #include #include "window_manager_hilog.h" @@ -46,20 +48,31 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteParcelable(&info); break; } - case TRANS_ID_CREATE_VIRTUAL_DISPLAY: { - VirtualDisplayInfo* virtualDisplayInfo = data.ReadParcelable(); + case TRANS_ID_CREATE_VIRTUAL_SCREEN: { + std::string name = data.ReadString(); + uint32_t width = data.ReadUint32(); + uint32_t height = data.ReadUint32(); + float density = data.ReadFloat(); sptr surfaceObject = data.ReadRemoteObject(); sptr bp = iface_cast(surfaceObject); sptr surface = Surface::CreateSurfaceAsProducer(bp); - DisplayId virtualId = CreateVirtualDisplay(*virtualDisplayInfo, surface); - reply.WriteUint64(virtualId); - virtualDisplayInfo = nullptr; + int32_t flags = data.ReadInt32(); + VirtualScreenOption option = { + .name_ = name, + .width_ = width, + .height_ = height, + .density_ = density, + .surface_ = surface, + .flags_ = flags + }; + ScreenId screenId = CreateVirtualScreen(option); + reply.WriteUint64(static_cast(screenId)); break; } - case TRANS_ID_DESTROY_VIRTUAL_DISPLAY: { - DisplayId virtualId = static_cast(data.ReadUint64()); - bool result = DestroyVirtualDisplay(virtualId); - reply.WriteBool(result); + case TRANS_ID_DESTROY_VIRTUAL_SCREEN: { + ScreenId screenId = static_cast(data.ReadUint64()); + DMError result = DestroyVirtualScreen(screenId); + reply.WriteInt32(static_cast(result)); break; } case TRANS_ID_GET_DISPLAY_SNAPSHOT: { @@ -122,6 +135,13 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, NotifyDisplayEvent(event); break; } + case TRANS_ID_ADD_MIRROR: { + ScreenId mainScreenId = static_cast(data.ReadUint64()); + ScreenId mirrorScreenId = static_cast(data.ReadUint64()); + DMError result = AddMirror(mainScreenId, mirrorScreenId); + reply.WriteInt32(static_cast(result)); + break; + } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 80f1c1f1d8b45065e85972fb3f70ff4972aff2ee..4d3067ddec28b4143810ef1fdcbd75a0daac85f9 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -24,7 +24,6 @@ #include "display.h" #include "dm_common.h" #include "singleton_delegator.h" -#include "virtual_display_info.h" // #include "wm_common.h" @@ -44,10 +43,6 @@ public: std::vector GetAllDisplayIds(); - DisplayId CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, - sptr surface, DisplayId displayIdToMirror, int32_t flags); - - bool DestroyVirtualDisplay(DisplayId displayId); std::shared_ptr GetScreenshot(DisplayId displayId); std::shared_ptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, const Media::Size &size, int rotation); diff --git a/interfaces/innerkits/dm/dm_common.h b/interfaces/innerkits/dm/dm_common.h index 4bd162489ac97a606fa74bf44e03ac85f6fce32b..aacbca50fcdc943b105a1fc31a16aa74a01dac1d 100644 --- a/interfaces/innerkits/dm/dm_common.h +++ b/interfaces/innerkits/dm/dm_common.h @@ -43,6 +43,20 @@ enum class DisplayState : uint32_t { enum class DisplayEvent : uint32_t { UNLOCK }; + +enum class DMError : int32_t { + DM_OK = 0, + DM_ERROR_INIT_DMS_PROXY_LOCKED = 100, + DM_ERROR_IPC_FAILED = 101, + DM_ERROR_REMOTE_CREATE_FAILED = 110, + DM_ERROR_NULLPTR = 120, + DM_ERROR_INVALID_PARAM = 130, + DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140, + DM_ERROR_DEATH_RECIPIENT = 150, + DM_ERROR_INVALID_MODE_ID = 160, + DM_ERROR_WRITE_DATA_FAILED = 170, + DM_ERROR_UNKNOWN, +}; using DisplayStateCallback = std::function; enum class DisplayPowerEvent : uint32_t { diff --git a/interfaces/innerkits/dm/screen.h b/interfaces/innerkits/dm/screen.h index ae2221364c2c1b5eaa5bb6cc64f6ded3c5bd6cb4..cc902bdda01b1e3ddf2d435ea4deb79bfec06254 100644 --- a/interfaces/innerkits/dm/screen.h +++ b/interfaces/innerkits/dm/screen.h @@ -31,7 +31,7 @@ struct Point { }; struct VirtualScreenOption { - const std::string& name_; + const std::string name_; uint32_t width_; uint32_t height_; float density_; diff --git a/interfaces/innerkits/dm/screen_manager.h b/interfaces/innerkits/dm/screen_manager.h index 7900ef8bc090fdf020d077ba5f3f0f47c7b90a60..3310d2fdac6131169b4ada81366a231cd61de1c8 100644 --- a/interfaces/innerkits/dm/screen_manager.h +++ b/interfaces/innerkits/dm/screen_manager.h @@ -18,8 +18,10 @@ #include #include "screen.h" +#include "dm_common.h" #include "screen_group.h" #include "wm_single_instance.h" +#include "wm_single_instance.h" namespace OHOS::Rosen { class IScreenChangeListener : public RefBase { @@ -34,10 +36,13 @@ WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenManager); public: sptr GetScreenById(ScreenId id); std::vector> GetAllScreens(); + void RegisterScreenChangeListener(sptr listener); - sptr makeExpand(std::vector screenId, std::vector startPoint); - sptr makeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); - sptr createVirtualScreen(VirtualScreenOption option); + sptr MakeExpand(std::vector screenId, std::vector startPoint); + sptr MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); + sptr AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); + ScreenId CreateVirtualScreen(VirtualScreenOption option); + DMError DestroyVirtualScreen(ScreenId screenId); private: ScreenManager(); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 722750966e13f90f66c6886b71b1da398f3112d9..f8a56ff343f578757c7a49ae8f775e125e09f0df 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -31,7 +31,6 @@ ohos_shared_library("libwmutil") { sources = [ "src/display_info.cpp", "src/singleton_container.cpp", - "src/virtual_display_info.cpp", "src/window_property.cpp", "src/wm_trace.cpp", ] diff --git a/utils/include/virtual_display_info.h b/utils/include/virtual_display_info.h deleted file mode 100644 index cb45bc7803455d30bb7df4e3f34a1788af78b160..0000000000000000000000000000000000000000 --- a/utils/include/virtual_display_info.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_VIRTUAL_DISPLAY_INFO_H -#define FOUNDATION_VIRTUAL_DISPLAY_INFO_H - -#include - -#include - -#include - -#include "display.h" - -namespace OHOS::Rosen { -class VirtualDisplayInfo : public Parcelable { -public: - VirtualDisplayInfo(); - VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, - DisplayId displayIdToMirror, int32_t flags); - ~VirtualDisplayInfo() = default; - - virtual bool Marshalling(Parcel& parcel) const override; - static VirtualDisplayInfo* Unmarshalling(Parcel& parcel); - - std::string name_; - uint32_t width_; - uint32_t height_; - DisplayId displayIdToMirror_; - int32_t flags_; -}; -} // namespace OHOS::Rosen - -#endif // FOUNDATION_VIRTUAL_DISPLAY_INFO_H \ No newline at end of file diff --git a/utils/src/virtual_display_info.cpp b/utils/src/virtual_display_info.cpp deleted file mode 100644 index 9542f71511d6453964647345297c156b02b34049..0000000000000000000000000000000000000000 --- a/utils/src/virtual_display_info.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "virtual_display_info.h" - -namespace OHOS::Rosen { -VirtualDisplayInfo::VirtualDisplayInfo() -{ - name_ = ""; - width_ = 0; - height_ = 0; - displayIdToMirror_ = 0; - flags_ = 0; -} - -VirtualDisplayInfo::VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, - DisplayId displayIdToMirror, int32_t flags) -{ - name_ = name; - width_ = width; - height_ = height; - displayIdToMirror_ = displayIdToMirror; - flags_ = flags; -} - -bool VirtualDisplayInfo::Marshalling(Parcel &parcel) const -{ - return parcel.WriteString(name_) && parcel.WriteUint32(width_) && - parcel.WriteUint32(height_) && parcel.WriteUint64(displayIdToMirror_) && - parcel.WriteInt32(flags_); -} - -VirtualDisplayInfo* VirtualDisplayInfo::Unmarshalling(Parcel &parcel) -{ - VirtualDisplayInfo *virtualDisplayInfo = new VirtualDisplayInfo(); - if (virtualDisplayInfo == nullptr) { - return nullptr; - } - bool res = parcel.ReadString(virtualDisplayInfo->name_) && - parcel.ReadUint32(virtualDisplayInfo->width_) && - parcel.ReadUint32(virtualDisplayInfo->height_) && - parcel.ReadUint64(virtualDisplayInfo->displayIdToMirror_) && - parcel.ReadInt32(virtualDisplayInfo->flags_); - if (!res) { - return nullptr; - } - return virtualDisplayInfo; -} -} // namespace OHOS::Rosen \ No newline at end of file