Change RenderTaskList to behave like any other SceneGraph object
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / layer-impl.cpp
index 721ac12..b790963 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * 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.
 // CLASS HEADER
 #include <dali/internal/event/actors/layer-impl.h>
 
+// EXTERNAL INCLUDES
+
 // INTERNAL INCLUDES
+#include <dali/public-api/actors/layer.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/internal/event/actors/layer-list.h>
@@ -30,6 +33,18 @@ using Dali::Internal::SceneGraph::UpdateManager;
 namespace Dali
 {
 
+namespace
+{
+
+typedef Layer::Behavior Behavior;
+
+DALI_ENUM_TO_STRING_TABLE_BEGIN( BEHAVIOR )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Layer, LAYER_2D )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Layer, LAYER_3D )
+DALI_ENUM_TO_STRING_TABLE_END( BEHAVIOR )
+
+} // namespace
+
 namespace Internal
 {
 
@@ -40,16 +55,17 @@ namespace
 
 //              Name                Type      writable animatable constraint-input  enum for index-checking
 DALI_PROPERTY_TABLE_BEGIN
-DALI_PROPERTY( "clipping-enable",   BOOLEAN,    true,    false,   true,   Dali::Layer::Property::ClippingEnable )
-DALI_PROPERTY( "clipping-box",      RECTANGLE,  true,    false,   true,   Dali::Layer::Property::ClippingBox    )
+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_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX )
 
 // Actions
 
 const char* const ACTION_RAISE =           "raise";
 const char* const ACTION_LOWER =           "lower";
-const char* const ACTION_RAISE_TO_TOP =    "raise-to-top";
-const char* const ACTION_LOWER_TO_BOTTOM = "lower-to-bottom";
+const char* const ACTION_RAISE_TO_TOP =    "raiseToTop";
+const char* const ACTION_LOWER_TO_BOTTOM = "lowerToBottom";
 
 BaseHandle Create()
 {
@@ -65,6 +81,7 @@ TypeAction a4( mType, ACTION_LOWER_TO_BOTTOM, &Layer::DoAction );
 
 } // unnamed namespace
 
+
 LayerPtr Layer::New()
 {
   LayerPtr layer( new Layer( Actor::LAYER ) );
@@ -75,19 +92,15 @@ LayerPtr Layer::New()
   return layer;
 }
 
-LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& manager, bool systemLevel )
+LayerPtr Layer::NewRoot( LayerList& layerList, UpdateManager& manager )
 {
   LayerPtr root( new Layer( Actor::ROOT_LAYER ) );
 
-  // Second-phase construction
-  SceneGraph::Layer* layer = static_cast<SceneGraph::Layer*>( root->CreateNode() );
-  InstallRootMessage( manager, *layer, systemLevel ); // Transfer ownership to scene-graph
-
-  // Keep a raw pointer to the layer node.
-  root->mNode = layer;
-
-  // stage must be set for the root layer
-  root->mStage = &stage;
+  // Second-phase construction, keep a raw pointer to the layer node.
+  SceneGraph::Layer* rootLayer = static_cast<SceneGraph::Layer*>( root->CreateNode() );
+  root->mNode = rootLayer;
+  OwnerPointer< SceneGraph::Layer > transferOwnership( rootLayer );
+  InstallRootMessage( manager, transferOwnership );
 
   // root actor is immediately considered to be on-stage
   root->mIsOnStage = true;
@@ -97,6 +110,7 @@ LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& mana
 
   // layer-list must be set for the root layer
   root->mLayerList = &layerList;
+  layerList.SetRootLayer( &(*root) );
   layerList.RegisterLayer( *root );
 
   return root;
@@ -104,13 +118,14 @@ LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& mana
 
 Layer::Layer( Actor::DerivedType type )
 : Actor( type ),
-  mLayerList(NULL),
-  mClippingBox(0,0,0,0),
-  mSortFunction(Dali::Layer::ZValue),
-  mIsClipping(false),
-  mDepthTestDisabled(false),
-  mTouchConsumed(false),
-  mHoverConsumed(false)
+  mLayerList( NULL ),
+  mClippingBox( 0, 0, 0, 0 ),
+  mSortFunction( Layer::ZValue ),
+  mBehavior( Dali::Layer::LAYER_2D ),
+  mIsClipping( false ),
+  mDepthTestDisabled( true ),
+  mTouchConsumed( false ),
+  mHoverConsumed( false )
 {
 }
 
@@ -149,7 +164,7 @@ void Layer::RaiseAbove( const Internal::Layer& target )
   if( ( this != &target ) && OnStage() && target.OnStage() )
   {
     // get parameters depth
-    const unsigned int targetDepth = target.GetDepth();
+    const uint32_t targetDepth = target.GetDepth();
     if( GetDepth() < targetDepth )
     {
       MoveAbove( target );
@@ -163,7 +178,7 @@ void Layer::LowerBelow( const Internal::Layer& target )
   if( ( this != &target ) && OnStage() && target.OnStage() )
   {
     // get parameters depth
-    const unsigned int targetDepth = target.GetDepth();
+    const uint32_t targetDepth = target.GetDepth();
     if( GetDepth() > targetDepth )
     {
       MoveBelow( target );
@@ -205,6 +220,16 @@ void Layer::MoveBelow( const Internal::Layer& target )
   }
 }
 
+void Layer::SetBehavior( Dali::Layer::Behavior behavior )
+{
+  mBehavior = behavior;
+
+  // Notify update side object.
+  SetBehaviorMessage( GetEventThreadServices(), GetSceneLayerOnStage(), behavior );
+  // By default, disable depth test for LAYER_2D, and enable for LAYER_3D.
+  SetDepthTestDisabled( mBehavior == Dali::Layer::LAYER_2D );
+}
+
 void Layer::SetClipping(bool enabled)
 {
   if (enabled != mIsClipping)
@@ -212,7 +237,7 @@ void Layer::SetClipping(bool enabled)
     mIsClipping = enabled;
 
     // layerNode is being used in a separate thread; queue a message to set the value
-    SetClippingMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mIsClipping );
+    SetClippingMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mIsClipping );
   }
 }
 
@@ -228,10 +253,15 @@ void Layer::SetClippingBox(int x, int y, int width, int height)
 
     // Convert mClippingBox to GL based coordinates (from bottom-left)
     ClippingBox clippingBox( mClippingBox );
-    clippingBox.y = mStage->GetSize().height - clippingBox.y - clippingBox.height;
 
-    // layerNode is being used in a separate thread; queue a message to set the value
-    SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), clippingBox );
+    StagePtr stage = Stage::GetCurrent();
+    if( stage )
+    {
+      clippingBox.y = static_cast<int32_t>( stage->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 );
+    }
   }
 }
 
@@ -241,9 +271,9 @@ void Layer::SetDepthTestDisabled( bool disable )
   {
     mDepthTestDisabled = disable;
 
-    // Send message .....
+    // Send message.
     // layerNode is being used in a separate thread; queue a message to set the value
-    SetDepthTestDisabledMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mDepthTestDisabled );
+    SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
   }
 }
 
@@ -259,7 +289,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( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mSortFunction );
+    SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction );
   }
 }
 
@@ -285,7 +315,7 @@ bool Layer::IsHoverConsumed() const
 
 SceneGraph::Node* Layer::CreateNode() const
 {
-  return SceneGraph::Layer::New();
+  return SceneGraph::Layer::New( mId );
 }
 
 void Layer::OnStageConnectionInternal()
@@ -332,12 +362,12 @@ unsigned int Layer::GetDefaultPropertyCount() const
 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
 {
   Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
-  indices.reserve( indices.size() + DEFAULT_PROPERTY_COUNT );
+  indices.Reserve( indices.Size() + DEFAULT_PROPERTY_COUNT );
 
-  int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
-  for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
+  int32_t index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
+  for ( int32_t i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
   {
-    indices.push_back( index );
+    indices.PushBack( index );
   }
 }
 
@@ -410,10 +440,10 @@ Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
   Property::Index index = Property::INVALID_INDEX;
 
   // Look for name in current class' default properties
-  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
+  for( int32_t i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
   {
     const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[i];
-    if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
+    if( 0 == name.compare( property->name ) ) // dont want to convert rhs to string
     {
       index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
       break;
@@ -438,17 +468,26 @@ void Layer::SetDefaultProperty( Property::Index index, const Property::Value& pr
   {
     switch( index )
     {
-      case Dali::Layer::Property::ClippingEnable:
+      case Dali::Layer::Property::CLIPPING_ENABLE:
       {
         SetClipping( propertyValue.Get<bool>() );
         break;
       }
-      case Dali::Layer::Property::ClippingBox:
+      case Dali::Layer::Property::CLIPPING_BOX:
       {
-        Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
+        Rect<int32_t> clippingBox( propertyValue.Get<Rect<int32_t> >() );
         SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
         break;
       }
+      case Dali::Layer::Property::BEHAVIOR:
+      {
+        Behavior behavior(Dali::Layer::LAYER_2D);
+        if( Scripting::GetEnumeration< Behavior >( propertyValue.Get< std::string >().c_str(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT, behavior ) )
+        {
+          SetBehavior( behavior );
+        }
+        break;
+      }
       default:
       {
         DALI_LOG_WARNING( "Unknown property (%d)\n", index );
@@ -470,16 +509,21 @@ Property::Value Layer::GetDefaultProperty( Property::Index index ) const
   {
     switch( index )
     {
-      case Dali::Layer::Property::ClippingEnable:
+      case Dali::Layer::Property::CLIPPING_ENABLE:
       {
         ret = mIsClipping;
         break;
       }
-      case Dali::Layer::Property::ClippingBox:
+      case Dali::Layer::Property::CLIPPING_BOX:
       {
         ret = mClippingBox;
         break;
       }
+      case Dali::Layer::Property::BEHAVIOR:
+      {
+        ret = Scripting::GetLinearEnumerationName< Behavior >( GetBehavior(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT );
+        break;
+      }
       default:
       {
         DALI_LOG_WARNING( "Unknown property (%d)\n", index );
@@ -491,29 +535,44 @@ Property::Value Layer::GetDefaultProperty( Property::Index index ) const
   return ret;
 }
 
-bool Layer::DoAction( BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes )
+Property::Value Layer::GetDefaultPropertyCurrentValue( Property::Index index ) const
+{
+  Property::Value ret;
+  if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
+  {
+    ret = Actor::GetDefaultPropertyCurrentValue( index );
+  }
+  else
+  {
+    ret = GetDefaultProperty( index ); // Layer only has event-side properties
+  }
+
+  return ret;
+}
+
+bool Layer::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/ )
 {
   bool done = false;
   Layer* layer = dynamic_cast<Layer*>( object );
 
   if( layer )
   {
-    if( 0 == strcmp( actionName.c_str(), ACTION_RAISE ) )
+    if( 0 == actionName.compare( ACTION_RAISE ) )
     {
       layer->Raise();
       done = true;
     }
-    else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER ) )
+    else if( 0 == actionName.compare( ACTION_LOWER ) )
     {
       layer->Lower();
       done = true;
     }
-    else if( 0 == strcmp( actionName.c_str(), ACTION_RAISE_TO_TOP ) )
+    else if( 0 == actionName.compare( ACTION_RAISE_TO_TOP ) )
     {
       layer->RaiseToTop();
       done = true;
     }
-    else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER_TO_BOTTOM ) )
+    else if( 0 == actionName.compare( ACTION_LOWER_TO_BOTTOM ) )
     {
       layer->LowerToBottom();
       done = true;
@@ -526,4 +585,3 @@ bool Layer::DoAction( BaseObject* object, const std::string& actionName, const s
 } // namespace Internal
 
 } // namespace Dali
-