Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / android / native-image-source-impl-android.cpp
index 19312b5..1052d0b 100755 (executable)
 #include <dali/internal/graphics/gles/egl-graphics.h>
 #include <dali/internal/adaptor/common/adaptor-impl.h>
 
+
+namespace
+{
+const char* FRAGMENT_PREFIX = "#extension GL_OES_EGL_image_external:require\n";
+const char* SAMPLER_TYPE = "samplerExternalOES";
+}
+
+
 namespace Dali
 {
 
@@ -175,9 +183,30 @@ bool NativeImageSourceAndroid::GetPixels(std::vector<unsigned char>& pixbuf, uns
     return success;
   }
 
-  uint32_t size = bufferDescription.stride * bufferDescription.height;
-  pixbuf.resize( size );
-  memcpy( pixbuf.data(), buffer, size );
+  uint32_t pixelBytes = GetBytesPerPixel(pixelFormat);
+  if ( bufferDescription.stride < (pixelBytes * bufferDescription.width) )
+  {
+    //On Android device, bufferDescription.stride doesn't seem to mean (width * pixelbytes)
+    //in an actual case, (AHardwareBuffer_Desc) bufferDescription = (width = 1080, height = 1060, layers = 1, format = 1, usage = 306, stride = 1088, rfu0 = 0, rfu1 = 0)
+    //deal with situation
+    uint32_t dstStride = pixelBytes * bufferDescription.width;
+    uint32_t srcStride = pixelBytes * bufferDescription.stride;
+    uint32_t size = dstStride * bufferDescription.height;
+    pixbuf.resize( size );
+    //copy each row over
+    const unsigned char* ptrSrc = reinterpret_cast<const unsigned char*>(buffer);
+    unsigned char* ptrDst = pixbuf.data();
+    for (int y=0; y < bufferDescription.height; y++, ptrSrc += srcStride, ptrDst += dstStride )
+    {
+      memcpy( ptrDst, ptrSrc, dstStride );
+    }
+  }
+  else
+  {
+    uint32_t size = bufferDescription.stride * bufferDescription.height;
+    pixbuf.resize( size );
+    memcpy( pixbuf.data(), buffer, size );
+  }
 
   ret = AHardwareBuffer_unlock( mPixmap, NULL );
   if( ret != 0 )
@@ -217,12 +246,12 @@ bool NativeImageSourceAndroid::IsColorDepthSupported( Dali::NativeImageSource::C
   return true;
 }
 
-bool NativeImageSourceAndroid::GlExtensionCreate()
+bool NativeImageSourceAndroid::CreateResource()
 {
   // if the image existed previously delete it.
   if( mEglImageKHR != NULL )
   {
-    GlExtensionDestroy();
+    DestroyResource();
   }
 
   DALI_ASSERT_ALWAYS( mPixmap );
@@ -261,7 +290,7 @@ bool NativeImageSourceAndroid::GlExtensionCreate()
   return mEglImageKHR != NULL;
 }
 
-void NativeImageSourceAndroid::GlExtensionDestroy()
+void NativeImageSourceAndroid::DestroyResource()
 {
   mEglImageExtensions->DestroyImageKHR( mEglImageKHR );
 
@@ -279,6 +308,22 @@ void NativeImageSourceAndroid::PrepareTexture()
 {
 }
 
+int NativeImageSourceAndroid::GetTextureTarget() const
+{
+  return GL_TEXTURE_2D;
+}
+
+const char* NativeImageSourceAndroid::GetCustomFragmentPrefix() const
+{
+  return nullptr;
+}
+
+const char* NativeImageSourceAndroid::GetCustomSamplerTypename() const
+{
+  return nullptr;
+}
+
+
 void* NativeImageSourceAndroid::GetPixmapFromAny(Any pixmap) const
 {
   if( pixmap.Empty() )