1 #ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
5 * Copyright (c) 2021 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 // Construct message in the message queue memory; note that delete should not be called on the return value
86 new(slot) NodePropertyMessage(eventThreadServices.GetUpdateManager(), node, property, member, value);
92 ~NodePropertyMessage() override = default;
95 * @copydoc MessageBase::Process
97 void Process(BufferIndex updateBufferIndex) override
99 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
105 * @note The node is expected to be const in the thread which sends this message.
106 * However it can be modified when Process() is called in a different thread.
107 * @param[in] updateManager The update-manager.
108 * @param[in] node The node.
109 * @param[in] property The property to bake.
110 * @param[in] member The member function of the object.
111 * @param[in] value The new value of the property.
113 NodePropertyMessage(UpdateManager& updateManager,
115 const AnimatableProperty<P>* property,
116 MemberFunction member,
117 typename ParameterType<P>::PassingType value)
118 : NodePropertyMessageBase(updateManager),
119 mNode(const_cast<Node*>(node)),
120 mProperty(const_cast<AnimatableProperty<P>*>(property)),
121 mMemberFunction(member),
128 AnimatableProperty<P>* mProperty;
129 MemberFunction mMemberFunction;
130 typename ParameterType<P>::HolderType mParam;
134 * Templated message which bakes a Node property.
137 class NodePropertyComponentMessage : public NodePropertyMessageBase
140 using MemberFunction = void (AnimatableProperty<P>::*)(BufferIndex, float);
144 * @note The node is expected to be const in the thread which sends this message.
145 * However it can be modified when Process() is called in a different thread.
146 * @param[in] eventThreadServices The object used to send messages to the scene graph
147 * @param[in] node The node.
148 * @param[in] property The property to bake.
149 * @param[in] member The member function of the object.
150 * @param[in] value The new value of the X,Y,Z or W component.
152 static void Send(EventThreadServices& eventThreadServices,
154 const AnimatableProperty<P>* property,
155 MemberFunction member,
158 // Reserve some memory inside the message queue
159 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(NodePropertyComponentMessage));
161 // Construct message in the message queue memory; note that delete should not be called on the return value
162 new(slot) NodePropertyComponentMessage(eventThreadServices.GetUpdateManager(), node, property, member, value);
168 ~NodePropertyComponentMessage() override = default;
171 * @copydoc MessageBase::Process
173 void Process(BufferIndex updateBufferIndex) override
175 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
181 * @note The node is expected to be const in the thread which sends this message.
182 * However it can be modified when Process() is called in a different thread.
183 * @param[in] updateManager The update-manager.
184 * @param[in] node The node.
185 * @param[in] property The property to bake.
186 * @param[in] member The member function of the object.
187 * @param[in] value The new value of the X,Y,Z or W component.
189 NodePropertyComponentMessage(UpdateManager& updateManager,
191 const AnimatableProperty<P>* property,
192 MemberFunction member,
194 : NodePropertyMessageBase(updateManager),
195 mNode(const_cast<Node*>(node)),
196 mProperty(const_cast<AnimatableProperty<P>*>(property)),
197 mMemberFunction(member),
204 AnimatableProperty<P>* mProperty;
205 MemberFunction mMemberFunction;
210 class NodeTransformPropertyMessage : public NodePropertyMessageBase
213 using MemberFunction = void (TransformManagerPropertyHandler<P>::*)(BufferIndex, const P&);
217 * @note The node is expected to be const in the thread which sends this message.
218 * However it can be modified when Process() is called in a different thread.
219 * @param[in] eventThreadServices The object used to send messages to the scene graph
220 * @param[in] node The node.
221 * @param[in] property The property to bake.
222 * @param[in] member The member function of the object.
223 * @param[in] value The new value of the property.
225 static void Send(EventThreadServices& eventThreadServices,
227 const TransformManagerPropertyHandler<P>* property,
228 MemberFunction member,
231 // Reserve some memory inside the message queue
232 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(NodeTransformPropertyMessage));
234 // Construct message in the message queue memory; note that delete should not be called on the return value
235 new(slot) NodeTransformPropertyMessage(eventThreadServices.GetUpdateManager(), node, property, member, value);
241 ~NodeTransformPropertyMessage() override = default;
244 * @copydoc MessageBase::Process
246 void Process(BufferIndex updateBufferIndex) override
248 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
254 * @note The node is expected to be const in the thread which sends this message.
255 * However it can be modified when Process() is called in a different thread.
256 * @param[in] updateManager The update-manager.
257 * @param[in] node The node.
258 * @param[in] property The property to bake.
259 * @param[in] member The member function of the object.
260 * @param[in] value The new value of the property.
262 NodeTransformPropertyMessage(UpdateManager& updateManager,
264 const TransformManagerPropertyHandler<P>* property,
265 MemberFunction member,
267 : NodePropertyMessageBase(updateManager),
268 mNode(const_cast<Node*>(node)),
269 mProperty(const_cast<TransformManagerPropertyHandler<P>*>(property)),
270 mMemberFunction(member),
277 TransformManagerPropertyHandler<P>* mProperty;
278 MemberFunction mMemberFunction;
283 class NodeTransformComponentMessage : public NodePropertyMessageBase
286 using MemberFunction = void (TransformManagerPropertyHandler<P>::*)(BufferIndex, float);
290 * @note The node is expected to be const in the thread which sends this message.
291 * However it can be modified when Process() is called in a different thread.
292 * @param[in] eventThreadServices The object used to send messages to the scene graph
293 * @param[in] node The node.
294 * @param[in] property The property to bake.
295 * @param[in] member The member function of the object.
296 * @param[in] value The new value of the X,Y,Z or W component.
298 static void Send(EventThreadServices& eventThreadServices,
300 const TransformManagerPropertyHandler<P>* property,
301 MemberFunction member,
304 // Reserve some memory inside the message queue
305 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(NodeTransformComponentMessage));
307 // Construct message in the message queue memory; note that delete should not be called on the return value
308 new(slot) NodeTransformComponentMessage(eventThreadServices.GetUpdateManager(), node, property, member, value);
314 ~NodeTransformComponentMessage() override = default;
317 * @copydoc MessageBase::Process
319 void Process(BufferIndex updateBufferIndex) override
321 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
327 * @note The node is expected to be const in the thread which sends this message.
328 * However it can be modified when Process() is called in a different thread.
329 * @param[in] updateManager The update-manager.
330 * @param[in] node The node.
331 * @param[in] property The property to bake.
332 * @param[in] member The member function of the object.
333 * @param[in] value The new value of the X,Y,Z or W component.
335 NodeTransformComponentMessage(UpdateManager& updateManager,
337 const TransformManagerPropertyHandler<P>* property,
338 MemberFunction member,
340 : NodePropertyMessageBase(updateManager),
341 mNode(const_cast<Node*>(node)),
342 mProperty(const_cast<TransformManagerPropertyHandler<P>*>(property)),
343 mMemberFunction(member),
350 TransformManagerPropertyHandler<P>* mProperty;
351 MemberFunction mMemberFunction;
355 } // namespace SceneGraph
357 } // namespace Internal
361 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H