[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-render-surface.cpp
index 509c174..2ec42bf 100644 (file)
@@ -67,6 +67,7 @@ WindowRenderSurface::WindowRenderSurface( Dali::PositionSize positionSize, Any s
   mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
   mOutputTransformedSignal(),
   mFrameCallbackInfoContainer(),
+  mMutex(),
   mRotationAngle( 0 ),
   mScreenRotationAngle( 0 ),
   mOwnSurface( false ),
@@ -106,13 +107,6 @@ void WindowRenderSurface::Initialize( Any surface )
 
   // Connect signals
   mWindowBase->OutputTransformedSignal().Connect( this, &WindowRenderSurface::OutputTransformed );
-
-  // Check screen rotation
-  mScreenRotationAngle = mWindowBase->GetScreenRotationAngle();
-  if( mScreenRotationAngle != 0 )
-  {
-    mScreenRotationFinished = false;
-  }
 }
 
 Any WindowRenderSurface::GetNativeWindow()
@@ -142,12 +136,6 @@ void WindowRenderSurface::SetTransparency( bool transparent )
 
 void WindowRenderSurface::RequestRotation( int angle, int width, int height )
 {
-  if( !mRotationSupported )
-  {
-    DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: Rotation is not supported!\n" );
-    return;
-  }
-
   if( !mRotationTrigger )
   {
     mRotationTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessRotationRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
@@ -199,6 +187,11 @@ void WindowRenderSurface::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpi
   dpiVertical = mDpiVertical;
 }
 
+int WindowRenderSurface::GetOrientation() const
+{
+  return mWindowBase->GetOrientation();
+}
+
 void WindowRenderSurface::InitializeGraphics()
 {
   mGraphics = &mAdaptor->GetGraphicsInterface();
@@ -224,20 +217,8 @@ void WindowRenderSurface::CreateSurface()
 {
   DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );
 
-  int width, height;
-  if( mScreenRotationAngle == 0 || mScreenRotationAngle == 180 )
-  {
-    width = mPositionSize.width;
-    height = mPositionSize.height;
-  }
-  else
-  {
-    width = mPositionSize.height;
-    height = mPositionSize.width;
-  }
-
   // Create the EGL window
-  EGLNativeWindowType window = mWindowBase->CreateEglWindow( width, height );
+  EGLNativeWindowType window = mWindowBase->CreateEglWindow( mPositionSize.width, mPositionSize.height );
 
   auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
 
@@ -361,22 +342,21 @@ bool WindowRenderSurface::PreRender( bool resizingSurface, const std::vector<Rec
   Dali::Integration::Scene scene = mScene.GetHandle();
   if( scene )
   {
+    bool needFrameRenderedTrigger = false;
+
     scene.GetFrameRenderedCallback( callbacks );
     if( !callbacks.empty() )
     {
       int frameRenderedSync = mWindowBase->CreateFrameRenderedSyncFence();
       if( frameRenderedSync != -1 )
       {
+        Dali::Mutex::ScopedLock lock( mMutex );
+
         DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: CreateFrameRenderedSyncFence [%d]\n", frameRenderedSync );
 
         mFrameCallbackInfoContainer.push_back( std::unique_ptr< FrameCallbackInfo >( new FrameCallbackInfo( callbacks, frameRenderedSync ) ) );
 
-        if( !mFrameRenderedTrigger )
-        {
-          mFrameRenderedTrigger = std::unique_ptr< TriggerEventInterface >( TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessFrameCallback ),
-                                                                                                                     TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ) );
-        }
-        mFrameRenderedTrigger->Trigger();
+        needFrameRenderedTrigger = true;
       }
       else
       {
@@ -393,16 +373,13 @@ bool WindowRenderSurface::PreRender( bool resizingSurface, const std::vector<Rec
       int framePresentedSync = mWindowBase->CreateFramePresentedSyncFence();
       if( framePresentedSync != -1 )
       {
+        Dali::Mutex::ScopedLock lock( mMutex );
+
         DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: CreateFramePresentedSyncFence [%d]\n", framePresentedSync );
 
         mFrameCallbackInfoContainer.push_back( std::unique_ptr< FrameCallbackInfo >( new FrameCallbackInfo( callbacks, framePresentedSync ) ) );
 
-        if( !mFrameRenderedTrigger )
-        {
-          mFrameRenderedTrigger = std::unique_ptr< TriggerEventInterface >( TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessFrameCallback ),
-                                                                                                                     TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ) );
-        }
-        mFrameRenderedTrigger->Trigger();
+        needFrameRenderedTrigger = true;
       }
       else
       {
@@ -412,6 +389,16 @@ bool WindowRenderSurface::PreRender( bool resizingSurface, const std::vector<Rec
       // Clear callbacks
       callbacks.clear();
     }
+
+    if( needFrameRenderedTrigger )
+    {
+      if( !mFrameRenderedTrigger )
+      {
+        mFrameRenderedTrigger = std::unique_ptr< TriggerEventInterface >( TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessFrameCallback ),
+                                                                                                                   TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ) );
+      }
+      mFrameRenderedTrigger->Trigger();
+    }
   }
 
   MakeContextCurrent();
@@ -420,11 +407,11 @@ bool WindowRenderSurface::PreRender( bool resizingSurface, const std::vector<Rec
 
   if( resizingSurface )
   {
+    int totalAngle = (mRotationAngle + mScreenRotationAngle) % 360;
+
     // Window rotate or screen rotate
     if( !mRotationFinished || !mScreenRotationFinished )
     {
-      int totalAngle = (mRotationAngle + mScreenRotationAngle) % 360;
-
       mWindowBase->SetEglWindowRotation( totalAngle );
       mWindowBase->SetEglWindowBufferTransform( totalAngle );
 
@@ -441,9 +428,22 @@ bool WindowRenderSurface::PreRender( bool resizingSurface, const std::vector<Rec
     }
 
     // Resize case
-    if( !mResizeFinished )
+    if ( !mResizeFinished )
     {
-      mWindowBase->ResizeEglWindow( mPositionSize );
+      Dali::PositionSize positionSize;
+      positionSize.x = mPositionSize.x;
+      positionSize.y = mPositionSize.y;
+      if( totalAngle == 0 || totalAngle == 180 )
+      {
+        positionSize.width = mPositionSize.width;
+        positionSize.height = mPositionSize.height;
+      }
+      else
+      {
+        positionSize.width = mPositionSize.height;
+        positionSize.height = mPositionSize.width;
+      }
+      mWindowBase->ResizeEglWindow( positionSize );
       mResizeFinished = true;
 
       DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: Set resize\n" );
@@ -561,14 +561,15 @@ void WindowRenderSurface::OutputTransformed()
   {
     mScreenRotationAngle = screenRotationAngle;
     mScreenRotationFinished = false;
+    mResizeFinished = false;
 
     mOutputTransformedSignal.Emit();
 
-    DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OutputTransformed: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle );
+    DALI_LOG_RELEASE_INFO( "WindowRenderSurface::OutputTransformed: window = %d screen = %d\n", mRotationAngle, mScreenRotationAngle );
   }
   else
   {
-    DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OutputTransformed: Ignore output transform [%d]\n", mScreenRotationAngle );
+    DALI_LOG_RELEASE_INFO( "WindowRenderSurface::OutputTransformed: Ignore output transform [%d]\n", mScreenRotationAngle );
   }
 }
 
@@ -588,6 +589,8 @@ void WindowRenderSurface::ProcessRotationRequest()
 
 void WindowRenderSurface::ProcessFrameCallback()
 {
+  Dali::Mutex::ScopedLock lock( mMutex );
+
   for( auto&& iter : mFrameCallbackInfoContainer )
   {
     if( !iter->fileDescriptorMonitor )
@@ -611,19 +614,29 @@ void WindowRenderSurface::OnFileDescriptorEventDispatched( FileDescriptorMonitor
 
   DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OnFileDescriptorEventDispatched: Frame rendered [%d]\n", fileDescriptor );
 
-  auto frameCallbackInfo = std::find_if( mFrameCallbackInfoContainer.begin(), mFrameCallbackInfoContainer.end(),
-                                    [fileDescriptor]( std::unique_ptr< FrameCallbackInfo >& callbackInfo )
-                                    {
-                                      return callbackInfo->fileDescriptor == fileDescriptor;
-                                    } );
-  if( frameCallbackInfo != mFrameCallbackInfoContainer.end() )
+  std::unique_ptr< FrameCallbackInfo > callbackInfo;
+  {
+    Dali::Mutex::ScopedLock lock( mMutex );
+    auto frameCallbackInfo = std::find_if( mFrameCallbackInfoContainer.begin(), mFrameCallbackInfoContainer.end(),
+                                      [fileDescriptor]( std::unique_ptr< FrameCallbackInfo >& callbackInfo )
+                                      {
+                                        return callbackInfo->fileDescriptor == fileDescriptor;
+                                      } );
+    if( frameCallbackInfo != mFrameCallbackInfoContainer.end() )
+    {
+      callbackInfo = std::move( *frameCallbackInfo );
+
+      mFrameCallbackInfoContainer.erase( frameCallbackInfo );
+    }
+  }
+
+  // Call the connected callback
+  if( callbackInfo )
   {
-    // Call the connected callback
-    for( auto&& iter : ( *frameCallbackInfo )->callbacks )
+    for( auto&& iter : ( callbackInfo )->callbacks )
     {
       CallbackBase::Execute( *( iter.first ), iter.second );
     }
-    mFrameCallbackInfoContainer.erase( frameCallbackInfo );
   }
 }