diff --git a/window_scene/session/screen/include/screen_property.h b/window_scene/session/screen/include/screen_property.h index 132de619ec33face968b4627f86c42acb4760674..ea5d86909a0ea1ab7f382708e1baa2adb4ba9780 100644 --- a/window_scene/session/screen/include/screen_property.h +++ b/window_scene/session/screen/include/screen_property.h @@ -29,10 +29,14 @@ public: void SetBounds(const RRect& bounds); RRect GetBounds() const; + float GetDpi(); private: float rotation_ { 0.0f }; RRect bounds_; + int32_t width_ { 0 }; + int32_t height_ { 0 }; + float dpi_ { 1.5f }; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index 0f34908059a9918ed46d73fd3727fdaf003dae1c..1f5bfce5d7cf077a9e44588902ed92a5568413b3 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -53,6 +53,8 @@ public: void Connect(); void Disconnect(); + float GetDensityDpi(); + private: ScreenId screenId_; ScreenProperty property_; diff --git a/window_scene/session/screen/src/screen_property.cpp b/window_scene/session/screen/src/screen_property.cpp index f2ba5d003f166db5ce850fb6754cfd3980e3f3c6..ba0bc2ce19ba936016e0eba5edcf01b475a7c961 100644 --- a/window_scene/session/screen/src/screen_property.cpp +++ b/window_scene/session/screen/src/screen_property.cpp @@ -35,4 +35,17 @@ RRect ScreenProperty::GetBounds() const { return bounds_; } + +float ScreenProperty::GetDpi() +{ + width_ = bounds_.rect_.height_; + height_ = bounds_.rect_.width_; + + if (width_ == 1344 && height_ == 2772) { // telephone + dpi_ = 3.5f; + } else { + dpi_ = 1.5f; + } + return dpi_; +} } // namespace OHOS::Rosen diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index 68df6f71cf0de63a3f670869388d0b025b429428..ffe5eea8db238a4db7707f5b97df298cbc63b299 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -84,4 +84,9 @@ void ScreenSession::Disconnect() } } +float ScreenSession::GetDensityDpi() +{ + return property_.GetDpi(); +} + } // namespace OHOS::Rosen