Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.cpp
index 4414f1d..ab20929 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -540,7 +540,15 @@ const Vector2 Actor::GetCurrentScreenPosition() const
   if(mScene)
   {
     BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
-    return CalculateActorScreenPosition(*this, bufferIndex);
+    if(mLayer3DParentsCount == 0)
+    {
+      // We can assume that this actor is under 2d layer. Use faster, but imprecise algorithm
+      return CalculateActorScreenPosition(*this, bufferIndex);
+    }
+    else
+    {
+      return CalculateActorScreenPositionRenderTaskList(*this, bufferIndex);
+    }
   }
   return Vector2::ZERO;
 }
@@ -1076,6 +1084,7 @@ Actor::Actor(DerivedType derivedType, const SceneGraph::Node& node)
   mName(),
   mSortedDepth(0u),
   mDepth(0u),
+  mLayer3DParentsCount(0),
   mIsRoot(ROOT_LAYER == derivedType),
   mIsLayer(LAYER == derivedType || ROOT_LAYER == derivedType),
   mIsOnScene(false),
@@ -1195,7 +1204,7 @@ void Actor::UnparentChildren()
   mParentImpl.UnparentChildren();
 }
 
-void Actor::ConnectToScene(uint32_t parentDepth, bool notify)
+void Actor::ConnectToScene(uint32_t parentDepth, uint32_t layer3DParentsCount, bool notify)
 {
   // This container is used instead of walking the Actor hierarchy.
   // It protects us when the Actor hierarchy is modified during OnSceneConnectionExternal callbacks.
@@ -1207,7 +1216,7 @@ void Actor::ConnectToScene(uint32_t parentDepth, bool notify)
   }
 
   // This stage is not interrupted by user callbacks.
-  mParentImpl.RecursiveConnectToScene(connectionList, parentDepth + 1);
+  mParentImpl.RecursiveConnectToScene(connectionList, layer3DParentsCount, parentDepth + 1);
 
   // Notify applications about the newly connected actors.
   for(const auto& actor : connectionList)
@@ -1472,11 +1481,11 @@ void Actor::SetParent(ActorParent* parent, bool notify)
     Actor* parentActor = static_cast<Actor*>(parent);
     mScene             = parentActor->mScene;
 
-    if(EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction
+    if(!EventThreadServices::IsShuttingDown() && // Don't emit signals or send messages during Core destruction
        parentActor->OnScene())
     {
       // Instruct each actor to create a corresponding node in the scene graph
-      ConnectToScene(parentActor->GetHierarchyDepth(), notify);
+      ConnectToScene(parentActor->GetHierarchyDepth(), parentActor->GetLayer3DParentCount(), notify);
     }
 
     // Resolve the name and index for the child properties if any
@@ -1488,7 +1497,7 @@ void Actor::SetParent(ActorParent* parent, bool notify)
 
     mParent = nullptr;
 
-    if(EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction
+    if(!EventThreadServices::IsShuttingDown() && // Don't emit signals or send messages during Core destruction
        OnScene())
     {
       // Disconnect the Node & its children from the scene-graph.
@@ -1504,9 +1513,18 @@ void Actor::SetParent(ActorParent* parent, bool notify)
 
 Rect<> Actor::CalculateScreenExtents() const
 {
-  auto        screenPosition = GetCurrentScreenPosition();
-  BufferIndex bufferIndex    = GetEventThreadServices().GetEventBufferIndex();
-  return CalculateActorScreenExtents(*this, screenPosition, bufferIndex);
+  if(mLayer3DParentsCount == 0)
+  {
+    // We can assume that this actor is under 2d layer. Use faster, but imprecise algorithm
+    auto        screenPosition = GetCurrentScreenPosition();
+    BufferIndex bufferIndex    = GetEventThreadServices().GetEventBufferIndex();
+    return CalculateActorScreenExtents(*this, screenPosition, bufferIndex);
+  }
+  else
+  {
+    BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
+    return CalculateActorScreenExtentsRenderTaskList(*this, bufferIndex);
+  }
 }
 
 Vector3 Actor::GetAnchorPointForPosition() const