Added ref/unref tbm_surface 60/129060/1
authortaeyoon0.lee <taeyoon0.lee@samsung.com>
Fri, 17 Mar 2017 12:17:55 +0000 (21:17 +0900)
committerNick Holland <nick.holland@partner.samsung.com>
Fri, 12 May 2017 15:23:14 +0000 (16:23 +0100)
Cherry picked from Tizen_3.0 branch

https://review.tizen.org/gerrit/#/c/119596/1

Change-Id: I3c52d475da8a7c908d3a1da6d140fe36cec23714

adaptors/tizen/native-image-source-impl-tizen.cpp

index c0e5da5..e83af6c 100755 (executable)
@@ -22,6 +22,7 @@
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/gl-defines.h>
 #include <cstring>
+#include <tbm_surface_internal.h>
 
 // INTERNAL INCLUDES
 #include <gl/egl-image-extensions.h>
@@ -99,6 +100,7 @@ NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, D
 
   if( mTbmSurface != NULL )
   {
+    tbm_surface_internal_ref( mTbmSurface );
     mBlendingRequired = CheckBlending( tbm_surface_get_format( mTbmSurface ) );
     mWidth = tbm_surface_get_width( mTbmSurface );
     mHeight = tbm_surface_get_height( mTbmSurface );
@@ -184,13 +186,20 @@ tbm_surface_h NativeImageSource::GetSurfaceFromAny( Any source ) const
 
 NativeImageSource::~NativeImageSource()
 {
-  if( mOwnTbmSurface && mTbmSurface != NULL )
+  if( mOwnTbmSurface )
   {
-    if( tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
+    if( mTbmSurface != NULL && tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
     {
       DALI_LOG_ERROR( "Failed to destroy tbm_surface\n" );
     }
   }
+  else
+  {
+    if( mTbmSurface != NULL )
+    {
+      tbm_surface_internal_unref( mTbmSurface );
+    }
+  }
 }
 
 Any NativeImageSource::GetNativeImageSource() const
@@ -310,9 +319,9 @@ bool NativeImageSource::EncodeToFile(const std::string& filename) const
 
 void NativeImageSource::SetSource( Any source )
 {
-  if( mOwnTbmSurface && mTbmSurface != NULL )
+  if( mOwnTbmSurface )
   {
-    if( tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
+    if( mTbmSurface != NULL && tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
     {
       DALI_LOG_ERROR( "Failed to destroy tbm_surface\n" );
     }
@@ -320,12 +329,21 @@ void NativeImageSource::SetSource( Any source )
     mTbmSurface = NULL;
     mOwnTbmSurface = false;
   }
+  else
+  {
+    if( mTbmSurface != NULL )
+    {
+      tbm_surface_internal_unref( mTbmSurface );
+      mTbmSurface = NULL;
+    }
+  }
 
   mTbmSurface = GetSurfaceFromAny( source );
-  mSetSource = true;
 
   if( mTbmSurface != NULL )
   {
+    mSetSource = true;
+    tbm_surface_internal_ref( mTbmSurface );
     mBlendingRequired = CheckBlending( tbm_surface_get_format( mTbmSurface ) );
     mWidth = tbm_surface_get_width( mTbmSurface );
     mHeight = tbm_surface_get_height( mTbmSurface );