[4.0] When native image is destroyed, It call TriggerEventInterface callback.
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / native-image-source-impl-tizen.cpp
old mode 100755 (executable)
new mode 100644 (file)
index e83af6c..fecf43b
 #include <gl/egl-factory.h>
 #include <adaptor-impl.h>
 #include <render-surface.h>
+#include <trigger-event-factory.h>
+
 
 // Allow this to be encoded and saved:
-#include <platform-abstractions/tizen/resource-loader/resource-loader.h>
 #include <bitmap-saver.h>
 
 namespace Dali
@@ -89,7 +90,8 @@ NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, D
   mColorDepth( depth ),
   mEglImageKHR( NULL ),
   mEglImageExtensions( NULL ),
-  mSetSource( false )
+  mSetSource( false ),
+  mNotification( NULL )
 {
   DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
   EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory();
@@ -198,6 +200,11 @@ NativeImageSource::~NativeImageSource()
     if( mTbmSurface != NULL )
     {
       tbm_surface_internal_unref( mTbmSurface );
+
+      if (mNotification != NULL) {
+          TriggerEventInterface* triggerEvent = static_cast<TriggerEventInterface* >(mNotification);
+          triggerEvent->Trigger();
+      }
     }
   }
 }
@@ -207,6 +214,12 @@ Any NativeImageSource::GetNativeImageSource() const
   return Any( mTbmSurface );
 }
 
+
+void NativeImageSource::SetDestructorNotification(void* notification)
+{
+  mNotification = notification;
+}
+
 bool NativeImageSource::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
 {
   if( mTbmSurface != NULL )
@@ -248,7 +261,7 @@ bool NativeImageSource::GetPixels(std::vector<unsigned char>& pixbuf, unsigned&
           {
             cOffset = c*3;
             offset = cOffset + r*stride;
-            *(bufptr) = ptr[offset+2];
+            *(bufptr+cOffset) = ptr[offset+2];
             *(bufptr+cOffset+1) = ptr[offset+1];
             *(bufptr+cOffset+2) = ptr[offset];
           }
@@ -268,7 +281,7 @@ bool NativeImageSource::GetPixels(std::vector<unsigned char>& pixbuf, unsigned&
           {
             cOffset = c*4;
             offset = cOffset + r*stride;
-            *(bufptr) = ptr[offset+3];
+            *(bufptr+cOffset) = ptr[offset+3];
             *(bufptr+cOffset+1) = ptr[offset+2];
             *(bufptr+cOffset+2) = ptr[offset+1];
             *(bufptr+cOffset+3) = ptr[offset];
@@ -278,11 +291,7 @@ bool NativeImageSource::GetPixels(std::vector<unsigned char>& pixbuf, unsigned&
       }
       default:
       {
-        DALI_LOG_WARNING( "Tbm surface has unsupported pixel format.\n" );
-
-        pixbuf.resize( 0 );
-        width = 0;
-        height = 0;
+        DALI_ASSERT_ALWAYS( 0 && "Tbm surface has unsupported pixel format.\n" );
 
         return false;
       }