X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fnodes%2Fnode.cpp;h=e873a6f48024f5415d1835094da9a760ce4fa394;hb=9ac94c145f620fc90c39a0f3dadbd88cc4b01940;hp=1b74e67cc16dae13e96ed65489903dad0b1ff7b5;hpb=9d825be196fa6565a6dabc8647fe4867f5e9a89a;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/nodes/node.cpp b/dali/internal/update/nodes/node.cpp index 1b74e67..e873a6f 100644 --- a/dali/internal/update/nodes/node.cpp +++ b/dali/internal/update/nodes/node.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -19,11 +19,18 @@ #include // INTERNAL INCLUDES -#include +#include +#include #include #include #include +namespace //Unnamed namespace +{ +//Memory pool used to allocate new nodes. Memory used by this pool will be released when shutting down DALi +Dali::Internal::MemoryPoolObjectAllocator gNodeMemoryPool; +} + namespace Dali { @@ -38,63 +45,80 @@ const ColorMode Node::DEFAULT_COLOR_MODE( USE_OWN_MULTIPLY_PARENT_ALPHA ); Node* Node::New() { - return new Node(); + return new ( gNodeMemoryPool.AllocateRawThreadSafe() ) Node(); } Node::Node() -: mParentOrigin( ParentOrigin::DEFAULT ), - mAnchorPoint( AnchorPoint::DEFAULT ), - mSize(), // zero initialized by default - mPosition(), // zero initialized by default - mOrientation(), // initialized to identity by default - mScale( Vector3::ONE ), +: mTransformManager(0), + mTransformId( INVALID_TRANSFORM_ID ), + mParentOrigin( TRANSFORM_PROPERTY_PARENT_ORIGIN ), + mAnchorPoint( TRANSFORM_PROPERTY_ANCHOR_POINT ), + mSize( TRANSFORM_PROPERTY_SIZE ), // Zero initialized by default + mPosition( TRANSFORM_PROPERTY_POSITION ), // Zero initialized by default + mOrientation(), // Initialized to identity by default + mScale( TRANSFORM_PROPERTY_SCALE ), mVisible( true ), mColor( Color::WHITE ), - mWorldPosition(), // zero initialized by default - mWorldOrientation(), // initialized to identity by default - mWorldScale( Vector3::ONE ), + mWorldPosition( TRANSFORM_PROPERTY_WORLD_POSITION, Vector3( 0.0f,0.0f,0.0f ) ), // Zero initialized by default + mWorldScale( TRANSFORM_PROPERTY_WORLD_SCALE, Vector3( 1.0f,1.0f,1.0f ) ), + mWorldOrientation(), // Initialized to identity by default mWorldMatrix(), mWorldColor( Color::WHITE ), + mClippingSortModifier( 0u ), mParent( NULL ), mExclusiveRenderTask( NULL ), - mAttachment( NULL ), mChildren(), - mDirtyFlags(AllFlags), - mIsRoot( false ), - mInheritOrientation( true ), - mInheritScale( true ), - mInhibitLocalTransform( false ), - mIsActive( true ), + mClippingDepth( 0u ), + mRegenerateUniformMap( 0 ), + mDepth( 0u ), + mDirtyFlags( AllFlags ), mDrawMode( DrawMode::NORMAL ), - mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ), - mColorMode( DEFAULT_COLOR_MODE ) + mColorMode( DEFAULT_COLOR_MODE ), + mClippingMode( ClippingMode::DISABLED ), + mIsRoot( false ) { + mUniformMapChanged[0] = 0u; + mUniformMapChanged[1] = 0u; } Node::~Node() { + if( mTransformId != INVALID_TRANSFORM_ID ) + { + mTransformManager->RemoveTransform(mTransformId); + } } -void Node::OnDestroy() +void Node::operator delete( void* ptr ) { - // Node attachments should be notified about the disconnection. - if ( mAttachment ) - { - mAttachment->OnDestroy(); - } + gNodeMemoryPool.FreeThreadSafe( static_cast( ptr ) ); +} +void Node::OnDestroy() +{ // Animators, Constraints etc. should be disconnected from the child's properties. PropertyOwner::Destroy(); } -void Node::Attach( NodeAttachment& object ) +void Node::CreateTransform( SceneGraph::TransformManager* transformManager ) { - DALI_ASSERT_DEBUG(!mAttachment); - - object.SetParent(*this); - - mAttachment = &object; - SetAllDirtyFlags(); + //Create a new transform + mTransformManager = transformManager; + mTransformId = transformManager->CreateTransform(); + + //Initialize all the animatable properties + mPosition.Initialize( transformManager, mTransformId ); + mScale.Initialize( transformManager, mTransformId ); + mOrientation.Initialize( transformManager, mTransformId ); + mSize.Initialize( transformManager, mTransformId ); + mParentOrigin.Initialize( transformManager, mTransformId ); + mAnchorPoint.Initialize( transformManager, mTransformId ); + + //Initialize all the input properties + mWorldPosition.Initialize( transformManager, mTransformId ); + mWorldScale.Initialize( transformManager, mTransformId ); + mWorldOrientation.Initialize( transformManager, mTransformId ); + mWorldMatrix.Initialize( transformManager, mTransformId ); } void Node::SetRoot(bool isRoot) @@ -104,7 +128,51 @@ void Node::SetRoot(bool isRoot) mIsRoot = isRoot; } -void Node::ConnectChild( Node* childNode, int index ) +void Node::AddUniformMapping( UniformPropertyMapping* map ) +{ + PropertyOwner::AddUniformMapping( map ); + mRegenerateUniformMap = 2; +} + +void Node::RemoveUniformMapping( const std::string& uniformName ) +{ + PropertyOwner::RemoveUniformMapping( uniformName ); + mRegenerateUniformMap = 2; +} + +void Node::PrepareRender( BufferIndex bufferIndex ) +{ + if(mRegenerateUniformMap != 0 ) + { + if( mRegenerateUniformMap == 2 ) + { + CollectedUniformMap& localMap = mCollectedUniformMap[ bufferIndex ]; + localMap.Resize(0); + + for( unsigned int i=0, count=mUniformMaps.Count(); iSetAllDirtyFlags(); - if (index == -1) - { - mChildren.PushBack( childNode ); - } - else - { - mChildren.Insert(mChildren.Begin()+index, childNode); - } + // Add the node to the end of the child list. + mChildren.PushBack( childNode ); // Inform property observers of new connection childNode->ConnectToSceneGraph(); - - // Inform child node attachment that the node has been added to the stage - if( childNode->mAttachment ) - { - childNode->mAttachment->ConnectedToSceneGraph(); - } } -void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set& connectedNodes, std::set& disconnectedNodes ) +void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode ) { DALI_ASSERT_ALWAYS( this != &childNode ); DALI_ASSERT_ALWAYS( childNode.GetParent() == this ); @@ -155,28 +211,26 @@ void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std: } DALI_ASSERT_ALWAYS( NULL != found ); - found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes ); + found->RecursiveDisconnectFromSceneGraph( updateBufferIndex ); } -int Node::GetDirtyFlags() const +void Node::RemoveRenderer( Renderer* renderer ) { - // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already - int flags = mDirtyFlags; - const bool sizeFlag = mSize.IsClean(); - - if ( !(flags & TransformFlag) ) + unsigned int rendererCount( mRenderer.Size() ); + for( unsigned int i(0); iIsVisible( updateBufferIndex ) ) - { - return false; - } - - parent = parent->GetParent(); - } - - return true; -} - void Node::SetParent(Node& parentNode) { DALI_ASSERT_ALWAYS(this != &parentNode); @@ -244,9 +262,15 @@ void Node::SetParent(Node& parentNode) DALI_ASSERT_ALWAYS(mParent == NULL); mParent = &parentNode; + mDepth = mParent->GetDepth() + 1u; + + if( mTransformId != INVALID_TRANSFORM_ID ) + { + mTransformManager->SetParent( mTransformId, parentNode.GetTransformId() ); + } } -void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set& connectedNodes, std::set& disconnectedNodes ) +void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex ) { DALI_ASSERT_ALWAYS(!mIsRoot); DALI_ASSERT_ALWAYS(mParent != NULL); @@ -254,7 +278,7 @@ void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std const NodeIter endIter = mChildren.End(); for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter ) { - (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes ); + (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex ); } // Animators, Constraints etc. should be disconnected from the child's properties. @@ -262,20 +286,15 @@ void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std // Remove back-pointer to parent mParent = NULL; + mDepth = 0u; // Remove all child pointers mChildren.Clear(); - // Inform child node attachment that the node has been removed from the stage - if( mAttachment ) + if( mTransformId != INVALID_TRANSFORM_ID ) { - mAttachment->DisconnectedFromSceneGraph(); + mTransformManager->SetParent( mTransformId, INVALID_TRANSFORM_ID ); } - - // Move into disconnectedNodes - std::set::size_type removed = connectedNodes.erase( this ); - DALI_ASSERT_ALWAYS( removed ); - disconnectedNodes.insert( this ); } } // namespace SceneGraph