/*
- * Copyright (c) 2014 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>
-#include "resource-loader/resource-loader.h"
-#include "dynamics/dynamics-factory.h"
-
-#include "tizen-font-configuration-parser.h"
+// INTERNAL INCLUDES
#include "image-loaders/image-loader.h"
+#include "portable/file-closer.h"
namespace Dali
{
-Integration::PlatformAbstraction* CreatePlatformAbstraction()
-{
- return new TizenPlatform::TizenPlatformAbstraction();
-}
-
-
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( "" )
+: mDataStoragePath( "" )
{
}
TizenPlatformAbstraction::~TizenPlatformAbstraction()
{
- delete mResourceLoader;
- delete mDynamicsFactory;
-}
-
-void TizenPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds)
-{
- 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();
- }
-}
-
-void TizenPlatformAbstraction::GetDefaultFontDescription( std::string& fontFamily, std::string& fontStyle ) const
-{
- FontConfigurationParser::Parse(FONT_CONFIGURATION_FILE, fontFamily, fontStyle);
-}
-
-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,
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 bitmap = 0;
-
-void TizenPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request)
-{
- if (mResourceLoader)
+ Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
+ FILE * const fp = fileCloser.GetFile();
+ if( fp )
{
- if( request.GetType()->id == Integration::ResourceShader )
+ bool result = ImageLoader::ConvertStreamToBitmap( resource, "", fp, bitmap );
+ if ( !result || !bitmap )
{
-#ifdef SHADERBIN_CACHE_ENABLED
- std::string path = mDataStoragePath;
- path += request.GetPath();
-
- Integration::ResourceRequest newRequest( request.GetId(), *request.GetType(), path, request.GetResource() );
- mResourceLoader->SaveResource(newRequest);
-#endif
+ bitmap.Reset();
+ DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
}
- else
- {
- mResourceLoader->SaveResource(request);
- }
- }
-}
-
-void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
-{
- if (mResourceLoader)
- {
- mResourceLoader->CancelLoad(id, typeId);
- }
-}
-
-bool TizenPlatformAbstraction::IsLoading()
-{
- if (mResourceLoader)
- {
- return mResourceLoader->IsLoading();
- }
-
- return false;
-}
-
-void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
-{
- if (mResourceLoader)
- {
- mResourceLoader->GetResources(cache);
}
-}
-void TizenPlatformAbstraction::SetDpi(unsigned int dpiHor, unsigned int dpiVer)
-{
- if (mResourceLoader)
- {
- mResourceLoader->SetDpi(dpiHor, dpiVer);
- }
+ return bitmap;
}
-bool TizenPlatformAbstraction::LoadFile( 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;
- if (mResourceLoader)
- {
- result = mResourceLoader->LoadFile(filename, buffer);
- }
+#ifdef SHADERBIN_CACHE_ENABLED
+ std::string path;
- return result;
-}
+ // First check the system location where shaders are stored at install time:
+ path = DALI_SHADERBIN_DIR;
+ path += filename;
+ result = LoadFile( path, buffer );
-std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
-{
- std::string result;
- if (mResourceLoader)
+ // 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 )
{
- result = mResourceLoader->LoadFile(filename);
+ path = mDataStoragePath;
+ path += filename;
+ result = LoadFile( path, buffer );
}
+#endif
return result;
}
-bool TizenPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const
+bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
{
bool result = false;
- if (mResourceLoader)
- {
- result = mResourceLoader->SaveFile(filename, buffer);
- }
+#ifdef SHADERBIN_CACHE_ENABLED
+
+ // 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;
}
-void TizenPlatformAbstraction::JoinLoaderThreads()
+void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
{
- delete mResourceLoader;
- mResourceLoader = NULL;
+ mDataStoragePath = path;
}
-Integration::DynamicsFactory* TizenPlatformAbstraction::GetDynamicsFactory()
+TizenPlatformAbstraction* CreatePlatformAbstraction()
{
- if( NULL == mDynamicsFactory )
- {
- mDynamicsFactory = new DynamicsFactory;
- }
-
- return mDynamicsFactory;
+ return new TizenPlatformAbstraction();
}
-bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
+bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes )
{
- bool result = false;
+ DALI_ASSERT_DEBUG( 0 != filename.length());
-#ifdef SHADERBIN_CACHE_ENABLED
- std::string path;
+ bool result = false;
- if( mResourceLoader )
+ std::filebuf buf;
+ buf.open(filename.c_str(), std::ios::out | std::ios_base::trunc | std::ios::binary);
+ if( buf.is_open() )
{
- path = DALI_SHADERBIN_DIR;
- path += filename;
- result = mResourceLoader->LoadFile( path, buffer );
- }
+ std::ostream stream(&buf);
- if( mResourceLoader && result == false )
- {
- path = mDataStoragePath;
- path += filename;
- result = mResourceLoader->LoadFile( path, buffer );
+ // 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;
+ }
}
-#endif
return result;
}
-void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
-{
- mDataStoragePath = path;
-}
-
} // namespace TizenPlatform
} // namespace Dali