Simplifying UniformMap updating
[platform/core/uifw/dali-core.git] / dali / internal / update / common / collected-uniform-map.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_COLLECTED_UNIFORM_MAP_H
2 #define DALI_INTERNAL_SCENE_GRAPH_COLLECTED_UNIFORM_MAP_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 #include <dali/internal/common/buffer-index.h>
20 #include <dali/internal/update/common/uniform-map.h>
21 #include <dali/public-api/common/dali-vector.h>
22
23 namespace Dali
24 {
25 namespace Internal
26 {
27 namespace SceneGraph
28 {
29 class UniformMap;
30 class UniformPropertyMapping;
31
32 /**
33  * Class to collect uniform mappings together into a new map.
34  * Distinct from UniformMap, as it doesn't need the observation/lifecycle
35  * overhead.
36  *
37  * It has a counter that increments each time it's changed, which
38  * allows a client to know if it's been modified since the last time
39  * the client checked.
40  */
41 struct CollectedUniformMap
42 {
43   /**
44    * Constructor
45    */
46   CollectedUniformMap() = default;
47
48   /**
49    * Destructor
50    */
51   ~CollectedUniformMap() = default;
52
53   /**
54    * @brief Add mappings from a UniformMap.
55    * @param[in] uniformMap to copy
56    */
57   void AddMappings(const UniformMap& uniformMap);
58
59   /**
60    * Clear the mappings
61    */
62   inline void Clear()
63   {
64     mUniformMap.Clear();
65     UpdateChangeCounter();
66   }
67
68   /**
69    * Reserve space for mappings
70    * @param[in] size The number of mappings to reserve
71    */
72   inline void Reserve(std::size_t size)
73   {
74     mUniformMap.Reserve(size);
75   }
76
77   /**
78    * @return the count of the number of mappings
79    */
80   inline std::size_t Count() const
81   {
82     return mUniformMap.Size();
83   }
84
85   /**
86    * @brief Update the change counter if the map changes.
87    */
88   void UpdateChangeCounter()
89   {
90     ++mChangeCounter;
91   }
92
93   /**
94    * Return the currently calculated hash.
95    */
96   inline std::size_t GetChangeCounter() const
97   {
98     return mChangeCounter;
99   }
100
101   Dali::Vector<UniformPropertyMapping> mUniformMap;        ///< The mappings
102   std::size_t                          mChangeCounter{0u}; ///< The change counter
103 };
104
105 } // namespace SceneGraph
106 } // namespace Internal
107 } // namespace Dali
108
109 #endif // DALI_INTERNAL_SCENE_GRAPH_COLLECTED_UNIFORM_MAP_H