X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fproperty-buffer-impl.cpp;h=ecd9a69723023796c989689ef4ac9762dd732157;hb=14502a507909174b52e486a0ee7516cb26e6ad45;hp=4bdcd1fb66d8404ee55738e3721928bb7dc37d4e;hpb=e6e076469c34355f7272afd82861812c0e323a1f;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/property-buffer-impl.cpp b/dali/internal/event/common/property-buffer-impl.cpp index 4bdcd1f..ecd9a69 100644 --- a/dali/internal/event/common/property-buffer-impl.cpp +++ b/dali/internal/event/common/property-buffer-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -16,16 +16,11 @@ */ // CLASS HEADER -#include // Dali::Internal::PropertyBuffer - -// EXTERNAL INCLUDE -#include // std::sort +#include // INTERNAL INCLUDES -#include // Dali::Internal::PropertyBuffer -#include // Dali::Internal::ObjectHelper -#include // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END -#include +#include +#include #include namespace Dali @@ -33,23 +28,10 @@ namespace Dali namespace Internal { -using SceneGraph::PropertyBufferMetadata::Format; -using SceneGraph::PropertyBufferMetadata::Component; - namespace { /** - * |name |type |writable|animatable|constraint-input|enum for index-checking| - */ -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 PROPERTY_BUFFER_IMPL = { DEFAULT_PROPERTY_DETAILS }; - -/** * Calculate the alignment requirements of a type * * This is used to calculate the memory alignment requirements of a type @@ -68,21 +50,12 @@ struct PropertyImplementationTypeAlignment enum { VALUE = offsetof( TestStructure, data ) }; }; -unsigned int GetPropertyImplementationAlignment( Property::Type& propertyType ) +uint32_t GetPropertyImplementationAlignment( Property::Type& propertyType ) { - unsigned int alignment = 0u; + uint32_t alignment = 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: { alignment = PropertyImplementationTypeAlignment< Property::BOOLEAN >::VALUE; @@ -93,11 +66,6 @@ unsigned int GetPropertyImplementationAlignment( Property::Type& propertyType ) alignment = PropertyImplementationTypeAlignment< Property::INTEGER >::VALUE; break; } - case Property::UNSIGNED_INTEGER: - { - alignment = PropertyImplementationTypeAlignment< Property::UNSIGNED_INTEGER >::VALUE; - break; - } case Property::FLOAT: { alignment = PropertyImplementationTypeAlignment< Property::FLOAT >::VALUE; @@ -138,6 +106,14 @@ unsigned int GetPropertyImplementationAlignment( Property::Type& propertyType ) 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 alignment; @@ -145,283 +121,113 @@ unsigned int GetPropertyImplementationAlignment( Property::Type& propertyType ) } // 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( data ); - std::copy( source, source + mBuffer.Size(), &mBuffer[0] ); - - SceneGraph::SetDataMessage( GetEventThreadServices(), - *mSceneObject, - new SceneGraph::PropertyBuffer::BufferType( mBuffer ) ); -} - -const SceneGraph::PropertyBuffer* PropertyBuffer::GetPropertyBufferSceneObject() const -{ - return mSceneObject; -} - -void PropertyBuffer::SetFormat( Dali::Property::Map& format ) +PropertyBufferPtr PropertyBuffer::New( 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 ); -} + PropertyBufferPtr propertyBuffer( new PropertyBuffer() ); + propertyBuffer->Initialize( format ); -bool PropertyBuffer::IsDefaultPropertyWritable( Property::Index index ) const -{ - return PROPERTY_BUFFER_IMPL.IsDefaultPropertyWritable( index ); + return propertyBuffer; } -bool PropertyBuffer::IsDefaultPropertyAnimatable( Property::Index index ) const +void PropertyBuffer::SetData( const void* data, uint32_t size ) { - return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAnimatable( index ); -} + mSize = size; // size is the number of elements -bool PropertyBuffer::IsDefaultPropertyAConstraintInput( Property::Index index ) const -{ - return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAConstraintInput( index ); -} + uint32_t bufferSize = mBufferFormatSize * mSize; -Property::Type PropertyBuffer::GetDefaultPropertyType( Property::Index index ) const -{ - return PROPERTY_BUFFER_IMPL.GetDefaultPropertyType( index ); -} + // create a new DALi vector to store the buffer data + // the heap allocated vector will end up being owned by Render::PropertyBuffer + OwnerPointer< Vector > bufferCopy = new Dali::Vector(); + bufferCopy->Resize( bufferSize ); -void PropertyBuffer::SetDefaultProperty( Property::Index index, - const Property::Value& propertyValue ) -{ - switch( index ) - { - case Dali::PropertyBuffer::Property::SIZE: - { - SetSize( propertyValue.Get() ); - break; - } - case Dali::PropertyBuffer::Property::BUFFER_FORMAT: - { - DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" ); - break; - } - } -} + // copy the data + const uint8_t* source = static_cast( data ); + uint8_t* destination = &((*bufferCopy)[0]); + std::copy( source, source + bufferSize, destination ); -void PropertyBuffer::SetSceneGraphProperty( Property::Index index, - const PropertyMetadata& entry, - const Property::Value& value ) -{ - PROPERTY_BUFFER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value ); + // Ownership of the bufferCopy is passed to the message ( uses an owner pointer ) + SceneGraph::SetPropertyBufferData( mEventThreadServices.GetUpdateManager(), *mRenderObject, bufferCopy, mSize ); } -Property::Value PropertyBuffer::GetDefaultProperty( Property::Index index ) const +uint32_t PropertyBuffer::GetSize() const { - Property::Value value; - - switch( index ) - { - case Dali::PropertyBuffer::Property::SIZE: - { - value = static_cast( GetSize() ); // @todo MESH_REWORK Add a size_t type to PropertyValue - break; - } - case Dali::PropertyBuffer::Property::BUFFER_FORMAT: - { - DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" ); - break; - } - } - return value; -} - -const SceneGraph::PropertyOwner* PropertyBuffer::GetPropertyOwner() const -{ - return mSceneObject; -} - -const SceneGraph::PropertyOwner* PropertyBuffer::GetSceneObject() const -{ - return mSceneObject; + return mSize; } -const SceneGraph::PropertyBase* PropertyBuffer::GetSceneObjectAnimatableProperty( Property::Index index ) const +const Render::PropertyBuffer* PropertyBuffer::GetRenderObject() const { - 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 ); - - if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT ) - { - DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" ); - } - } - - return property; + return mRenderObject; } -const PropertyInputImpl* PropertyBuffer::GetSceneObjectInputProperty( Property::Index index ) const +PropertyBuffer::~PropertyBuffer() { - const PropertyInputImpl* property = NULL; - - if( OnStage() ) + if( EventThreadServices::IsCoreRunning() && mRenderObject) { - const SceneGraph::PropertyBase* baseProperty = - PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty( this, - &PropertyBuffer::FindAnimatableProperty, - &PropertyBuffer::FindCustomProperty, - index ); - property = static_cast( baseProperty ); - - if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT ) - { - if( index == Dali::PropertyBuffer::Property::SIZE ) - { - // @todo MESH_REWORK - DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" ); - } - } + SceneGraph::RemovePropertyBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject ); } - - return property; -} - -int PropertyBuffer::GetPropertyComponentIndex( Property::Index index ) const -{ - return Property::INVALID_COMPONENT_INDEX; -} - -bool PropertyBuffer::OnStage() const -{ - return mOnStage; -} - -void PropertyBuffer::Connect() -{ - mOnStage = true; -} - -void PropertyBuffer::Disconnect() -{ - mOnStage = false; -} - -PropertyBuffer::~PropertyBuffer() -{ } PropertyBuffer::PropertyBuffer() -: mSceneObject( NULL ), - mBufferFormat( NULL ), - mSize( 0 ), - mOnStage( false ) +: mEventThreadServices( *Stage::GetCurrent() ), + mRenderObject( NULL ), + mBufferFormatSize( 0 ), + mSize( 0 ) { } -void PropertyBuffer::Initialize() +void PropertyBuffer::Initialize( Dali::Property::Map& formatMap ) { - EventThreadServices& eventThreadServices = GetEventThreadServices(); - SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); - - DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" ); + mRenderObject = new Render::PropertyBuffer(); + OwnerPointer< Render::PropertyBuffer > transferOwnership( mRenderObject ); + SceneGraph::AddPropertyBuffer( mEventThreadServices.GetUpdateManager(), transferOwnership ); - mSceneObject = new SceneGraph::PropertyBuffer(); - AddMessage( updateManager, updateManager.GetPropertyBufferOwner(), *mSceneObject ); -} - -void PropertyBuffer::FormatChanged() -{ - size_t numComponents = mFormat.Count(); + uint32_t numComponents = static_cast( 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 ); - unsigned int currentAlignment = 0u; - unsigned int maxAlignmentRequired = 0u; + uint32_t currentAlignment = 0u; + uint32_t maxAlignmentRequired = 0u; - 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; // enums are stored in the map as int Property::Type type = Property::Type( component.second.Get() ); // Get the size and alignment - unsigned int elementSize = GetPropertyImplementationSize( type ); - unsigned int elementAlignment = GetPropertyImplementationAlignment( type ); + 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( unsigned int offset = currentAlignment % elementAlignment ) + if( uint32_t offset = currentAlignment % elementAlignment ) { // Not compatible, realign currentAlignment = currentAlignment + elementSize - offset; } // write to the format - bufferFormat->components[i].size = elementSize; - bufferFormat->components[i].offset = currentAlignment; - bufferFormat->components[i].type = type; + format->components[i].size = elementSize; + format->components[i].offset = currentAlignment; + format->components[i].type = type; // update offset currentAlignment += elementSize; @@ -435,52 +241,29 @@ void PropertyBuffer::FormatChanged() } // Check the alignment for the maxAlignment required to calculate the size of the format - if( unsigned int offset = currentAlignment % maxAlignmentRequired ) + if( maxAlignmentRequired != 0 ) { - // Not compatible, realign - currentAlignment = currentAlignment + maxAlignmentRequired - offset; + if( uint32_t offset = currentAlignment % maxAlignmentRequired ) + { + // Not compatible, realign + currentAlignment = currentAlignment + maxAlignmentRequired - offset; + } } // Set the format size - bufferFormat->size = currentAlignment; + format->size = currentAlignment; - mBufferFormat = bufferFormat; + mBufferFormatSize = format->size; - SceneGraph::SetFormatMessage( GetEventThreadServices(), - *mSceneObject, - bufferFormat ); - - if( mSize ) - { - SizeChanged(); - } + SceneGraph::SetPropertyBufferFormat(mEventThreadServices.GetUpdateManager(), *mRenderObject, format ); } -void PropertyBuffer::SizeChanged() +uint32_t GetPropertyImplementationSize( Property::Type& propertyType ) { - // Check if format and size have been set yet - if( mBufferFormat != NULL ) - { - unsigned int bufferSize = mBufferFormat->size * mSize; - mBuffer.Resize( bufferSize ); - } -} - -unsigned int 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 ); @@ -491,11 +274,6 @@ unsigned int GetPropertyImplementationSize( Property::Type& propertyType ) size = sizeof( PropertyImplementationType< Property::INTEGER >::Type ); break; } - case Property::UNSIGNED_INTEGER: - { - size = sizeof( PropertyImplementationType< Property::UNSIGNED_INTEGER >::Type ); - break; - } case Property::FLOAT: { size = sizeof( PropertyImplementationType< Property::FLOAT >::Type ); @@ -536,6 +314,14 @@ unsigned int GetPropertyImplementationSize( Property::Type& propertyType ) 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;