/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
#include <dali/public-api/common/constants.h>
#include <dali/public-api/common/dali-common.h>
+#include <dali/internal/update/common/resetter-manager.h> ///< For AddInitializeResetter
+
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<Dali::Internal::SceneGraph::Node> gNodeMemoryPool;
+// 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<Dali::Internal::SceneGraph::Node>& GetNodeMemoryPool()
+{
+ static Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::Node> gNodeMemoryPool;
+ return 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;
Node* Node::New()
{
- return new(gNodeMemoryPool.AllocateRawThreadSafe()) Node;
+ return new(GetNodeMemoryPool().AllocateRawThreadSafe()) Node;
}
void Node::Delete(Node* node)
{
- // check we have a node not a layer
- if(!node->mIsLayer)
+ // check we have a node not a derived node
+ if(!node->mIsLayer && !node->mIsCamera)
{
// Manually call the destructor
node->~Node();
// Mark the memory it used as free in the memory pool
- gNodeMemoryPool.FreeThreadSafe(node);
+ GetNodeMemoryPool().FreeThreadSafe(node);
}
else
{
}
Node::Node()
-: mOrientation(), // Initialized to identity by default
- mVisible(true),
- mCulled(false),
- mColor(Color::WHITE),
- mUpdateSizeHint(Vector3::ZERO),
+: mTransformManagerData(), // Initialized to use invalid id by default
+ mOrientation(), // Initialized to identity by default
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(),
+ mVisible(true),
+ mCulled(false),
+ mColor(Color::WHITE),
mWorldColor(Color::WHITE),
+ mUpdateAreaHint(Vector4::ZERO),
mClippingSortModifier(0u),
mId(++mNodeCounter),
mParent(nullptr),
mScissorDepth(0u),
mDepthIndex(0u),
mDirtyFlags(NodePropertyFlags::ALL),
- mRegenerateUniformMap(0),
mDrawMode(DrawMode::NORMAL),
mColorMode(DEFAULT_COLOR_MODE),
mClippingMode(ClippingMode::DISABLED),
mIsRoot(false),
mIsLayer(false),
+ mIsCamera(false),
mPositionUsesAnchorPoint(true),
- mTransparent(false)
+ mTransparent(false),
+ mUpdateAreaChanged(false),
+ mUseTextureUpdateArea(false)
{
- mUniformMapChanged[0] = 0u;
- mUniformMapChanged[1] = 0u;
-
#ifdef DEBUG_ENABLED
gNodeCount++;
#endif
void Node::CreateTransform(SceneGraph::TransformManager* transformManager)
{
- //Create a new transform
+ // Create a new transform
mTransformManagerData.mManager = transformManager;
TransformId createdTransformId = transformManager->CreateTransform();
- //Initialize all the animatable properties
- mPosition.Initialize(&mTransformManagerData);
- mScale.Initialize(&mTransformManagerData);
- mOrientation.Initialize(&mTransformManagerData);
- mSize.Initialize(&mTransformManagerData);
- mParentOrigin.Initialize(&mTransformManagerData);
- mAnchorPoint.Initialize(&mTransformManagerData);
-
- //Initialize all the input properties
- mWorldPosition.Initialize(&mTransformManagerData);
- mWorldScale.Initialize(&mTransformManagerData);
- mWorldOrientation.Initialize(&mTransformManagerData);
- mWorldMatrix.Initialize(&mTransformManagerData);
-
- //Set whether the position should use the anchor point
+ // Set whether the position should use the anchor point
transformManager->SetPositionUsesAnchorPoint(createdTransformId, mPositionUsesAnchorPoint);
- //Set TransformId after initialize done.
+ // Set TransformId after initialize done.
mTransformManagerData.mId = createdTransformId;
}
mIsRoot = isRoot;
}
-void Node::AddUniformMapping(const UniformPropertyMapping& map)
-{
- PropertyOwner::AddUniformMapping(map);
- mRegenerateUniformMap = 2;
-}
-
-void Node::RemoveUniformMapping(const ConstString& uniformName)
-{
- PropertyOwner::RemoveUniformMapping(uniformName);
- mRegenerateUniformMap = 2;
-}
-
bool Node::IsAnimationPossible() const
{
return mIsConnectedToSceneGraph;
}
-void Node::PrepareRender(BufferIndex bufferIndex)
+void Node::AddInitializeResetter(ResetterManager& manager) const
{
- if(mRegenerateUniformMap != 0)
- {
- if(mRegenerateUniformMap == 2)
- {
- CollectedUniformMap& localMap = mCollectedUniformMap[bufferIndex];
- localMap.Resize(0);
-
- for(UniformMap::SizeType 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());
-
- CollectedUniformMap::SizeType index = 0;
- for(CollectedUniformMap::Iterator iter = oldMap.Begin(), end = oldMap.End(); iter != end; ++iter, ++index)
- {
- localMap[index] = *iter;
- }
- }
- --mRegenerateUniformMap;
- mUniformMapChanged[bufferIndex] = 1u;
- }
+ manager.AddNodeResetter(*this);
}
void Node::ConnectChild(Node* childNode)
found->RecursiveDisconnectFromSceneGraph(updateBufferIndex);
}
-void Node::AddRenderer(Renderer* renderer)
+void Node::AddRenderer(const RendererKey& renderer)
{
// 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())
+ if(mRenderers.Empty())
{
mDirtyFlags |= NodePropertyFlags::TRANSFORM;
}
else
{
// Check that it has not been already added.
- for(auto&& existingRenderer : mRenderer)
+ for(auto&& existingRenderer : mRenderers)
{
if(existingRenderer == renderer)
{
SetUpdated(true);
- mRenderer.PushBack(renderer);
+ mRenderers.PushBack(renderer);
}
-void Node::RemoveRenderer(const Renderer* renderer)
+void Node::RemoveRenderer(const RendererKey& renderer)
{
- RendererContainer::SizeType rendererCount(mRenderer.Size());
+ RendererContainer::SizeType rendererCount(mRenderers.Size());
for(RendererContainer::SizeType i = 0; i < rendererCount; ++i)
{
- if(mRenderer[i] == renderer)
+ if(mRenderers[i] == renderer)
{
+ renderer->DetachFromNodeDataProvider(*this);
+
SetUpdated(true);
- mRenderer.Erase(mRenderer.Begin() + i);
+ mRenderers.Erase(mRenderers.Begin() + i);
return;
}
}
void Node::ResetDirtyFlags(BufferIndex updateBufferIndex)
{
mDirtyFlags = NodePropertyFlags::NOTHING;
+
+ mUpdateAreaChanged = false;
}
void Node::SetParent(Node& parentNode)
}
}
+uint32_t Node::GetMemoryPoolCapacity()
+{
+ return GetNodeMemoryPool().GetCapacity();
+}
+
} // namespace SceneGraph
} // namespace Internal