#include <string>
#include <cstdlib>
+#if ANDROID
+#include <dali/integration-api/adaptor-framework/android/android-framework.h>
+#endif
+
std::string GetSystemCachePath()
{
+#if ANDROID
+ return Dali::Integration::AndroidFramework::Get().GetInternalDataPath() + "/dali_common_caches/";
+#else
return std::string( "@cachePath@/.cache/dali_common_caches/" );
-}
\ No newline at end of file
+#endif
+}
return mImpl->GetApplicationAssets();
}
+void AndroidFramework::SetInternalDataPath( const std::string& path )
+{
+ mImpl->SetInternalDataPath( path );
+}
+
+std::string AndroidFramework::GetInternalDataPath() const
+{
+ return mImpl->GetInternalDataPath();
+}
+
void AndroidFramework::SetApplicationConfiguration( AConfiguration* configuration )
{
mImpl->SetApplicationConfiguration( configuration );
#define DALI_INTEGRATION_ANDROID_FRAMEWORK_H
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
*/
// EXTERNAL INCLUDES
+#include <string>
+
#include <jni.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
AAssetManager* GetApplicationAssets() const;
/**
+ * Sets the Android application internal data path.
+ * @param[in] path A path to the application data path
+ */
+ void SetInternalDataPath( const std::string& path );
+
+ /**
+ * Gets the Android application internal data path.
+ * @return The application data path
+ */
+ std::string GetInternalDataPath() const;
+
+ /**
* @brief Sets the Android application configuration
* @param[in] configuration A pointer to Android application configuration
*/
return mBufferStream;
}
- std::ios_base::openmode openMode = std::ios::ate;
- if( mMode & Dali::FileStream::BINARY )
+ int openMode = 0;
+
+ if( mMode & Dali::FileStream::APPEND )
{
- openMode |= std::ios::binary;
+ openMode |= ( std::ios::out | std::ios::app );
}
-
- if( mMode & Dali::FileStream::WRITE )
+ else if( mMode & Dali::FileStream::WRITE )
{
- openMode |= std::ios::out;
+ openMode |= ( std::ios::out | std::ios::ate );
}
- else
+
+ if( mMode & Dali::FileStream::READ )
{
openMode |= std::ios::in;
}
+ if( mMode & Dali::FileStream::BINARY )
+ {
+ openMode |= std::ios::binary;
+ }
+
if( !mFileName.empty() )
{
- if ( !(mMode & Dali::FileStream::WRITE) )
+ // TODO: it works only with text files, we need custom stream buffer implementation for binary and to avoid buffer copy
+ if( !( mMode & Dali::FileStream::WRITE ) && !( mMode & Dali::FileStream::APPEND ) && !( mMode & Dali::FileStream::BINARY ) )
{
std::streampos fileSize;
- if ( ReadFile( mFileName, fileSize, mFileBuffer, Dali::FileLoader::BINARY ) )
+ if( ReadFile( mFileName, fileSize, mFileBuffer, Dali::FileLoader::TEXT ) )
{
mBuffer = reinterpret_cast<uint8_t*>( &mFileBuffer[0] );
mDataSize = fileSize;
- mBufferStream.rdbuf()->pubsetbuf( reinterpret_cast<char*>( mBuffer ), mDataSize );
+ mBufferStream.str( std::string ( &mFileBuffer[0], fileSize ) );
if( !mBufferStream.rdbuf()->in_avail() )
{
DALI_LOG_ERROR( "File open failed for memory buffer at location: \"%p\", of size: \"%u\", in mode: \"%d\".\n",
}
else
{
- mFileStream.open( mFileName, openMode );
+ mFileStream.open( mFileName, static_cast<std::ios_base::openmode>( openMode ) );
if( !mFileStream.is_open() )
{
DALI_LOG_ERROR( "stream open failed for: \"%s\", in mode: \"%d\".\n", mFileName.c_str(), static_cast<int>( openMode ) );
char openMode[16] = { 0 };
int i = 0;
- if( mMode & Dali::FileStream::WRITE )
+ if( mMode & Dali::FileStream::APPEND )
+ {
+ openMode[i++] = 'a';
+ }
+ else if( mMode & Dali::FileStream::WRITE )
{
openMode[i++] = 'w';
}
if( !mFileName.empty() )
{
- if ( !( mMode & Dali::FileStream::WRITE ) )
+ if ( !( mMode & Dali::FileStream::WRITE ) && !( mMode & Dali::FileStream::APPEND ) )
{
std::streampos fileSize;
- if ( ReadFile( mFileName, fileSize, mFileBuffer, Dali::FileLoader::BINARY ) )
+ if ( ReadFile( mFileName, fileSize, mFileBuffer, ( mMode & Dali::FileStream::BINARY ) ? Dali::FileLoader::BINARY : Dali::FileLoader::TEXT ) )
{
mBuffer = reinterpret_cast<uint8_t*>( &mFileBuffer[0] );
mDataSize = fileSize;
return mAssets;
}
+void AndroidFramework::SetInternalDataPath( const std::string& path )
+{
+ mInternalDataPath = path;
+}
+
+std::string AndroidFramework::GetInternalDataPath() const
+{
+ return mInternalDataPath;
+}
+
void AndroidFramework::SetApplicationConfiguration( AConfiguration* configuration )
{
mConfiguration = configuration;
AAssetManager* GetApplicationAssets() const;
/**
+ * copydoc Dali::Integration::AndroidFramework::SetInternalDataPath()
+ */
+ void SetInternalDataPath( const std::string& path );
+
+ /**
+ * copydoc Dali::Integration::AndroidFramework::GetInternalDataPath()
+ */
+ std::string GetInternalDataPath() const;
+
+ /**
* @copydoc Dali::Integration::AndroidFramework::SetApplicationConfiguration()
*/
void SetApplicationConfiguration( AConfiguration* configuration );
android_app* mNativeApplication;
ANativeWindow* mWindow;
AAssetManager* mAssets;
+ std::string mInternalDataPath;
AConfiguration* mConfiguration;
JavaVM* mJVM;
const std::string SYSTEM_CACHE_FILE = "gpu-environment.conf";
const std::string DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT";
-bool RetrieveKeyFromFile( std::fstream& stream, std::string key, std::string& value )
+bool RetrieveKeyFromConfigFile( std::iostream& stream, const std::string& key, std::string& value )
{
bool keyFound = false;
ConfigurationManager::ConfigurationManager( std::string systemCachePath, EglGraphics* eglGraphics, ThreadController* threadController )
: mSystemCacheFilePath( systemCachePath + SYSTEM_CACHE_FILE ),
- mFileStream( new Dali::FileStream( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT ) ),
mEglGraphics( eglGraphics ),
mThreadController( threadController ),
mMaxTextureSize( 0u ),
{
}
-unsigned int ConfigurationManager::GetMaxTextureSize()
+void ConfigurationManager::RetrieveKeysFromConfigFile( const std::string& configFilePath )
{
- if ( !mMaxTextureSizeCached )
+ Dali::FileStream configFile( configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT );
+ std::iostream& stream = configFile.GetStream();
+ if( stream.rdbuf()->in_avail() )
{
- std::fstream& configFile = dynamic_cast<std::fstream&>( mFileStream->GetStream() );
- if( configFile.is_open() )
+ std::string value;
+ if( !mMaxTextureSizeCached &&
+ RetrieveKeyFromConfigFile( stream, DALI_ENV_MAX_TEXTURE_SIZE, value ) )
{
- std::string environmentVariableValue;
- if( RetrieveKeyFromFile( configFile, DALI_ENV_MAX_TEXTURE_SIZE, environmentVariableValue ) )
- {
- mMaxTextureSize = std::atoi( environmentVariableValue.c_str() );
- }
- else
- {
- GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
- mMaxTextureSize = mGLES.GetMaxTextureSize();
+ mMaxTextureSize = std::atoi( value.c_str() );
+ mMaxTextureSizeCached = true;
+ }
- configFile.clear();
- configFile << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
- }
+ if( !mIsMultipleWindowSupportedCached &&
+ RetrieveKeyFromConfigFile( stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value ) )
+ {
+ mIsMultipleWindowSupported = std::atoi( value.c_str() );
+ mIsMultipleWindowSupportedCached = true;
+ }
+ }
+}
+
+unsigned int ConfigurationManager::GetMaxTextureSize()
+{
+ if( !mMaxTextureSizeCached )
+ {
+ RetrieveKeysFromConfigFile( mSystemCacheFilePath );
+ if( !mMaxTextureSizeCached )
+ {
+ GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
+ mMaxTextureSize = mGLES.GetMaxTextureSize();
mMaxTextureSizeCached = true;
- if ( mIsMultipleWindowSupportedCached )
+ Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
+ std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
+ if( stream.is_open() )
{
- configFile.close();
+ stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
+ }
+ else
+ {
+ DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
}
- }
- else
- {
- DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
}
}
{
if ( !mIsMultipleWindowSupportedCached )
{
- std::fstream& configFile = dynamic_cast<std::fstream&>( mFileStream->GetStream() );
- if( configFile.is_open() )
+ RetrieveKeysFromConfigFile( mSystemCacheFilePath );
+
+ if ( !mIsMultipleWindowSupportedCached )
{
- std::string environmentVariableValue;
- if( RetrieveKeyFromFile( configFile, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, environmentVariableValue ) )
+ EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
+ if ( !eglImpl.IsGlesInitialized() )
{
- mIsMultipleWindowSupported = std::atoi( environmentVariableValue.c_str() );
- }
- else
- {
- EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
- if ( !eglImpl.IsGlesInitialized() )
- {
- // Wait until GLES is initialised, but this will happen once.
- // This method blocks until the render thread has initialised the graphics.
- mThreadController->WaitForGraphicsInitialization();
- }
-
- // Query from GLES and save the cache
- mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
-
- configFile.clear();
- configFile << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
+ // Wait until GLES is initialised, but this will happen once.
+ // This method blocks until the render thread has initialised the graphics.
+ mThreadController->WaitForGraphicsInitialization();
}
+ // Query from GLES and save the cache
+ mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
mIsMultipleWindowSupportedCached = true;
- if ( mMaxTextureSizeCached )
+ Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
+ std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
+ if ( stream.is_open() )
{
- configFile.close();
+ stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
+ }
+ else
+ {
+ DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
}
- }
- else
- {
- DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
}
}
virtual ~ConfigurationManager();
/**
+ * @brief Retrieve all keys from the config file if the file exists.
+ */
+ void RetrieveKeysFromConfigFile( const std::string& configFilePath );
+
+ /**
* @brief Get the maximum texture size.
* @return The maximum texture size
*/
private: // Data
std::string mSystemCacheFilePath; ///< The path of system cache file
- std::unique_ptr<FileStream> mFileStream; ///< The file stream to access the system cache
EglGraphics* mEglGraphics; ///< EGL graphics
ThreadController* mThreadController; ///< The thread controller
unsigned int mMaxTextureSize; ///< The largest texture that the GL can handle