Refactor UniformMap, PropertyOwner and Program to use ConstString 69/248569/5
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Mon, 30 Nov 2020 05:52:58 +0000 (14:52 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Tue, 1 Dec 2020 04:33:41 +0000 (13:33 +0900)
Change-Id: Ie3c8048a57ad667f4f8e557ba1cc4ec19b2d686f

14 files changed:
dali/internal/event/common/object-impl.cpp
dali/internal/event/rendering/vertex-buffer-impl.cpp
dali/internal/render/renderers/render-geometry.cpp
dali/internal/render/renderers/render-vertex-buffer.h
dali/internal/render/shaders/program.cpp
dali/internal/render/shaders/program.h
dali/internal/update/common/property-owner-messages.h
dali/internal/update/common/property-owner.cpp
dali/internal/update/common/property-owner.h
dali/internal/update/common/uniform-map.cpp
dali/internal/update/common/uniform-map.h
dali/internal/update/nodes/node.cpp
dali/internal/update/nodes/node.h
dali/internal/update/rendering/scene-graph-renderer.cpp

index 811d3fa..b117b09 100644 (file)
@@ -34,6 +34,7 @@
 #include <dali/internal/event/common/property-notification-impl.h>
 #include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/event/common/type-registry-impl.h>
+#include <dali/internal/common/const-string.h>
 
 using Dali::Internal::SceneGraph::AnimatableProperty;
 using Dali::Internal::SceneGraph::PropertyBase;
@@ -803,7 +804,7 @@ void Object::AddUniformMapping(Property::Index propertyIndex, std::string unifor
     const SceneGraph::PropertyOwner& sceneObject = GetSceneObject();
 
     OwnerPointer<SceneGraph::UniformPropertyMapping> map =
-      new SceneGraph::UniformPropertyMapping(std::move(uniformName), propertyPtr);
+      new SceneGraph::UniformPropertyMapping(ConstString(uniformName), propertyPtr);
     // Message takes ownership of Uniform map (and will delete it after copy)
     AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, map );
   }
@@ -812,7 +813,7 @@ void Object::AddUniformMapping(Property::Index propertyIndex, std::string unifor
 void Object::RemoveUniformMapping( const std::string& uniformName ) const
 {
   const SceneGraph::PropertyOwner& sceneObject = GetSceneObject();
-  RemoveUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, uniformName);
+  RemoveUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, ConstString(uniformName));
 }
 
 void Object::ApplyConstraint( ConstraintBase& constraint )
index 9d131c7..bce5aab 100644 (file)
@@ -215,7 +215,7 @@ void VertexBuffer::Initialize( Dali::Property::Map& formatMap )
     {
       continue;
     }
-    format->components[i].name = component.first.stringKey;
+    format->components[i].name = ConstString(component.first.stringKey);
 
     // enums are stored in the map as int
     Property::Type type = Property::Type( component.second.Get<int>() );
index d3a2809..0f0a70a 100644 (file)
@@ -87,13 +87,13 @@ void Geometry::GetAttributeLocationFromProgram( Vector<GLint>& attributeLocation
     const uint32_t attributeCount = vertexBuffer->GetAttributeCount();
     for( uint32_t j = 0; j < attributeCount; ++j )
     {
-      const std::string& attributeName = vertexBuffer->GetAttributeName( j );
+      auto attributeName = vertexBuffer->GetAttributeName( j );
       uint32_t index = program.RegisterCustomAttribute( attributeName );
       GLint location = program.GetCustomAttributeLocation( index );
 
       if( -1 == location )
       {
-        DALI_LOG_WARNING( "Attribute not found in the shader: %s\n", attributeName.c_str() );
+        DALI_LOG_WARNING( "Attribute not found in the shader: %s\n", attributeName.GetCString() );
       }
 
       attributeLocation.PushBack( location );
index f2b02b8..37d2aeb 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/internal/common/owner-pointer.h>
 #include <dali/internal/render/renderers/render-sampler.h>
 #include <dali/internal/render/gl-resources/gpu-buffer.h>
+#include <dali/internal/common/const-string.h>
 
 namespace Dali
 {
@@ -38,7 +39,7 @@ public:
 
   struct Component
   {
-    std::string    name;
+    ConstString    name;
     uint32_t       offset;
     uint32_t       size;
     Property::Type type;
@@ -124,7 +125,7 @@ public:
    * @param[in] index The index of the attribute
    * @return The name of the attribute
    */
-  inline const std::string& GetAttributeName( uint32_t index ) const
+  inline ConstString GetAttributeName( uint32_t index ) const
   {
     DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
     return mFormat->components[index].name;
index 246d0fe..fe333dd 100755 (executable)
@@ -144,7 +144,7 @@ GLint Program::GetAttribLocation( AttribType type )
   return GetCustomAttributeLocation( type );
 }
 
-uint32_t Program::RegisterCustomAttribute( const std::string& name )
+uint32_t Program::RegisterCustomAttribute( ConstString name )
 {
   uint32_t index = 0;
   // find the value from cache
@@ -171,17 +171,17 @@ GLint Program::GetCustomAttributeLocation( uint32_t attributeIndex )
 
   if( location == ATTRIB_UNKNOWN )
   {
-    location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetAttribLocation( mProgramId, mAttributeLocations[ attributeIndex ].first.c_str() ) );
+    location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetAttribLocation( mProgramId, mAttributeLocations[ attributeIndex ].first.GetCString() ) );
 
     mAttributeLocations[ attributeIndex ].second = location;
-    LOG_GL( "GetAttributeLocation(program=%d,%s) = %d\n", mProgramId, mAttributeLocations[ attributeIndex ].first.c_str(), mAttributeLocations[ attributeIndex ].second );
+    LOG_GL( "GetAttributeLocation(program=%d,%s) = %d\n", mProgramId, mAttributeLocations[ attributeIndex ].first.GetCString(), mAttributeLocations[ attributeIndex ].second );
   }
 
   return location;
 }
 
 
-uint32_t Program::RegisterUniform( const std::string& name )
+uint32_t Program::RegisterUniform( ConstString name )
 {
   uint32_t index = 0;
   // find the value from cache
@@ -208,10 +208,10 @@ GLint Program::GetUniformLocation( uint32_t uniformIndex )
 
   if( location == UNIFORM_NOT_QUERIED )
   {
-    location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetUniformLocation( mProgramId, mUniformLocations[ uniformIndex ].first.c_str() ) );
+    location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetUniformLocation( mProgramId, mUniformLocations[ uniformIndex ].first.GetCString() ) );
 
     mUniformLocations[ uniformIndex ].second = location;
-    LOG_GL( "GetUniformLocation(program=%d,%s) = %d\n", mProgramId, mUniformLocations[ uniformIndex ].first.c_str(), mUniformLocations[ uniformIndex ].second );
+    LOG_GL( "GetUniformLocation(program=%d,%s) = %d\n", mProgramId, mUniformLocations[ uniformIndex ].first.GetCString(), mUniformLocations[ uniformIndex ].second );
   }
 
   return location;
@@ -645,7 +645,7 @@ Program::Program( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool
   mAttributeLocations.reserve( ATTRIB_TYPE_LAST );
   for( uint32_t i = 0; i < ATTRIB_TYPE_LAST; ++i )
   {
-    RegisterCustomAttribute( gStdAttribs[i] );
+    RegisterCustomAttribute( ConstString(gStdAttribs[i]) );
   }
 
   // reserve space for standard uniforms
@@ -653,7 +653,7 @@ Program::Program( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool
   // reset built in uniform names in cache
   for( uint32_t i = 0; i < UNIFORM_TYPE_LAST; ++i )
   {
-    RegisterUniform( gStdUniforms[ i ] );
+    RegisterUniform( ConstString(gStdUniforms[ i ]) );
   }
 
   // reset values
index 0913989..acdec12 100644 (file)
@@ -27,6 +27,7 @@
 #include <dali/public-api/object/ref-object.h>
 #include <dali/integration-api/gl-abstraction.h>
 #include <dali/internal/common/shader-data.h>
+#include <dali/internal/common/const-string.h>
 
 namespace Dali
 {
@@ -130,7 +131,7 @@ public:
    * @param [in] name attribute name
    * @return the index of the attribute name in local cache
    */
-  uint32_t RegisterCustomAttribute( const std::string& name );
+  uint32_t RegisterCustomAttribute( ConstString name );
 
   /**
    * Gets the location of a pre-registered attribute.
@@ -144,7 +145,7 @@ public:
    * @param [in] name uniform name
    * @return the index of the uniform name in local cache
    */
-  uint32_t RegisterUniform( const std::string& name );
+  uint32_t RegisterUniform( ConstString name );
 
   /**
    * Gets the location of a pre-registered uniform.
@@ -373,7 +374,7 @@ private:  // Data
   Internal::ShaderDataPtr mProgramData;       ///< Shader program source and binary (when compiled & linked or loaded)
 
   // location caches
-  using NameLocationPair = std::pair<std::string, GLint>;
+  using NameLocationPair = std::pair<ConstString, GLint>;
   using Locations        = std::vector<NameLocationPair>;
 
   Locations mAttributeLocations;      ///< attribute location cache
index db5759d..ebfb567 100644 (file)
@@ -26,6 +26,7 @@
 #include <dali/internal/event/common/property-input-impl.h>
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
+#include <dali/internal/common/const-string.h>
 
 namespace Dali
 {
@@ -263,9 +264,9 @@ inline void AddUniformMapMessage( EventThreadServices& eventThreadServices, cons
   new (slot) LocalType( &owner, &PropertyOwner::AddUniformMapping, map );
 }
 
-inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const std::string& uniformName )
+inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, ConstString uniformName )
 {
-  using LocalType = MessageValue1<PropertyOwner, std::string>;
+  using LocalType = MessageValue1<PropertyOwner, ConstString>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
index 8d560ca..7398de3 100644 (file)
@@ -24,6 +24,7 @@
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
+#include <dali/internal/common/const-string.h>
 
 namespace Dali
 {
@@ -157,7 +158,7 @@ void PropertyOwner::AddUniformMapping( OwnerPointer< UniformPropertyMapping >& m
   mUniformMaps.Add( map.Release() );
 }
 
-void PropertyOwner::RemoveUniformMapping( const std::string& uniformName )
+void PropertyOwner::RemoveUniformMapping( const ConstString& uniformName )
 {
   mUniformMaps.Remove( uniformName );
 }
index d8f3330..677b81c 100644 (file)
@@ -26,6 +26,7 @@
 #include <dali/internal/update/common/scene-graph-buffers.h>
 #include <dali/internal/update/common/uniform-map.h>
 #include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
+#include <dali/internal/common/const-string.h>
 
 
 namespace Dali
@@ -205,7 +206,7 @@ public:
   /**
    * @copydoc UniformMap::Remove
    */
-  virtual void RemoveUniformMapping( const std::string& uniformName );
+  virtual void RemoveUniformMapping( const ConstString& uniformName );
 
   /**
    * Get the mappings table
index c68ac13..3f72540 100644 (file)
@@ -23,12 +23,6 @@ namespace Internal
 {
 namespace SceneGraph
 {
-UniformMap::UniformMap() = default;
-
-UniformMap::~UniformMap()
-{
-  // Nothing to do - let the owner container delete the maps
-}
 
 void UniformMap::AddObserver( Observer& observer )
 {
@@ -70,8 +64,6 @@ void UniformMap::MappingChanged()
 
 void UniformMap::Add( UniformPropertyMapping* newMap )
 {
-  UniformPropertyMapping::Hash nameHash = CalculateHash( newMap->uniformName );
-
   bool found = false;
 
   for( UniformMapIter iter = mUniformMaps.Begin() ;
@@ -79,15 +71,12 @@ void UniformMap::Add( UniformPropertyMapping* newMap )
        ++iter )
   {
     UniformPropertyMapping* map = *iter;
-    if( map->uniformNameHash == nameHash )
+    if( map->uniformName == newMap->uniformName )
     {
-      if( map->uniformName == newMap->uniformName )
-      {
-        found = true;
-        // Mapping already exists - update it.
-        map->propertyPtr = newMap->propertyPtr;
-        break;
-      }
+      found = true;
+      // Mapping already exists - update it.
+      map->propertyPtr = newMap->propertyPtr;
+      break;
     }
   }
 
@@ -100,10 +89,8 @@ void UniformMap::Add( UniformPropertyMapping* newMap )
   MappingChanged();
 }
 
-void UniformMap::Remove( const std::string& uniformName )
+void UniformMap::Remove( ConstString uniformName )
 {
-  UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
-
   bool found=false;
 
   for( UniformMapIter iter = mUniformMaps.Begin() ;
@@ -111,14 +98,11 @@ void UniformMap::Remove( const std::string& uniformName )
        ++iter )
   {
     UniformPropertyMapping* map = *iter;
-    if( map->uniformNameHash == nameHash )
+    if( map->uniformName == uniformName )
     {
-      if( map->uniformName == uniformName )
-      {
-        mUniformMaps.Erase( iter );
-        found = true;
-        break;
-      }
+      mUniformMaps.Erase( iter );
+      found = true;
+      break;
     }
   }
 
@@ -128,21 +112,16 @@ void UniformMap::Remove( const std::string& uniformName )
   }
 }
 
-const PropertyInputImpl* UniformMap::Find( const std::string& uniformName )
+const PropertyInputImpl* UniformMap::Find( ConstString uniformName )
 {
-  UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
-
   for( UniformMapIter iter = mUniformMaps.Begin() ;
        iter != mUniformMaps.End() ;
        ++iter )
   {
     UniformPropertyMapping* map = *iter;
-    if( map->uniformNameHash == nameHash )
+    if( map->uniformName == uniformName )
     {
-      if( map->uniformName == uniformName )
-      {
-        return map->propertyPtr;
-      }
+      return map->propertyPtr;
     }
   }
   return nullptr;
index 2df39e2..c243a51 100644 (file)
@@ -24,6 +24,7 @@
 // INTERNAL INCLUDES
 #include <dali/devel-api/common/hash.h>
 #include <dali/devel-api/common/owner-container.h>
+#include <dali/internal/common/const-string.h>
 
 namespace Dali
 {
@@ -40,29 +41,19 @@ namespace SceneGraph
 class UniformPropertyMapping
 {
 public:
-  using Hash = unsigned long;
-
   /**
    * Constructor
    */
-  UniformPropertyMapping(std::string theUniformName, const PropertyInputImpl* thePropertyPtr)
+  UniformPropertyMapping(ConstString theUniformName, const PropertyInputImpl* thePropertyPtr)
   : propertyPtr(thePropertyPtr),
-    uniformName(std::move(theUniformName)),
-    uniformNameHash(Dali::CalculateHash(theUniformName))
-  {
-  }
-
-  UniformPropertyMapping()
-  : propertyPtr( nullptr ),
-    uniformName( "" ),
-    uniformNameHash( 0 )
+    uniformName(theUniformName)
   {
   }
 
+  UniformPropertyMapping() = default;
 
-  const PropertyInputImpl* propertyPtr;
-  std::string uniformName;
-  Hash uniformNameHash;
+  const PropertyInputImpl* propertyPtr{nullptr};
+  ConstString uniformName;
 };
 
 /**
@@ -96,16 +87,6 @@ public:
   };
 
   /**
-   * Constructor
-   */
-  UniformMap();
-
-  /**
-   * Destructor
-   */
-  ~UniformMap();
-
-  /**
    * Add an observer that watches for changes in the mappings
    */
   void AddObserver( Observer& observer );
@@ -123,13 +104,13 @@ public:
   /**
    * Remove a map from the mappings table
    */
-  void Remove( const std::string& uniformName );
+  void Remove( ConstString uniformName );
 
   /**
    * Find a property given the uniform name.
    * @return The address of the property if it's in the map, or NULL otherwise.
    */
-  const PropertyInputImpl* Find( const std::string& uniformName );
+  const PropertyInputImpl* Find( ConstString uniformName );
 
   /**
    * Get the count of uniforms in the map
index ae6dd7f..6cbf519 100755 (executable)
@@ -182,7 +182,7 @@ void Node::AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map )
   mRegenerateUniformMap = 2;
 }
 
-void Node::RemoveUniformMapping( const std::string& uniformName )
+void Node::RemoveUniformMapping( const ConstString& uniformName )
 {
   PropertyOwner::RemoveUniformMapping( uniformName );
   mRegenerateUniformMap = 2;
index 7e5a05d..6377a5f 100644 (file)
@@ -803,7 +803,7 @@ public:
   /**
    * @copydoc UniformMap::Remove
    */
-  void RemoveUniformMapping( const std::string& uniformName ) override;
+  void RemoveUniformMapping( const ConstString& uniformName ) override;
 
   /**
    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::IsAnimationPossible
index cce7464..e8d9cd9 100644 (file)
@@ -60,19 +60,15 @@ void AddMappings( CollectedUniformMap& localMap, const UniformMap& uniformMap )
 
   for( UniformMap::SizeType i = 0, count=uniformMap.Count(); i<count; ++i )
   {
-    UniformPropertyMapping::Hash nameHash = uniformMap[i].uniformNameHash;
     bool found = false;
 
     for( CollectedUniformMap::Iterator iter = localMap.Begin() ; iter != localMap.End() ; ++iter )
     {
       const UniformPropertyMapping* map = (*iter);
-      if( map->uniformNameHash == nameHash )
+      if( map->uniformName == uniformMap[i].uniformName )
       {
-        if( map->uniformName == uniformMap[i].uniformName )
-        {
-          found = true;
-          break;
-        }
+        found = true;
+        break;
       }
     }
     if( !found )