mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 06:50:40 +00:00
Description:去除为拓展屏单独设置DPI功能
IssueNo:https://gitee.com/openharmony/window_window_manager/issues/IB5BTT Binary Source:No Signed-off-by: songjiawei9 <songjiawei9@h-partners.com>
This commit is contained in:
parent
86be0556e9
commit
4bc201ad3b
@ -34,7 +34,6 @@ const static std::string DEFAULT_SCREEN_NAME = "buildIn";
|
||||
constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 1000;
|
||||
constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80;
|
||||
constexpr uint32_t BASELINE_DENSITY = 160;
|
||||
constexpr float INCH_TO_MM = 25.4f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,7 +245,6 @@ public:
|
||||
void NotifyScreenMagneticStateChanged(bool isMagneticState);
|
||||
void OnTentModeChanged(bool isTentMode);
|
||||
void RegisterSettingDpiObserver();
|
||||
void RegisterExtendSettingDpiObserver();
|
||||
void RegisterSettingRotationObserver();
|
||||
|
||||
void OnConnect(ScreenId screenId) override {}
|
||||
@ -342,7 +341,6 @@ private:
|
||||
sptr<ScreenSession> GetOrCreateScreenSession(ScreenId screenId);
|
||||
void CreateScreenProperty(ScreenId screenId, ScreenProperty& property);
|
||||
void InitExtendScreenDensity(sptr<ScreenSession> session, ScreenProperty property);
|
||||
float CalcDefaultExtendScreenDensity(const ScreenProperty& property);
|
||||
sptr<ScreenSession> GetScreenSessionInner(ScreenId screenId, ScreenProperty property);
|
||||
sptr<ScreenSession> CreatePhysicalMirrorSessionInner(ScreenId screenId, ScreenId defaultScreenId,
|
||||
ScreenProperty property);
|
||||
@ -512,7 +510,6 @@ private:
|
||||
void HandleFoldScreenPowerInit();
|
||||
void SetFoldScreenPowerInit(std::function<void()> foldScreenPowerInit);
|
||||
void SetDpiFromSettingData();
|
||||
void SetDpiFromSettingData(bool isInternal);
|
||||
void SetRotateLockedFromSettingData();
|
||||
void NotifyClientProxyUpdateFoldDisplayMode(FoldDisplayMode displayMode);
|
||||
void UpdateDisplayScaleState(ScreenId screenId);
|
||||
@ -531,6 +528,7 @@ private:
|
||||
void RegisterCastObserver(std::vector<ScreenId>& mirrorScreenIds);
|
||||
void ExitCoordination(const std::string& reason);
|
||||
void UpdateDisplayState(std::vector<ScreenId> screenIds, DisplayState state);
|
||||
void SetExtendPixelRatio(const float& dpi);
|
||||
DisplayState lastDisplayState_ { DisplayState::UNKNOWN };
|
||||
|
||||
private:
|
||||
|
@ -27,8 +27,6 @@ class ScreenSettingHelper {
|
||||
public:
|
||||
static void RegisterSettingDpiObserver(SettingObserver::UpdateFunc func);
|
||||
static void UnregisterSettingDpiObserver();
|
||||
static void RegisterExtendSettingDpiObserver(SettingObserver::UpdateFunc func);
|
||||
static void UnregisterExtendSettingDpiObserver();
|
||||
static bool GetSettingDpi(uint32_t& dpi, const std::string& key = SETTING_DPI_KEY);
|
||||
static bool SetSettingDefaultDpi(uint32_t& dpi, const std::string& key);
|
||||
static bool GetSettingValue(uint32_t& value, const std::string& key);
|
||||
@ -56,7 +54,6 @@ public:
|
||||
|
||||
private:
|
||||
static const constexpr char* SETTING_DPI_KEY {"user_set_dpi_value"};
|
||||
static const constexpr char* SETTING_DPI_KEY_EXTEND {"user_set_dpi_value_extend"};
|
||||
static const constexpr char* SETTING_CAST_KEY {"huaweicast.data.privacy_projection_state"};
|
||||
static const constexpr char* SETTING_ROTATION_KEY {"screen_rotation_value"};
|
||||
static const constexpr char* SETTING_ROTATION_SCREEN_ID_KEY {"screen_rotation_screen_id_value"};
|
||||
@ -64,7 +61,6 @@ private:
|
||||
static const constexpr char* SETTING_SCREEN_MODE_KEY {"user_set_last_screen_mode"};
|
||||
static const constexpr char* SETTING_RELATIVE_POSITION_KEY {"user_set_relative_position"};
|
||||
static sptr<SettingObserver> dpiObserver_;
|
||||
static sptr<SettingObserver> extendDpiObserver_;
|
||||
static sptr<SettingObserver> castObserver_;
|
||||
static sptr<SettingObserver> rotationObserver_;
|
||||
};
|
||||
|
@ -97,7 +97,6 @@ constexpr int32_t CAST_WIRED_PROJECTION_START = 1005;
|
||||
constexpr int32_t CAST_WIRED_PROJECTION_STOP = 1007;
|
||||
constexpr int32_t RES_FAILURE_FOR_PRIVACY_WINDOW = -2;
|
||||
constexpr int32_t REMOVE_DISPLAY_MODE = 0;
|
||||
constexpr int32_t INVALID_DPI = 0;
|
||||
constexpr int32_t IRREGULAR_REFRESH_RATE_SKIP_THRETHOLD = 10;
|
||||
constexpr uint32_t SCREEN_MAIN_IN_DATA = 0;
|
||||
constexpr uint32_t SCREEN_MIRROR_IN_DATA = 1;
|
||||
@ -111,14 +110,11 @@ const int32_t ROTATE_POLICY = system::GetIntParameter("const.window.device.rotat
|
||||
constexpr int32_t FOLDABLE_DEVICE { 2 };
|
||||
constexpr float DEFAULT_PIVOT = 0.5f;
|
||||
constexpr float DEFAULT_SCALE = 1.0f;
|
||||
static const constexpr char* SETTING_DPI_KEY {"user_set_dpi_value"};
|
||||
static const constexpr char* SETTING_DPI_KEY_EXTEND {"user_set_dpi_value_extend"};
|
||||
static const constexpr char* SET_SETTING_DPI_KEY {"default_display_dpi"};
|
||||
|
||||
const std::string SCREEN_EXTEND = "extend";
|
||||
const std::string SCREEN_MIRROR = "mirror";
|
||||
const std::string SCREEN_UNKNOWN = "unknown";
|
||||
constexpr float PHYSICAL_MASS = 1.6f;
|
||||
|
||||
// based on the bundle_util
|
||||
inline int32_t GetUserIdByCallingUid()
|
||||
@ -796,7 +792,6 @@ void ScreenSessionManager::RecoverMultiScreenInfoFromData(sptr<ScreenSession> sc
|
||||
secondaryScreenOption.screenId_, secondaryScreenOption.startX_, secondaryScreenOption.startY_);
|
||||
SetMultiScreenMode(mainScreenOption.screenId_, secondaryScreenOption.screenId_, multiScreenMode);
|
||||
SetMultiScreenRelativePosition(mainScreenOption, secondaryScreenOption);
|
||||
SetDpiFromSettingData(false);
|
||||
}
|
||||
|
||||
void ScreenSessionManager::HandleScreenConnectEvent(sptr<ScreenSession> screenSession,
|
||||
@ -1512,9 +1507,14 @@ void ScreenSessionManager::InitExtendScreenDensity(sptr<ScreenSession> session,
|
||||
TLOGI(WmsLogTag::DMS, "Not expandable screen, no need to set dpi");
|
||||
return;
|
||||
}
|
||||
float extendDensity = CalcDefaultExtendScreenDensity(property);
|
||||
ScreenId mainScreenId = GetDefaultScreenId();
|
||||
sptr<ScreenSession> screenSession = GetScreenSession(mainScreenId);
|
||||
if (screenSession == nullptr) {
|
||||
TLOGE(WmsLogTag::DMS, "screenSession is nullptr");
|
||||
return;
|
||||
}
|
||||
float extendDensity = screenSession->GetScreenProperty().GetDensity();
|
||||
TLOGI(WmsLogTag::DMS, "extendDensity = %{public}f", extendDensity);
|
||||
extendDefaultDpi_ = static_cast<uint32_t>(extendDensity * BASELINE_DENSITY);
|
||||
session->SetVirtualPixelRatio(extendDensity);
|
||||
session->SetDefaultDensity(extendDensity);
|
||||
session->SetDensityInCurResolution(extendDensity);
|
||||
@ -1529,26 +1529,6 @@ void ScreenSessionManager::InitExtendScreenDensity(sptr<ScreenSession> session,
|
||||
return;
|
||||
}
|
||||
|
||||
float ScreenSessionManager::CalcDefaultExtendScreenDensity(const ScreenProperty& property)
|
||||
{
|
||||
int32_t phyWith = property.GetPhyWidth();
|
||||
int32_t phyHeight = property.GetPhyHeight();
|
||||
float phyDiagonal = std::sqrt(static_cast<float>(phyWith * phyWith + phyHeight * phyHeight));
|
||||
TLOGI(WmsLogTag::DMS, "phyDiagonal:%{public}f", phyDiagonal);
|
||||
if (phyDiagonal > 0) {
|
||||
RRect phyBounds = property.GetPhyBounds();
|
||||
int32_t width = phyBounds.rect_.GetWidth();
|
||||
int32_t height = phyBounds.rect_.GetHeight();
|
||||
float PPI = std::sqrt(static_cast<float>(width * width + height * height)) * INCH_TO_MM / phyDiagonal;
|
||||
float DPI = std::ceil(PPI * PHYSICAL_MASS);
|
||||
TLOGI(WmsLogTag::DMS, "DPI:%{public}f", DPI);
|
||||
float density = DPI / BASELINE_DENSITY;
|
||||
return density;
|
||||
} else {
|
||||
return densityDpi_;
|
||||
}
|
||||
}
|
||||
|
||||
sptr<ScreenSession> ScreenSessionManager::GetOrCreateScreenSession(ScreenId screenId)
|
||||
{
|
||||
TLOGI(WmsLogTag::DMS, "ENTER. ScreenId: %{public}" PRIu64 "", screenId);
|
||||
@ -2271,7 +2251,6 @@ void ScreenSessionManager::BootFinishedCallback(const char *key, const char *val
|
||||
that.SetRotateLockedFromSettingData();
|
||||
that.SetDpiFromSettingData();
|
||||
that.RegisterSettingDpiObserver();
|
||||
that.RegisterExtendSettingDpiObserver();
|
||||
if (that.foldScreenPowerInit_ != nullptr) {
|
||||
that.foldScreenPowerInit_();
|
||||
}
|
||||
@ -2310,21 +2289,9 @@ void ScreenSessionManager::SetRotateLockedFromSettingData()
|
||||
|
||||
void ScreenSessionManager::RegisterSettingDpiObserver()
|
||||
{
|
||||
TLOGI(WmsLogTag::DMS, "start");
|
||||
if (ScreenSceneConfig::GetExternalScreenDefaultMode() == "mirror") {
|
||||
SettingObserver::UpdateFunc updateFunc = [&](const std::string& key) { SetDpiFromSettingData(); };
|
||||
ScreenSettingHelper::RegisterSettingDpiObserver(updateFunc);
|
||||
} else {
|
||||
SettingObserver::UpdateFunc updateFunc = [&](const std::string& key) { SetDpiFromSettingData(true); };
|
||||
ScreenSettingHelper::RegisterSettingDpiObserver(updateFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSessionManager::RegisterExtendSettingDpiObserver()
|
||||
{
|
||||
TLOGI(WmsLogTag::DMS, "start");
|
||||
SettingObserver::UpdateFunc updateFunc = [&](const std::string& key) { SetDpiFromSettingData(false); };
|
||||
ScreenSettingHelper::RegisterExtendSettingDpiObserver(updateFunc);
|
||||
TLOGI(WmsLogTag::DMS, "Register Setting Dpi Observer");
|
||||
SettingObserver::UpdateFunc updateFunc = [&](const std::string& key) { SetDpiFromSettingData(); };
|
||||
ScreenSettingHelper::RegisterSettingDpiObserver(updateFunc);
|
||||
}
|
||||
|
||||
void ScreenSessionManager::SetDpiFromSettingData()
|
||||
@ -2343,45 +2310,22 @@ void ScreenSessionManager::SetDpiFromSettingData()
|
||||
float dpi = static_cast<float>(settingDpi) / BASELINE_DENSITY;
|
||||
ScreenId defaultScreenId = GetDefaultScreenId();
|
||||
SetVirtualPixelRatio(defaultScreenId, dpi);
|
||||
if (g_isPcDevice) {
|
||||
SetExtendPixelRatio(dpi);
|
||||
}
|
||||
} else {
|
||||
TLOGE(WmsLogTag::DMS, "setting dpi error, settingDpi: %{public}d", settingDpi);
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSessionManager::SetDpiFromSettingData(bool isInternal)
|
||||
void ScreenSessionManager::SetExtendPixelRatio(const float& dpi)
|
||||
{
|
||||
uint32_t settingDpi = INVALID_DPI;
|
||||
bool ret = false;
|
||||
if (isInternal == true) {
|
||||
ret = ScreenSettingHelper::GetSettingDpi(settingDpi, SETTING_DPI_KEY);
|
||||
} else {
|
||||
ret = ScreenSettingHelper::GetSettingDpi(settingDpi, SETTING_DPI_KEY_EXTEND);
|
||||
}
|
||||
if (!ret) {
|
||||
TLOGW(WmsLogTag::DMS, "get setting dpi failed,use default dpi");
|
||||
if (isInternal) {
|
||||
settingDpi = defaultDpi;
|
||||
} else {
|
||||
settingDpi = extendDefaultDpi_;
|
||||
std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
|
||||
for (const auto& sessionIt : screenSessionMap_) {
|
||||
const auto& screenSession = sessionIt.second;
|
||||
if (screenSession->GetScreenProperty().GetScreenType() == ScreenType::REAL && !screenSession->isInternal_) {
|
||||
SetVirtualPixelRatio(sessionIt.first, dpi);
|
||||
}
|
||||
} else {
|
||||
TLOGI(WmsLogTag::DMS, "get setting dpi success,settingDpi: %{public}u", settingDpi);
|
||||
}
|
||||
if (settingDpi >= DOT_PER_INCH_MINIMUM_VALUE && settingDpi <= DOT_PER_INCH_MAXIMUM_VALUE) {
|
||||
float dpi = static_cast<float>(settingDpi) / BASELINE_DENSITY;
|
||||
ScreenId screenId = SCREEN_ID_INVALID;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(screenSessionMapMutex_);
|
||||
for (const auto& sessionIt : screenSessionMap_) {
|
||||
const auto& screenSession = sessionIt.second;
|
||||
if (screenSession->GetScreenProperty().GetScreenType() == ScreenType::REAL &&
|
||||
screenSession->isInternal_ == isInternal) {
|
||||
screenId = sessionIt.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
SetVirtualPixelRatio(screenId, dpi);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
sptr<SettingObserver> ScreenSettingHelper::dpiObserver_;
|
||||
sptr<SettingObserver> ScreenSettingHelper::extendDpiObserver_;
|
||||
sptr<SettingObserver> ScreenSettingHelper::castObserver_;
|
||||
sptr<SettingObserver> ScreenSettingHelper::rotationObserver_;
|
||||
constexpr int32_t PARAM_NUM_TEN = 10;
|
||||
@ -47,21 +46,6 @@ void ScreenSettingHelper::RegisterSettingDpiObserver(SettingObserver::UpdateFunc
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSettingHelper::RegisterExtendSettingDpiObserver(SettingObserver::UpdateFunc func)
|
||||
{
|
||||
if (extendDpiObserver_) {
|
||||
TLOGD(WmsLogTag::DMS, "setting extend dpi observer is registered");
|
||||
return;
|
||||
}
|
||||
SettingProvider& provider = SettingProvider::GetInstance(DISPLAY_MANAGER_SERVICE_SA_ID);
|
||||
extendDpiObserver_ = provider.CreateObserver(SETTING_DPI_KEY_EXTEND, func);
|
||||
ErrCode ret = provider.RegisterObserver(extendDpiObserver_);
|
||||
if (ret != ERR_OK) {
|
||||
TLOGW(WmsLogTag::DMS, "failed, ret=%{public}d", ret);
|
||||
extendDpiObserver_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSettingHelper::UnregisterSettingDpiObserver()
|
||||
{
|
||||
if (dpiObserver_ == nullptr) {
|
||||
@ -76,20 +60,6 @@ void ScreenSettingHelper::UnregisterSettingDpiObserver()
|
||||
dpiObserver_ = nullptr;
|
||||
}
|
||||
|
||||
void ScreenSettingHelper::UnregisterExtendSettingDpiObserver()
|
||||
{
|
||||
if (extendDpiObserver_ == nullptr) {
|
||||
TLOGD(WmsLogTag::DMS, "extendDpiObserver_ is nullptr");
|
||||
return;
|
||||
}
|
||||
SettingProvider& provider = SettingProvider::GetInstance(DISPLAY_MANAGER_SERVICE_SA_ID);
|
||||
ErrCode ret = provider.UnregisterObserver(extendDpiObserver_);
|
||||
if (ret != ERR_OK) {
|
||||
TLOGW(WmsLogTag::DMS, "failed, ret=%{public}d", ret);
|
||||
}
|
||||
extendDpiObserver_ = nullptr;
|
||||
}
|
||||
|
||||
bool ScreenSettingHelper::GetSettingDpi(uint32_t& dpi, const std::string& key)
|
||||
{
|
||||
return GetSettingValue(dpi, key);
|
||||
|
@ -212,30 +212,6 @@ namespace {
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterExtendSettingDpiObserver01
|
||||
* @tc.desc: UnregisterExtendSettingDpiObserver01
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenSettingHelperTest, UnregisterExtendSettingDpiObserver01, Function | SmallTest | Level3)
|
||||
{
|
||||
ScreenSettingHelper::extendDpiObserver_ = nullptr;
|
||||
ScreenSettingHelper::UnregisterExtendSettingDpiObserver();
|
||||
ASSERT_EQ(ScreenSettingHelper::extendDpiObserver_, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterExtendSettingDpiObserver02
|
||||
* @tc.desc: UnregisterExtendSettingDpiObserver02
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenSettingHelperTest, UnregisterExtendSettingDpiObserver02, Function | SmallTest | Level3)
|
||||
{
|
||||
ScreenSettingHelper::extendDpiObserver_ = new SettingObserver;
|
||||
ScreenSettingHelper::UnregisterExtendSettingDpiObserver();
|
||||
ASSERT_EQ(ScreenSettingHelper::extendDpiObserver_, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterSettingRotationObserver01
|
||||
* @tc.desc: UnregisterSettingRotationObserver01
|
||||
@ -244,7 +220,6 @@ namespace {
|
||||
HWTEST_F(ScreenSettingHelperTest, UnregisterSettingRotationObserver01, Function | SmallTest | Level3)
|
||||
{
|
||||
ScreenSettingHelper::rotationObserver_ = nullptr;
|
||||
ScreenSettingHelper::UnregisterExtendSettingDpiObserver();
|
||||
ASSERT_EQ(ScreenSettingHelper::rotationObserver_, nullptr);
|
||||
}
|
||||
|
||||
@ -256,7 +231,6 @@ namespace {
|
||||
HWTEST_F(ScreenSettingHelperTest, UnregisterSettingRotationObserver02, Function | SmallTest | Level3)
|
||||
{
|
||||
ScreenSettingHelper::rotationObserver_ = new SettingObserver;
|
||||
ScreenSettingHelper::UnregisterExtendSettingDpiObserver();
|
||||
ASSERT_NE(ScreenSettingHelper::rotationObserver_, nullptr);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user