Merge "Use existing callback ID for recurring callbacks" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index be836c1..ab97cb4
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -19,6 +19,7 @@
 #include <dali/internal/window-system/common/window-impl.h>
 
 // EXTERNAL HEADERS
+#include <thread>
 #include <dali/integration-api/core.h>
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/render-tasks/render-task.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
 #include <dali/public-api/rendering/frame-buffer.h>
+#include <dali/public-api/adaptor-framework/window-enumerations.h>
 #include <dali/devel-api/adaptor-framework/orientation.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 
 // INTERNAL HEADERS
 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
 #include <dali/internal/window-system/common/event-handler.h>
 #include <dali/internal/window-system/common/orientation-impl.h>
 #include <dali/internal/window-system/common/render-surface-factory.h>
@@ -39,6 +42,7 @@
 #include <dali/internal/window-system/common/window-system.h>
 #include <dali/internal/window-system/common/window-render-surface.h>
 #include <dali/internal/window-system/common/window-visibility-observer.h>
+#include <dali/devel-api/adaptor-framework/accessibility-impl.h>
 
 namespace Dali
 {
@@ -56,11 +60,17 @@ Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "
 
 } // unnamed namespace
 
-Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
+Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
+{
+  Any surface;
+  return Window::New(surface, positionSize, name, className, isTransparent);
+}
+
+Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
 {
   Window* window = new Window();
   window->mIsTransparent = isTransparent;
-  window->Initialize( positionSize, name, className );
+  window->Initialize(surface, positionSize, name, className);
   return window;
 }
 
@@ -72,36 +82,44 @@ Window::Window()
   mIconified( false ),
   mOpaqueState( false ),
   mResizeEnabled( false ),
-  mType( Dali::Window::NORMAL ),
+  mType( WindowType::NORMAL ),
   mParentWindow( NULL ),
-  mPreferredAngle( Dali::Window::NO_ORIENTATION_PREFERENCE ),
+  mPreferredAngle( static_cast< int >( WindowOrientation::NO_ORIENTATION_PREFERENCE ) ),
   mRotationAngle( -1 ),
   mWindowWidth( 0 ),
   mWindowHeight( 0 ),
   mOrientationMode( Internal::Adaptor::Window::OrientationMode::PORTRAIT ),
   mNativeWindowId( -1 ),
-  mFocusChangedSignal(),
-  mResizedSignal(),
   mDeleteRequestSignal(),
   mFocusChangeSignal(),
   mResizeSignal(),
   mVisibilityChangedSignal(),
-  mTransitionEffectEventSignal()
+  mTransitionEffectEventSignal(),
+  mKeyboardRepeatSettingsChangedSignal()
 {
 }
 
 Window::~Window()
 {
+  if ( mAdaptor )
+  {
+    auto bridge = Accessibility::Bridge::GetCurrentBridge();
+    auto accessible2 = mScene.GetRootLayer();
+    auto accessible = Accessibility::Accessible::Get( accessible2 );
+    bridge->RemoveTopLevelWindow( accessible );
+
+    mAdaptor->RemoveWindow( this );
+  }
+
   if ( mEventHandler )
   {
     mEventHandler->RemoveObserver( *this );
   }
 }
 
-void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
+void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className)
 {
   // Create a window render surface
-  Any surface;
   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
@@ -114,6 +132,8 @@ void Window::Initialize(const PositionSize& positionSize, const std::string& nam
   mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
   mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
   mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
+  mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect( this, &Window::OnKeyboardRepeatSettingsChanged );
+  mWindowBase->WindowRedrawRequestSignal().Connect( this, &Window::OnWindowRedrawRequest );
 
   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
 
@@ -146,25 +166,21 @@ void Window::Initialize(const PositionSize& positionSize, const std::string& nam
 
 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
 {
-  mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
+  mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface->GetWindowBase(), *mAdaptor ) );
   mEventHandler->AddObserver( *this );
-}
 
-void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
-{
-  mWindowSurface = static_cast<WindowRenderSurface*>( surface );
-}
-
-void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
-{
-}
+  auto bridge = Accessibility::Bridge::GetCurrentBridge();
+  auto v = mScene.GetRootLayer();
+  auto accessible = Accessibility::Accessible::Get( v, true );
+  bridge->AddTopLevelWindow( accessible );
 
-void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
-{
+  //FIXME: line below is temporary solution for missing "activate" signal and should be removed
+  Show();
 }
 
-void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
+void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
 {
+  mWindowSurface = static_cast<WindowRenderSurface*>( surface );
 }
 
 void Window::SetClass( std::string name, std::string className )
@@ -182,18 +198,27 @@ std::string Window::GetClassName() const
 void Window::Raise()
 {
   mWindowBase->Raise();
+
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId );
 }
 
 void Window::Lower()
 {
   mWindowBase->Lower();
+
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId );
 }
 
 void Window::Activate()
 {
   mWindowBase->Activate();
+
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId );
 }
 
@@ -212,7 +237,7 @@ Dali::RenderTaskList Window::GetRenderTaskList() const
   return mScene.GetRenderTaskList();
 }
 
-void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
+void Window::AddAvailableOrientation( WindowOrientation orientation )
 {
   if( IsOrientationAvailable( orientation ) == false )
   {
@@ -238,7 +263,7 @@ void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientatio
   }
 }
 
-void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
+void Window::RemoveAvailableOrientation( WindowOrientation orientation )
 {
   if( IsOrientationAvailable( orientation ) == false )
   {
@@ -260,9 +285,9 @@ void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orienta
   SetAvailableAnlges( mAvailableAngles );
 }
 
-void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
+void Window::SetPreferredOrientation( WindowOrientation orientation )
 {
-  if( orientation < Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
+  if( orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE )
   {
     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation );
     return;
@@ -272,10 +297,10 @@ void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientatio
   mWindowBase->SetPreferredAngle( mPreferredAngle );
 }
 
-Dali::Window::WindowOrientation Window::GetPreferredOrientation()
+WindowOrientation Window::GetPreferredOrientation()
 {
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle );
-  Dali::Window::WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
+  WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
   return preferredOrientation;
 }
 
@@ -290,34 +315,34 @@ void Window::SetAvailableAnlges( const std::vector< int >& angles )
   mWindowBase->SetAvailableAnlges( angles );
 }
 
-int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
+int Window::ConvertToAngle( WindowOrientation orientation )
 {
   int convertAngle = static_cast< int >( orientation );
   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
   {
     switch( orientation )
     {
-      case Dali::Window::LANDSCAPE:
+      case WindowOrientation::LANDSCAPE:
       {
         convertAngle = 0;
         break;
       }
-      case Dali::Window::PORTRAIT:
+      case WindowOrientation::PORTRAIT:
       {
         convertAngle = 90;
         break;
       }
-      case Dali::Window::LANDSCAPE_INVERSE:
+      case WindowOrientation::LANDSCAPE_INVERSE:
       {
         convertAngle = 180;
         break;
       }
-      case Dali::Window::PORTRAIT_INVERSE:
+      case WindowOrientation::PORTRAIT_INVERSE:
       {
         convertAngle = 270;
         break;
       }
-      case Dali::Window::NO_ORIENTATION_PREFERENCE:
+      case WindowOrientation::NO_ORIENTATION_PREFERENCE:
       {
         convertAngle = -1;
         break;
@@ -327,36 +352,36 @@ int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
   return convertAngle;
 }
 
-Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle ) const
+WindowOrientation Window::ConvertToOrientation( int angle ) const
 {
-  Dali::Window::WindowOrientation orientation = static_cast< Dali::Window::WindowOrientation >( angle );
+  WindowOrientation orientation = static_cast< WindowOrientation >( angle );
   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
   {
     switch( angle )
     {
       case 0:
       {
-        orientation = Dali::Window::LANDSCAPE;
+        orientation = WindowOrientation::LANDSCAPE;
         break;
       }
       case 90:
       {
-        orientation = Dali::Window::PORTRAIT;
+        orientation = WindowOrientation::PORTRAIT;
         break;
       }
       case 180:
       {
-        orientation = Dali::Window::LANDSCAPE_INVERSE;
+        orientation = WindowOrientation::LANDSCAPE_INVERSE;
         break;
       }
       case 270:
       {
-        orientation = Dali::Window::PORTRAIT_INVERSE;
+        orientation = WindowOrientation::PORTRAIT_INVERSE;
         break;
       }
       case -1:
       {
-        orientation = Dali::Window::NO_ORIENTATION_PREFERENCE;
+        orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
         break;
       }
     }
@@ -364,9 +389,9 @@ Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle ) const
   return orientation;
 }
 
-bool Window::IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const
+bool Window::IsOrientationAvailable( WindowOrientation orientation ) const
 {
-  if( orientation <= Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
+  if( orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE )
   {
     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation );
     return false;
@@ -406,6 +431,8 @@ void Window::Show()
     mVisibilityChangedSignal.Emit( handle, true );
   }
 
+  mSurface->SetFullSwapNextFrame();
+
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
 }
 
@@ -475,7 +502,7 @@ void Window::SetInputRegion( const Rect< int >& inputRegion )
   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
 }
 
-void Window::SetType( Dali::Window::Type type )
+void Window::SetType( WindowType type )
 {
   if( type != mType )
   {
@@ -485,14 +512,14 @@ void Window::SetType( Dali::Window::Type type )
   }
 }
 
-Dali::Window::Type Window::GetType() const
+WindowType Window::GetType() const
 {
   return mType;
 }
 
-bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
+bool Window::SetNotificationLevel( WindowNotificationLevel level )
 {
-  if( mType != Dali::Window::NOTIFICATION )
+  if( mType != WindowType::NOTIFICATION )
   {
     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
     return false;
@@ -501,12 +528,12 @@ bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
   return mWindowBase->SetNotificationLevel( level );
 }
 
-Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
+WindowNotificationLevel Window::GetNotificationLevel() const
 {
-  if( mType != Dali::Window::NOTIFICATION )
+  if( mType != WindowType::NOTIFICATION )
   {
     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
-    return Dali::Window::NotificationLevel::NONE;
+    return WindowNotificationLevel::NONE;
   }
 
   return mWindowBase->GetNotificationLevel();
@@ -526,12 +553,12 @@ bool Window::IsOpaqueState() const
   return mOpaqueState;
 }
 
-bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
+bool Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
 {
   return mWindowBase->SetScreenOffMode( screenOffMode );
 }
 
-Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
+WindowScreenOffMode Window::GetScreenOffMode() const
 {
   return mWindowBase->GetScreenOffMode();
 }
@@ -578,11 +605,12 @@ void Window::SetSize( Dali::Window::WindowSize size )
     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
 
     Dali::Window handle( this );
-    mResizedSignal.Emit( newSize );
     mResizeSignal.Emit( handle, newSize );
 
     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 Dali::Window::WindowSize Window::GetSize() const
@@ -603,6 +631,8 @@ void Window::SetPosition( Dali::Window::WindowPosition position )
   PositionSize oldRect = mSurface->GetPositionSize();
 
   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 Dali::Window::WindowPosition Window::GetPosition() const
@@ -637,10 +667,11 @@ void Window::SetPositionSize( PositionSize positionSize )
 
     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
     Dali::Window handle( this );
-    mResizedSignal.Emit( newSize );
     mResizeSignal.Emit( handle, newSize );
     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 Dali::Layer Window::GetRootLayer() const
@@ -705,13 +736,28 @@ void Window::OnIconifyChanged( bool iconified )
 
     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 void Window::OnFocusChanged( bool focusIn )
 {
   Dali::Window handle( this );
-  mFocusChangedSignal.Emit( focusIn );
   mFocusChangeSignal.Emit( handle, focusIn );
+
+  mSurface->SetFullSwapNextFrame();
+
+  if (auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
+  {
+    if (focusIn)
+    {
+      b->ApplicationShown();
+    }
+    else
+    {
+      b->ApplicationHidden();
+    }
+  }
 }
 
 void Window::OnOutputTransformed()
@@ -727,12 +773,23 @@ void Window::OnDeleteRequest()
   mDeleteRequestSignal.Emit();
 }
 
-void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
+void Window::OnTransitionEffectEvent( WindowEffectState state, WindowEffectType type )
 {
   Dali::Window handle( this );
   mTransitionEffectEventSignal.Emit( handle, state, type );
 }
 
+void Window::OnKeyboardRepeatSettingsChanged()
+{
+  Dali::Window handle( this );
+  mKeyboardRepeatSettingsChangedSignal.Emit();
+}
+
+void Window::OnWindowRedrawRequest()
+{
+  mAdaptor->RenderOnce();
+}
+
 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
 {
   FeedTouchPoint( point, timeStamp );
@@ -766,7 +823,6 @@ void Window::OnRotation( const RotationEvent& rotation )
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight );
   // Emit signal
   Dali::Window handle( this );
-  mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
 
   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
@@ -786,6 +842,8 @@ void Window::OnResume()
   {
     mEventHandler->Resume();
   }
+
+  mSurface->SetFullSwapNextFrame();
 }
 
 void Window::RecalculateTouchPosition( Integration::Point& point )
@@ -866,13 +924,13 @@ Dali::Window Window::GetParent()
   return mParentWindow;
 }
 
-Dali::Window::WindowOrientation Window::GetCurrentOrientation() const
+WindowOrientation Window::GetCurrentOrientation() const
 {
   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle );
   return ConvertToOrientation( mRotationAngle );
 }
 
-void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations )
+void Window::SetAvailableOrientations( const Dali::Vector<WindowOrientation>& orientations )
 {
   Dali::Vector<float>::SizeType count = orientations.Count();
   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
@@ -904,6 +962,11 @@ void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOr
   SetAvailableAnlges( mAvailableAngles );
 }
 
+int32_t Window::GetNativeId() const
+{
+  return mWindowBase->GetNativeWindowId();
+}
+
 } // Adaptor
 
 } // Internal