Let we make multiple native render surface has seperated display 68/320768/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 7 Mar 2025 06:49:38 +0000 (15:49 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 11 Mar 2025 04:35:41 +0000 (13:35 +0900)
Until now, we make native render surface use single unique dummy buffer.
But if we try to use multiple displays at the same time,
it might use same EGLDisplay, so might have invalid dummy display.

To guard this case, let we keep dummy display staci for it.

Change-Id: If3fdcc9fb4d64a7bb8067452b61fbc18138e3205
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/window-system/tizen-wayland/display-connection-impl-ecore-wl.cpp

index 3d5d8a87a70e6523ddb93774037ffd7f9802390f..14f3d14e6140c377f3e2191e3a2f4b469f9a4245 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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_HEADERS
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/common/vector-wrapper.h>
 #include <tbm_bufmgr.h>
 #include <tbm_dummy_display.h>
+#include <utility> ///< for std::pair
 
 // INTERNAL HEADERS
 #include <dali/internal/window-system/tizen-wayland/display-connection-native-types.h>
@@ -43,7 +45,7 @@ struct NativeRenderSurfaceDisplayHolder
 {
   NativeRenderSurfaceDisplayHolder()
   : mBufMgr(nullptr),
-    mDisplay(nullptr)
+    mDisplayList()
   {
     Initialize();
   }
@@ -56,44 +58,98 @@ struct NativeRenderSurfaceDisplayHolder
   void Initialize()
   {
     mBufMgr = tbm_bufmgr_init(-1); // -1 is meaningless. The parameter in this function is deprecated.
+  }
+
+  tbm_dummy_display* AcquireDisplay()
+  {
+    tbm_dummy_display* display = nullptr;
     if(mBufMgr)
     {
-      mDisplay = tbm_dummy_display_create();
+      for(auto& displayPair : mDisplayList)
+      {
+        if(!displayPair.second)
+        {
+          displayPair.second = true;
+          DALI_LOG_DEBUG_INFO("Use created dummy display : %p (total dummy display : %zu)\n", displayPair.first, mDisplayList.size());
+          return displayPair.first;
+        }
+      }
+
+      // Create new dummy 1 display
+      display = tbm_dummy_display_create();
+      if(display)
+      {
+        mDisplayList.push_back({display, true});
+        DALI_LOG_DEBUG_INFO("Create dummy display : %p (total dummy display : %zu)\n", display, mDisplayList.size());
+      }
     }
+    return display;
   }
+
+  void ReleaseDisplay(tbm_dummy_display* display)
+  {
+    for(auto& displayPair : mDisplayList)
+    {
+      if(displayPair.first == display)
+      {
+        DALI_LOG_DEBUG_INFO("Release dummy display : %p (total dummy display : %zu)\n", display, mDisplayList.size());
+        displayPair.second = false;
+        break;
+      }
+    }
+  }
+
   void Destroy()
   {
-    if(mDisplay)
+    for(auto& displayPair : mDisplayList)
     {
-      tbm_dummy_display_destroy(mDisplay);
+      tbm_dummy_display_destroy(displayPair.first);
     }
+    mDisplayList.clear();
 
     if(mBufMgr)
     {
       tbm_bufmgr_deinit(mBufMgr);
+      mBufMgr = nullptr;
     }
   }
 
   tbm_bufmgr mBufMgr; ///< For creating tbm_dummy_display
 
-  tbm_dummy_display* mDisplay;
+  std::vector<std::pair<tbm_dummy_display*, bool>> mDisplayList; ///< pair of {display, used}. Increase only.
 };
 
-static tbm_dummy_display* GetUniqueTbmDummyDisplay()
+static NativeRenderSurfaceDisplayHolder& GetDummyDisplayHolder()
+{
+  static NativeRenderSurfaceDisplayHolder gNativeRenderSurfaceDisplayHolder;
+  return gNativeRenderSurfaceDisplayHolder;
+}
+
+static tbm_dummy_display* AcquireUniqueTbmDummyDisplay()
 {
-  static NativeRenderSurfaceDisplayHolder sNativeRenderSurfaceDisplayHolder;
-  if(sNativeRenderSurfaceDisplayHolder.mBufMgr == nullptr)
+  auto& displayHolder = GetDummyDisplayHolder();
+  if(displayHolder.mBufMgr == nullptr)
   {
     // Retry to initialize tbm bufmgr
-    sNativeRenderSurfaceDisplayHolder.Destroy();
-    sNativeRenderSurfaceDisplayHolder.Initialize();
-    if(sNativeRenderSurfaceDisplayHolder.mBufMgr == nullptr)
+    displayHolder.Destroy();
+    displayHolder.Initialize();
+    if(displayHolder.mBufMgr == nullptr)
     {
       DALI_LOG_ERROR("Fail to init tbm buf mgr\n");
       return nullptr;
     }
   }
-  return sNativeRenderSurfaceDisplayHolder.mDisplay;
+  return displayHolder.AcquireDisplay();
+}
+
+static void ReleaseTbmDummyDisplay(tbm_dummy_display* display)
+{
+  auto& displayHolder = GetDummyDisplayHolder();
+  if(displayHolder.mBufMgr == nullptr)
+  {
+    return;
+  }
+  return displayHolder.ReleaseDisplay(display);
 }
 } // namespace
 
@@ -103,7 +159,14 @@ DisplayConnectionEcoreWl::DisplayConnectionEcoreWl()
 {
 }
 
-DisplayConnectionEcoreWl::~DisplayConnectionEcoreWl() = default;
+DisplayConnectionEcoreWl::~DisplayConnectionEcoreWl()
+{
+  if(mSurfaceType == Integration::RenderSurfaceInterface::NATIVE_RENDER_SURFACE)
+  {
+    ReleaseTbmDummyDisplay(mDisplay);
+    mDisplay = nullptr;
+  }
+}
 
 Any DisplayConnectionEcoreWl::GetDisplay()
 {
@@ -120,7 +183,7 @@ void DisplayConnectionEcoreWl::SetSurfaceType(Integration::RenderSurfaceInterfac
 
   if(mSurfaceType == Integration::RenderSurfaceInterface::NATIVE_RENDER_SURFACE)
   {
-    mDisplay = static_cast<wl_display*>(GetUniqueTbmDummyDisplay());
+    mDisplay = static_cast<wl_display*>(AcquireUniqueTbmDummyDisplay());
   }
   else
   {