/*
- * 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 "data-cache/metrics-cache.h"
#include "image-loaders/image-loader.h"
+#include "portable/file-closer.h"
namespace Dali
{
namespace TizenPlatform
{
-namespace
-{
-const std::string FONT_CONFIGURATION_FILE( FONT_CONFIGURATION_FILE_PATH ); ///< Default font configuration file
-const std::string DEFAULT_FONT_FAMILY( "HelveticaNeue" ); ///< Default font family when unable to retrieve from font configuration file
-const std::string DEFAULT_FONT_STYLE( "Book" ); ///< Default font style when unable to retrieve from font configuration file
-const std::string NULL_FONT_FAMILY_NAME( "" );
-const unsigned int NANOSECS_TO_MICROSECS( 1000 ); ///< 1000 nanoseconds = 1 microsecond
-
-/// Settings to float point conversion table
-const float FONT_SIZE_TABLE[5] =
-{
- 8.0f, ///< Small
- 10.0f, ///< Normal
- 15.0f, ///< Large
- 19.0f, ///< Huge
- 25.0f ///< Giant
-};
-}
-
TizenPlatformAbstraction::TizenPlatformAbstraction()
: mResourceLoader(new ResourceLoader),
- mDynamicsFactory(NULL),
- mDataStoragePath( "" ),
- mDefaultFontSize(FONT_SIZE_TABLE[1])
+ mDataStoragePath( "" )
{
- int error = FT_Init_FreeType(&mFreeTypeHandle);
- DALI_ASSERT_ALWAYS( error == 0 && "Freetype initialization failed" );
-
- UpdateDefaultsFromDevice();
}
TizenPlatformAbstraction::~TizenPlatformAbstraction()
{
delete mResourceLoader;
- delete mDynamicsFactory;
-
- if (mFreeTypeHandle)
- {
- FT_Done_FreeType(mFreeTypeHandle);
- }
-}
-
-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()
}
}
-const std::string& TizenPlatformAbstraction::GetDefaultFontFamily() const
-{
- // VCC TODO: return default font style as well.
- return mDefaultFontFamily;
-}
-
-float TizenPlatformAbstraction::GetDefaultFontSize() const
-{
- return mDefaultFontSize;
-}
-
-PixelSize TizenPlatformAbstraction::GetFontLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, CapsHeight capsHeight) const
+int TizenPlatformAbstraction::GetDefaultFontSize() const
{
- PixelSize result(0);
+ int fontSize( -1 );
- if (mResourceLoader)
- {
- result = mResourceLoader->GetFontLineHeightFromCapsHeight(fontFamily, fontStyle, capsHeight, mFreeTypeHandle);
- }
-
- return result;
-}
-
-Integration::GlyphSet* TizenPlatformAbstraction::GetGlyphData ( const Dali::Integration::TextResourceType& textRequest,
- const std::string& fontFamily,
- bool getBitmap) const
-{
- if (mResourceLoader)
- {
- return mResourceLoader->GetGlyphData(textRequest,
- mFreeTypeHandle,
- fontFamily,
- getBitmap);
- }
- return NULL;
-}
+#ifndef DALI_PROFILE_UBUNTU
+ vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
+#endif // DALI_PROFILE_UBUNTU
-Integration::GlyphSet* TizenPlatformAbstraction::GetCachedGlyphData( const Integration::TextResourceType& textRequest,
- const std::string& fontFamily ) const
-{
- if (mResourceLoader)
- {
- return mResourceLoader->GetCachedGlyphData( textRequest, fontFamily );
- }
- return NULL;
+ return fontSize;
}
-
-void TizenPlatformAbstraction::GetGlobalMetrics( const std::string& fontFamily, const std::string& fontStyle, Integration::GlobalMetrics& globalMetrics ) const
+ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- if( mResourceLoader )
- {
- mResourceLoader->GetGlobalMetrics( mFreeTypeHandle,
- fontFamily,
- fontStyle,
- globalMetrics );
- }
+ return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
}
-void TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2& closestSize )
+ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- closestSize = Vector2::ZERO;
- ImageLoader::GetClosestImageSize(filename, attributes, closestSize );
+ return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
}
-void TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2& closestSize )
-{
- closestSize = Vector2::ZERO;
- ImageLoader::GetClosestImageSize(resourceBuffer, attributes, closestSize );
-}
-
-
void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
{
if (mResourceLoader)
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)
}
}
-bool TizenPlatformAbstraction::IsLoading()
-{
- if (mResourceLoader)
- {
- return mResourceLoader->IsLoading();
- }
-
- return false;
-}
-
void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
{
if (mResourceLoader)
}
}
-void TizenPlatformAbstraction::SetDpi(unsigned int dpiHor, unsigned int dpiVer)
-{
- if (mResourceLoader)
- {
- mResourceLoader->SetDpi(dpiHor, dpiVer);
- }
-}
-
-const std::string& TizenPlatformAbstraction::GetFontFamilyForChars(const Integration::TextArray& charsRequested) const
-{
- if( mResourceLoader )
- {
- return mResourceLoader->GetFontFamilyForChars(charsRequested);
- }
-
- return NULL_FONT_FAMILY_NAME;
-}
-
-bool TizenPlatformAbstraction::AllGlyphsSupported(const std::string &fontFamily, const std::string& fontStyle, const Integration::TextArray& charsRequested) const
-{
- bool ret = false;
- if (mResourceLoader)
- {
- ret = mResourceLoader->AllGlyphsSupported(fontFamily, fontStyle, charsRequested);
- }
- return ret;
-}
-
-bool TizenPlatformAbstraction::ValidateFontFamilyName(const std::string& fontFamily, const std::string& fontStyle, bool& isDefaultSystemFont, std::string& closestMatch, std::string& closestStyleMatch) const
-{
- bool ret = false;
- if( mResourceLoader )
- {
- // TODO: Consider retrieve both isDefaultSystemFontFamily and isDefaultSystemFontStyle.
- bool isDefaultFamily = false;
- bool isDefaultStyle = false;
- ret = mResourceLoader->ValidateFontFamilyName( fontFamily, fontStyle, isDefaultFamily, isDefaultStyle, closestMatch, closestStyleMatch );
- isDefaultSystemFont = isDefaultFamily && isDefaultStyle;
- }
- return ret;
-}
-
-void TizenPlatformAbstraction::GetFontList( Dali::Integration::PlatformAbstraction::FontListMode mode, std::vector<std::string>& fontList ) const
-{
- if( mResourceLoader )
- {
- mResourceLoader->GetFontList( mode, fontList );
- }
-}
-
-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;
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;
}
-void TizenPlatformAbstraction::UpdateDefaultsFromDevice()
-{
- // FontConfigurationParser::Parse sets the default font family and the default font style.
- // If the isn't a configuration file or is invalid, or it doesn't have any tag with the default
- // font family nor font style then default values set by the application are used.
- mDefaultFontFamily = DEFAULT_FONT_FAMILY;
- mDefaultFontStyle = DEFAULT_FONT_STYLE;
-
- // The initialized values above are not used to parse the configuration file. These values
- // are set just in case FontConfigurationParser::Parse is not able to set default values.
- FontConfigurationParser::Parse(FONT_CONFIGURATION_FILE, mDefaultFontFamily, mDefaultFontStyle);
-
- if ( mResourceLoader )
- {
- mResourceLoader->SetDefaultFontFamily( mDefaultFontFamily, mDefaultFontStyle );
- }
-
- int fontSize(0);
-#ifndef DALI_PROFILE_UBUNTU
- vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
-#endif // DALI_PROFILE_UBUNTU
- mDefaultFontSize = FONT_SIZE_TABLE[fontSize];
-}
-
-Integration::DynamicsFactory* TizenPlatformAbstraction::GetDynamicsFactory()
-{
- if( NULL == mDynamicsFactory )
- {
- mDynamicsFactory = new DynamicsFactory;
- }
-
- return mDynamicsFactory;
-}
-
-bool TizenPlatformAbstraction::ReadGlobalMetricsFromCache( const std::string& fontFamily,
- const std::string& fontStyle,
- Integration::GlobalMetrics& globalMetrics )
-{
- return MetricsCache::ReadGlobal( fontFamily, fontStyle, globalMetrics );
-}
-
-void TizenPlatformAbstraction::WriteGlobalMetricsToCache( const std::string& fontFamily,
- const std::string& fontStyle,
- const Integration::GlobalMetrics& globalMetrics )
-{
- MetricsCache::WriteGlobal( fontFamily, fontStyle, globalMetrics);
-}
-
-bool TizenPlatformAbstraction::ReadMetricsFromCache( const std::string& fontFamily,
- const std::string& fontStyle,
- std::vector<Integration::GlyphMetrics>& glyphMetricsContainer )
-{
- return MetricsCache::Read( fontFamily, fontStyle, glyphMetricsContainer );
-}
-
-void TizenPlatformAbstraction::WriteMetricsToCache( const std::string& fontFamily,
- const std::string& fontStyle,
- const Integration::GlyphSet& glyphSet )
-{
- MetricsCache::Write( fontFamily, fontStyle, glyphSet );
-}
-
-void TizenPlatformAbstraction::GetFileNamesFromDirectory( const std::string& directoryName,
- std::vector<std::string>& fileNames )
-{
- dirent* de = NULL;
- DIR* dp;
- dp = opendir( directoryName.c_str() );
- if( dp )
- {
- const std::string dot( "." );
- const std::string dotDot( ".." );
- while( true )
- {
- de = readdir( dp );
- if( de == NULL )
- {
- break;
- }
- const std::string fileName( de->d_name );
- if( ( fileName != dot ) &&
- ( fileName != dotDot ) )
- {
- fileNames.push_back( fileName );
- }
- }
- closedir( dp );
- }
-}
-
-Integration::BitmapPtr TizenPlatformAbstraction::GetGlyphImage( const std::string& fontFamily, const std::string& fontStyle, const float fontSize, const uint32_t character ) const
-{
- Integration::BitmapPtr glyphImage;
-
- if( mResourceLoader )
- {
- glyphImage = mResourceLoader->GetGlyphImage( mFreeTypeHandle, fontFamily, fontStyle, fontSize, character );
- }
-
- return glyphImage;
-}
-
-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;
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;
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;