1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H
5 * Copyright (c) 2022 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/common/const-string.h>
26 #include <dali/internal/event/common/event-thread-services.h>
27 #include <dali/internal/event/common/property-input-impl.h>
28 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
29 #include <dali/internal/update/common/property-owner.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
52 PropertyOwnerMessageBase();
57 ~PropertyOwnerMessageBase() override;
61 PropertyOwnerMessageBase(const PropertyOwnerMessageBase&);
62 PropertyOwnerMessageBase& operator=(const PropertyOwnerMessageBase& rhs);
66 * Templated message which bakes a property.
69 class AnimatablePropertyMessage : public PropertyOwnerMessageBase
72 using MemberFunction = void (AnimatableProperty<P>::*)(BufferIndex, typename ParameterType<P>::PassingType);
76 * @note The scene object is expected to be const in the thread which sends this message.
77 * However it can be modified when Process() is called in a different thread.
78 * @param[in] eventThreadServices The object used to send messages to the scene graph
79 * @param[in] sceneObject The property owner scene object
80 * @param[in] property The property to bake.
81 * @param[in] member The member function of the object.
82 * @param[in] value The new value of the property.
84 static void Send(EventThreadServices& eventThreadServices,
85 const PropertyOwner* sceneObject,
86 const AnimatableProperty<P>* property,
87 MemberFunction member,
88 typename ParameterType<P>::PassingType value)
90 // Reserve some memory inside the message queue
91 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(AnimatablePropertyMessage));
93 // Construct message in the message queue memory; note that delete should not be called on the return value
94 new(slot) AnimatablePropertyMessage(sceneObject, property, member, value);
100 ~AnimatablePropertyMessage() override = default;
103 * @copydoc MessageBase::Process
105 void Process(BufferIndex updateBufferIndex) override
107 (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 AnimatablePropertyMessage(const PropertyOwner* sceneObject,
121 const AnimatableProperty<P>* property,
122 MemberFunction member,
123 typename ParameterType<P>::PassingType value)
124 : PropertyOwnerMessageBase(),
125 mSceneObject(const_cast<PropertyOwner*>(sceneObject)),
126 mProperty(const_cast<AnimatableProperty<P>*>(property)),
127 mMemberFunction(member),
133 PropertyOwner* mSceneObject;
134 AnimatableProperty<P>* mProperty;
135 MemberFunction mMemberFunction;
136 typename ParameterType<P>::HolderType mParam;
140 * Templated message which bakes a property.
143 class AnimatablePropertyComponentMessage : public PropertyOwnerMessageBase
146 using MemberFunction = void (AnimatableProperty<P>::*)(BufferIndex, float);
150 * @note The scene object is expected to be const in the thread which sends this message.
151 * However it can be modified when Process() is called in a different thread.
152 * @param[in] eventThreadServices The service object used for sending messages to the scene graph
153 * @param[in] sceneObject The property owner scene object
154 * @param[in] property The property to bake.
155 * @param[in] member The member function of the object.
156 * @param[in] value The new value of the X,Y,Z or W component.
158 static void Send(EventThreadServices& eventThreadServices,
159 const PropertyOwner* sceneObject,
160 const AnimatableProperty<P>* property,
161 MemberFunction member,
164 // Reserve some memory inside the message queue
165 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(AnimatablePropertyComponentMessage));
167 // Construct message in the message queue memory; note that delete should not be called on the return value
168 new(slot) AnimatablePropertyComponentMessage(sceneObject, property, member, value);
174 ~AnimatablePropertyComponentMessage() override = default;
177 * @copydoc MessageBase::Process
179 void Process(BufferIndex updateBufferIndex) override
181 (mProperty->*mMemberFunction)(updateBufferIndex, mParam);
187 * @note The scene object is expected to be const in the thread which sends this message.
188 * However it can be modified when Process() is called in a different thread.
189 * @param[in] sceneObject The property owner scene object
190 * @param[in] property The property to bake.
191 * @param[in] member The member function of the object.
192 * @param[in] value The new value of the X,Y,Z or W component.
194 AnimatablePropertyComponentMessage(const PropertyOwner* sceneObject,
195 const AnimatableProperty<P>* property,
196 MemberFunction member,
198 : PropertyOwnerMessageBase(),
199 mSceneObject(const_cast<PropertyOwner*>(sceneObject)),
200 mProperty(const_cast<AnimatableProperty<P>*>(property)),
201 mMemberFunction(member),
207 PropertyOwner* mSceneObject;
208 AnimatableProperty<P>* mProperty;
209 MemberFunction mMemberFunction;
213 // Messages for PropertyOwner
215 inline void InstallCustomPropertyMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<PropertyBase>& property)
217 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<PropertyBase> >;
219 // Reserve some memory inside the message queue
220 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
222 // Construct message in the message queue memory; note that delete should not be called on the return value
223 new(slot) LocalType(&owner, &PropertyOwner::InstallCustomProperty, property);
226 inline void ApplyConstraintMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<ConstraintBase>& constraint)
228 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<ConstraintBase> >;
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::ApplyConstraint, constraint);
237 inline void RemoveConstraintMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, const ConstraintBase& constConstraint)
239 // The update-thread can modify this object.
240 ConstraintBase& constraint = const_cast<ConstraintBase&>(constConstraint);
242 using LocalType = MessageValue1<PropertyOwner, ConstraintBase*>;
244 // Reserve some memory inside the message queue
245 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
247 // Construct message in the message queue memory; note that delete should not be called on the return value
248 new(slot) LocalType(&owner, &PropertyOwner::RemoveConstraint, &constraint);
251 inline void ApplyPostConstraintMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<ConstraintBase>& constraint)
253 using LocalType = MessageValue1<PropertyOwner, OwnerPointer<ConstraintBase> >;
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::ApplyPostConstraint, constraint);
262 inline void RemovePostConstraintMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, const ConstraintBase& constConstraint)
264 // The update-thread can modify this object.
265 ConstraintBase& constraint = const_cast<ConstraintBase&>(constConstraint);
267 using LocalType = MessageValue1<PropertyOwner, ConstraintBase*>;
269 // Reserve some memory inside the message queue
270 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
272 // Construct message in the message queue memory; note that delete should not be called on the return value
273 new(slot) LocalType(&owner, &PropertyOwner::RemovePostConstraint, &constraint);
276 inline void AddUniformMapMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, UniformPropertyMapping map)
278 using LocalType = MessageValue1<PropertyOwner, UniformPropertyMapping>;
280 // Reserve some memory inside the message queue
281 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
283 new(slot) LocalType(&owner, &PropertyOwner::AddUniformMapping, map);
286 inline void RemoveUniformMapMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, ConstString uniformName)
288 using LocalType = MessageValue1<PropertyOwner, ConstString>;
290 // Reserve some memory inside the message queue
291 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
293 new(slot) LocalType(&owner, &PropertyOwner::RemoveUniformMapping, uniformName);
296 inline void ReservePropertiesMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, int propertyCount)
298 using LocalType = MessageValue1<PropertyOwner, int>;
300 // Reserve some memory inside the message queue
301 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
303 new(slot) LocalType(&owner, &PropertyOwner::ReserveProperties, propertyCount);
306 } // namespace SceneGraph
308 } // namespace Internal
312 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H