Add FreeReleasedBuffers method to NativeImageSourceQueue 61/284861/5
authorHeeyong Song <heeyong.song@samsung.com>
Tue, 29 Nov 2022 10:43:13 +0000 (19:43 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Mon, 5 Dec 2022 07:32:47 +0000 (16:32 +0900)
Change-Id: I39ee5656a71860cf688467bd8d2dc32a2e48a27d

dali/devel-api/adaptor-framework/native-image-source-queue.cpp
dali/devel-api/adaptor-framework/native-image-source-queue.h
dali/internal/imaging/android/native-image-source-queue-impl-android.cpp
dali/internal/imaging/android/native-image-source-queue-impl-android.h
dali/internal/imaging/common/native-image-source-queue-impl.h
dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.cpp
dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.h
dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.cpp
dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.h
dali/internal/imaging/x11/native-image-source-queue-impl-x.cpp
dali/internal/imaging/x11/native-image-source-queue-impl-x.h

index 9655a5a..4bf089b 100644 (file)
@@ -76,6 +76,11 @@ bool NativeImageSourceQueue::EnqueueBuffer(uint8_t* buffer)
   return mImpl->EnqueueBuffer(buffer);
 }
 
+void NativeImageSourceQueue::FreeReleasedBuffers()
+{
+  mImpl->FreeReleasedBuffers();
+}
+
 bool NativeImageSourceQueue::CreateResource()
 {
   return mImpl->CreateResource();
index cba01ca..d6995d9 100644 (file)
@@ -145,6 +145,11 @@ public:
   bool EnqueueBuffer(uint8_t* buffer);
 
   /**
+   * @brief Free all released buffers.
+   */
+  void FreeReleasedBuffers();
+
+  /**
    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
    */
   int GetTextureTarget() const override;
index 79e009f..ff0addc 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.
@@ -80,6 +80,10 @@ bool NativeImageSourceQueueAndroid::EnqueueBuffer(uint8_t* buffer)
   return false;
 }
 
+void NativeImageSourceQueueAndroid::FreeReleasedBuffers()
+{
+}
+
 bool NativeImageSourceQueueAndroid::CreateResource()
 {
   return true;
index 28a5c2e..0ed28c3 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_ANDROID_H
 
 /*
- * 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.
@@ -80,6 +80,11 @@ public:
   bool EnqueueBuffer(uint8_t* buffer) override;
 
   /**
+   * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
+   */
+  void FreeReleasedBuffers() override;
+
+  /**
    * destructor
    */
   ~NativeImageSourceQueueAndroid() override;
index 8c9028b..19ea0c6 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_H
 
 /*
- * 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.
@@ -69,6 +69,11 @@ public:
   virtual bool EnqueueBuffer(uint8_t* buffer) = 0;
 
   /**
+   * @copydoc Dali::NativeImageSourceQueue::FreeReleasedBuffers
+   */
+  virtual void FreeReleasedBuffers() = 0;
+
+  /**
    * destructor
    */
   virtual ~NativeImageSourceQueue() = default;
index c47b775..b5d926b 100644 (file)
@@ -92,7 +92,8 @@ NativeImageSourceQueueTizen::NativeImageSourceQueueTizen(uint32_t width, uint32_
   mEglImageExtensions(NULL),
   mOwnTbmQueue(false),
   mBlendingRequired(false),
-  mIsResized(false)
+  mIsResized(false),
+  mFreeRequest(false)
 {
   DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
 
@@ -302,6 +303,12 @@ bool NativeImageSourceQueueTizen::EnqueueBuffer(uint8_t* buffer)
   return false;
 }
 
+void NativeImageSourceQueueTizen::FreeReleasedBuffers()
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+  mFreeRequest = true;
+}
+
 bool NativeImageSourceQueueTizen::CreateResource()
 {
   mEglImageExtensions = mEglGraphics->GetImageExtensions();
@@ -326,24 +333,37 @@ void NativeImageSourceQueueTizen::PrepareTexture()
 {
   Dali::Mutex::ScopedLock lock(mMutex);
 
-  tbm_surface_h oldSurface = mConsumeSurface;
+  bool updated = false;
 
-  if(tbm_surface_queue_can_acquire(mTbmQueue, 0))
+  do
   {
-    if(tbm_surface_queue_acquire(mTbmQueue, &mConsumeSurface) != TBM_SURFACE_QUEUE_ERROR_NONE)
-    {
-      DALI_LOG_ERROR("Failed to aquire a tbm_surface\n");
-      return;
-    }
+    tbm_surface_h oldSurface = mConsumeSurface;
 
-    if(oldSurface)
+    if(tbm_surface_queue_can_acquire(mTbmQueue, 0))
     {
-      if(tbm_surface_internal_is_valid(oldSurface))
+      if(tbm_surface_queue_acquire(mTbmQueue, &mConsumeSurface) != TBM_SURFACE_QUEUE_ERROR_NONE)
+      {
+        DALI_LOG_ERROR("Failed to aquire a tbm_surface\n");
+        return;
+      }
+
+      if(oldSurface)
       {
-        tbm_surface_queue_release(mTbmQueue, oldSurface);
+        if(tbm_surface_internal_is_valid(oldSurface))
+        {
+          tbm_surface_queue_release(mTbmQueue, oldSurface);
+        }
       }
+      updated = true;
+    }
+    else
+    {
+      break;
     }
+  } while(mFreeRequest); // Get the last one if buffer free was requested
 
+  if(updated)
+  {
     if(mIsResized)
     {
       ResetEglImageList(false);
@@ -376,6 +396,19 @@ void NativeImageSourceQueueTizen::PrepareTexture()
       }
     }
   }
+
+  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());
+
+    tbm_surface_queue_free_flush(mTbmQueue);
+    mFreeRequest = false;
+  }
 }
 
 bool NativeImageSourceQueueTizen::ApplyNativeFragmentShader(std::string& shader)
index 3556448..736ab60 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
 
 /*
- * 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.
@@ -84,6 +84,11 @@ public:
   bool EnqueueBuffer(uint8_t* buffer) override;
 
   /**
+   * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
+   */
+  void FreeReleasedBuffers() override;
+
+  /**
    * destructor
    */
   ~NativeImageSourceQueueTizen() override;
@@ -199,6 +204,7 @@ private:
   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
index 8023374..5198ee3 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.
@@ -85,6 +85,10 @@ bool NativeImageSourceQueueX::EnqueueBuffer(uint8_t* buffer)
   return false;
 }
 
+void NativeImageSourceQueueX::FreeReleasedBuffers()
+{
+}
+
 bool NativeImageSourceQueueX::CreateResource()
 {
   return true;
index 5711b6c..279b368 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_X_H
 
 /*
- * 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.
@@ -80,6 +80,11 @@ public:
   bool EnqueueBuffer(uint8_t* buffer) override;
 
   /**
+   * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
+   */
+  void FreeReleasedBuffers() override;
+
+  /**
    * destructor
    */
   ~NativeImageSourceQueueX() override;
index 8f26e41..d5c5da5 100644 (file)
@@ -28,7 +28,6 @@ namespace Internal
 {
 namespace Adaptor
 {
-
 NativeImageSourceQueueX* NativeImageSourceQueueX::New(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorFormat colorFormat, Any nativeImageSourceQueue)
 {
   NativeImageSourceQueueX* image = new NativeImageSourceQueueX(width, height, colorFormat, nativeImageSourceQueue);
@@ -76,6 +75,10 @@ bool NativeImageSourceQueueX::EnqueueBuffer(uint8_t* buffer)
   return false;
 }
 
+void NativeImageSourceQueueX::FreeReleasedBuffers()
+{
+}
+
 bool NativeImageSourceQueueX::CreateResource()
 {
   return true;
index 61d1eff..279b368 100644 (file)
@@ -80,6 +80,11 @@ public:
   bool EnqueueBuffer(uint8_t* buffer) override;
 
   /**
+   * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
+   */
+  void FreeReleasedBuffers() override;
+
+  /**
    * destructor
    */
   ~NativeImageSourceQueueX() override;