From: Andrew Cox Date: Tue, 16 Jun 2015 18:42:42 +0000 (+0100) Subject: Shader binary synchronous simplified IO X-Git-Tag: dali_1.0.49~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f4b8f5f07122757d1c9bffbd4c384d8ad70de515;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Shader binary synchronous simplified IO Change-Id: I4894729a48527bcaa7b710d616eeeacdc7f7c8b3 Signed-off-by: Andrew Cox --- diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.cpp b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.cpp index 58f07ca..6acbca7 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.cpp +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.cpp @@ -193,7 +193,7 @@ void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int d /** * @copydoc PlatformAbstraction::LoadFile() */ -bool TestPlatformAbstraction::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const +bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const { mTrace.PushCall("LoadFile", ""); if( mLoadFileResult.loadResult ) @@ -205,11 +205,11 @@ bool TestPlatformAbstraction::LoadFile( const std::string& filename, std::vector } /** - * @copydoc PlatformAbstraction::LoadShaderBinFile() + * @copydoc PlatformAbstraction::LoadShaderBinaryFile() */ -bool TestPlatformAbstraction::LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const +bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const { - mTrace.PushCall("LoadShaderBinFile", ""); + mTrace.PushCall("LoadShaderBinaryFile", ""); if( mLoadFileResult.loadResult ) { buffer = mLoadFileResult.buffer; @@ -221,7 +221,7 @@ bool TestPlatformAbstraction::LoadShaderBinFile( const std::string& filename, st /** * @copydoc PlatformAbstraction::SaveFile() */ -bool TestPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const +bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes) const { mTrace.PushCall("SaveFile", ""); return false; @@ -260,7 +260,8 @@ bool TestPlatformAbstraction::WasCalled(TestFuncEnum func) case LoadResourceFunc: return mTrace.FindMethod("LoadResource"); case SaveResourceFunc: return mTrace.FindMethod("SaveResource"); case LoadFileFunc: return mTrace.FindMethod("LoadFile"); - case LoadShaderBinFileFunc: return mTrace.FindMethod("LoadShaderBinFile"); + case LoadShaderBinaryFileFunc: return mTrace.FindMethod("LoadShaderBinaryFile"); + case SaveShaderBinaryFileFunc: return mTrace.FindMethod("SaveShaderBinaryFile"); case SaveFileFunc: return mTrace.FindMethod("SaveFile"); case CancelLoadFunc: return mTrace.FindMethod("CancelLoad"); case GetResourcesFunc: return mTrace.FindMethod("GetResources"); @@ -346,7 +347,7 @@ void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size) mClosestSize = size; } -void TestPlatformAbstraction::SetLoadFileResult( bool result, std::vector< unsigned char >& buffer ) +void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer ) { mLoadFileResult.loadResult = result; if( result ) diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.h b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.h index a323f65..2e0fd8e 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.h +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-platform-abstraction.h @@ -70,7 +70,7 @@ public: } bool loadResult; - std::vector< unsigned char> buffer; + Dali::Vector< unsigned char> buffer; }; /** @@ -163,18 +163,20 @@ public: /** * @copydoc PlatformAbstraction::LoadFile() */ - virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const; + virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const; /** - * @copydoc PlatformAbstraction::LoadShaderBinFile() + * @copydoc PlatformAbstraction::LoadShaderBinaryFile() */ - virtual bool LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer + virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const; + virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; } + /** * @copydoc PlatformAbstraction::SaveFile() */ - virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const; + virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes) const; virtual void JoinLoaderThreads(); @@ -190,7 +192,8 @@ public: // TEST FUNCTIONS SaveResourceFunc, SaveFileFunc, LoadFileFunc, - LoadShaderBinFileFunc, + LoadShaderBinaryFileFunc, + SaveShaderBinaryFileFunc, CancelLoadFunc, GetResourcesFunc, IsLoadingFunc, @@ -240,7 +243,7 @@ public: // TEST FUNCTIONS void SetClosestImageSize(const Vector2& size); - void SetLoadFileResult( bool result, std::vector< unsigned char >& buffer ); + void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer ); void SetSaveFileResult( bool result ); diff --git a/build/tizen/configure.ac b/build/tizen/configure.ac index e63b894..8980728 100644 --- a/build/tizen/configure.ac +++ b/build/tizen/configure.ac @@ -275,6 +275,7 @@ Configuration Data Dir (Read Only): $dataReadOnlyDir OVERTIZEN2.2: $with_over_tizen_2_2 EldBus: $eldbus_available + Shader Binary Cache: $enable_shaderbincache Build for Node.JS (LibUV) $build_for_node_js " # optional output of node.js source path if we're building for node.js diff --git a/platform-abstractions/tizen/file.list b/platform-abstractions/tizen/file.list index 2f1eda0..98711fc 100755 --- a/platform-abstractions/tizen/file.list +++ b/platform-abstractions/tizen/file.list @@ -8,11 +8,9 @@ tizen_platform_abstraction_src_files = \ $(tizen_platform_abstraction_src_dir)/resource-loader/resource-loader.cpp \ $(tizen_platform_abstraction_src_dir)/resource-loader/resource-requester-base.cpp \ $(tizen_platform_abstraction_src_dir)/resource-loader/resource-bitmap-requester.cpp \ - $(tizen_platform_abstraction_src_dir)/resource-loader/resource-shader-requester.cpp \ \ $(tizen_platform_abstraction_src_dir)/resource-loader/resource-thread-base.cpp \ $(tizen_platform_abstraction_src_dir)/resource-loader/resource-thread-image.cpp \ - $(tizen_platform_abstraction_src_dir)/resource-loader/resource-thread-shader.cpp \ \ $(tizen_platform_abstraction_src_dir)/resource-loader/network/file-download.cpp \ $(tizen_platform_abstraction_src_dir)/resource-loader/network/http-utils.cpp \ diff --git a/platform-abstractions/tizen/resource-loader/resource-loader.cpp b/platform-abstractions/tizen/resource-loader/resource-loader.cpp index 6db70e8..d866c40 100755 --- a/platform-abstractions/tizen/resource-loader/resource-loader.cpp +++ b/platform-abstractions/tizen/resource-loader/resource-loader.cpp @@ -33,7 +33,6 @@ #include #include "resource-requester-base.h" #include "resource-bitmap-requester.h" -#include "resource-shader-requester.h" #include "debug/resource-loader-debug.h" @@ -90,7 +89,6 @@ struct ResourceLoader::ResourceLoaderImpl ResourceLoaderImpl( ResourceLoader* loader ) { mRequestHandlers.insert(std::make_pair(ResourceBitmap, new ResourceBitmapRequester(*loader))); - mRequestHandlers.insert(std::make_pair(ResourceShader, new ResourceShaderRequester(*loader))); } ~ResourceLoaderImpl() @@ -429,6 +427,15 @@ void ResourceLoader::SetDpi(unsigned int dpiHor, unsigned int dpiVer) bool ResourceLoader::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const { + Dali::Vector daliVec; + const bool result = LoadFile( filename, daliVec ); + buffer.resize( daliVec.Size() ); + memcpy( &buffer[0], &daliVec[0], daliVec.Size() ); + return result; +} + +bool ResourceLoader::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const +{ DALI_LOG_TRACE_METHOD(gLoaderFilter); DALI_ASSERT_DEBUG( 0 != filename.length()); @@ -447,9 +454,9 @@ bool ResourceLoader::LoadFile( const std::string& filename, std::vector< unsigne stream.seekg(0, std::ios_base::beg); // allocate a buffer - buffer.resize(length); + buffer.Resize(length); // read data into buffer - stream.read(reinterpret_cast(buffer.data()), length); + stream.read(reinterpret_cast(buffer.Begin()), length); DALI_LOG_INFO(gLoaderFilter, Debug::Verbose, "ResourceLoader::LoadFile(%s) - loaded %d bytes\n", filename.c_str(), length); @@ -500,6 +507,11 @@ std::string ResourceLoader::LoadFile(const std::string& filename) const bool ResourceLoader::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) { + return SaveFile( filename, &buffer[0], buffer.size() ); +} + +bool ResourceLoader::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) +{ DALI_LOG_TRACE_METHOD(gLoaderFilter); DALI_ASSERT_DEBUG( 0 != filename.length()); @@ -513,10 +525,10 @@ bool ResourceLoader::SaveFile(const std::string& filename, std::vector< unsigned std::ostream stream(&buf); // determine size of buffer - int length = static_cast(buffer.size()); + int length = static_cast(numBytes); // write contents of buffer to the file - stream.write(reinterpret_cast(buffer.data()), length); + stream.write(reinterpret_cast(buffer), length); if( !stream.bad() ) { diff --git a/platform-abstractions/tizen/resource-loader/resource-loader.h b/platform-abstractions/tizen/resource-loader/resource-loader.h index 3dc0f19..10b99ed 100644 --- a/platform-abstractions/tizen/resource-loader/resource-loader.h +++ b/platform-abstractions/tizen/resource-loader/resource-loader.h @@ -79,7 +79,7 @@ struct LoadedResource } Integration::ResourceId id; ///< Integer ID - Integration::ResourceTypeId type; ///< Type enum (bitmap, shader, ...) + Integration::ResourceTypeId type; ///< Type enum (bitmap, ...) Integration::ResourcePointer resource; ///< Reference counting pointer to the loaded / decoded representation of the resource. }; @@ -261,6 +261,7 @@ public: * @copydoc SlpPlatformAbstraction::LoadFile() */ bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const; + bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const; /** * @copydoc TizenPlatformAbstraction::LoadFile() @@ -270,7 +271,8 @@ public: /** * @copydoc TizenPlatformAbstraction::SaveFile() */ - static bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer); + static bool SaveFile( const std::string& filename, std::vector< unsigned char >& buffer ); + static bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ); private: struct ResourceLoaderImpl; diff --git a/platform-abstractions/tizen/resource-loader/resource-shader-requester.cpp b/platform-abstractions/tizen/resource-loader/resource-shader-requester.cpp deleted file mode 100644 index e074625..0000000 --- a/platform-abstractions/tizen/resource-loader/resource-shader-requester.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "resource-shader-requester.h" - -using namespace Dali::Integration; - -namespace Dali -{ -namespace TizenPlatform -{ - -ResourceShaderRequester::ResourceShaderRequester( ResourceLoader& resourceLoader ) -: ResourceRequesterBase( resourceLoader ) -{ - mThreadShader = new ResourceThreadShader( resourceLoader ); -} - -ResourceShaderRequester::~ResourceShaderRequester() -{ - delete mThreadShader; -} - -void ResourceShaderRequester::Pause() -{ - mThreadShader->Pause(); -} - -void ResourceShaderRequester::Resume() -{ - mThreadShader->Resume(); -} - -void ResourceShaderRequester::LoadResource( Integration::ResourceRequest& request ) -{ - mThreadShader->AddRequest(request, ResourceThreadBase::RequestLoad); -} - -ResourcePointer ResourceShaderRequester::LoadResourceSynchronously( const Integration::ResourceType& type, const std::string& path ) -{ - DALI_ASSERT_ALWAYS( false && "Cannot load shaders synchronously" ); -} - -Integration::LoadStatus ResourceShaderRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource ) -{ - // Nothing to do - return RESOURCE_COMPLETELY_LOADED; -} - -void ResourceShaderRequester::SaveResource(const Integration::ResourceRequest& request ) -{ - mThreadShader->AddRequest(request, ResourceThreadBase::RequestSave); -} - -void ResourceShaderRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId) -{ - mThreadShader->CancelRequest(id); -} - -} // TizenPlatform -} // Dali diff --git a/platform-abstractions/tizen/resource-loader/resource-shader-requester.h b/platform-abstractions/tizen/resource-loader/resource-shader-requester.h deleted file mode 100644 index b78a0df..0000000 --- a/platform-abstractions/tizen/resource-loader/resource-shader-requester.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef __DALI_TIZEN_PLATFORM_RESOURCE_SHADER_REQUESTER_H__ -#define __DALI_TIZEN_PLATFORM_RESOURCE_SHADER_REQUESTER_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "resource-requester-base.h" -#include "resource-thread-shader.h" - -namespace Dali -{ -namespace TizenPlatform -{ - -/** - * Class to own request thread and manage resource requests for shader - */ -class ResourceShaderRequester : public ResourceRequesterBase -{ -public: - /** - * Constructor - * @param[in] resourceLoader The resource loader with which to communicate results - */ - ResourceShaderRequester( ResourceLoader& resourceLoader ); - - /** - * Destructor - */ - virtual ~ResourceShaderRequester(); - - /** - * @copydoc ResourceRequester::Pause() - */ - virtual void Pause(); - - /** - * @copydoc ResourceRequester::Resume() - */ - virtual void Resume(); - - /** - * @copydoc ResourceRequester::LoadResource() - */ - virtual void LoadResource( Integration::ResourceRequest& request ); - - /** - * @copydoc ResourceRequester::LoadResourceSynchronously() - */ - virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& type, const std::string& path ); - - /** - * @copydoc ResourceRequester::LoadFurtherResources() - */ - virtual Integration::LoadStatus LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource ); - - /** - * @copydoc ResourceRequester::SaveResource() - */ - virtual void SaveResource(const Integration::ResourceRequest& request ); - - /** - * @copydoc ResourceRequester::CancelLoad() - */ - virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId); - -protected: - ResourceThreadShader* mThreadShader; ///< Thread to load requests -}; - -} // TizenPlatform -} // Dali - -#endif // __DALI_TIZEN_PLATFORM_RESOURCE_SHADER_REQUESTER_H__ diff --git a/platform-abstractions/tizen/resource-loader/resource-thread-shader.cpp b/platform-abstractions/tizen/resource-loader/resource-thread-shader.cpp deleted file mode 100644 index b06ba37..0000000 --- a/platform-abstractions/tizen/resource-loader/resource-thread-shader.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "resource-thread-shader.h" -#include -#include - -using namespace Dali::Integration; -using boost::mutex; -using boost::unique_lock; - -namespace Dali -{ - -namespace TizenPlatform -{ - -ResourceThreadShader::ResourceThreadShader(ResourceLoader& resourceLoader) -: ResourceThreadBase(resourceLoader) -{ -} - -ResourceThreadShader::~ResourceThreadShader() -{ -} - -void ResourceThreadShader::Load(const ResourceRequest& request) -{ - // fake successfull load as this is dead code - // Construct LoadedResource and ResourcePointer for shader data - LoadedResource resource( request.GetId(), request.GetType()->id, ResourcePointer() ); - - // Queue the loaded resource - mResourceLoader.AddLoadedResource(resource); -} - -void ResourceThreadShader::Save(const ResourceRequest& request) -{ - DALI_ASSERT_DEBUG(request.GetType()->id == ResourceShader); - - DALI_LOG_INFO(mLogFilter, Debug::Verbose, "ResourceThreadShader::Save(%s)\n", request.GetPath().c_str()); - - bool result = false; - - ShaderDataPtr shaderData( reinterpret_cast< ShaderData* >(request.GetResource().Get()) ); - - FILE *fp = fopen(request.GetPath().c_str(), "wb"); - if (fp != NULL) - { - fwrite( shaderData->GetBufferData(), shaderData->GetBufferSize(), 1, fp ); - - fclose(fp); - - result = true; - - DALI_LOG_INFO(mLogFilter, Debug::Verbose, "ResourceThreadShader::Save(%s) - succeeded, wrote %d bytes\n", - request.GetPath().c_str(), shaderData->GetBufferSize()); - } - else - { - DALI_LOG_WARNING("**Failed** to save \"%s\"\n", request.GetPath().c_str()); - } - - - if (result) - { - // Construct LoadedResource and ResourcePointer for image data - SavedResource resource( request.GetId(), request.GetType()->id ); - - // Queue the loaded resource - mResourceLoader.AddSavedResource(resource); - } - else - { - // add to the failed queue - FailedResource resource(request.GetId(), FailureUnknown); - mResourceLoader.AddFailedSave(resource); - } -} - - -} // namespace TizenPlatform - -} // namespace Dali diff --git a/platform-abstractions/tizen/resource-loader/resource-thread-shader.h b/platform-abstractions/tizen/resource-loader/resource-thread-shader.h deleted file mode 100644 index b178b1b..0000000 --- a/platform-abstractions/tizen/resource-loader/resource-thread-shader.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_SHADER_H__ -#define __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_SHADER_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "resource-thread-base.h" - -namespace Dali -{ - -namespace Integration -{ -namespace Log -{ -class Filter; -} -} - -namespace TizenPlatform -{ - -class ResourceThreadShader : public ResourceThreadBase -{ -public: - /** - * Constructor - * @param[in] resourceLoader A reference to the ResourceLoader - */ - ResourceThreadShader(ResourceLoader& resourceLoader); - - /** - * Destructor - */ - virtual ~ResourceThreadShader(); - -private: - /** - * @copydoc ResourceThreadBase:Load - */ - virtual void Load(const Integration::ResourceRequest& request); - - /** - *@copydoc ResourceThreadBase::Save - */ - virtual void Save(const Integration::ResourceRequest& request); - -private: - -}; // class ResourceThreadShader - -} // namespace TizenPlatform - -} // namespace Dali - -#endif // __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_SHADER_H__ diff --git a/platform-abstractions/tizen/tizen-platform-abstraction.cpp b/platform-abstractions/tizen/tizen-platform-abstraction.cpp index 0b93dcc..b125d13 100644 --- a/platform-abstractions/tizen/tizen-platform-abstraction.cpp +++ b/platform-abstractions/tizen/tizen-platform-abstraction.cpp @@ -131,25 +131,11 @@ Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath ); } - void TizenPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request) { if (mResourceLoader) { - if( request.GetType()->id == Integration::ResourceShader ) - { -#ifdef SHADERBIN_CACHE_ENABLED - std::string path = mDataStoragePath; - path += request.GetPath(); - - Integration::ResourceRequest newRequest( request.GetId(), *request.GetType(), path, request.GetResource() ); - mResourceLoader->SaveResource(newRequest); -#endif - } - else - { - mResourceLoader->SaveResource(request); - } + mResourceLoader->SaveResource(request); } } @@ -187,13 +173,13 @@ void TizenPlatformAbstraction::SetDpi(unsigned int dpiHor, unsigned int dpiVer) } } -bool TizenPlatformAbstraction::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const +bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const { bool result = false; - if (mResourceLoader) + if( mResourceLoader ) { - result = mResourceLoader->LoadFile(filename, buffer); + result = mResourceLoader->LoadFile( filename, buffer ); } return result; @@ -210,13 +196,13 @@ std::string TizenPlatformAbstraction::LoadFile( const std::string& filename ) return result; } -bool TizenPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const +bool TizenPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { bool result = false; - if (mResourceLoader) + if( mResourceLoader ) { - result = mResourceLoader->SaveFile(filename, buffer); + result = mResourceLoader->SaveFile( filename, buffer, numBytes ); } return result; @@ -228,13 +214,14 @@ void TizenPlatformAbstraction::JoinLoaderThreads() mResourceLoader = NULL; } -bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const +bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const { bool result = false; #ifdef SHADERBIN_CACHE_ENABLED std::string path; + // First check the system location where shaders are stored at install time: if( mResourceLoader ) { path = DALI_SHADERBIN_DIR; @@ -242,6 +229,8 @@ bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, s result = mResourceLoader->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. if( mResourceLoader && result == false ) { path = mDataStoragePath; @@ -253,6 +242,25 @@ bool TizenPlatformAbstraction::LoadShaderBinFile( const std::string& filename, s return result; } +bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const +{ + bool result = false; + +#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 ); + } +#endif + + return result; +} + void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path ) { mDataStoragePath = path; diff --git a/platform-abstractions/tizen/tizen-platform-abstraction.h b/platform-abstractions/tizen/tizen-platform-abstraction.h index b9bcf83..01c8510 100644 --- a/platform-abstractions/tizen/tizen-platform-abstraction.h +++ b/platform-abstractions/tizen/tizen-platform-abstraction.h @@ -143,7 +143,7 @@ public: // PlatformAbstraction overrides /** * @copydoc PlatformAbstraction::LoadFile() */ - virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const; + virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const; /** * @copydoc PlatformAbstraction::LoadFile() @@ -153,12 +153,17 @@ public: // PlatformAbstraction overrides /** * @copydoc PlatformAbstraction::SaveFile() */ - virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const; + virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const; /** - * @copydoc PlatformAbstraction::LoadShaderBinFile() + * @copydoc PlatformAbstraction::LoadShaderBinaryFile() */ - virtual bool LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const; + virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const; + + /** + * @copydoc PlatformAbstraction::SaveShaderBinaryFile() + */ + virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const; /** * Sets path for data/resource storage.