/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// CLASS HEADER
-#include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
-
-// EXTERNAL INCLUDE
-#include <algorithm> // std::sort
+#include <dali/internal/event/common/property-buffer-impl.h>
// INTERNAL INCLUDES
-#include <dali/public-api/object/property-buffer.h> // Dali::Internal::PropertyBuffer
-#include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
-#include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
-#include <dali/internal/update/common/scene-graph-property-buffer.h>
+#include <dali/public-api/rendering/property-buffer.h>
#include <dali/internal/update/manager/update-manager.h>
namespace Dali
namespace Internal
{
-using SceneGraph::PropertyBufferMetadata::Format;
-using SceneGraph::PropertyBufferMetadata::Component;
-
namespace
{
/**
- * |name |type |writable|animatable|constraint-input|enum for index-checking|
+ * Calculate the alignment requirements of a type
+ *
+ * This is used to calculate the memory alignment requirements of a type
+ * It creates a structure with a dummy char and a member of the type we want to check
+ * this will cause the second member to be aligned by it's alignment requirement.
*/
-DALI_PROPERTY_TABLE_BEGIN
-DALI_PROPERTY( "size", UNSIGNED_INTEGER, true, false, true, Dali::PropertyBuffer::Property::SIZE )
-DALI_PROPERTY( "buffer-format", MAP, false, false, false, Dali::PropertyBuffer::Property::BUFFER_FORMAT )
-DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
-
-const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> PROPERTY_BUFFER_IMPL = { DEFAULT_PROPERTY_DETAILS };
-
-} // unnamed namespace
-
-PropertyBufferPtr PropertyBuffer::New()
-{
- PropertyBufferPtr propertyBuffer( new PropertyBuffer() );
- propertyBuffer->Initialize();
-
- return propertyBuffer;
-}
-
-void PropertyBuffer::SetSize( std::size_t size )
-{
- mSize = size;
-
- SizeChanged();
-
- SceneGraph::SetSizeMessage( GetEventThreadServices(),
- *mSceneObject,
- mSize );
-}
-
-std::size_t PropertyBuffer::GetSize() const
-{
- return mSize;
-}
-
-void PropertyBuffer::SetData( const void* data )
-{
- DALI_ASSERT_DEBUG( mFormat.Count() && "Format must be set before setting the data." );
-
- DALI_ASSERT_ALWAYS( mSize && "Size of the buffer must be set before setting the data." );
-
- const char* source = static_cast<const char*>( data );
- std::copy( source, source + mBuffer.Size(), &mBuffer[0] );
-
- SceneGraph::SetDataMessage( GetEventThreadServices(),
- *mSceneObject,
- new SceneGraph::PropertyBuffer::BufferType( mBuffer ) );
-}
-
-Dali::Property::Index PropertyBuffer::GetPropertyIndex( const std::string name, std::size_t index )
-{
- //TODO: MESH_REWORK
- DALI_ASSERT_ALWAYS( false && "MESH_REWORK" );
- return 0;
-}
-
-const SceneGraph::PropertyBuffer* PropertyBuffer::GetPropertyBufferSceneObject() const
-{
- return mSceneObject;
-}
-
-void PropertyBuffer::SetType( Dali::PropertyBuffer::Type type )
-{
- DALI_ASSERT_DEBUG( mType == Dali::PropertyBuffer::TYPE_COUNT && "Type can only be set once." );
- DALI_ASSERT_DEBUG( type != Dali::PropertyBuffer::TYPE_COUNT && "Type must be set to a valid value." );
-
- mType = type;
-}
-
-void PropertyBuffer::SetFormat( Dali::Property::Map& format )
-{
- DALI_ASSERT_ALWAYS( format.Count() && "Format cannot be empty." );
-
- DALI_ASSERT_DEBUG( 0 == mFormat.Count() && "Format of property buffer can only be set once." );
-
- mFormat = format;
-
- FormatChanged();
-}
-
-unsigned int PropertyBuffer::GetDefaultPropertyCount() const
-{
- return PROPERTY_BUFFER_IMPL.GetDefaultPropertyCount();
-}
-
-void PropertyBuffer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
-{
- PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndices( indices );
-}
-
-const char* PropertyBuffer::GetDefaultPropertyName(Property::Index index) const
-{
- return PROPERTY_BUFFER_IMPL.GetDefaultPropertyName( index );
-}
-
-Property::Index PropertyBuffer::GetDefaultPropertyIndex( const std::string& name ) const
-{
- return PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndex( name );
-}
-
-bool PropertyBuffer::IsDefaultPropertyWritable( Property::Index index ) const
-{
- return PROPERTY_BUFFER_IMPL.IsDefaultPropertyWritable( index );
-}
-
-bool PropertyBuffer::IsDefaultPropertyAnimatable( Property::Index index ) const
+template<Property::Type type>
+struct PropertyImplementationTypeAlignment
{
- return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAnimatable( index );
-}
-
-bool PropertyBuffer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
-{
- return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAConstraintInput( index );
-}
+ // Create a structure that forces alignment of the data type
+ struct TestStructure
+ {
+ char oneChar; ///< Member with sizeof() == 1
+ typename PropertyImplementationType<type>::Type data;
+ };
+ enum { VALUE = offsetof( TestStructure, data ) };
+};
-Property::Type PropertyBuffer::GetDefaultPropertyType( Property::Index index ) const
+uint32_t GetPropertyImplementationAlignment( Property::Type& propertyType )
{
- return PROPERTY_BUFFER_IMPL.GetDefaultPropertyType( index );
-}
+ uint32_t alignment = 0u;
-void PropertyBuffer::SetDefaultProperty( Property::Index index,
- const Property::Value& propertyValue )
-{
- switch( index )
+ switch( propertyType )
{
- case Dali::PropertyBuffer::Property::SIZE:
+ case Property::BOOLEAN:
{
- SetSize( propertyValue.Get<int>() );
+ alignment = PropertyImplementationTypeAlignment< Property::BOOLEAN >::VALUE;
break;
}
- case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
+ case Property::INTEGER:
{
- DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
+ alignment = PropertyImplementationTypeAlignment< Property::INTEGER >::VALUE;
break;
}
- }
-}
-
-void PropertyBuffer::SetSceneGraphProperty( Property::Index index,
- const PropertyMetadata& entry,
- const Property::Value& value )
-{
- PROPERTY_BUFFER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
-}
-
-Property::Value PropertyBuffer::GetDefaultProperty( Property::Index index ) const
-{
- Property::Value value;
-
- switch( index )
- {
- case Dali::PropertyBuffer::Property::SIZE:
+ case Property::FLOAT:
+ {
+ alignment = PropertyImplementationTypeAlignment< Property::FLOAT >::VALUE;
+ break;
+ }
+ case Property::VECTOR2:
+ {
+ alignment = PropertyImplementationTypeAlignment< Property::VECTOR2 >::VALUE;
+ break;
+ }
+ case Property::VECTOR3:
{
- value = static_cast<int>( GetSize() ); // @todo MESH_REWORK Add a size_t type to PropertyValue
+ alignment = PropertyImplementationTypeAlignment< Property::VECTOR3 >::VALUE;
break;
}
- case Dali::PropertyBuffer::Property::BUFFER_FORMAT:
+ case Property::VECTOR4:
+ {
+ alignment = PropertyImplementationTypeAlignment< Property::VECTOR4 >::VALUE;
+ break;
+ }
+ case Property::MATRIX3:
+ {
+ alignment = PropertyImplementationTypeAlignment< Property::MATRIX3 >::VALUE;
+ break;
+ }
+ case Property::MATRIX:
+ {
+ alignment = PropertyImplementationTypeAlignment< Property::MATRIX >::VALUE;
+ break;
+ }
+ case Property::RECTANGLE:
+ {
+ alignment = PropertyImplementationTypeAlignment< Property::RECTANGLE >::VALUE;
+ break;
+ }
+ case Property::ROTATION:
{
- DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
+ alignment = PropertyImplementationTypeAlignment< Property::ROTATION >::VALUE;
break;
}
+ case Property::NONE:
+ case Property::STRING:
+ case Property::ARRAY:
+ case Property::MAP:
+ case Property::EXTENTS:
+ {
+ // already handled by higher level code
+ }
}
- return value;
-}
-const SceneGraph::PropertyOwner* PropertyBuffer::GetPropertyOwner() const
-{
- return mSceneObject;
+ return alignment;
}
-const SceneGraph::PropertyOwner* PropertyBuffer::GetSceneObject() const
-{
- return mSceneObject;
-}
+} // unnamed namespace
-const SceneGraph::PropertyBase* PropertyBuffer::GetSceneObjectAnimatableProperty( Property::Index index ) const
+PropertyBufferPtr PropertyBuffer::New( Dali::Property::Map& format )
{
- DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
- const SceneGraph::PropertyBase* property = NULL;
-
- if( OnStage() )
- {
- property = PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty(
- this,
- &PropertyBuffer::FindAnimatableProperty,
- &PropertyBuffer::FindCustomProperty,
- index );
+ DALI_ASSERT_ALWAYS( format.Count() && "Format cannot be empty." );
- if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
- {
- DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
- }
- }
+ PropertyBufferPtr propertyBuffer( new PropertyBuffer() );
+ propertyBuffer->Initialize( format );
- return property;
+ return propertyBuffer;
}
-const PropertyInputImpl* PropertyBuffer::GetSceneObjectInputProperty( Property::Index index ) const
+void PropertyBuffer::SetData( const void* data, uint32_t size )
{
- const PropertyInputImpl* property = NULL;
+ mSize = size; // size is the number of elements
- if( OnStage() )
- {
- const SceneGraph::PropertyBase* baseProperty =
- PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty( this,
- &PropertyBuffer::FindAnimatableProperty,
- &PropertyBuffer::FindCustomProperty,
- index );
- property = static_cast<const PropertyInputImpl*>( baseProperty );
-
- if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
- {
- if( index == Dali::PropertyBuffer::Property::SIZE )
- {
- // @todo MESH_REWORK
- DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
- }
- }
- }
+ uint32_t bufferSize = mBufferFormatSize * mSize;
- return property;
-}
+ // create a new DALi vector to store the buffer data
+ // the heap allocated vector will end up being owned by Render::PropertyBuffer
+ OwnerPointer< Vector<uint8_t> > bufferCopy = new Dali::Vector<uint8_t>();
+ bufferCopy->Resize( bufferSize );
-int PropertyBuffer::GetPropertyComponentIndex( Property::Index index ) const
-{
- return PROPERTY_BUFFER_IMPL.GetPropertyComponentIndex( index );
-}
+ // copy the data
+ const uint8_t* source = static_cast<const uint8_t*>( data );
+ uint8_t* destination = &((*bufferCopy)[0]);
+ std::copy( source, source + bufferSize, destination );
-bool PropertyBuffer::OnStage() const
-{
- return mOnStage;
+ // Ownership of the bufferCopy is passed to the message ( uses an owner pointer )
+ SceneGraph::SetPropertyBufferData( mEventThreadServices.GetUpdateManager(), *mRenderObject, bufferCopy, mSize );
}
-void PropertyBuffer::Connect()
+uint32_t PropertyBuffer::GetSize() const
{
- mOnStage = true;
+ return mSize;
}
-void PropertyBuffer::Disconnect()
+const Render::PropertyBuffer* PropertyBuffer::GetRenderObject() const
{
- mOnStage = false;
+ return mRenderObject;
}
PropertyBuffer::~PropertyBuffer()
{
+ if( EventThreadServices::IsCoreRunning() && mRenderObject)
+ {
+ SceneGraph::RemovePropertyBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
+ }
}
PropertyBuffer::PropertyBuffer()
-: mSceneObject( NULL ),
- mBufferFormat( NULL ),
- mSize( 0 ),
- mType( Dali::PropertyBuffer::TYPE_COUNT ),
- mOnStage( false )
+: mEventThreadServices( EventThreadServices::Get() ),
+ mRenderObject( NULL ),
+ mBufferFormatSize( 0 ),
+ mSize( 0 )
{
}
-void PropertyBuffer::Initialize()
+void PropertyBuffer::Initialize( Dali::Property::Map& formatMap )
{
- EventThreadServices& eventThreadServices = GetEventThreadServices();
- SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
+ mRenderObject = new Render::PropertyBuffer();
+ OwnerPointer< Render::PropertyBuffer > transferOwnership( mRenderObject );
+ SceneGraph::AddPropertyBuffer( mEventThreadServices.GetUpdateManager(), transferOwnership );
- DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
-
- mSceneObject = new SceneGraph::PropertyBuffer();
- AddMessage( updateManager, updateManager.GetPropertyBufferOwner(), *mSceneObject );
-}
-
-void PropertyBuffer::FormatChanged()
-{
- size_t numComponents = mFormat.Count();
+ uint32_t numComponents = static_cast<uint32_t>( formatMap.Count() );
// Create the format
- DALI_ASSERT_DEBUG( mBufferFormat == NULL && "PropertyFormat should not be set yet" );
- Format* bufferFormat = new Format();
- bufferFormat->components.resize( numComponents );
+ OwnerPointer< Render::PropertyBuffer::Format> format = new Render::PropertyBuffer::Format();
+ format->components.resize( numComponents );
+
+ uint32_t currentAlignment = 0u;
+ uint32_t maxAlignmentRequired = 0u;
- unsigned int elementSize = 0;
- for( size_t i = 0u; i < numComponents; ++i )
+ for( uint32_t i = 0u; i < numComponents; ++i )
{
- StringValuePair component = mFormat.GetPair( i );
+ KeyValuePair component = formatMap.GetKeyValue( i );
// Get the name
- bufferFormat->components[i].name = component.first;
+ if(component.first.type == Property::Key::INDEX)
+ {
+ continue;
+ }
+ format->components[i].name = component.first.stringKey;
- // Get the size ( enums are stored in the map as int )
+ // enums are stored in the map as int
Property::Type type = Property::Type( component.second.Get<int>() );
- elementSize += GetPropertyImplementationSize( type );
- // write the accumulatedSize
- bufferFormat->components[i].accumulatedSize = elementSize;
- }
+ // Get the size and alignment
+ if( ( type == Property::NONE ) ||
+ ( type == Property::STRING ) ||
+ ( type == Property::ARRAY ) ||
+ ( type == Property::MAP ) )
+ {
+ DALI_ABORT( "Property::Type not supported in PropertyBuffer" );
+ }
+ uint32_t elementSize = GetPropertyImplementationSize( type );
+ uint32_t elementAlignment = GetPropertyImplementationAlignment( type );
+
+ // check if current alignment is compatible with new member
+ if( uint32_t offset = currentAlignment % elementAlignment )
+ {
+ // Not compatible, realign
+ currentAlignment = currentAlignment + elementSize - offset;
+ }
- mBufferFormat = bufferFormat;
+ // write to the format
+ format->components[i].size = elementSize;
+ format->components[i].offset = currentAlignment;
+ format->components[i].type = type;
- SceneGraph::SetFormatMessage( GetEventThreadServices(),
- *mSceneObject,
- bufferFormat );
+ // update offset
+ currentAlignment += elementSize;
+
+ // update max alignment requirement
+ if( elementAlignment > maxAlignmentRequired )
+ {
+ maxAlignmentRequired = elementAlignment;
+ }
- if( mSize )
- {
- SizeChanged();
}
-}
-void PropertyBuffer::SizeChanged()
-{
- // Check if format and size have been set yet
- if( mBufferFormat != NULL )
+ // Check the alignment for the maxAlignment required to calculate the size of the format
+ if( maxAlignmentRequired != 0 )
{
- unsigned int bufferSize = mBufferFormat->GetElementSize() * mSize;
- mBuffer.Resize( bufferSize );
+ if( uint32_t offset = currentAlignment % maxAlignmentRequired )
+ {
+ // Not compatible, realign
+ currentAlignment = currentAlignment + maxAlignmentRequired - offset;
+ }
}
+
+ // Set the format size
+ format->size = currentAlignment;
+
+ mBufferFormatSize = format->size;
+
+ SceneGraph::SetPropertyBufferFormat(mEventThreadServices.GetUpdateManager(), *mRenderObject, format );
}
-unsigned int GetPropertyImplementationSize( Property::Type& propertyType )
+uint32_t GetPropertyImplementationSize( Property::Type& propertyType )
{
- unsigned int size = 0u;
+ uint32_t size = 0u;
switch( propertyType )
{
- case Property::NONE:
- case Property::TYPE_COUNT:
- case Property::STRING:
- case Property::ARRAY:
- case Property::MAP:
- {
- DALI_ASSERT_ALWAYS( "No size for properties with no type, or dynamic sizes" );
- break;
- }
case Property::BOOLEAN:
{
size = sizeof( PropertyImplementationType< Property::BOOLEAN >::Type );
size = sizeof( PropertyImplementationType< Property::INTEGER >::Type );
break;
}
- case Property::UNSIGNED_INTEGER:
- {
- size = sizeof( PropertyImplementationType< Property::UNSIGNED_INTEGER >::Type );
- break;
- }
- // TODO : MESH_REWORK : uncoment this code
-// case Property::UNSIGNED_SHORT:
-// {
-// size = sizeof( PropertyImplementationType< Property::UNSIGNED_SHORT >::Type );
-// break;
-// }
case Property::FLOAT:
{
size = sizeof( PropertyImplementationType< Property::FLOAT >::Type );
size = sizeof( PropertyImplementationType< Property::ROTATION >::Type );
break;
}
+ case Property::NONE:
+ case Property::STRING:
+ case Property::ARRAY:
+ case Property::MAP:
+ case Property::EXTENTS:
+ {
+ // already handled by higher level code
+ }
}
return size;
}
+
} // namespace Internal
} // namespace Dali