X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fcommon%2Funiform-map.h;h=0a505ded17fb93369e07d9d342d81a294f6ebb3d;hb=df66eaa6145d1d1ec9c43f49b7595b9cb359d336;hp=2df39e2c5a2d5fefbe20dad7ce659eaeddd26e7a;hpb=0db05961b8c65b81ab2e8795f3264cd6fb5cc919;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/common/uniform-map.h b/dali/internal/update/common/uniform-map.h index 2df39e2..0a505de 100644 --- a/dali/internal/update/common/uniform-map.h +++ b/dali/internal/update/common/uniform-map.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -18,12 +18,13 @@ */ // EXTERNAL INCLUDES -#include #include // uint32_t +#include // INTERNAL INCLUDES #include #include +#include namespace Dali { @@ -33,7 +34,6 @@ class PropertyInputImpl; namespace SceneGraph { - /** * The uniform map is used to map a uniform name to a property value. */ @@ -45,24 +45,39 @@ public: /** * 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), + uniformNameHash(0u), + uniformNameHashNoArray(0u), + arrayIndex(0u) { + // Look for array index closing bracket + auto nameStringView = theUniformName.GetStringView(); + auto pos = nameStringView.rfind("]"); + + // If found, extract the array index and store it, if it's an element in an array of basic types. + if(pos != std::string::npos) + { + auto pos0 = theUniformName.GetStringView().rfind("[", pos); + if(pos == nameStringView.length() - 1) // if element is in struct, don't set array index. + { + arrayIndex = atoi(theUniformName.GetCString() + pos0 + 1); + } + // Calculate hash from name without array index + uniformNameHashNoArray = Dali::CalculateHash(theUniformName.GetStringView().substr(0, pos0).data(), '['); + } + uniformName = theUniformName; + uniformNameHash = Dali::CalculateHash(theUniformName.GetCString()); } + UniformPropertyMapping() = default; - const PropertyInputImpl* propertyPtr; - std::string uniformName; - Hash uniformNameHash; + const PropertyInputImpl* propertyPtr{nullptr}; + ConstString uniformName{}; + Hash uniformNameHash{0u}; + Hash uniformNameHashNoArray{0u}; + int32_t arrayIndex{0u}; }; /** @@ -80,7 +95,6 @@ public: class Observer { public: - /** * Inform observer that uniform mappings have been changed * @param mappings @@ -88,7 +102,6 @@ public: virtual void UniformMappingsChanged(const UniformMap& mappings) = 0; protected: - /** * Virtual destructor, no deletion through this interface */ @@ -96,40 +109,30 @@ public: }; /** - * Constructor - */ - UniformMap(); - - /** - * Destructor - */ - ~UniformMap(); - - /** * Add an observer that watches for changes in the mappings */ - void AddObserver( Observer& observer ); + void AddObserver(Observer& observer); /** * Remove an observer */ - void RemoveObserver( Observer& observer ); + void RemoveObserver(Observer& observer); /** * Add a map to the mappings table. */ - void Add( UniformPropertyMapping* map ); + void Add(UniformPropertyMapping map); /** * 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 @@ -142,7 +145,7 @@ public: * @param[in] index The index of the element to fetch * @return reference to the element in the map */ - const UniformPropertyMapping& operator[]( SizeType index ) const; + const UniformPropertyMapping& operator[](SizeType index) const; private: /** @@ -151,7 +154,7 @@ private: void MappingChanged(); private: - using UniformMapContainer = OwnerContainer; + using UniformMapContainer = Dali::Vector; using UniformMapIter = UniformMapContainer::Iterator; using Observers = Dali::Vector; using ObserversIter = Observers::Iterator; @@ -161,7 +164,6 @@ private: Observers mObservers; }; - } // namespace SceneGraph } // namespace Internal } // namespace Dali