2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
22 #include <algorithm> // std::sort
25 #include <dali/public-api/object/property-buffer.h> // Dali::Internal::PropertyBuffer
26 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
27 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
28 #include <dali/internal/update/common/scene-graph-property-buffer.h>
29 #include <dali/internal/update/manager/update-manager.h>
36 using SceneGraph::PropertyBufferMetadata::Format;
37 using SceneGraph::PropertyBufferMetadata::Component;
43 * |name |type |writable|animatable|constraint-input|enum for index-checking|
45 DALI_PROPERTY_TABLE_BEGIN
46 DALI_PROPERTY( "size", UNSIGNED_INTEGER, true, false, true, Dali::PropertyBuffer::Property::SIZE )
47 DALI_PROPERTY( "buffer-format", MAP, false, false, false, Dali::PropertyBuffer::Property::BUFFER_FORMAT )
48 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
50 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> PROPERTY_BUFFER_IMPL = { DEFAULT_PROPERTY_DETAILS };
52 } // unnamed namespace
54 PropertyBufferPtr PropertyBuffer::New()
56 PropertyBufferPtr propertyBuffer( new PropertyBuffer() );
57 propertyBuffer->Initialize();
59 return propertyBuffer;
62 void PropertyBuffer::SetSize( std::size_t size )
68 SceneGraph::SetSizeMessage( GetEventThreadServices(),
73 std::size_t PropertyBuffer::GetSize() const
78 void PropertyBuffer::SetData( const void* data )
80 DALI_ASSERT_DEBUG( mFormat.Count() && "Format must be set before setting the data." );
82 DALI_ASSERT_ALWAYS( mSize && "Size of the buffer must be set before setting the data." );
84 const char* source = static_cast<const char*>( data );
85 std::copy( source, source + mBuffer.Size(), &mBuffer[0] );
87 SceneGraph::SetDataMessage( GetEventThreadServices(),
89 new SceneGraph::PropertyBuffer::BufferType( mBuffer ) );
92 Dali::Property::Index PropertyBuffer::GetPropertyIndex( const std::string name, std::size_t index )
95 DALI_ASSERT_ALWAYS( false && "MESH_REWORK" );
99 const SceneGraph::PropertyBuffer* PropertyBuffer::GetPropertyBufferSceneObject() const
104 void PropertyBuffer::SetType( Dali::PropertyBuffer::Type type )
106 DALI_ASSERT_DEBUG( mType == Dali::PropertyBuffer::TYPE_COUNT && "Type can only be set once." );
107 DALI_ASSERT_DEBUG( type != Dali::PropertyBuffer::TYPE_COUNT && "Type must be set to a valid value." );
112 void PropertyBuffer::SetFormat( Dali::Property::Map& format )
114 DALI_ASSERT_ALWAYS( format.Count() && "Format cannot be empty." );
116 DALI_ASSERT_DEBUG( 0 == mFormat.Count() && "Format of property buffer can only be set once." );
123 unsigned int PropertyBuffer::GetDefaultPropertyCount() const
125 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyCount();
128 void PropertyBuffer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
130 PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndices( indices );
133 const char* PropertyBuffer::GetDefaultPropertyName(Property::Index index) const
135 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyName( index );
138 Property::Index PropertyBuffer::GetDefaultPropertyIndex( const std::string& name ) const
140 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndex( name );
143 bool PropertyBuffer::IsDefaultPropertyWritable( Property::Index index ) const
145 return PROPERTY_BUFFER_IMPL.IsDefaultPropertyWritable( index );
148 bool PropertyBuffer::IsDefaultPropertyAnimatable( Property::Index index ) const
150 return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAnimatable( index );
153 bool PropertyBuffer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
155 return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAConstraintInput( index );
158 Property::Type PropertyBuffer::GetDefaultPropertyType( Property::Index index ) const
160 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyType( index );
163 void PropertyBuffer::SetDefaultProperty( Property::Index index,
164 const Property::Value& propertyValue )
168 case Dali::PropertyBuffer::Property::SIZE:
170 SetSize( propertyValue.Get<int>() );
173 case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
175 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
181 void PropertyBuffer::SetSceneGraphProperty( Property::Index index,
182 const PropertyMetadata& entry,
183 const Property::Value& value )
185 PROPERTY_BUFFER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
188 Property::Value PropertyBuffer::GetDefaultProperty( Property::Index index ) const
190 Property::Value value;
194 case Dali::PropertyBuffer::Property::SIZE:
196 value = static_cast<int>( GetSize() ); // @todo MESH_REWORK Add a size_t type to PropertyValue
199 case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
201 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
208 const SceneGraph::PropertyOwner* PropertyBuffer::GetPropertyOwner() const
213 const SceneGraph::PropertyOwner* PropertyBuffer::GetSceneObject() const
218 const SceneGraph::PropertyBase* PropertyBuffer::GetSceneObjectAnimatableProperty( Property::Index index ) const
220 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
221 const SceneGraph::PropertyBase* property = NULL;
225 property = PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty(
227 &PropertyBuffer::FindAnimatableProperty,
228 &PropertyBuffer::FindCustomProperty,
231 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
233 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
240 const PropertyInputImpl* PropertyBuffer::GetSceneObjectInputProperty( Property::Index index ) const
242 const PropertyInputImpl* property = NULL;
246 const SceneGraph::PropertyBase* baseProperty =
247 PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty( this,
248 &PropertyBuffer::FindAnimatableProperty,
249 &PropertyBuffer::FindCustomProperty,
251 property = static_cast<const PropertyInputImpl*>( baseProperty );
253 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
255 if( index == Dali::PropertyBuffer::Property::SIZE )
258 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
266 int PropertyBuffer::GetPropertyComponentIndex( Property::Index index ) const
268 return PROPERTY_BUFFER_IMPL.GetPropertyComponentIndex( index );
271 bool PropertyBuffer::OnStage() const
276 void PropertyBuffer::Connect()
281 void PropertyBuffer::Disconnect()
286 PropertyBuffer::~PropertyBuffer()
290 PropertyBuffer::PropertyBuffer()
291 : mSceneObject( NULL ),
292 mBufferFormat( NULL ),
294 mType( Dali::PropertyBuffer::TYPE_COUNT ),
299 void PropertyBuffer::Initialize()
301 EventThreadServices& eventThreadServices = GetEventThreadServices();
302 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
304 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
306 mSceneObject = new SceneGraph::PropertyBuffer();
307 AddMessage( updateManager, updateManager.GetPropertyBufferOwner(), *mSceneObject );
310 void PropertyBuffer::FormatChanged()
312 size_t numComponents = mFormat.Count();
315 DALI_ASSERT_DEBUG( mBufferFormat == NULL && "PropertyFormat should not be set yet" );
316 Format* bufferFormat = new Format();
317 bufferFormat->components.resize( numComponents );
319 unsigned int elementSize = 0;
320 for( size_t i = 0u; i < numComponents; ++i )
322 StringValuePair component = mFormat.GetPair( i );
325 bufferFormat->components[i].name = component.first;
327 // Get the size ( enums are stored in the map as int )
328 Property::Type type = Property::Type( component.second.Get<int>() );
329 elementSize += GetPropertyImplementationSize( type );
331 // write the accumulatedSize
332 bufferFormat->components[i].accumulatedSize = elementSize;
335 mBufferFormat = bufferFormat;
337 SceneGraph::SetFormatMessage( GetEventThreadServices(),
347 void PropertyBuffer::SizeChanged()
349 // Check if format and size have been set yet
350 if( mBufferFormat != NULL )
352 unsigned int bufferSize = mBufferFormat->GetElementSize() * mSize;
353 mBuffer.Resize( bufferSize );
357 unsigned int GetPropertyImplementationSize( Property::Type& propertyType )
359 unsigned int size = 0u;
361 switch( propertyType )
364 case Property::TYPE_COUNT:
365 case Property::STRING:
366 case Property::ARRAY:
369 DALI_ASSERT_ALWAYS( "No size for properties with no type, or dynamic sizes" );
372 case Property::BOOLEAN:
374 size = sizeof( PropertyImplementationType< Property::BOOLEAN >::Type );
377 case Property::INTEGER:
379 size = sizeof( PropertyImplementationType< Property::INTEGER >::Type );
382 case Property::UNSIGNED_INTEGER:
384 size = sizeof( PropertyImplementationType< Property::UNSIGNED_INTEGER >::Type );
387 // TODO : MESH_REWORK : uncoment this code
388 // case Property::UNSIGNED_SHORT:
390 // size = sizeof( PropertyImplementationType< Property::UNSIGNED_SHORT >::Type );
393 case Property::FLOAT:
395 size = sizeof( PropertyImplementationType< Property::FLOAT >::Type );
398 case Property::VECTOR2:
400 size = sizeof( PropertyImplementationType< Property::VECTOR2 >::Type );
403 case Property::VECTOR3:
405 size = sizeof( PropertyImplementationType< Property::VECTOR3 >::Type );
408 case Property::VECTOR4:
410 size = sizeof( PropertyImplementationType< Property::VECTOR4 >::Type );
413 case Property::MATRIX3:
415 size = sizeof( PropertyImplementationType< Property::MATRIX3 >::Type );
418 case Property::MATRIX:
420 size = sizeof( PropertyImplementationType< Property::MATRIX >::Type );
423 case Property::RECTANGLE:
425 size = sizeof( PropertyImplementationType< Property::RECTANGLE >::Type );
428 case Property::ROTATION:
430 size = sizeof( PropertyImplementationType< Property::ROTATION >::Type );
438 } // namespace Internal