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 ~PropertyOwnerMessageBase() override;
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
73 using MemberFunction = void ( AnimatableProperty<P>::* )( BufferIndex, typename ParameterType<P>::PassingType );
77 * @note The scene object is expected to be const in the thread which sends this message.
78 * However it can be modified when Process() is called in a different thread.
79 * @param[in] eventThreadServices The object used to send messages to the scene graph
80 * @param[in] sceneObject The property owner scene object
81 * @param[in] property The property to bake.
82 * @param[in] member The member function of the object.
83 * @param[in] value The new value of the property.
85 static void Send( EventThreadServices& eventThreadServices,
86 const PropertyOwner* sceneObject,
87 const AnimatableProperty<P>* property,
88 MemberFunction member,
89 typename ParameterType< P >::PassingType value )
91 // Reserve some memory inside the message queue
92 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyMessage ) );
94 // Construct message in the message queue memory; note that delete should not be called on the return value
95 new (slot) AnimatablePropertyMessage( sceneObject, property, member, value );
101 ~AnimatablePropertyMessage() override = default;
104 * @copydoc MessageBase::Process
106 void Process( BufferIndex updateBufferIndex ) override
108 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
115 * @note The property owner is expected to be const in the thread which sends this message.
116 * However it can be modified when Process() is called in a different thread.
117 * @param[in] sceneObject the property owner scene object
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 AnimatablePropertyMessage( const PropertyOwner* sceneObject,
123 const AnimatableProperty<P>* property,
124 MemberFunction member,
125 typename ParameterType< P >::PassingType value )
126 : PropertyOwnerMessageBase(),
127 mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
128 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
129 mMemberFunction( member ),
136 PropertyOwner* mSceneObject;
137 AnimatableProperty<P>* mProperty;
138 MemberFunction mMemberFunction;
139 typename ParameterType< P >::HolderType mParam;
143 * Templated message which bakes a property.
145 template< typename P >
146 class AnimatablePropertyComponentMessage : public PropertyOwnerMessageBase
149 using MemberFunction = void ( AnimatableProperty<P>::* )( BufferIndex, float );
153 * @note The scene object 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 service object used for sending messages to the scene graph
156 * @param[in] sceneObject The property owner scene object
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,
162 const PropertyOwner* sceneObject,
163 const AnimatableProperty<P>* property,
164 MemberFunction member,
167 // Reserve some memory inside the message queue
168 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyComponentMessage ) );
170 // Construct message in the message queue memory; note that delete should not be called on the return value
171 new (slot) AnimatablePropertyComponentMessage( sceneObject, property, member, value );
177 ~AnimatablePropertyComponentMessage() override = default;
180 * @copydoc MessageBase::Process
182 void Process( BufferIndex updateBufferIndex ) override
184 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
191 * @note The scene object is expected to be const in the thread which sends this message.
192 * However it can be modified when Process() is called in a different thread.
193 * @param[in] sceneObject The property owner scene object
194 * @param[in] property The property to bake.
195 * @param[in] member The member function of the object.
196 * @param[in] value The new value of the X,Y,Z or W component.
198 AnimatablePropertyComponentMessage( const PropertyOwner* sceneObject,
199 const AnimatableProperty<P>* property,
200 MemberFunction member,
202 : PropertyOwnerMessageBase(),
203 mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
204 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
205 mMemberFunction( member ),
211 PropertyOwner* mSceneObject;
212 AnimatableProperty<P>* mProperty;
213 MemberFunction mMemberFunction;
218 // Messages for PropertyOwner
220 inline void InstallCustomPropertyMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<PropertyBase>& property )
222 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<PropertyBase> >;
224 // Reserve some memory inside the message queue
225 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
227 // Construct message in the message queue memory; note that delete should not be called on the return value
228 new (slot) LocalType( &owner, &PropertyOwner::InstallCustomProperty, property );
231 inline void ApplyConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<ConstraintBase>& constraint )
233 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<ConstraintBase> >;
235 // Reserve some memory inside the message queue
236 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
238 // Construct message in the message queue memory; note that delete should not be called on the return value
239 new (slot) LocalType( &owner, &PropertyOwner::ApplyConstraint, constraint );
242 inline void RemoveConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const ConstraintBase& constConstraint )
244 // The update-thread can modify this object.
245 ConstraintBase& constraint = const_cast< ConstraintBase& >( constConstraint );
247 using LocalType = MessageValue1<PropertyOwner, ConstraintBase*>;
249 // Reserve some memory inside the message queue
250 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
252 // Construct message in the message queue memory; note that delete should not be called on the return value
253 new (slot) LocalType( &owner, &PropertyOwner::RemoveConstraint, &constraint );
256 inline void AddUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer< UniformPropertyMapping >& map )
258 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<UniformPropertyMapping> >;
260 // Reserve some memory inside the message queue
261 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
263 new (slot) LocalType( &owner, &PropertyOwner::AddUniformMapping, map );
266 inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const std::string& uniformName )
268 using LocalType = MessageValue1<PropertyOwner, std::string>;
270 // Reserve some memory inside the message queue
271 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
273 new (slot) LocalType( &owner, &PropertyOwner::RemoveUniformMapping, uniformName );
277 } // namespace SceneGraph
279 } // namespace Internal
283 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H