Sort RenderItems only if we need 65/323965/3
authorEunki Hong <eunkiki.hong@samsung.com>
Fri, 9 May 2025 15:24:19 +0000 (00:24 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 12 May 2025 02:05:31 +0000 (11:05 +0900)
Change-Id: I9ac9fde63a8a473d1d7999603874fd5ebdda43f1
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali/internal/update/manager/render-instruction-processor.cpp

index 631832a67328b81a83d38a0b9de0c5b707233758..52270a056100db6fd9f41f75bbb04121669e64a5 100644 (file)
@@ -475,6 +475,8 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex,
   //   2 is LAYER_3D + Clipping
   const int comparitorIndex = layer.GetBehavior() == Dali::Layer::LAYER_3D ? respectClippingOrder ? 2u : 1u : 0u;
 
+  bool needToSort = false;
+
   for(uint32_t index = 0; index < renderableCount; ++index)
   {
     RenderItemKey itemKey = renderList.GetItemKey(index);
@@ -501,9 +503,24 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex,
 
     // Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
     mSortingHelper[index].renderItem = itemKey;
+
+    if(!needToSort && index > 0u)
+    {
+      // Check if we need to sort the list.
+      // We only need to sort if the depth index is not the same as the previous item.
+      // This is a fast way of checking if we need to sort.
+      if(mSortComparitors[comparitorIndex](mSortingHelper[index], mSortingHelper[index - 1u]))
+      {
+        needToSort = true;
+      }
+    }
   }
 
-  std::stable_sort(mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[comparitorIndex]);
+  // If we don't need to sort, we can skip the sort.
+  if(needToSort)
+  {
+    std::stable_sort(mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[comparitorIndex]);
+  }
 
   // Reorder / re-populate the RenderItems in the RenderList to correct order based on the sortinghelper.
   DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "Sorted Transparent List:\n");