82940716f8ba6f1a96120d956d60bb325b42d149
[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) 2021 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/vector-wrapper.h>
30 #include <dali/public-api/math/matrix.h>
31 #include <dali/public-api/math/vector3.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace SceneGraph
38 {
39 class UpdateManager;
40 }
41
42 /**
43  * @brief The implementation of Dali::UpdateProxy.
44  *
45  * Ref-counting is not required for this object.
46  *
47  * @see Dali::UpdateProxy
48  */
49 class UpdateProxy
50 {
51 public:
52   /**
53    * @brief Constructor.
54    * @param[in]  updateManager      Ref to the UpdateManager in order to add property resetters
55    * @param[in]  transformManager   Ref to the TransformManager in order to set/get transform properties of nodes
56    * @param[in]  rootNode           The root node for this proxy
57    */
58   UpdateProxy(SceneGraph::UpdateManager& updateManager, SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode);
59
60   /**
61    * @brief Destructor.
62    */
63   ~UpdateProxy();
64
65   // Movable but not copyable
66
67   UpdateProxy(const UpdateProxy&) = delete;            ///< Deleted copy constructor.
68   UpdateProxy(UpdateProxy&&)      = default;           ///< Default move constructor.
69   UpdateProxy& operator=(const UpdateProxy&) = delete; ///< Deleted copy assignment operator.
70   UpdateProxy& operator=(UpdateProxy&&) = delete;      ///< Deleted move assignment operator.
71
72   /**
73    * @copydoc Dali::UpdateProxy::GetPosition()
74    */
75   bool GetPosition(uint32_t id, Vector3& position) const;
76
77   /**
78    * @copydoc Dali::UpdateProxy::SetPosition()
79    */
80   bool SetPosition(uint32_t id, const Vector3& position);
81
82   /**
83    * @copydoc Dali::UpdateProxy::BakePosition()
84    */
85   bool BakePosition(uint32_t id, const Vector3& position);
86
87   /**
88    * @copydoc Dali::UpdateProxy::GetSize()
89    */
90   bool GetSize(uint32_t id, Vector3& size) const;
91
92   /**
93    * @copydoc Dali::UpdateProxy::SetSize()
94    */
95   bool SetSize(uint32_t id, const Vector3& size);
96
97   /**
98    * @copydoc Dali::UpdateProxy::BakeSize()
99    */
100   bool BakeSize(uint32_t id, const Vector3& size);
101
102   /**
103    * @copydoc Dali::UpdateProxy::GetPositionAndSize()
104    */
105   bool GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const;
106
107   /**
108    * @copydoc Dali::UpdateProxy::GetScale()
109    */
110   bool GetScale(uint32_t id, Vector3& scale) const;
111
112   /**
113    * @copydoc Dali::UpdateProxy::SetScale()
114    */
115   bool SetScale(uint32_t id, const Vector3& scale);
116
117   /**
118    * @copydoc Dali::UpdateProxy::BakeScale()
119    */
120   bool BakeScale(uint32_t id, const Vector3& scale);
121
122   /**
123    * @copydoc Dali::UpdateProxy::GetColor()
124    */
125   bool GetColor(uint32_t id, Vector4& color) const;
126
127   /**
128    * @copydoc Dali::UpdateProxy::SetColor()
129    */
130   bool SetColor(uint32_t id, const Vector4& color);
131
132   /**
133    * @copydoc Dali::UpdateProxy::BakeColor()
134    */
135   bool BakeColor(uint32_t id, const Vector4& color);
136
137   /**
138    * @brief Retrieves the root-node used by this class
139    * @return The root node used by this class.
140    */
141   SceneGraph::Node& GetRootNode() const
142   {
143     return mRootNode;
144   }
145
146   /**
147    * @brief Sets the buffer index to use when processing the next callback.
148    * @param[in]  bufferIndex  The current buffer index
149    */
150   void SetCurrentBufferIndex(BufferIndex bufferIndex)
151   {
152     mCurrentBufferIndex = bufferIndex;
153   }
154
155   /**
156    * @brief Informs the update-proxy that the node hierarchy has changed.
157    */
158   void NodeHierarchyChanged();
159
160 private:
161   /**
162    * @brief Retrieves the node with the specified ID.
163    * @param[in]  id  The ID of the node required
164    * @return A pointer to the required node if found.
165    * @note This caches the last accessed node.
166    */
167   SceneGraph::Node* GetNodeWithId(uint32_t id) const;
168
169   /**
170    * @brief Adds a property-resetter for non-transform properties so that they can be reset to their base value every frame.
171    * @param[in]  node          The node the property belongs to
172    * @param[in]  propertyBase  The property itself
173    */
174   void AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase);
175
176 private:
177   /**
178    * Structure to store the ID & Node pair
179    */
180   struct IdNodePair
181   {
182     uint32_t          id;   ///< The ID of the node
183     SceneGraph::Node* node; ///< The node itself
184   };
185
186   class PropertyModifier;
187   using PropertyModifierPtr = std::unique_ptr<PropertyModifier>;
188
189   mutable std::vector<IdNodePair> mNodeContainer;        ///< Used to store cached pointers to already searched for Nodes.
190   mutable IdNodePair              mLastCachedIdNodePair; ///< Used to cache the last retrieved id-node pair.
191   BufferIndex                     mCurrentBufferIndex;
192
193   SceneGraph::UpdateManager&    mUpdateManager;    ///< Reference to the Update Manager.
194   SceneGraph::TransformManager& mTransformManager; ///< Reference to the Transform Manager.
195   SceneGraph::Node&             mRootNode;         ///< The root node of this update proxy.
196
197   PropertyModifierPtr mPropertyModifier; ///< To ensure non-transform property modifications reset to base values.
198 };
199
200 } // namespace Internal
201
202 } // namespace Dali
203
204 #endif // DALI_INTERNAL_UPDATE_PROXY_IMPL_H