-//
-// 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) 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.
+ * 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 <dali/internal/update/nodes/node.h>
// INTERNAL INCLUDES
-#include <dali/internal/update/node-attachments/node-attachment.h>
+#include <dali/internal/common/internal-constants.h>
+#include <dali/internal/common/memory-pool-object-allocator.h>
#include <dali/internal/update/common/discard-queue.h>
-#include <dali/internal/render/shaders/shader.h>
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/common/constants.h>
+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<Dali::Internal::SceneGraph::Node> gNodeMemoryPool;
+}
+
namespace Dali
{
Node* Node::New()
{
- return new Node();
+ return new ( gNodeMemoryPool.AllocateRawThreadSafe() ) Node();
}
Node::Node()
-: mParentOrigin( ParentOrigin::DEFAULT ),
- mAnchorPoint( AnchorPoint::DEFAULT ),
- mSize( Vector3::ZERO ),
- mPosition( Vector3::ZERO ),
- mRotation( Quaternion::IDENTITY ),
- 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( 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 ),
mParent( NULL ),
- mAppliedShader( NULL ),
- mInheritedShader( NULL ),
mExclusiveRenderTask( NULL ),
- mAttachment( NULL ),
mChildren(),
- mGeometryScale( Vector3::ONE ),
- mInitialVolume( Vector3::ONE ),
+ mRegenerateUniformMap( 0 ),
+ mDepth(0u),
mDirtyFlags(AllFlags),
mIsRoot( false ),
- mInheritShader( true ),
- mInheritRotation( true ),
- mInheritScale( true ),
- mTransmitGeometryScaling( false ),
- mInhibitLocalTransform( false ),
- mIsActive( true ),
mDrawMode( DrawMode::NORMAL ),
- mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ),
mColorMode( DEFAULT_COLOR_MODE )
{
+ 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<Node*>( ptr ) );
+}
+void Node::OnDestroy()
+{
// Animators, Constraints etc. should be disconnected from the child's properties.
- PropertyOwner::DisconnectFromSceneGraph();
+ 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)
mIsRoot = isRoot;
}
+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(); i<count; ++i )
+ {
+ localMap.PushBack( &mUniformMaps[i] );
+ }
+ }
+ else if( mRegenerateUniformMap == 1 )
+ {
+ CollectedUniformMap& localMap = mCollectedUniformMap[ bufferIndex ];
+ CollectedUniformMap& oldMap = mCollectedUniformMap[ 1-bufferIndex ];
+
+ localMap.Resize( oldMap.Count() );
+
+ unsigned int index=0;
+ for( CollectedUniformMap::Iterator iter = oldMap.Begin(), end = oldMap.End() ; iter != end ; ++iter, ++index )
+ {
+ localMap[index] = *iter;
+ }
+ }
+ --mRegenerateUniformMap;
+ mUniformMapChanged[bufferIndex] = 1u;
+ }
+}
+
void Node::ConnectChild( Node* childNode )
{
DALI_ASSERT_ALWAYS( this != childNode );
// Everything should be reinherited when reconnected to scene-graph
childNode->SetAllDirtyFlags();
+ // 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<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
+void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode )
{
DALI_ASSERT_ALWAYS( this != &childNode );
DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
}
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);
+ found->RecursiveDisconnectFromSceneGraph( updateBufferIndex );
}
-Shader* Node::GetAppliedShader() const
+void Node::RemoveRenderer( Renderer* renderer )
{
- return mAppliedShader;
-}
-
-void Node::SetInheritedShader(Shader* shader)
-{
- mInheritedShader = shader;
-}
-
-Shader* Node::GetInheritedShader() const
-{
- return mInheritedShader;
-}
-
-void Node::InheritShader(Shader* defaultShader)
-{
- DALI_ASSERT_DEBUG(mParent != NULL);
-
- // If we have a custom shader for this node, then use it
- if ( mAppliedShader != NULL )
+ unsigned int rendererCount( mRenderer.Size() );
+ for( unsigned int i(0); i<rendererCount; ++i )
{
- mInheritedShader = mAppliedShader;
- }
- else
- {
- // Otherwise we either inherit a shader, or fall-back to the default
- if (mInheritShader)
+ if( mRenderer[i] == renderer )
{
- mInheritedShader = mParent->GetInheritedShader();
- }
- else
- {
- mInheritedShader = defaultShader;
+ mRenderer.Erase( mRenderer.Begin()+i);
+ return;
}
}
- DALI_ASSERT_DEBUG( mInheritedShader != NULL );
}
int Node::GetDirtyFlags() const
{
// 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) )
- {
- // 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() )
- {
- flags |= TransformFlag;
- }
- }
// Check whether the visible property has changed
if ( !mVisible.IsClean() )
flags |= ColorFlag;
}
- // Check whether the size property has changed
- if ( !sizeFlag )
- {
- flags |= SizeFlag;
- }
-
return flags;
}
void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
{
- // Reset default properties
- mSize.ResetToBaseValue( updateBufferIndex );
- mPosition.ResetToBaseValue( updateBufferIndex );
- mRotation.ResetToBaseValue( updateBufferIndex );
- mScale.ResetToBaseValue( updateBufferIndex );
mVisible.ResetToBaseValue( updateBufferIndex );
mColor.ResetToBaseValue( updateBufferIndex );
mDirtyFlags = NothingFlag;
}
-bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
-{
- if( !IsVisible( updateBufferIndex ) )
- {
- return false;
- }
-
- Node* parent = mParent;
-
- while( NULL != parent )
- {
- if( !parent->IsVisible( updateBufferIndex ) )
- {
- return false;
- }
-
- parent = parent->GetParent();
- }
-
- return true;
-}
-
void Node::SetParent(Node& parentNode)
{
DALI_ASSERT_ALWAYS(this != &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<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
+void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex )
{
DALI_ASSERT_ALWAYS(!mIsRoot);
DALI_ASSERT_ALWAYS(mParent != NULL);
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;
+ mDepth = 0u;
// Remove all child pointers
mChildren.Clear();
- // Move into disconnectedNodes
- std::set<Node*>::size_type removed = connectedNodes.erase( this );
- DALI_ASSERT_ALWAYS( removed );
- disconnectedNodes.insert( this );
+ if( mTransformId != INVALID_TRANSFORM_ID )
+ {
+ mTransformManager->SetParent( mTransformId, INVALID_TRANSFORM_ID );
+ }
}
} // namespace SceneGraph