/**
* @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 )
}
/**
- * @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;
/**
* @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;
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");
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 )
}
bool loadResult;
- std::vector< unsigned char> buffer;
+ Dali::Vector< unsigned char> buffer;
};
/**
/**
* @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();
SaveResourceFunc,
SaveFileFunc,
LoadFileFunc,
- LoadShaderBinFileFunc,
+ LoadShaderBinaryFileFunc,
+ SaveShaderBinaryFileFunc,
CancelLoadFunc,
GetResourcesFunc,
IsLoadingFunc,
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 );
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
$(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 \
#include <dali/public-api/math/vector2.h>
#include "resource-requester-base.h"
#include "resource-bitmap-requester.h"
-#include "resource-shader-requester.h"
#include "debug/resource-loader-debug.h"
ResourceLoaderImpl( ResourceLoader* loader )
{
mRequestHandlers.insert(std::make_pair(ResourceBitmap, new ResourceBitmapRequester(*loader)));
- mRequestHandlers.insert(std::make_pair(ResourceShader, new ResourceShaderRequester(*loader)));
}
~ResourceLoaderImpl()
bool ResourceLoader::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
{
+ Dali::Vector<unsigned char> 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());
stream.seekg(0, std::ios_base::beg);
// allocate a buffer
- buffer.resize(length);
+ buffer.Resize(length);
// read data into buffer
- stream.read(reinterpret_cast<char*>(buffer.data()), length);
+ stream.read(reinterpret_cast<char*>(buffer.Begin()), length);
DALI_LOG_INFO(gLoaderFilter, Debug::Verbose, "ResourceLoader::LoadFile(%s) - loaded %d bytes\n", filename.c_str(), length);
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());
std::ostream stream(&buf);
// determine size of buffer
- int length = static_cast<int>(buffer.size());
+ int length = static_cast<int>(numBytes);
// write contents of buffer to the file
- stream.write(reinterpret_cast<char*>(buffer.data()), length);
+ stream.write(reinterpret_cast<const char*>(buffer), length);
if( !stream.bad() )
{
}
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.
};
* @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()
/**
* @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;
+++ /dev/null
-/*
- * 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
+++ /dev/null
-#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__
+++ /dev/null
-/*
- * 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 <stdio.h>
-
-#include "resource-thread-shader.h"
-#include <dali/integration-api/debug.h>
-#include <dali/integration-api/shader-data.h>
-
-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
+++ /dev/null
-#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 <dali/integration-api/resource-cache.h>
-
-#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__
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);
}
}
}
}
-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;
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;
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;
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;
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;
/**
* @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()
/**
* @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.