[Tizen] Add a method to update the screen size 47/284447/1
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 17 Nov 2022 06:15:46 +0000 (15:15 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Thu, 17 Nov 2022 08:17:41 +0000 (17:17 +0900)
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

dali/internal/adaptor/common/application-impl.cpp
dali/internal/window-system/android/window-system-android.cpp
dali/internal/window-system/common/window-system.h
dali/internal/window-system/macos/window-system-mac.mm
dali/internal/window-system/tizen-wayland/ecore-wl/window-system-ecore-wl.cpp
dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp
dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h
dali/internal/window-system/tizen-wayland/ecore-wl2/window-system-ecore-wl2.cpp
dali/internal/window-system/ubuntu-x11/window-system-ecore-x.cpp
dali/internal/window-system/windows/window-system-win.cpp

index 13a3fbe..148758f 100644 (file)
@@ -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);
 
index 749e140..1f6b120 100644 (file)
@@ -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;
index ee92762..d669791 100644 (file)
@@ -18,7 +18,9 @@
  *
  */
 
+// EXTERNAL_HEADERS
 #include <dali/public-api/object/any.h>
+#include <cstdint>
 
 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
index 9d2ee83..70aa68c 100644 (file)
@@ -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<int>(r.size.width);
-  height = static_cast<int>(r.size.height);
+  width = static_cast<int32_t>(r.size.width);
+  height = static_cast<int32_t>(r.size.height);
+}
+
+void UpdateScreenSize()
+{
 }
 
 bool SetKeyboardRepeatInfo( float rate, float delay )
index 626ee7e..4f57a10 100644 (file)
@@ -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<double>(rate), static_cast<double>(delay));
index 903dc20..7aaf6db 100644 (file)
@@ -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),
@@ -1690,24 +1688,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;
@@ -1726,25 +1726,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;
   }
@@ -2634,9 +2636,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)
index 6b66478..d5789ed 100644 (file)
@@ -618,8 +618,6 @@ private:
   int        mWindowRotationAngle;
   int        mScreenRotationAngle;
   int        mSupportedPreProtation;
-  int        mScreenWidth;
-  int        mScreenHeight;
 
   uint32_t          mNotificationChangeState;
   uint32_t          mScreenOffModeChangeState;
index b10af4c..514c38b 100644 (file)
@@ -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);
   }
 }
 
index aa91438..71f840e 100644 (file)
@@ -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;
index 1536d0d..7740edd 100644 (file)
@@ -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;