From 06e1bc7147010573ecfad8977280220ed03843a7 Mon Sep 17 00:00:00 2001 From: sunghyun kim Date: Thu, 19 Aug 2021 22:33:55 +0900 Subject: [PATCH] Add API for setting resource destruction callback Add api for setting resource destruction callback. this callback will be called when NativeImageSource is desroyed its resource Change-Id: Ib97573c648105b12bf38f601ace89a5b0fc54608 --- .../native-image-source-devel.cpp | 5 ++++ .../adaptor-framework/native-image-source-devel.h | 11 ++++++++ .../android/native-image-source-impl-android.cpp | 17 ++++++++++-- .../android/native-image-source-impl-android.h | 22 +++++++++------ .../imaging/common/native-image-source-impl.h | 7 +++++ .../imaging/macos/native-image-source-impl-mac.cpp | 8 +++++- .../imaging/macos/native-image-source-impl-mac.h | 6 ++++ .../tizen/native-image-source-impl-tizen.cpp | 14 +++++++++- .../imaging/tizen/native-image-source-impl-tizen.h | 32 +++++++++++++--------- .../ubuntu-x11/native-image-source-impl-x.cpp | 13 ++++++++- .../ubuntu-x11/native-image-source-impl-x.h | 22 +++++++++------ .../windows/native-image-source-impl-win.cpp | 13 ++++++++- .../imaging/windows/native-image-source-impl-win.h | 22 +++++++++------ 13 files changed, 148 insertions(+), 44 deletions(-) diff --git a/dali/devel-api/adaptor-framework/native-image-source-devel.cpp b/dali/devel-api/adaptor-framework/native-image-source-devel.cpp index 948e52b..6b2ea45 100644 --- a/dali/devel-api/adaptor-framework/native-image-source-devel.cpp +++ b/dali/devel-api/adaptor-framework/native-image-source-devel.cpp @@ -40,6 +40,11 @@ bool ReleaseBuffer(NativeImageSource& image) return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).ReleaseBuffer(); } +void SetResourceDestructionCallback(NativeImageSource& image, EventThreadCallback* callback) +{ + return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).SetResourceDestructionCallback(callback); +} + } // namespace DevelNativeImageSource } // namespace Dali diff --git a/dali/devel-api/adaptor-framework/native-image-source-devel.h b/dali/devel-api/adaptor-framework/native-image-source-devel.h index 605cca5..3ddc317 100644 --- a/dali/devel-api/adaptor-framework/native-image-source-devel.h +++ b/dali/devel-api/adaptor-framework/native-image-source-devel.h @@ -19,6 +19,8 @@ // EXTERNAL INCLUDES #include +#include + namespace Dali { @@ -60,6 +62,15 @@ DALI_ADAPTOR_API uint8_t* AcquireBuffer(NativeImageSource& image, uint16_t& widt */ DALI_ADAPTOR_API bool ReleaseBuffer(NativeImageSource& image); +/** + * @brief Set the Resource Destruction Callback object + * + * @param image The instance of NativeImageSource. + * @param callback The Resource Destruction callback + * @note Ownership of the callback is passed onto this class. + */ +DALI_ADAPTOR_API void SetResourceDestructionCallback(NativeImageSource& image, EventThreadCallback* callback); + } // namespace DevelNativeImageSource } // namespace Dali diff --git a/dali/internal/imaging/android/native-image-source-impl-android.cpp b/dali/internal/imaging/android/native-image-source-impl-android.cpp index e06af8e..bb6693f 100644 --- a/dali/internal/imaging/android/native-image-source-impl-android.cpp +++ b/dali/internal/imaging/android/native-image-source-impl-android.cpp @@ -56,15 +56,16 @@ NativeImageSourceAndroid* NativeImageSourceAndroid::New(uint32_t width, uint32_t return image; } -NativeImageSourceAndroid::NativeImageSourceAndroid(uint32_t width, uint32_t height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource) +NativeImageSourceAndroid::NativeImageSourceAndroid( uint32_t width, uint32_t height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) : mWidth(width), - mHeight(height), + mHeight(height ), mOwnPixmap(true), mPixmap(NULL), mBlendingRequired(false), mColorDepth(depth), mEglImageKHR(NULL), - mEglImageExtensions(NULL) + mEglImageExtensions(NULL), + mResourceDestructionCallback() { DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -285,6 +286,11 @@ void NativeImageSourceAndroid::DestroyResource() mEglImageExtensions->DestroyImageKHR(mEglImageKHR); mEglImageKHR = NULL; + + if(mResourceDestructionCallback) + { + mResourceDestructionCallback->Trigger(); + } } uint32_t NativeImageSourceAndroid::TargetTexture() @@ -390,6 +396,11 @@ bool NativeImageSourceAndroid::ReleaseBuffer() return false; } +void NativeImageSourceAndroid::SetResourceDestructionCallback(EventThreadCallback* callback) +{ + mResourceDestructionCallback = std::unique_ptr(callback); +} + } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/imaging/android/native-image-source-impl-android.h b/dali/internal/imaging/android/native-image-source-impl-android.h index 1b87f5f..65397d6 100644 --- a/dali/internal/imaging/android/native-image-source-impl-android.h +++ b/dali/internal/imaging/android/native-image-source-impl-android.h @@ -173,6 +173,11 @@ public: */ bool ReleaseBuffer() override; + /** + * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback() + */ + void SetResourceDestructionCallback(EventThreadCallback* callback) override; + private: /** * Private constructor; @see NativeImageSource::New() @@ -205,14 +210,15 @@ private: void GetPixmapDetails(); private: - uint32_t mWidth; ///< image width - uint32_t mHeight; ///< image heights - bool mOwnPixmap; ///< Whether we created pixmap or not - AHardwareBuffer* mPixmap; ///< - bool mBlendingRequired; ///< Whether blending is required - Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image - void* mEglImageKHR; ///< From EGL extension - EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + uint32_t mWidth; ///< image width + uint32_t mHeight; ///< image heights + bool mOwnPixmap; ///< Whether we created pixmap or not + AHardwareBuffer* mPixmap; ///< + bool mBlendingRequired; ///< Whether blending is required + Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image + void* mEglImageKHR; ///< From EGL extension + EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + std::unique_ptr mResourceDestructionCallback; ///< The Resource Destruction Callback }; } // namespace Adaptor diff --git a/dali/internal/imaging/common/native-image-source-impl.h b/dali/internal/imaging/common/native-image-source-impl.h index 3dd33b2..dcb0570 100644 --- a/dali/internal/imaging/common/native-image-source-impl.h +++ b/dali/internal/imaging/common/native-image-source-impl.h @@ -21,6 +21,8 @@ // INTERNAL INCLUDES #include #include +#include + namespace Dali { @@ -150,6 +152,11 @@ public: virtual bool ReleaseBuffer() = 0; /** + * @brief Dali::DevelNativeImageSource::SetResourceDestructionCallback() + */ + virtual void SetResourceDestructionCallback(EventThreadCallback* callback) = 0; + + /** * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& ) */ inline bool EncodeToFile(const std::string& filename) const diff --git a/dali/internal/imaging/macos/native-image-source-impl-mac.cpp b/dali/internal/imaging/macos/native-image-source-impl-mac.cpp index 3e3b33f..cc99b1b 100644 --- a/dali/internal/imaging/macos/native-image-source-impl-mac.cpp +++ b/dali/internal/imaging/macos/native-image-source-impl-mac.cpp @@ -45,7 +45,8 @@ NativeImageSourceCocoa::NativeImageSourceCocoa( unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource) -: mImage(MakeRef(nullptr)) +: mImage(MakeRef(nullptr)), + mResourceDestructionCallback() { DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); DALI_ASSERT_ALWAYS(nativeImageSource.Empty()); @@ -205,4 +206,9 @@ bool NativeImageSourceCocoa::ReleaseBuffer() return false; } +void NativeImageSourceCocoa::SetResourceDestructionCallback(EventThreadCallback* callback) +{ + mResourceDestructionCallback = std::unique_ptr(callback); +} + } // namespace Dali::Internal::Adaptor diff --git a/dali/internal/imaging/macos/native-image-source-impl-mac.h b/dali/internal/imaging/macos/native-image-source-impl-mac.h index 6e5ed2a..5bb1db5 100644 --- a/dali/internal/imaging/macos/native-image-source-impl-mac.h +++ b/dali/internal/imaging/macos/native-image-source-impl-mac.h @@ -156,6 +156,11 @@ public: */ bool ReleaseBuffer() override; + /** + * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback() + */ + void SetResourceDestructionCallback(EventThreadCallback* callback) override; + private: /** * Private constructor; @see NativeImageSource::New() @@ -172,6 +177,7 @@ private: private: CFRef mImage; + std::unique_ptr mResourceDestructionCallback; ///< The Resource Destruction Callback }; } // namespace Dali::Internal::Adaptor diff --git a/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp b/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp index a6e7cc6..f8e8f7c 100644 --- a/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp +++ b/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp @@ -86,7 +86,9 @@ NativeImageSourceTizen::NativeImageSourceTizen(uint32_t width, uint32_t height, mEglImageExtensions(NULL), mSetSource(false), mMutex(), - mIsBufferAcquired(false) + mIsBufferAcquired(false), + mResourceDestructionCallback() + { DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -431,6 +433,11 @@ void NativeImageSourceTizen::DestroyResource() mEglImageKHR = NULL; } + + if(mResourceDestructionCallback) + { + mResourceDestructionCallback->Trigger(); + } } uint32_t NativeImageSourceTizen::TargetTexture() @@ -547,6 +554,11 @@ bool NativeImageSourceTizen::ReleaseBuffer() return ret; } +void NativeImageSourceTizen::SetResourceDestructionCallback(EventThreadCallback* callback) +{ + mResourceDestructionCallback = std::unique_ptr(callback); +} + } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/imaging/tizen/native-image-source-impl-tizen.h b/dali/internal/imaging/tizen/native-image-source-impl-tizen.h index 11569fc..10dd6c9 100644 --- a/dali/internal/imaging/tizen/native-image-source-impl-tizen.h +++ b/dali/internal/imaging/tizen/native-image-source-impl-tizen.h @@ -168,6 +168,11 @@ public: */ bool ReleaseBuffer() override; + /** + * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback() + */ + void SetResourceDestructionCallback(EventThreadCallback* callback) override; + private: /** * Private constructor; @see NativeImageSource::New() @@ -190,19 +195,20 @@ private: void DestroySurface(); private: - uint32_t mWidth; ///< image width - uint32_t mHeight; ///< image height - bool mOwnTbmSurface; ///< Whether we created pixmap or not - tbm_surface_h mTbmSurface; - tbm_format mTbmFormat; - bool mBlendingRequired; ///< Whether blending is required - Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image - void* mEglImageKHR; ///< From EGL extension - EglGraphics* mEglGraphics; ///< EGL Graphics - EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions - bool mSetSource; - mutable Dali::Mutex mMutex; - bool mIsBufferAcquired; ///< Whether AcquireBuffer is called + uint32_t mWidth; ///< image width + uint32_t mHeight; ///< image height + bool mOwnTbmSurface; ///< Whether we created pixmap or not + tbm_surface_h mTbmSurface; + tbm_format mTbmFormat; + bool mBlendingRequired; ///< Whether blending is required + Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image + void* mEglImageKHR; ///< From EGL extension + EglGraphics* mEglGraphics; ///< EGL Graphics + EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + bool mSetSource; + mutable Dali::Mutex mMutex; + bool mIsBufferAcquired; ///< Whether AcquireBuffer is called + std::unique_ptr mResourceDestructionCallback; ///< The Resource Destruction Callback }; } // namespace Adaptor diff --git a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp index 656c2e0..5ae65a1 100644 --- a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp +++ b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp @@ -92,7 +92,8 @@ NativeImageSourceX::NativeImageSourceX(uint32_t width, uint32_t height, Dali::Na mBlendingRequired(false), mColorDepth(depth), mEglImageKHR(NULL), - mEglImageExtensions(NULL) + mEglImageExtensions(NULL), + mResourceDestructionCallback() { DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -306,6 +307,11 @@ void NativeImageSourceX::DestroyResource() mEglImageExtensions->DestroyImageKHR(mEglImageKHR); mEglImageKHR = NULL; + + if(mResourceDestructionCallback) + { + mResourceDestructionCallback->Trigger(); + } } uint32_t NativeImageSourceX::TargetTexture() @@ -425,6 +431,11 @@ bool NativeImageSourceX::ReleaseBuffer() return false; } +void NativeImageSourceX::SetResourceDestructionCallback(EventThreadCallback* callback) +{ + mResourceDestructionCallback = std::unique_ptr(callback); +} + } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h index e6b672c..a522fa1 100644 --- a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h +++ b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h @@ -167,6 +167,11 @@ public: */ bool ReleaseBuffer() override; + /** + * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback() + */ + void SetResourceDestructionCallback(EventThreadCallback* callback) override; + private: /** * Private constructor; @see NativeImageSource::New() @@ -206,14 +211,15 @@ private: void GetPixmapDetails(); private: - uint32_t mWidth; ///< image width - uint32_t mHeight; ///< image heights - bool mOwnPixmap; ///< Whether we created pixmap or not - Ecore_X_Pixmap mPixmap; ///< From Xlib - bool mBlendingRequired; ///< Whether blending is required - Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image - void* mEglImageKHR; ///< From EGL extension - EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + uint32_t mWidth; ///< image width + uint32_t mHeight; ///< image heights + bool mOwnPixmap; ///< Whether we created pixmap or not + Ecore_X_Pixmap mPixmap; ///< From Xlib + bool mBlendingRequired; ///< Whether blending is required + Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image + void* mEglImageKHR; ///< From EGL extension + EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + std::unique_ptr mResourceDestructionCallback; ///< The Resource Destruction Callback }; } // namespace Adaptor diff --git a/dali/internal/imaging/windows/native-image-source-impl-win.cpp b/dali/internal/imaging/windows/native-image-source-impl-win.cpp index f1997a7..44742ee 100644 --- a/dali/internal/imaging/windows/native-image-source-impl-win.cpp +++ b/dali/internal/imaging/windows/native-image-source-impl-win.cpp @@ -58,7 +58,8 @@ NativeImageSourceWin::NativeImageSourceWin(unsigned int width, unsigned int heig mBlendingRequired(false), mColorDepth(depth), mEglImageKHR(NULL), - mEglImageExtensions(NULL) + mEglImageExtensions(NULL), + mResourceDestructionCallback() { DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -157,6 +158,11 @@ void NativeImageSourceWin::DestroyResource() mEglImageExtensions->DestroyImageKHR(mEglImageKHR); mEglImageKHR = NULL; + + if(mResourceDestructionCallback) + { + mResourceDestructionCallback->Trigger(); + } } unsigned int NativeImageSourceWin::TargetTexture() @@ -263,6 +269,11 @@ bool NativeImageSourceWin::ReleaseBuffer() return false; } +void NativeImageSourceWin::SetResourceDestructionCallback(EventThreadCallback* callback) +{ + mResourceDestructionCallback = std::unique_ptr(callback); +} + } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/imaging/windows/native-image-source-impl-win.h b/dali/internal/imaging/windows/native-image-source-impl-win.h index 8893c50..81e2ab2 100644 --- a/dali/internal/imaging/windows/native-image-source-impl-win.h +++ b/dali/internal/imaging/windows/native-image-source-impl-win.h @@ -162,6 +162,11 @@ public: */ bool ReleaseBuffer() override; + /** + * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback() + */ + void SetResourceDestructionCallback(EventThreadCallback* callback) override; + private: /** * Private constructor; @see NativeImageSource::New() @@ -201,14 +206,15 @@ private: void GetPixmapDetails(); private: - unsigned int mWidth; ///< image width - unsigned int mHeight; ///< image heights - bool mOwnPixmap; ///< Whether we created pixmap or not - unsigned int mPixmap; ///< From Windows - bool mBlendingRequired; ///< Whether blending is required - Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image - void* mEglImageKHR; ///< From EGL extension - EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + unsigned int mWidth; ///< image width + unsigned int mHeight; ///< image heights + bool mOwnPixmap; ///< Whether we created pixmap or not + unsigned int mPixmap; ///< From Windows + bool mBlendingRequired; ///< Whether blending is required + Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image + void* mEglImageKHR; ///< From EGL extension + EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + std::unique_ptr mResourceDestructionCallback; ///< The Resource Destruction Callback }; } // namespace Adaptor -- 2.7.4