From: Subhransu Mohanty Date: Mon, 30 Nov 2020 05:52:58 +0000 (+0900) Subject: Refactor UniformMap, PropertyOwner and Program to use ConstString X-Git-Tag: dali_2.0.4~6^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=221740c9e8ba6a373868d9710ef5008ff61b0676;p=platform%2Fcore%2Fuifw%2Fdali-core.git Refactor UniformMap, PropertyOwner and Program to use ConstString Change-Id: Ie3c8048a57ad667f4f8e557ba1cc4ec19b2d686f --- diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index 811d3fa..b117b09 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -34,6 +34,7 @@ #include #include #include +#include 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 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(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(GetEventThreadServices()), sceneObject, uniformName); + RemoveUniformMapMessage( const_cast(GetEventThreadServices()), sceneObject, ConstString(uniformName)); } void Object::ApplyConstraint( ConstraintBase& constraint ) diff --git a/dali/internal/event/rendering/vertex-buffer-impl.cpp b/dali/internal/event/rendering/vertex-buffer-impl.cpp index 9d131c7..bce5aab 100644 --- a/dali/internal/event/rendering/vertex-buffer-impl.cpp +++ b/dali/internal/event/rendering/vertex-buffer-impl.cpp @@ -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() ); diff --git a/dali/internal/render/renderers/render-geometry.cpp b/dali/internal/render/renderers/render-geometry.cpp index d3a2809..0f0a70a 100644 --- a/dali/internal/render/renderers/render-geometry.cpp +++ b/dali/internal/render/renderers/render-geometry.cpp @@ -87,13 +87,13 @@ void Geometry::GetAttributeLocationFromProgram( Vector& 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 ); diff --git a/dali/internal/render/renderers/render-vertex-buffer.h b/dali/internal/render/renderers/render-vertex-buffer.h index f2b02b8..37d2aeb 100644 --- a/dali/internal/render/renderers/render-vertex-buffer.h +++ b/dali/internal/render/renderers/render-vertex-buffer.h @@ -24,6 +24,7 @@ #include #include #include +#include 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; diff --git a/dali/internal/render/shaders/program.cpp b/dali/internal/render/shaders/program.cpp index 246d0fe..fe333dd 100755 --- a/dali/internal/render/shaders/program.cpp +++ b/dali/internal/render/shaders/program.cpp @@ -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 diff --git a/dali/internal/render/shaders/program.h b/dali/internal/render/shaders/program.h index 0913989..acdec12 100644 --- a/dali/internal/render/shaders/program.h +++ b/dali/internal/render/shaders/program.h @@ -27,6 +27,7 @@ #include #include #include +#include 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; + using NameLocationPair = std::pair; using Locations = std::vector; Locations mAttributeLocations; ///< attribute location cache diff --git a/dali/internal/update/common/property-owner-messages.h b/dali/internal/update/common/property-owner-messages.h index db5759d..ebfb567 100644 --- a/dali/internal/update/common/property-owner-messages.h +++ b/dali/internal/update/common/property-owner-messages.h @@ -26,6 +26,7 @@ #include #include #include +#include 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; + using LocalType = MessageValue1; // Reserve some memory inside the message queue uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); diff --git a/dali/internal/update/common/property-owner.cpp b/dali/internal/update/common/property-owner.cpp index 8d560ca..7398de3 100644 --- a/dali/internal/update/common/property-owner.cpp +++ b/dali/internal/update/common/property-owner.cpp @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include #include +#include 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 ); } diff --git a/dali/internal/update/common/property-owner.h b/dali/internal/update/common/property-owner.h index d8f3330..677b81c 100644 --- a/dali/internal/update/common/property-owner.h +++ b/dali/internal/update/common/property-owner.h @@ -26,6 +26,7 @@ #include #include #include +#include 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 diff --git a/dali/internal/update/common/uniform-map.cpp b/dali/internal/update/common/uniform-map.cpp index c68ac13..3f72540 100644 --- a/dali/internal/update/common/uniform-map.cpp +++ b/dali/internal/update/common/uniform-map.cpp @@ -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; diff --git a/dali/internal/update/common/uniform-map.h b/dali/internal/update/common/uniform-map.h index 2df39e2..c243a51 100644 --- a/dali/internal/update/common/uniform-map.h +++ b/dali/internal/update/common/uniform-map.h @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include #include +#include 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 diff --git a/dali/internal/update/nodes/node.cpp b/dali/internal/update/nodes/node.cpp index ae6dd7f..6cbf519 100755 --- a/dali/internal/update/nodes/node.cpp +++ b/dali/internal/update/nodes/node.cpp @@ -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; diff --git a/dali/internal/update/nodes/node.h b/dali/internal/update/nodes/node.h index 7e5a05d..6377a5f 100644 --- a/dali/internal/update/nodes/node.h +++ b/dali/internal/update/nodes/node.h @@ -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 diff --git a/dali/internal/update/rendering/scene-graph-renderer.cpp b/dali/internal/update/rendering/scene-graph-renderer.cpp index cce7464..e8d9cd9 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.cpp +++ b/dali/internal/update/rendering/scene-graph-renderer.cpp @@ -60,19 +60,15 @@ void AddMappings( CollectedUniformMap& localMap, const UniformMap& uniformMap ) for( UniformMap::SizeType i = 0, count=uniformMap.Count(); iuniformNameHash == nameHash ) + if( map->uniformName == uniformMap[i].uniformName ) { - if( map->uniformName == uniformMap[i].uniformName ) - { - found = true; - break; - } + found = true; + break; } } if( !found )