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 "image-loaders/image-loader.h"
32 #include "portable/file-closer.h"
37 Integration::PlatformAbstraction* CreatePlatformAbstraction()
39 return new TizenPlatform::TizenPlatformAbstraction();
43 namespace TizenPlatform
48 const unsigned int NANOSECS_TO_MICROSECS( 1000 ); ///< 1000 nanoseconds = 1 microsecond
51 TizenPlatformAbstraction::TizenPlatformAbstraction()
52 : mResourceLoader(new ResourceLoader),
53 mDataStoragePath( "" )
57 TizenPlatformAbstraction::~TizenPlatformAbstraction()
59 delete mResourceLoader;
62 void TizenPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds)
65 clock_gettime(CLOCK_MONOTONIC, &time);
66 seconds = time.tv_sec;
67 microSeconds = time.tv_nsec / NANOSECS_TO_MICROSECS;
70 void TizenPlatformAbstraction::Suspend()
74 mResourceLoader->Pause();
78 void TizenPlatformAbstraction::Resume()
82 mResourceLoader->Resume();
86 int TizenPlatformAbstraction::GetDefaultFontSize() const
90 #ifndef DALI_PROFILE_UBUNTU
91 vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
92 #endif // DALI_PROFILE_UBUNTU
97 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
99 FittingMode::Type fittingMode,
100 SamplingMode::Type samplingMode,
101 bool orientationCorrection )
103 return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
106 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
107 ImageDimensions size,
108 FittingMode::Type fittingMode,
109 SamplingMode::Type samplingMode,
110 bool orientationCorrection )
112 return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
115 void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
119 mResourceLoader->LoadResource(request);
123 Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
125 return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
128 Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
130 Integration::BitmapPtr bitmap = 0;
132 Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
133 FILE * const fp = fileCloser.GetFile();
136 bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
137 if ( !result || !bitmap )
140 DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
147 void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
151 mResourceLoader->CancelLoad(id, typeId);
155 void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
159 mResourceLoader->GetResources(cache);
163 bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
167 if( mResourceLoader )
169 result = mResourceLoader->LoadFile( filename, buffer );
175 std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
180 result = mResourceLoader->LoadFile(filename);
186 void TizenPlatformAbstraction::JoinLoaderThreads()
188 delete mResourceLoader;
189 mResourceLoader = NULL;
192 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
196 #ifdef SHADERBIN_CACHE_ENABLED
199 // First check the system location where shaders are stored at install time:
200 if( mResourceLoader )
202 path = DALI_SHADERBIN_DIR;
204 result = mResourceLoader->LoadFile( path, buffer );
207 // Fallback to the cache of shaders stored after previous runtime compilations:
208 // On desktop this looks in the current working directory that the app was launched from.
209 if( mResourceLoader && result == false )
211 path = mDataStoragePath;
213 result = mResourceLoader->LoadFile( path, buffer );
220 bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
224 #ifdef SHADERBIN_CACHE_ENABLED
226 // Fallback to the cache of shaders stored after previous runtime compilations:
227 // On desktop this looks in the current working directory that the app was launched from.
228 if( mResourceLoader )
230 std::string path = mDataStoragePath;
232 result = mResourceLoader->SaveFile( path, buffer, numBytes );
239 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
241 mDataStoragePath = path;
244 } // namespace TizenPlatform