Set display size as screen mode changes

Change-Id: I8c49155056aaa161c483941f4a857fcb2614db34
Signed-off-by: shiyueeee <nieshiyue@huawei.com>
This commit is contained in:
shiyueeee 2022-01-30 17:55:41 +08:00
parent 8cd99a305e
commit 98f5dd15f4
22 changed files with 468 additions and 27 deletions

View File

@ -28,6 +28,7 @@ public:
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override;
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override;
virtual void OnDisplayChange(const sptr<DisplayInfo>, DisplayChangeEvent) override;
};
}
}

View File

@ -32,7 +32,7 @@ public:
void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) override {};
void OnDisplayCreate(sptr<DisplayInfo>) override {};
void OnDisplayDestroy(DisplayId) override {};
void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) override {};
void OnDisplayChange(const sptr<DisplayInfo>, DisplayChangeEvent) override {};
};
}
}

View File

@ -25,6 +25,7 @@ private:
int32_t width_ { 0 };
int32_t height_ { 0 };
uint32_t freshRate_ { 0 };
ScreenId screenId_ {SCREEN_ID_INVALID};
};
Display::Display(const std::string& name, DisplayInfo* info)
@ -35,6 +36,7 @@ Display::Display(const std::string& name, DisplayInfo* info)
pImpl_->width_ = info->width_;
pImpl_->height_ = info->height_;
pImpl_->freshRate_ = info->freshRate_;
pImpl_->screenId_ = info->screenId_;
}
DisplayId Display::GetId() const
@ -57,6 +59,11 @@ uint32_t Display::GetFreshRate() const
return pImpl_->freshRate_;
}
ScreenId Display::GetScreenId() const
{
return pImpl_->screenId_;
}
void Display::SetWidth(int32_t width)
{
pImpl_->width_ = width;

View File

@ -82,7 +82,7 @@ public:
}
};
void OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event) override
void OnDisplayChange(const sptr<DisplayInfo> displayInfo, DisplayChangeEvent event) override
{
if (displayInfo == nullptr || displayInfo->id_ == DISPLAY_ID_INVALD) {
WLOGFE("OnDisplayChange, displayInfo is invalid.");
@ -94,7 +94,7 @@ public:
}
WLOGD("OnDisplayChange. display %{public}" PRIu64", event %{public}u", displayInfo->id_, event);
for (auto listener : pImpl_->displayListeners_) {
listener->OnChange(displayInfo->id_);
listener->OnChange(displayInfo->id_, event);
}
};
private:
@ -364,6 +364,16 @@ void DisplayManager::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
WLOGFW("callback_ target is not set!");
}
void DisplayManager::NotifyDisplayChangedEvent(const sptr<DisplayInfo> info, DisplayChangeEvent event)
{
WLOGI("NotifyDisplayChangedEvent event:%{public}u, size:%{public}zu", event,
pImpl_->displayListeners_.size());
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
for (auto& listener : pImpl_->displayListeners_) {
listener->OnChange(info->id_, event);
}
}
bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason)
{
WLOGFI("WakeUpBegin start, reason:%{public}u", reason);

View File

@ -47,15 +47,35 @@ sptr<Display> DisplayManagerAdapter::GetDisplayById(DisplayId displayId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto iter = displayMap_.find(displayId);
if (iter != displayMap_.end()) {
return iter->second;
if (!InitDMSProxyLocked()) {
WLOGFE("GetDisplayById: InitDMSProxyLocked failed!");
return nullptr;
}
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::GetDisplayById: InitDMSProxyLocked failed!");
auto iter = displayMap_.find(displayId);
if (iter != displayMap_.end()) {
// Update display in map
// should be updated automatically
DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId);
if (displayInfo.id_ == DISPLAY_ID_INVALD) {
WLOGFE("GetDisplayById: Get invalid displayInfo!");
return nullptr;
}
sptr<Display> display = iter->second;
if (displayInfo.width_ != display->GetWidth()) {
display->SetWidth(displayInfo.width_);
WLOGFI("GetDisplayById: set new width %{public}d", display->GetWidth());
}
if (displayInfo.height_ != display->GetHeight()) {
display->SetHeight(displayInfo.height_);
WLOGFI("GetDisplayById: set new height %{public}d", display->GetHeight());
}
if (displayInfo.freshRate_ != display->GetFreshRate()) {
display->SetFreshRate(displayInfo.freshRate_);
WLOGFI("GetDisplayById: set new freshRate %{public}ud", display->GetFreshRate());
}
return iter->second;
}
DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId);
sptr<Display> display = new Display("", &displayInfo);
if (display->GetId() != DISPLAY_ID_INVALD) {

View File

@ -28,5 +28,10 @@ void DisplayManagerAgent::NotifyDisplayStateChanged(DisplayId id, DisplayState s
{
SingletonContainer::Get<DisplayManager>().NotifyDisplayStateChanged(id, state);
}
void DisplayManagerAgent::OnDisplayChange(const sptr<DisplayInfo> info, DisplayChangeEvent event)
{
SingletonContainer::Get<DisplayManager>().NotifyDisplayChangedEvent(info, event);
}
} // namespace Rosen
} // namespace OHOS

View File

@ -19,6 +19,7 @@ group("systemtest") {
testonly = true
deps = [
":dm_display_change_test",
":dm_display_minimal_test",
":dm_display_power_test",
":dm_screen_gamut_test",
@ -48,6 +49,17 @@ ohos_systemtest("dm_display_power_test") {
## SystemTest dm_display_minimal_test }}}
## SystemTest dm_display_change_test {{{
ohos_systemtest("dm_display_change_test") {
module_out_path = module_out_path
sources = [ "display_change_test.cpp" ]
deps = [ ":dm_systemtest_common" ]
}
## SystemTest dm_display_change_test }}}
## SystemTest dm_screenshot_test {{{
ohos_systemtest("dm_screenshot_test") {
module_out_path = module_out_path

View File

@ -0,0 +1,276 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include "display_info.h"
#include "display_manager.h"
#include "screen_manager.h"
#include "screen_manager/rs_screen_mode_info.h"
#include "window_manager_hilog.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayChangeTest"};
constexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 20;
constexpr uint32_t SLEEP_TIME_IN_US = 1000; // 1ms
}
class DisplayChangeEventListener : public DisplayManager::IDisplayListener {
public:
virtual void OnCreate(DisplayId displayId)
{
WLOGI("DisplayChangeEventListener::OnCreate displayId=%{public}" PRIu64"", displayId);
}
virtual void OnDestroy(DisplayId displayId)
{
WLOGI("DisplayChangeEventListener::OnDestroy displayId=%{public}" PRIu64"", displayId);
}
virtual void OnChange(DisplayId displayId, DisplayChangeEvent event)
{
WLOGI("DisplayChangeEventListener::OnChange displayId=%{public}" PRIu64"", displayId);
isCallbackCalled_ = true;
event_ = event;
displayId_ = displayId;
}
bool isCallbackCalled_ { false };
DisplayChangeEvent event_ { DisplayChangeEvent::UNKNOWN };
DisplayId displayId_ { DISPLAY_ID_INVALD };
};
using DisplayChangeCallback = std::function<void(sptr<DisplayInfo>, DisplayChangeEvent)>;
class DisplayChangeTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
bool CheckDisplayChangeEventCallback(bool valueExpected);
bool ScreenSizeEqual(const sptr<Screen> screen, const sptr<SupportedScreenModes> curInfo);
bool DisplaySizeEqual(const sptr<Display> display, const sptr<SupportedScreenModes> curInfo);
static DisplayId defaultdisplayId_;
static sptr<DisplayChangeEventListener> listener_;
static inline uint32_t times_ = 0;
};
DisplayId DisplayChangeTest::defaultdisplayId_ = DISPLAY_ID_INVALD;
sptr<DisplayChangeEventListener> DisplayChangeTest::listener_ = new DisplayChangeEventListener();
void DisplayChangeTest::SetUpTestCase()
{
defaultdisplayId_ = DisplayManager::GetInstance().GetDefaultDisplayId();
if (defaultdisplayId_ == DISPLAY_ID_INVALD) {
WLOGE("DisplayId is invalid!");
}
if (!DisplayManager::GetInstance().RegisterDisplayListener(listener_)) {
WLOGE("Fail to register display listener");
}
}
void DisplayChangeTest::TearDownTestCase()
{
DisplayManager::GetInstance().UnregisterDisplayListener(listener_);
}
void DisplayChangeTest::SetUp()
{
times_ = 0;
listener_->isCallbackCalled_ = false;
listener_->event_ = DisplayChangeEvent::UNKNOWN;
listener_->displayId_ = DISPLAY_ID_INVALD;
}
void DisplayChangeTest::TearDown()
{
}
bool DisplayChangeTest::CheckDisplayChangeEventCallback(bool valueExpected)
{
WLOGI("CheckDisplayChangeEventCallback in");
do {
if (listener_->isCallbackCalled_ == valueExpected) {
WLOGI("CheckDisplayChangeEventCallback: get valueExpected %{public}d for display %{public}" PRIu64"",
static_cast<int>(valueExpected), listener_->displayId_);
return true;
}
WLOGI("CheckDisplayChangeEventCallback: wait times %{public}d", times_);
usleep(SLEEP_TIME_IN_US);
++times_;
} while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK);
return false;
}
bool DisplayChangeTest::ScreenSizeEqual(const sptr<Screen> screen, const sptr<SupportedScreenModes> curInfo)
{
uint32_t sWidth = screen->GetWidth();
uint32_t sHeight = screen->GetHeight();
WLOGI("ScreenSizeEqual: ScreenSize: %{public}u %{public}u, ActiveModeInfoSize: %{public}u %{public}u",
sWidth, sHeight, curInfo->width_, curInfo->height_);
return ((curInfo->width_ == sWidth) && (curInfo->height_ == sHeight));
}
bool DisplayChangeTest::DisplaySizeEqual(const sptr<Display> display, const sptr<SupportedScreenModes> curInfo)
{
uint32_t dWidth = static_cast<uint32_t>(display->GetWidth());
uint32_t dHeight = static_cast<uint32_t>(display->GetHeight());
WLOGI("DisplaySizeEqual:: DisplaySize: %{public}u %{public}u, ActiveModeInfoSize: %{public}u %{public}u",
dWidth, dHeight, curInfo->width_, curInfo->height_);
return ((curInfo->width_ == dWidth) && (curInfo->height_ == dHeight));
}
namespace {
/**
* @tc.name: RegisterDisplayChangeListener01
* @tc.desc: Register displayChangeListener with valid listener and check return true
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, RegisterDisplayChangeListener01, Function | SmallTest | Level2)
{
sptr<DisplayChangeEventListener> listener = new DisplayChangeEventListener();
bool ret = DisplayManager::GetInstance().RegisterDisplayListener(listener);
ASSERT_EQ(true, ret);
}
/**
* @tc.name: RegisterDisplayChangeListener02
* @tc.desc: Register displayChangeListener with nullptr and check return false
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, RegisterDisplayChangeListener02, Function | SmallTest | Level2)
{
bool ret = DisplayManager::GetInstance().RegisterDisplayListener(nullptr);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: UnregisterDisplayChangeListener01
* @tc.desc: Unregister displayChangeListener with valid listener and check return true
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, UnregisterDisplayChangeListener01, Function | SmallTest | Level2)
{
sptr<DisplayChangeEventListener> listener = new DisplayChangeEventListener();
DisplayManager::GetInstance().RegisterDisplayListener(listener);
bool ret = DisplayManager::GetInstance().UnregisterDisplayListener(listener);
ASSERT_EQ(true, ret);
}
/**
* @tc.name: UnregisterDisplayChangeListener02
* @tc.desc: Register displayChangeListener with nullptr and check return false
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, UnregisterDisplayChangeListener02, Function | SmallTest | Level2)
{
bool ret = DisplayManager::GetInstance().UnregisterDisplayListener(nullptr);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: UnregisterDisplayChangeListener03
* @tc.desc: Register displayChangeListener with invalid listener and check return false
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, UnregisterDisplayChangeListener03, Function | SmallTest | Level2)
{
sptr<DisplayChangeEventListener> listener = new DisplayChangeEventListener();
bool ret = DisplayManager::GetInstance().UnregisterDisplayListener(listener);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: CheckDisplayStateChange01
* @tc.desc: DisplayState not change if screen sets same mode
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, CheckDisplayStateChange01, Function | SmallTest | Level2)
{
WLOGFI("CheckDisplayStateChange01");
sptr<Display> defaultDisplay = DisplayManager::GetInstance().GetDisplayById(defaultdisplayId_);
ScreenId screenId = defaultDisplay->GetScreenId();
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(screenId);
ASSERT_NE(nullptr, screen);
uint32_t usedModeIdx = screen->GetModeId();
screen->SetScreenActiveMode(usedModeIdx);
WLOGFI("SetScreenActiveMode: %{public}u", usedModeIdx);
ASSERT_EQ(false, CheckDisplayChangeEventCallback(true));
}
/**
* @tc.name: CheckDisplayStateChange02
* @tc.desc: DisplayState changes if screen sets different mode
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, CheckDisplayStateChange02, Function | SmallTest | Level2)
{
WLOGFI("CheckDisplayStateChange02");
sptr<Display> defaultDisplay = DisplayManager::GetInstance().GetDisplayById(defaultdisplayId_);
ScreenId screenId = defaultDisplay->GetScreenId();
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(screenId);
ASSERT_NE(nullptr, screen);
auto modes = screen->GetSupportedModes();
uint32_t usedModeIdx = screen->GetModeId();
WLOGFI("usedModeIdx / SupportMode size: %{public}u %{public}d", usedModeIdx, static_cast<int>(modes.size()));
for (uint32_t modeIdx = 0; modeIdx < modes.size(); modeIdx++) {
if (modeIdx != usedModeIdx) {
screen->SetScreenActiveMode(modeIdx);
WLOGFI("SetScreenActiveMode: %{public}u", modeIdx);
ASSERT_EQ(true, CheckDisplayChangeEventCallback(true));
WLOGFI("CheckDisplayChangeEventCallback: true");
}
}
screen->SetScreenActiveMode(usedModeIdx);
WLOGFI("SetScreenActiveMode: %{public}u", usedModeIdx);
}
/**
* @tc.name: CheckDisplaySizeChange01
* @tc.desc: Check display size change as screen mode set if screen sets another mode
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, CheckDisplaySizeChange01, Function | MediumTest | Level2)
{
WLOGFI("CheckDisplaySizeChange01");
sptr<Display> defaultDisplay = DisplayManager::GetInstance().GetDisplayById(defaultdisplayId_);
ScreenId screenId = defaultDisplay->GetScreenId();
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(screenId);
ASSERT_NE(nullptr, screen);
auto modes = screen->GetSupportedModes();
uint32_t usedModeIdx = screen->GetModeId();
WLOGFI("usedModeIdx / SupportMode size: %{public}u %{public}d", usedModeIdx, static_cast<int>(modes.size()));
for (uint32_t modeIdx = 0; modeIdx < modes.size(); modeIdx++) {
if (modeIdx != usedModeIdx) {
screen->SetScreenActiveMode(modeIdx);
WLOGFI("SetScreenActiveMode: %{public}u -> %{public}u", usedModeIdx, modeIdx);
ASSERT_EQ(true, ScreenSizeEqual(screen, modes[modeIdx]));
ASSERT_EQ(true, CheckDisplayChangeEventCallback(true));
defaultDisplay = DisplayManager::GetInstance().GetDisplayById(defaultdisplayId_);
ASSERT_EQ(true, DisplaySizeEqual(defaultDisplay, modes[modeIdx]));
}
}
screen->SetScreenActiveMode(usedModeIdx);
WLOGFI("SetScreenActiveMode: %{public}u", usedModeIdx);
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -45,9 +45,12 @@ private:
void OnAbstractScreenConnect(sptr<AbstractScreen> absScreen);
void OnAbstractScreenDisconnect(sptr<AbstractScreen> absScreen);
void OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event);
void ProcessDisplayUpdateRotation(sptr<AbstractScreen> absScreen);
void ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen);
void BindAloneScreenLocked(sptr<AbstractScreen> absScreen);
void AddScreenToMirrorLocked(sptr<AbstractScreenGroup> group, sptr<AbstractScreen> realAbsScreen);
void ProcessScreenDisconnected(sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup);
bool UpdateDisplaySize(sptr<AbstractDisplay> absDisplay, sptr<SupportedScreenModes> info);
std::recursive_mutex& mutex_;
std::atomic<DisplayId> displayCount_ { 0 };

View File

@ -81,6 +81,7 @@ private:
bool CheckScreenInScreenGroup(sptr<AbstractScreen> newScreen) const;
sptr<AbstractScreenGroup> AddAsFirstScreenLocked(sptr<AbstractScreen> newScreen);
sptr<AbstractScreenGroup> AddAsSuccedentScreenLocked(sptr<AbstractScreen> newScreen);
void ProcessScreenModeChanged(ScreenId rsScreenId);
std::recursive_mutex& mutex_;
OHOS::Rosen::RSInterfaces& rsInterface_;

View File

@ -148,6 +148,7 @@ const sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
displayInfo->height_ = height_;
displayInfo->id_ = id_;
displayInfo->freshRate_ = freshRate_;
displayInfo->screenId_ = screenId_;
return displayInfo;
}
} // namespace OHOS::Rosen

View File

@ -168,10 +168,22 @@ void AbstractDisplayController::ProcessScreenDisconnected(
void AbstractDisplayController::OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event)
{
if (event != DisplayChangeEvent::UPDATE_ROTATION) {
WLOGFE("unknown display event: %{public}u", event);
if (absScreen == nullptr) {
WLOGE("OnAbstractScreenChanged::the information of the screen is wrong");
return;
}
WLOGI("screen changes. id:%{public}" PRIu64"", absScreen->dmsId_);
if (event == DisplayChangeEvent::UPDATE_ROTATION) {
ProcessDisplayUpdateRotation(absScreen);
}
if (event == DisplayChangeEvent::DISPLAY_SIZE_CHANGED) {
ProcessDisplaySizeChange(absScreen);
}
}
void AbstractDisplayController::ProcessDisplayUpdateRotation(sptr<AbstractScreen> absScreen)
{
sptr<AbstractDisplay> abstractDisplay = nullptr;
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto iter = abstractDisplayMap_.begin();
@ -214,6 +226,43 @@ void AbstractDisplayController::OnAbstractScreenChange(sptr<AbstractScreen> absS
}
}
void AbstractDisplayController::ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen)
{
sptr<SupportedScreenModes> info = absScreen->GetActiveScreenMode();
if (info == nullptr) {
WLOGE("cannot get active screen info.");
return;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto iter = abstractDisplayMap_.begin(); iter != abstractDisplayMap_.end(); iter++) {
sptr<AbstractDisplay> absDisplay = iter->second;
if (absDisplay->GetAbstractScreenId() != absScreen->dmsId_) {
continue;
}
if (UpdateDisplaySize(absDisplay, info)) {
WLOGFI("Notify display size change");
DisplayManagerService::GetInstance().NotifyDisplayStateChange(
iter->first, DisplayStateChangeType::SIZE_CHANGE);
DisplayManagerAgentController::GetInstance().OnDisplayChange(
absDisplay->ConvertToDisplayInfo(), DisplayChangeEvent::DISPLAY_SIZE_CHANGED);
}
}
}
bool AbstractDisplayController::UpdateDisplaySize(sptr<AbstractDisplay> absDisplay, sptr<SupportedScreenModes> info)
{
if (info->height_ == absDisplay->GetHeight() && info->width_ == absDisplay->GetWidth()) {
WLOGI("keep display size. display:%{public}" PRIu64"", absDisplay->GetId());
return false;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
absDisplay->SetHeight(info->height_);
absDisplay->SetWidth(info->width_);
WLOGI("update display size. id %{public}" PRIu64", size: %{public}d %{public}d",
absDisplay->GetId(), absDisplay->GetWidth(), absDisplay->GetHeight());
return true;
}
void AbstractDisplayController::BindAloneScreenLocked(sptr<AbstractScreen> realAbsScreen)
{
ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();

View File

@ -19,6 +19,7 @@
#include <screen_manager/rs_screen_mode_info.h>
#include <screen_manager/screen_types.h>
#include <surface.h>
#include <thread>
#include "display_manager_agent_controller.h"
#include "display_manager_service.h"
@ -235,6 +236,35 @@ void AbstractScreenController::OnRsScreenConnectionChange(ScreenId rsScreenId, S
}
}
void AbstractScreenController::ProcessScreenModeChanged(ScreenId rsScreenId)
{
auto iter = rs2DmsScreenIdMap_.find(rsScreenId);
if (iter == rs2DmsScreenIdMap_.end()) {
WLOGE("ProcessScreenModeChanged: screenId=%{public}" PRIu64" is not in rs2DmsScreenIdMap_", rsScreenId);
return;
}
WLOGFD("ProcessScreenModeChanged: process screen info changes");
ScreenId dmsScreenId = iter->second;
auto dmsScreenMapIter = dmsScreenMap_.find(dmsScreenId);
if (dmsScreenMapIter == dmsScreenMap_.end()) {
WLOGE("ProcessScreenModeChanged: no dms screen is found, rsscreenId=%{public}" PRIu64"", rsScreenId);
return;
}
sptr<AbstractScreen> absScreen = dmsScreenMapIter->second;
int32_t activeModeId = rsInterface_.GetScreenActiveMode(rsScreenId).GetScreenModeId();
if (activeModeId < 0 || activeModeId >= absScreen->modes_.size()) {
WLOGE("activeModeId exceed, screenId=%{public}" PRIu64", activeModeId:%{public}d/%{public}u",
rsScreenId, activeModeId, static_cast<uint32_t>(absScreen->modes_.size()));
return;
}
absScreen->activeIdx_ = activeModeId;
if (abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onChange_(absScreen, DisplayChangeEvent::DISPLAY_SIZE_CHANGED);
}
DisplayManagerAgentController::GetInstance().OnScreenChange(
absScreen->ConvertToScreenInfo(), ScreenChangeEvent::CHANGE_MODE);
}
void AbstractScreenController::ProcessScreenDisconnected(ScreenId rsScreenId)
{
WLOGI("disconnect screen, screenId=%{public}" PRIu64"", rsScreenId);
@ -557,7 +587,20 @@ bool AbstractScreenController::SetScreenActiveMode(ScreenId screenId, uint32_t m
WLOGFE("SetScreenActiveMode: Get AbstractScreen failed");
return false;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
uint32_t usedModeId = screen->activeIdx_;
screen->activeIdx_ = modeId;
// add thread to process mode change sync event
// should be called by OnRsScreenChange if rs implement corresponding event callback
if (usedModeId != modeId) {
WLOGI("SetScreenActiveMode: modeId: %{public}u -> %{public}u", usedModeId, modeId);
auto func = [=]() {
ProcessScreenModeChanged(screenId);
return;
};
std::thread thread(func);
thread.detach();
}
return true;
}

View File

@ -135,7 +135,8 @@ void DisplayManagerAgentController::OnDisplayDestroy(DisplayId displayId)
}
}
void DisplayManagerAgentController::OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent screenChangeEvent)
void DisplayManagerAgentController::OnDisplayChange(
sptr<DisplayInfo> displayInfo, DisplayChangeEvent displayChangeEvent)
{
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
if (agents.empty()) {
@ -143,7 +144,7 @@ void DisplayManagerAgentController::OnDisplayChange(sptr<DisplayInfo> displayInf
}
WLOGFI("OnDisplayChange");
for (auto& agent : agents) {
agent->OnDisplayChange(displayInfo, screenChangeEvent);
agent->OnDisplayChange(displayInfo, displayChangeEvent);
}
}
}

View File

@ -92,12 +92,16 @@ DisplayId DisplayManagerService::GetDefaultDisplayId()
DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
{
DisplayInfo displayInfo;
ScreenId screenId = GetScreenIdFromDisplayId(displayId);
auto screenModeInfo = abstractDisplayController_->GetScreenActiveMode(screenId);
sptr<AbstractDisplay> display = GetDisplayByDisplayId(displayId);
if (display == nullptr) {
WLOGFE("GetDisplayById: Get invalid display!");
return displayInfo;
}
displayInfo.id_ = displayId;
displayInfo.width_ = screenModeInfo.GetScreenWidth();
displayInfo.height_ = screenModeInfo.GetScreenHeight();
displayInfo.freshRate_ = screenModeInfo.GetScreenFreshRate();
displayInfo.width_ = display->GetWidth();
displayInfo.height_ = display->GetHeight();
displayInfo.freshRate_ = display->GetFreshRate();
displayInfo.screenId_ = display->GetAbstractScreenId();
return displayInfo;
}

View File

@ -17,12 +17,10 @@
#define FOUNDATION_DM_DISPLAY_H
#include <string>
#include <refbase.h>
#include "dm_common.h"
namespace OHOS::Rosen {
class DisplayInfo;
using DisplayId = uint64_t;
static constexpr DisplayId DISPLAY_ID_INVALD = -1ULL;
typedef enum DisplayType {
DEFAULT = 0,
@ -37,6 +35,7 @@ public:
int32_t GetWidth() const;
int32_t GetHeight() const;
uint32_t GetFreshRate() const;
ScreenId GetScreenId() const;
float GetVirtualPixelRatio() const;
void SetId(DisplayId displayId);

View File

@ -35,7 +35,7 @@ public:
public:
virtual void OnCreate(DisplayId) = 0;
virtual void OnDestroy(DisplayId) = 0;
virtual void OnChange(DisplayId) = 0;
virtual void OnChange(DisplayId, DisplayChangeEvent) = 0;
};
std::vector<const sptr<Display>> GetAllDisplays();
@ -64,6 +64,7 @@ public:
uint32_t GetScreenBrightness(uint64_t screenId) const;
void NotifyDisplayEvent(DisplayEvent event);
constexpr static int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 3840; // max resolution, 4K
private:
DisplayManager();
~DisplayManager();
@ -75,6 +76,7 @@ private:
void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);
void NotifyDisplayStateChanged(DisplayId id, DisplayState state);
void NotifyDisplayChangedEvent(const sptr<DisplayInfo> info, DisplayChangeEvent event);
};
} // namespace OHOS::Rosen

View File

@ -20,6 +20,11 @@
namespace OHOS {
namespace Rosen {
using DisplayId = uint64_t;
using ScreenId = uint64_t;
static constexpr DisplayId DISPLAY_ID_INVALD = -1ULL;
static constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
enum class PowerStateChangeReason : uint32_t {
POWER_BUTTON,
};
@ -83,6 +88,7 @@ enum class ScreenChangeEvent : uint32_t {
REMOVE_FROM_GROUP,
CHANGE_GROUP,
UPDATE_ROTATION,
CHANGE_MODE,
};
enum class Rotation : uint32_t {
@ -95,6 +101,7 @@ enum class Rotation : uint32_t {
enum class DisplayChangeEvent : uint32_t {
UPDATE_ROTATION,
DISPLAY_SIZE_CHANGED,
UNKNOWN,
};
}
}

View File

@ -19,7 +19,6 @@
#include <string>
#include <vector>
#include <refbase.h>
#include <surface.h>
#include <screen_manager/screen_types.h>
@ -27,8 +26,6 @@
namespace OHOS::Rosen {
class ScreenInfo;
using ScreenId = uint64_t;
static constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
struct Point {
int32_t posX_;

View File

@ -24,6 +24,7 @@ enum class DisplayStateChangeType : uint32_t {
BEFORE_SUSPEND,
BEFORE_UNLOCK,
UPDATE_ROTATION,
SIZE_CHANGE,
};
class IDisplayChangeListener : public RefBase {
public:

View File

@ -37,6 +37,7 @@ public:
int32_t width_ { 0 };
int32_t height_ { 0 };
uint32_t freshRate_ { 0 };
ScreenId screenId_ { SCREEN_ID_INVALID };
float xDpi_ { 0.0 };
float yDpi_ { 0.0 };
Rotation rotation_ { Rotation::ROTATION_0 };

View File

@ -23,6 +23,7 @@ void DisplayInfo::Update(DisplayInfo* info)
width_ = info->width_;
height_ = info->height_;
freshRate_ = info->freshRate_;
screenId_ = info->screenId_;
xDpi_ = info->xDpi_;
yDpi_ = info->yDpi_;
rotation_ = info->rotation_;
@ -32,7 +33,7 @@ bool DisplayInfo::Marshalling(Parcel &parcel) const
{
return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) &&
parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
parcel.WriteUint32(freshRate_) &&
parcel.WriteUint32(freshRate_) && parcel.WriteUint64(screenId_) &&
parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
parcel.WriteUint32(static_cast<uint32_t>(rotation_));
}
@ -47,7 +48,7 @@ DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
uint32_t rotation;
bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
parcel.ReadUint32(displayInfo->freshRate_) &&
parcel.ReadUint32(displayInfo->freshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
parcel.ReadUint32(rotation);
if (!res) {