Add API for setting resource destruction callback 80/262780/9
authorsunghyun kim <scholb.kim@samsung.com>
Thu, 19 Aug 2021 13:33:55 +0000 (22:33 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Tue, 5 Oct 2021 03:15:02 +0000 (03:15 +0000)
Add api for setting resource destruction callback.
this callback will be called when NativeImageSource is desroyed its resource

Change-Id: Ib97573c648105b12bf38f601ace89a5b0fc54608

13 files changed:
dali/devel-api/adaptor-framework/native-image-source-devel.cpp
dali/devel-api/adaptor-framework/native-image-source-devel.h
dali/internal/imaging/android/native-image-source-impl-android.cpp
dali/internal/imaging/android/native-image-source-impl-android.h
dali/internal/imaging/common/native-image-source-impl.h
dali/internal/imaging/macos/native-image-source-impl-mac.cpp
dali/internal/imaging/macos/native-image-source-impl-mac.h
dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp
dali/internal/imaging/tizen/native-image-source-impl-tizen.h
dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp
dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h
dali/internal/imaging/windows/native-image-source-impl-win.cpp
dali/internal/imaging/windows/native-image-source-impl-win.h

index 948e52b..6b2ea45 100644 (file)
@@ -40,6 +40,11 @@ bool ReleaseBuffer(NativeImageSource& image)
   return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).ReleaseBuffer();\r
 }\r
 \r
+void SetResourceDestructionCallback(NativeImageSource& image, EventThreadCallback* callback)\r
+{\r
+  return Dali::Internal::Adaptor::NativeImageSource::GetImplementation(image).SetResourceDestructionCallback(callback);\r
+}\r
+\r
 } // namespace DevelNativeImageSource\r
 \r
 } // namespace Dali\r
index 605cca5..3ddc317 100644 (file)
@@ -19,6 +19,8 @@
 \r
 // EXTERNAL INCLUDES\r
 #include <dali/public-api/adaptor-framework/native-image-source.h>\r
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>\r
+\r
 \r
 namespace Dali\r
 {\r
@@ -60,6 +62,15 @@ DALI_ADAPTOR_API uint8_t* AcquireBuffer(NativeImageSource& image, uint16_t& widt
  */\r
 DALI_ADAPTOR_API bool ReleaseBuffer(NativeImageSource& image);\r
 \r
+/**\r
+ * @brief Set the Resource Destruction Callback object\r
+ *\r
+ * @param image The instance of NativeImageSource.\r
+ * @param callback The Resource Destruction callback\r
+ * @note Ownership of the callback is passed onto this class.\r
+ */\r
+DALI_ADAPTOR_API void SetResourceDestructionCallback(NativeImageSource& image, EventThreadCallback* callback);\r
+\r
 } // namespace DevelNativeImageSource\r
 \r
 } // namespace Dali\r
index e06af8e..bb6693f 100644 (file)
@@ -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<EventThreadCallback>(callback);
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 1b87f5f..65397d6 100644 (file)
@@ -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<EventThreadCallback> mResourceDestructionCallback;  ///< The Resource Destruction Callback
 };
 
 } // namespace Adaptor
index 3dd33b2..dcb0570 100644 (file)
@@ -21,6 +21,8 @@
 // INTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/bitmap-saver.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
+
 
 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
index 3e3b33f..cc99b1b 100644 (file)
@@ -45,7 +45,8 @@ NativeImageSourceCocoa::NativeImageSourceCocoa(
   unsigned int                        height,
   Dali::NativeImageSource::ColorDepth depth,
   Any                                 nativeImageSource)
-: mImage(MakeRef<CGImageRef>(nullptr))
+: mImage(MakeRef<CGImageRef>(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<EventThreadCallback>(callback);
+}
+
 } // namespace Dali::Internal::Adaptor
index 6e5ed2a..5bb1db5 100644 (file)
@@ -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<CGImageRef> mImage;
+  std::unique_ptr<EventThreadCallback> mResourceDestructionCallback;  ///< The Resource Destruction Callback
 };
 
 } // namespace Dali::Internal::Adaptor
index a6e7cc6..f8e8f7c 100644 (file)
@@ -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<EventThreadCallback>(callback);
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 11569fc..10dd6c9 100644 (file)
@@ -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<EventThreadCallback> mResourceDestructionCallback;  ///< The Resource Destruction Callback
 };
 
 } // namespace Adaptor
index 656c2e0..5ae65a1 100644 (file)
@@ -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<EventThreadCallback>(callback);
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index e6b672c..a522fa1 100644 (file)
@@ -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<EventThreadCallback> mResourceDestructionCallback;  ///< The Resource Destruction Callback
 };
 
 } // namespace Adaptor
index f1997a7..44742ee 100644 (file)
@@ -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<EventThreadCallback>(callback);
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 8893c50..81e2ab2 100644 (file)
@@ -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<EventThreadCallback> mResourceDestructionCallback;  ///< The Resource Destruction Callback
 };
 
 } // namespace Adaptor