mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-21 04:25:28 -04:00
update the size of the Display after rotate screen
Signed-off-by: lu <zhaolu2@huawei.com> Change-Id: I918630d93678f4cdce904461e4a0f0efc846b2fd
This commit is contained in:
@@ -67,6 +67,8 @@ public:
|
||||
virtual void NotifyDisplayEvent(DisplayEvent event);
|
||||
virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId);
|
||||
virtual void Clear();
|
||||
virtual DisplayInfo GetDisplayInfo(DisplayId displayId);
|
||||
virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId);
|
||||
virtual sptr<Screen> GetScreenById(ScreenId screenId);
|
||||
virtual sptr<ScreenGroup> GetScreenGroupById(ScreenId screenId);
|
||||
virtual std::vector<sptr<Screen>> GetAllScreens();
|
||||
|
||||
@@ -15,19 +15,40 @@
|
||||
|
||||
#include "display.h"
|
||||
#include "display_info.h"
|
||||
#include "display_manager_adapter.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "Display"};
|
||||
}
|
||||
class Display::Impl : public RefBase {
|
||||
friend class Display;
|
||||
private:
|
||||
void UpdateDisplay(sptr<DisplayInfo> info);
|
||||
|
||||
std::string name_;
|
||||
DisplayId id_ { DISPLAY_ID_INVALD };
|
||||
int32_t width_ { 0 };
|
||||
int32_t height_ { 0 };
|
||||
uint32_t freshRate_ { 0 };
|
||||
ScreenId screenId_ {SCREEN_ID_INVALID};
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
};
|
||||
|
||||
void Display::Impl::UpdateDisplay(sptr<DisplayInfo> info)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
WLOGFE("info is nullptr.");
|
||||
return;
|
||||
}
|
||||
width_ = info->width_;
|
||||
height_ = info->height_;
|
||||
freshRate_ = info->freshRate_;
|
||||
screenId_ = info->screenId_;
|
||||
rotation_ = info->rotation_;
|
||||
}
|
||||
|
||||
Display::Display(const std::string& name, DisplayInfo* info)
|
||||
: pImpl_(new Impl())
|
||||
{
|
||||
@@ -37,6 +58,7 @@ Display::Display(const std::string& name, DisplayInfo* info)
|
||||
pImpl_->height_ = info->height_;
|
||||
pImpl_->freshRate_ = info->freshRate_;
|
||||
pImpl_->screenId_ = info->screenId_;
|
||||
pImpl_->rotation_ = info->rotation_;
|
||||
}
|
||||
|
||||
DisplayId Display::GetId() const
|
||||
@@ -46,21 +68,29 @@ DisplayId Display::GetId() const
|
||||
|
||||
int32_t Display::GetWidth() const
|
||||
{
|
||||
DisplayInfo info = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(pImpl_->id_);
|
||||
pImpl_->UpdateDisplay(&info);
|
||||
return pImpl_->width_;
|
||||
}
|
||||
|
||||
int32_t Display::GetHeight() const
|
||||
{
|
||||
DisplayInfo info = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(pImpl_->id_);
|
||||
pImpl_->UpdateDisplay(&info);
|
||||
return pImpl_->height_;
|
||||
}
|
||||
|
||||
uint32_t Display::GetFreshRate() const
|
||||
{
|
||||
DisplayInfo info = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(pImpl_->id_);
|
||||
pImpl_->UpdateDisplay(&info);
|
||||
return pImpl_->freshRate_;
|
||||
}
|
||||
|
||||
ScreenId Display::GetScreenId() const
|
||||
{
|
||||
DisplayInfo info = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(pImpl_->id_);
|
||||
pImpl_->UpdateDisplay(&info);
|
||||
return pImpl_->screenId_;
|
||||
}
|
||||
|
||||
|
||||
@@ -378,6 +378,38 @@ DMError DisplayManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<Scr
|
||||
return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId);
|
||||
}
|
||||
|
||||
sptr<ScreenInfo> DisplayManagerAdapter::GetScreenInfo(ScreenId screenId)
|
||||
{
|
||||
if (screenId == SCREEN_ID_INVALID) {
|
||||
WLOGFE("screen id is invalid");
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("InitDMSProxyLocked failed!");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<ScreenInfo> screenInfo = displayManagerServiceProxy_->GetScreenInfoById(screenId);
|
||||
if (screenInfo == nullptr) {
|
||||
WLOGFE("screenInfo is null");
|
||||
}
|
||||
return screenInfo;
|
||||
}
|
||||
|
||||
DisplayInfo DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId)
|
||||
{
|
||||
if (displayId == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("screen id is invalid");
|
||||
return DisplayInfo();
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("InitDMSProxyLocked failed!");
|
||||
return DisplayInfo();
|
||||
}
|
||||
return displayManagerServiceProxy_->GetDisplayInfoById(displayId);
|
||||
}
|
||||
|
||||
sptr<Screen> DisplayManagerAdapter::GetScreenById(ScreenId screenId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
@@ -29,6 +29,7 @@ friend class Screen;
|
||||
public:
|
||||
Impl() = default;
|
||||
~Impl() = default;
|
||||
void UpdateScreen(sptr<ScreenInfo> info);
|
||||
|
||||
ScreenId id_ { SCREEN_ID_INVALID };
|
||||
uint32_t virtualWidth_ { 0 };
|
||||
@@ -41,6 +42,22 @@ public:
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
};
|
||||
|
||||
void Screen::Impl::UpdateScreen(sptr<ScreenInfo> info)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
WLOGFE("info is nullptr.");
|
||||
return;
|
||||
}
|
||||
virtualWidth_ = info->virtualWidth_;
|
||||
virtualHeight_ = info->virtualHeight_;
|
||||
virtualPixelRatio_ = info->virtualPixelRatio_;
|
||||
parent_ = info->parent_;
|
||||
canHasChild_ = info->canHasChild_;
|
||||
modeId_ = info->modeId_;
|
||||
modes_ = info->modes_;
|
||||
rotation_ = info->rotation_;
|
||||
}
|
||||
|
||||
Screen::Screen(const ScreenInfo* info)
|
||||
: pImpl_(new Impl())
|
||||
{
|
||||
@@ -56,6 +73,7 @@ Screen::Screen(const ScreenInfo* info)
|
||||
pImpl_->canHasChild_ = info->canHasChild_;
|
||||
pImpl_->modeId_ = info->modeId_;
|
||||
pImpl_->modes_ = info->modes_;
|
||||
pImpl_->rotation_ = info->rotation_;
|
||||
}
|
||||
|
||||
Screen::~Screen()
|
||||
@@ -64,6 +82,8 @@ Screen::~Screen()
|
||||
|
||||
bool Screen::IsGroup() const
|
||||
{
|
||||
sptr<ScreenInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetScreenInfo(pImpl_->id_);
|
||||
pImpl_->UpdateScreen(info);
|
||||
return pImpl_->canHasChild_;
|
||||
}
|
||||
|
||||
@@ -74,6 +94,8 @@ ScreenId Screen::GetId() const
|
||||
|
||||
uint32_t Screen::GetWidth() const
|
||||
{
|
||||
sptr<ScreenInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetScreenInfo(pImpl_->id_);
|
||||
pImpl_->UpdateScreen(info);
|
||||
auto modeId = pImpl_->modeId_;
|
||||
auto modes = pImpl_->modes_;
|
||||
if (modeId < 0 || modeId >= modes.size()) {
|
||||
@@ -84,6 +106,8 @@ uint32_t Screen::GetWidth() const
|
||||
|
||||
uint32_t Screen::GetHeight() const
|
||||
{
|
||||
sptr<ScreenInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetScreenInfo(pImpl_->id_);
|
||||
pImpl_->UpdateScreen(info);
|
||||
auto modeId = pImpl_->modeId_;
|
||||
auto modes = pImpl_->modes_;
|
||||
if (modeId < 0 || modeId >= modes.size()) {
|
||||
@@ -94,21 +118,29 @@ uint32_t Screen::GetHeight() const
|
||||
|
||||
uint32_t Screen::GetVirtualWidth() const
|
||||
{
|
||||
sptr<ScreenInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetScreenInfo(pImpl_->id_);
|
||||
pImpl_->UpdateScreen(info);
|
||||
return pImpl_->virtualWidth_;
|
||||
}
|
||||
|
||||
uint32_t Screen::GetVirtualHeight() const
|
||||
{
|
||||
sptr<ScreenInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetScreenInfo(pImpl_->id_);
|
||||
pImpl_->UpdateScreen(info);
|
||||
return pImpl_->virtualHeight_;
|
||||
}
|
||||
|
||||
float Screen::GetVirtualPixelRatio() const
|
||||
{
|
||||
sptr<ScreenInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetScreenInfo(pImpl_->id_);
|
||||
pImpl_->UpdateScreen(info);
|
||||
return pImpl_->virtualPixelRatio_;
|
||||
}
|
||||
|
||||
Rotation Screen::GetRotation()
|
||||
{
|
||||
sptr<ScreenInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetScreenInfo(pImpl_->id_);
|
||||
pImpl_->UpdateScreen(info);
|
||||
return pImpl_->rotation_;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
void SetFreshRate(uint32_t freshRate);
|
||||
void SetVirtualPixelRatio(float virtualPixelRatio);
|
||||
bool RequestRotation(Rotation rotation);
|
||||
Rotation GetRotation();
|
||||
|
||||
private:
|
||||
DisplayId id_ { DISPLAY_ID_INVALD };
|
||||
|
||||
@@ -107,6 +107,11 @@ bool AbstractDisplay::RequestRotation(Rotation rotation)
|
||||
return true;
|
||||
}
|
||||
|
||||
Rotation AbstractDisplay::GetRotation()
|
||||
{
|
||||
return rotation_;
|
||||
}
|
||||
|
||||
bool AbstractDisplay::BindAbstractScreen(ScreenId dmsScreenId)
|
||||
{
|
||||
sptr<AbstractScreenController> screenController
|
||||
|
||||
@@ -102,6 +102,7 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
|
||||
displayInfo.height_ = display->GetHeight();
|
||||
displayInfo.freshRate_ = display->GetFreshRate();
|
||||
displayInfo.screenId_ = display->GetAbstractScreenId();
|
||||
displayInfo.rotation_ = display->GetRotation();
|
||||
return displayInfo;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user