From: Heeyong Song Date: Tue, 29 Nov 2022 10:43:13 +0000 (+0900) Subject: [Tizen] Add FreeReleasedBuffers method to NativeImageSourceQueue X-Git-Tag: accepted/tizen/7.0/unified/20221212.015717~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=406e5709c9429d490d0fb9c0178e4fee32fa6e3e [Tizen] Add FreeReleasedBuffers method to NativeImageSourceQueue Change-Id: I39ee5656a71860cf688467bd8d2dc32a2e48a27d --- diff --git a/dali/devel-api/adaptor-framework/native-image-source-queue.cpp b/dali/devel-api/adaptor-framework/native-image-source-queue.cpp index 9655a5a..4bf089b 100644 --- a/dali/devel-api/adaptor-framework/native-image-source-queue.cpp +++ b/dali/devel-api/adaptor-framework/native-image-source-queue.cpp @@ -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(); diff --git a/dali/devel-api/adaptor-framework/native-image-source-queue.h b/dali/devel-api/adaptor-framework/native-image-source-queue.h index cba01ca..d6995d9 100644 --- a/dali/devel-api/adaptor-framework/native-image-source-queue.h +++ b/dali/devel-api/adaptor-framework/native-image-source-queue.h @@ -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; diff --git a/dali/internal/imaging/android/native-image-source-queue-impl-android.cpp b/dali/internal/imaging/android/native-image-source-queue-impl-android.cpp index 79e009f..ff0addc 100644 --- a/dali/internal/imaging/android/native-image-source-queue-impl-android.cpp +++ b/dali/internal/imaging/android/native-image-source-queue-impl-android.cpp @@ -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; diff --git a/dali/internal/imaging/android/native-image-source-queue-impl-android.h b/dali/internal/imaging/android/native-image-source-queue-impl-android.h index 28a5c2e..0ed28c3 100644 --- a/dali/internal/imaging/android/native-image-source-queue-impl-android.h +++ b/dali/internal/imaging/android/native-image-source-queue-impl-android.h @@ -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; diff --git a/dali/internal/imaging/common/native-image-source-queue-impl.h b/dali/internal/imaging/common/native-image-source-queue-impl.h index 8c9028b..19ea0c6 100644 --- a/dali/internal/imaging/common/native-image-source-queue-impl.h +++ b/dali/internal/imaging/common/native-image-source-queue-impl.h @@ -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; diff --git a/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.cpp b/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.cpp index c47b775..b5d926b 100644 --- a/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.cpp +++ b/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.cpp @@ -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) diff --git a/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.h b/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.h index 3556448..736ab60 100644 --- a/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.h +++ b/dali/internal/imaging/tizen/native-image-source-queue-impl-tizen.h @@ -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 diff --git a/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.cpp b/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.cpp index 8023374..5198ee3 100644 --- a/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.cpp +++ b/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.cpp @@ -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; diff --git a/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.h b/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.h index 5711b6c..279b368 100644 --- a/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.h +++ b/dali/internal/imaging/ubuntu-x11/native-image-source-queue-impl-x.h @@ -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; diff --git a/dali/internal/imaging/x11/native-image-source-queue-impl-x.cpp b/dali/internal/imaging/x11/native-image-source-queue-impl-x.cpp index 8f26e41..d5c5da5 100644 --- a/dali/internal/imaging/x11/native-image-source-queue-impl-x.cpp +++ b/dali/internal/imaging/x11/native-image-source-queue-impl-x.cpp @@ -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; diff --git a/dali/internal/imaging/x11/native-image-source-queue-impl-x.h b/dali/internal/imaging/x11/native-image-source-queue-impl-x.h index 61d1eff..279b368 100644 --- a/dali/internal/imaging/x11/native-image-source-queue-impl-x.h +++ b/dali/internal/imaging/x11/native-image-source-queue-impl-x.h @@ -80,6 +80,11 @@ public: bool EnqueueBuffer(uint8_t* buffer) override; /** + * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer + */ + void FreeReleasedBuffers() override; + + /** * destructor */ ~NativeImageSourceQueueX() override;