use modern construct 'override' in the derive class.
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner-messages.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
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
30 namespace Dali
31 {
32 namespace Internal
33 {
34 namespace SceneGraph
35 {
36 class UniformMap;
37 class PropertyOwner;
38
39 // Property Messages for PropertyOwner
40
41 /**
42  * A base class for property owner property messages.
43  * (For future optimization - see NodeMessageBase & Node.SetActive())
44  */
45 class PropertyOwnerMessageBase : public MessageBase
46 {
47 public:
48
49   /**
50    * Create a message.
51    */
52   PropertyOwnerMessageBase();
53
54   /**
55    * Virtual destructor
56    */
57   ~PropertyOwnerMessageBase() override;
58
59 private:
60
61   // Undefined
62   PropertyOwnerMessageBase(const PropertyOwnerMessageBase&);
63   PropertyOwnerMessageBase& operator=(const PropertyOwnerMessageBase& rhs);
64 };
65
66 /**
67  * Templated message which bakes a property.
68  */
69 template< typename P >
70 class AnimatablePropertyMessage : public PropertyOwnerMessageBase
71 {
72 public:
73   using MemberFunction = void ( AnimatableProperty<P>::* )( BufferIndex, typename ParameterType<P>::PassingType );
74
75   /**
76    * Create a message.
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.
84    */
85   static void Send( EventThreadServices& eventThreadServices,
86                     const PropertyOwner* sceneObject,
87                     const AnimatableProperty<P>* property,
88                     MemberFunction member,
89                     typename ParameterType< P >::PassingType value )
90   {
91     // Reserve some memory inside the message queue
92     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyMessage ) );
93
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 );
96   }
97
98   /**
99    * Virtual destructor
100    */
101   ~AnimatablePropertyMessage() override
102   {
103   }
104
105   /**
106    * @copydoc MessageBase::Process
107    */
108   void Process( BufferIndex updateBufferIndex ) override
109   {
110     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
111   }
112
113 private:
114
115   /**
116    * Create a message.
117    * @note The property owner is expected to be const in the thread which sends this message.
118    * However it can be modified when Process() is called in a different thread.
119    * @param[in] sceneObject the property owner scene object
120    * @param[in] property The property to bake.
121    * @param[in] member The member function of the object.
122    * @param[in] value The new value of the property.
123    */
124   AnimatablePropertyMessage( const PropertyOwner* sceneObject,
125                              const AnimatableProperty<P>* property,
126                              MemberFunction member,
127                              typename ParameterType< P >::PassingType value )
128   : PropertyOwnerMessageBase(),
129     mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
130     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
131     mMemberFunction( member ),
132     mParam( value )
133   {
134   }
135
136 private:
137
138   PropertyOwner* mSceneObject;
139   AnimatableProperty<P>* mProperty;
140   MemberFunction mMemberFunction;
141   typename ParameterType< P >::HolderType mParam;
142 };
143
144 /**
145  * Templated message which bakes a property.
146  */
147 template< typename P >
148 class AnimatablePropertyComponentMessage : public PropertyOwnerMessageBase
149 {
150 public:
151   using MemberFunction = void ( AnimatableProperty<P>::* )( BufferIndex, float );
152
153   /**
154    * Send a message.
155    * @note The scene object is expected to be const in the thread which sends this message.
156    * However it can be modified when Process() is called in a different thread.
157    * @param[in] eventThreadServices The service object used for sending messages to the scene graph
158    * @param[in] sceneObject The property owner scene object
159    * @param[in] property The property to bake.
160    * @param[in] member The member function of the object.
161    * @param[in] value The new value of the X,Y,Z or W component.
162    */
163   static void Send( EventThreadServices& eventThreadServices,
164                     const PropertyOwner* sceneObject,
165                     const AnimatableProperty<P>* property,
166                     MemberFunction member,
167                     float value )
168   {
169     // Reserve some memory inside the message queue
170     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyComponentMessage ) );
171
172     // Construct message in the message queue memory; note that delete should not be called on the return value
173     new (slot) AnimatablePropertyComponentMessage( sceneObject, property, member, value );
174   }
175
176   /**
177    * Virtual destructor
178    */
179   ~AnimatablePropertyComponentMessage() override
180   {
181   }
182
183   /**
184    * @copydoc MessageBase::Process
185    */
186   void Process( BufferIndex updateBufferIndex ) override
187   {
188     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
189   }
190
191 private:
192
193   /**
194    * Create a message.
195    * @note The scene object is expected to be const in the thread which sends this message.
196    * However it can be modified when Process() is called in a different thread.
197    * @param[in] sceneObject The property owner scene object
198    * @param[in] property The property to bake.
199    * @param[in] member The member function of the object.
200    * @param[in] value The new value of the X,Y,Z or W component.
201   */
202   AnimatablePropertyComponentMessage( const PropertyOwner* sceneObject,
203                                       const AnimatableProperty<P>* property,
204                                       MemberFunction member,
205                                       float value )
206   : PropertyOwnerMessageBase(),
207     mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
208     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
209     mMemberFunction( member ),
210     mParam( value )
211   {
212   }
213
214 private:
215   PropertyOwner* mSceneObject;
216   AnimatableProperty<P>* mProperty;
217   MemberFunction mMemberFunction;
218   float mParam;
219 };
220
221
222 // Messages for PropertyOwner
223
224 inline void InstallCustomPropertyMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<PropertyBase>& property )
225 {
226   using LocalType = MessageValue1<PropertyOwner, OwnerPointer<PropertyBase> >;
227
228   // Reserve some memory inside the message queue
229   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
230
231   // Construct message in the message queue memory; note that delete should not be called on the return value
232   new (slot) LocalType( &owner, &PropertyOwner::InstallCustomProperty, property );
233 }
234
235 inline void ApplyConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<ConstraintBase>& constraint )
236 {
237   using LocalType = MessageValue1<PropertyOwner, OwnerPointer<ConstraintBase> >;
238
239   // Reserve some memory inside the message queue
240   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
241
242   // Construct message in the message queue memory; note that delete should not be called on the return value
243   new (slot) LocalType( &owner, &PropertyOwner::ApplyConstraint, constraint );
244 }
245
246 inline void RemoveConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const ConstraintBase& constConstraint )
247 {
248   // The update-thread can modify this object.
249   ConstraintBase& constraint = const_cast< ConstraintBase& >( constConstraint );
250
251   using LocalType = MessageValue1<PropertyOwner, ConstraintBase*>;
252
253   // Reserve some memory inside the message queue
254   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
255
256   // Construct message in the message queue memory; note that delete should not be called on the return value
257   new (slot) LocalType( &owner, &PropertyOwner::RemoveConstraint, &constraint );
258 }
259
260 inline void AddUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer< UniformPropertyMapping >& map )
261 {
262   using LocalType = MessageValue1<PropertyOwner, OwnerPointer<UniformPropertyMapping> >;
263
264   // Reserve some memory inside the message queue
265   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
266
267   new (slot) LocalType( &owner, &PropertyOwner::AddUniformMapping, map );
268 }
269
270 inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const std::string& uniformName )
271 {
272   using LocalType = MessageValue1<PropertyOwner, std::string>;
273
274   // Reserve some memory inside the message queue
275   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
276
277   new (slot) LocalType( &owner, &PropertyOwner::RemoveUniformMapping, uniformName );
278 }
279
280
281 } // namespace SceneGraph
282
283 } // namespace Internal
284
285 } // namespace Dali
286
287 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H