1 #ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/update/nodes/node.h>
35 class NodePropertyMessageBase : public MessageBase
41 NodePropertyMessageBase(UpdateManager& updateManager);
46 ~NodePropertyMessageBase() override;
50 NodePropertyMessageBase(const NodePropertyMessageBase&);
51 NodePropertyMessageBase& operator=(const NodePropertyMessageBase& rhs);
54 UpdateManager& mUpdateManager;
58 * Templated message which bakes a Node property.
61 class NodePropertyMessage : public NodePropertyMessageBase
64 using MemberFunction = void (AnimatableProperty<P>::*)(BufferIndex, typename ParameterType<P>::PassingType);
68 * @note The node is expected to be const in the thread which sends this message.
69 * However it can be modified when Process() is called in a different thread.
70 * @param[in] eventThreadServices The object used to send messages to the scene graph
71 * @param[in] node The node.
72 * @param[in] property The property to bake.
73 * @param[in] member The member function of the object.
74 * @param[in] value The new value of the property.
76 static void Send(EventThreadServices& eventThreadServices,
78 const AnimatableProperty<P>* property,
79 MemberFunction member,
80 typename ParameterType<P>::PassingType value)
82 // Reserve some memory inside the message queue
83 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(NodePropertyMessage));
85 auto& updateManager = eventThreadServices.GetUpdateManager();
87 // Construct message in the message queue memory; note that delete should not be called on the return value
88 new(slot) NodePropertyMessage(updateManager, node, property, member, value);
90 // Non-transform property doesn't get reset. Add a resetter.
91 OwnerPointer<SceneGraph::PropertyResetterBase> resetter(
92 new SceneGraph::BakerResetter(const_cast<Node*>(node),
93 const_cast<AnimatableProperty<P>*>(property),
94 BakerResetter::Lifetime::BAKE));
95 AddResetterMessage(updateManager, resetter);
101 ~NodePropertyMessage() override = default;
104 * @copydoc MessageBase::Process
106 void Process(BufferIndex updateBufferIndex) override
108 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
114 * @note The node is expected to be const in the thread which sends this message.
115 * However it can be modified when Process() is called in a different thread.
116 * @param[in] updateManager The update-manager.
117 * @param[in] node The node.
118 * @param[in] property The property to bake.
119 * @param[in] member The member function of the object.
120 * @param[in] value The new value of the property.
122 NodePropertyMessage(UpdateManager& updateManager,
124 const AnimatableProperty<P>* property,
125 MemberFunction member,
126 typename ParameterType<P>::PassingType value)
127 : NodePropertyMessageBase(updateManager),
128 mNode(const_cast<Node*>(node)),
129 mProperty(const_cast<AnimatableProperty<P>*>(property)),
130 mMemberFunction(member),
137 AnimatableProperty<P>* mProperty;
138 MemberFunction mMemberFunction;
139 typename ParameterType<P>::HolderType mParam;
143 * Templated message which bakes a Node property.
146 class NodePropertyComponentMessage : public NodePropertyMessageBase
149 using MemberFunction = void (AnimatableProperty<P>::*)(BufferIndex, float);
153 * @note The node is expected to be const in the thread which sends this message.
154 * However it can be modified when Process() is called in a different thread.
155 * @param[in] eventThreadServices The object used to send messages to the scene graph
156 * @param[in] node The node.
157 * @param[in] property The property to bake.
158 * @param[in] member The member function of the object.
159 * @param[in] value The new value of the X,Y,Z or W component.
161 static void Send(EventThreadServices& eventThreadServices,
163 const AnimatableProperty<P>* property,
164 MemberFunction member,
167 // Reserve some memory inside the message queue
168 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(NodePropertyComponentMessage));
170 auto& updateManager = eventThreadServices.GetUpdateManager();
172 // Construct message in the message queue memory; note that delete should not be called on the return value
173 new(slot) NodePropertyComponentMessage(updateManager, node, property, member, value);
175 // Non-transform property doesn't get reset. Add a resetter.
176 OwnerPointer<SceneGraph::PropertyResetterBase> resetter(
177 new SceneGraph::BakerResetter(const_cast<Node*>(node),
178 const_cast<AnimatableProperty<P>*>(property),
179 BakerResetter::Lifetime::BAKE));
180 AddResetterMessage(updateManager, resetter);
186 ~NodePropertyComponentMessage() override = default;
189 * @copydoc MessageBase::Process
191 void Process(BufferIndex updateBufferIndex) override
193 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
199 * @note The node is expected to be const in the thread which sends this message.
200 * However it can be modified when Process() is called in a different thread.
201 * @param[in] updateManager The update-manager.
202 * @param[in] node The node.
203 * @param[in] property The property to bake.
204 * @param[in] member The member function of the object.
205 * @param[in] value The new value of the X,Y,Z or W component.
207 NodePropertyComponentMessage(UpdateManager& updateManager,
209 const AnimatableProperty<P>* property,
210 MemberFunction member,
212 : NodePropertyMessageBase(updateManager),
213 mNode(const_cast<Node*>(node)),
214 mProperty(const_cast<AnimatableProperty<P>*>(property)),
215 mMemberFunction(member),
222 AnimatableProperty<P>* mProperty;
223 MemberFunction mMemberFunction;
228 class NodeTransformPropertyMessage : public NodePropertyMessageBase
231 using MemberFunction = void (TransformManagerPropertyHandler<P>::*)(BufferIndex, const P&);
235 * @note The node is expected to be const in the thread which sends this message.
236 * However it can be modified when Process() is called in a different thread.
237 * @param[in] eventThreadServices The object used to send messages to the scene graph
238 * @param[in] node The node.
239 * @param[in] property The property to bake.
240 * @param[in] member The member function of the object.
241 * @param[in] value The new value of the property.
243 static void Send(EventThreadServices& eventThreadServices,
245 const TransformManagerPropertyHandler<P>* property,
246 MemberFunction member,
249 // Reserve some memory inside the message queue
250 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(NodeTransformPropertyMessage));
252 // Construct message in the message queue memory; note that delete should not be called on the return value
253 new(slot) NodeTransformPropertyMessage(eventThreadServices.GetUpdateManager(), node, property, member, value);
259 ~NodeTransformPropertyMessage() override = default;
262 * @copydoc MessageBase::Process
264 void Process(BufferIndex updateBufferIndex) override
266 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
272 * @note The node is expected to be const in the thread which sends this message.
273 * However it can be modified when Process() is called in a different thread.
274 * @param[in] updateManager The update-manager.
275 * @param[in] node The node.
276 * @param[in] property The property to bake.
277 * @param[in] member The member function of the object.
278 * @param[in] value The new value of the property.
280 NodeTransformPropertyMessage(UpdateManager& updateManager,
282 const TransformManagerPropertyHandler<P>* property,
283 MemberFunction member,
285 : NodePropertyMessageBase(updateManager),
286 mNode(const_cast<Node*>(node)),
287 mProperty(const_cast<TransformManagerPropertyHandler<P>*>(property)),
288 mMemberFunction(member),
295 TransformManagerPropertyHandler<P>* mProperty;
296 MemberFunction mMemberFunction;
301 class NodeTransformComponentMessage : public NodePropertyMessageBase
304 using MemberFunction = void (TransformManagerPropertyHandler<P>::*)(BufferIndex, float);
308 * @note The node is expected to be const in the thread which sends this message.
309 * However it can be modified when Process() is called in a different thread.
310 * @param[in] eventThreadServices The object used to send messages to the scene graph
311 * @param[in] node The node.
312 * @param[in] property The property to bake.
313 * @param[in] member The member function of the object.
314 * @param[in] value The new value of the X,Y,Z or W component.
316 static void Send(EventThreadServices& eventThreadServices,
318 const TransformManagerPropertyHandler<P>* property,
319 MemberFunction member,
322 // Reserve some memory inside the message queue
323 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(NodeTransformComponentMessage));
325 // Construct message in the message queue memory; note that delete should not be called on the return value
326 new(slot) NodeTransformComponentMessage(eventThreadServices.GetUpdateManager(), node, property, member, value);
332 ~NodeTransformComponentMessage() override = default;
335 * @copydoc MessageBase::Process
337 void Process(BufferIndex updateBufferIndex) override
339 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
345 * @note The node is expected to be const in the thread which sends this message.
346 * However it can be modified when Process() is called in a different thread.
347 * @param[in] updateManager The update-manager.
348 * @param[in] node The node.
349 * @param[in] property The property to bake.
350 * @param[in] member The member function of the object.
351 * @param[in] value The new value of the X,Y,Z or W component.
353 NodeTransformComponentMessage(UpdateManager& updateManager,
355 const TransformManagerPropertyHandler<P>* property,
356 MemberFunction member,
358 : NodePropertyMessageBase(updateManager),
359 mNode(const_cast<Node*>(node)),
360 mProperty(const_cast<TransformManagerPropertyHandler<P>*>(property)),
361 mMemberFunction(member),
368 TransformManagerPropertyHandler<P>* mProperty;
369 MemberFunction mMemberFunction;
373 } // namespace SceneGraph
375 } // namespace Internal
379 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H