1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_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.
25 #include <dali/internal/event/common/event-thread-services.h>
26 #include <dali/internal/event/common/property-input-impl.h>
27 #include <dali/internal/update/common/property-owner.h>
28 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
39 // Property Messages for PropertyOwner
42 * A base class for property owner property messages.
43 * (For future optimization - see NodeMessageBase & Node.SetActive())
45 class PropertyOwnerMessageBase : public MessageBase
52 PropertyOwnerMessageBase();
57 virtual ~PropertyOwnerMessageBase();
62 PropertyOwnerMessageBase(const PropertyOwnerMessageBase&);
63 PropertyOwnerMessageBase& operator=(const PropertyOwnerMessageBase& rhs);
67 * Templated message which bakes a property.
69 template< typename P >
70 class AnimatablePropertyMessage : public PropertyOwnerMessageBase
74 typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, typename ParameterType< P >::PassingType );
78 * @note The scene object is expected to be const in the thread which sends this message.
79 * However it can be modified when Process() is called in a different thread.
80 * @param[in] eventThreadServices The object used to send messages to the scene graph
81 * @param[in] sceneObject The property owner scene object
82 * @param[in] property The property to bake.
83 * @param[in] member The member function of the object.
84 * @param[in] value The new value of the property.
86 static void Send( EventThreadServices& eventThreadServices,
87 const PropertyOwner* sceneObject,
88 const AnimatableProperty<P>* property,
89 MemberFunction member,
90 typename ParameterType< P >::PassingType value )
92 // Reserve some memory inside the message queue
93 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyMessage ) );
95 // Construct message in the message queue memory; note that delete should not be called on the return value
96 new (slot) AnimatablePropertyMessage( sceneObject, property, member, value );
102 virtual ~AnimatablePropertyMessage()
107 * @copydoc MessageBase::Process
109 virtual void Process( BufferIndex updateBufferIndex )
111 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
118 * @note The property owner is expected to be const in the thread which sends this message.
119 * However it can be modified when Process() is called in a different thread.
120 * @param[in] sceneObject the property owner scene object
121 * @param[in] property The property to bake.
122 * @param[in] member The member function of the object.
123 * @param[in] value The new value of the property.
125 AnimatablePropertyMessage( const PropertyOwner* sceneObject,
126 const AnimatableProperty<P>* property,
127 MemberFunction member,
128 typename ParameterType< P >::PassingType value )
129 : PropertyOwnerMessageBase(),
130 mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
131 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
132 mMemberFunction( member ),
139 PropertyOwner* mSceneObject;
140 AnimatableProperty<P>* mProperty;
141 MemberFunction mMemberFunction;
142 typename ParameterType< P >::HolderType mParam;
146 * Templated message which bakes a property.
148 template< typename P >
149 class AnimatablePropertyComponentMessage : public PropertyOwnerMessageBase
153 typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, float );
157 * @note The scene object is expected to be const in the thread which sends this message.
158 * However it can be modified when Process() is called in a different thread.
159 * @param[in] eventThreadServices The service object used for sending messages to the scene graph
160 * @param[in] sceneObject The property owner scene object
161 * @param[in] property The property to bake.
162 * @param[in] member The member function of the object.
163 * @param[in] value The new value of the X,Y,Z or W component.
165 static void Send( EventThreadServices& eventThreadServices,
166 const PropertyOwner* sceneObject,
167 const AnimatableProperty<P>* property,
168 MemberFunction member,
171 // Reserve some memory inside the message queue
172 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyComponentMessage ) );
174 // Construct message in the message queue memory; note that delete should not be called on the return value
175 new (slot) AnimatablePropertyComponentMessage( sceneObject, property, member, value );
181 virtual ~AnimatablePropertyComponentMessage()
186 * @copydoc MessageBase::Process
188 virtual void Process( BufferIndex updateBufferIndex )
190 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
197 * @note The scene object is expected to be const in the thread which sends this message.
198 * However it can be modified when Process() is called in a different thread.
199 * @param[in] sceneObject The property owner scene object
200 * @param[in] property The property to bake.
201 * @param[in] member The member function of the object.
202 * @param[in] value The new value of the X,Y,Z or W component.
204 AnimatablePropertyComponentMessage( const PropertyOwner* sceneObject,
205 const AnimatableProperty<P>* property,
206 MemberFunction member,
208 : PropertyOwnerMessageBase(),
209 mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
210 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
211 mMemberFunction( member ),
217 PropertyOwner* mSceneObject;
218 AnimatableProperty<P>* mProperty;
219 MemberFunction mMemberFunction;
224 // Messages for PropertyOwner
226 inline void InstallCustomPropertyMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<PropertyBase>& property )
228 typedef MessageValue1< PropertyOwner, OwnerPointer<PropertyBase> > LocalType;
230 // Reserve some memory inside the message queue
231 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
233 // Construct message in the message queue memory; note that delete should not be called on the return value
234 new (slot) LocalType( &owner, &PropertyOwner::InstallCustomProperty, property );
237 inline void ApplyConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<ConstraintBase>& constraint )
239 typedef MessageValue1< PropertyOwner, OwnerPointer<ConstraintBase> > LocalType;
241 // Reserve some memory inside the message queue
242 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
244 // Construct message in the message queue memory; note that delete should not be called on the return value
245 new (slot) LocalType( &owner, &PropertyOwner::ApplyConstraint, constraint );
248 inline void RemoveConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const ConstraintBase& constConstraint )
250 // The update-thread can modify this object.
251 ConstraintBase& constraint = const_cast< ConstraintBase& >( constConstraint );
253 typedef MessageValue1< PropertyOwner, ConstraintBase* > LocalType;
255 // Reserve some memory inside the message queue
256 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
258 // Construct message in the message queue memory; note that delete should not be called on the return value
259 new (slot) LocalType( &owner, &PropertyOwner::RemoveConstraint, &constraint );
262 inline void AddUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer< UniformPropertyMapping >& map )
264 typedef MessageValue1< PropertyOwner, OwnerPointer< UniformPropertyMapping > > LocalType;
266 // Reserve some memory inside the message queue
267 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
269 new (slot) LocalType( &owner, &PropertyOwner::AddUniformMapping, map );
272 inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const std::string& uniformName )
274 typedef MessageValue1< PropertyOwner, std::string > LocalType;
276 // Reserve some memory inside the message queue
277 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
279 new (slot) LocalType( &owner, &PropertyOwner::RemoveUniformMapping, uniformName );
283 } // namespace SceneGraph
285 } // namespace Internal
289 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H