/*
- * 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.
*
*/
+// CLASS HEADER
#include "tizen-platform-abstraction.h"
-#ifndef DALI_PROFILE_UBUNTU
-#include <vconf.h>
-#endif // DALI_PROFILE_UBUNTU
+// EXTERNAL INCLUDES
#include <dirent.h>
-
+#include <fstream>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
#include <dali/integration-api/resource-types.h>
// INTERNAL INCLUDES
-#include "resource-loader/resource-loader.h"
#include "image-loaders/image-loader.h"
-#include "portable/file-closer.h"
+#include "portable/file-reader.h"
+#include <adaptors/common/pixel-buffer-impl.h>
namespace Dali
{
-Integration::PlatformAbstraction* CreatePlatformAbstraction()
-{
- return new TizenPlatform::TizenPlatformAbstraction();
-}
-
-
namespace TizenPlatform
{
TizenPlatformAbstraction::TizenPlatformAbstraction()
-: mResourceLoader(new ResourceLoader),
- mDataStoragePath( "" )
+: mDataStoragePath( "" )
{
}
TizenPlatformAbstraction::~TizenPlatformAbstraction()
{
- delete mResourceLoader;
-}
-
-void TizenPlatformAbstraction::GetTimeNanoseconds( uint64_t& seconds, uint64_t& nanoseconds )
-{
- timespec time;
- clock_gettime( CLOCK_MONOTONIC, &time );
- seconds = time.tv_sec;
- nanoseconds = time.tv_nsec;
-}
-
-void TizenPlatformAbstraction::Suspend()
-{
- if (mResourceLoader)
- {
- mResourceLoader->Pause();
- }
-}
-
-void TizenPlatformAbstraction::Resume()
-{
- if (mResourceLoader)
- {
- mResourceLoader->Resume();
- }
-}
-
-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,
return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
}
-void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
-{
- if (mResourceLoader)
- {
- mResourceLoader->LoadResource(request);
- }
-}
-
-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;
+ Integration::BitmapPtr resultBitmap;
+ Dali::Devel::PixelBuffer bitmap;
- 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
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.
{
path = mDataStoragePath;
path += filename;
- result = mResourceLoader->LoadFile( path, buffer );
+ result = LoadFile( path, buffer );
}
#endif
#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;
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<int>(numBytes);
+
+ // write contents of buffer to the file
+ stream.write(reinterpret_cast<const char*>(buffer), length);
+
+ if( !stream.bad() )
+ {
+ result = true;
+ }
+ }
+
+ return result;
+}
+
} // namespace TizenPlatform
} // namespace Dali