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