[Tizen] Do not call PreRender if rendering will be skipped
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / combined-update-render-controller.cpp
index 2076d17..c8e0d1b 100644 (file)
@@ -115,7 +115,7 @@ CombinedUpdateRenderController::CombinedUpdateRenderController(AdaptorInternalSe
   mNewSurface(NULL),
   mDeletedSurface(nullptr),
   mPostRendering(FALSE),
-  mSurfaceResized(FALSE),
+  mSurfaceResized(0),
   mForceClear(FALSE),
   mUploadWithoutRendering(FALSE),
   mFirstFrameAfterResume(FALSE)
@@ -366,8 +366,9 @@ void CombinedUpdateRenderController::ResizeSurface()
 
   {
     ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
-    mPostRendering  = FALSE; // Clear the post-rendering flag as Update/Render thread will resize the surface now
-    mSurfaceResized = TRUE;
+    mPostRendering = FALSE; // Clear the post-rendering flag as Update/Render thread will resize the surface now
+    // Surface is resized and the surface resized count is increased.
+    mSurfaceResized++;
     mUpdateRenderThreadWaitCondition.Notify(lock);
   }
 }
@@ -573,8 +574,7 @@ void CombinedUpdateRenderController::UpdateRenderThread()
       // Then create a new pixmap/window and new surface
       // If the new surface has a different display connection, then the context will be lost
       mAdaptorInterfaces.GetDisplayConnectionInterface().Initialize();
-      newSurface->InitializeGraphics();
-      newSurface->MakeContextCurrent();
+      graphics.ActivateSurfaceContext(newSurface);
       // TODO: ReplaceGraphicsSurface doesn't work, InitializeGraphics()
       // already creates new surface window, the surface and the context.
       // We probably don't need ReplaceGraphicsSurface at all.
@@ -633,19 +633,6 @@ void CombinedUpdateRenderController::UpdateRenderThread()
       LOG_UPDATE_RENDER("Notification Triggered");
     }
 
-    // Check resize
-    bool surfaceResized         = false;
-    bool shouldSurfaceBeResized = ShouldSurfaceBeResized();
-    if(DALI_UNLIKELY(shouldSurfaceBeResized))
-    {
-      if(updateStatus.SurfaceRectChanged())
-      {
-        LOG_UPDATE_RENDER_TRACE_FMT("Resizing Surface");
-        SurfaceResized();
-        surfaceResized = true;
-      }
-    }
-
     // Optional logging of update/render status
     mUpdateStatusLogger.Log(keepUpdatingStatus);
 
@@ -688,6 +675,8 @@ void CombinedUpdateRenderController::UpdateRenderThread()
       WindowContainer windows;
       mAdaptorInterfaces.GetWindowContainerInterface(windows);
 
+      bool sceneSurfaceResized;
+
       for(auto&& window : windows)
       {
         Dali::Integration::Scene      scene         = window->GetScene();
@@ -697,13 +686,15 @@ void CombinedUpdateRenderController::UpdateRenderThread()
         {
           Integration::RenderStatus windowRenderStatus;
 
-          windowSurface->InitializeGraphics();
+          // Get Surface Resized flag
+          sceneSurfaceResized = scene.IsSurfaceRectChanged();
+          windowSurface->SetIsResizing(sceneSurfaceResized);
 
           // clear previous frame damaged render items rects, buffer history is tracked on surface level
           mDamagedRects.clear();
 
           // Collect damage rects
-          mCore.PreRender(scene, mDamagedRects);
+          mCore.PreRender(windowRenderStatus, scene, mDamagedRects);
 
           // Render off-screen frame buffers first if any
           mCore.RenderScene(windowRenderStatus, scene, true);
@@ -711,24 +702,30 @@ void CombinedUpdateRenderController::UpdateRenderThread()
           Rect<int> clippingRect; // Empty for fbo rendering
 
           // Switch to the context of the surface, merge damaged areas for previous frames
-          windowSurface->PreRender(surfaceResized, mDamagedRects, clippingRect); // Switch GL context
-
-          if(clippingRect.IsEmpty())
+          if(windowRenderStatus.NeedsUpdate())
           {
-            mDamagedRects.clear();
+            windowSurface->PreRender(sceneSurfaceResized, mDamagedRects, clippingRect); // Switch GL context
           }
 
           // Render the surface
           mCore.RenderScene(windowRenderStatus, scene, false, clippingRect);
 
-          if(windowRenderStatus.NeedsPostRender())
+          // Buffer swapping now happens when the surface render target is presented.
+
+          // If surface is resized, the surface resized count is decreased.
+          if(DALI_UNLIKELY(sceneSurfaceResized))
           {
-            windowSurface->PostRender(false, false, surfaceResized, mDamagedRects); // Swap Buffer with damage
+            SurfaceResized();
           }
         }
       }
     }
 
+    if(!mUploadWithoutRendering)
+    {
+      graphics.PostRender();
+    }
+
     mCore.PostRender(mUploadWithoutRendering);
 
     //////////////////////////////
@@ -912,16 +909,13 @@ void CombinedUpdateRenderController::SurfaceDeleted()
   mSurfaceSemaphore.Release(1);
 }
 
-bool CombinedUpdateRenderController::ShouldSurfaceBeResized()
-{
-  ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
-  return mSurfaceResized;
-}
-
 void CombinedUpdateRenderController::SurfaceResized()
 {
   ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
-  mSurfaceResized = FALSE;
+  if(mSurfaceResized)
+  {
+    mSurfaceResized--;
+  }
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////