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 unsigned int NANOSECS_TO_MICROSECS( 1000 ); ///< 1000 nanoseconds = 1 microsecond
52 TizenPlatformAbstraction::TizenPlatformAbstraction()
53 : mResourceLoader(new ResourceLoader),
54 mDataStoragePath( "" )
58 TizenPlatformAbstraction::~TizenPlatformAbstraction()
60 delete mResourceLoader;
63 void TizenPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds)
66 clock_gettime(CLOCK_MONOTONIC, &time);
67 seconds = time.tv_sec;
68 microSeconds = time.tv_nsec / NANOSECS_TO_MICROSECS;
71 void TizenPlatformAbstraction::Suspend()
75 mResourceLoader->Pause();
79 void TizenPlatformAbstraction::Resume()
83 mResourceLoader->Resume();
87 void TizenPlatformAbstraction::GetDefaultFontDescription( std::string& fontFamily, std::string& fontStyle ) const
89 FontConfigurationParser::Parse(FONT_CONFIGURATION_FILE, fontFamily, fontStyle);
92 int TizenPlatformAbstraction::GetDefaultFontSize() const
96 #ifndef DALI_PROFILE_UBUNTU
97 vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
98 #endif // DALI_PROFILE_UBUNTU
103 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
104 ImageDimensions size,
105 FittingMode::Type fittingMode,
106 SamplingMode::Type samplingMode,
107 bool orientationCorrection )
109 return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
112 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
113 ImageDimensions size,
114 FittingMode::Type fittingMode,
115 SamplingMode::Type samplingMode,
116 bool orientationCorrection )
118 return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
121 void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
125 mResourceLoader->LoadResource(request);
129 Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
131 return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
134 Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
136 Integration::BitmapPtr bitmap = 0;
138 Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
139 FILE * const fp = fileCloser.GetFile();
142 bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
143 if ( !result || !bitmap )
146 DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
153 void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
157 mResourceLoader->CancelLoad(id, typeId);
161 void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
165 mResourceLoader->GetResources(cache);
169 bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
173 if( mResourceLoader )
175 result = mResourceLoader->LoadFile( filename, buffer );
181 std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
186 result = mResourceLoader->LoadFile(filename);
192 void TizenPlatformAbstraction::JoinLoaderThreads()
194 delete mResourceLoader;
195 mResourceLoader = NULL;
198 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
202 #ifdef SHADERBIN_CACHE_ENABLED
205 // First check the system location where shaders are stored at install time:
206 if( mResourceLoader )
208 path = DALI_SHADERBIN_DIR;
210 result = mResourceLoader->LoadFile( path, buffer );
213 // Fallback to the cache of shaders stored after previous runtime compilations:
214 // On desktop this looks in the current working directory that the app was launched from.
215 if( mResourceLoader && result == false )
217 path = mDataStoragePath;
219 result = mResourceLoader->LoadFile( path, buffer );
226 bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
230 #ifdef SHADERBIN_CACHE_ENABLED
232 // Fallback to the cache of shaders stored after previous runtime compilations:
233 // On desktop this looks in the current working directory that the app was launched from.
234 if( mResourceLoader )
236 std::string path = mDataStoragePath;
238 result = mResourceLoader->SaveFile( path, buffer, numBytes );
245 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
247 mDataStoragePath = path;
250 } // namespace TizenPlatform