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
46 TizenPlatformAbstraction::TizenPlatformAbstraction()
47 : mResourceLoader(new ResourceLoader),
48 mDataStoragePath( "" )
52 TizenPlatformAbstraction::~TizenPlatformAbstraction()
54 delete mResourceLoader;
57 void TizenPlatformAbstraction::Suspend()
61 mResourceLoader->Pause();
65 void TizenPlatformAbstraction::Resume()
69 mResourceLoader->Resume();
73 int TizenPlatformAbstraction::GetDefaultFontSize() const
77 #ifndef DALI_PROFILE_UBUNTU
78 vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
79 #endif // DALI_PROFILE_UBUNTU
84 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
86 FittingMode::Type fittingMode,
87 SamplingMode::Type samplingMode,
88 bool orientationCorrection )
90 return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
93 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
95 FittingMode::Type fittingMode,
96 SamplingMode::Type samplingMode,
97 bool orientationCorrection )
99 return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
102 void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
106 mResourceLoader->LoadResource(request);
110 Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
112 return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
115 Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
117 Integration::BitmapPtr bitmap = 0;
119 Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
120 FILE * const fp = fileCloser.GetFile();
123 bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
124 if ( !result || !bitmap )
127 DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
134 void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
138 mResourceLoader->CancelLoad(id, typeId);
142 void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
146 mResourceLoader->GetResources(cache);
150 bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
154 if( mResourceLoader )
156 result = mResourceLoader->LoadFile( filename, buffer );
162 std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
167 result = mResourceLoader->LoadFile(filename);
173 void TizenPlatformAbstraction::JoinLoaderThreads()
175 delete mResourceLoader;
176 mResourceLoader = NULL;
179 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
183 #ifdef SHADERBIN_CACHE_ENABLED
186 // First check the system location where shaders are stored at install time:
187 if( mResourceLoader )
189 path = DALI_SHADERBIN_DIR;
191 result = mResourceLoader->LoadFile( path, buffer );
194 // Fallback to the cache of shaders stored after previous runtime compilations:
195 // On desktop this looks in the current working directory that the app was launched from.
196 if( mResourceLoader && result == false )
198 path = mDataStoragePath;
200 result = mResourceLoader->LoadFile( path, buffer );
207 bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
211 #ifdef SHADERBIN_CACHE_ENABLED
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 )
217 std::string path = mDataStoragePath;
219 result = mResourceLoader->SaveFile( path, buffer, numBytes );
226 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
228 mDataStoragePath = path;
231 } // namespace TizenPlatform