[3.0] Add DALI_IMPORT_API for reference
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / tizen / tizen-platform-abstraction.cpp
index f99c7c5..338f5da 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
 #include <dali/integration-api/bitmap.h>
 #include <dali/integration-api/resource-types.h>
 
+// INTERNAL INCLUDES
 #include "resource-loader/resource-loader.h"
-#include "dynamics/dynamics-factory.h"
-
-#include "tizen-font-configuration-parser.h"
 #include "image-loaders/image-loader.h"
+#include "portable/file-closer.h"
 
 namespace Dali
 {
@@ -44,15 +43,8 @@ Integration::PlatformAbstraction* CreatePlatformAbstraction()
 namespace TizenPlatform
 {
 
-namespace
-{
-const std::string FONT_CONFIGURATION_FILE( FONT_CONFIGURATION_FILE_PATH ); ///< Default font configuration file
-const unsigned int NANOSECS_TO_MICROSECS( 1000 );                          ///< 1000 nanoseconds = 1 microsecond
-}
-
 TizenPlatformAbstraction::TizenPlatformAbstraction()
 : mResourceLoader(new ResourceLoader),
-  mDynamicsFactory(NULL),
   mDataStoragePath( "" )
 {
 }
@@ -60,15 +52,6 @@ TizenPlatformAbstraction::TizenPlatformAbstraction()
 TizenPlatformAbstraction::~TizenPlatformAbstraction()
 {
   delete mResourceLoader;
-  delete mDynamicsFactory;
-}
-
-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()
@@ -87,11 +70,6 @@ void TizenPlatformAbstraction::Resume()
   }
 }
 
-void TizenPlatformAbstraction::GetDefaultFontDescription( std::string& fontFamily, std::string& fontStyle ) const
-{
-  FontConfigurationParser::Parse(FONT_CONFIGURATION_FILE, fontFamily, fontStyle);
-}
-
 int TizenPlatformAbstraction::GetDefaultFontSize() const
 {
   int fontSize( -1 );
@@ -134,26 +112,23 @@ Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously
   return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
 }
 
-
-void TizenPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request)
+Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
 {
-  if (mResourceLoader)
-  {
-    if( request.GetType()->id == Integration::ResourceShader )
-    {
-#ifdef SHADERBIN_CACHE_ENABLED
-      std::string path = mDataStoragePath;
-      path += request.GetPath();
+  Integration::BitmapPtr bitmap = 0;
 
-      Integration::ResourceRequest newRequest( request.GetId(), *request.GetType(), path, request.GetResource() );
-      mResourceLoader->SaveResource(newRequest);
-#endif
-    }
-    else
+  Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
+  FILE * const fp = fileCloser.GetFile();
+  if( fp )
+  {
+    bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
+    if ( !result || !bitmap )
     {
-      mResourceLoader->SaveResource(request);
+      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)
@@ -164,16 +139,6 @@ void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integratio
   }
 }
 
-bool TizenPlatformAbstraction::IsLoading()
-{
-  if (mResourceLoader)
-  {
-    return mResourceLoader->IsLoading();
-  }
-
-  return false;
-}
-
 void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
 {
   if (mResourceLoader)
@@ -182,21 +147,13 @@ void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
   }
 }
 
-void TizenPlatformAbstraction::SetDpi(unsigned int dpiHor, unsigned int dpiVer)
-{
-  if (mResourceLoader)
-  {
-    mResourceLoader->SetDpi(dpiHor, dpiVer);
-  }
-}
-
-bool TizenPlatformAbstraction::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
+bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
 {
   bool result = false;
 
-  if (mResourceLoader)
+  if( mResourceLoader )
   {
-    result = mResourceLoader->LoadFile(filename, buffer);
+    result = mResourceLoader->LoadFile( filename, buffer );
   }
 
   return result;
@@ -213,41 +170,20 @@ std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
   return result;
 }
 
-bool TizenPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const
-{
-  bool result = false;
-
-  if (mResourceLoader)
-  {
-    result = mResourceLoader->SaveFile(filename, buffer);
-  }
-
-  return result;
-}
-
 void TizenPlatformAbstraction::JoinLoaderThreads()
 {
   delete mResourceLoader;
   mResourceLoader = NULL;
 }
 
-Integration::DynamicsFactory* TizenPlatformAbstraction::GetDynamicsFactory()
-{
-  if( NULL == mDynamicsFactory )
-  {
-    mDynamicsFactory = new DynamicsFactory;
-  }
-
-  return mDynamicsFactory;
-}
-
-bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
+bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
 {
   bool result = false;
 
 #ifdef SHADERBIN_CACHE_ENABLED
   std::string path;
 
+  // First check the system location where shaders are stored at install time:
   if( mResourceLoader )
   {
     path = DALI_SHADERBIN_DIR;
@@ -255,6 +191,8 @@ bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, s
     result = mResourceLoader->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.
   if( mResourceLoader && result == false )
   {
     path = mDataStoragePath;
@@ -266,6 +204,25 @@ bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, s
   return result;
 }
 
+bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
+{
+  bool result = false;
+
+#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 );
+    }
+#endif
+
+  return result;
+}
+
 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
 {
   mDataStoragePath = path;