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( !mTypeSet && "Type of property buffer can only be set once." );
110 case Dali::PropertyBuffer::STATIC:
112 mIsAnimatable = false;
115 case Dali::PropertyBuffer::ANIMATABLE:
117 mIsAnimatable = true;
124 #endif // DEBUG_ENABLED
127 void PropertyBuffer::SetFormat( Dali::Property::Map& format )
129 DALI_ASSERT_ALWAYS( format.Count() && "Format cannot be empty." );
131 DALI_ASSERT_DEBUG( 0 == mFormat.Count() && "Format of property buffer can only be set once." );
138 unsigned int PropertyBuffer::GetDefaultPropertyCount() const
140 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyCount();
143 void PropertyBuffer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
145 PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndices( indices );
148 const char* PropertyBuffer::GetDefaultPropertyName(Property::Index index) const
150 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyName( index );
153 Property::Index PropertyBuffer::GetDefaultPropertyIndex( const std::string& name ) const
155 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndex( name );
158 bool PropertyBuffer::IsDefaultPropertyWritable( Property::Index index ) const
160 return PROPERTY_BUFFER_IMPL.IsDefaultPropertyWritable( index );
163 bool PropertyBuffer::IsDefaultPropertyAnimatable( Property::Index index ) const
165 return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAnimatable( index );
168 bool PropertyBuffer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
170 return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAConstraintInput( index );
173 Property::Type PropertyBuffer::GetDefaultPropertyType( Property::Index index ) const
175 return PROPERTY_BUFFER_IMPL.GetDefaultPropertyType( index );
178 void PropertyBuffer::SetDefaultProperty( Property::Index index,
179 const Property::Value& propertyValue )
183 case Dali::PropertyBuffer::Property::SIZE:
185 SetSize( propertyValue.Get<int>() );
188 case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
190 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
196 void PropertyBuffer::SetSceneGraphProperty( Property::Index index,
197 const PropertyMetadata& entry,
198 const Property::Value& value )
200 PROPERTY_BUFFER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
203 Property::Value PropertyBuffer::GetDefaultProperty( Property::Index index ) const
205 Property::Value value;
209 case Dali::PropertyBuffer::Property::SIZE:
211 value = static_cast<int>( GetSize() ); // @todo MESH_REWORK Add a size_t type to PropertyValue
214 case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
216 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
223 const SceneGraph::PropertyOwner* PropertyBuffer::GetPropertyOwner() const
228 const SceneGraph::PropertyOwner* PropertyBuffer::GetSceneObject() const
233 const SceneGraph::PropertyBase* PropertyBuffer::GetSceneObjectAnimatableProperty( Property::Index index ) const
235 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
236 const SceneGraph::PropertyBase* property = NULL;
240 property = PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty(
242 &PropertyBuffer::FindAnimatableProperty,
243 &PropertyBuffer::FindCustomProperty,
246 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
248 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
255 const PropertyInputImpl* PropertyBuffer::GetSceneObjectInputProperty( Property::Index index ) const
257 const PropertyInputImpl* property = NULL;
261 const SceneGraph::PropertyBase* baseProperty =
262 PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty( this,
263 &PropertyBuffer::FindAnimatableProperty,
264 &PropertyBuffer::FindCustomProperty,
266 property = static_cast<const PropertyInputImpl*>( baseProperty );
268 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
270 if( index == Dali::PropertyBuffer::Property::SIZE )
273 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
281 int PropertyBuffer::GetPropertyComponentIndex( Property::Index index ) const
283 return PROPERTY_BUFFER_IMPL.GetPropertyComponentIndex( index );
286 bool PropertyBuffer::OnStage() const
291 void PropertyBuffer::Connect()
296 void PropertyBuffer::Disconnect()
301 PropertyBuffer::~PropertyBuffer()
305 PropertyBuffer::PropertyBuffer()
306 : mSceneObject( NULL ),
307 mBufferFormat( NULL ),
309 mIsAnimatable( false ),
317 void PropertyBuffer::Initialize()
319 EventThreadServices& eventThreadServices = GetEventThreadServices();
320 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
322 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
324 mSceneObject = new SceneGraph::PropertyBuffer();
325 AddMessage( updateManager, updateManager.GetPropertyBufferOwner(), *mSceneObject );
328 void PropertyBuffer::FormatChanged()
330 size_t numComponents = mFormat.Count();
333 DALI_ASSERT_DEBUG( mBufferFormat == NULL && "PropertyFormat should not be set yet" );
334 Format* bufferFormat = new Format();
335 bufferFormat->components.resize( numComponents );
337 unsigned int elementSize = 0;
338 for( size_t i = 0u; i < numComponents; ++i )
340 StringValuePair component = mFormat.GetPair( i );
343 bufferFormat->components[i].name = component.first;
346 Property::Type type = Property::Type( component.second.Get<int>() );
347 elementSize += GetPropertyImplementationSize( type );
349 // write the accumulatedSize
350 bufferFormat->components[i].accumulatedSize = elementSize;
353 mBufferFormat = bufferFormat;
355 SceneGraph::SetFormatMessage( GetEventThreadServices(),
365 void PropertyBuffer::SizeChanged()
367 // Check if format and size have been set yet
368 if( mBufferFormat != NULL )
370 unsigned int bufferSize = mBufferFormat->GetElementSize() * mSize;
371 mBuffer.Resize( bufferSize );
375 unsigned int GetPropertyImplementationSize( Property::Type& propertyType )
377 unsigned int size = 0u;
379 switch( propertyType )
382 case Property::TYPE_COUNT:
383 case Property::STRING:
384 case Property::ARRAY:
387 DALI_ASSERT_ALWAYS( "No size for properties with no type, or dynamic sizes" );
390 case Property::BOOLEAN:
392 size = sizeof( PropertyImplementationType< Property::BOOLEAN >::Type );
395 case Property::FLOAT:
397 size = sizeof( PropertyImplementationType< Property::FLOAT >::Type );
400 case Property::INTEGER:
402 size = sizeof( PropertyImplementationType< Property::INTEGER >::Type );
405 case Property::UNSIGNED_INTEGER:
407 size = sizeof( PropertyImplementationType< Property::UNSIGNED_INTEGER >::Type );
410 case Property::VECTOR2:
412 size = sizeof( PropertyImplementationType< Property::VECTOR2 >::Type );
415 case Property::VECTOR3:
417 size = sizeof( PropertyImplementationType< Property::VECTOR3 >::Type );
420 case Property::VECTOR4:
422 size = sizeof( PropertyImplementationType< Property::VECTOR4 >::Type );
425 case Property::MATRIX3:
427 size = sizeof( PropertyImplementationType< Property::MATRIX3 >::Type );
430 case Property::MATRIX:
432 size = sizeof( PropertyImplementationType< Property::MATRIX >::Type );
435 case Property::RECTANGLE:
437 size = sizeof( PropertyImplementationType< Property::RECTANGLE >::Type );
440 case Property::ROTATION:
442 size = sizeof( PropertyImplementationType< Property::ROTATION >::Type );
450 } // namespace Internal