Add GetRenderThreadId()
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / combined-update-render-controller.cpp
index 0f1f71b..53514de 100644 (file)
 #include "dali/public-api/common/dali-common.h"
 
 // INTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/thread-settings.h>
 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
 #include <dali/internal/adaptor/common/combined-update-render-controller-debug.h>
 #include <dali/internal/graphics/common/graphics-interface.h>
 #include <dali/internal/graphics/gles/egl-graphics.h>
-#include <dali/internal/graphics/gles/egl-implementation.h>
 #include <dali/internal/system/common/environment-options.h>
 #include <dali/internal/system/common/time-service.h>
+#include <dali/internal/thread/common/thread-settings-impl.h>
 #include <dali/internal/window-system/common/window-impl.h>
 
 namespace Dali
@@ -106,6 +105,7 @@ CombinedUpdateRenderController::CombinedUpdateRenderController(AdaptorInternalSe
   mDefaultHalfFrameNanoseconds(0u),
   mUpdateRequestCount(0u),
   mRunning(FALSE),
+  mThreadId(0),
   mThreadMode(threadMode),
   mUpdateRenderRunCount(0),
   mDestroyUpdateRenderThread(FALSE),
@@ -408,6 +408,11 @@ void CombinedUpdateRenderController::AddSurface(Dali::RenderSurfaceInterface* su
   }
 }
 
+int32_t CombinedUpdateRenderController::GetThreadId() const
+{
+  return mThreadId;
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // EVENT THREAD
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -498,7 +503,8 @@ void CombinedUpdateRenderController::ProcessSleepRequest()
 
 void CombinedUpdateRenderController::UpdateRenderThread()
 {
-  SetThreadName("RenderThread\0");
+  ThreadSettings::SetThreadName("RenderThread\0");
+  mThreadId = ThreadSettings::GetThreadId();
 
   // Install a function for logging
   mEnvironmentOptions.InstallLogFunction();
@@ -528,6 +534,7 @@ void CombinedUpdateRenderController::UpdateRenderThread()
   // Update time
   uint64_t lastFrameTime;
   TimeService::GetNanoseconds(lastFrameTime);
+  uint64_t lastMemPoolLogTime = lastFrameTime;
 
   LOG_UPDATE_RENDER("THREAD INITIALISED");
 
@@ -536,6 +543,8 @@ void CombinedUpdateRenderController::UpdateRenderThread()
   uint64_t timeToSleepUntil   = 0;
   int      extraFramesDropped = 0;
 
+  const uint64_t memPoolInterval = 1e9 * float(mEnvironmentOptions.GetMemoryPoolInterval());
+
   const unsigned int renderToFboInterval = mEnvironmentOptions.GetRenderToFboInterval();
   const bool         renderToFboEnabled  = 0u != renderToFboInterval;
   unsigned int       frameCount          = 0u;
@@ -545,7 +554,8 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     LOG_UPDATE_RENDER_TRACE;
 
     // For thread safe
-    bool uploadOnly = mUploadWithoutRendering;
+    bool         uploadOnly     = mUploadWithoutRendering;
+    unsigned int surfaceResized = mSurfaceResized;
 
     // Performance statistics are logged upon a VSYNC tick so use this point for a VSync marker
     AddPerformanceMarker(PerformanceInterface::VSYNC);
@@ -592,8 +602,8 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     // UPDATE
     //////////////////////////////
 
-    const unsigned int currentTime   = currentFrameStartTime / NANOSECONDS_PER_MILLISECOND;
-    const unsigned int nextFrameTime = currentTime + mDefaultFrameDurationMilliseconds;
+    const uint32_t currentTime   = static_cast<uint32_t>(currentFrameStartTime / NANOSECONDS_PER_MILLISECOND);
+    const uint32_t nextFrameTime = currentTime + static_cast<uint32_t>(mDefaultFrameDurationMilliseconds);
 
     uint64_t noOfFramesSinceLastUpdate = 1;
     float    frameDelta                = 0.0f;
@@ -646,6 +656,7 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     // RENDER
     //////////////////////////////
 
+    graphics.FrameStart();
     mAdaptorInterfaces.GetDisplayConnectionInterface().ConsumeEvents();
 
     if(mPreRenderCallback != NULL)
@@ -676,14 +687,12 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     // Upload shared resources
     mCore.PreRender(renderStatus, mForceClear);
 
-    if(!uploadOnly)
+    if(!uploadOnly || surfaceResized)
     {
       // Go through each window
       WindowContainer windows;
       mAdaptorInterfaces.GetWindowContainerInterface(windows);
 
-      bool sceneSurfaceResized;
-
       for(auto&& window : windows)
       {
         Dali::Integration::Scene      scene         = window->GetScene();
@@ -693,9 +702,7 @@ void CombinedUpdateRenderController::UpdateRenderThread()
         {
           Integration::RenderStatus windowRenderStatus;
 
-          // Get Surface Resized flag
-          sceneSurfaceResized = scene.IsSurfaceRectChanged();
-          windowSurface->SetIsResizing(sceneSurfaceResized);
+          const bool sceneSurfaceResized = scene.IsSurfaceRectChanged();
 
           // clear previous frame damaged render items rects, buffer history is tracked on surface level
           mDamagedRects.clear();
@@ -749,6 +756,13 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     TRACE_UPDATE_RENDER_END("DALI_RENDER");
     AddPerformanceMarker(PerformanceInterface::RENDER_END);
 
+    // if the memory pool interval is set and has elapsed, log the graphics memory pools
+    if(0 < memPoolInterval && memPoolInterval < lastFrameTime - lastMemPoolLogTime)
+    {
+      lastMemPoolLogTime = lastFrameTime;
+      graphics.LogMemoryPools();
+    }
+
     mForceClear = false;
 
     // Trigger event thread to request Update/Render thread to sleep if update not required