[Tizen] Add API for setting resource destruction callback
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / tizen / native-image-source-impl-tizen.cpp
index 2682522..3cd6831 100755 (executable)
@@ -30,9 +30,6 @@
 #include <dali/internal/adaptor/common/adaptor-impl.h>
 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
 
-// Allow this to be encoded and saved:
-#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
-
 namespace Dali
 {
 
@@ -91,7 +88,8 @@ NativeImageSourceTizen::NativeImageSourceTizen( uint32_t width, uint32_t height,
   mEglImageExtensions( NULL ),
   mSetSource( false ),
   mMutex(),
-  mIsBufferAcquired( false )
+  mIsBufferAcquired( false ),
+  mResourceDestructionCallback()
 {
   DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
 
@@ -301,10 +299,10 @@ bool NativeImageSourceTizen::GetPixels(std::vector<unsigned char>& pixbuf, unsig
           {
             cOffset = c*4;
             offset = cOffset + r*stride;
-            *(bufptr+cOffset) = ptr[offset];
-            *(bufptr+cOffset+1) = ptr[offset+3];
-            *(bufptr+cOffset+2) = ptr[offset+2];
-            *(bufptr+cOffset+3) = ptr[offset+1];
+            *(bufptr+cOffset)   = ptr[offset+2];
+            *(bufptr+cOffset+1) = ptr[offset+1];
+            *(bufptr+cOffset+2) = ptr[offset];
+            *(bufptr+cOffset+3) = ptr[offset+3];
           }
         }
         break;
@@ -333,19 +331,6 @@ bool NativeImageSourceTizen::GetPixels(std::vector<unsigned char>& pixbuf, unsig
   return false;
 }
 
-bool NativeImageSourceTizen::EncodeToFile(const std::string& filename) const
-{
-  std::vector< unsigned char > pixbuf;
-  unsigned int width(0), height(0);
-  Pixel::Format pixelFormat;
-
-  if(GetPixels(pixbuf, width, height, pixelFormat))
-  {
-    return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height);
-  }
-  return false;
-}
-
 void NativeImageSourceTizen::SetSource( Any source )
 {
   Dali::Mutex::ScopedLock lock( mMutex );
@@ -416,7 +401,7 @@ bool NativeImageSourceTizen::IsColorDepthSupported( Dali::NativeImageSource::Col
   return false;
 }
 
-bool NativeImageSourceTizen::GlExtensionCreate()
+bool NativeImageSourceTizen::CreateResource()
 {
   // casting from an unsigned int to a void *, which should then be cast back
   // to an unsigned int in the driver.
@@ -434,7 +419,7 @@ bool NativeImageSourceTizen::GlExtensionCreate()
   return mEglImageKHR != NULL;
 }
 
-void NativeImageSourceTizen::GlExtensionDestroy()
+void NativeImageSourceTizen::DestroyResource()
 {
   Dali::Mutex::ScopedLock lock( mMutex );
   if( mEglImageKHR )
@@ -443,6 +428,11 @@ void NativeImageSourceTizen::GlExtensionDestroy()
 
     mEglImageKHR = NULL;
   }
+
+  if(mResourceDestructionCallback)
+  {
+    mResourceDestructionCallback->Trigger();
+  }
 }
 
 uint32_t NativeImageSourceTizen::TargetTexture()
@@ -459,7 +449,7 @@ void NativeImageSourceTizen::PrepareTexture()
   {
     void* eglImage = mEglImageKHR;
 
-    if( GlExtensionCreate() )
+    if( CreateResource() )
     {
       TargetTexture();
     }
@@ -470,21 +460,31 @@ void NativeImageSourceTizen::PrepareTexture()
   }
 }
 
-const char* NativeImageSourceTizen::GetCustomFragmentPreFix()
+const char* NativeImageSourceTizen::GetCustomFragmentPrefix() const
 {
   return FRAGMENT_PREFIX;
 }
 
-const char* NativeImageSourceTizen::GetCustomSamplerTypename()
+const char* NativeImageSourceTizen::GetCustomSamplerTypename() const
 {
   return SAMPLER_TYPE;
 }
 
-int NativeImageSourceTizen::GetEglImageTextureTarget()
+int NativeImageSourceTizen::GetTextureTarget() const
 {
   return GL_TEXTURE_EXTERNAL_OES;
 }
 
+Any NativeImageSourceTizen::GetNativeImageHandle() const
+{
+  return GetNativeImageSource();
+}
+
+bool NativeImageSourceTizen::SourceChanged() const
+{
+  return false;
+}
+
 bool NativeImageSourceTizen::CheckBlending( tbm_format format )
 {
   if( mTbmFormat != format )
@@ -549,6 +549,10 @@ bool NativeImageSourceTizen::ReleaseBuffer()
   return ret;
 }
 
+void NativeImageSourceTizen::SetResourceDestructionCallback(EventThreadCallback* callback)
+{
+  mResourceDestructionCallback = std::unique_ptr<EventThreadCallback>(callback);
+}
 
 } // namespace Adaptor