X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fnodes%2Fnode.cpp;h=0a7dc5a17dfd5cc3fa815bfa466e5be8053726d0;hb=b43741a90b40ca9dfbd33d6a9d390d3c09230e89;hp=52fad10689edc98770873f5634a872c46e86ba86;hpb=deb43a837c49c7f514816ea189ba661eae251a76;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/nodes/node.cpp b/dali/internal/update/nodes/node.cpp old mode 100644 new mode 100755 index 52fad10..f1faa84 --- 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) 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. @@ -21,16 +21,26 @@ // INTERNAL INCLUDES #include #include -#include #include #include #include -namespace //Unnamed namespace +namespace { -//Memory pool used to allocate new nodes. Memory used by this pool will be released when shutting down DALi +//Memory pool used to allocate new nodes. Memory used by this pool will be released when process dies +// or DALI library is unloaded Dali::Internal::MemoryPoolObjectAllocator gNodeMemoryPool; +#ifdef DEBUG_ENABLED +// keep track of nodes alive, to ensure we have 0 when the process exits or DALi library is unloaded +int32_t gNodeCount = 0; + +// Called when the process is about to exit, Node count should be zero at this point. +void __attribute__ ((destructor)) ShutDown(void) +{ +DALI_ASSERT_DEBUG( (gNodeCount == 0) && "Node memory leak"); } +#endif +} // Unnamed namespace namespace Dali { @@ -41,78 +51,124 @@ namespace Internal namespace SceneGraph { -const PositionInheritanceMode Node::DEFAULT_POSITION_INHERITANCE_MODE( INHERIT_PARENT_POSITION ); const ColorMode Node::DEFAULT_COLOR_MODE( USE_OWN_MULTIPLY_PARENT_ALPHA ); +uint32_t Node::mNodeCounter = 0; ///< A counter to provide unique node ids, up-to 4 billion + Node* Node::New() { - return new ( gNodeMemoryPool.AllocateRawThreadSafe() ) Node(); + return new ( gNodeMemoryPool.AllocateRawThreadSafe() ) Node; +} + +void Node::Delete( Node* node ) +{ + // check we have a node not a layer + if( !node->mIsLayer ) + { + // Manually call the destructor + node->~Node(); + + // Mark the memory it used as free in the memory pool + gNodeMemoryPool.FreeThreadSafe( node ); + } + else + { + // not in the pool, just delete it. + delete 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( NULL ), + 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 ), + mUpdateSizeHint( TRANSFORM_PROPERTY_UPDATE_SIZE_HINT ), mVisible( true ), + mCulled( false ), 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 ), + mId( ++mNodeCounter ), mParent( NULL ), mExclusiveRenderTask( NULL ), - mAttachment( NULL ), mChildren(), + mClippingDepth( 0u ), + mScissorDepth( 0u ), + mDepthIndex( 0u ), + mDirtyFlags( NodePropertyFlags::ALL ), mRegenerateUniformMap( 0 ), - mDepth(0u), - mDirtyFlags(AllFlags), - mIsRoot( false ), - mInheritPosition( true ), - mInheritOrientation( true ), - mInheritScale( true ), mDrawMode( DrawMode::NORMAL ), - mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ), - mColorMode( DEFAULT_COLOR_MODE ) + mColorMode( DEFAULT_COLOR_MODE ), + mClippingMode( ClippingMode::DISABLED ), + mIsRoot( false ), + mIsLayer( false ), + mPositionUsesAnchorPoint( true ) { mUniformMapChanged[0] = 0u; mUniformMapChanged[1] = 0u; + mPropertyDirty = false; + +#ifdef DEBUG_ENABLED + gNodeCount++; +#endif + } Node::~Node() { -} + if( mTransformId != INVALID_TRANSFORM_ID ) + { + mTransformManager->RemoveTransform(mTransformId); + } -void Node::operator delete( void* ptr ) -{ - gNodeMemoryPool.FreeThreadSafe( static_cast( ptr ) ); +#ifdef DEBUG_ENABLED + gNodeCount--; +#endif } void Node::OnDestroy() { - // Node attachments should be notified about the disconnection. - if ( mAttachment ) - { - mAttachment->OnDestroy(); - } - // Animators, Constraints etc. should be disconnected from the child's properties. PropertyOwner::Destroy(); } -void Node::Attach( NodeAttachment& object ) +uint32_t Node::GetId() const { - DALI_ASSERT_DEBUG(!mAttachment); - - object.SetParent(*this); - - mAttachment = &object; - SetAllDirtyFlags(); + return mId; +} - mAttachment->ConnectedToSceneGraph(); +void Node::CreateTransform( SceneGraph::TransformManager* transformManager ) +{ + //Create a new transform + mTransformManager = transformManager; + mTransformId = transformManager->CreateTransform(); + + //Initialize all the animatable properties + mPosition.Initialize( transformManager, mTransformId ); + mScale.Initialize( transformManager, mTransformId ); + mUpdateSizeHint.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 ); + + //Set whether the position should use the anchor point + transformManager->SetPositionUsesAnchorPoint( mTransformId, mPositionUsesAnchorPoint ); } void Node::SetRoot(bool isRoot) @@ -122,7 +178,7 @@ void Node::SetRoot(bool isRoot) mIsRoot = isRoot; } -void Node::AddUniformMapping( UniformPropertyMapping* map ) +void Node::AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map ) { PropertyOwner::AddUniformMapping( map ); mRegenerateUniformMap = 2; @@ -136,14 +192,14 @@ void Node::RemoveUniformMapping( const std::string& uniformName ) void Node::PrepareRender( BufferIndex bufferIndex ) { - if(mRegenerateUniformMap != 0 ) + if( mRegenerateUniformMap != 0 ) { if( mRegenerateUniformMap == 2 ) { CollectedUniformMap& localMap = mCollectedUniformMap[ bufferIndex ]; localMap.Resize(0); - for( unsigned int i=0, count=mUniformMaps.Count(); iConnectToSceneGraph(); - - // 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 ) @@ -214,84 +264,95 @@ void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode ) found->RecursiveDisconnectFromSceneGraph( updateBufferIndex ); } -void Node::RemoveRenderer( Renderer* renderer ) +void Node::AddRenderer( Renderer* renderer ) { - unsigned int rendererCount( mRenderer.Size() ); - for( unsigned int i(0); i::type; + + return static_cast( static_cast( mDirtyFlags ) | + ( static_cast( parentFlags ) & static_cast( InheritedDirtyFlags ) ) ); } -void Node::SetParent(Node& parentNode) +void Node::ResetDirtyFlags( BufferIndex updateBufferIndex ) +{ + mDirtyFlags = NodePropertyFlags::NOTHING; + + SetPropertyDirty( false ); + +} + +void Node::SetParent( Node& parentNode ) { DALI_ASSERT_ALWAYS(this != &parentNode); DALI_ASSERT_ALWAYS(!mIsRoot); 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 ) @@ -310,17 +371,39 @@ void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex ) // 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 ) + { + mTransformManager->SetParent( mTransformId, INVALID_TRANSFORM_ID ); + } +} + +void Node::SetPropertyDirty( bool value ) +{ + mPropertyDirty = value; + + const NodeIter endIter = mChildren.End(); + for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter ) + { + Node* current = *iter; + current->SetPropertyDirty( value ); + } +} + +bool Node::IsPropertyDirty() const +{ + for( auto&& existingRenderer : mRenderer ) { - mAttachment->DisconnectedFromSceneGraph(); + if( existingRenderer->IsDirty() ) + { + return true; + } } + return mPropertyDirty; } } // namespace SceneGraph