Add a mechanism to specify a callback on every frame
[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 <dali/public-api/common/vector-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/math/matrix.h>
26 #include <dali/public-api/math/vector3.h>
27 #include <dali/internal/common/buffer-index.h>
28 #include <dali/internal/update/manager/transform-manager.h>
29 #include <dali/internal/update/nodes/node.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 /**
38  * @brief The implementation of Dali::UpdateProxy.
39  *
40  * Ref-counting is not required for this object.
41  *
42  * @see Dali::UpdateProxy
43  */
44 class UpdateProxy
45 {
46 public:
47
48   /**
49    * @brief Constructor.
50    * @param[in]  transformManager   Ref to the TransformManager in order to set/get transform properties of nodes
51    * @param[in]  rootNode           The root node for this proxy
52    */
53   UpdateProxy( SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode );
54
55   /**
56    * @brief Destructor.
57    */
58   ~UpdateProxy();
59
60   // Movable but not copyable
61
62   UpdateProxy( const UpdateProxy& )            = delete;  ///< Deleted copy constructor.
63   UpdateProxy( UpdateProxy&& )                 = default; ///< Default move constructor.
64   UpdateProxy& operator=( const UpdateProxy& ) = delete;  ///< Deleted copy assignment operator.
65   UpdateProxy& operator=( UpdateProxy&& )      = default; ///< Default move assignment operator.
66
67   /**
68    * @copydoc Dali::UpdateProxy::GetPosition()
69    */
70   Vector3 GetPosition( unsigned int id ) const;
71
72   /**
73    * @copydoc Dali::UpdateProxy::SetPosition()
74    */
75   void SetPosition( unsigned int id, const Vector3& position );
76
77   /**
78    * @copydoc Dali::UpdateProxy::GetSize()
79    */
80   const Vector3& GetSize( unsigned int id ) const;
81
82   /**
83    * @copydoc Dali::UpdateProxy::SetSize()
84    */
85   void SetSize( unsigned int id, const Vector3& size );
86
87   /**
88    * @copydoc Dali::UpdateProxy::GetPositionAndSize()
89    */
90   void GetPositionAndSize( unsigned int id, Vector3& position, Vector3& size ) const;
91
92   /**
93    * @copydoc Dali::UpdateProxy::GetColor()
94    */
95   Vector4 GetWorldColor( unsigned int id ) const;
96
97   /**
98    * @copydoc Dali::UpdateProxy::SetColor()
99    */
100   void SetWorldColor( unsigned int id, const Vector4& color ) const;
101
102   /**
103    * @copydoc Dali::UpdateProxy::GetWorldMatrixAndSize()
104    */
105   void GetWorldMatrixAndSize( unsigned int id, Matrix& worldMatrix, Vector3& size ) const;
106
107   /**
108    * @copydoc Dali::UpdateProxy::GetWorldMatrix()
109    */
110   const Matrix& GetWorldMatrix( unsigned int id ) const;
111
112   /**
113    * @copydoc Dali::UpdateProxy::SetWorldMatrix()
114    */
115   void SetWorldMatrix( unsigned int id, const Matrix& worldMatrix );
116
117   /**
118    * @brief Retrieves the root-node used by this class
119    * @return The root node used by this class.
120    */
121   SceneGraph::Node& GetRootNode() const
122   {
123     return mRootNode;
124   }
125
126   void SetCurrentBufferIndex( BufferIndex bufferIndex )
127   {
128     mCurrentBufferIndex = bufferIndex;
129   }
130
131 private:
132
133   /**
134    * @brief Retrieves the node with the specified ID.
135    * @param[in]  id  The ID of the node required
136    * @return A pointer to the required node if found.
137    * @note This caches the last accessed node.
138    */
139   SceneGraph::Node* GetNodeWithId( unsigned int id ) const;
140
141 private:
142
143   /**
144    * Structure to store the ID & Node pair
145    */
146   struct IdNodePair
147   {
148     unsigned int id; ///< The ID of the node
149     SceneGraph::Node* node; ///< The node itself
150   };
151
152   mutable std::vector< IdNodePair > mNodeContainer; ///< Used to store cached pointers to already searched for Nodes.
153   mutable IdNodePair mLastCachedIdNodePair; ///< Used to cache the last retrieved id-node pair.
154   unsigned int mCurrentBufferIndex;
155
156   SceneGraph::TransformManager& mTransformManager; ///< Reference to the Transform Manager.
157   SceneGraph::Node& mRootNode; ///< The root node of this update proxy.
158 };
159
160 } // namespace Internal
161
162 } // namespace Dali
163
164 #endif // DALI_INTERNAL_UPDATE_PROXY_IMPL_H