X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=platform-abstractions%2Ftizen%2Ftizen-platform-abstraction.cpp;h=1a8a876c8b13e54878a5c926ce430037ea973c04;hb=422667d3df334499df2778b973a0a92515c53c0a;hp=0ca22e4ddcf6edd75bc786c3db2568c1f240b27a;hpb=afdbf909870dea6ddf0144db823a4bf6a0b414f2;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/platform-abstractions/tizen/tizen-platform-abstraction.cpp b/platform-abstractions/tizen/tizen-platform-abstraction.cpp index 0ca22e4..1a8a876 100644 --- a/platform-abstractions/tizen/tizen-platform-abstraction.cpp +++ b/platform-abstractions/tizen/tizen-platform-abstraction.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,54 +15,33 @@ * */ +// CLASS HEADER #include "tizen-platform-abstraction.h" -#ifndef DALI_PROFILE_UBUNTU -#include -#endif // DALI_PROFILE_UBUNTU +// EXTERNAL INCLUDES #include - +#include #include #include #include // INTERNAL INCLUDES -#include "resource-loader/resource-loader.h" #include "image-loaders/image-loader.h" -#include "portable/file-closer.h" +#include "portable/file-reader.h" namespace Dali { -Integration::PlatformAbstraction* CreatePlatformAbstraction() -{ - return new TizenPlatform::TizenPlatformAbstraction(); -} - - namespace TizenPlatform { TizenPlatformAbstraction::TizenPlatformAbstraction() -: mResourceLoader(new ResourceLoader), - mDataStoragePath( "" ) +: mDataStoragePath( "" ) { } TizenPlatformAbstraction::~TizenPlatformAbstraction() { - delete mResourceLoader; -} - -int TizenPlatformAbstraction::GetDefaultFontSize() const -{ - int fontSize( -1 ); - -#ifndef DALI_PROFILE_UBUNTU - vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize ); -#endif // DALI_PROFILE_UBUNTU - - return fontSize; } ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename, @@ -83,20 +62,20 @@ ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::Reso return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection ); } -Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath) +Integration::ResourcePointer TizenPlatformAbstraction::LoadImageSynchronously(const Integration::BitmapResourceType& resource, const std::string& resourcePath) { - return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath ); + return ImageLoader::LoadImageSynchronously( resource, resourcePath ); } -Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size ) +Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::BitmapResourceType& resource, uint8_t * buffer, size_t size ) { Integration::BitmapPtr bitmap = 0; - Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" ); - FILE * const fp = fileCloser.GetFile(); + Dali::Internal::Platform::FileReader fileReader( buffer, size ); + FILE * const fp = fileReader.GetFile(); if( fp ) { - bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap ); + bool result = ImageLoader::ConvertStreamToBitmap( resource, "", fp, bitmap ); if ( !result || !bitmap ) { bitmap.Reset(); @@ -115,12 +94,9 @@ bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename std::string path; // First check the system location where shaders are stored at install time: - if( mResourceLoader ) - { - path = DALI_SHADERBIN_DIR; - path += filename; - result = mResourceLoader->LoadFile( path, buffer ); - } + path = DALI_SHADERBIN_DIR; + path += filename; + result = LoadFile( path, buffer ); // Fallback to the cache of shaders stored after previous runtime compilations: // On desktop this looks in the current working directory that the app was launched from. @@ -128,7 +104,7 @@ bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename { path = mDataStoragePath; path += filename; - result = mResourceLoader->LoadFile( path, buffer ); + result = LoadFile( path, buffer ); } #endif @@ -141,14 +117,12 @@ bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename #ifdef SHADERBIN_CACHE_ENABLED - // Fallback to the cache of shaders stored after previous runtime compilations: - // On desktop this looks in the current working directory that the app was launched from. - if( mResourceLoader ) - { - std::string path = mDataStoragePath; - path += filename; - result = mResourceLoader->SaveFile( path, buffer, numBytes ); - } + // Use the cache of shaders stored after previous runtime compilations: + // On desktop this looks in the current working directory that the app was launched from. + std::string path = mDataStoragePath; + path += filename; + result = SaveFile( path, buffer, numBytes ); + #endif return result; @@ -159,6 +133,38 @@ void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path ) mDataStoragePath = path; } +TizenPlatformAbstraction* CreatePlatformAbstraction() +{ + return new TizenPlatformAbstraction(); +} + +bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) +{ + DALI_ASSERT_DEBUG( 0 != filename.length()); + + bool result = false; + + std::filebuf buf; + buf.open(filename.c_str(), std::ios::out | std::ios_base::trunc | std::ios::binary); + if( buf.is_open() ) + { + std::ostream stream(&buf); + + // determine size of buffer + int length = static_cast(numBytes); + + // write contents of buffer to the file + stream.write(reinterpret_cast(buffer), length); + + if( !stream.bad() ) + { + result = true; + } + } + + return result; +} + } // namespace TizenPlatform } // namespace Dali