diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index bd65da5f9d19cc1725e5f533d7746f7b348cf3c6..1f9469d715b6b1277784bca39291c3f0f58620ce 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -2629,6 +2629,12 @@ DMError DisplayManager::Impl::ConvertRelativeCoordinateToGlobal(const RelativePo return DMError::DM_ERROR_NULLPTR; } + if (displayInfo->GetDisplaySourceMode() != DisplaySourceMode::MAIN && + displayInfo->GetDisplaySourceMode() != DisplaySourceMode::EXTEND) { + TLOGE(WmsLogTag::DMS, "Display is not main or extend mode:%u", displayInfo->GetDisplaySourceMode()); + return DMError::DM_ERROR_ILLEGAL_PARAM; + } + int32_t startX = displayInfo->GetX(); int32_t startY = displayInfo->GetY(); if (IsInt32AddOverflow(relativePosition.position.x, startX) || diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index 54ec30d80da553cba6f5f0623a9aa00532c86125..3acd821eb4f46c74811325e5a5ae6fbfca79c5d3 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -31,6 +31,7 @@ #include "screen_group.h" #include "screen_group_info.h" #include "screen_info.h" +#include "display_info.h" namespace OHOS::Rosen { class AbstractScreenGroup; @@ -62,6 +63,8 @@ public: void InitRSDefaultDisplayNode(const RSDisplayNodeConfig& config, const Point& startPoint); void UpdateRSDisplayNode(Point startPoint, const sptr& absScreen); ScreenId GetScreenGroupId() const; + sptr ScreenInfoConvertToDisplayInfo(sptr info); + void FillDisplayInfoByScreenInfo(sptr displayInfo, sptr info); // colorspace, gamut DMError GetScreenSupportedColorGamuts(std::vector& colorGamuts); diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index ac93c4ffc8aac0f1d9eb6c1e471729a0ec1f2583..08061a197e5f9f7d96ee717aef5c2023ec5f14e5 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -104,6 +104,7 @@ public: DMError StopExpand(const std::vector& expandScreenIds); void RemoveVirtualScreenFromGroup(std::vector screens); sptr GetScreenInfoById(ScreenId screenId); + sptr GetDisplayInfoByScreenId(ScreenId screenId); sptr GetScreenGroupInfoById(ScreenId screenId); ScreenId GetScreenGroupIdByScreenId(ScreenId screenId); DMError GetAllScreenInfos(std::vector>& screenInfos); diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index 0bf600ec5fa811af2f41b9d3592dcc925eb3c563..efb337209e723f1a77238fbee88d0b26dbfdb5c7 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -21,6 +21,7 @@ #include "dm_common.h" #include "rs_adapter.h" #include "window_manager_hilog.h" +#include "screen_rotation_controller.h" namespace OHOS::Rosen { namespace { @@ -72,6 +73,44 @@ sptr AbstractScreen::ConvertToScreenInfo() const return info; } +sptr AbstractScreen::ScreenInfoConvertToDisplayInfo(sptr info) +{ + sptr displayInfo = new(std::nothrow) DisplayInfo(); + if (displayInfo == nullptr) { + return nullptr; + } + FillDisplayInfoByScreenInfo(displayInfo, info); + return displayInfo; +} + +void AbstractScreen::FillDisplayInfoByScreenInfo(sptr displayInfo, sptr info) +{ + if (displayInfo == nullptr || info == nullptr) { + TLOGE(WmsLogTag::DMS, "displayInfo is nullptr"); + return; + } + sptr abstractScreenModes = GetActiveScreenMode(); + if (abstractScreenModes != nullptr) { + displayInfo->SetRefreshRate(abstractScreenModes->refreshRate_); + std::vector supportedRefreshRate; + supportedRefreshRate.push_back(abstractScreenModes->refreshRate_); + displayInfo->SetSupportedRefreshRate(supportedRefreshRate); + } + + displayInfo->SetName(info->name_); + displayInfo->SetDisplayId(info->id_); + displayInfo->SetWidth(info->virtualWidth_); + displayInfo->SetHeight(info->virtualHeight_); + displayInfo->SetScreenId(info->id_); + displayInfo->SetVirtualPixelRatio(info->virtualPixelRatio_); + displayInfo->SetDpi(info->virtualPixelRatio_ * DOT_PER_INCH); + displayInfo->SetRotation(info->rotation_); + displayInfo->SetOrientation(info->orientation_); + displayInfo->SetDisplayOrientation( + ScreenRotationController::ConvertRotationToDisplayOrientation(info->rotation_)); + displayInfo->SetDisplaySourceMode(GetDisplaySourceMode()); +} + void AbstractScreen::UpdateRSTree(std::shared_ptr& surfaceNode, bool isAdd, bool needToUpdate) { if (rsDisplayNode_ == nullptr || surfaceNode == nullptr) { @@ -712,4 +751,44 @@ ScreenCombination AbstractScreenGroup::GetScreenCombination() const { return combination_; } + +DisplaySourceMode AbstractScreen::GetDisplaySourceMode() const +{ + sptr abstractScreenGroup = GetGroup(); + TLOGI(WmsLogTag::DMS, "in"); + if (abstractScreenGroup == nullptr || screenController_ == nullptr) { + TLOGE(WmsLogTag::DMS, "default NONE"); + return DisplaySourceMode::NONE; + } + ScreenId defaultId = screenController_->GetDefaultAbstractScreenId(); + if (dmsId_ == defaultId) { + TLOGE(WmsLogTag::DMS, "err MAIN"); + return DisplaySourceMode::MAIN; + } + ScreenCombination combination = abstractScreenGroup->GetScreenCombination(); + switch (combination) { + case ScreenCombination::SCREEN_MAIN: { + return DisplaySourceMode::MAIN; + } + case ScreenCombination::SCREEN_MIRROR: { + return DisplaySourceMode::MIRROR; + } + case ScreenCombination::SCREEN_EXPAND: { + return DisplaySourceMode::EXTEND; + } + case ScreenCombination::SCREEN_EXTEND: { + return DisplaySourceMode::EXTEND; + } + case ScreenCombination::SCREEN_UNIQUE: { + return DisplaySourceMode::ALONE; + } + case ScreenCombination::SCREEN_ALONE: { + return DisplaySourceMode::NONE; + } + default: { + TLOGE(WmsLogTag::DMS, "default NONE"); + return DisplaySourceMode::NONE; + } + } +} } // namespace OHOS::Rosen diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 2fab87697c26e5fdc0dd2dbefe165d5fac307dde..02b13e080da6c91cda59d7dd0fd997c02c89c744 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -184,7 +184,12 @@ sptr DisplayManagerService::GetDisplayInfoById(DisplayId displayId) { sptr display = abstractDisplayController_->GetAbstractDisplay(displayId); if (display == nullptr) { - TLOGE(WmsLogTag::DMS, "fail to get displayInfo by id: invalid display"); + TLOGI(WmsLogTag::DMS, "fail to get displayInfo by id: %{public}" PRIu64" invalid display", displayId); + sptr displayInfo = GetDisplayInfoByScreenId(displayId); + if (displayInfo != nullptr) { + return displayInfo; + } + TLOGW(WmsLogTag::DMS, "fail to get displayInfo by screen id: %{public}" PRIu64" invalid screen", displayId); return nullptr; } return display->ConvertToDisplayInfo(); @@ -646,6 +651,20 @@ sptr DisplayManagerService::GetScreenInfoById(ScreenId screenId) return screen->ConvertToScreenInfo(); } +sptr DisplayManagerService::GetDisplayInfoByScreenId(ScreenId screenId) +{ + auto screen = abstractScreenController_->GetAbstractScreen(screenId); + if (screen == nullptr) { + TLOGE(WmsLogTag::DMS, "cannot find screenInfo: %{public}" PRIu64, screenId); + return nullptr; + } + sptr screenInfo = screen->ConvertToScreenInfo(); + if (screenInfo == nullptr) { + return nullptr; + } + return screen->ScreenInfoConvertToDisplayInfo(screenInfo); +} + sptr DisplayManagerService::GetScreenGroupInfoById(ScreenId screenId) { auto screenGroup = abstractScreenController_->GetAbstractScreenGroup(screenId); diff --git a/interfaces/kits/napi/display_runtime/js_display.cpp b/interfaces/kits/napi/display_runtime/js_display.cpp index ba26aede6e9ec29470d0bcb597a863c442a4b694..8d9315d50134791c5a5dafe80c1fb1a9193c9001 100644 --- a/interfaces/kits/napi/display_runtime/js_display.cpp +++ b/interfaces/kits/napi/display_runtime/js_display.cpp @@ -859,7 +859,7 @@ void NapiSetNamedProperty(napi_env env, napi_value objValue, sptr i napi_set_named_property(env, objValue, "y", NapiGetUndefined(env)); } napi_set_named_property(env, objValue, "sourceMode", CreateJsValue(env, info->GetDisplaySourceMode())); - napi_set_named_property(env, objValue, "supportedRefreshRate", CreateJsSupportedRefreshRateArray( + napi_set_named_property(env, objValue, "supportedRefreshRates", CreateJsSupportedRefreshRateArray( env, info->GetSupportedRefreshRate())); } diff --git a/interfaces/kits/napi/display_runtime/js_display_manager.cpp b/interfaces/kits/napi/display_runtime/js_display_manager.cpp index 489cbd54ddf4230dd9bb27d2e34f334af13ea0f0..2109648811233b847f018512e066ee8816781353 100644 --- a/interfaces/kits/napi/display_runtime/js_display_manager.cpp +++ b/interfaces/kits/napi/display_runtime/js_display_manager.cpp @@ -953,9 +953,6 @@ napi_value CreateJsCreaseRectsArrayObject(napi_env env, std::vector crea napi_value OnCreateVirtualScreen(napi_env env, napi_callback_info info) { TLOGI(WmsLogTag::DMS, "called"); - if (!SceneBoardJudgement::IsSceneBoardEnabled()) { - return NapiThrowError(env, DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT, "Device not support."); - } DmErrorCode errCode = DmErrorCode::DM_OK; VirtualScreenOption option; size_t argc = 4; diff --git a/utils/include/display_info.h b/utils/include/display_info.h index fdad57e343417e20f6ff18334638f3b645447368..79be7416da078aa32b0db04cfa84ea741e13f139 100644 --- a/utils/include/display_info.h +++ b/utils/include/display_info.h @@ -36,7 +36,7 @@ public: virtual bool Marshalling(Parcel& parcel) const override; static DisplayInfo *Unmarshalling(Parcel& parcel); - DEFINE_VAR_DEFAULT_FUNC_GET(std::string, Name, name, ""); + DEFINE_VAR_DEFAULT_FUNC_GET_SET(std::string, Name, name, ""); DEFINE_VAR_DEFAULT_FUNC_GET_SET(DisplayId, DisplayId, id, DISPLAY_ID_INVALID); DEFINE_VAR_DEFAULT_FUNC_GET_SET(DisplayType, DisplayType, type, DisplayType::DEFAULT); DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, Width, width, 0);