(Partial update) Change calculation of damaged rects
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-render-surface.cpp
index 4a7a8e7..4a44951 100644 (file)
@@ -127,7 +127,7 @@ WindowRenderSurface::WindowRenderSurface(Dali::PositionSize positionSize, Any su
   mWindowBase(),
   mThreadSynchronization(nullptr),
   mRenderNotification(nullptr),
-  mRotationTrigger(nullptr),
+  mPostRenderTrigger(),
   mFrameRenderedTrigger(),
   mGraphics(nullptr),
   mEGLSurface(nullptr),
@@ -145,7 +145,8 @@ WindowRenderSurface::WindowRenderSurface(Dali::PositionSize positionSize, Any su
   mWindowRotationFinished(true),
   mScreenRotationFinished(true),
   mResizeFinished(true),
-  mDefaultScreenRotationAvailable(false)
+  mDefaultScreenRotationAvailable(false),
+  mIsImeWindowSurface(false)
 {
   DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n");
   Initialize(surface);
@@ -153,10 +154,6 @@ WindowRenderSurface::WindowRenderSurface(Dali::PositionSize positionSize, Any su
 
 WindowRenderSurface::~WindowRenderSurface()
 {
-  if(mRotationTrigger)
-  {
-    delete mRotationTrigger;
-  }
 }
 
 void WindowRenderSurface::Initialize(Any surface)
@@ -215,9 +212,10 @@ void WindowRenderSurface::SetTransparency(bool transparent)
 
 void WindowRenderSurface::RequestRotation(int angle, int width, int height)
 {
-  if(!mRotationTrigger)
+  if(!mPostRenderTrigger)
   {
-    mRotationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &WindowRenderSurface::ProcessRotationRequest), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
+    mPostRenderTrigger = std::unique_ptr<TriggerEventInterface>(TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &WindowRenderSurface::ProcessPostRender),
+                                                                                                        TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
   }
 
   mPositionSize.width  = width;
@@ -225,6 +223,7 @@ void WindowRenderSurface::RequestRotation(int angle, int width, int height)
 
   mWindowRotationAngle    = angle;
   mWindowRotationFinished = false;
+  mResizeFinished         = false;
 
   mWindowBase->SetWindowRotationAngle(mWindowRotationAngle);
 
@@ -273,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);
@@ -429,6 +428,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;
@@ -544,7 +545,7 @@ bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vector<Rect
       mWindowBase->ResizeEglWindow(positionSize);
       mResizeFinished = true;
 
-      DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: Set resize\n");
+      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);
     }
 
     SetFullSwapNextFrame();
@@ -553,9 +554,16 @@ bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vector<Rect
 
   SetBufferDamagedRects(mDamagedRects, clippingRect);
 
-  if(clippingRect.IsEmpty())
+  Rect<int> surfaceRect(0, 0, mPositionSize.width, mPositionSize.height);
+  if(clippingRect == surfaceRect)
+  {
+    mDamagedRects.assign(1, surfaceRect);
+  }
+  else if(mDamagedRects.empty() && !clippingRect.IsEmpty())
   {
-    mDamagedRects.clear();
+    // 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
@@ -573,25 +581,23 @@ void WindowRenderSurface::PostRender()
     GlImplementation& mGLES = eglGraphics->GetGlesInterface();
     mGLES.PostRender();
 
-    if(mIsResizing)
+    if((mIsResizing && !mWindowRotationFinished) || mIsImeWindowSurface)
     {
-      if(!mWindowRotationFinished)
+      if(mThreadSynchronization)
       {
-        if(mThreadSynchronization)
-        {
-          // Enable PostRender flag
-          mThreadSynchronization->PostRenderStarted();
-        }
-
-        DALI_LOG_RELEASE_INFO("WindowRenderSurface::PostRender: Trigger rotation event\n");
+        // Enable PostRender flag
+        mThreadSynchronization->PostRenderStarted();
+      }
 
-        mRotationTrigger->Trigger();
+      if(!mWindowRotationFinished || mIsImeWindowSurface)
+      {
+        mPostRenderTrigger->Trigger();
+      }
 
-        if(mThreadSynchronization)
-        {
-          // Wait until the event-thread complete the rotation event processing
-          mThreadSynchronization->PostRenderWaitForCompletion();
-        }
+      if(mThreadSynchronization)
+      {
+        // Wait until the event-thread complete the rotation event processing
+        mThreadSynchronization->PostRenderWaitForCompletion();
       }
     }
 
@@ -643,6 +649,16 @@ Integration::StencilBufferAvailable WindowRenderSurface::GetStencilBufferRequire
   return mGraphics ? mGraphics->GetStencilBufferRequired() : Integration::StencilBufferAvailable::FALSE;
 }
 
+void WindowRenderSurface::InitializeImeSurface()
+{
+  mIsImeWindowSurface = true;
+  if(!mPostRenderTrigger)
+  {
+    mPostRenderTrigger = std::unique_ptr<TriggerEventInterface>(TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &WindowRenderSurface::ProcessPostRender),
+                                                                                                        TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
+  }
+}
+
 void WindowRenderSurface::OutputTransformed()
 {
   int screenRotationAngle = mWindowBase->GetScreenRotationAngle();
@@ -663,13 +679,19 @@ void WindowRenderSurface::OutputTransformed()
   }
 }
 
-void WindowRenderSurface::ProcessRotationRequest()
+void WindowRenderSurface::ProcessPostRender()
 {
-  mWindowRotationFinished = true;
-
-  mWindowBase->WindowRotationCompleted(mWindowRotationAngle, mPositionSize.width, mPositionSize.height);
+  if(!mWindowRotationFinished)
+  {
+    mWindowBase->WindowRotationCompleted(mWindowRotationAngle, mPositionSize.width, mPositionSize.height);
+    DALI_LOG_RELEASE_INFO("WindowRenderSurface::ProcessPostRender: Rotation Done\n");
+    mWindowRotationFinished = true;
+  }
 
-  DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::ProcessRotationRequest: Rotation Done\n");
+  if(mIsImeWindowSurface)
+  {
+    mWindowBase->ImeWindowReadyToRender();
+  }
 
   if(mThreadSynchronization)
   {
@@ -734,28 +756,25 @@ 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())
-    {
-      return;
-    }
-
     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;
     }
 
@@ -773,22 +792,25 @@ 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;
+      Dali::Integration::Scene scene = mScene.GetHandle();
+      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);
+    }
   }
 }
 
@@ -809,7 +831,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);
@@ -862,6 +884,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