[Tizen] Implement partial update
[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   virtual ~PropertyOwnerMessageBase();
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
74   typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, typename ParameterType< P >::PassingType );
75
76   /**
77    * Create a message.
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.
85    */
86   static void Send( EventThreadServices& eventThreadServices,
87                     const PropertyOwner* sceneObject,
88                     const AnimatableProperty<P>* property,
89                     MemberFunction member,
90                     typename ParameterType< P >::PassingType value )
91   {
92     // Reserve some memory inside the message queue
93     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyMessage ) );
94
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 );
97   }
98
99   /**
100    * Virtual destructor
101    */
102   virtual ~AnimatablePropertyMessage()
103   {
104   }
105
106   /**
107    * @copydoc MessageBase::Process
108    */
109   virtual void Process( BufferIndex updateBufferIndex )
110   {
111     mSceneObject->SetPropertyDirty( true );
112     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
113   }
114
115 private:
116
117   /**
118    * Create a message.
119    * @note The property owner is expected to be const in the thread which sends this message.
120    * However it can be modified when Process() is called in a different thread.
121    * @param[in] sceneObject the property owner scene object
122    * @param[in] property The property to bake.
123    * @param[in] member The member function of the object.
124    * @param[in] value The new value of the property.
125    */
126   AnimatablePropertyMessage( const PropertyOwner* sceneObject,
127                              const AnimatableProperty<P>* property,
128                              MemberFunction member,
129                              typename ParameterType< P >::PassingType value )
130   : PropertyOwnerMessageBase(),
131     mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
132     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
133     mMemberFunction( member ),
134     mParam( value )
135   {
136   }
137
138 private:
139
140   PropertyOwner* mSceneObject;
141   AnimatableProperty<P>* mProperty;
142   MemberFunction mMemberFunction;
143   typename ParameterType< P >::HolderType mParam;
144 };
145
146 /**
147  * Templated message which bakes a property.
148  */
149 template< typename P >
150 class AnimatablePropertyComponentMessage : public PropertyOwnerMessageBase
151 {
152 public:
153
154   typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, float );
155
156   /**
157    * Send a message.
158    * @note The scene object is expected to be const in the thread which sends this message.
159    * However it can be modified when Process() is called in a different thread.
160    * @param[in] eventThreadServices The service object used for sending messages to the scene graph
161    * @param[in] sceneObject The property owner scene object
162    * @param[in] property The property to bake.
163    * @param[in] member The member function of the object.
164    * @param[in] value The new value of the X,Y,Z or W component.
165    */
166   static void Send( EventThreadServices& eventThreadServices,
167                     const PropertyOwner* sceneObject,
168                     const AnimatableProperty<P>* property,
169                     MemberFunction member,
170                     float value )
171   {
172     // Reserve some memory inside the message queue
173     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( AnimatablePropertyComponentMessage ) );
174
175     // Construct message in the message queue memory; note that delete should not be called on the return value
176     new (slot) AnimatablePropertyComponentMessage( sceneObject, property, member, value );
177   }
178
179   /**
180    * Virtual destructor
181    */
182   virtual ~AnimatablePropertyComponentMessage()
183   {
184   }
185
186   /**
187    * @copydoc MessageBase::Process
188    */
189   virtual void Process( BufferIndex updateBufferIndex )
190   {
191     mSceneObject->SetPropertyDirty( true );
192     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
193   }
194
195 private:
196
197   /**
198    * Create a message.
199    * @note The scene object is expected to be const in the thread which sends this message.
200    * However it can be modified when Process() is called in a different thread.
201    * @param[in] sceneObject The property owner scene object
202    * @param[in] property The property to bake.
203    * @param[in] member The member function of the object.
204    * @param[in] value The new value of the X,Y,Z or W component.
205   */
206   AnimatablePropertyComponentMessage( const PropertyOwner* sceneObject,
207                                       const AnimatableProperty<P>* property,
208                                       MemberFunction member,
209                                       float value )
210   : PropertyOwnerMessageBase(),
211     mSceneObject( const_cast< PropertyOwner* >( sceneObject ) ),
212     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
213     mMemberFunction( member ),
214     mParam( value )
215   {
216   }
217
218 private:
219   PropertyOwner* mSceneObject;
220   AnimatableProperty<P>* mProperty;
221   MemberFunction mMemberFunction;
222   float mParam;
223 };
224
225
226 // Messages for PropertyOwner
227
228 inline void InstallCustomPropertyMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<PropertyBase>& property )
229 {
230   typedef MessageValue1< PropertyOwner, OwnerPointer<PropertyBase> > LocalType;
231
232   // Reserve some memory inside the message queue
233   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
234
235   // Construct message in the message queue memory; note that delete should not be called on the return value
236   new (slot) LocalType( &owner, &PropertyOwner::InstallCustomProperty, property );
237 }
238
239 inline void ApplyConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer<ConstraintBase>& constraint )
240 {
241   typedef MessageValue1< PropertyOwner, OwnerPointer<ConstraintBase> > LocalType;
242
243   // Reserve some memory inside the message queue
244   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
245
246   // Construct message in the message queue memory; note that delete should not be called on the return value
247   new (slot) LocalType( &owner, &PropertyOwner::ApplyConstraint, constraint );
248 }
249
250 inline void RemoveConstraintMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const ConstraintBase& constConstraint )
251 {
252   // The update-thread can modify this object.
253   ConstraintBase& constraint = const_cast< ConstraintBase& >( constConstraint );
254
255   typedef MessageValue1< PropertyOwner, ConstraintBase* > LocalType;
256
257   // Reserve some memory inside the message queue
258   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
259
260   // Construct message in the message queue memory; note that delete should not be called on the return value
261   new (slot) LocalType( &owner, &PropertyOwner::RemoveConstraint, &constraint );
262 }
263
264 inline void AddUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, OwnerPointer< UniformPropertyMapping >& map )
265 {
266   typedef MessageValue1< PropertyOwner, OwnerPointer< UniformPropertyMapping > > LocalType;
267
268   // Reserve some memory inside the message queue
269   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
270
271   new (slot) LocalType( &owner, &PropertyOwner::AddUniformMapping, map );
272 }
273
274 inline void RemoveUniformMapMessage( EventThreadServices& eventThreadServices, const PropertyOwner& owner, const std::string& uniformName )
275 {
276   typedef MessageValue1< PropertyOwner, std::string > LocalType;
277
278   // Reserve some memory inside the message queue
279   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
280
281   new (slot) LocalType( &owner, &PropertyOwner::RemoveUniformMapping, uniformName );
282 }
283
284
285 } // namespace SceneGraph
286
287 } // namespace Internal
288
289 } // namespace Dali
290
291 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H