Optimize NativeImageSourceQueue rendering time 49/304149/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 10 Jan 2024 20:35:05 +0000 (05:35 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 10 Jan 2024 20:41:40 +0000 (05:41 +0900)
If NativeImageSourceQueue has a lots of queue, it might have some overhead
during rendering.

Let we remove some useless iteration for that case, so reduce overhead.

Change-Id: I43b57b61cf2434e659cd368d6166c65e2fbe9f39
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.cpp
dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.h

index 6b394bd..94ad034 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -289,21 +289,19 @@ uint8_t* NativeImageSourceQueueTizen::DequeueBuffer(uint32_t& width, uint32_t& h
   height = mHeight;
 
   // Push the buffer
-  mBuffers.push_back(BufferPair(tbmSurface, buffer));
+  mBuffers.insert({buffer, tbmSurface});
   return buffer;
 }
 
 bool NativeImageSourceQueueTizen::EnqueueBuffer(uint8_t* buffer)
 {
   Dali::Mutex::ScopedLock lock(mMutex);
-  auto                    bufferInstance = std::find_if(mBuffers.begin(),
-                                     mBuffers.end(),
-                                     [buffer](BufferPair pair) { return (pair.second == buffer); });
+  auto                    bufferInstance = mBuffers.find(buffer);
   if(bufferInstance != mBuffers.end())
   {
-    tbm_surface_internal_unref((*bufferInstance).first);
-    tbm_surface_unmap((*bufferInstance).first);
-    tbm_surface_queue_enqueue(mTbmQueue, (*bufferInstance).first);
+    tbm_surface_internal_unref((*bufferInstance).second);
+    tbm_surface_unmap((*bufferInstance).second);
+    tbm_surface_queue_enqueue(mTbmQueue, (*bufferInstance).second);
     mBuffers.erase(bufferInstance);
     return true;
   }
@@ -379,19 +377,8 @@ void NativeImageSourceQueueTizen::PrepareTexture()
 
     if(mConsumeSurface)
     {
-      bool existing = false;
-      for(auto&& iter : mEglImages)
-      {
-        if(iter.first == mConsumeSurface)
-        {
-          // Find the surface in the existing list
-          existing = true;
-          mEglImageExtensions->TargetTextureKHR(iter.second);
-          break;
-        }
-      }
-
-      if(!existing)
+      auto iter = mEglImages.find(mConsumeSurface);
+      if(iter == mEglImages.end())
       {
         // Push the surface
         tbm_surface_internal_ref(mConsumeSurface);
@@ -399,19 +386,32 @@ void NativeImageSourceQueueTizen::PrepareTexture()
         void* eglImageKHR = mEglImageExtensions->CreateImageKHR(reinterpret_cast<EGLClientBuffer>(mConsumeSurface));
         mEglImageExtensions->TargetTextureKHR(eglImageKHR);
 
-        mEglImages.push_back(EglImagePair(mConsumeSurface, eglImageKHR));
+        mEglImages.insert({mConsumeSurface, eglImageKHR});
+      }
+      else
+      {
+        mEglImageExtensions->TargetTextureKHR(iter->second);
       }
     }
   }
 
   if(mFreeRequest)
   {
-    auto iter = std::remove_if(mEglImages.begin(), mEglImages.end(), [&](EglImagePair& eglImage) {
-        if(mConsumeSurface == eglImage.first) return false;
-        mEglImageExtensions->DestroyImageKHR(eglImage.second);
-        tbm_surface_internal_unref(eglImage.first);
-        return true; });
-    mEglImages.erase(iter, mEglImages.end());
+    // Destroy all egl images which is not mConsumeSurface.
+    for(auto iter = mEglImages.begin(); iter != mEglImages.end();)
+    {
+      if(iter->first == mConsumeSurface)
+      {
+        ++iter;
+      }
+      else
+      {
+        mEglImageExtensions->DestroyImageKHR(iter->second);
+        tbm_surface_internal_unref(iter->first);
+
+        iter = mEglImages.erase(iter);
+      }
+    }
 
     tbm_surface_queue_free_flush(mTbmQueue);
     mFreeRequest = false;
index a24f754..3f66b5a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
  */
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/common/map-wrapper.h>
 #include <dali/devel-api/threading/mutex.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <tbm_surface.h>
 #include <tbm_surface_queue.h>
+#include <unordered_map>
 
 // INTERNAL INCLUDES
 #include <dali/internal/imaging/common/native-image-source-queue-impl.h>
@@ -207,23 +209,23 @@ private:
   bool CheckBlending(int format);
 
 private:
-  typedef std::pair<tbm_surface_h, void*>    EglImagePair;
-  typedef std::pair<tbm_surface_h, uint8_t*> BufferPair;
-
-  Dali::Mutex               mMutex;              ///< Mutex
-  uint32_t                  mQueueCount;         ///< queue count
-  uint32_t                  mWidth;              ///< image width
-  uint32_t                  mHeight;             ///< image height
-  tbm_surface_queue_h       mTbmQueue;           ///< Tbm surface queue handle
-  tbm_surface_h             mConsumeSurface;     ///< The current tbm surface
-  std::vector<EglImagePair> mEglImages;          ///< EGL Image vector
-  std::vector<BufferPair>   mBuffers;            ///< Buffer vector
-  EglGraphics*              mEglGraphics;        ///< EGL Graphics
-  EglImageExtensions*       mEglImageExtensions; ///< The EGL Image Extensions
-  bool                      mOwnTbmQueue;        ///< Whether we created tbm queue
-  bool                      mBlendingRequired;   ///< Whether blending is required
-  bool                      mIsResized;          ///< Whether the size has changed
-  bool                      mFreeRequest;        ///< Whether it is requested to free the released buffers
+  using SurfaceEglContainer    = std::unordered_map<tbm_surface_h, void*>;
+  using BufferSurfaceContainer = std::unordered_map<uint8_t*, tbm_surface_h>;
+
+  Dali::Mutex            mMutex;              ///< Mutex
+  uint32_t               mQueueCount;         ///< queue count
+  uint32_t               mWidth;              ///< image width
+  uint32_t               mHeight;             ///< image height
+  tbm_surface_queue_h    mTbmQueue;           ///< Tbm surface queue handle
+  tbm_surface_h          mConsumeSurface;     ///< The current tbm surface
+  SurfaceEglContainer    mEglImages;          ///< EGL Image map
+  BufferSurfaceContainer mBuffers;            ///< Buffer map
+  EglGraphics*           mEglGraphics;        ///< EGL Graphics
+  EglImageExtensions*    mEglImageExtensions; ///< The EGL Image Extensions
+  bool                   mOwnTbmQueue;        ///< Whether we created tbm queue
+  bool                   mBlendingRequired;   ///< Whether blending is required
+  bool                   mIsResized;          ///< Whether the size has changed
+  bool                   mFreeRequest;        ///< Whether it is requested to free the released buffers
 };
 
 } // namespace Adaptor