Revert "[Tizen] Restore Uploaded signal for BufferImage and ResourceImage"
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl-helper.h
1 #ifndef DALI_INTERNAL_OBJECT_IMPL_HELPER_H
2 #define DALI_INTERNAL_OBJECT_IMPL_HELPER_H
3
4 /*
5  * Copyright (c) 2018 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 <cstring>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/property.h> // Dali::Property
26 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
27 #include <dali/internal/event/common/property-helper.h> // Dali::Internal::PropertyDetails
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/update/common/animatable-property.h>
30 #include <dali/internal/update/common/property-owner-messages.h>
31 #include <dali/internal/update/manager/update-manager.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 class PropertyMetadata;
38 class AnimatablePropertyMetadata;
39 class CustomPropertyMetadata;
40 class PropertyInputImpl;
41
42 namespace SceneGraph
43 {
44
45 class PropertyBase;
46 class PropertyOwner;
47
48
49 } // namespace SceneGraph
50
51 // Typedefs to allow object methods to be passed via parameter
52 typedef AnimatablePropertyMetadata* (Object::*FindAnimatablePropertyMethod)( Property::Index index ) const;
53 typedef CustomPropertyMetadata* (Object::*FindCustomPropertyMethod)( Property::Index index ) const;
54
55
56 /**
57  * Helper template class to be used by class that implement Object
58  *
59  * Example:
60  *<pre>
61  * typename ObjectImplHelper<DEFAULT_PROPERTY_COUNT, DEFAULT_PROPERTY_DETAILS> MyObjectImpl;
62  *
63  * MyObjectImpl::GetDefaultPropertyCount();
64  * </pre>
65  */
66 template<int DEFAULT_PROPERTY_COUNT>
67 struct ObjectImplHelper
68 {
69   const PropertyDetails* DEFAULT_PROPERTY_DETAILS;
70   const int DEFAULT_PROPERTY_START_INDEX;
71
72   unsigned int GetDefaultPropertyCount() const
73   {
74     return DEFAULT_PROPERTY_COUNT;
75   }
76
77   void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
78   {
79     indices.Reserve( DEFAULT_PROPERTY_COUNT );
80
81     for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
82     {
83       indices.PushBack( DEFAULT_PROPERTY_START_INDEX + i );
84     }
85   }
86
87   const char* GetDefaultPropertyName( Property::Index index ) const
88   {
89     const char* name = NULL;
90
91     if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT )
92     {
93       name = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].name;
94     }
95
96     return name;
97   }
98
99   Property::Index GetDefaultPropertyIndex( const std::string& name ) const
100   {
101     Property::Index index = Property::INVALID_INDEX;
102
103     // Look for name in default properties
104     for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
105     {
106       const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
107       if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
108       {
109         index = i;
110         break;
111       }
112     }
113
114     return index;
115   }
116
117   bool IsDefaultPropertyWritable( Property::Index index ) const
118   {
119     bool isWritable = false;
120
121     if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT )
122     {
123       isWritable = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].writable;
124     }
125
126     return isWritable;
127   }
128
129   bool IsDefaultPropertyAnimatable( Property::Index index ) const
130   {
131     bool isAnimatable = false;
132
133     if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT )
134     {
135       isAnimatable =  DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].animatable;
136     }
137
138     return isAnimatable;
139   }
140
141   bool IsDefaultPropertyAConstraintInput( Property::Index index ) const
142   {
143     bool isConstraintInput = false;
144
145     if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT )
146     {
147       isConstraintInput = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].constraintInput;
148     }
149
150     return isConstraintInput;
151   }
152
153   Property::Type GetDefaultPropertyType( Property::Index index ) const
154   {
155     Property::Type type = Property::NONE;
156
157     if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT )
158     {
159       type =  DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].type;
160     }
161
162     return type;
163   }
164
165   // Get the (animatable) scene graph property. (All registered scene graph properties are animatable)
166   const SceneGraph::PropertyBase* GetRegisteredSceneGraphProperty(
167     const Object* object,
168     FindAnimatablePropertyMethod findAnimatablePropertyMethod,
169     FindCustomPropertyMethod findCustomPropertyMethod,
170     Property::Index index ) const
171   {
172     const SceneGraph::PropertyBase* property = NULL;
173     if ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX && index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )
174     {
175       AnimatablePropertyMetadata* animatable = (object->*findAnimatablePropertyMethod)( index );
176       DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
177       property = animatable->GetSceneGraphProperty();
178     }
179     else if ( ( index > CHILD_PROPERTY_REGISTRATION_START_INDEX ) && // Child properties are also stored as custom properties
180               ( index <= PROPERTY_CUSTOM_MAX_INDEX ) )
181     {
182       CustomPropertyMetadata* custom = (object->*findCustomPropertyMethod)( index );
183       DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
184       property = custom->GetSceneGraphProperty();
185     }
186     return property;
187   }
188
189   void SetSceneGraphProperty( EventThreadServices& eventThreadServices,
190                               const Object* object,
191                               Property::Index index,
192                               const PropertyMetadata& entry,
193                               const Property::Value& value ) const
194   {
195     const SceneGraph::PropertyOwner* sceneObject = object->GetSceneObject();
196
197     switch ( entry.GetType() )
198     {
199       case Property::BOOLEAN:
200       {
201         const SceneGraph::AnimatableProperty<bool>* property = dynamic_cast< const SceneGraph::AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
202         DALI_ASSERT_DEBUG( NULL != property );
203
204         // property is being used in a separate thread; queue a message to set the property
205         SceneGraph::AnimatablePropertyMessage<bool>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<bool>::Bake, value.Get<bool>() );
206
207         break;
208       }
209
210       case Property::FLOAT:
211       {
212         const SceneGraph::AnimatableProperty<float>* property = dynamic_cast< const SceneGraph::AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
213         DALI_ASSERT_DEBUG( NULL != property );
214
215         // property is being used in a separate thread; queue a message to set the property
216         SceneGraph::AnimatablePropertyMessage<float>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<float>::Bake, value.Get<float>() );
217
218         break;
219       }
220
221       case Property::INTEGER:
222       {
223         const SceneGraph::AnimatableProperty<int>* property = dynamic_cast< const SceneGraph::AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
224         DALI_ASSERT_DEBUG( NULL != property );
225
226         // property is being used in a separate thread; queue a message to set the property
227         SceneGraph::AnimatablePropertyMessage<int>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<int>::Bake, value.Get<int>() );
228
229         break;
230       }
231
232       case Property::VECTOR2:
233       {
234         const SceneGraph::AnimatableProperty<Vector2>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
235         DALI_ASSERT_DEBUG( NULL != property );
236
237         // property is being used in a separate thread; queue a message to set the property
238         SceneGraph::AnimatablePropertyMessage<Vector2>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector2>::Bake, value.Get<Vector2>() );
239
240         break;
241       }
242
243       case Property::VECTOR3:
244       {
245         const SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
246         DALI_ASSERT_DEBUG( NULL != property );
247
248         // property is being used in a separate thread; queue a message to set the property
249         SceneGraph::AnimatablePropertyMessage<Vector3>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector3>::Bake, value.Get<Vector3>() );
250
251         break;
252       }
253
254       case Property::VECTOR4:
255       {
256         const SceneGraph::AnimatableProperty<Vector4>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
257         DALI_ASSERT_DEBUG( NULL != property );
258
259         // property is being used in a separate thread; queue a message to set the property
260         SceneGraph::AnimatablePropertyMessage<Vector4>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector4>::Bake, value.Get<Vector4>() );
261
262         break;
263       }
264
265       case Property::ROTATION:
266       {
267         const SceneGraph::AnimatableProperty<Quaternion>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
268         DALI_ASSERT_DEBUG( NULL != property );
269
270         // property is being used in a separate thread; queue a message to set the property
271         SceneGraph::AnimatablePropertyMessage<Quaternion>::Send( eventThreadServices, sceneObject, property,&SceneGraph::AnimatableProperty<Quaternion>::Bake,  value.Get<Quaternion>() );
272
273         break;
274       }
275
276       case Property::MATRIX:
277       {
278         const SceneGraph::AnimatableProperty<Matrix>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
279         DALI_ASSERT_DEBUG( NULL != property );
280
281         // property is being used in a separate thread; queue a message to set the property
282         SceneGraph::AnimatablePropertyMessage<Matrix>::Send( eventThreadServices, sceneObject, property,&SceneGraph::AnimatableProperty<Matrix>::Bake,  value.Get<Matrix>() );
283
284         break;
285       }
286
287       case Property::MATRIX3:
288       {
289         const SceneGraph::AnimatableProperty<Matrix3>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
290         DALI_ASSERT_DEBUG( NULL != property );
291
292         // property is being used in a separate thread; queue a message to set the property
293         SceneGraph::AnimatablePropertyMessage<Matrix3>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Matrix3>::Bake,  value.Get<Matrix3>() );
294
295         break;
296       }
297
298       default:
299       {
300         // ignore non-scene-graph types
301       }
302     }
303   }
304 };
305
306
307
308 } // namespace Internal
309
310 } // namespace Dali
311
312 #endif // DALI_INTERNAL_OBJECT_IMPL_HELPER_H