X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fproperty-buffer-impl.cpp;h=c44df2ce8b1e27adf27d763d9c90b5dde9dae6f0;hb=d8944bba8449a3c5bce03041eccccf2eba4a7ae3;hp=7b00e9ec1edaf849b8a02cabe1cb9fbce711eea9;hpb=9e6fd5c8ae44b09b759674e98135d57b29bd88e4;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 7b00e9e..c44df2c 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) 2016 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. @@ -20,7 +20,6 @@ // INTERNAL INCLUDES #include -#include #include namespace Dali @@ -50,20 +49,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::STRING: - case Property::ARRAY: - case Property::MAP: - { - DALI_ASSERT_ALWAYS( false && "No size for properties with no type, or dynamic sizes" ); - break; - } case Property::BOOLEAN: { alignment = PropertyImplementationTypeAlignment< Property::BOOLEAN >::VALUE; @@ -114,6 +105,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; @@ -131,26 +130,27 @@ PropertyBufferPtr PropertyBuffer::New( Dali::Property::Map& format ) return propertyBuffer; } -void PropertyBuffer::SetData( const void* data, std::size_t size ) +void PropertyBuffer::SetData( const void* data, uint32_t size ) { - DALI_ASSERT_DEBUG( mFormat.Count() && "Format must be set before setting the data." ); + mSize = size; // size is the number of elements - mSize = size; + uint32_t bufferSize = mBufferFormatSize * mSize; - // Check if format and size have been set yet - if( mBufferFormat != NULL ) - { - unsigned int bufferSize = mBufferFormat->size * mSize; - mBuffer.Resize( bufferSize ); - } + // 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 ); - const char* source = static_cast( data ); - std::copy( source, source + mBuffer.Size(), &mBuffer[0] ); + // copy the data + const uint8_t* source = static_cast( data ); + uint8_t* destination = &((*bufferCopy)[0]); + std::copy( source, source + bufferSize, destination ); - SceneGraph::SetPropertyBufferData( mEventThreadServices.GetUpdateManager(), *mRenderObject, new Dali::Vector( mBuffer ), mSize ); + // Ownership of the bufferCopy is passed to the message ( uses an owner pointer ) + SceneGraph::SetPropertyBufferData( mEventThreadServices.GetUpdateManager(), *mRenderObject, bufferCopy, mSize ); } -std::size_t PropertyBuffer::GetSize() const +uint32_t PropertyBuffer::GetSize() const { return mSize; } @@ -169,9 +169,9 @@ PropertyBuffer::~PropertyBuffer() } PropertyBuffer::PropertyBuffer() -: mEventThreadServices( *Stage::GetCurrent() ), +: mEventThreadServices( EventThreadServices::Get() ), mRenderObject( NULL ), - mBufferFormat( NULL ), + mBufferFormatSize( 0 ), mSize( 0 ) { } @@ -179,36 +179,45 @@ PropertyBuffer::PropertyBuffer() void PropertyBuffer::Initialize( Dali::Property::Map& formatMap ) { mRenderObject = new Render::PropertyBuffer(); - SceneGraph::AddPropertyBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject ); + OwnerPointer< Render::PropertyBuffer > transferOwnership( mRenderObject ); + SceneGraph::AddPropertyBuffer( mEventThreadServices.GetUpdateManager(), transferOwnership ); - mFormat = formatMap; - - 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" ); - Render::PropertyBuffer::Format* format = new Render::PropertyBuffer::Format(); + 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 - format->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; @@ -233,7 +242,7 @@ void PropertyBuffer::Initialize( Dali::Property::Map& formatMap ) // Check the alignment for the maxAlignment required to calculate the size of the format if( maxAlignmentRequired != 0 ) { - if( unsigned int offset = currentAlignment % maxAlignmentRequired ) + if( uint32_t offset = currentAlignment % maxAlignmentRequired ) { // Not compatible, realign currentAlignment = currentAlignment + maxAlignmentRequired - offset; @@ -243,25 +252,17 @@ void PropertyBuffer::Initialize( Dali::Property::Map& formatMap ) // Set the format size format->size = currentAlignment; - mBufferFormat = format; + 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::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 ); @@ -312,6 +313,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;