X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=platform-abstractions%2Ftizen%2Ftizen-platform-abstraction.cpp;h=2bf6e6f9954564bbfaa8dc38959ae747c1893993;hb=0e18992346b92b3951f71616ffe18230ff79b3b3;hp=ff4a29589990cbbb741a983cf2699d9b2c65c58f;hpb=a68e01140f2816f8154001fd866394d359aacc83;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 ff4a295..2bf6e6f 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,90 +15,34 @@ * */ +// 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 "tizen-font-configuration-parser.h" #include "image-loaders/image-loader.h" -#include "portable/file-closer.h" +#include "portable/file-reader.h" +#include namespace Dali { -Integration::PlatformAbstraction* CreatePlatformAbstraction() -{ - return new TizenPlatform::TizenPlatformAbstraction(); -} - - namespace TizenPlatform { -namespace -{ -const std::string FONT_CONFIGURATION_FILE( FONT_CONFIGURATION_FILE_PATH ); ///< Default font configuration file -const unsigned int NANOSECS_TO_MICROSECS( 1000 ); ///< 1000 nanoseconds = 1 microsecond -} - TizenPlatformAbstraction::TizenPlatformAbstraction() -: mResourceLoader(new ResourceLoader), - mDataStoragePath( "" ) +: mDataStoragePath( "" ) { } TizenPlatformAbstraction::~TizenPlatformAbstraction() { - delete mResourceLoader; -} - -void TizenPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds) -{ - timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); - seconds = time.tv_sec; - microSeconds = time.tv_nsec / NANOSECS_TO_MICROSECS; -} - -void TizenPlatformAbstraction::Suspend() -{ - if (mResourceLoader) - { - mResourceLoader->Pause(); - } -} - -void TizenPlatformAbstraction::Resume() -{ - if (mResourceLoader) - { - mResourceLoader->Resume(); - } -} - -void TizenPlatformAbstraction::GetDefaultFontDescription( std::string& fontFamily, std::string& fontStyle ) const -{ - FontConfigurationParser::Parse(FONT_CONFIGURATION_FILE, fontFamily, fontStyle); -} - -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, @@ -119,81 +63,49 @@ ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::Reso return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection ); } -void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request) +Integration::ResourcePointer TizenPlatformAbstraction::LoadImageSynchronously(const Integration::BitmapResourceType& resource, const std::string& resourcePath) { - if (mResourceLoader) - { - mResourceLoader->LoadResource(request); - } + return ImageLoader::LoadImageSynchronously( resource, resourcePath ); } -Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath) +Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::BitmapResourceType& resource, uint8_t * buffer, size_t size ) { - return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath ); -} + Integration::BitmapPtr resultBitmap; + Dali::Devel::PixelBuffer bitmap; -Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, 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(); DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" ); } - } - - return bitmap; -} - -void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId) -{ - if (mResourceLoader) - { - mResourceLoader->CancelLoad(id, typeId); - } -} - -void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache) -{ - if (mResourceLoader) - { - mResourceLoader->GetResources(cache); - } -} + else + { + Integration::Bitmap::Profile profile{Integration::Bitmap::Profile::BITMAP_2D_PACKED_PIXELS}; -bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const -{ - bool result = false; + // For backward compatibility the Bitmap must be created + auto retval = Integration::Bitmap::New(profile, Dali::ResourcePolicy::OWNED_DISCARD); - if( mResourceLoader ) - { - result = mResourceLoader->LoadFile( filename, buffer ); - } + retval->GetPackedPixelsProfile()->ReserveBuffer( + bitmap.GetPixelFormat(), + bitmap.GetWidth(), + bitmap.GetHeight(), + bitmap.GetWidth(), + bitmap.GetHeight() + ); - return result; -} + auto& impl = Dali::GetImplementation(bitmap); -std::string TizenPlatformAbstraction::LoadFile( const std::string& filename ) -{ - std::string result; - if (mResourceLoader) - { - result = mResourceLoader->LoadFile(filename); + std::copy( impl.GetBuffer(), impl.GetBuffer()+impl.GetBufferSize(), retval->GetBuffer()); + resultBitmap.Reset(retval); + } } - return result; -} - -void TizenPlatformAbstraction::JoinLoaderThreads() -{ - delete mResourceLoader; - mResourceLoader = NULL; + return resultBitmap; } bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const @@ -204,12 +116,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. @@ -217,7 +126,7 @@ bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename { path = mDataStoragePath; path += filename; - result = mResourceLoader->LoadFile( path, buffer ); + result = LoadFile( path, buffer ); } #endif @@ -230,14 +139,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; @@ -248,6 +155,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