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 int TizenPlatformAbstraction::GetDefaultFontSize() const
61 #ifndef DALI_PROFILE_UBUNTU
62 vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
63 #endif // DALI_PROFILE_UBUNTU
68 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
70 FittingMode::Type fittingMode,
71 SamplingMode::Type samplingMode,
72 bool orientationCorrection )
74 return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
77 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
79 FittingMode::Type fittingMode,
80 SamplingMode::Type samplingMode,
81 bool orientationCorrection )
83 return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
86 Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
88 return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
91 Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
93 Integration::BitmapPtr bitmap = 0;
95 Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
96 FILE * const fp = fileCloser.GetFile();
99 bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
100 if ( !result || !bitmap )
103 DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
110 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
114 #ifdef SHADERBIN_CACHE_ENABLED
117 // First check the system location where shaders are stored at install time:
118 if( mResourceLoader )
120 path = DALI_SHADERBIN_DIR;
122 result = mResourceLoader->LoadFile( path, buffer );
125 // Fallback to the cache of shaders stored after previous runtime compilations:
126 // On desktop this looks in the current working directory that the app was launched from.
127 if( mResourceLoader && result == false )
129 path = mDataStoragePath;
131 result = mResourceLoader->LoadFile( path, buffer );
138 bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
142 #ifdef SHADERBIN_CACHE_ENABLED
144 // Fallback to the cache of shaders stored after previous runtime compilations:
145 // On desktop this looks in the current working directory that the app was launched from.
146 if( mResourceLoader )
148 std::string path = mDataStoragePath;
150 result = mResourceLoader->SaveFile( path, buffer, numBytes );
157 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
159 mDataStoragePath = path;
162 } // namespace TizenPlatform