[dali_2.3.29] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / devel-api / update / update-proxy.h
1 #ifndef DALI_UPDATE_PROXY_H
2 #define DALI_UPDATE_PROXY_H
3
4 /*
5  * Copyright (c) 2023 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
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/math/matrix.h>
27 #include <dali/public-api/math/vector3.h>
28
29 namespace Dali
30 {
31 namespace Internal DALI_INTERNAL
32 {
33 class UpdateProxy;
34 }
35
36 /**
37  * @brief This class is used to access data of the actors from the update-thread.
38  *
39  * The Actor API _CANNOT_ be called directly from the update-thread.
40  * This class can be used as a proxy to that required Actor data.
41  * An actor's data can be accessed using the Actor's Unique ID.
42  * The unique ID should be passed to the callback using this class in a thread-safe manner
43  * (as you cannot call Actor::GetId from the update-thread).
44  */
45 class DALI_CORE_API UpdateProxy
46 {
47 public:
48   /**
49    * Type to define a unique sync point.
50    */
51   using NotifySyncPoint = int;
52   static constexpr NotifySyncPoint INVALID_SYNC{-1};
53
54   /**
55    * @brief Given the Actor ID, this retrieves that Actor's local position.
56    * @param[in]   id        The Actor ID
57    * @param[out]  position  Set to the Actor's current position, if Actor ID is valid
58    * @return Whether the method call was successful or not.
59    */
60   bool GetPosition(uint32_t id, Vector3& position) const;
61
62   /**
63    * @brief Allows setting an Actor's local position from the Frame callback function for the current frame only.
64    * @param[in]  id        The Actor ID
65    * @param[in]  position  The position to set
66    * @return Whether the method call was successful or not.
67    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
68    */
69   bool SetPosition(uint32_t id, const Vector3& position);
70
71   /**
72    * @brief Allows baking an Actor's local position from the Frame callback function.
73    * @param[in]  id        The Actor ID
74    * @param[in]  position  The position to bake
75    * @return Whether the method call was successful or not.
76    * @note The value is saved so will cause undesired effects if this property is being animated.
77    */
78   bool BakePosition(uint32_t id, const Vector3& position);
79
80   /**
81    * @brief Given the Actor ID, this retrieves that Actor's local orientation.
82    * @param[in]   id        The Actor ID
83    * @param[out]  orientation  Set to the Actor's current orientation, if Actor ID is valid
84    * @return Whether the method call was successful or not.
85    */
86   bool GetOrientation(uint32_t id, Quaternion& orientation) const;
87
88   /**
89    * @brief Allows setting an Actor's local orientation from the Frame callback function for the current frame only.
90    * @param[in]  id        The Actor ID
91    * @param[in]  orientation  The orientation to set
92    * @return Whether the method call was successful or not.
93    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
94    */
95   bool SetOrientation(uint32_t id, const Quaternion& orientation);
96
97   /**
98    * @brief Allows baking an Actor's local orientation from the Frame callback function.
99    * @param[in]  id        The Actor ID
100    * @param[in]  orientation  The orientation to bake
101    * @return Whether the method call was successful or not.
102    * @note The value is saved so will cause undesired effects if this property is being animated.
103    */
104   bool BakeOrientation(uint32_t id, const Quaternion& orientation);
105
106   /**
107    * @brief Given the Actor ID, this retrieves that Actor's size.
108    * @param[in]   id    The Actor ID
109    * @param[out]  size  Set to the Actor's current size, if Actor ID is valid
110    * @return Whether the method call was successful or not.
111    */
112   bool GetSize(uint32_t id, Vector3& size) const;
113
114   /**
115    * @brief Allows setting an Actor's size from the Frame callback function for the current frame only.
116    * @param[in]  id    The Actor ID
117    * @param[in]  size  The size to set
118    * @return Whether the method call was successful or not.
119    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
120    */
121   bool SetSize(uint32_t id, const Vector3& size);
122
123   /**
124    * @brief Allows baking an Actor's size from the Frame callback function.
125    * @param[in]  id    The Actor ID
126    * @param[in]  size  The size to bake
127    * @return Whether the method call was successful or not.
128    * @note The value is saved so will cause undesired effects if this property is being animated.
129    */
130   bool BakeSize(uint32_t id, const Vector3& size);
131
132   /**
133    * @brief Given the Actor ID, this retrieves that Actor's local position and size.
134    * @param[in]   id        The Actor ID
135    * @param[out]  position  Set to the Actor's current position, if Actor ID is valid
136    * @param[out]  size      Set to the Actor's current size, if Actor ID is valid
137    * @return Whether the method call was successful or not.
138    */
139   bool GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const;
140
141   /**
142    * @brief Given the Actor ID, this retrieves that Actor's world position and size.
143    * @param[in]   id        The Actor ID
144    * @param[out]  position  Set to the Actor's current world position, if Actor ID is valid
145    * @param[out]  scale     Set to the Actor's current world scale, if Actor ID is valid
146    * @param[out]  size      Set to the Actor's current size, if Actor ID is valid
147    * @return Whether the method call was successful or not.
148    */
149   bool GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const;
150
151   /**
152    * @brief Given the Actor ID, this retrieves that Actor's world transform properties and size.
153    * @param[in]   id        The Actor ID
154    * @param[out]  position  Set to the Actor's current world position, if Actor ID is valid
155    * @param[out]  scale     Set to the Actor's current world scale, if Actor ID is valid
156    * @param[out]  orientation Set to the Actor's current world orientation, if Actor ID is valid
157    * @param[out]  size      Set to the Actor's current size, if Actor ID is valid
158    * @return Whether the method call was successful or not.
159    */
160   bool GetWorldTransformAndSize(uint32_t id, Vector3& position, Vector3& scale, Quaternion& orientation, Vector3& size) const;
161
162   /**
163    * @brief Given the Actor ID, this retrieves that Actor's local scale.
164    * @param[in]   id     The Actor ID
165    * @param[out]  scale  Set to the Actor's current scale, if Actor ID is valid
166    * @return Whether the method call was successful or not.
167    */
168   bool GetScale(uint32_t id, Vector3& scale) const;
169
170   /**
171    * @brief Allows setting an Actor's local scale from the Frame callback function for the current frame only.
172    * @param[in]  id     The Actor ID
173    * @param[in]  scale  The scale to set
174    * @return Whether the method call was successful or not.
175    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
176    */
177   bool SetScale(uint32_t id, const Vector3& scale);
178
179   /**
180    * @brief Allows baking an Actor's local scale from the Frame callback function.
181    * @param[in]  id     The Actor ID
182    * @param[in]  scale  The scale to bake
183    * @return Whether the method call was successful or not.
184    * @note The value is saved so will cause undesired effects if this property is being animated.
185    */
186   bool BakeScale(uint32_t id, const Vector3& scale);
187
188   /**
189    * @brief Given the Actor ID, this retrieves that Actor's local color.
190    * @param[in]   id     The Actor ID
191    * @param[out]  color  Set to the Actor's current color, if Actor ID is valid
192    * @return Whether the method call was successful or not.
193    */
194   bool GetColor(uint32_t id, Vector4& color) const;
195
196   /**
197    * @brief Allows setting an Actor's local color from the Frame callback function for the current frame only.
198    * @param[in]  id     The Actor ID
199    * @param[in]  color  The color to set
200    * @return Whether the method call was successful or not.
201    * @note This will get reset to the internally calculated or previously baked value in the next frame, so will have to be set again.
202    */
203   bool SetColor(uint32_t id, const Vector4& color);
204
205   /**
206    * @brief Allows baking an Actor's local color from the Frame callback function.
207    * @param[in]  id     The Actor ID
208    * @param[in]  color  The color to bake
209    * @return Whether the method call was successful or not.
210    * @note The value is saved so will cause undesired effects if this property is being animated.
211    */
212   bool BakeColor(uint32_t id, const Vector4& color);
213
214   /**
215    * @brief Pop a sync point off the stack.
216    *
217    * Sync points can be added from the event side using Dali::DevelStage::NotifyFrameCallback().
218    * @return INVALID_SYNC if there was no SyncPoint, or a unique value if there was a sync point.
219    */
220   NotifySyncPoint PopSyncPoint();
221
222   /**
223    * @brief Given the Actor ID, Gets the updated area of the actor.
224    *
225    * @param[in]   id     The Actor ID
226    * @param[out]  updateArea  Get to the Actor's current updated area, if Actor ID is valid
227    * @return Whether the method call was successful or not.
228    */
229   bool GetUpdateArea(uint32_t id, Vector4& updateArea) const;
230
231   /**
232    * @brief Given the Actor ID, Sets the updated area of the actor.
233    *
234    * @param[in]   id     The Actor ID
235    * @param[in]   updateArea  Set to the Actor's current updated area, if Actor ID is valid
236    * @return Whether the method call was successful or not.
237    */
238   bool SetUpdateArea(uint32_t id, const Vector4& updateArea);
239
240 public: // Not intended for application developers
241   /// @cond internal
242
243   /**
244    * @brief Constructor.
245    * @param[in]  impl  A reference to the internal object.
246    */
247   DALI_INTERNAL UpdateProxy(Internal::UpdateProxy& impl);
248
249   /**
250    * @brief Destructor.
251    */
252   DALI_INTERNAL ~UpdateProxy();
253
254   // Not copyable or movable
255
256   UpdateProxy(const UpdateProxy&) = delete;            ///< Deleted copy constructor
257   UpdateProxy(UpdateProxy&&)      = delete;            ///< Deleted move constructor
258   UpdateProxy& operator=(const UpdateProxy&) = delete; ///< Deleted copy assignment operator
259   UpdateProxy& operator=(UpdateProxy&&) = delete;      ///< Deleted move assignment operator
260
261   /// @endcond
262
263 private:
264   /// @cond internal
265   Internal::UpdateProxy& mImpl;
266   /// @endcond
267 };
268
269 } // namespace Dali
270
271 #endif // DALI_UPDATE_PROXY_H