From 256827304273edc6d97840b76adebf26328a4f12 Mon Sep 17 00:00:00 2001 From: dingguanyu Date: Thu, 8 Jun 2023 23:26:10 +0800 Subject: [PATCH] add get set property Signed-off-by: dingguanyu Change-Id: I24213d3c039deae1a8dfebc829f5bbf229b398c8 --- dm/src/screen.cpp | 2 +- test/demo/BUILD.gn | 28 +++++ test/demo/demo_session_manager.cpp | 60 ++++++++--- utils/include/screen_info.h | 1 + window_scene/session/BUILD.gn | 1 + .../session/screen/include/screen_property.h | 33 +++++- .../session/screen/include/screen_session.h | 29 ++++- .../session/screen/src/screen_property.cpp | 96 ++++++++++++++++- .../session/screen/src/screen_session.cpp | 101 +++++++++++++++++- .../include/scene_session_manager.h | 2 + .../include/screen_session_manager.h | 14 +++ .../zidl/screen_session_manager_proxy.h | 2 + .../src/screen_session_manager.cpp | 75 ++++++++++++- .../src/zidl/screen_session_manager_proxy.cpp | 42 ++++++++ .../src/zidl/screen_session_manager_stub.cpp | 14 +++ 15 files changed, 470 insertions(+), 30 deletions(-) diff --git a/dm/src/screen.cpp b/dm/src/screen.cpp index 7f2400a809..7c88044dd9 100644 --- a/dm/src/screen.cpp +++ b/dm/src/screen.cpp @@ -214,4 +214,4 @@ sptr Screen::GetScreenInfo() const UpdateScreenInfo(); return pImpl_->GetScreenInfo(); } -} // namespace OHOS::Rosen \ No newline at end of file +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/test/demo/BUILD.gn b/test/demo/BUILD.gn index 1fcfb52a48..756edf38b3 100644 --- a/test/demo/BUILD.gn +++ b/test/demo/BUILD.gn @@ -137,3 +137,31 @@ ohos_executable("demo_water_mark_listener") { part_name = "window_manager" subsystem_name = "window" } + +ohos_executable("demo_session_manager") { + sources = [ "demo_session_manager.cpp" ] + + include_dirs = [ + "${window_base_path}/interfaces/innerkits/wm", + "${window_base_path}/interfaces/innerkits/dm", + "${window_base_path}/test/common/utils/include", + "${window_base_path}/window_scene/session_manager/include", + "${window_base_path}/window_scene/session_manager_service/include", + "${window_base_path}/wm/include", + "window/window_manager/utils", + ] + + deps = [ + "${graphic_base_path}/graphic_2d/rosen/modules/render_service_base:librender_service_base", + "${window_base_path}/wm:libwm", + "${window_base_path}/dm:libdm", + "${window_base_path}/window_scene/session_manager:session_manager", + ] + + external_deps = [ "c_utils:utils", + "ipc:ipc_core", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/test/demo/demo_session_manager.cpp b/test/demo/demo_session_manager.cpp index 599c7cae6a..95d0cf9c92 100644 --- a/test/demo/demo_session_manager.cpp +++ b/test/demo/demo_session_manager.cpp @@ -14,33 +14,69 @@ */ #include "session_manager.h" -#include "session_manager_service_proxy.h" #include #include #include +#include "session_manager_service_proxy.h" +#include "display_manager.h" using namespace OHOS; using namespace OHOS::Rosen; int main(int argc, char *argv[]) { - SessionManager sessionManager; + // SessionManager& sessionManager = SessionManager::GetInstance(); + /* sessionManager.Init(); - sleep(1); + usleep(10 * 1000); + sptr screenSessionManagerProxy = sessionManager.GetScreenSessionManagerProxy(); + + if (!screenSessionManagerProxy) { + std::cout << "Get screenSessionManagerProxy: nullptr" << std::endl; + return 0; + } - auto remoteObject = sessionManager.GetRemoteObject(); - if (!remoteObject) { - std::cout << "remoteObject is nullptr." << std::endl; + sptr displayInfo = screenSessionManagerProxy->GetDefaultDisplayInfo(); + if (!displayInfo) { + std::cout << "Get default display info failed." << std::endl; + return 0; } - auto proxy = std::make_unique(remoteObject); + std::cout << "Name: " << displayInfo->GetName() << std::endl; + std::cout << "Id: " << displayInfo->GetDisplayId() << std::endl; + std::cout << "Width: " << displayInfo->GetWidth() << std::endl; + std::cout << "Height: " << displayInfo->GetHeight() << std::endl; + + std::cout << " ---------------------- " << std::endl; +*/ +/* DisplayManager& dm = DisplayManager::GetInstance(); - if (!proxy) { - std::cout << "proxy is nullptr." << std::endl; - } else { - int ret = proxy->GetValueById(1); - std::cout << "ret value: " << ret << std::endl; + auto display = dm.GetDefaultDisplay(); + if (display) { + std::cout << "Name: " << display->GetName() << std::endl; + std::cout << "Id: " << display->GetId() << std::endl; + std::cout << "Width: " << display->GetWidth() << std::endl; + std::cout << "Height: " << display->GetHeight() << std::endl; } +*/ + + auto& dms = OHOS::Rosen::DisplayManager::GetInstance(); + auto displays = dms.GetDefaultDisplay(); + std::cout << "ID:" << displays->GetId() << std::endl; + std::cout << "Width:" << displays->GetWidth() << std::endl; + std::cout << "Height:" << displays->GetHeight() << std::endl; + std::cout << "RefreshRate:" << displays->GetRefreshRate() << std::endl; + std::cout << "ScreenId:" << displays->GetScreenId() << std::endl; + std::cout << "Rotation:" << static_cast(displays->GetRotation()) << std::endl; + std::cout << "Orientation:" << static_cast(displays->GetOrientation()) << std::endl; + std::cout << "VirtualPixelRatio:" << displays->GetVirtualPixelRatio() << std::endl; + std::cout << "Dpi:" << displays->GetDpi() << std::endl; + + // while (displays.empty()) { + // printf("displays is empty, retry to get displays\n"); + // displays = displays.GetId(); + // usleep(30 * 1000); + // } return 0; } \ No newline at end of file diff --git a/utils/include/screen_info.h b/utils/include/screen_info.h index 53c6a4acee..6d2d1f5a20 100644 --- a/utils/include/screen_info.h +++ b/utils/include/screen_info.h @@ -29,6 +29,7 @@ enum class ScreenType : uint32_t { }; class ScreenInfo : public Parcelable { friend class AbstractScreen; +friend class ScreenSession; public: ScreenInfo() = default; ~ScreenInfo() = default; diff --git a/window_scene/session/BUILD.gn b/window_scene/session/BUILD.gn index 5f898e0f79..8493ca621e 100644 --- a/window_scene/session/BUILD.gn +++ b/window_scene/session/BUILD.gn @@ -18,6 +18,7 @@ config("session_public_config") { include_dirs = [ "${window_base_path}/window_scene", "${window_base_path}/interfaces/innerkits/dm", + # for window_manager_hilog "${window_base_path}/utils/include", diff --git a/window_scene/session/screen/include/screen_property.h b/window_scene/session/screen/include/screen_property.h index 4a5f889677..6ba848b025 100644 --- a/window_scene/session/screen/include/screen_property.h +++ b/window_scene/session/screen/include/screen_property.h @@ -17,6 +17,8 @@ #define OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H #include "common/rs_rect.h" +#include "dm_common.h" +#include "class_var_definition.h" namespace OHOS::Rosen { class ScreenProperty { @@ -24,17 +26,38 @@ public: ScreenProperty() = default; ~ScreenProperty() = default; - void SetRotation(float rotation); + RRect GetBounds() const; + int32_t GetPhyWidth() const; + int32_t GetPhyHeight() const; + uint32_t GetRefreshRate() const; + + float GetVirtualPixelRatio() const; + Orientation GetOrientation() const; float GetRotation() const; + float GetDensity(); void SetBounds(const RRect& bounds); - RRect GetBounds() const; - float GetDensity(); + void SetPhyWidth(uint32_t phyWidth); + void SetPhyHeight(uint32_t phyHeight); + void SetRefreshRate(uint32_t refreshRate); + void SetVirtualPixelRatio(float virtualPixelRatio); + void SetOrientation(Orientation orientation); + void SetRotation(Rotation rotation); + + void UpdateXDpi(); + void UpdateYDpi(); private: - float rotation_ { 0.0f }; RRect bounds_; - float density_ { 1.5f }; + uint32_t phyWidth_ { UINT32_MAX }; + uint32_t phyHeight_ { UINT32_MAX }; + uint32_t refreshRate_ { 0 }; + float virtualPixelRatio_ { 1.0f }; + Orientation orientation_ { Orientation::UNSPECIFIED }; + Rotation rotation_ { Rotation::ROTATION_0 }; + float density_ { 0.0f }; + float xDpi_ { 0.0f }; + float yDpi_ { 0.0f }; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index 75282bcb3b..87987d8d6f 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -25,8 +25,14 @@ #include "screen_property.h" #include "dm_common.h" #include "display_info.h" +#include "event_handler.h" +#include "screen.h" +#include "screen_info.h" + + namespace OHOS::Rosen { + class IScreenChangeListener : public RefBase { public: IScreenChangeListener() = default; @@ -45,24 +51,39 @@ enum class ScreenState : int32_t { class ScreenSession : public RefBase { public: - explicit ScreenSession(ScreenId screenId, const ScreenProperty& property); + explicit ScreenSession(ScreenId screenId, ScreenProperty& property); ~ScreenSession() = default; void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener); void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener); + void FillScreenInfo(sptr info) const; sptr ConvertToDisplayInfo(); + sptr GetActiveScreenMode() const; + ScreenSourceMode GetSourceMode() const; + sptr ConvertToScreenInfo() const; ScreenId GetScreenId(); ScreenProperty GetScreenProperty() const; std::shared_ptr GetDisplayNode() const; - + ScreenId GetId() const; + ScreenState GetScreenState() const; + ScreenId GetAbstractScreenGroupId() const; + DMError SetScreenActiveMode(uint32_t modeId); + void SetVirtualPixelRatio(float virtualPixelRatio); void Connect(); void Disconnect(); + int32_t activeIdx_ { 0 }; + std::vector> modes_ = {}; + ScreenId screenId_; + float virtualPixelRatio_ = { 1.0 }; + private: - ScreenId screenId_; - ScreenProperty property_; + std::string name_ { "UNKNOW" }; + ScreenProperty& property_; + int32_t activeModeIdx_ { 0 }; + ScreenId screenGroupId_ { SCREEN_ID_INVALID }; std::shared_ptr displayNode_; ScreenState screenState_ { ScreenState::INIT }; std::vector screenChangeListenerList_; diff --git a/window_scene/session/screen/src/screen_property.cpp b/window_scene/session/screen/src/screen_property.cpp index b663369f49..8ca5b3ffa0 100644 --- a/window_scene/session/screen/src/screen_property.cpp +++ b/window_scene/session/screen/src/screen_property.cpp @@ -14,16 +14,42 @@ */ #include "session/screen/include/screen_property.h" +#include "window_manager_hilog.h" namespace OHOS::Rosen { -void ScreenProperty::SetRotation(float rotation) +namespace { + constexpr int32_t PHONE_SCREEN_WIDTH = 1344; + constexpr int32_t PHONE_SCREEN_HEIGHT = 2772; + constexpr float PHONE_SCREEN_DENSITY = 3.5f; + constexpr float ELSE_SCREEN_DENSITY = 1.5f; + constexpr float INCH_2_MM = 25.4f; +} + +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "Screen_property" }; + +void ScreenProperty::SetRotation(Rotation rotation) { rotation_ = rotation; } +float convert_Rotation_to_float(Rotation rotation) +{ + switch(rotation){ + case Rotation::ROTATION_0: + return 0.0f; + case Rotation::ROTATION_90: + return 1.0f; + case Rotation::ROTATION_180: + return 2.0f; + case Rotation::ROTATION_270: + return 3.0f; + } +} + float ScreenProperty::GetRotation() const { - return rotation_; + //todo: convert to float + return convert_Rotation_to_float(rotation_); } void ScreenProperty::SetBounds(const RRect& bounds) @@ -41,11 +67,71 @@ float ScreenProperty::GetDensity() int32_t width = bounds_.rect_.width_; int32_t height = bounds_.rect_.height_; - if (width == 1344 && height == 2772) { // telephone - density_ = 3.5f; + if (width == PHONE_SCREEN_WIDTH && height == PHONE_SCREEN_HEIGHT) { + density_ = PHONE_SCREEN_DENSITY; } else { - density_ = 1.5f; + density_ = ELSE_SCREEN_DENSITY; } return density_; } + +void ScreenProperty::UpdateXDpi() +{ + if (phyWidth_ != UINT32_MAX) { + int32_t width = bounds_.rect_.width_; + xDpi_ = width * INCH_2_MM / phyWidth_; + } +} + +void ScreenProperty::UpdateYDpi() +{ + if (phyHeight_ != UINT32_MAX) { + int32_t height = bounds_.rect_.height_; + yDpi_ = height * INCH_2_MM / phyHeight_; + } +} + +uint32_t ScreenProperty::GetRefreshRate() const +{ + return refreshRate_; +} + +float ScreenProperty::GetVirtualPixelRatio() const +{ + return virtualPixelRatio_; +} + +void ScreenProperty::SetRefreshRate(uint32_t refreshRate) +{ + refreshRate_ = refreshRate; +} + +void ScreenProperty::SetPhyWidth(uint32_t phyWidth) +{ + phyWidth_ = phyWidth; +} + +void ScreenProperty::SetPhyHeight(uint32_t PhyHeight) +{ + phyHeight_ = PhyHeight; +} + +void ScreenProperty::SetVirtualPixelRatio(float virtualPixelRatio) +{ + virtualPixelRatio_ = virtualPixelRatio; + WLOGE(" virtualPixelRatio_ value is %{public}f", + virtualPixelRatio_); +} + +void ScreenProperty::SetOrientation(Orientation orientation) +{ + orientation_ = orientation; +} + + +Orientation ScreenProperty::GetOrientation() const +{ + return orientation_; +} + } // namespace OHOS::Rosen diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index 08d4eae4c5..846353a52a 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -22,7 +22,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ScreenSession" }; } -ScreenSession::ScreenSession(ScreenId screenId, const ScreenProperty& property) +ScreenSession::ScreenSession(ScreenId screenId, ScreenProperty& property) : screenId_(screenId), property_(property) { Rosen::RSDisplayNodeConfig config = { .screenId = screenId_ }; @@ -72,7 +72,21 @@ sptr ScreenSession::ConvertToDisplayInfo() displayInfo->SetHeight(property_.GetBounds().rect_.GetHeight()); displayInfo->SetScreenId(screenId_); displayInfo->SetDisplayId(screenId_); - + displayInfo->SetRefreshRate(refreshRate_); + displayInfo->SetVirtualPixelRatio(virtualPixelRatio_); + displayInfo->SetXDpi(xDpi_); + displayInfo->SetYDpi(yDpi_); + displayInfo->SetDpi(density_); + displayInfo->SetRotation(rotation_); + displayInfo->Orientation(orientation_); + displayInfo->SetOffsetX(0.0f); + displayInfo->SetOffsetY(0.0f); + // displayInfo->SetDisplayState(); + // displayInfo->SetWaterfallDisplayCompressionStatus(); + // displayInfo->SetDisplayOrientation(); + // displayInfo->SetDisplayStateChangeType(); + // displayInfo->SetisDefaultVertical(); + // displayInfo->SetAliveStatus(); return displayInfo; } ScreenId ScreenSession::GetScreenId() @@ -90,6 +104,28 @@ std::shared_ptr ScreenSession::GetDisplayNode() const return displayNode_; } +ScreenId ScreenSession::GetId() const +{ + return screenId_; +} + +ScreenState ScreenSession::GetScreenState() const +{ + return screenState_; +} + +DMError ScreenSession::SetScreenActiveMode(uint32_t modeId) +{ + activeModeIdx_ = modeId; + return DMError::DM_OK; +} + +void ScreenSession::SetVirtualPixelRatio(float virtualPixelRatio) +{ + property_.SetVirtualPixelRatio(virtualPixelRatio); +} + + void ScreenSession::Connect() { screenState_ = ScreenState::CONNECTION; @@ -105,4 +141,65 @@ void ScreenSession::Disconnect() listener->OnDisconnect(); } } + +sptr ScreenSession::GetActiveScreenMode() const +{ + if (activeIdx_ < 0 || activeIdx_ >= static_cast(modes_.size())) { + WLOGE("active mode index is wrong: %{public}d", activeIdx_); + return nullptr; + } + return modes_[activeIdx_]; +} + +ScreenSourceMode ScreenSession::GetSourceMode() const +{ + return ScreenSourceMode::SCREEN_ALONE; +} + +void ScreenSession::FillScreenInfo(sptr info) const +{ + if (info == nullptr) { + WLOGE("FillScreenInfo failed! info is nullptr"); + return; + } + info->id_ = screenId_; + info->name_ = name_; + uint32_t width = 0; + uint32_t height = 0; + sptr ScreenSessionModes = GetActiveScreenMode(); + if (ScreenSessionModes != nullptr) { + height = ScreenSessionModes->height_; + width = ScreenSessionModes->width_; + } + float virtualPixelRatio = virtualPixelRatio_; + // "< 1e-6" means virtualPixelRatio is 0. + if (fabsf(virtualPixelRatio) < 1e-6) { + virtualPixelRatio = 1.0f; + } + ScreenSourceMode sourceMode = GetSourceMode(); + info->virtualPixelRatio_ = virtualPixelRatio; + info->virtualHeight_ = height / virtualPixelRatio; + info->virtualWidth_ = width / virtualPixelRatio; + // info->lastParent_ = lastGroupDmsId_; + // info->parent_ = groupDmsId_; + // info->isScreenGroup_ = isScreenGroup_; + // info->rotation_ = rotation_; + // info->orientation_ = orientation_; + info->sourceMode_ = sourceMode; + // info->type_ = type_; + // info->modeId_ = activeIdx_; + // info->modes_ = modes_; +} + +sptr ScreenSession::ConvertToScreenInfo() const +{ + sptr info = new(std::nothrow) ScreenInfo(); + if (info == nullptr) { + return nullptr; + } + FillScreenInfo(info); + return info; +} + + } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 5fa7534089..4c9619b804 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -34,8 +34,10 @@ class SceneSession; using NotifyCreateSpecificSessionFunc = std::function& session)>; class SceneSessionManager : public SceneSessionManagerStub, public SessionManagerBase { + WM_DECLARE_SINGLE_INSTANCE_BASE(SceneSessionManager) public: + sptr RequestSceneSession(const SessionInfo& sessionInfo); WSError RequestSceneSessionActivation(const sptr& sceneSession); WSError RequestSceneSessionBackground(const sptr& sceneSession); diff --git a/window_scene/session_manager/include/screen_session_manager.h b/window_scene/session_manager/include/screen_session_manager.h index f2a77e17a2..d1232694c0 100644 --- a/window_scene/session_manager/include/screen_session_manager.h +++ b/window_scene/session_manager/include/screen_session_manager.h @@ -25,6 +25,7 @@ #include "session_display_power_controller.h" + namespace OHOS::Rosen { class IScreenConnectionListener : public RefBase { public: @@ -38,7 +39,14 @@ public: class RSInterfaces; class ScreenSessionManager : public ScreenSessionManagerStub { +// using OnAbstractScreenConnectCb = std::function)>; +// using OnAbstractScreenChangeCb = std::function, DisplayChangeEvent event)>; public: +// struct AbstractScreenCallback : public RefBase { +// OnAbstractScreenConnectCb onConnect_; +// OnAbstractScreenConnectCb onDisconnect_; +// OnAbstractScreenChangeCb onChange_; +// }; static ScreenSessionManager& GetInstance(); ScreenSessionManager(const ScreenSessionManager&) = delete; ScreenSessionManager(ScreenSessionManager&&) = delete; @@ -49,6 +57,9 @@ public: std::vector GetAllScreenIds(); sptr GetDefaultDisplayInfo() override; + DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override; + DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override; + void NotifyScreenChanged(sptr screenInfo, ScreenChangeEvent event) ; void RegisterScreenConnectionListener(sptr& screenConnectionListener); void UnregisterScreenConnectionListener(sptr& screenConnectionListener); @@ -72,6 +83,8 @@ public: void RegisterDisplayChangeListener(sptr listener); bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); bool NotifyDisplayStateChanged(DisplayId id, DisplayState state); + std::shared_ptr controllerHandler_; + protected: ScreenSessionManager(); @@ -99,6 +112,7 @@ private: sptr displayChangeListener_; sptr sessionDisplayPowerController_; + // sptr abstractScreenCallback_; }; } // namespace OHOS::Rosen 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 a93d4c9223..0ed5ac56ab 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 @@ -30,6 +30,8 @@ public: ~ScreenSessionManagerProxy() = default; virtual sptr GetDefaultDisplayInfo() override; + virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override; + virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override; virtual DMError RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) override; diff --git a/window_scene/session_manager/src/screen_session_manager.cpp b/window_scene/session_manager/src/screen_session_manager.cpp index 9d921008e6..da158ab96f 100644 --- a/window_scene/session_manager/src/screen_session_manager.cpp +++ b/window_scene/session_manager/src/screen_session_manager.cpp @@ -170,6 +170,72 @@ sptr ScreenSessionManager::GetDefaultDisplayInfo() } } +DMError ScreenSessionManager::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) +{ + if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { + WLOGFE("set screen active permission denied!"); + return DMError::DM_ERROR_NOT_SYSTEM_APP; + } + // HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetScreenActiveMode(%" PRIu64", %u)", screenId, modeId); + sptr screenSession = GetScreenSession(screenId); + if (screenSession) { + return screenSession->SetScreenActiveMode(modeId); + } else { + WLOGFE("get screen session faile."); + return DMError::DM_ERROR_UNKNOWN; + } +} + +void ScreenSessionManager::NotifyScreenChanged(sptr screenInfo, ScreenChangeEvent event) +{ + if (screenInfo == nullptr) { + WLOGFE("NotifyScreenChanged error, screenInfo is nullptr."); + return; + } + auto task = [=] { + WLOGFI("NotifyScreenChanged, screenId:%{public}" PRIu64"", screenInfo->GetScreenId()); + // from display_manager_agent_controller.cpp onscreenconnect + if (screenInfo == nullptr) + { + return; + } + auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER); + if (agents.empty()) { + return; + } + WLOGFI("OnScreenChange"); + for (auto& agent : agents) { + agent->OnScreenChange(screenInfo, event); + } + }; + controllerHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::HIGH); +} + +DMError ScreenSessionManager::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) +{ + + // from display_manager_service.cpp + if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { + WLOGFE("set virtual pixel permission denied!"); + return DMError::DM_ERROR_NOT_SYSTEM_APP; + } + // HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetVirtualPixelRatio(%" PRIu64", %f)", screenId, + // virtualPixelRatio); + + // from abstract_screen_controller.cpp + WLOGD("set virtual pixel ratio. screen %{public}" PRIu64" virtualPixelRatio %{public}f", + screenId, virtualPixelRatio); + sptr screenSession = GetScreenSession(screenId); + if (!screenSession) { + WLOGFE("screen session is nullptr"); + return DMError::DM_ERROR_UNKNOWN; + } + screenSession->SetVirtualPixelRatio(virtualPixelRatio); + NotifyScreenChanged(screenSession->ConvertToScreenInfo(), ScreenChangeEvent::VIRTUAL_PIXEL_RATIO_CHANGED); + + return DMError::DM_OK; +} + sptr ScreenSessionManager::GetOrCreateScreenSession(ScreenId screenId) { auto sessionIt = screenSessionMap_.find(screenId); @@ -179,9 +245,16 @@ sptr ScreenSessionManager::GetOrCreateScreenSession(ScreenId scre auto screenMode = rsInterface_.GetScreenActiveMode(screenId); auto screenBounds = RRect({ 0, 0, screenMode.GetScreenWidth(), screenMode.GetScreenHeight() }, 0.0f, 0.0f); + auto screenRefreshRate = screenMode.GetScreenRefreshRate(); + auto screenCapability = rsInterface_.GetScreenCapability(screenId); + auto PhyWidth = screenCapability.GetPhyWidth(); + auto PhyHeight = screenCapability.GetPhyHeight(); ScreenProperty property; - property.SetRotation(0.0f); + // property.SetRotation(0.0f); property.SetBounds(screenBounds); + property.SetRefreshRate(screenRefreshRate); + property.SetPhyWidth(PhyWidth); + property.SetPhyHeight(PhyHeight); sptr session = new(std::nothrow) ScreenSession(screenId, property); if (!session) { WLOGFE("screen session is nullptr"); 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 e1e12175b3..27e917b52d 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 @@ -42,6 +42,48 @@ sptr OHOS::Rosen::ScreenSessionManagerProxy::GetDefaultDisplayInfo( return info; } +DMError ScreenSessionManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("SetScreenActiveMode: WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteUint64(screenId) || !data.WriteUint32(modeId)) { + WLOGFE("SetScreenActiveMode: write screenId/modeId failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE), + data, reply, option) != ERR_NONE) { + WLOGFE("SetScreenActiveMode: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} + +DMError ScreenSessionManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteUint64(screenId) || !data.WriteFloat(virtualPixelRatio)) { + WLOGFE("write screenId/modeId failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} + DMError ScreenSessionManagerProxy::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { 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 8bb6c12fd9..b21d332ad1 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 @@ -37,6 +37,20 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& reply.WriteParcelable(info); break; } + case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE: { + ScreenId screenId = static_cast(data.ReadUint64()); + uint32_t modeId = data.ReadUint32(); + DMError ret = SetScreenActiveMode(screenId, modeId); + reply.WriteInt32(static_cast(ret)); + break; + } + case DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO: { + ScreenId screenId = static_cast(data.ReadUint64()); + float virtualPixelRatio = data.ReadFloat(); + DMError ret = SetVirtualPixelRatio(screenId, virtualPixelRatio); + reply.WriteInt32(static_cast(ret)); + break; + } case DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT: { auto agent = iface_cast(data.ReadRemoteObject()); auto type = static_cast(data.ReadUint32()); -- Gitee