Add GetRenderThreadId()
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / combined-update-render-controller.cpp
index a8a1401..53514de 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #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;
@@ -544,6 +553,10 @@ void CombinedUpdateRenderController::UpdateRenderThread()
   {
     LOG_UPDATE_RENDER_TRACE;
 
+    // For thread safe
+    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);
 
@@ -589,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;
@@ -616,12 +629,15 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     Integration::UpdateStatus updateStatus;
 
     AddPerformanceMarker(PerformanceInterface::UPDATE_START);
+    TRACE_UPDATE_RENDER_BEGIN("DALI_UPDATE");
     mCore.Update(frameDelta,
                  currentTime,
                  nextFrameTime,
                  updateStatus,
                  renderToFboEnabled,
-                 isRenderingToFbo);
+                 isRenderingToFbo,
+                 uploadOnly);
+    TRACE_UPDATE_RENDER_END("DALI_UPDATE");
     AddPerformanceMarker(PerformanceInterface::UPDATE_END);
 
     unsigned int keepUpdatingStatus = updateStatus.KeepUpdating();
@@ -640,6 +656,7 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     // RENDER
     //////////////////////////////
 
+    graphics.FrameStart();
     mAdaptorInterfaces.GetDisplayConnectionInterface().ConsumeEvents();
 
     if(mPreRenderCallback != NULL)
@@ -665,18 +682,17 @@ void CombinedUpdateRenderController::UpdateRenderThread()
     Integration::RenderStatus renderStatus;
 
     AddPerformanceMarker(PerformanceInterface::RENDER_START);
+    TRACE_UPDATE_RENDER_BEGIN("DALI_RENDER");
 
     // Upload shared resources
-    mCore.PreRender(renderStatus, mForceClear, mUploadWithoutRendering);
+    mCore.PreRender(renderStatus, mForceClear);
 
-    if(!mUploadWithoutRendering)
+    if(!uploadOnly || surfaceResized)
     {
       // Go through each window
       WindowContainer windows;
       mAdaptorInterfaces.GetWindowContainerInterface(windows);
 
-      bool sceneSurfaceResized;
-
       for(auto&& window : windows)
       {
         Dali::Integration::Scene      scene         = window->GetScene();
@@ -686,11 +702,7 @@ void CombinedUpdateRenderController::UpdateRenderThread()
         {
           Integration::RenderStatus windowRenderStatus;
 
-          // Get Surface Resized flag
-          sceneSurfaceResized = scene.IsSurfaceRectChanged();
-          windowSurface->SetIsResizing(sceneSurfaceResized);
-
-          windowSurface->InitializeGraphics();
+          const bool sceneSurfaceResized = scene.IsSurfaceRectChanged();
 
           // clear previous frame damaged render items rects, buffer history is tracked on surface level
           mDamagedRects.clear();
@@ -720,12 +732,12 @@ void CombinedUpdateRenderController::UpdateRenderThread()
       }
     }
 
-    if(!mUploadWithoutRendering)
+    if(!uploadOnly)
     {
-      graphics.ActivateResourceContext();
+      graphics.PostRender();
     }
 
-    mCore.PostRender(mUploadWithoutRendering);
+    mCore.PostRender();
 
     //////////////////////////////
     // DELETE SURFACE
@@ -741,8 +753,16 @@ void CombinedUpdateRenderController::UpdateRenderThread()
       SurfaceDeleted();
     }
 
+    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