2 * Copyright (c) 2017 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.
19 #include "tizen-platform-abstraction.h"
24 #include <dali/integration-api/debug.h>
25 #include <dali/integration-api/bitmap.h>
26 #include <dali/integration-api/resource-types.h>
29 #include "image-loaders/image-loader.h"
30 #include "portable/file-reader.h"
35 namespace TizenPlatform
38 TizenPlatformAbstraction::TizenPlatformAbstraction()
39 : mDataStoragePath( "" )
43 TizenPlatformAbstraction::~TizenPlatformAbstraction()
47 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
49 FittingMode::Type fittingMode,
50 SamplingMode::Type samplingMode,
51 bool orientationCorrection )
53 return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
56 ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
58 FittingMode::Type fittingMode,
59 SamplingMode::Type samplingMode,
60 bool orientationCorrection )
62 return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
65 Integration::ResourcePointer TizenPlatformAbstraction::LoadImageSynchronously(const Integration::BitmapResourceType& resource, const std::string& resourcePath)
67 return ImageLoader::LoadImageSynchronously( resource, resourcePath );
70 Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::BitmapResourceType& resource, uint8_t * buffer, size_t size )
72 Integration::BitmapPtr bitmap = 0;
74 Dali::Internal::Platform::FileReader fileReader( buffer, size );
75 FILE * const fp = fileReader.GetFile();
78 bool result = ImageLoader::ConvertStreamToBitmap( resource, "", fp, bitmap );
79 if ( !result || !bitmap )
82 DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
89 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
93 #ifdef SHADERBIN_CACHE_ENABLED
96 // First check the system location where shaders are stored at install time:
97 path = DALI_SHADERBIN_DIR;
99 result = LoadFile( path, buffer );
101 // Fallback to the cache of shaders stored after previous runtime compilations:
102 // On desktop this looks in the current working directory that the app was launched from.
103 if( mResourceLoader && result == false )
105 path = mDataStoragePath;
107 result = LoadFile( path, buffer );
114 bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
118 #ifdef SHADERBIN_CACHE_ENABLED
120 // Use the cache of shaders stored after previous runtime compilations:
121 // On desktop this looks in the current working directory that the app was launched from.
122 std::string path = mDataStoragePath;
124 result = SaveFile( path, buffer, numBytes );
131 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
133 mDataStoragePath = path;
136 TizenPlatformAbstraction* CreatePlatformAbstraction()
138 return new TizenPlatformAbstraction();
141 bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes )
143 DALI_ASSERT_DEBUG( 0 != filename.length());
148 buf.open(filename.c_str(), std::ios::out | std::ios_base::trunc | std::ios::binary);
151 std::ostream stream(&buf);
153 // determine size of buffer
154 int length = static_cast<int>(numBytes);
156 // write contents of buffer to the file
157 stream.write(reinterpret_cast<const char*>(buffer), length);
168 } // namespace TizenPlatform