use std::string_view to avoid shader string duplication. 86/248886/1
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Thu, 3 Dec 2020 04:19:55 +0000 (13:19 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Thu, 3 Dec 2020 04:45:45 +0000 (13:45 +0900)
Change-Id: Iacad7e8c45d6176d2347c8ed423edd32e58de61f

dali/internal/common/shader-data.h
dali/internal/event/effects/shader-factory.cpp
dali/internal/event/effects/shader-factory.h
dali/internal/event/rendering/shader-impl.cpp
dali/internal/event/rendering/shader-impl.h
dali/public-api/rendering/shader.cpp
dali/public-api/rendering/shader.h

index 0dba6a1..97236e9 100644 (file)
@@ -48,10 +48,10 @@ public:
    * @param[in] vertexSource   Source code for vertex program
    * @param[in] fragmentSource Source code for fragment program
    */
-  ShaderData(const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints)
+  ShaderData(std::string vertexSource, std::string fragmentSource, const Dali::Shader::Hint::Value hints)
   : mShaderHash( -1 ),
-    mVertexShader(vertexSource),
-    mFragmentShader(fragmentSource),
+    mVertexShader(std::move(vertexSource)),
+    mFragmentShader(std::move(fragmentSource)),
     mHints(hints)
   { }
 
index c91f2ed..64aafe4 100644 (file)
@@ -74,10 +74,10 @@ ShaderFactory::~ShaderFactory()
   }
 }
 
-ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash )
+ShaderDataPtr ShaderFactory::Load( std::string_view vertexSource, std::string_view 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() );
+  shaderHash = CalculateHash( vertexSource.data(), fragmentSource.data() );
   std::string binaryShaderFilename;
   shaderBinaryFilename( shaderHash, binaryShaderFilename );
 
@@ -99,7 +99,7 @@ ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::s
   if( shaderData.Get() == nullptr )
   {
     // Allocate the structure that returns the loaded shader:
-    shaderData = new ShaderData( vertexSource, fragmentSource, hints );
+    shaderData = new ShaderData( std::string(vertexSource), std::string(fragmentSource), hints );
     shaderData->SetHashValue( shaderHash );
     shaderData->GetBuffer().Clear();
 
index 6cf6cf9..12e0d2b 100644 (file)
@@ -67,7 +67,7 @@ public:
    *                            a compiled shader program binary if one could be found, else an
    *                            empty binary buffer cleared to size zero.
    */
-  Internal::ShaderDataPtr Load( const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash );
+  Internal::ShaderDataPtr Load( std::string_view vertexSource, std::string_view fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash );
 
   /**
    * @brief Saves shader to memory cache and filesystem.
index aa85ac7..35698d1 100644 (file)
@@ -91,8 +91,8 @@ Property::Value HintString(const Dali::Shader::Hint::Value& hints)
 
 } // unnamed namespace
 
-ShaderPtr Shader::New( const std::string& vertexShader,
-                       const std::string& fragmentShader,
+ShaderPtr Shader::New( std::string_view vertexShader,
+                       std::string_view fragmentShader,
                        Dali::Shader::Hint::Value hints )
 {
   // create scene object first so it's guaranteed to exist for the event side
@@ -195,8 +195,8 @@ Shader::Shader( const SceneGraph::Shader* sceneObject )
 {
 }
 
-void Shader::SetShader( const std::string& vertexSource,
-                        const std::string& fragmentSource,
+void Shader::SetShader( std::string_view vertexSource,
+                        std::string_view fragmentSource,
                         Dali::Shader::Hint::Value hints )
 {
   // Try to load a pre-compiled shader binary for the source pair:
index 9476f40..0f0940e 100644 (file)
@@ -49,8 +49,8 @@ public:
   /**
    * @copydoc Dali::Shader::New()
    */
-  static ShaderPtr New( const std::string& vertexShader,
-                        const std::string& fragmentShader,
+  static ShaderPtr New( std::string_view vertexShader,
+                        std::string_view fragmentShader,
                         Dali::Shader::Hint::Value hints );
 
   /**
@@ -88,7 +88,7 @@ private: // implementation
   /**
    * Second stage initialization
    */
-  void SetShader( const std::string& vertexShader, const std::string& fragmentShader, Dali::Shader::Hint::Value hints );
+  void SetShader( std::string_view vertexShader, std::string_view fragmentShader, Dali::Shader::Hint::Value hints );
 
 protected:
   /**
index 9adf7de..c00bc8f 100644 (file)
@@ -23,8 +23,8 @@
 
 namespace Dali
 {
-Shader Shader::New(const std::string& vertexShader,
-                   const std::string& fragmentShader,
+Shader Shader::New(std::string_view vertexShader,
+                   std::string_view fragmentShader,
                    Hint::Value        hints)
 {
   Internal::ShaderPtr renderer = Internal::Shader::New(vertexShader, fragmentShader, hints);
index f20c707..39604b8 100644 (file)
@@ -124,8 +124,8 @@ public:
    * @param[in] hints Hints to define the geometry of the rendered object
    * @return A handle to a shader effect
    */
-  static Shader New(const std::string& vertexShader,
-                    const std::string& fragmentShader,
+  static Shader New(std::string_view vertexShader,
+                    std::string_view fragmentShader,
                     Hint::Value        hints = Hint::NONE);
 
   /**