[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-proxy-impl.h
1 #ifndef DALI_INTERNAL_UPDATE_PROXY_IMPL_H
2 #define DALI_INTERNAL_UPDATE_PROXY_IMPL_H
3
4 /*
5  * Copyright (c) 2024 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  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/common/buffer-index.h>
27 #include <dali/internal/update/manager/transform-manager.h>
28 #include <dali/internal/update/nodes/node.h>
29 #include <dali/public-api/common/list-wrapper.h>
30 #include <dali/public-api/common/vector-wrapper.h>
31 #include <dali/public-api/math/matrix.h>
32 #include <dali/public-api/math/vector3.h>
33
34 #include <dali/internal/update/manager/scene-graph-traveler-interface.h>
35
36 namespace Dali
37 {
38 namespace Internal
39 {
40 namespace SceneGraph
41 {
42 class UpdateManager;
43 }
44
45 /**
46  * @brief The implementation of Dali::UpdateProxy.
47  *
48  * Ref-counting is not required for this object.
49  *
50  * @see Dali::UpdateProxy
51  */
52 class UpdateProxy
53 {
54 public:
55   /**
56    * @brief Constructor.
57    * @param[in]  updateManager      Ref to the UpdateManager in order to add property resetters
58    * @param[in]  transformManager   Ref to the TransformManager in order to set/get transform properties of nodes
59    * @param[in]  traveler           The cache of traversal.
60    */
61   UpdateProxy(SceneGraph::UpdateManager& updateManager, SceneGraph::TransformManager& transformManager, SceneGraphTravelerInterfacePtr traveler);
62
63   /**
64    * @brief Destructor.
65    */
66   ~UpdateProxy();
67
68   // Movable but not copyable
69
70   UpdateProxy(const UpdateProxy&) = delete;            ///< Deleted copy constructor.
71   UpdateProxy(UpdateProxy&&)      = default;           ///< Default move constructor.
72   UpdateProxy& operator=(const UpdateProxy&) = delete; ///< Deleted copy assignment operator.
73   UpdateProxy& operator=(UpdateProxy&&) = delete;      ///< Deleted move assignment operator.
74
75   /**
76    * @copydoc Dali::UpdateProxy::GetPosition()
77    */
78   bool GetPosition(uint32_t id, Vector3& position) const;
79
80   /**
81    * @copydoc Dali::UpdateProxy::SetPosition()
82    */
83   bool SetPosition(uint32_t id, const Vector3& position);
84
85   /**
86    * @copydoc Dali::UpdateProxy::BakePosition()
87    */
88   bool BakePosition(uint32_t id, const Vector3& position);
89
90   /**
91    * @copydoc Dali::UpdateProxy::GetOrientation()
92    */
93   bool GetOrientation(uint32_t id, Quaternion& orientation) const;
94
95   /**
96    * @copydoc Dali::UpdateProxy::SetOrientation()
97    */
98   bool SetOrientation(uint32_t id, const Quaternion& orientation);
99
100   /**
101    * @copydoc Dali::UpdateProxy::BakeOrientation()
102    */
103   bool BakeOrientation(uint32_t id, const Quaternion& orientation);
104
105   /**
106    * @copydoc Dali::UpdateProxy::GetSize()
107    */
108   bool GetSize(uint32_t id, Vector3& size) const;
109
110   /**
111    * @copydoc Dali::UpdateProxy::SetSize()
112    */
113   bool SetSize(uint32_t id, const Vector3& size);
114
115   /**
116    * @copydoc Dali::UpdateProxy::BakeSize()
117    */
118   bool BakeSize(uint32_t id, const Vector3& size);
119
120   /**
121    * @copydoc Dali::UpdateProxy::GetPositionAndSize()
122    */
123   bool GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const;
124
125   /**
126    * @copydoc Dali::UpdateProxy::GetWorldPositionScaleAndSize()
127    */
128   bool GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const;
129
130   /**
131    * @copydoc Dali::UpdateProxy::GetWorldTransformAndSize()
132    */
133   bool GetWorldTransformAndSize(uint32_t id, Vector3& position, Vector3& scale, Quaternion& orientation, Vector3& size) const;
134
135   /**
136    * @copydoc Dali::UpdateProxy::GetScale()
137    */
138   bool GetScale(uint32_t id, Vector3& scale) const;
139
140   /**
141    * @copydoc Dali::UpdateProxy::SetScale()
142    */
143   bool SetScale(uint32_t id, const Vector3& scale);
144
145   /**
146    * @copydoc Dali::UpdateProxy::BakeScale()
147    */
148   bool BakeScale(uint32_t id, const Vector3& scale);
149
150   /**
151    * @copydoc Dali::UpdateProxy::GetColor()
152    */
153   bool GetColor(uint32_t id, Vector4& color) const;
154
155   /**
156    * @copydoc Dali::UpdateProxy::SetColor()
157    */
158   bool SetColor(uint32_t id, const Vector4& color);
159
160   /**
161    * @copydoc Dali::UpdateProxy::BakeColor()
162    */
163   bool BakeColor(uint32_t id, const Vector4& color);
164
165   /**
166    * @brief Sets the buffer index to use when processing the next callback.
167    * @param[in]  bufferIndex  The current buffer index
168    */
169   void SetCurrentBufferIndex(BufferIndex bufferIndex)
170   {
171     mCurrentBufferIndex = bufferIndex;
172   }
173
174   /**
175    * @brief Informs the update-proxy that the node hierarchy has changed.
176    */
177   void NodeHierarchyChanged();
178
179   /**
180    * @brief Inform the proxy that a sync point was requested.
181    *
182    * @param[in] syncPoint The sync point to notify with.
183    */
184   void Notify(Dali::UpdateProxy::NotifySyncPoint syncPoint);
185
186   /**
187    * @brief Get the sync point from the proxy. If there was no sync point,
188    * this returns INVALID_SYNC. It is intended that this method is only called
189    * once per Update(), so clears any stored sync point.
190    * @return Valid sync point or INVALID_SYNC
191   */
192   Dali::UpdateProxy::NotifySyncPoint PopSyncPoint();
193
194   /**
195    * @brief Adds node resetter for each dirty node whose animatable properties have been changed.
196    */
197   void AddNodeResetters();
198
199   /**
200    * @copydoc Dali::UpdateProxy::GetUpdateArea()
201    */
202   bool GetUpdateArea(uint32_t id, Vector4& updateArea) const;
203
204   /**
205    * @copydoc Dali::UpdateProxy::SetUpdateArea()
206    */
207   bool SetUpdateArea(uint32_t id, const Vector4& updateArea);
208
209 private:
210   /**
211    * @brief Retrieves the node with the specified ID.
212    * @param[in]  id  The ID of the node required
213    * @return A pointer to the required node if found.
214    * @note This caches the last accessed node.
215    */
216   SceneGraph::Node* GetNodeWithId(uint32_t id) const;
217
218   /**
219    * @brief Adds a property-resetter for non-transform properties so that they can be reset to their base value every frame.
220    * @param[in]  node          The node the property belongs to
221    * @param[in]  propertyBase  The property itself
222    */
223   void AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase);
224
225 private:
226   /**
227    * Structure to store the ID & Node pair
228    */
229   struct IdNodePair
230   {
231     uint32_t          id;   ///< The ID of the node
232     SceneGraph::Node* node; ///< The node itself
233   };
234
235   class PropertyModifier;
236   using PropertyModifierPtr = std::unique_ptr<PropertyModifier>;
237
238   mutable IdNodePair    mLastCachedIdNodePair; ///< Used to cache the last retrieved id-node pair.
239   std::vector<uint32_t> mDirtyNodes;           ///< Used to store the ID of the dirty nodes with non-transform property modifications.
240   BufferIndex           mCurrentBufferIndex;
241
242   SceneGraph::UpdateManager&     mUpdateManager;      ///< Reference to the Update Manager.
243   SceneGraph::TransformManager&  mTransformManager;   ///< Reference to the Transform Manager.
244   SceneGraphTravelerInterfacePtr mSceneGraphTraveler; ///< The cache system when we travel scene graph. (Not owned)
245
246   std::list<Dali::UpdateProxy::NotifySyncPoint> mSyncPoints;
247
248   PropertyModifierPtr mPropertyModifier; ///< To ensure non-transform property modifications reset to base values.
249 };
250
251 } // namespace Internal
252
253 } // namespace Dali
254
255 #endif // DALI_INTERNAL_UPDATE_PROXY_IMPL_H