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>
29 #include <dali/internal/common/const-string.h>
40 // Property Messages for PropertyOwner
43 * A base class for property owner property messages.
44 * (For future optimization - see NodeMessageBase & Node.SetActive())
46 class PropertyOwnerMessageBase : public MessageBase
53 PropertyOwnerMessageBase();
58 ~PropertyOwnerMessageBase() override;
63 PropertyOwnerMessageBase(const PropertyOwnerMessageBase&);
64 PropertyOwnerMessageBase& operator=(const PropertyOwnerMessageBase& rhs);
68 * Templated message which bakes a property.
70 template< typename P >
71 class AnimatablePropertyMessage : public PropertyOwnerMessageBase
74 using MemberFunction = void ( AnimatableProperty<P>::* )( 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 ~AnimatablePropertyMessage() override = default;
105 * @copydoc MessageBase::Process
107 void Process( BufferIndex updateBufferIndex ) override
109 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
116 * @note The property owner is expected to be const in the thread which sends this message.
117 * However it can be modified when Process() is called in a different thread.
118 * @param[in] sceneObject the property owner scene object
119 * @param[in] property The property to bake.
120 * @param[in] member The member function of the object.
121 * @param[in] value The new value of the property.
123 AnimatablePropertyMessage( const PropertyOwner* sceneObject,
124 const AnimatableProperty<P>* property,
125 MemberFunction member,
126 typename ParameterType< P >::PassingType value )
127 : PropertyOwnerMessageBase(),
128 mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
129 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
130 mMemberFunction( member ),
137 PropertyOwner* mSceneObject;
138 AnimatableProperty<P>* mProperty;
139 MemberFunction mMemberFunction;
140 typename ParameterType< P >::HolderType mParam;
144 * Templated message which bakes a property.
146 template< typename P >
147 class AnimatablePropertyComponentMessage : public PropertyOwnerMessageBase
150 using MemberFunction = void ( AnimatableProperty<P>::* )( BufferIndex, float );
154 * @note The scene object is expected to be const in the thread which sends this message.
155 * However it can be modified when Process() is called in a different thread.
156 * @param[in] eventThreadServices The service object used for sending messages to the scene graph
157 * @param[in] sceneObject The property owner scene object
158 * @param[in] property The property to bake.
159 * @param[in] member The member function of the object.
160 * @param[in] value The new value of the X,Y,Z or W component.
162 static void Send( EventThreadServices& eventThreadServices,
163 const PropertyOwner* sceneObject,
164 const AnimatableProperty<P>* property,
165 MemberFunction member,
168 // Reserve some memory inside the message queue
169 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyComponentMessage ) );
171 // Construct message in the message queue memory; note that delete should not be called on the return value
172 new (slot) AnimatablePropertyComponentMessage( sceneObject, property, member, value );
178 ~AnimatablePropertyComponentMessage() override = default;
181 * @copydoc MessageBase::Process
183 void Process( BufferIndex updateBufferIndex ) override
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 AnimatablePropertyComponentMessage( const PropertyOwner* sceneObject,
200 const AnimatableProperty<P>* property,
201 MemberFunction member,
203 : PropertyOwnerMessageBase(),
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, OwnerPointer<PropertyBase>& property )
223 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<PropertyBase> >;
225 // Reserve some memory inside the message queue
226 uint32_t* 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, OwnerPointer<ConstraintBase>& constraint )
234 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<ConstraintBase> >;
236 // Reserve some memory inside the message queue
237 uint32_t* 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 using LocalType = MessageValue1<PropertyOwner, ConstraintBase*>;
250 // Reserve some memory inside the message queue
251 uint32_t* 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, OwnerPointer< UniformPropertyMapping >& map )
259 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<UniformPropertyMapping> >;
261 // Reserve some memory inside the message queue
262 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
264 new (slot) LocalType( &owner, &PropertyOwner::AddUniformMapping, map );
267 inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, ConstString uniformName )
269 using LocalType = MessageValue1<PropertyOwner, ConstString>;
271 // Reserve some memory inside the message queue
272 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
274 new (slot) LocalType( &owner, &PropertyOwner::RemoveUniformMapping, uniformName );
278 } // namespace SceneGraph
280 } // namespace Internal
284 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H