Add to get the status whether window is rotating or not
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-render-surface.cpp
index b1ba7a1..c6cee4a 100644 (file)
@@ -146,7 +146,8 @@ WindowRenderSurface::WindowRenderSurface(Dali::PositionSize positionSize, Any su
   mScreenRotationFinished(true),
   mResizeFinished(true),
   mDefaultScreenRotationAvailable(false),
-  mIsImeWindowSurface(false)
+  mIsImeWindowSurface(false),
+  mNeedWindowRotationAcknowledgement(false)
 {
   DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n");
   Initialize(surface);
@@ -210,24 +211,23 @@ void WindowRenderSurface::SetTransparency(bool transparent)
   mWindowBase->SetTransparency(transparent);
 }
 
-void WindowRenderSurface::RequestRotation(int angle, int width, int height)
+void WindowRenderSurface::RequestRotation(int angle, PositionSize positionSize)
 {
   if(!mPostRenderTrigger)
   {
     mPostRenderTrigger = std::unique_ptr<TriggerEventInterface>(TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &WindowRenderSurface::ProcessPostRender),
-                                                                                                        TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
+                                                                                                      TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
   }
 
-  mPositionSize.width  = width;
-  mPositionSize.height = height;
+  mPositionSize = positionSize;
 
   mWindowRotationAngle    = angle;
   mWindowRotationFinished = false;
-  mResizeFinished = false;
+  mResizeFinished         = false;
 
   mWindowBase->SetWindowRotationAngle(mWindowRotationAngle);
 
-  DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: angle = %d screen rotation = %d\n", mWindowRotationAngle, mScreenRotationAngle);
+  DALI_LOG_RELEASE_INFO("angle = %d screen rotation = %d, flag = %d\n", mWindowRotationAngle, mScreenRotationAngle, mWindowRotationFinished);
 }
 
 WindowBase* WindowRenderSurface::GetWindowBase()
@@ -272,15 +272,15 @@ int WindowRenderSurface::GetOrientation() const
 
 void WindowRenderSurface::InitializeGraphics()
 {
-  mGraphics = &mAdaptor->GetGraphicsInterface();
+  if(mEGLContext == NULL)
+  {
+    mGraphics = &mAdaptor->GetGraphicsInterface();
 
-  DALI_ASSERT_ALWAYS(mGraphics && "Graphics interface is not created");
+    DALI_ASSERT_ALWAYS(mGraphics && "Graphics interface is not created");
 
-  auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
-  mEGL             = &eglGraphics->GetEglInterface();
+    auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
+    mEGL             = &eglGraphics->GetEglInterface();
 
-  if(mEGLContext == NULL)
-  {
     // Create the OpenGL context for this window
     Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>(*mEGL);
     eglImpl.ChooseConfig(true, mColorDepth);
@@ -315,8 +315,9 @@ void WindowRenderSurface::CreateSurface()
   Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
   mEGLSurface                                   = eglImpl.CreateSurfaceWindow(window, mColorDepth);
 
-  DALI_LOG_RELEASE_INFO("WindowRenderSurface::CreateSurface: WinId (%d), w = %d h = %d angle = %d screen rotation = %d\n",
+  DALI_LOG_RELEASE_INFO("WindowRenderSurface::CreateSurface: WinId (%d), EGLSurface (%p), w = %d h = %d angle = %d screen rotation = %d\n",
                         mWindowBase->GetNativeWindowId(),
+                        mEGLSurface,
                         mPositionSize.width,
                         mPositionSize.height,
                         mWindowRotationAngle,
@@ -376,6 +377,41 @@ bool WindowRenderSurface::ReplaceGraphicsSurface()
   return eglImpl.ReplaceSurfaceWindow(window, mEGLSurface, mEGLContext);
 }
 
+void WindowRenderSurface::UpdatePositionSize(Dali::PositionSize positionSize)
+{
+  bool needToMove   = false;
+  bool needToResize = false;
+
+  // Check moving
+  if((fabs(positionSize.x - mPositionSize.x) >= MINIMUM_DIMENSION_CHANGE) ||
+     (fabs(positionSize.y - mPositionSize.y) >= MINIMUM_DIMENSION_CHANGE))
+  {
+    needToMove = true;
+  }
+
+  // Check resizing
+  if((fabs(positionSize.width - mPositionSize.width) >= MINIMUM_DIMENSION_CHANGE) ||
+     (fabs(positionSize.height - mPositionSize.height) >= MINIMUM_DIMENSION_CHANGE))
+  {
+    needToResize = true;
+  }
+
+  if(needToResize)
+  {
+    mResizeFinished = false;
+    mPositionSize   = positionSize;
+  }
+  else
+  {
+    if(needToMove)
+    {
+      mPositionSize = positionSize;
+    }
+  }
+
+  DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::MoveResize: %d, %d, %d, %d\n", mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height);
+}
+
 void WindowRenderSurface::MoveResize(Dali::PositionSize positionSize)
 {
   bool needToMove   = false;
@@ -428,6 +464,8 @@ void WindowRenderSurface::StartRender()
 
 bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
 {
+  InitializeGraphics();
+
   mDamagedRects.assign(damagedRects.begin(), damagedRects.end());
 
   Dali::Integration::Scene::FrameCallbackContainer callbacks;
@@ -543,7 +581,7 @@ bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vector<Rect
       mWindowBase->ResizeEglWindow(positionSize);
       mResizeFinished = true;
 
-      DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: Set resize, x: %d, y: %d, w: %d, h:%d\n", positionSize.x, positionSize.y, positionSize.width, positionSize.height);
+      DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: Set resize, totalAngle: %d, x: %d, y: %d, w: %d, h:%d\n", totalAngle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
     }
 
     SetFullSwapNextFrame();
@@ -552,9 +590,19 @@ bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vector<Rect
 
   SetBufferDamagedRects(mDamagedRects, clippingRect);
 
-  if(clippingRect.IsEmpty())
+  if(scene)
   {
-    mDamagedRects.clear();
+    Rect<int> surfaceRect = scene.GetCurrentSurfaceRect();
+    if(clippingRect == surfaceRect)
+    {
+      mDamagedRects.assign(1, surfaceRect);
+    }
+    else if(mDamagedRects.empty() && !clippingRect.IsEmpty())
+    {
+      // We will render clippingRect area but mDamagedRects is empty.
+      // So make mDamagedRects same with clippingRect to swap buffers.
+      mDamagedRects.assign(1, clippingRect);
+    }
   }
 
   // This is now done when the render pass for the render surface begins
@@ -572,7 +620,31 @@ void WindowRenderSurface::PostRender()
     GlImplementation& mGLES = eglGraphics->GetGlesInterface();
     mGLES.PostRender();
 
-    if((mIsResizing && !mWindowRotationFinished) || mIsImeWindowSurface)
+    bool needWindowRotationCompleted = false;
+
+    if(!mWindowRotationFinished)
+    {
+      if(mNeedWindowRotationAcknowledgement)
+      {
+        Dali::Integration::Scene scene = mScene.GetHandle();
+        if(scene)
+        {
+          if(scene.IsRotationCompletedAcknowledgementSet())
+          {
+            needWindowRotationCompleted = true;
+          }
+        }
+      }
+      else
+      {
+        if(mIsResizing)
+        {
+          needWindowRotationCompleted = true;
+        }
+      }
+    }
+
+    if(needWindowRotationCompleted || mIsImeWindowSurface)
     {
       if(mThreadSynchronization)
       {
@@ -650,6 +722,11 @@ void WindowRenderSurface::InitializeImeSurface()
   }
 }
 
+void WindowRenderSurface::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
+{
+  mNeedWindowRotationAcknowledgement = needAcknowledgement;
+}
+
 void WindowRenderSurface::OutputTransformed()
 {
   int screenRotationAngle = mWindowBase->GetScreenRotationAngle();
@@ -670,13 +747,18 @@ void WindowRenderSurface::OutputTransformed()
   }
 }
 
+bool WindowRenderSurface::IsWindowRotating() const
+{
+  return !(mWindowRotationFinished);
+}
+
 void WindowRenderSurface::ProcessPostRender()
 {
   if(!mWindowRotationFinished)
   {
     mWindowBase->WindowRotationCompleted(mWindowRotationAngle, mPositionSize.width, mPositionSize.height);
-    DALI_LOG_RELEASE_INFO("WindowRenderSurface::ProcessPostRender: Rotation Done\n");
     mWindowRotationFinished = true;
+    DALI_LOG_RELEASE_INFO("WindowRenderSurface::ProcessPostRender: Rotation Done, flag = %d\n", mWindowRotationFinished);
   }
 
   if(mIsImeWindowSurface)
@@ -747,28 +829,32 @@ void WindowRenderSurface::SetBufferDamagedRects(const std::vector<Rect<int>>& da
   auto eglGraphics = static_cast<EglGraphics*>(mGraphics);
   if(eglGraphics)
   {
-    Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
-    if(!eglImpl.IsPartialUpdateRequired())
+    // If scene is not exist, just use stored mPositionSize.
+    Rect<int> surfaceRect(0, 0, mPositionSize.width, mPositionSize.height);
+
+    Dali::Integration::Scene scene = mScene.GetHandle();
+    if(scene)
     {
-      return;
+      surfaceRect = scene.GetCurrentSurfaceRect();
     }
 
-    Rect<int> surfaceRect(0, 0, mPositionSize.width, mPositionSize.height);
-
-    if(mFullSwapNextFrame)
+    Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
+    if(!eglImpl.IsPartialUpdateRequired() || mFullSwapNextFrame)
     {
       InsertRects(mBufferDamagedRects, std::vector<Rect<int>>(1, surfaceRect));
-      clippingRect = Rect<int>();
+      clippingRect = surfaceRect;
       return;
     }
 
+    mGraphics->ActivateSurfaceContext(this);
+
     EGLint bufferAge = eglImpl.GetBufferAge(mEGLSurface);
 
     // Buffer age 0 means the back buffer in invalid and requires full swap
-    if(!damagedRects.size() || bufferAge == 0)
+    if(bufferAge == 0)
     {
       InsertRects(mBufferDamagedRects, std::vector<Rect<int>>(1, surfaceRect));
-      clippingRect = Rect<int>();
+      clippingRect = surfaceRect;
       return;
     }
 
@@ -786,22 +872,24 @@ void WindowRenderSurface::SetBufferDamagedRects(const std::vector<Rect<int>>& da
     if(!clippingRect.Intersect(surfaceRect) || clippingRect.Area() > surfaceRect.Area() * FULL_UPDATE_RATIO)
     {
       // clipping area too big or doesn't intersect surface rect
-      clippingRect = Rect<int>();
+      clippingRect = surfaceRect;
       return;
     }
 
-    std::vector<Rect<int>>   damagedRegion;
-    Dali::Integration::Scene scene = mScene.GetHandle();
-    if(scene)
-    {
-      damagedRegion.push_back(RecalculateRect[std::min(scene.GetCurrentSurfaceOrientation() / 90, 3)](clippingRect, scene.GetCurrentSurfaceRect()));
-    }
-    else
+    if(!clippingRect.IsEmpty())
     {
-      damagedRegion.push_back(clippingRect);
-    }
+      std::vector<Rect<int>> damagedRegion;
+      if(scene)
+      {
+        damagedRegion.push_back(RecalculateRect[std::min(scene.GetCurrentSurfaceOrientation() / 90, 3)](clippingRect, scene.GetCurrentSurfaceRect()));
+      }
+      else
+      {
+        damagedRegion.push_back(clippingRect);
+      }
 
-    eglImpl.SetDamageRegion(mEGLSurface, damagedRegion);
+      eglImpl.SetDamageRegion(mEGLSurface, damagedRegion);
+    }
   }
 }
 
@@ -822,7 +910,7 @@ void WindowRenderSurface::SwapBuffers(const std::vector<Rect<int>>& damagedRects
 
     Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
-    if(!eglImpl.IsPartialUpdateRequired() || mFullSwapNextFrame || !damagedRects.size() || (damagedRects[0].Area() > surfaceRect.Area() * FULL_UPDATE_RATIO))
+    if(!eglImpl.IsPartialUpdateRequired() || mFullSwapNextFrame || (damagedRects.size() != 0 && damagedRects[0].Area() > surfaceRect.Area() * FULL_UPDATE_RATIO))
     {
       mFullSwapNextFrame = false;
       eglImpl.SwapBuffers(mEGLSurface);
@@ -875,6 +963,8 @@ void WindowRenderSurface::SwapBuffers(const std::vector<Rect<int>>& damagedRects
 
     if(!mergedRects.size() || (mergedRects[0].Area() > surfaceRect.Area() * FULL_UPDATE_RATIO))
     {
+      // In normal cases, WindowRenderSurface::SwapBuffers() will not be called if mergedRects.size() is 0.
+      // For exceptional cases, swap full area.
       eglImpl.SwapBuffers(mEGLSurface);
     }
     else