Mofidy codes for Dali Windows backend
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / geometry-impl.cpp
index 1759c79..45c0a37 100644 (file)
@@ -22,8 +22,6 @@
 #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/update/common/double-buffered-property.h>
 #include <dali/internal/update/manager/update-manager.h>
 
 namespace Dali
@@ -31,29 +29,6 @@ namespace Dali
 namespace Internal
 {
 
-namespace
-{
-
-/**
- *            |name                    |type     |writable|animatable|constraint-input|enum for index-checking|
- */
-DALI_PROPERTY_TABLE_BEGIN
-DALI_PROPERTY( "geometry-type",         STRING,   true, false,  true, Dali::Geometry::Property::GEOMETRY_TYPE )
-DALI_PROPERTY( "geometry-center",       VECTOR3,  true, true,   true, Dali::Geometry::Property::GEOMETRY_CENTER )
-DALI_PROPERTY( "requires-depth-test",   BOOLEAN,  true, false,  true, Dali::Geometry::Property::REQUIRES_DEPTH_TEST )
-DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
-
-const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> GEOMETRY_IMPL = { DEFAULT_PROPERTY_DETAILS };
-
-BaseHandle Create()
-{
-  return Dali::Geometry::New();
-}
-
-TypeRegistration mType( typeid( Dali::Geometry ), typeid( Dali::Handle ), Create );
-
-} // unnamed namespace
-
 GeometryPtr Geometry::New()
 {
   GeometryPtr geometry( new Geometry() );
@@ -64,7 +39,7 @@ GeometryPtr Geometry::New()
 std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer )
 {
   mVertexBuffers.push_back( &vertexBuffer );
-  SceneGraph::AddVertexBufferMessage( GetEventThreadServices(), *mSceneObject, *vertexBuffer.GetRenderObject() );
+  SceneGraph::AttachVertexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, *vertexBuffer.GetRenderObject() );
   return mVertexBuffers.size() - 1u;
 }
 
@@ -76,299 +51,62 @@ std::size_t Geometry::GetNumberOfVertexBuffers() const
 void Geometry::RemoveVertexBuffer( std::size_t index )
 {
   const Render::PropertyBuffer& renderPropertyBuffer = static_cast<const Render::PropertyBuffer&>( *(mVertexBuffers[index]->GetRenderObject()) );
-  SceneGraph::RemoveVertexBufferMessage( GetEventThreadServices(), *mSceneObject, renderPropertyBuffer );
+  SceneGraph::RemoveVertexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, renderPropertyBuffer );
 
   mVertexBuffers.erase( mVertexBuffers.begin() + index );
 }
 
-void Geometry::SetIndexBuffer( PropertyBuffer& indexBuffer )
-{
-  mIndexBuffer = &indexBuffer;
-  SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, *indexBuffer.GetRenderObject() );
-}
-
-void Geometry::SetGeometryType( Dali::Geometry::GeometryType geometryType )
+void Geometry::SetIndexBuffer( const unsigned short* indices, size_t count )
 {
-  if( NULL != mSceneObject )
+  Dali::Vector<unsigned short> indexData;
+  if( indices && count )
   {
-    SceneGraph::DoubleBufferedPropertyMessage<int>::Send(
-      GetEventThreadServices(),
-      mSceneObject,
-      &mSceneObject->mGeometryType,
-      &SceneGraph::DoubleBufferedProperty<int>::Set,
-      static_cast<int>(geometryType) );
+    indexData.Resize( count );
+    std::copy( indices, indices + count, indexData.Begin() );
   }
-}
 
-Dali::Geometry::GeometryType Geometry::GetGeometryType() const
-{
-  return mSceneObject->GetGeometryType(GetEventThreadServices().GetEventBufferIndex());
+  SceneGraph::SetIndexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, indexData );
 }
 
-void Geometry::SetRequiresDepthTesting( bool requiresDepthTest )
+void Geometry::SetType( Dali::Geometry::Type geometryType )
 {
-  if( NULL != mSceneObject )
+  if( geometryType != mType )
   {
-    SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, static_cast<int>(requiresDepthTest) );
-  }
-}
+    SceneGraph::SetGeometryTypeMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, geometryType );
 
-bool Geometry::GetRequiresDepthTesting() const
-{
-  if( mSceneObject )
-  {
-    // mSceneObject is being used in a separate thread; copy the value from the previous update
-    return mSceneObject->GetRequiresDepthTesting(GetEventThreadServices().GetEventBufferIndex());
+    mType = geometryType;
   }
-  return false;
-}
-
-const SceneGraph::Geometry* Geometry::GetGeometrySceneObject() const
-{
-  return mSceneObject;
 }
 
-unsigned int Geometry::GetDefaultPropertyCount() const
+Dali::Geometry::Type Geometry::GetType() const
 {
-  return GEOMETRY_IMPL.GetDefaultPropertyCount();
+  return mType;
 }
 
-void Geometry::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
+const Render::Geometry* Geometry::GetRenderObject() const
 {
-  GEOMETRY_IMPL.GetDefaultPropertyIndices( indices );
-}
-
-const char* Geometry::GetDefaultPropertyName(Property::Index index) const
-{
-  return GEOMETRY_IMPL.GetDefaultPropertyName( index );
-}
-
-Property::Index Geometry::GetDefaultPropertyIndex( const std::string& name ) const
-{
-  return GEOMETRY_IMPL.GetDefaultPropertyIndex( name );
-}
-
-bool Geometry::IsDefaultPropertyWritable( Property::Index index ) const
-{
-  return GEOMETRY_IMPL.IsDefaultPropertyWritable( index );
-}
-
-bool Geometry::IsDefaultPropertyAnimatable( Property::Index index ) const
-{
-  return GEOMETRY_IMPL.IsDefaultPropertyAnimatable( index );
-}
-
-bool Geometry::IsDefaultPropertyAConstraintInput( Property::Index index ) const
-{
-  return GEOMETRY_IMPL.IsDefaultPropertyAConstraintInput( index );
-}
-
-Property::Type Geometry::GetDefaultPropertyType( Property::Index index ) const
-{
-  return GEOMETRY_IMPL.GetDefaultPropertyType( index );
-}
-
-void Geometry::SetDefaultProperty( Property::Index index,
-                                   const Property::Value& propertyValue )
-{
-  switch( index )
-  {
-    case Dali::Geometry::Property::GEOMETRY_TYPE :
-    {
-      SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mGeometryType, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
-      break;
-    }
-    case Dali::Geometry::Property::GEOMETRY_CENTER :
-    {
-      SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mCenter, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
-      break;
-    }
-    case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
-    {
-      SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, propertyValue.Get<bool>() );
-      break;
-    }
-  }
-}
-
-void Geometry::SetSceneGraphProperty( Property::Index index,
-                                      const PropertyMetadata& entry,
-                                      const Property::Value& value )
-{
-  GEOMETRY_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
-}
-
-Property::Value Geometry::GetDefaultProperty( Property::Index index ) const
-{
-  BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
-  Property::Value value;
-
-  switch( index )
-  {
-    case Dali::Geometry::Property::GEOMETRY_TYPE :
-    {
-      if( mSceneObject )
-      {
-        value = mSceneObject->mGeometryType[bufferIndex];
-      }
-      break;
-    }
-    case Dali::Geometry::Property::GEOMETRY_CENTER :
-    {
-      if( mSceneObject )
-      {
-        value = mSceneObject->mCenter[bufferIndex];
-      }
-      break;
-    }
-
-    case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
-    {
-      if( mSceneObject )
-      {
-        value = mSceneObject->mRequiresDepthTest[bufferIndex];
-      }
-      break;
-    }
-  }
-
-  return value;
-}
-
-const SceneGraph::PropertyOwner* Geometry::GetPropertyOwner() const
-{
-  return mSceneObject;
-}
-
-const SceneGraph::PropertyOwner* Geometry::GetSceneObject() const
-{
-  return mSceneObject;
-}
-
-const SceneGraph::PropertyBase* Geometry::GetSceneObjectAnimatableProperty( Property::Index index ) const
-{
-  const SceneGraph::PropertyBase* property = NULL;
-
-  if( OnStage() )
-  {
-    property = GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
-                                                               &Geometry::FindAnimatableProperty,
-                                                               &Geometry::FindCustomProperty,
-                                                               index );
-
-    if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
-    {
-      switch(index)
-      {
-        case Dali::Geometry::Property::GEOMETRY_CENTER :
-        {
-          property = &mSceneObject->mCenter;
-          break;
-        }
-        default:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
-          break;
-        }
-      }
-    }
-  }
-  return property;
-}
-
-const PropertyInputImpl* Geometry::GetSceneObjectInputProperty( Property::Index index ) const
-{
-  const PropertyInputImpl* property = NULL;
-
-  if( OnStage() )
-  {
-    const SceneGraph::PropertyBase* baseProperty =
-      GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
-                                                      &Geometry::FindAnimatableProperty,
-                                                      &Geometry::FindCustomProperty,
-                                                      index );
-
-    property = static_cast<const PropertyInputImpl*>( baseProperty );
-
-    if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
-    {
-      switch(index)
-      {
-        case Dali::Geometry::Property::GEOMETRY_TYPE :
-        {
-          property = &mSceneObject->mGeometryType;
-          break;
-        }
-        case Dali::Geometry::Property::GEOMETRY_CENTER :
-        {
-          property = &mSceneObject->mCenter;
-          break;
-        }
-        case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
-        {
-          property = &mSceneObject->mRequiresDepthTest;
-          break;
-        }
-        default:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Property cannot be a constraint input");
-          break;
-        }
-      }
-    }
-  }
-
-  return property;
-}
-
-int Geometry::GetPropertyComponentIndex( Property::Index index ) const
-{
-  // @todo MESH_REWORK - Change this if component properties are added for center/half-extent
-  return Property::INVALID_COMPONENT_INDEX;
-}
-
-bool Geometry::OnStage() const
-{
-  return mOnStage;
-}
-
-void Geometry::Connect()
-{
-  mOnStage = true;
-}
-
-void Geometry::Disconnect()
-{
-  mOnStage = false;
+  return mRenderObject;
 }
 
 Geometry::Geometry()
-: mIndexBuffer( NULL ),
-  mSceneObject( NULL ),
-  mOnStage( false )
+: mEventThreadServices( *Stage::GetCurrent() ),
+  mRenderObject( NULL ),
+  mType(Dali::Geometry::TRIANGLES)
 {
 }
 
 void Geometry::Initialize()
 {
-  EventThreadServices& eventThreadServices = GetEventThreadServices();
-  SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
-
-  mSceneObject = new SceneGraph::Geometry();
-  AddMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
-
-  eventThreadServices.RegisterObject( this );
+  mRenderObject = new Render::Geometry();
+  OwnerPointer< Render::Geometry > transferOwnership( mRenderObject );
+  AddGeometry( mEventThreadServices.GetUpdateManager(), transferOwnership );
 }
 
 Geometry::~Geometry()
 {
-  if( EventThreadServices::IsCoreRunning() )
+  if( EventThreadServices::IsCoreRunning() && mRenderObject )
   {
-    EventThreadServices& eventThreadServices = GetEventThreadServices();
-    SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
-    RemoveMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
-
-    eventThreadServices.UnregisterObject( this );
+    RemoveGeometry( mEventThreadServices.GetUpdateManager(), *mRenderObject );
   }
 }