Support screen and client rotation
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-base-ecore-wl2.cpp
index 0879f0f..856a8de 100755 (executable)
@@ -702,37 +702,41 @@ const struct tizen_display_policy_listener tizenDisplayPolicyListener =
 
 } // unnamed namespace
 
-WindowBaseEcoreWl2::WindowBaseEcoreWl2( Dali::PositionSize positionSize, Any surface, bool isTransparent )
+WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surface, bool isTransparent)
 : mEcoreEventHandler(),
-  mEcoreWindow( NULL ),
-  mWlSurface( NULL ),
-  mEglWindow( NULL ),
-  mDisplay( NULL ),
-  mEventQueue( NULL ),
-  mTizenPolicy( NULL ),
-  mTizenDisplayPolicy( NULL ),
-  mKeyMap( NULL ),
+  mEcoreWindow(nullptr),
+  mWlSurface(nullptr),
+  mEglWindow(nullptr),
+  mDisplay(nullptr),
+  mEventQueue(nullptr),
+  mTizenPolicy(nullptr),
+  mTizenDisplayPolicy(nullptr),
+  mKeyMap(nullptr),
   mSupportedAuxiliaryHints(),
   mAuxiliaryHints(),
-  mNotificationLevel( -1 ),
-  mNotificationChangeState( 0 ),
-  mNotificationLevelChangeDone( true ),
-  mScreenOffMode( 0 ),
-  mScreenOffModeChangeState( 0 ),
-  mScreenOffModeChangeDone( true ),
-  mBrightness( 0 ),
-  mBrightnessChangeState( 0 ),
-  mBrightnessChangeDone( true ),
-  mVisible( true ),
-  mWindowPositionSize( positionSize ),
-  mOwnSurface( false ),
-  mMoveResizeSerial( 0 ),
-  mLastSubmittedMoveResizeSerial( 0 )
+  mNotificationLevel(-1),
+  mNotificationChangeState(0),
+  mNotificationLevelChangeDone(true),
+  mScreenOffMode(0),
+  mScreenOffModeChangeState(0),
+  mScreenOffModeChangeDone(true),
+  mBrightness(0),
+  mBrightnessChangeState(0),
+  mBrightnessChangeDone(true),
+  mVisible(true),
+  mWindowPositionSize(positionSize),
+  mOwnSurface(false),
+  mMoveResizeSerial(0),
+  mLastSubmittedMoveResizeSerial(0),
+  mWindowRotationAngle(0),
+  mScreenRotationAngle(0),
+  mSupportedPreProtation(0)
 #ifdef DALI_ELDBUS_AVAILABLE
-  , mSystemConnection( NULL )
+  ,
+  mSystemConnection(NULL)
 #endif
 {
-  Initialize( positionSize, surface, isTransparent );
+  Initialize(positionSize, surface, isTransparent);
 }
 
 WindowBaseEcoreWl2::~WindowBaseEcoreWl2()
@@ -949,6 +953,8 @@ Eina_Bool WindowBaseEcoreWl2::OnOutputTransform( void* data, int type, void* eve
   {
     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow );
 
+    mScreenRotationAngle = GetScreenRotationAngle();
+
     mOutputTransformedSignal.Emit();
   }
 
@@ -963,39 +969,42 @@ Eina_Bool WindowBaseEcoreWl2::OnIgnoreOutputTransform( void* data, int type, voi
   {
     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow );
 
+    mScreenRotationAngle = GetScreenRotationAngle();
+
     mOutputTransformedSignal.Emit();
   }
 
   return ECORE_CALLBACK_PASS_ON;
 }
 
-void WindowBaseEcoreWl2::OnRotation( void* data, int type, void* event )
+void WindowBaseEcoreWl2::OnRotation(void* data, int type, void* event)
 {
-  Ecore_Wl2_Event_Window_Rotation* ev( static_cast< Ecore_Wl2_Event_Window_Rotation* >( event ) );
+  Ecore_Wl2_Event_Window_Rotation* ev(static_cast<Ecore_Wl2_Event_Window_Rotation*>(event));
 
-  if( ev->win == static_cast< unsigned int >( ecore_wl2_window_id_get( mEcoreWindow ) ) )
+  if(ev->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
   {
-    DALI_LOG_RELEASE_INFO( "WindowBaseEcoreWl2::OnRotation, angle: %d, width: %d, height: %d\n", ev->angle, ev->w, ev->h );
+    DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnRotation, angle: %d, width: %d, height: %d\n", ev->angle, ev->w, ev->h);
 
     RotationEvent rotationEvent;
-    rotationEvent.angle = ev->angle;
+    rotationEvent.angle     = ev->angle;
     rotationEvent.winResize = 0;
+    mWindowRotationAngle    = ev->angle;
 
-    if( ev->angle == 0 || ev->angle == 180 )
+    if(ev->angle == 0 || ev->angle == 180)
     {
-      rotationEvent.width = ev->w;
+      rotationEvent.width  = ev->w;
       rotationEvent.height = ev->h;
     }
     else
     {
-      rotationEvent.width = ev->h;
+      rotationEvent.width  = ev->h;
       rotationEvent.height = ev->w;
     }
 
-    mWindowPositionSize.width = rotationEvent.width;
+    mWindowPositionSize.width  = rotationEvent.width;
     mWindowPositionSize.height = rotationEvent.height;
 
-    mRotationSignal.Emit( rotationEvent );
+    mRotationSignal.Emit(rotationEvent);
   }
 }
 
@@ -1117,7 +1126,7 @@ void WindowBaseEcoreWl2::OnMouseButtonCancel( void* data, int type, void* event
 
     mTouchEventSignal.Emit( point, touchEvent->timestamp );
 
-    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnMouseButtonCancel\n" );
+    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnMouseButtonCancel\n" );
   }
 }
 
@@ -1127,7 +1136,7 @@ void WindowBaseEcoreWl2::OnMouseWheel( void* data, int type, void* event )
 
   if( mouseWheelEvent->window == static_cast< unsigned int >( ecore_wl2_window_id_get( mEcoreWindow ) ) )
   {
-    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnMouseWheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z );
+    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnMouseWheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z );
 
     Integration::WheelEvent wheelEvent( Integration::WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2( mouseWheelEvent->x, mouseWheelEvent->y ), mouseWheelEvent->z, mouseWheelEvent->timestamp );
 
@@ -1139,7 +1148,7 @@ void WindowBaseEcoreWl2::OnDetentRotation( void* data, int type, void* event )
 {
   Ecore_Event_Detent_Rotate* detentEvent = static_cast< Ecore_Event_Detent_Rotate* >( event );
 
-  DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::OnDetentRotation\n" );
+  DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::OnDetentRotation\n" );
 
   int direction = ( detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE ) ? 1 : -1;
   int timeStamp = detentEvent->timestamp;
@@ -1155,7 +1164,7 @@ void WindowBaseEcoreWl2::OnKeyDown( void* data, int type, void* event )
 
   if( keyEvent->window == static_cast< unsigned int >( ecore_wl2_window_id_get( mEcoreWindow ) ) )
   {
-    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyDown\n" );
+    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyDown\n" );
 
     std::string keyName( keyEvent->keyname );
     std::string logicalKey( "" );
@@ -1217,7 +1226,7 @@ void WindowBaseEcoreWl2::OnKeyUp( void* data, int type, void* event )
 
   if( keyEvent->window == static_cast< unsigned int >( ecore_wl2_window_id_get( mEcoreWindow ) ) )
   {
-    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyUp\n" );
+    DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyUp\n" );
 
 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 23)
     // Cancel processing flag is sent because this key event will combine with the previous key. So, the event should not actually perform anything.
@@ -1436,11 +1445,19 @@ int WindowBaseEcoreWl2::GetNativeWindowId()
   return ecore_wl2_window_id_get( mEcoreWindow );
 }
 
-EGLNativeWindowType WindowBaseEcoreWl2::CreateEglWindow( int width, int height )
+EGLNativeWindowType WindowBaseEcoreWl2::CreateEglWindow(int width, int height)
 {
-  mEglWindow = wl_egl_window_create( mWlSurface, width, height );
+  int totalAngle = (mWindowRotationAngle + mScreenRotationAngle) % 360;
+  if(totalAngle == 90 || totalAngle == 270)
+  {
+    mEglWindow = wl_egl_window_create(mWlSurface, height, width);
+  }
+  else
+  {
+    mEglWindow = wl_egl_window_create(mWlSurface, width, height);
+  }
 
-  return static_cast< EGLNativeWindowType >( mEglWindow );
+  return static_cast<EGLNativeWindowType>(mEglWindow);
 }
 
 void WindowBaseEcoreWl2::DestroyEglWindow()
@@ -1575,12 +1592,13 @@ void WindowBaseEcoreWl2::ResizeEglWindow( PositionSize positionSize )
 bool WindowBaseEcoreWl2::IsEglWindowRotationSupported()
 {
   // Check capability
-  wl_egl_window_tizen_capability capability = static_cast< wl_egl_window_tizen_capability >( wl_egl_window_tizen_get_capabilities( mEglWindow ) );
-  if( capability == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED )
+  wl_egl_window_tizen_capability capability = static_cast<wl_egl_window_tizen_capability>(wl_egl_window_tizen_get_capabilities(mEglWindow));
+  if(capability == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED)
   {
+    mSupportedPreProtation = true;
     return true;
   }
-
+  mSupportedPreProtation = false;
   return false;
 }
 
@@ -1624,20 +1642,21 @@ void WindowBaseEcoreWl2::Activate()
   ecore_wl2_window_activate( mEcoreWindow );
 }
 
-void WindowBaseEcoreWl2::SetAvailableAnlges( const std::vector< int >& angles )
+void WindowBaseEcoreWl2::SetAvailableAnlges(const std::vector<int>& angles)
 {
-  int rotations[4] = { 0 };
-  DALI_LOG_RELEASE_INFO( "WindowBaseEcoreWl2::SetAvailableAnlges, angle's count: %d, angles\n", angles.size() );
-  for( std::size_t i = 0; i < angles.size(); ++i )
+  int rotations[4] = {0};
+  DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetAvailableAnlges, angle's count: %d, angles\n", angles.size());
+  for(std::size_t i = 0; i < angles.size(); ++i)
   {
-    rotations[i] = static_cast< int >( angles[i] );
-    DALI_LOG_RELEASE_INFO( "%d ", rotations[i] );
+    rotations[i] = static_cast<int>(angles[i]);
+    DALI_LOG_RELEASE_INFO("%d ", rotations[i]);
   }
-  ecore_wl2_window_available_rotations_set( mEcoreWindow, rotations, angles.size() );
+  ecore_wl2_window_available_rotations_set(mEcoreWindow, rotations, angles.size());
 }
 
 void WindowBaseEcoreWl2::SetPreferredAngle( int angle )
 {
+  DALI_LOG_RELEASE_INFO( "WindowBaseEcoreWl2::SetPreferredAngle, angle: %d\n", angle );
   ecore_wl2_window_preferred_rotation_set( mEcoreWindow, angle );
 }
 
@@ -2334,30 +2353,41 @@ void WindowBaseEcoreWl2::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiV
   dpiVertical   = int( yres + 0.5f );
 }
 
+int WindowBaseEcoreWl2::GetOrientation() const
+{
+  int orientation = (mScreenRotationAngle + mWindowRotationAngle) % 360;
+  if(mSupportedPreProtation)
+  {
+    orientation = 0;
+  }
+  return orientation;
+}
+
 int WindowBaseEcoreWl2::GetScreenRotationAngle()
 {
   int transform = 0;
 
-  if( ecore_wl2_window_ignore_output_transform_get( mEcoreWindow ) )
+  if(ecore_wl2_window_ignore_output_transform_get(mEcoreWindow))
   {
     transform = 0;
   }
   else
   {
-    transform = ecore_wl2_output_transform_get( ecore_wl2_window_output_find( mEcoreWindow ) );
+    transform = ecore_wl2_output_transform_get(ecore_wl2_window_output_find(mEcoreWindow));
   }
-
-  return transform * 90;
+  mScreenRotationAngle = transform * 90;
+  return mScreenRotationAngle;
 }
 
-void WindowBaseEcoreWl2::SetWindowRotationAngle( int degree )
+void WindowBaseEcoreWl2::SetWindowRotationAngle(int degree)
 {
-  ecore_wl2_window_rotation_set( mEcoreWindow, degree );
+  mWindowRotationAngle = degree;
+  ecore_wl2_window_rotation_set(mEcoreWindow, degree);
 }
 
-void WindowBaseEcoreWl2::WindowRotationCompleted( int degree, int width, int height )
+void WindowBaseEcoreWl2::WindowRotationCompleted(int degree, int width, int height)
 {
-  ecore_wl2_window_rotation_change_done_send( mEcoreWindow, degree, width, height );
+  ecore_wl2_window_rotation_change_done_send(mEcoreWindow, degree, width, height);
 }
 
 void WindowBaseEcoreWl2::SetTransparency( bool transparent )