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 void TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
107 const ImageAttributes& attributes,
108 Vector2& closestSize )
110 closestSize = Vector2::ZERO;
111 ImageLoader::GetClosestImageSize(filename, attributes, closestSize );
114 void TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
115 const ImageAttributes& attributes,
116 Vector2& closestSize )
118 closestSize = Vector2::ZERO;
119 ImageLoader::GetClosestImageSize(resourceBuffer, attributes, closestSize );
123 void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
127 mResourceLoader->LoadResource(request);
131 Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
133 return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
137 void TizenPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request)
141 if( request.GetType()->id == Integration::ResourceShader )
143 #ifdef SHADERBIN_CACHE_ENABLED
144 std::string path = mDataStoragePath;
145 path += request.GetPath();
147 Integration::ResourceRequest newRequest( request.GetId(), *request.GetType(), path, request.GetResource() );
148 mResourceLoader->SaveResource(newRequest);
153 mResourceLoader->SaveResource(request);
158 void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
162 mResourceLoader->CancelLoad(id, typeId);
166 bool TizenPlatformAbstraction::IsLoading()
170 return mResourceLoader->IsLoading();
176 void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
180 mResourceLoader->GetResources(cache);
184 void TizenPlatformAbstraction::SetDpi(unsigned int dpiHor, unsigned int dpiVer)
188 mResourceLoader->SetDpi(dpiHor, dpiVer);
192 bool TizenPlatformAbstraction::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
198 result = mResourceLoader->LoadFile(filename, buffer);
204 std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
209 result = mResourceLoader->LoadFile(filename);
215 bool TizenPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const
221 result = mResourceLoader->SaveFile(filename, buffer);
227 void TizenPlatformAbstraction::JoinLoaderThreads()
229 delete mResourceLoader;
230 mResourceLoader = NULL;
233 Integration::DynamicsFactory* TizenPlatformAbstraction::GetDynamicsFactory()
235 if( NULL == mDynamicsFactory )
237 mDynamicsFactory = new DynamicsFactory;
240 return mDynamicsFactory;
243 bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
247 #ifdef SHADERBIN_CACHE_ENABLED
250 if( mResourceLoader )
252 path = DALI_SHADERBIN_DIR;
254 result = mResourceLoader->LoadFile( path, buffer );
257 if( mResourceLoader && result == false )
259 path = mDataStoragePath;
261 result = mResourceLoader->LoadFile( path, buffer );
268 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
270 mDataStoragePath = path;
273 } // namespace TizenPlatform