[Tizen] Implement partial update
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 8d923b3..50c744e
@@ -42,6 +42,8 @@
 #include <dali/internal/event/common/property-helper.h>
 #include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/event/common/type-info-impl.h>
+#include <dali/internal/event/common/scene-impl.h>
+#include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/animation/constraint-impl.h>
 #include <dali/internal/event/common/projection.h>
 #include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
@@ -192,6 +194,7 @@ DALI_PROPERTY( "leaveRequired",             BOOLEAN,  true,  false, false, Dali:
 DALI_PROPERTY( "inheritOrientation",        BOOLEAN,  true,  false, false, Dali::Actor::Property::INHERIT_ORIENTATION )
 DALI_PROPERTY( "inheritScale",              BOOLEAN,  true,  false, false, Dali::Actor::Property::INHERIT_SCALE )
 DALI_PROPERTY( "colorMode",                 STRING,   true,  false, false, Dali::Actor::Property::COLOR_MODE )
+DALI_PROPERTY( "reservedProperty01",        STRING,   true,  false, false, Dali::Actor::Property::RESERVED_PROPERTY_01 ) // This property was removed, but to keep binary compatibility and TypeRegister test app, remain it here.
 DALI_PROPERTY( "drawMode",                  STRING,   true,  false, false, Dali::Actor::Property::DRAW_MODE )
 DALI_PROPERTY( "sizeModeFactor",            VECTOR3,  true,  false, false, Dali::Actor::Property::SIZE_MODE_FACTOR )
 DALI_PROPERTY( "widthResizePolicy",         STRING,   true,  false, false, Dali::Actor::Property::WIDTH_RESIZE_POLICY )
@@ -211,6 +214,7 @@ DALI_PROPERTY( "opacity",                   FLOAT,    true,  true,  true,  Dali:
 DALI_PROPERTY( "screenPosition",            VECTOR2,  false, false, false, Dali::DevelActor::Property::SCREEN_POSITION )
 DALI_PROPERTY( "positionUsesAnchorPoint",   BOOLEAN,  true,  false, false, Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT )
 DALI_PROPERTY( "culled",                    BOOLEAN,  false, false, true, Dali::DevelActor::Property::CULLED )
+DALI_PROPERTY( "updateSizeHint",            VECTOR2,  true, true, true, Dali::DevelActor::Property::UPDATE_SIZE_HINT )
 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX, ActorDefaultProperties )
 
 // Signals
@@ -411,7 +415,8 @@ const SceneGraph::Node* Actor::CreateNode()
   // create node. Nodes are owned by the update manager
   SceneGraph::Node* node = SceneGraph::Node::New();
   OwnerPointer< SceneGraph::Node > transferOwnership( node );
-  AddNodeMessage( Stage::GetCurrent()->GetUpdateManager(), transferOwnership );
+  Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal();
+  AddNodeMessage( tls->GetUpdateManager(), transferOwnership );
 
   return node;
 }
@@ -791,20 +796,19 @@ const Vector3& Actor::GetCurrentWorldPosition() const
 
 const Vector2 Actor::GetCurrentScreenPosition() const
 {
-  StagePtr stage = Stage::GetCurrent();
-  if( stage && OnStage() )
+  if( mScene && OnStage() )
   {
     Vector3 worldPosition =  GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
-    Vector3 cameraPosition = stage->GetDefaultCameraActor().GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
+    Vector3 cameraPosition = mScene->GetDefaultCameraActor().GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
     worldPosition -= cameraPosition;
 
     Vector3 actorSize = GetCurrentSize() * GetCurrentWorldScale();
-    Vector2 halfStageSize( stage->GetSize() * 0.5f ); // World position origin is center of stage
+    Vector2 halfSceneSize( mScene->GetSize() * 0.5f ); // World position origin is center of scene
     Vector3 halfActorSize( actorSize * 0.5f );
     Vector3 anchorPointOffSet = halfActorSize - actorSize * ( mPositionUsesAnchorPoint ? GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT );
 
-    return Vector2( halfStageSize.width + worldPosition.x - anchorPointOffSet.x,
-                    halfStageSize.height + worldPosition.y - anchorPointOffSet.y );
+    return Vector2( halfSceneSize.width + worldPosition.x - anchorPointOffSet.x,
+                    halfSceneSize.height + worldPosition.y - anchorPointOffSet.y );
   }
 
   return Vector2::ZERO;
@@ -1311,6 +1315,9 @@ void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
   EnsureRelayoutData();
 
   mRelayoutData->sizeSetPolicy = policy;
+
+  // Trigger relayout on this control
+  RelayoutRequest();
 }
 
 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
@@ -1498,10 +1505,9 @@ DrawMode::Type Actor::GetDrawMode() const
 bool Actor::ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const
 {
   // only valid when on-stage
-  StagePtr stage = Stage::GetCurrent();
-  if( stage && OnStage() )
+  if( mScene && OnStage() )
   {
-    const RenderTaskList& taskList = stage->GetRenderTaskList();
+    const RenderTaskList& taskList = mScene->GetRenderTaskList();
 
     Vector2 converted( screenX, screenY );
 
@@ -2001,6 +2007,7 @@ bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra
 
 Actor::Actor( DerivedType derivedType, const SceneGraph::Node& node )
 : Object( &node ),
+  mScene( nullptr ),
   mParent( NULL ),
   mChildren( NULL ),
   mRenderers( NULL ),
@@ -2077,9 +2084,13 @@ Actor::~Actor()
   // Guard to allow handle destruction after Core has been destroyed
   if( EventThreadServices::IsCoreRunning() )
   {
-    DestroyNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() );
+    // Root layer will destroy its node in its own destructor
+    if ( !mIsRoot )
+    {
+      DestroyNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() );
 
-    GetEventThreadServices().UnregisterObject( this );
+      GetEventThreadServices().UnregisterObject( this );
+    }
   }
 
   // Cleanup optional gesture data
@@ -2099,10 +2110,9 @@ void Actor::ConnectToStage( uint32_t parentDepth )
   // It protects us when the Actor hierarchy is modified during OnStageConnectionExternal callbacks.
   ActorContainer connectionList;
 
-  StagePtr stage = Stage::GetCurrent();
-  if( stage )
+  if( mScene )
   {
-    stage->RequestRebuildDepthTree();
+    mScene->RequestRebuildDepthTree();
   }
 
   // This stage is atomic i.e. not interrupted by user callbacks.
@@ -2139,6 +2149,7 @@ void Actor::RecursiveConnectToStage( ActorContainer& connectionList, uint32_t de
     ActorConstIter endIter = mChildren->end();
     for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter )
     {
+      (*iter)->SetScene( *mScene );
       (*iter)->RecursiveConnectToStage( connectionList, depth + 1 );
     }
   }
@@ -2193,10 +2204,9 @@ void Actor::DisconnectFromStage()
   // It protects us when the Actor hierachy is modified during OnStageDisconnectionExternal callbacks.
   ActorContainer disconnectionList;
 
-  StagePtr stage = Stage::GetCurrent();
-  if( stage )
+  if( mScene )
   {
-    stage->RequestRebuildDepthTree();
+    mScene->RequestRebuildDepthTree();
   }
 
   // This stage is atomic i.e. not interrupted by user callbacks
@@ -2709,6 +2719,12 @@ void Actor::SetDefaultProperty( Property::Index index, const Property::Value& pr
       break;
     }
 
+    case Dali::DevelActor::Property::UPDATE_SIZE_HINT:
+    {
+      SetUpdateSizeHint( property.Get< Vector2 >() );
+      break;
+    }
+
     default:
     {
       // this can happen in the case of a non-animatable default property so just do nothing
@@ -3409,6 +3425,8 @@ void Actor::SetParent( Actor* parent )
 
     mParent = parent;
 
+    mScene = parent->mScene;
+
     if ( EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction
          parent->OnStage() )
     {
@@ -3434,6 +3452,8 @@ void Actor::SetParent( Actor* parent )
       // Instruct each actor to discard pointers to the scene-graph
       DisconnectFromStage();
     }
+
+    mScene = nullptr;
   }
 }
 
@@ -3954,6 +3974,12 @@ bool Actor::GetCurrentPropertyValue( Property::Index index, Property::Value& val
       break;
     }
 
+    case Dali::DevelActor::Property::UPDATE_SIZE_HINT:
+    {
+      value = GetUpdateSizeHint();
+      break;
+    }
+
     default:
     {
       // Must be an event-side only property
@@ -4703,6 +4729,19 @@ float Actor::GetMaximumSize( Dimension::Type dimension ) const
   return FLT_MAX;  // Default
 }
 
+void Actor::SetUpdateSizeHint( const Vector2& updateSizeHint )
+{
+  // node is being used in a separate thread; queue a message to set the value & base value
+  SceneGraph::NodeTransformPropertyMessage<Vector3>::Send( GetEventThreadServices(), &GetNode(), &GetNode().mUpdateSizeHint, &SceneGraph::TransformManagerPropertyHandler<Vector3>::Bake, Vector3(updateSizeHint.width, updateSizeHint.height, 0.f ) );
+}
+
+const Vector2 Actor::GetUpdateSizeHint() const
+{
+  // node is being used in a separate thread; copy the value from the previous update
+  Vector3 updateSizeHint = GetNode().GetUpdateSizeHint( GetEventThreadServices().GetEventBufferIndex() );
+  return Vector2( updateSizeHint.width, updateSizeHint.height );
+}
+
 Object* Actor::GetParentObject() const
 {
   return mParent;
@@ -4781,10 +4820,9 @@ void Actor::RequestRebuildDepthTree()
 {
   if( mIsOnStage )
   {
-    StagePtr stage = Stage::GetCurrent();
-    if( stage )
+    if( mScene )
     {
-      stage->RequestRebuildDepthTree();
+      mScene->RequestRebuildDepthTree();
     }
   }
 }
@@ -4968,6 +5006,16 @@ void Actor::LowerBelow( Internal::Actor& target )
   }
 }
 
+void Actor::SetScene( Scene& scene )
+{
+  mScene = &scene;
+}
+
+Scene& Actor::GetScene() const
+{
+  return *mScene;
+}
+
 void Actor::SetInheritLayoutDirection( bool inherit )
 {
   if( mInheritLayoutDirection != inherit )