1 #ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
5 * Copyright (c) 2019 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/nodes/node.h>
25 #include <dali/internal/update/manager/update-manager.h>
38 class NodePropertyMessageBase : public MessageBase
45 NodePropertyMessageBase(UpdateManager& updateManager);
50 ~NodePropertyMessageBase() override;
55 NodePropertyMessageBase(const NodePropertyMessageBase&);
56 NodePropertyMessageBase& operator=(const NodePropertyMessageBase& rhs);
60 UpdateManager& mUpdateManager;
64 * Templated message which bakes a Node property.
66 template< typename P >
67 class NodePropertyMessage : public NodePropertyMessageBase
70 using MemberFunction = void ( AnimatableProperty<P>::* )( BufferIndex, typename ParameterType<P>::PassingType );
74 * @note The node is expected to be const in the thread which sends this message.
75 * However it can be modified when Process() is called in a different thread.
76 * @param[in] eventThreadServices The object used to send messages to the scene graph
77 * @param[in] node The node.
78 * @param[in] property The property to bake.
79 * @param[in] member The member function of the object.
80 * @param[in] value The new value of the property.
82 static void Send( EventThreadServices& eventThreadServices,
84 const AnimatableProperty<P>* property,
85 MemberFunction member,
86 typename ParameterType< P >::PassingType value )
88 // Reserve some memory inside the message queue
89 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodePropertyMessage ) );
91 // Construct message in the message queue memory; note that delete should not be called on the return value
92 new (slot) NodePropertyMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
98 ~NodePropertyMessage() override = default;
101 * @copydoc MessageBase::Process
103 void Process( BufferIndex updateBufferIndex ) override
105 mNode->SetUpdated( true );
106 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
113 * @note The node is expected to be const in the thread which sends this message.
114 * However it can be modified when Process() is called in a different thread.
115 * @param[in] updateManager The update-manager.
116 * @param[in] node The node.
117 * @param[in] property The property to bake.
118 * @param[in] member The member function of the object.
119 * @param[in] value The new value of the property.
121 NodePropertyMessage( UpdateManager& updateManager,
123 const AnimatableProperty<P>* property,
124 MemberFunction member,
125 typename ParameterType< P >::PassingType value )
126 : NodePropertyMessageBase( updateManager ),
127 mNode( const_cast< Node* >( node ) ),
128 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
129 mMemberFunction( member ),
137 AnimatableProperty<P>* mProperty;
138 MemberFunction mMemberFunction;
139 typename ParameterType< P >::HolderType mParam;
143 * Templated message which bakes a Node property.
145 template< typename P >
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 // Construct message in the message queue memory; note that delete should not be called on the return value
171 new (slot) NodePropertyComponentMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
177 ~NodePropertyComponentMessage() override = default;
180 * @copydoc MessageBase::Process
182 void Process( BufferIndex updateBufferIndex ) override
184 mNode->SetUpdated( true );
185 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
192 * @note The node is expected to be const in the thread which sends this message.
193 * However it can be modified when Process() is called in a different thread.
194 * @param[in] updateManager The update-manager.
195 * @param[in] node The node.
196 * @param[in] property The property to bake.
197 * @param[in] member The member function of the object.
198 * @param[in] value The new value of the X,Y,Z or W component.
200 NodePropertyComponentMessage( UpdateManager& updateManager,
202 const AnimatableProperty<P>* property,
203 MemberFunction member,
205 : NodePropertyMessageBase( updateManager ),
206 mNode( const_cast< Node* >( node ) ),
207 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
208 mMemberFunction( member ),
216 AnimatableProperty<P>* mProperty;
217 MemberFunction mMemberFunction;
222 template <typename P>
223 class NodeTransformPropertyMessage : public NodePropertyMessageBase
226 using MemberFunction = void ( TransformManagerPropertyHandler<P>::* )( BufferIndex, const P& );
230 * @note The node is expected to be const in the thread which sends this message.
231 * However it can be modified when Process() is called in a different thread.
232 * @param[in] eventThreadServices The object used to send messages to the scene graph
233 * @param[in] node The node.
234 * @param[in] property The property to bake.
235 * @param[in] member The member function of the object.
236 * @param[in] value The new value of the property.
238 static void Send( EventThreadServices& eventThreadServices,
240 const TransformManagerPropertyHandler<P>* property,
241 MemberFunction member,
244 // Reserve some memory inside the message queue
245 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodeTransformPropertyMessage ) );
247 // Construct message in the message queue memory; note that delete should not be called on the return value
248 new (slot) NodeTransformPropertyMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
254 ~NodeTransformPropertyMessage() override = default;
257 * @copydoc MessageBase::Process
259 void Process( BufferIndex updateBufferIndex ) override
261 mNode->SetUpdated( true );
262 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
269 * @note The node is expected to be const in the thread which sends this message.
270 * However it can be modified when Process() is called in a different thread.
271 * @param[in] updateManager The update-manager.
272 * @param[in] node The node.
273 * @param[in] property The property to bake.
274 * @param[in] member The member function of the object.
275 * @param[in] value The new value of the property.
277 NodeTransformPropertyMessage( UpdateManager& updateManager,
279 const TransformManagerPropertyHandler<P>* property,
280 MemberFunction member,
282 : NodePropertyMessageBase( updateManager ),
283 mNode( const_cast< Node* >( node ) ),
284 mProperty( const_cast< TransformManagerPropertyHandler<P>* >( property ) ),
285 mMemberFunction( member ),
293 TransformManagerPropertyHandler<P>* mProperty;
294 MemberFunction mMemberFunction;
299 template <typename P>
300 class NodeTransformComponentMessage : public NodePropertyMessageBase
303 using MemberFunction = void ( TransformManagerPropertyHandler<P>::* )( BufferIndex, float );
307 * @note The node is expected to be const in the thread which sends this message.
308 * However it can be modified when Process() is called in a different thread.
309 * @param[in] eventThreadServices The object used to send messages to the scene graph
310 * @param[in] node The node.
311 * @param[in] property The property to bake.
312 * @param[in] member The member function of the object.
313 * @param[in] value The new value of the X,Y,Z or W component.
315 static void Send( EventThreadServices& eventThreadServices,
317 const TransformManagerPropertyHandler<P>* property,
318 MemberFunction member,
321 // Reserve some memory inside the message queue
322 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodeTransformComponentMessage ) );
324 // Construct message in the message queue memory; note that delete should not be called on the return value
325 new (slot) NodeTransformComponentMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
331 ~NodeTransformComponentMessage() override = default;
334 * @copydoc MessageBase::Process
336 void Process( BufferIndex updateBufferIndex ) override
338 mNode->SetUpdated( true );
339 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
346 * @note The node is expected to be const in the thread which sends this message.
347 * However it can be modified when Process() is called in a different thread.
348 * @param[in] updateManager The update-manager.
349 * @param[in] node The node.
350 * @param[in] property The property to bake.
351 * @param[in] member The member function of the object.
352 * @param[in] value The new value of the X,Y,Z or W component.
354 NodeTransformComponentMessage( UpdateManager& updateManager,
356 const TransformManagerPropertyHandler<P>* property,
357 MemberFunction member,
359 : NodePropertyMessageBase( updateManager ),
360 mNode( const_cast< Node* >( node ) ),
361 mProperty( const_cast< TransformManagerPropertyHandler<P>* >( property ) ),
362 mMemberFunction( member ),
370 TransformManagerPropertyHandler<P>* mProperty;
371 MemberFunction mMemberFunction;
375 } // namespace SceneGraph
377 } // namespace Internal
381 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H