X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fnodes%2Fnode.cpp;h=0a7dc5a17dfd5cc3fa815bfa466e5be8053726d0;hb=b43741a90b40ca9dfbd33d6a9d390d3c09230e89;hp=171006315a8a5102fad6696d43f21d8a3209805d;hpb=5c66381841dd4dfd82c5a118d34104a00a2e0e1c;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 1710063..f1faa84 --- a/dali/internal/update/nodes/node.cpp +++ b/dali/internal/update/nodes/node.cpp @@ -1,29 +1,47 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // CLASS HEADER #include // INTERNAL INCLUDES -#include +#include +#include #include -#include #include #include +namespace +{ +//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 { @@ -33,74 +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 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( Vector3::ZERO ), - mPosition( Vector3::ZERO ), - mRotation( Quaternion::IDENTITY ), - 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( Vector3::ZERO ), - mWorldRotation( Quaternion::IDENTITY ), - mWorldScale( Vector3::ONE ), - mWorldMatrix( Matrix::IDENTITY ), + 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 ), - mAppliedShader( NULL ), - mInheritedShader( NULL ), mExclusiveRenderTask( NULL ), - mAttachment( NULL ), mChildren(), - mGeometryScale( Vector3::ONE ), - mInitialVolume( Vector3::ONE ), - mDirtyFlags(AllFlags), - mIsRoot( false ), - mInheritShader( true ), - mInheritRotation( true ), - mInheritScale( true ), - mTransmitGeometryScaling( false ), - mInhibitLocalTransform( false ), - mIsActive( true ), + mClippingDepth( 0u ), + mScissorDepth( 0u ), + mDepthIndex( 0u ), + mDirtyFlags( NodePropertyFlags::ALL ), + mRegenerateUniformMap( 0 ), 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); + } + +#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::DisconnectFromSceneGraph(); + PropertyOwner::Destroy(); } -void Node::Attach( NodeAttachment& object ) +uint32_t Node::GetId() const { - DALI_ASSERT_DEBUG(!mAttachment); - - object.SetParent(*this); + return mId; +} - mAttachment = &object; - SetAllDirtyFlags(); +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) @@ -110,6 +178,50 @@ void Node::SetRoot(bool isRoot) mIsRoot = isRoot; } +void Node::AddUniformMapping( OwnerPointer< 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( UniformMap::SizeType i = 0, count=mUniformMaps.Count(); iSetAllDirtyFlags(); + // Add the node to the end of the child list. mChildren.PushBack( childNode ); + + // Inform property observers of new connection + childNode->ConnectToSceneGraph(); } -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 ); @@ -145,153 +261,101 @@ void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std: } DALI_ASSERT_ALWAYS( NULL != found ); - found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes ); -} - -void Node::ApplyShader( Shader* shader ) -{ - DALI_ASSERT_DEBUG( shader && "null shader passed to node" ); - - mAppliedShader = shader; - - SetDirtyFlag(ShaderFlag); -} - -void Node::RemoveShader() -{ - mAppliedShader = NULL; // Wait until InheritShader to grab default shader - - SetDirtyFlag(ShaderFlag); -} - -Shader* Node::GetAppliedShader() const -{ - return mAppliedShader; -} - -void Node::SetInheritedShader(Shader* shader) -{ - mInheritedShader = shader; -} - -Shader* Node::GetInheritedShader() const -{ - return mInheritedShader; + found->RecursiveDisconnectFromSceneGraph( updateBufferIndex ); } -void Node::InheritShader(Shader* defaultShader) +void Node::AddRenderer( Renderer* renderer ) { - DALI_ASSERT_DEBUG(mParent != NULL); - - // If we have a custom shader for this node, then use it - if ( mAppliedShader != NULL ) + // If it is the first renderer added, make sure the world transform will be calculated + // in the next update as world transform is not computed if node has no renderers. + if( mRenderer.Empty() ) { - mInheritedShader = mAppliedShader; + mDirtyFlags |= NodePropertyFlags::TRANSFORM; } else { - // Otherwise we either inherit a shader, or fall-back to the default - if (mInheritShader) + // Check that it has not been already added. + for( auto&& existingRenderer : mRenderer ) { - mInheritedShader = mParent->GetInheritedShader(); - } - else - { - mInheritedShader = defaultShader; + if( existingRenderer == renderer ) + { + // Renderer is already in the list. + return; + } } } - DALI_ASSERT_DEBUG( mInheritedShader != NULL ); + + mRenderer.PushBack( renderer ); + SetPropertyDirty( true ); } -int Node::GetDirtyFlags() const +void Node::RemoveRenderer( const 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) ) + RendererContainer::SizeType rendererCount( mRenderer.Size() ); + for( RendererContainer::SizeType i = 0; i < rendererCount; ++i ) { - // Check whether the transform related properties have changed - if( !sizeFlag || - !mPosition.IsClean() || - !mRotation.IsClean() || - !mScale.IsClean() || - mParentOrigin.InputChanged() || // parent origin and anchor point rarely change - mAnchorPoint.InputChanged() ) + if( mRenderer[i] == renderer ) { - flags |= TransformFlag; + SetPropertyDirty( true ); + mRenderer.Erase( mRenderer.Begin()+i); + return; } } +} + +NodePropertyFlags Node::GetDirtyFlags() const +{ + // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already + NodePropertyFlags flags = mDirtyFlags; // Check whether the visible property has changed if ( !mVisible.IsClean() ) { - flags |= VisibleFlag; + flags |= NodePropertyFlags::VISIBLE; } // Check whether the color property has changed if ( !mColor.IsClean() ) { - flags |= ColorFlag; + flags |= NodePropertyFlags::COLOR; } - // Check whether the size property has changed - if ( !sizeFlag ) - { - flags |= SizeFlag; - } - return flags; } -void Node::ResetDefaultProperties( BufferIndex updateBufferIndex ) +NodePropertyFlags Node::GetInheritedDirtyFlags( NodePropertyFlags parentFlags ) const { - // clear dirty flags in parent origin & anchor point - mParentOrigin.Clear(); - mAnchorPoint.Clear(); - // Reset default properties - mSize.ResetToBaseValue( updateBufferIndex ); - mPosition.ResetToBaseValue( updateBufferIndex ); - mRotation.ResetToBaseValue( updateBufferIndex ); - mScale.ResetToBaseValue( updateBufferIndex ); - mVisible.ResetToBaseValue( updateBufferIndex ); - mColor.ResetToBaseValue( updateBufferIndex ); - - mDirtyFlags = NothingFlag; + // Size is not inherited. VisibleFlag is inherited + static const NodePropertyFlags InheritedDirtyFlags = NodePropertyFlags::TRANSFORM | NodePropertyFlags::VISIBLE | NodePropertyFlags::COLOR; + using UnderlyingType = typename std::underlying_type::type; + + return static_cast( static_cast( mDirtyFlags ) | + ( static_cast( parentFlags ) & static_cast( InheritedDirtyFlags ) ) ); } -bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const +void Node::ResetDirtyFlags( BufferIndex updateBufferIndex ) { - if( !IsVisible( updateBufferIndex ) ) - { - return false; - } - - Node* parent = mParent; - - while( NULL != parent ) - { - if( !parent->IsVisible( updateBufferIndex ) ) - { - return false; - } + mDirtyFlags = NodePropertyFlags::NOTHING; - parent = parent->GetParent(); - } + SetPropertyDirty( false ); - return true; } -void Node::SetParent(Node& parentNode) +void Node::SetParent( Node& parentNode ) { DALI_ASSERT_ALWAYS(this != &parentNode); DALI_ASSERT_ALWAYS(!mIsRoot); DALI_ASSERT_ALWAYS(mParent == NULL); mParent = &parentNode; + + 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); @@ -299,15 +363,11 @@ 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. - PropertyOwner::DisconnectFromSceneGraph(); - - // Remove effects - mAppliedShader = NULL; - mInheritedShader = NULL; + PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex ); // Remove back-pointer to parent mParent = NULL; @@ -315,10 +375,35 @@ void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std // Remove all child pointers mChildren.Clear(); - // Move into disconnectedNodes - std::set::size_type removed = connectedNodes.erase( this ); - DALI_ASSERT_ALWAYS( removed ); - disconnectedNodes.insert( this ); + 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 ) + { + if( existingRenderer->IsDirty() ) + { + return true; + } + } + + return mPropertyDirty; } } // namespace SceneGraph