1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H__
5 * Copyright (c) 2014 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.
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/event/common/property-input-impl.h>
25 #include <dali/internal/update/common/property-owner.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
38 // Property Messages for PropertyOwner
40 class PropertyMessageBase : public MessageBase
47 PropertyMessageBase();
52 virtual ~PropertyMessageBase();
57 PropertyMessageBase(const PropertyMessageBase&);
58 PropertyMessageBase& operator=(const PropertyMessageBase& rhs);
62 * Templated message which bakes a property.
64 template< typename P >
65 class PropertyMessage : public PropertyMessageBase
69 typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, typename ParameterType< P >::PassingType );
73 * @note The scene object is expected to be const in the thread which sends this message.
74 * However it can be modified when Process() is called in a different thread.
75 * @param[in] updateManager The update-manager.
76 * @param[in] sceneObject The property owner scene object
77 * @param[in] property The property to bake.
78 * @param[in] member The member function of the object.
79 * @param[in] value The new value of the property.
81 static void Send( EventThreadServices& eventThreadServices,
82 const PropertyOwner* sceneObject,
83 const AnimatableProperty<P>* property,
84 MemberFunction member,
85 typename ParameterType< P >::PassingType value )
87 // Reserve some memory inside the message queue
88 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( PropertyMessage ) );
90 // Construct message in the message queue memory; note that delete should not be called on the return value
91 new (slot) PropertyMessage( sceneObject, property, member, value );
97 virtual ~PropertyMessage()
102 * @copydoc MessageBase::Process
104 virtual void Process( BufferIndex updateBufferIndex )
106 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
113 * @note The property owner 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] sceneObject the property owner scene object
116 * @param[in] property The property to bake.
117 * @param[in] member The member function of the object.
118 * @param[in] value The new value of the property.
120 PropertyMessage( const PropertyOwner* sceneObject,
121 const AnimatableProperty<P>* property,
122 MemberFunction member,
123 typename ParameterType< P >::PassingType value )
124 : PropertyMessageBase(),
125 mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
126 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
127 mMemberFunction( member ),
134 PropertyOwner* mSceneObject;
135 AnimatableProperty<P>* mProperty;
136 MemberFunction mMemberFunction;
137 typename ParameterType< P >::HolderType mParam;
141 * Templated message which bakes a property.
143 template< typename P >
144 class PropertyComponentMessage : public PropertyMessageBase
148 typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, float );
152 * @note The scene object is expected to be const in the thread which sends this message.
153 * However it can be modified when Process() is called in a different thread.
154 * @param[in] eventThreadServices The service object used for sending messages to the scene graph
155 * @param[in] sceneObject The property owner scene object
156 * @param[in] property The property to bake.
157 * @param[in] member The member function of the object.
158 * @param[in] value The new value of the X,Y,Z or W component.
160 static void Send( EventThreadServices& eventThreadServices,
161 const PropertyOwner* sceneObject,
162 const AnimatableProperty<P>* property,
163 MemberFunction member,
166 // Reserve some memory inside the message queue
167 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( PropertyComponentMessage ) );
169 // Construct message in the message queue memory; note that delete should not be called on the return value
170 new (slot) PropertyComponentMessage( sceneObject, property, member, value );
176 virtual ~PropertyComponentMessage()
181 * @copydoc MessageBase::Process
183 virtual void Process( BufferIndex updateBufferIndex )
185 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
192 * @note The scene object 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] sceneObject The property owner scene object
195 * @param[in] property The property to bake.
196 * @param[in] member The member function of the object.
197 * @param[in] value The new value of the X,Y,Z or W component.
199 PropertyComponentMessage( const PropertyOwner* sceneObject,
200 const AnimatableProperty<P>* property,
201 MemberFunction member,
203 : PropertyMessageBase(),
204 mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
205 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
206 mMemberFunction( member ),
212 PropertyOwner* mSceneObject;
213 AnimatableProperty<P>* mProperty;
214 MemberFunction mMemberFunction;
219 // Messages for PropertyOwner
221 inline void InstallCustomPropertyMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, PropertyBase* property )
223 typedef MessageValue1< PropertyOwner, OwnerPointer<PropertyBase> > LocalType;
225 // Reserve some memory inside the message queue
226 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
228 // Construct message in the message queue memory; note that delete should not be called on the return value
229 new (slot) LocalType( &owner, &PropertyOwner::InstallCustomProperty, property );
232 inline void ApplyConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, ConstraintBase& constraint )
234 typedef MessageValue1< PropertyOwner, OwnerPointer<ConstraintBase> > LocalType;
236 // Reserve some memory inside the message queue
237 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
239 // Construct message in the message queue memory; note that delete should not be called on the return value
240 new (slot) LocalType( &owner, &PropertyOwner::ApplyConstraint, &constraint );
243 inline void RemoveConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const ConstraintBase& constConstraint )
245 // The update-thread can modify this object.
246 ConstraintBase& constraint = const_cast< ConstraintBase& >( constConstraint );
248 typedef MessageValue1< PropertyOwner, ConstraintBase* > LocalType;
250 // Reserve some memory inside the message queue
251 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
253 // Construct message in the message queue memory; note that delete should not be called on the return value
254 new (slot) LocalType( &owner, &PropertyOwner::RemoveConstraint, &constraint );
257 inline void AddUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, UniformPropertyMapping* map )
259 typedef MessageValue1< PropertyOwner, OwnerPointer< UniformPropertyMapping > > LocalType;
260 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
261 new (slot) LocalType( &owner, &PropertyOwner::AddUniformMapping, map );
264 inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const std::string& uniformName )
266 typedef MessageValue1< PropertyOwner, std::string > LocalType;
267 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
268 new (slot) LocalType( &owner, &PropertyOwner::RemoveUniformMapping, uniformName );
272 } // namespace SceneGraph
274 } // namespace Internal
278 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H__