Uniform map handling
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-buffer-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/common/property-buffer-impl.h>  // Dali::Internal::PropertyBuffer
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/property-buffer.h>     // Dali::Internal::PropertyBuffer
23 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
24 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
25 #include <dali/internal/update/common/scene-graph-property-buffer.h>
26 #include <dali/internal/update/manager/update-manager.h>
27 // @todo MESH_REWORK remove this comment - Don't include "stage.h" - use GetEventThreadServices() instead.
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33
34 namespace
35 {
36
37 /**
38  *            |name    |type             |writable|animatable|constraint-input|enum for index-checking|
39  */
40 DALI_PROPERTY_TABLE_BEGIN
41 DALI_PROPERTY( "size",          UNSIGNED_INTEGER, true, false,  true,   Dali::PropertyBuffer::Property::SIZE )
42 DALI_PROPERTY( "buffer-format", MAP,              false, false, false,  Dali::PropertyBuffer::Property::BUFFER_FORMAT )
43 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
44
45 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> PROPERTY_BUFFER_IMPL = { DEFAULT_PROPERTY_DETAILS };
46
47 } // unnamed namespace
48
49 PropertyBufferPtr PropertyBuffer::New()
50 {
51   return PropertyBufferPtr( new PropertyBuffer() );
52 }
53
54 void PropertyBuffer::SetSize( std::size_t size )
55 {
56   //TODO: MESH_REWORK
57   DALI_ASSERT_ALWAYS( false && "MESH_REWORK" );
58 }
59
60 std::size_t PropertyBuffer::GetSize() const
61 {
62   //TODO: MESH_REWORK
63   DALI_ASSERT_ALWAYS( false && "MESH_REWORK" );
64
65   return 0;
66 }
67
68 void PropertyBuffer::SetData( void* data )
69 {
70   //TODO: MESH_REWORK
71   DALI_ASSERT_ALWAYS( false && "MESH_REWORK" );
72 }
73
74 Dali::Property::Index PropertyBuffer::GetPropertyIndex( const std::string name, std::size_t index )
75 {
76   //TODO: MESH_REWORK
77   DALI_ASSERT_ALWAYS( false && "MESH_REWORK" );
78   return 0;
79 }
80
81 const SceneGraph::PropertyBuffer* PropertyBuffer::GetPropertyBufferSceneObject() const
82 {
83   return mSceneObject;
84 }
85
86 unsigned int PropertyBuffer::GetDefaultPropertyCount() const
87 {
88   return PROPERTY_BUFFER_IMPL.GetDefaultPropertyCount();
89 }
90
91 void PropertyBuffer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
92 {
93   PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndices( indices );
94 }
95
96 const char* PropertyBuffer::GetDefaultPropertyName(Property::Index index) const
97 {
98   return PROPERTY_BUFFER_IMPL.GetDefaultPropertyName( index );
99 }
100
101 Property::Index PropertyBuffer::GetDefaultPropertyIndex( const std::string& name ) const
102 {
103   return PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndex( name );
104 }
105
106 bool PropertyBuffer::IsDefaultPropertyWritable( Property::Index index ) const
107 {
108   return PROPERTY_BUFFER_IMPL.IsDefaultPropertyWritable( index );
109 }
110
111 bool PropertyBuffer::IsDefaultPropertyAnimatable( Property::Index index ) const
112 {
113   return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAnimatable( index );
114 }
115
116 bool PropertyBuffer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
117 {
118   return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAConstraintInput( index );
119 }
120
121 Property::Type PropertyBuffer::GetDefaultPropertyType( Property::Index index ) const
122 {
123   return PROPERTY_BUFFER_IMPL.GetDefaultPropertyType( index );
124 }
125
126 void PropertyBuffer::SetDefaultProperty( Property::Index index,
127                                          const Property::Value& propertyValue )
128 {
129   switch( index )
130   {
131     case Dali::PropertyBuffer::Property::SIZE:
132     {
133       SetSize( propertyValue.Get<int>() );
134       break;
135     }
136     case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
137     {
138       DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
139       break;
140     }
141   }
142 }
143
144 void PropertyBuffer::SetSceneGraphProperty( Property::Index index,
145                                             const PropertyMetadata& entry,
146                                             const Property::Value& value )
147 {
148   PROPERTY_BUFFER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
149 }
150
151 Property::Value PropertyBuffer::GetDefaultProperty( Property::Index index ) const
152 {
153   Property::Value value;
154
155   switch( index )
156   {
157     case Dali::PropertyBuffer::Property::SIZE:
158     {
159       value = static_cast<int>( GetSize() ); // @todo MESH_REWORK Add a size_t type to PropertyValue
160       break;
161     }
162     case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
163     {
164       DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
165       break;
166     }
167   }
168   return value;
169 }
170
171 const SceneGraph::PropertyOwner* PropertyBuffer::GetPropertyOwner() const
172 {
173   return mSceneObject;
174 }
175
176 const SceneGraph::PropertyOwner* PropertyBuffer::GetSceneObject() const
177 {
178   return mSceneObject;
179 }
180
181 const SceneGraph::PropertyBase* PropertyBuffer::GetSceneObjectAnimatableProperty( Property::Index index ) const
182 {
183   DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
184   const SceneGraph::PropertyBase* property = NULL;
185
186   if( OnStage() )
187   {
188     property = PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty(
189       this,
190       &PropertyBuffer::FindAnimatableProperty,
191       &PropertyBuffer::FindCustomProperty,
192       index );
193
194     if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
195     {
196       DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
197     }
198   }
199
200   return property;
201 }
202
203 const PropertyInputImpl* PropertyBuffer::GetSceneObjectInputProperty( Property::Index index ) const
204 {
205   const PropertyInputImpl* property = NULL;
206
207   if( OnStage() )
208   {
209     const SceneGraph::PropertyBase* baseProperty =
210       PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty( this,
211                                                             &PropertyBuffer::FindAnimatableProperty,
212                                                             &PropertyBuffer::FindCustomProperty,
213                                                             index );
214     property = static_cast<const PropertyInputImpl*>( baseProperty );
215
216     if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
217     {
218       if( index == Dali::PropertyBuffer::Property::SIZE )
219       {
220         // @todo MESH_REWORK
221         DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
222       }
223     }
224   }
225
226   return property;
227 }
228
229 int PropertyBuffer::GetPropertyComponentIndex( Property::Index index ) const
230 {
231   return PROPERTY_BUFFER_IMPL.GetPropertyComponentIndex( index );
232 }
233
234 bool PropertyBuffer::OnStage() const
235 {
236   return mOnStage;
237 }
238
239 void PropertyBuffer::Connect()
240 {
241   mOnStage = true;
242 }
243
244 void PropertyBuffer::Disconnect()
245 {
246   mOnStage = false;
247 }
248
249 PropertyBuffer::PropertyBuffer()
250 : mSceneObject(NULL),
251   mOnStage( false )
252 {
253 }
254
255 } // namespace Internal
256 } // namespace Dali