[4.0] When native image is destroyed, it release of wl buffer and remote surface. 95/155795/1
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Mon, 16 Oct 2017 07:11:03 +0000 (16:11 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Mon, 16 Oct 2017 07:11:26 +0000 (16:11 +0900)
This reverts commit 0268bf894fcb1747156025b4851325fc46b9d2bb.

Change-Id: Ic8cf895653e368ea7a5d5280e7cf3ccc8e6f95a0

widget_viewer_dali/internal/widget_view/widget_view_impl.cpp
widget_viewer_dali/internal/widget_view/widget_view_impl.h

index 8a9f205697005b53757f0165d2282d4513257c56..f34c02609d0c65efea9d9e22e2f47cc473351149 100644 (file)
@@ -42,6 +42,7 @@
 #include <unistd.h>
 #include <libintl.h>
 #include <xkbcommon/xkbcommon.h>
+#include <dali/devel-api/images/native-image-interface-extension.h>
 
 namespace Dali
 {
@@ -201,15 +202,7 @@ static void OnBufferUpdated( struct tizen_remote_surface *surface, uint32_t type
 
     //get tbm surface from buffer
     tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
-    widgetView->UpdateImageSource( tbmSurface );
-  }
-
-  if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
-  {
-    tizen_remote_surface_release( surface, preBuffer );
-    tbm_surface_h preTbmSurface = (tbm_surface_h)wl_buffer_get_user_data( preBuffer );
-    tbm_surface_internal_unref( preTbmSurface );
-    wl_buffer_destroy( preBuffer );
+    widgetView->UpdateImageSource( tbmSurface, buffer, surface);
   }
 
   remoteSurface = surface;
@@ -1011,11 +1004,62 @@ bool WidgetView::IsWidgetImageView()
   return ( mWidgetImageView )? true: false;
 }
 
-void WidgetView::UpdateImageSource( tbm_surface_h source )
+
+class DestructorCallback: public CallbackBase
 {
+public:
+  DestructorCallback(void *buffer ,void *surface)
+  :CallbackBase( reinterpret_cast< void* >( this ),
+   NULL, // we get the dispatcher to call function directly
+   reinterpret_cast< CallbackBase::Dispatcher>( &DestructorCallback::Dispatcher) ),
+   mWlBuffer( buffer ),
+   mRemoteSurface( surface ) {
+
+  }
+
+  void RunCallback()
+  {
+    struct wl_buffer *buffer = static_cast< struct wl_buffer* >(mWlBuffer);
+    struct tizen_remote_surface *surface = static_cast< struct tizen_remote_surface* >(mRemoteSurface);
+    if (tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION) {
+        tizen_remote_surface_release( surface, buffer );
+        tbm_surface_h preTbmSurface = (tbm_surface_h)wl_buffer_get_user_data( buffer );
+        tbm_surface_internal_unref( preTbmSurface );
+        wl_buffer_destroy( buffer );
+    }
+  }
+
+  static void Dispatcher( CallbackBase& base )
+  {
+    DestructorCallback& callback( static_cast< DestructorCallback& >( base) );
+    callback.RunCallback();
+  }
+
+  ~DestructorCallback()
+  {
+  }
+
+private:
+  void *mWlBuffer ;
+  void *mRemoteSurface;
+};
+
+
+void WidgetView::UpdateImageSource( tbm_surface_h source , struct wl_buffer *buffer , struct tizen_remote_surface *surface)
+{
+  DestructorCallback* callback = new DestructorCallback( buffer, surface );
+  TriggerEventFactory triggerEventFactory;
+  TriggerEventInterface* notification = triggerEventFactory.CreateTriggerEvent( callback,
+                                                                                TriggerEventInterface::DELETE_AFTER_TRIGGER );
+
   mImageSource = Dali::NativeImageSource::New( source );
   Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
 
+  NativeImageInterfacePtr mImageSourcePtr = static_cast< NativeImageInterfacePtr >(mImageSource);
+  NativeImageInterface::Extension* extension = mImageSourcePtr->GetExtension();
+  if( extension )
+   extension->SetDestructorNotification(notification);
+
   if( mWidgetImageView )
   {
     mWidgetImageView.SetImage( image );
index c7e2039c890f147f88590dbea139b12ccf770922..7009bf4b5216726628ad756b9801c5bdbbc26a42 100644 (file)
@@ -30,6 +30,7 @@
 #include <wayland-extension/tizen-remote-surface-client-protocol.h>
 #include <tbm_surface.h>
 #include <screen_connector_toolkit.h>
+#include <dali/integration-api/adaptors/trigger-event-factory.h>
 
 namespace Dali
 {
@@ -135,7 +136,7 @@ public: // Internal API
 
   bool IsWidgetImageView();
 
-  void UpdateImageSource( tbm_surface_h source );
+  void UpdateImageSource( tbm_surface_h source , struct wl_buffer *buffer , struct tizen_remote_surface *surface);
 
   void CreateWidgetImageView();