Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / effects / shader-factory.cpp
index 865bdbd..c91f2ed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/platform-abstraction.h>
 #include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/effects/shader-effect-impl.h>
-#include <dali/internal/event/effects/shader-declarations.h>
-
-// compile time generated shader strings
-#include "dali-shaders.h"
 
 namespace
 {
@@ -65,14 +60,12 @@ void shaderBinaryFilename( size_t shaderHash, std::string& filename )
 
 }
 
-ShaderFactory::ShaderFactory()
-{
-}
+ShaderFactory::ShaderFactory() = default;
 
 ShaderFactory::~ShaderFactory()
 {
   // Let all the cached objects destroy themselves:
-  for( int i = 0, cacheSize = mShaderBinaryCache.Size(); i < cacheSize; ++i )
+  for( std::size_t i = 0, cacheSize = mShaderBinaryCache.Size(); i < cacheSize; ++i )
   {
     if( mShaderBinaryCache[i] )
     {
@@ -81,7 +74,7 @@ ShaderFactory::~ShaderFactory()
   }
 }
 
-ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::string& fragmentSource, size_t& shaderHash )
+ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash )
 {
   // Work out the filename for the binary that the glsl source will be compiled and linked to:
   shaderHash = CalculateHash( vertexSource.c_str(), fragmentSource.c_str() );
@@ -91,7 +84,7 @@ ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::s
   ShaderDataPtr shaderData;
 
   /// Check a cache of previously loaded shaders:
-  for( int i = 0, cacheSize = mShaderBinaryCache.Size(); i < cacheSize; ++i )
+  for( std::size_t i = 0, cacheSize = mShaderBinaryCache.Size(); i < cacheSize; ++i )
   {
     if( mShaderBinaryCache[i]->GetHashValue() == shaderHash )
     {
@@ -103,10 +96,10 @@ ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::s
   }
 
   // If memory cache failed check the file system for a binary or return a source-only ShaderData:
-  if( shaderData.Get() == NULL )
+  if( shaderData.Get() == nullptr )
   {
     // Allocate the structure that returns the loaded shader:
-    shaderData = new ShaderData( vertexSource, fragmentSource );
+    shaderData = new ShaderData( vertexSource, fragmentSource, hints );
     shaderData->SetHashValue( shaderHash );
     shaderData->GetBuffer().Clear();
 
@@ -137,7 +130,7 @@ void ShaderFactory::SaveBinary( Internal::ShaderDataPtr shaderData )
 
   ThreadLocalStorage& tls = ThreadLocalStorage::Get();
   Integration::PlatformAbstraction& platformAbstraction = tls.GetPlatformAbstraction();
-  const bool saved = platformAbstraction.SaveShaderBinaryFile( binaryShaderFilename, &shaderData->GetBuffer()[0], shaderData->GetBufferSize() );
+  const bool saved = platformAbstraction.SaveShaderBinaryFile( binaryShaderFilename, &shaderData->GetBuffer()[0], static_cast<unsigned int>( shaderData->GetBufferSize() ) ); // don't expect buffer larger than unsigned int
 
   // Save the binary into to memory cache:
   MemoryCacheInsert( *shaderData );
@@ -146,11 +139,6 @@ void ShaderFactory::SaveBinary( Internal::ShaderDataPtr shaderData )
   if( saved ) {} // Avoid unused variable warning in release builds
 }
 
-void ShaderFactory::LoadDefaultShaders()
-{
-  mDefaultShader = ShaderEffect::New();
-}
-
 void ShaderFactory::MemoryCacheInsert( ShaderData& shaderData )
 {
   DALI_ASSERT_DEBUG( shaderData.GetBufferSize() > 0 );