From de66ef5b56bea3c4ad4d9b67faf1b8f0d4190d20 Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Thu, 17 Nov 2022 15:15:46 +0900 Subject: [PATCH] Add a method to update the screen size The real screen size may be different from the value of the preinitialized state. In case of ecore-wl2 backend, ecore_wl2_display_screen_size_get() may take some time. So save the screen size when it is called first and updade it when needed. Change-Id: Ief60c4f8ebcd5ba8b6dc7a0c74d8f22ed57bd757 --- .../adaptor/common/application-impl.cpp | 3 ++ .../android/window-system-android.cpp | 8 +++-- .../window-system/common/window-system.h | 12 ++++++-- .../window-system/macos/window-system-mac.mm | 12 +++++--- .../ecore-wl/window-system-ecore-wl.cpp | 8 +++-- .../ecore-wl2/window-base-ecore-wl2.cpp | 25 ++++++++-------- .../ecore-wl2/window-base-ecore-wl2.h | 2 -- .../ecore-wl2/window-system-ecore-wl2.cpp | 30 +++++++++++++++---- .../ubuntu-x11/window-system-ecore-x.cpp | 8 +++-- .../windows/window-system-win.cpp | 8 +++-- .../window-system/x11/window-system-x.cpp | 4 +++ 11 files changed, 86 insertions(+), 34 deletions(-) diff --git a/dali/internal/adaptor/common/application-impl.cpp b/dali/internal/adaptor/common/application-impl.cpp index 1032b3a37..c44318e9e 100644 --- a/dali/internal/adaptor/common/application-impl.cpp +++ b/dali/internal/adaptor/common/application-impl.cpp @@ -156,6 +156,9 @@ void Application::StoreWindowPositionSize(PositionSize positionSize) void Application::ChangePreInitializedWindowSize() { + // The real screen size may be different from the value of the preinitialized state. Update it. + Dali::Internal::Adaptor::WindowSystem::UpdateScreenSize(); + int screenWidth, screenHeight; Dali::Internal::Adaptor::WindowSystem::GetScreenSize(screenWidth, screenHeight); diff --git a/dali/internal/window-system/android/window-system-android.cpp b/dali/internal/window-system/android/window-system-android.cpp index 749e14011..1f6b120f0 100644 --- a/dali/internal/window-system/android/window-system-android.cpp +++ b/dali/internal/window-system/android/window-system-android.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ void Shutdown() { } -void GetScreenSize(int& width, int& height) +void GetScreenSize(int32_t& width, int32_t& height) { ANativeWindow* window = Dali::Integration::AndroidFramework::Get().GetApplicationWindow(); width = ANativeWindow_getWidth(window); @@ -47,6 +47,10 @@ void GetScreenSize(int& width, int& height) DALI_LOG_WARNING("Native window width %d, height %d", width, height); } +void UpdateScreenSize() +{ +} + bool SetKeyboardRepeatInfo(float rate, float delay) { return false; diff --git a/dali/internal/window-system/common/window-system.h b/dali/internal/window-system/common/window-system.h index ee92762f6..d6697919d 100644 --- a/dali/internal/window-system/common/window-system.h +++ b/dali/internal/window-system/common/window-system.h @@ -18,7 +18,9 @@ * */ +// EXTERNAL_HEADERS #include +#include namespace Dali { @@ -41,7 +43,13 @@ void Shutdown(); /** * @brief Get the screen size */ -void GetScreenSize(int& width, int& height); +void GetScreenSize(int32_t& width, int32_t& height); + +/** + * @brief Update the screen size + * @note The screen size may be updated while application is running. So update the stored size. + */ +void UpdateScreenSize(); /** * @copydoc Dali::Keyboard::SetRepeatInfo() @@ -136,7 +144,7 @@ public: * @param[out] width The width of the screen * @param[out] height The height of the screen */ - virtual void GetScreenSize(int& width, int& height) = 0; + virtual void GetScreenSize(int32_t& width, int32_t& height) = 0; }; } // namespace Adaptor diff --git a/dali/internal/window-system/macos/window-system-mac.mm b/dali/internal/window-system/macos/window-system-mac.mm index 9d2ee8315..70aa68c54 100644 --- a/dali/internal/window-system/macos/window-system-mac.mm +++ b/dali/internal/window-system/macos/window-system-mac.mm @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,15 @@ void Initialize() { } -void GetScreenSize( int& width, int& height ) +void GetScreenSize( int32_t& width, int32_t& height ) { NSRect r = [[NSScreen mainScreen] frame]; - width = static_cast(r.size.width); - height = static_cast(r.size.height); + width = static_cast(r.size.width); + height = static_cast(r.size.height); +} + +void UpdateScreenSize() +{ } bool SetKeyboardRepeatInfo( float rate, float delay ) diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl/window-system-ecore-wl.cpp b/dali/internal/window-system/tizen-wayland/ecore-wl/window-system-ecore-wl.cpp index 626ee7e86..4f57a10b9 100644 --- a/dali/internal/window-system/tizen-wayland/ecore-wl/window-system-ecore-wl.cpp +++ b/dali/internal/window-system/tizen-wayland/ecore-wl/window-system-ecore-wl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,11 +39,15 @@ void Shutdown() ecore_wl_shutdown(); } -void GetScreenSize(int& width, int& height) +void GetScreenSize(int32_t& width, int32_t& height) { ecore_wl_screen_size_get(&width, &height); } +void UpdateScreenSize() +{ +} + bool SetKeyboardRepeatInfo(float rate, float delay) { return ecore_wl_keyboard_repeat_info_set(static_cast(rate), static_cast(delay)); diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp index d2ebb005e..3c086b6fc 100644 --- a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp +++ b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp @@ -718,8 +718,6 @@ WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surf mWindowRotationAngle(0), mScreenRotationAngle(0), mSupportedPreProtation(0), - mScreenWidth(0), - mScreenHeight(0), mNotificationChangeState(0), mScreenOffModeChangeState(0), mBrightnessChangeState(0), @@ -1692,24 +1690,26 @@ bool WindowBaseEcoreWl2::IsEglWindowRotationSupported() PositionSize WindowBaseEcoreWl2::RecalculatePositionSizeToSystem(PositionSize positionSize) { PositionSize newPositionSize; + int32_t screenWidth, screenHeight; + WindowSystem::GetScreenSize(screenWidth, screenHeight); if(mWindowRotationAngle == 90) { newPositionSize.x = positionSize.y; - newPositionSize.y = mScreenHeight - (positionSize.x + positionSize.width); + newPositionSize.y = screenHeight - (positionSize.x + positionSize.width); newPositionSize.width = positionSize.height; newPositionSize.height = positionSize.width; } else if(mWindowRotationAngle == 180) { - newPositionSize.x = mScreenWidth - (positionSize.x + positionSize.width); - newPositionSize.y = mScreenHeight - (positionSize.y + positionSize.height); + newPositionSize.x = screenWidth - (positionSize.x + positionSize.width); + newPositionSize.y = screenHeight - (positionSize.y + positionSize.height); newPositionSize.width = positionSize.width; newPositionSize.height = positionSize.height; } else if(mWindowRotationAngle == 270) { - newPositionSize.x = mScreenWidth - (positionSize.y + positionSize.height); + newPositionSize.x = screenWidth - (positionSize.y + positionSize.height); newPositionSize.y = positionSize.x; newPositionSize.width = positionSize.height; newPositionSize.height = positionSize.width; @@ -1728,25 +1728,27 @@ PositionSize WindowBaseEcoreWl2::RecalculatePositionSizeToSystem(PositionSize po PositionSize WindowBaseEcoreWl2::RecalculatePositionSizeToCurrentOrientation(PositionSize positionSize) { PositionSize newPositionSize; + int32_t screenWidth, screenHeight; + WindowSystem::GetScreenSize(screenWidth, screenHeight); if(mWindowRotationAngle == 90) { - newPositionSize.x = mScreenHeight - (positionSize.y + positionSize.height); + newPositionSize.x = screenHeight - (positionSize.y + positionSize.height); newPositionSize.y = positionSize.x; newPositionSize.width = positionSize.height; newPositionSize.height = positionSize.width; } else if(mWindowRotationAngle == 180) { - newPositionSize.x = mScreenWidth - (positionSize.x + positionSize.width); - newPositionSize.y = mScreenHeight - (positionSize.y + positionSize.height); + newPositionSize.x = screenWidth - (positionSize.x + positionSize.width); + newPositionSize.y = screenHeight - (positionSize.y + positionSize.height); newPositionSize.width = positionSize.width; newPositionSize.height = positionSize.height; } else if(mWindowRotationAngle == 270) { newPositionSize.x = positionSize.y; - newPositionSize.y = mScreenWidth - (positionSize.x + positionSize.width); + newPositionSize.y = screenWidth - (positionSize.x + positionSize.width); newPositionSize.width = positionSize.height; newPositionSize.height = positionSize.width; } @@ -2636,9 +2638,6 @@ void WindowBaseEcoreWl2::CreateWindow(PositionSize positionSize) // Set default type ecore_wl2_window_type_set(mEcoreWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL); - - // Get Screen width, height - ecore_wl2_display_screen_size_get(display, &mScreenWidth, &mScreenHeight); } void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase, bool belowParent) diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h index 6b66478a3..d5789edff 100644 --- a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h +++ b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h @@ -618,8 +618,6 @@ private: int mWindowRotationAngle; int mScreenRotationAngle; int mSupportedPreProtation; - int mScreenWidth; - int mScreenHeight; uint32_t mNotificationChangeState; uint32_t mScreenOffModeChangeState; diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-system-ecore-wl2.cpp b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-system-ecore-wl2.cpp index b10af4c05..514c38b69 100644 --- a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-system-ecore-wl2.cpp +++ b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-system-ecore-wl2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,12 @@ namespace Adaptor { namespace WindowSystem { +namespace +{ +static int32_t gScreenWidth = 0; +static int32_t gScreenHeight = 0; +} // unnamed namespace + void Initialize() { ecore_wl2_init(); @@ -40,14 +46,28 @@ void Shutdown() ecore_wl2_shutdown(); } -void GetScreenSize(int& width, int& height) +void GetScreenSize(int32_t& width, int32_t& height) +{ + if(gScreenWidth == 0 || gScreenHeight == 0) + { + Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL); + if(display) + { + ecore_wl2_display_screen_size_get(display, &gScreenWidth, &gScreenHeight); + DALI_ASSERT_ALWAYS((gScreenWidth > 0) && "screen width is 0"); + DALI_ASSERT_ALWAYS((gScreenHeight > 0) && "screen height is 0"); + } + } + width = gScreenWidth; + height = gScreenHeight; +} + +void UpdateScreenSize() { Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL); if(display) { - ecore_wl2_display_screen_size_get(display, &width, &height); - DALI_ASSERT_ALWAYS((width > 0) && "screen width is 0"); - DALI_ASSERT_ALWAYS((height > 0) && "screen height is 0"); + ecore_wl2_display_screen_size_get(display, &gScreenWidth, &gScreenHeight); } } diff --git a/dali/internal/window-system/ubuntu-x11/window-system-ecore-x.cpp b/dali/internal/window-system/ubuntu-x11/window-system-ecore-x.cpp index aa9143861..71f840e5d 100644 --- a/dali/internal/window-system/ubuntu-x11/window-system-ecore-x.cpp +++ b/dali/internal/window-system/ubuntu-x11/window-system-ecore-x.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,11 +40,15 @@ void Shutdown() ecore_x_shutdown(); } -void GetScreenSize(int& width, int& height) +void GetScreenSize(int32_t& width, int32_t& height) { ecore_x_screen_size_get(ecore_x_default_screen_get(), &width, &height); } +void UpdateScreenSize() +{ +} + bool SetKeyboardRepeatInfo(float rate, float delay) { return false; diff --git a/dali/internal/window-system/windows/window-system-win.cpp b/dali/internal/window-system/windows/window-system-win.cpp index 1536d0d22..7740edd96 100644 --- a/dali/internal/window-system/windows/window-system-win.cpp +++ b/dali/internal/window-system/windows/window-system-win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,12 +33,16 @@ void Initialize() { } -void GetScreenSize(int& width, int& height) +void GetScreenSize(int32_t& width, int32_t& height) { width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); } +void UpdateScreenSize() +{ +} + bool SetKeyboardRepeatInfo(float rate, float delay) { return false; diff --git a/dali/internal/window-system/x11/window-system-x.cpp b/dali/internal/window-system/x11/window-system-x.cpp index 13c5618fd..d43981227 100644 --- a/dali/internal/window-system/x11/window-system-x.cpp +++ b/dali/internal/window-system/x11/window-system-x.cpp @@ -1044,6 +1044,10 @@ void GetScreenSize(int& width, int& height) } } +void UpdateScreenSize() +{ +} + bool SetKeyboardRepeatInfo(float rate, float delay) { return false; -- 2.34.1