2 * Copyright (c) 2014 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>
29 #include "resource-loader/resource-loader.h"
30 #include "dynamics/dynamics-factory.h"
32 #include "tizen-font-configuration-parser.h"
33 #include "image-loaders/image-loader.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 mDynamicsFactory(NULL),
56 mDataStoragePath( "" )
60 TizenPlatformAbstraction::~TizenPlatformAbstraction()
62 delete mResourceLoader;
63 delete mDynamicsFactory;
66 void TizenPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds)
69 clock_gettime(CLOCK_MONOTONIC, &time);
70 seconds = time.tv_sec;
71 microSeconds = time.tv_nsec / NANOSECS_TO_MICROSECS;
74 void TizenPlatformAbstraction::Suspend()
78 mResourceLoader->Pause();
82 void TizenPlatformAbstraction::Resume()
86 mResourceLoader->Resume();
90 void TizenPlatformAbstraction::GetDefaultFontDescription( std::string& fontFamily, std::string& fontStyle ) const
92 FontConfigurationParser::Parse(FONT_CONFIGURATION_FILE, fontFamily, fontStyle);
95 int TizenPlatformAbstraction::GetDefaultFontSize() const
99 #ifndef DALI_PROFILE_UBUNTU
100 vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
101 #endif // DALI_PROFILE_UBUNTU
106 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
107 ImageDimensions size,
108 FittingMode::Type fittingMode,
109 SamplingMode::Type samplingMode,
110 bool orientationCorrection )
112 return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
115 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
116 ImageDimensions size,
117 FittingMode::Type fittingMode,
118 SamplingMode::Type samplingMode,
119 bool orientationCorrection )
121 return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
124 void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
128 mResourceLoader->LoadResource(request);
132 Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
134 return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
138 void TizenPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request)
142 if( request.GetType()->id == Integration::ResourceShader )
144 #ifdef SHADERBIN_CACHE_ENABLED
145 std::string path = mDataStoragePath;
146 path += request.GetPath();
148 Integration::ResourceRequest newRequest( request.GetId(), *request.GetType(), path, request.GetResource() );
149 mResourceLoader->SaveResource(newRequest);
154 mResourceLoader->SaveResource(request);
159 void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
163 mResourceLoader->CancelLoad(id, typeId);
167 bool TizenPlatformAbstraction::IsLoading()
171 return mResourceLoader->IsLoading();
177 void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
181 mResourceLoader->GetResources(cache);
185 void TizenPlatformAbstraction::SetDpi(unsigned int dpiHor, unsigned int dpiVer)
189 mResourceLoader->SetDpi(dpiHor, dpiVer);
193 bool TizenPlatformAbstraction::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
199 result = mResourceLoader->LoadFile(filename, buffer);
205 std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
210 result = mResourceLoader->LoadFile(filename);
216 bool TizenPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const
222 result = mResourceLoader->SaveFile(filename, buffer);
228 void TizenPlatformAbstraction::JoinLoaderThreads()
230 delete mResourceLoader;
231 mResourceLoader = NULL;
234 Integration::DynamicsFactory* TizenPlatformAbstraction::GetDynamicsFactory()
236 if( NULL == mDynamicsFactory )
238 mDynamicsFactory = new DynamicsFactory;
241 return mDynamicsFactory;
244 bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
248 #ifdef SHADERBIN_CACHE_ENABLED
251 if( mResourceLoader )
253 path = DALI_SHADERBIN_DIR;
255 result = mResourceLoader->LoadFile( path, buffer );
258 if( mResourceLoader && result == false )
260 path = mDataStoragePath;
262 result = mResourceLoader->LoadFile( path, buffer );
269 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
271 mDataStoragePath = path;
274 } // namespace TizenPlatform