Merge "Remove unsafe new-delete pair from program and change unoptimal resizes to...
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-impl.cpp
index c28429b..bc8d2a9 100644 (file)
 
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/object/type-registry.h>
 #include <dali/internal/common/event-to-update.h>
 #include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/actors/camera-actor-impl.h>
+#include <dali/internal/event/common/property-helper.h>
 #include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/images/frame-buffer-image-impl.h>
-#include <dali/internal/update/render-tasks/scene-graph-render-task.h>
 #include <dali/internal/update/nodes/node.h>
+#include <dali/internal/update/render-tasks/scene-graph-render-task.h>
 
 #if defined(DEBUG_ENABLED)
 namespace
@@ -39,34 +41,30 @@ Debug::Filter* gLogRender = Debug::Filter::New(Debug::Concise, false, "LOG_RENDE
 namespace Dali
 {
 
-const Property::Index RenderTask::VIEWPORT_POSITION         = 0;
-const Property::Index RenderTask::VIEWPORT_SIZE             = 1;
-const Property::Index RenderTask::CLEAR_COLOR               = 2;
-
 namespace Internal
 {
 
 namespace // For internal properties
 {
 
-const std::string DEFAULT_PROPERTY_NAMES[] =
-{
-  "viewport-position",
-  "viewport-size",
-  "clear-color"
-};
-const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_NAMES ) / sizeof( std::string );
+// Properties
 
-const Property::Type DEFAULT_PROPERTY_TYPES[DEFAULT_PROPERTY_COUNT] =
-{
-  Property::VECTOR2,    // viewport-position
-  Property::VECTOR2,    // viewport-size
-  Property::VECTOR4,    // clear-color
-};
+//              Name                 Type     writable animatable constraint-input  enum for index-checking
+DALI_PROPERTY_TABLE_BEGIN
+DALI_PROPERTY( "viewport-position",  VECTOR2,    true,    true,    true,    Dali::RenderTask::Property::VIEWPORT_POSITION )
+DALI_PROPERTY( "viewport-size",      VECTOR2,    true,    true,    true,    Dali::RenderTask::Property::VIEWPORT_SIZE     )
+DALI_PROPERTY( "clear-color",        VECTOR4,    true,    true,    true,    Dali::RenderTask::Property::CLEAR_COLOR       )
+DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX )
+
+// Signals
 
-}// unnamed namespace
+const char* const SIGNAL_FINISHED = "finished";
 
-RenderTask::DefaultPropertyLookup* RenderTask::sDefaultPropertyLookup = NULL;
+TypeRegistration mType( typeid( Dali::RenderTask ), typeid( Dali::BaseHandle ), NULL );
+
+SignalConnectorType signalConnector1( mType, SIGNAL_FINISHED, &RenderTask::DoConnectSignal );
+
+} // Unnamed namespace
 
 RenderTask* RenderTask::New( bool isSystemLevel )
 {
@@ -285,6 +283,25 @@ bool RenderTask::GetClearEnabled() const
   return mClearEnabled;
 }
 
+void RenderTask::SetCullMode( bool mode )
+{
+  if ( mCullMode != mode )
+  {
+    mCullMode = mode;
+
+    if ( mSceneObject )
+    {
+      // mSceneObject is being used in a separate thread; queue a message to set the value
+      SetCullModeMessage( mEventToUpdate, *mSceneObject, mCullMode );
+    }
+  }
+}
+
+bool RenderTask::GetCullMode() const
+{
+  return mCullMode;
+}
+
 void RenderTask::SetRefreshRate( unsigned int refreshRate )
 {
   DALI_LOG_TRACE_METHOD_FMT(gLogRender, "this:%p  rate:%d\n", this, refreshRate);
@@ -405,6 +422,7 @@ SceneGraph::RenderTask* RenderTask::CreateSceneObject()
   SetExclusiveMessage( mEventToUpdate, *mSceneObject, mExclusive );
   SetClearColorMessage(  mEventToUpdate, *mSceneObject, mClearColor );
   SetClearEnabledMessage(  mEventToUpdate, *mSceneObject, mClearEnabled );
+  SetCullModeMessage(  mEventToUpdate, *mSceneObject, mCullMode );
   SetRefreshRateMessage(  mEventToUpdate, *mSceneObject, mRefreshRate );
 
   // Caller takes ownership
@@ -429,16 +447,9 @@ void RenderTask::DiscardSceneObject()
 }
 
 /********************************************************************************
- ********************************************************************************
  ********************************   PROPERTY METHODS   **************************
- ********************************************************************************
  ********************************************************************************/
 
-bool RenderTask::IsSceneObjectRemovable() const
-{
-  return false; // The scene object is permanently "on stage" whilst this object is alive
-}
-
 unsigned int RenderTask::GetDefaultPropertyCount() const
 {
   return DEFAULT_PROPERTY_COUNT;
@@ -454,17 +465,15 @@ void RenderTask::GetDefaultPropertyIndices( Property::IndexContainer& indices )
   }
 }
 
-const std::string& RenderTask::GetDefaultPropertyName( Property::Index index ) const
+const char* RenderTask::GetDefaultPropertyName( Property::Index index ) const
 {
   if( index < DEFAULT_PROPERTY_COUNT )
   {
-    return DEFAULT_PROPERTY_NAMES[index];
+    return DEFAULT_PROPERTY_DETAILS[index].name;
   }
   else
   {
-    // index out of range..return empty string
-    static const std::string INVALID_PROPERTY_NAME;
-    return INVALID_PROPERTY_NAME;
+    return NULL;
   }
 }
 
@@ -472,90 +481,72 @@ Property::Index RenderTask::GetDefaultPropertyIndex(const std::string& name) con
 {
   Property::Index index = Property::INVALID_INDEX;
 
-  // Lazy initialization of static sDefaultPropertyLookup
-  if (!sDefaultPropertyLookup)
+  // Look for name in default properties
+  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
   {
-    sDefaultPropertyLookup = new DefaultPropertyLookup();
-
-    for (int i=0; i<DEFAULT_PROPERTY_COUNT; ++i)
+    if( 0 == strcmp( name.c_str(), DEFAULT_PROPERTY_DETAILS[i].name ) ) // dont want to convert rhs to string
     {
-      (*sDefaultPropertyLookup)[DEFAULT_PROPERTY_NAMES[i]] = i;
+      index = i;
+      break;
     }
   }
-  DALI_ASSERT_DEBUG( NULL != sDefaultPropertyLookup );
-
-  // Look for name in default properties
-  DefaultPropertyLookup::const_iterator result = sDefaultPropertyLookup->find( name );
-  if ( sDefaultPropertyLookup->end() != result )
-  {
-    index = result->second;
-  }
 
   return index;
 }
 
 bool RenderTask::IsDefaultPropertyWritable(Property::Index index) const
 {
-  return true;
+  return DEFAULT_PROPERTY_DETAILS[ index ].writable;
 }
 
 bool RenderTask::IsDefaultPropertyAnimatable(Property::Index index) const
 {
-  return true;
+  return DEFAULT_PROPERTY_DETAILS[ index ].animatable;
 }
 
 bool RenderTask::IsDefaultPropertyAConstraintInput( Property::Index index ) const
 {
-  return true;
+  return DEFAULT_PROPERTY_DETAILS[ index ].constraintInput;
 }
 
 Property::Type RenderTask::GetDefaultPropertyType(Property::Index index) const
 {
   if( index < DEFAULT_PROPERTY_COUNT )
   {
-    return DEFAULT_PROPERTY_TYPES[index];
-  }
-  else
-  {
-    // index out of range...return Property::NONE
-    return Property::NONE;
+    return DEFAULT_PROPERTY_DETAILS[index].type;
   }
+
+  // index out of range...return Property::NONE
+  return Property::NONE;
 }
 
 void RenderTask::SetDefaultProperty( Property::Index index, const Property::Value& property )
 {
   switch ( index )
   {
-    case Dali::RenderTask::VIEWPORT_POSITION:
+    case Dali::RenderTask::Property::VIEWPORT_POSITION:
     {
       SetViewportPosition( property.Get<Vector2>() );
       break;
     }
-    case Dali::RenderTask::VIEWPORT_SIZE:
+    case Dali::RenderTask::Property::VIEWPORT_SIZE:
     {
       SetViewportSize( property.Get<Vector2>() );
       break;
     }
-    case Dali::RenderTask::CLEAR_COLOR:
+    case Dali::RenderTask::Property::CLEAR_COLOR:
     {
       SetClearColor( property.Get<Vector4>() );
       break;
     }
-
     default:
     {
-      DALI_ASSERT_ALWAYS(false && "RenderTask property index out of range"); // should not come here
+      // nothing to do
       break;
     }
   }
 }
 
-void RenderTask::SetCustomProperty( Property::Index /*index*/, const CustomProperty& /*entry*/, const Property::Value& /*value*/ )
-{
-  // TODO: support them, it doesn't hurt.
-  DALI_ASSERT_ALWAYS( 0 && "RenderTask does not support custom properties");
-}
-
 Property::Value RenderTask::GetDefaultProperty(Property::Index index) const
 {
   Property::Value value;
@@ -563,17 +554,17 @@ Property::Value RenderTask::GetDefaultProperty(Property::Index index) const
   switch ( index )
   {
 
-    case Dali::RenderTask::VIEWPORT_POSITION:
+    case Dali::RenderTask::Property::VIEWPORT_POSITION:
     {
       value = GetCurrentViewportPosition();
       break;
     }
-    case Dali::RenderTask::VIEWPORT_SIZE:
+    case Dali::RenderTask::Property::VIEWPORT_SIZE:
     {
       value = GetCurrentViewportSize();
       break;
     }
-    case Dali::RenderTask::CLEAR_COLOR:
+    case Dali::RenderTask::Property::CLEAR_COLOR:
     {
       value = GetClearColor();
       break;
@@ -589,12 +580,6 @@ Property::Value RenderTask::GetDefaultProperty(Property::Index index) const
   return value;
 }
 
-void RenderTask::InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
-{
-  // TODO: support them, it doesn't hurt.
-  DALI_ASSERT_ALWAYS( 0 && "RenderTask does not support custom properties" );
-}
-
 const SceneGraph::PropertyOwner* RenderTask::GetSceneObject() const
 {
   return mSceneObject;
@@ -611,15 +596,15 @@ const SceneGraph::PropertyBase* RenderTask::GetSceneObjectAnimatableProperty( Pr
   {
     switch ( index )
     {
-      case Dali::RenderTask::VIEWPORT_POSITION:
+      case Dali::RenderTask::Property::VIEWPORT_POSITION:
         property = &mSceneObject->mViewportPosition;
         break;
 
-      case Dali::RenderTask::VIEWPORT_SIZE:
+      case Dali::RenderTask::Property::VIEWPORT_SIZE:
         property = &mSceneObject->mViewportSize;
         break;
 
-      case Dali::RenderTask::CLEAR_COLOR:
+      case Dali::RenderTask::Property::CLEAR_COLOR:
         property = &mSceneObject->mClearColor;
         break;
 
@@ -638,15 +623,15 @@ const PropertyInputImpl* RenderTask::GetSceneObjectInputProperty( Property::Inde
   {
     switch ( index )
     {
-      case Dali::RenderTask::VIEWPORT_POSITION:
+      case Dali::RenderTask::Property::VIEWPORT_POSITION:
         property = &mSceneObject->mViewportPosition;
         break;
 
-      case Dali::RenderTask::VIEWPORT_SIZE:
+      case Dali::RenderTask::Property::VIEWPORT_SIZE:
         property = &mSceneObject->mViewportSize;
         break;
 
-      case Dali::RenderTask::CLEAR_COLOR:
+      case Dali::RenderTask::Property::CLEAR_COLOR:
         property = &mSceneObject->mViewportSize;
         break;
 
@@ -678,16 +663,16 @@ void RenderTask::EmitSignalFinish()
 {
   DALI_LOG_INFO(gLogRender, Debug::General, "RenderTask::EmitSignalFinish(this:%p)\n", this);
 
-  if( !mSignalFinishedV2.Empty() )
+  if( !mSignalFinished.Empty() )
   {
     Dali::RenderTask handle( this );
-    mSignalFinishedV2.Emit(handle );
+    mSignalFinished.Emit(handle );
   }
 }
 
-Dali::RenderTask::RenderTaskSignalV2& RenderTask::FinishedSignal()
+Dali::RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
 {
-  return mSignalFinishedV2;
+  return mSignalFinished;
 }
 
 bool RenderTask::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
@@ -695,7 +680,7 @@ bool RenderTask::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface
   bool connected( true );
   RenderTask* renderTask = dynamic_cast<RenderTask*>(object);
 
-  if ( Dali::RenderTask::SIGNAL_FINISHED == signalName )
+  if ( 0 == strcmp( signalName.c_str(), SIGNAL_FINISHED ) )
   {
     renderTask->FinishedSignal().Connect( tracker, functor );
   }
@@ -721,6 +706,7 @@ RenderTask::RenderTask( EventToUpdate& eventToUpdate, bool isSystemLevel )
   mExclusive( Dali::RenderTask::DEFAULT_EXCLUSIVE ),
   mInputEnabled( Dali::RenderTask::DEFAULT_INPUT_ENABLED ),
   mClearEnabled( Dali::RenderTask::DEFAULT_CLEAR_ENABLED ),
+  mCullMode( Dali::RenderTask::DEFAULT_CULL_MODE ),
   mIsSystemLevel( isSystemLevel )
 {
   DALI_LOG_INFO(gLogRender, Debug::General, "RenderTask::RenderTask(this:%p)\n", this);
@@ -765,17 +751,17 @@ void RenderTask::Connector::SetActor( Actor* actor )
   }
 }
 
-void RenderTask::Connector::SceneObjectAdded( ProxyObject& proxy )
+void RenderTask::Connector::SceneObjectAdded( Object& object )
 {
   UpdateRenderTask();
 }
 
-void RenderTask::Connector::SceneObjectRemoved( ProxyObject& proxy )
+void RenderTask::Connector::SceneObjectRemoved( Object& object )
 {
   UpdateRenderTask();
 }
 
-void RenderTask::Connector::ProxyDestroyed( ProxyObject& proxy )
+void RenderTask::Connector::ObjectDestroyed( Object& object )
 {
   mActor = NULL;