(Renderer) Fix memory leak when using blend-color
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / renderer-impl.cpp
index d9f30a1..3b82ab6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/devel-api/scripting/scripting.h>
+#include <dali/devel-api/rendering/renderer-devel.h>
 #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
@@ -64,7 +65,6 @@ DALI_PROPERTY( "stencilMask",                     INTEGER,   true, false,  false
 DALI_PROPERTY( "stencilOperationOnFail",          INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
 DALI_PROPERTY( "stencilOperationOnZFail",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
 DALI_PROPERTY( "stencilOperationOnZPass",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
-DALI_PROPERTY( "batchingEnabled",                 BOOLEAN,   true, false,  false, Dali::Renderer::Property::BATCHING_ENABLED )
 DALI_PROPERTY_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX )
 
 // Property string to enumeration tables:
@@ -192,14 +192,14 @@ Geometry* Renderer::GetGeometry() const
 
 void Renderer::SetTextures( TextureSet& textureSet )
 {
-  mTextureSetConnector.Set( textureSet, OnStage() );
+  mTextureSet = &textureSet;
   const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
   SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
 }
 
 TextureSet* Renderer::GetTextures() const
 {
-  return mTextureSetConnector.Get().Get();
+  return mTextureSet.Get();
 }
 
 void Renderer::SetShader( Shader& shader )
@@ -290,28 +290,6 @@ void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
   equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
 }
 
-void Renderer::SetBlendColor( const Vector4& color )
-{
-  if( !mBlendColor )
-  {
-    mBlendColor = new Vector4();
-  }
-  if( *mBlendColor != color )
-  {
-    *mBlendColor = color;
-    SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
-  }
-}
-
-Vector4 Renderer::GetBlendColor() const
-{
-  if( mBlendColor )
-  {
-    return *mBlendColor;
-  }
-  return Color::TRANSPARENT; // GL default
-}
-
 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
 {
   if( firstElement != mIndexedDrawFirstElement )
@@ -349,11 +327,6 @@ bool Renderer::IsPreMultipliedAlphaEnabled() const
   return mPremultipledAlphaEnabled;
 }
 
-bool Renderer::IsBatchingEnabled() const
-{
-  return mBatchingEnabled;
-}
-
 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
 {
   return mSceneObject;
@@ -651,19 +624,6 @@ void Renderer::SetDefaultProperty( Property::Index index,
       }
       break;
     }
-    case Dali::Renderer::Property::BATCHING_ENABLED:
-    {
-      bool enabled;
-      if( propertyValue.Get( enabled ) )
-      {
-        if( mBatchingEnabled != enabled )
-        {
-          mBatchingEnabled = enabled;
-          SetBatchingEnabledMessage( GetEventThreadServices(), *mSceneObject, mBatchingEnabled );
-        }
-      }
-      break;
-    }
   }
 }
 
@@ -747,14 +707,7 @@ Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
     }
     case Dali::Renderer::Property::BLEND_COLOR:
     {
-      if( mBlendColor )
-      {
-        value = *mBlendColor;
-      }
-      else
-      {
-        value = Color::TRANSPARENT;
-      }
+      value = GetBlendColor();
       break;
     }
     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
@@ -777,11 +730,6 @@ Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
       value = mDepthWriteMode;
       break;
     }
-    case Dali::Renderer::Property::BATCHING_ENABLED:
-    {
-      value = mBatchingEnabled;
-      break;
-    }
     case Dali::Renderer::Property::DEPTH_FUNCTION:
     {
       value = mDepthFunction;
@@ -851,14 +799,11 @@ const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Prop
   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 );
-  }
+  property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
+    this,
+    &Renderer::FindAnimatableProperty,
+    &Renderer::FindCustomProperty,
+    index );
 
   return property;
 }
@@ -867,15 +812,12 @@ const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::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 );
-  }
+  const SceneGraph::PropertyBase* baseProperty =
+    RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
+                                                   &Renderer::FindAnimatableProperty,
+                                                   &Renderer::FindCustomProperty,
+                                                   index );
+  property = static_cast<const PropertyInputImpl*>( baseProperty );
 
   return property;
 }
@@ -885,34 +827,9 @@ int Renderer::GetPropertyComponentIndex( Property::Index index ) const
   return Property::INVALID_COMPONENT_INDEX;
 }
 
-bool Renderer::OnStage() const
-{
-  return mOnStageCount > 0;
-}
-
-void Renderer::Connect()
-{
-  if( mOnStageCount == 0 )
-  {
-    mTextureSetConnector.OnStageConnect();
-  }
-  ++mOnStageCount;
-}
-
-void Renderer::Disconnect()
-{
-  --mOnStageCount;
-  if( mOnStageCount == 0 )
-  {
-    mTextureSetConnector.OnStageDisconnect();
-  }
-}
-
 Renderer::Renderer()
 : mSceneObject(NULL ),
-  mBlendColor( NULL ),
   mDepthIndex( 0 ),
-  mOnStageCount( 0 ),
   mIndexedDrawFirstElement( 0 ),
   mIndexedDrawElementCount( 0 ),
   mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
@@ -922,8 +839,7 @@ Renderer::Renderer()
   mBlendMode( BlendMode::AUTO ),
   mDepthWriteMode( DepthWriteMode::AUTO ),
   mDepthTestMode( DepthTestMode::AUTO ),
-  mPremultipledAlphaEnabled( false ),
-  mBatchingEnabled( false )
+  mPremultipledAlphaEnabled( false )
 {
 }
 
@@ -938,6 +854,22 @@ void Renderer::Initialize()
   eventThreadServices.RegisterObject( this );
 }
 
+void Renderer::SetBlendColor( const Vector4& blendColor )
+{
+  mBlendingOptions.SetBlendColor( blendColor );
+  SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, GetBlendColor() );
+}
+
+const Vector4& Renderer::GetBlendColor() const
+{
+  const Vector4* blendColor = mBlendingOptions.GetBlendColor();
+  if( blendColor )
+  {
+    return *blendColor;
+  }
+  return Color::TRANSPARENT; // GL default
+}
+
 Renderer::~Renderer()
 {
   if( EventThreadServices::IsCoreRunning() )