[4.0] Exposing Exif Image metadata
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / tizen / tizen-platform-abstraction.cpp
index 26debc0..2bf6e6f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
+// CLASS HEADER
 #include "tizen-platform-abstraction.h"
 
-#ifndef DALI_PROFILE_UBUNTU
-#include <vconf.h>
-#endif // DALI_PROFILE_UBUNTU
+// EXTERNAL INCLUDES
 #include <dirent.h>
-
+#include <fstream>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/bitmap.h>
 #include <dali/integration-api/resource-types.h>
 
 // INTERNAL INCLUDES
-#include "resource-loader/resource-loader.h"
 #include "image-loaders/image-loader.h"
-#include "portable/file-closer.h"
+#include "portable/file-reader.h"
+#include <adaptors/common/pixel-buffer-impl.h>
 
 namespace Dali
 {
 
-Integration::PlatformAbstraction* CreatePlatformAbstraction()
-{
-  return new TizenPlatform::TizenPlatformAbstraction();
-}
-
-
 namespace TizenPlatform
 {
 
-namespace
-{
-const unsigned int NANOSECS_TO_MICROSECS( 1000 );               ///< 1000 nanoseconds = 1 microsecond
-}
-
 TizenPlatformAbstraction::TizenPlatformAbstraction()
-: mResourceLoader(new ResourceLoader),
-  mDataStoragePath( "" )
+: mDataStoragePath( "" )
 {
 }
 
 TizenPlatformAbstraction::~TizenPlatformAbstraction()
 {
-  delete mResourceLoader;
-}
-
-void TizenPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds)
-{
-  timespec time;
-  clock_gettime(CLOCK_MONOTONIC, &time);
-  seconds = time.tv_sec;
-  microSeconds = time.tv_nsec / NANOSECS_TO_MICROSECS;
-}
-
-void TizenPlatformAbstraction::Suspend()
-{
-  if (mResourceLoader)
-  {
-    mResourceLoader->Pause();
-  }
-}
-
-void TizenPlatformAbstraction::Resume()
-{
-  if (mResourceLoader)
-  {
-    mResourceLoader->Resume();
-  }
-}
-
-int TizenPlatformAbstraction::GetDefaultFontSize() const
-{
-  int fontSize( -1 );
-
-#ifndef DALI_PROFILE_UBUNTU
-  vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
-#endif // DALI_PROFILE_UBUNTU
-
-  return fontSize;
 }
 
 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
@@ -112,81 +63,49 @@ ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::Reso
   return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
 }
 
-void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
+Integration::ResourcePointer TizenPlatformAbstraction::LoadImageSynchronously(const Integration::BitmapResourceType& resource, const std::string& resourcePath)
 {
-  if (mResourceLoader)
-  {
-    mResourceLoader->LoadResource(request);
-  }
+  return ImageLoader::LoadImageSynchronously( resource, resourcePath );
 }
 
-Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
+Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::BitmapResourceType& resource, uint8_t * buffer, size_t size )
 {
-  return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
-}
+  Integration::BitmapPtr resultBitmap;
+  Dali::Devel::PixelBuffer bitmap;
 
-Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
-{
-  Integration::BitmapPtr bitmap = 0;
-
-  Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
-  FILE * const fp = fileCloser.GetFile();
+  Dali::Internal::Platform::FileReader fileReader( buffer, size );
+  FILE * const fp = fileReader.GetFile();
   if( fp )
   {
-    bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
+    bool result = ImageLoader::ConvertStreamToBitmap( resource, "", fp, bitmap );
     if ( !result || !bitmap )
     {
       bitmap.Reset();
       DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
     }
-  }
-
-  return bitmap;
-}
-
-void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
-{
-  if (mResourceLoader)
-  {
-    mResourceLoader->CancelLoad(id, typeId);
-  }
-}
-
-void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
-{
-  if (mResourceLoader)
-  {
-    mResourceLoader->GetResources(cache);
-  }
-}
+    else
+    {
+      Integration::Bitmap::Profile profile{Integration::Bitmap::Profile::BITMAP_2D_PACKED_PIXELS};
 
-bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
-{
-  bool result = false;
+      // For backward compatibility the Bitmap must be created
+      auto retval = Integration::Bitmap::New(profile, Dali::ResourcePolicy::OWNED_DISCARD);
 
-  if( mResourceLoader )
-  {
-    result = mResourceLoader->LoadFile( filename, buffer );
-  }
+      retval->GetPackedPixelsProfile()->ReserveBuffer(
+              bitmap.GetPixelFormat(),
+              bitmap.GetWidth(),
+              bitmap.GetHeight(),
+              bitmap.GetWidth(),
+              bitmap.GetHeight()
+            );
 
-  return result;
-}
+      auto& impl = Dali::GetImplementation(bitmap);
 
-std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
-{
-  std::string result;
-  if (mResourceLoader)
-  {
-    result = mResourceLoader->LoadFile(filename);
+      std::copy( impl.GetBuffer(), impl.GetBuffer()+impl.GetBufferSize(), retval->GetBuffer());
+      resultBitmap.Reset(retval);
+    }
   }
 
-  return result;
-}
-
-void TizenPlatformAbstraction::JoinLoaderThreads()
-{
-  delete mResourceLoader;
-  mResourceLoader = NULL;
+  return resultBitmap;
 }
 
 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
@@ -197,12 +116,9 @@ bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename
   std::string path;
 
   // First check the system location where shaders are stored at install time:
-  if( mResourceLoader )
-  {
-    path = DALI_SHADERBIN_DIR;
-    path += filename;
-    result = mResourceLoader->LoadFile( path, buffer );
-  }
+  path = DALI_SHADERBIN_DIR;
+  path += filename;
+  result = LoadFile( path, buffer );
 
   // Fallback to the cache of shaders stored after previous runtime compilations:
   // On desktop this looks in the current working directory that the app was launched from.
@@ -210,7 +126,7 @@ bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename
   {
     path = mDataStoragePath;
     path += filename;
-    result = mResourceLoader->LoadFile( path, buffer );
+    result = LoadFile( path, buffer );
   }
 #endif
 
@@ -223,14 +139,12 @@ bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename
 
 #ifdef SHADERBIN_CACHE_ENABLED
 
-    // Fallback to the cache of shaders stored after previous runtime compilations:
-    // On desktop this looks in the current working directory that the app was launched from.
-    if( mResourceLoader )
-    {
-      std::string path = mDataStoragePath;
-      path += filename;
-      result = mResourceLoader->SaveFile( path, buffer, numBytes );
-    }
+  // Use the cache of shaders stored after previous runtime compilations:
+  // On desktop this looks in the current working directory that the app was launched from.
+  std::string path = mDataStoragePath;
+  path += filename;
+  result = SaveFile( path, buffer, numBytes );
+
 #endif
 
   return result;
@@ -241,6 +155,38 @@ void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
   mDataStoragePath = path;
 }
 
+TizenPlatformAbstraction* CreatePlatformAbstraction()
+{
+  return new TizenPlatformAbstraction();
+}
+
+bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes )
+{
+  DALI_ASSERT_DEBUG( 0 != filename.length());
+
+  bool result = false;
+
+  std::filebuf buf;
+  buf.open(filename.c_str(), std::ios::out | std::ios_base::trunc | std::ios::binary);
+  if( buf.is_open() )
+  {
+    std::ostream stream(&buf);
+
+    // determine size of buffer
+    int length = static_cast<int>(numBytes);
+
+    // write contents of buffer to the file
+    stream.write(reinterpret_cast<const char*>(buffer), length);
+
+    if( !stream.bad() )
+    {
+      result = true;
+    }
+  }
+
+  return result;
+}
+
 }  // namespace TizenPlatform
 
 }  // namespace Dali