Revert "Move new mesh API to devel-api"
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / renderer-impl.cpp
index 5496dbd..f11870d 100644 (file)
 
 // INTERNAL INCLUDES
 #include <dali/public-api/actors/renderer.h> // Dali::Renderer
+#include <dali/public-api/object/type-registry.h>
 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
-#include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/event/common/property-input-impl.h>
 #include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
+#include <dali/internal/update/manager/update-manager.h>
 
 namespace Dali
 {
@@ -37,11 +39,18 @@ namespace
  *            |name          |type     |writable|animatable|constraint-input|enum for index-checking|
  */
 DALI_PROPERTY_TABLE_BEGIN
-DALI_PROPERTY( "depth-index", INTEGER,  true, true, true, Dali::Renderer::Property::DEPTH_INDEX )
+DALI_PROPERTY( "depth-index", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
 
 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
 
+BaseHandle Create()
+{
+  return Dali::BaseHandle();
+}
+
+TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
+
 } // unnamed namespace
 
 RendererPtr Renderer::New()
@@ -55,9 +64,15 @@ void Renderer::SetGeometry( Geometry& geometry )
 {
   mGeometryConnector.Set( geometry, OnStage() );
   const SceneGraph::Geometry* geometrySceneObject = geometry.GetGeometrySceneObject();
+
   SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
 }
 
+Geometry* Renderer::GetGeometry() const
+{
+  return mGeometryConnector.Get().Get();
+}
+
 void Renderer::SetMaterial( Material& material )
 {
   mMaterialConnector.Set( material, OnStage() );
@@ -65,11 +80,23 @@ void Renderer::SetMaterial( Material& material )
   SetMaterialMessage( GetEventThreadServices(), *mSceneObject, *materialSceneObject );
 }
 
+Material* Renderer::GetMaterial() const
+{
+  return mMaterialConnector.Get().Get();
+}
+
 void Renderer::SetDepthIndex( int depthIndex )
 {
-  //SceneGraph::NodePropertyMessage<Vector3>::Send( mStage->GetUpdateManager(), mNode, &mNode->mPosition, &AnimatableProperty<Vector3>::Bake, position );
-  // TODO: MESH_REWORK
-  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+  if ( mDepthIndex != depthIndex )
+  {
+    mDepthIndex = depthIndex;
+    SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
+  }
+}
+
+int Renderer::GetDepthIndex() const
+{
+  return mDepthIndex;
 }
 
 SceneGraph::RendererAttachment* Renderer::GetRendererSceneObject()
@@ -120,24 +147,41 @@ Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
 void Renderer::SetDefaultProperty( Property::Index index,
                                    const Property::Value& propertyValue )
 {
-  RENDERER_IMPL.SetDefaultProperty( index, propertyValue );
+  switch( index )
+  {
+    case Dali::Renderer::Property::DEPTH_INDEX:
+    {
+      SetDepthIndex( propertyValue.Get<int>() );
+    }
+    break;
+  }
 }
 
 void Renderer::SetSceneGraphProperty( Property::Index index,
                                       const PropertyMetadata& entry,
                                       const Property::Value& value )
 {
-  RENDERER_IMPL.SetSceneGraphProperty( index, entry, value );
+  RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
+  OnPropertySet(index, value);
 }
 
 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
 {
-  return RENDERER_IMPL.GetDefaultProperty( index );
+  Property::Value value;
+  switch( index )
+  {
+    case Dali::Renderer::Property::DEPTH_INDEX:
+    {
+      value = GetDepthIndex();
+    }
+    break;
+  }
+  return value;
 }
 
 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
 {
-  return RENDERER_IMPL.GetPropertyOwner();
+  return mSceneObject;
 }
 
 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
@@ -147,29 +191,51 @@ const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
 
 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
 {
-  return RENDERER_IMPL.GetSceneObjectAnimatableProperty( index );
+  DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
+  const SceneGraph::PropertyBase* property = NULL;
+
+  if( OnStage() )
+  {
+    property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
+      this,
+      &Renderer::FindAnimatableProperty,
+      &Renderer::FindCustomProperty,
+      index );
+  }
+
+  return property;
 }
 
 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
 {
-  return RENDERER_IMPL.GetSceneObjectInputProperty( index );
+  const PropertyInputImpl* property = NULL;
+
+  if( OnStage() )
+  {
+    const SceneGraph::PropertyBase* baseProperty =
+      RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
+                                                     &Renderer::FindAnimatableProperty,
+                                                     &Renderer::FindCustomProperty,
+                                                     index );
+    property = static_cast<const PropertyInputImpl*>( baseProperty );
+  }
+
+  return property;
 }
 
 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
 {
-  return RENDERER_IMPL.GetPropertyComponentIndex( index );
+  return Property::INVALID_COMPONENT_INDEX;
 }
 
 bool Renderer::OnStage() const
 {
-  // TODO: MESH_REWORK
-  //DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
   return mOnStage;
 }
 
 void Renderer::Connect()
 {
-  // TODO: MESH_REWORK : check this
+  // @todo: MESH_REWORK : check this
   mGeometryConnector.OnStageConnect();
   mMaterialConnector.OnStageConnect();
   mOnStage = true;
@@ -177,7 +243,7 @@ void Renderer::Connect()
 
 void Renderer::Disconnect()
 {
-  // TODO: MESH_REWORK : check this
+  // @todo: MESH_REWORK : check this
   mGeometryConnector.OnStageDisconnect();
   mMaterialConnector.OnStageDisconnect();
   mOnStage = false;
@@ -185,19 +251,36 @@ void Renderer::Disconnect()
 
 Renderer::Renderer()
 : mSceneObject(NULL),
+  mDepthIndex(0),
   mOnStage(false)
 {
 }
 
 void Renderer::Initialize()
 {
+  EventThreadServices& eventThreadServices = GetEventThreadServices();
+  SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
+
   // Transfer object ownership of scene-object to message
   mSceneObject = SceneGraph::RendererAttachment::New();
 
   // Send message to update to connect to scene graph:
-  AttachToSceneGraphMessage( Stage::GetCurrent()->GetUpdateManager(), mSceneObject );
+  AttachToSceneGraphMessage( updateManager, mSceneObject );
+
+  eventThreadServices.RegisterObject( this );
 }
 
+Renderer::~Renderer()
+{
+  if( EventThreadServices::IsCoreRunning() )
+  {
+    EventThreadServices& eventThreadServices = GetEventThreadServices();
+    SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
+    RemoveObjectMessage( updateManager, mSceneObject );
+
+    eventThreadServices.UnregisterObject( this );
+  }
+}
 
 } // namespace Internal
 } // namespace Dali