Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / layer-impl.cpp
index 8040640..d164abb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -58,15 +58,19 @@ namespace
 DALI_PROPERTY_TABLE_BEGIN
 DALI_PROPERTY( "clippingEnable",    BOOLEAN,    true,    false,   true,   Dali::Layer::Property::CLIPPING_ENABLE )
 DALI_PROPERTY( "clippingBox",       RECTANGLE,  true,    false,   true,   Dali::Layer::Property::CLIPPING_BOX    )
-DALI_PROPERTY( "behavior",          STRING,     true,    false,   false,  Dali::Layer::Property::BEHAVIOR        )
+DALI_PROPERTY( "behavior",          INTEGER,    true,    false,   false,  Dali::Layer::Property::BEHAVIOR        )
+DALI_PROPERTY( "depth",             INTEGER,    false,   false,   false,  Dali::Layer::Property::DEPTH           )
+DALI_PROPERTY( "depthTest",         BOOLEAN,    true,    false,   false,  Dali::Layer::Property::DEPTH_TEST      )
+DALI_PROPERTY( "consumesTouch",     BOOLEAN,    true,    false,   false,  Dali::Layer::Property::CONSUMES_TOUCH  )
+DALI_PROPERTY( "consumesHover",     BOOLEAN,    true,    false,   false,  Dali::Layer::Property::CONSUMES_HOVER  )
 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, LayerDefaultProperties )
 
 // Actions
 
-const char* const ACTION_RAISE =           "raise";
-const char* const ACTION_LOWER =           "lower";
-const char* const ACTION_RAISE_TO_TOP =    "raiseToTop";
-const char* const ACTION_LOWER_TO_BOTTOM = "lowerToBottom";
+static constexpr std::string_view ACTION_RAISE           = "raise";
+static constexpr std::string_view ACTION_LOWER           = "lower";
+static constexpr std::string_view ACTION_RAISE_TO_TOP    = "raiseToTop";
+static constexpr std::string_view ACTION_LOWER_TO_BOTTOM = "lowerToBottom";
 
 BaseHandle Create()
 {
@@ -75,10 +79,10 @@ BaseHandle Create()
 
 TypeRegistration mType( typeid( Dali::Layer ), typeid( Dali::Actor ), Create, LayerDefaultProperties );
 
-TypeAction a1( mType, ACTION_RAISE, &Layer::DoAction );
-TypeAction a2( mType, ACTION_LOWER, &Layer::DoAction );
-TypeAction a3( mType, ACTION_RAISE_TO_TOP, &Layer::DoAction );
-TypeAction a4( mType, ACTION_LOWER_TO_BOTTOM, &Layer::DoAction );
+TypeAction a1(mType, std::string(ACTION_RAISE), &Layer::DoAction);
+TypeAction a2(mType, std::string(ACTION_LOWER), &Layer::DoAction);
+TypeAction a3(mType, std::string(ACTION_RAISE_TO_TOP), &Layer::DoAction);
+TypeAction a4(mType, std::string(ACTION_LOWER_TO_BOTTOM), &Layer::DoAction);
 
 } // unnamed namespace
 
@@ -97,20 +101,20 @@ LayerPtr Layer::New()
   return layer;
 }
 
-LayerPtr Layer::NewRoot( LayerList& layerList, UpdateManager& manager )
+LayerPtr Layer::NewRoot( LayerList& layerList )
 {
   // create node, nodes are owned by UpdateManager
   SceneGraph::Layer* rootLayer = SceneGraph::Layer::New();
   OwnerPointer< SceneGraph::Layer > transferOwnership( rootLayer );
-  InstallRootMessage( manager, transferOwnership );
+  InstallRootMessage( EventThreadServices::Get().GetUpdateManager(), transferOwnership );
 
   LayerPtr root( new Layer( Actor::ROOT_LAYER, *rootLayer ) );
 
   // root actor is immediately considered to be on-stage
-  root->mIsOnStage = true;
+  root->mIsOnScene = true;
 
   // The root actor will not emit a stage connection signal so set the signalled flag here as well
-  root->mOnStageSignalled = true;
+  root->mOnSceneSignalled = true;
 
   // layer-list must be set for the root layer
   root->mLayerList = &layerList;
@@ -122,7 +126,7 @@ LayerPtr Layer::NewRoot( LayerList& layerList, UpdateManager& manager )
 
 Layer::Layer( Actor::DerivedType type, const SceneGraph::Layer& layer )
 : Actor( type, layer ),
-  mLayerList( NULL ),
+  mLayerList( nullptr ),
   mClippingBox( 0, 0, 0, 0 ),
   mSortFunction( Layer::ZValue ),
   mBehavior( Dali::Layer::LAYER_UI ),
@@ -139,6 +143,16 @@ void Layer::OnInitialize()
 
 Layer::~Layer()
 {
+  if ( mIsRoot )
+  {
+    // Guard to allow handle destruction after Core has been destroyed
+    if( EventThreadServices::IsCoreRunning() )
+    {
+      UninstallRootMessage( GetEventThreadServices().GetUpdateManager(), &GetSceneGraphLayer() );
+
+      GetEventThreadServices().UnregisterObject( this );
+    }
+  }
 }
 
 unsigned int Layer::GetDepth() const
@@ -164,8 +178,8 @@ void Layer::Lower()
 
 void Layer::RaiseAbove( const Internal::Layer& target )
 {
-  // cannot raise above ourself, both have to be on stage
-  if( ( this != &target ) && OnStage() && target.OnStage() )
+  // cannot raise above ourself, both have to be on the scene
+  if( ( this != &target ) && OnScene() && target.OnScene() )
   {
     // get parameters depth
     const uint32_t targetDepth = target.GetDepth();
@@ -178,8 +192,8 @@ void Layer::RaiseAbove( const Internal::Layer& target )
 
 void Layer::LowerBelow( const Internal::Layer& target )
 {
-  // cannot lower below ourself, both have to be on stage
-  if( ( this != &target ) && OnStage() && target.OnStage() )
+  // cannot lower below ourself, both have to be on the scene
+  if( ( this != &target ) && OnScene() && target.OnScene() )
   {
     // get parameters depth
     const uint32_t targetDepth = target.GetDepth();
@@ -208,8 +222,8 @@ void Layer::LowerToBottom()
 
 void Layer::MoveAbove( const Internal::Layer& target )
 {
-  // cannot raise above ourself, both have to be on stage
-  if( ( this != &target ) && mLayerList && target.OnStage() )
+  // cannot raise above ourself, both have to be on the scene
+  if( ( this != &target ) && mLayerList && target.OnScene() )
   {
     mLayerList->MoveLayerAbove(*this, target );
   }
@@ -217,8 +231,8 @@ void Layer::MoveAbove( const Internal::Layer& target )
 
 void Layer::MoveBelow( const Internal::Layer& target )
 {
-  // cannot lower below ourself, both have to be on stage
-  if( ( this != &target ) && mLayerList && target.OnStage() )
+  // cannot lower below ourself, both have to be on the scene
+  if( ( this != &target ) && mLayerList && target.OnScene() )
   {
     mLayerList->MoveLayerBelow(*this, target );
   }
@@ -229,7 +243,7 @@ void Layer::SetBehavior( Dali::Layer::Behavior behavior )
   mBehavior = behavior;
 
   // Notify update side object.
-  SetBehaviorMessage( GetEventThreadServices(), GetSceneLayerOnStage(), behavior );
+  SetBehaviorMessage( GetEventThreadServices(), GetSceneGraphLayer(), behavior );
   // By default, disable depth test for LAYER_UI, and enable for LAYER_3D.
   SetDepthTestDisabled( mBehavior == Dali::Layer::LAYER_UI );
 }
@@ -241,7 +255,7 @@ void Layer::SetClipping(bool enabled)
     mIsClipping = enabled;
 
     // layerNode is being used in a separate thread; queue a message to set the value
-    SetClippingMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mIsClipping );
+    SetClippingMessage( GetEventThreadServices(), GetSceneGraphLayer(), mIsClipping );
   }
 }
 
@@ -263,7 +277,7 @@ void Layer::SetClippingBox(int x, int y, int width, int height)
       clippingBox.y = static_cast<int32_t>( mScene->GetSize().height ) - clippingBox.y - clippingBox.height;
 
       // layerNode is being used in a separate thread; queue a message to set the value
-      SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
+      SetClippingBoxMessage( GetEventThreadServices(), GetSceneGraphLayer(), clippingBox );
     }
   }
 }
@@ -276,7 +290,7 @@ void Layer::SetDepthTestDisabled( bool disable )
 
     // Send message.
     // layerNode is being used in a separate thread; queue a message to set the value
-    SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
+    SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneGraphLayer(), mDepthTestDisabled );
   }
 }
 
@@ -292,7 +306,7 @@ void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
     mSortFunction = function;
 
     // layerNode is being used in a separate thread; queue a message to set the value
-    SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction );
+    SetSortFunctionMessage( GetEventThreadServices(), GetSceneGraphLayer(), mSortFunction );
   }
 }
 
@@ -316,14 +330,14 @@ bool Layer::IsHoverConsumed() const
   return mHoverConsumed;
 }
 
-void Layer::OnStageConnectionInternal()
+void Layer::OnSceneConnectionInternal()
 {
   if ( !mIsRoot )
   {
     DALI_ASSERT_DEBUG( NULL == mLayerList );
 
     // Find the ordered layer-list
-    for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
+    for ( Actor* parent = mParent; parent != nullptr; parent = parent->GetParent() )
     {
       if( parent->IsLayer() )
       {
@@ -337,15 +351,15 @@ void Layer::OnStageConnectionInternal()
   mLayerList->RegisterLayer( *this );
 }
 
-void Layer::OnStageDisconnectionInternal()
+void Layer::OnSceneDisconnectionInternal()
 {
   mLayerList->UnregisterLayer(*this);
 
   // mLayerList is only valid when on-stage
-  mLayerList = NULL;
+  mLayerList = nullptr;
 }
 
-const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
+const SceneGraph::Layer& Layer::GetSceneGraphLayer() const
 {
   return static_cast< const SceneGraph::Layer& >( GetNode() ); // we know our node is a layer node
 }
@@ -373,13 +387,37 @@ void Layer::SetDefaultProperty( Property::Index index, const Property::Value& pr
       }
       case Dali::Layer::Property::BEHAVIOR:
       {
-        Behavior behavior(Dali::Layer::LAYER_UI);
-        if( Scripting::GetEnumeration< Behavior >( propertyValue.Get< std::string >().c_str(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT, behavior ) )
+        Behavior behavior = mBehavior;
+
+        Property::Type type = propertyValue.GetType();
+        if( type == Property::STRING )
+        {
+          if( Scripting::GetEnumeration< Behavior >( propertyValue.Get< std::string >().c_str(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT, behavior ) )
+          {
+            SetBehavior( behavior );
+          }
+        }
+        else if ( type == Property::INTEGER )
         {
-          SetBehavior( behavior );
+          SetBehavior( propertyValue.Get< Dali::Layer::Behavior >() );
         }
         break;
       }
+      case Dali::Layer::Property::DEPTH_TEST:
+      {
+        SetDepthTestDisabled( !propertyValue.Get<bool>() );
+        break;
+      }
+      case Dali::Layer::Property::CONSUMES_TOUCH:
+      {
+        SetTouchConsumed( propertyValue.Get<bool>() );
+        break;
+      }
+      case Dali::Layer::Property::CONSUMES_HOVER:
+      {
+        SetHoverConsumed( propertyValue.Get<bool>() );
+        break;
+      }
       default:
       {
         DALI_LOG_WARNING( "Unknown property (%d)\n", index );
@@ -413,7 +451,27 @@ Property::Value Layer::GetDefaultProperty( Property::Index index ) const
       }
       case Dali::Layer::Property::BEHAVIOR:
       {
-        ret = Scripting::GetLinearEnumerationName< Behavior >( GetBehavior(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT );
+        ret = mBehavior;
+        break;
+      }
+      case Dali::Layer::Property::DEPTH:
+      {
+        ret = static_cast<int>( GetDepth() );
+        break;
+      }
+      case Dali::Layer::Property::DEPTH_TEST:
+      {
+        ret = !mDepthTestDisabled;
+        break;
+      }
+      case Dali::Layer::Property::CONSUMES_TOUCH:
+      {
+        ret = mTouchConsumed;
+        break;
+      }
+      case Dali::Layer::Property::CONSUMES_HOVER:
+      {
+        ret = mHoverConsumed;
         break;
       }
       default:
@@ -449,22 +507,24 @@ bool Layer::DoAction( BaseObject* object, const std::string& actionName, const P
 
   if( layer )
   {
-    if( 0 == actionName.compare( ACTION_RAISE ) )
+    std::string_view name(actionName);
+
+    if(name == ACTION_RAISE)
     {
       layer->Raise();
       done = true;
     }
-    else if( 0 == actionName.compare( ACTION_LOWER ) )
+    else if(name == ACTION_LOWER)
     {
       layer->Lower();
       done = true;
     }
-    else if( 0 == actionName.compare( ACTION_RAISE_TO_TOP ) )
+    else if(name == ACTION_RAISE_TO_TOP)
     {
       layer->RaiseToTop();
       done = true;
     }
-    else if( 0 == actionName.compare( ACTION_LOWER_TO_BOTTOM ) )
+    else if(name == ACTION_LOWER_TO_BOTTOM)
     {
       layer->LowerToBottom();
       done = true;