2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "tizen-platform-abstraction.h"
20 #ifndef DALI_PROFILE_UBUNTU
22 #endif // DALI_PROFILE_UBUNTU
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/bitmap.h>
27 #include <dali/integration-api/resource-types.h>
30 #include "resource-loader/resource-loader.h"
31 #include "tizen-font-configuration-parser.h"
32 #include "image-loaders/image-loader.h"
33 #include "portable/file-closer.h"
38 Integration::PlatformAbstraction* CreatePlatformAbstraction()
40 return new TizenPlatform::TizenPlatformAbstraction();
44 namespace TizenPlatform
49 const std::string FONT_CONFIGURATION_FILE( FONT_CONFIGURATION_FILE_PATH ); ///< Default font configuration file
50 const unsigned int NANOSECS_TO_MICROSECS( 1000 ); ///< 1000 nanoseconds = 1 microsecond
53 TizenPlatformAbstraction::TizenPlatformAbstraction()
54 : mResourceLoader(new ResourceLoader),
55 mDataStoragePath( "" )
59 TizenPlatformAbstraction::~TizenPlatformAbstraction()
61 delete mResourceLoader;
64 void TizenPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds)
67 clock_gettime(CLOCK_MONOTONIC, &time);
68 seconds = time.tv_sec;
69 microSeconds = time.tv_nsec / NANOSECS_TO_MICROSECS;
72 void TizenPlatformAbstraction::Suspend()
76 mResourceLoader->Pause();
80 void TizenPlatformAbstraction::Resume()
84 mResourceLoader->Resume();
88 void TizenPlatformAbstraction::GetDefaultFontDescription( std::string& fontFamily, std::string& fontStyle ) const
90 FontConfigurationParser::Parse(FONT_CONFIGURATION_FILE, fontFamily, fontStyle);
93 int TizenPlatformAbstraction::GetDefaultFontSize() const
97 #ifndef DALI_PROFILE_UBUNTU
98 vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
99 #endif // DALI_PROFILE_UBUNTU
104 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
105 ImageDimensions size,
106 FittingMode::Type fittingMode,
107 SamplingMode::Type samplingMode,
108 bool orientationCorrection )
110 return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
113 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
114 ImageDimensions size,
115 FittingMode::Type fittingMode,
116 SamplingMode::Type samplingMode,
117 bool orientationCorrection )
119 return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
122 void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
126 mResourceLoader->LoadResource(request);
130 Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
132 return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
135 Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
137 Integration::BitmapPtr bitmap = 0;
139 Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
140 FILE * const fp = fileCloser.GetFile();
143 bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
144 if ( !result || !bitmap )
147 DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
154 void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
158 mResourceLoader->CancelLoad(id, typeId);
162 void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
166 mResourceLoader->GetResources(cache);
170 bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
174 if( mResourceLoader )
176 result = mResourceLoader->LoadFile( filename, buffer );
182 std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
187 result = mResourceLoader->LoadFile(filename);
193 void TizenPlatformAbstraction::JoinLoaderThreads()
195 delete mResourceLoader;
196 mResourceLoader = NULL;
199 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
203 #ifdef SHADERBIN_CACHE_ENABLED
206 // First check the system location where shaders are stored at install time:
207 if( mResourceLoader )
209 path = DALI_SHADERBIN_DIR;
211 result = mResourceLoader->LoadFile( path, buffer );
214 // Fallback to the cache of shaders stored after previous runtime compilations:
215 // On desktop this looks in the current working directory that the app was launched from.
216 if( mResourceLoader && result == false )
218 path = mDataStoragePath;
220 result = mResourceLoader->LoadFile( path, buffer );
227 bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
231 #ifdef SHADERBIN_CACHE_ENABLED
233 // Fallback to the cache of shaders stored after previous runtime compilations:
234 // On desktop this looks in the current working directory that the app was launched from.
235 if( mResourceLoader )
237 std::string path = mDataStoragePath;
239 result = mResourceLoader->SaveFile( path, buffer, numBytes );
246 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
248 mDataStoragePath = path;
251 } // namespace TizenPlatform