[Tizen] Fix build warning
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-implementation.cpp
index d63989f..485bcff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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 <sstream>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/environment-variable.h>
 #include <dali/internal/graphics/gles/egl-debug.h>
 #include <dali/internal/graphics/gles/gl-implementation.h>
+#include <dali/internal/system/common/time-service.h>
 #include <dali/public-api/dali-adaptor-common.h>
 
 // EGL constants use C style casts
@@ -43,7 +45,17 @@ const std::string EGL_KHR_CREATE_CONTEXT                  = "EGL_KHR_create_cont
 const std::string EGL_KHR_PARTIAL_UPDATE                  = "EGL_KHR_partial_update";
 const std::string EGL_KHR_SWAP_BUFFERS_WITH_DAMAGE        = "EGL_KHR_swap_buffers_with_damage";
 
+// Threshold time in miliseconds
+constexpr auto PERFORMANCE_LOG_THRESHOLD_TIME_ENV = "DALI_EGL_PERFORMANCE_LOG_THRESHOLD_TIME";
+
 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_EGL, true);
+
+static uint32_t GetPerformanceLogThresholdTime()
+{
+  auto     timeString = Dali::EnvironmentVariable::GetEnvironmentVariable(PERFORMANCE_LOG_THRESHOLD_TIME_ENV);
+  uint32_t time       = timeString ? static_cast<uint32_t>(std::atoi(timeString)) : 0u;
+  return time;
+}
 } // namespace
 
 namespace Dali
@@ -179,10 +191,13 @@ bool EglImplementation::InitializeGles(EGLNativeDisplayType display, bool isOwnS
     mPartialUpdateRequired = false;
   }
 
+  mLogThreshold = GetPerformanceLogThresholdTime();
+  mLogEnabled   = mLogThreshold > 0 ? true : false;
+
   mGlesInitialized = true;
 
   // We want to display this information all the time, so use the LogMessage directly
-  Integration::Log::LogMessage(Integration::Log::DebugInfo,
+  Integration::Log::LogMessage(Integration::Log::INFO,
                                "EGL Information\n"
                                "            PartialUpdate  %d\n"
                                "            Vendor:        %s\n"
@@ -383,6 +398,12 @@ void EglImplementation::SwapBuffers(EGLSurface& eglSurface)
 {
   if(eglSurface != EGL_NO_SURFACE) // skip if using surfaceless context
   {
+    uint32_t startTime = 0, endTime = 0;
+    if(mLogEnabled)
+    {
+      startTime = TimeService::GetMilliSeconds();
+    }
+
 #ifndef DALI_PROFILE_UBUNTU
     if(mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT)
     {
@@ -402,11 +423,26 @@ void EglImplementation::SwapBuffers(EGLSurface& eglSurface)
       mSwapBufferCountAfterResume++;
     }
 #endif //DALI_PROFILE_UBUNTU
+
+    if(mLogEnabled)
+    {
+      endTime = TimeService::GetMilliSeconds();
+      if(endTime - startTime > mLogThreshold)
+      {
+        DALI_LOG_DEBUG_INFO("eglSwapBuffers takes long time! [%u ms]\n", endTime - startTime);
+      }
+    }
   }
 }
 
 EGLint EglImplementation::GetBufferAge(EGLSurface& eglSurface) const
 {
+  uint32_t startTime = 0, endTime = 0;
+  if(mLogEnabled)
+  {
+    startTime = TimeService::GetMilliSeconds();
+  }
+
   EGLint age = 0;
   eglQuerySurface(mEglDisplay, eglSurface, EGL_BUFFER_AGE_EXT, &age);
   if(age < 0)
@@ -415,14 +451,14 @@ EGLint EglImplementation::GetBufferAge(EGLSurface& eglSurface) const
     age = 0;
   }
 
-  // 0 - invalid buffer
-  // 1, 2, 3
-  if(age > 3)
+  if(mLogEnabled)
   {
-    DALI_LOG_ERROR("EglImplementation::GetBufferAge() buffer age %d > 3\n", age);
-    age = 0; // shoudn't be more than 3 back buffers, if there is just reset, I don't want to add extra history level
+    endTime = TimeService::GetMilliSeconds();
+    if(endTime - startTime > mLogThreshold)
+    {
+      DALI_LOG_DEBUG_INFO("eglQuerySurface takes long time! [%u ms]\n", endTime - startTime);
+    }
   }
-
   return age;
 }
 
@@ -438,7 +474,7 @@ void EglImplementation::SetDamageRegion(EGLSurface& eglSurface, std::vector<Rect
     EGLBoolean result = mEglSetDamageRegionKHR(mEglDisplay, eglSurface, reinterpret_cast<int*>(damagedRects.data()), 1);
     if(result == EGL_FALSE)
     {
-      DALI_LOG_ERROR("eglSetDamageRegionKHR(%d)\n", eglGetError());
+      DALI_LOG_ERROR("eglSetDamageRegionKHR(0x%x)\n", eglGetError());
     }
   }
 }
@@ -453,6 +489,12 @@ void EglImplementation::SwapBuffers(EGLSurface& eglSurface, const std::vector<Re
       return;
     }
 
+    uint32_t startTime = 0, endTime = 0;
+    if(mLogEnabled)
+    {
+      startTime = TimeService::GetMilliSeconds();
+    }
+
 #ifndef DALI_PROFILE_UBUNTU
     if(mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT)
     {
@@ -475,6 +517,15 @@ void EglImplementation::SwapBuffers(EGLSurface& eglSurface, const std::vector<Re
       mSwapBufferCountAfterResume++;
     }
 #endif //DALI_PROFILE_UBUNTU
+
+    if(mLogEnabled)
+    {
+      endTime = TimeService::GetMilliSeconds();
+      if(endTime - startTime > mLogThreshold)
+      {
+        DALI_LOG_DEBUG_INFO("eglSwapBuffersWithDamageKHR takes long time! [%u ms]\n", endTime - startTime);
+      }
+    }
   }
 }
 
@@ -606,7 +657,7 @@ bool EglImplementation::ChooseConfig(bool isWindowType, ColorDepth depth)
     DALI_ASSERT_ALWAYS(false && "eglChooseConfig failed!");
     return false;
   }
-  Integration::Log::LogMessage(Integration::Log::DebugInfo, "Using OpenGL es %d.%d.\n", mGlesVersion / 10, mGlesVersion % 10);
+  Integration::Log::LogMessage(Integration::Log::INFO, "Using OpenGL es %d.%d.\n", mGlesVersion / 10, mGlesVersion % 10);
 
   mContextAttribs.Clear();
   if(mIsKhrCreateContextSupported)