Blend Equation Advanced Supporting
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
index 69e859b..748bcec 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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,7 +20,6 @@
 
 // EXTERNAL HEADER
 #include <dali-toolkit/public-api/dali-toolkit-common.h>
-#include <dali/devel-api/object/handle-devel.h>
 #include <dali/devel-api/scripting/enum-helper.h>
 #include <dali/devel-api/rendering/renderer-devel.h>
 #include <dali/integration-api/debug.h>
@@ -368,7 +367,6 @@ void Visual::Base::CreatePropertyMap( Property::Map& map ) const
   // which is ok, because they have a different key value range.
   map.Insert( Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor ); // vec4
   map.Insert( Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a );
-  map.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired() );
 
   auto fittingModeString = Scripting::GetLinearEnumerationName< FittingMode >(
     mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT );
@@ -415,6 +413,11 @@ bool Visual::Base::IsPreMultipliedAlphaEnabled() const
   return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
 }
 
+bool Visual::Base::IsAdvancedBlendEquationApplied() const
+{
+  return IsPreMultipliedAlphaEnabled() && DevelRenderer::IsAdvancedBlendEquationApplied( mImpl->mRenderer );
+}
+
 void Visual::Base::DoSetOffScene( Actor& actor )
 {
   actor.RemoveRenderer( mImpl->mRenderer );
@@ -442,14 +445,13 @@ void Visual::Base::RegisterMixColor()
   // (Color and Primitive visuals will register their own and save to this index)
   if( mImpl->mMixColorIndex == Property::INVALID_INDEX )
   {
-    mImpl->mMixColorIndex = DevelHandle::RegisterProperty(
-      mImpl->mRenderer,
+    mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(
       Toolkit::Visual::Property::MIX_COLOR,
       MIX_COLOR,
       Vector3(mImpl->mMixColor) );
   }
 
-  if( mImpl->mMixColor.a < 1.f )
+  if( mImpl->mMixColor.a < 1.f || IsAdvancedBlendEquationApplied() )
   {
     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
   }
@@ -472,7 +474,7 @@ void Visual::Base::SetMixColor( const Vector4& color )
   {
     mImpl->mRenderer.SetProperty( mImpl->mMixColorIndex, Vector3(color) );
     mImpl->mRenderer.SetProperty( DevelRenderer::Property::OPACITY, color.a );
-    if( color.a < 1.f )
+    if( color.a < 1.f || IsAdvancedBlendEquationApplied() )
     {
       mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
     }
@@ -557,13 +559,13 @@ Renderer Visual::Base::GetRenderer()
 
 Property::Index Visual::Base::GetPropertyIndex( Property::Key key )
 {
-  Property::Index index = DevelHandle::GetPropertyIndex( mImpl->mRenderer, key );
+  Property::Index index = mImpl->mRenderer.GetPropertyIndex( key );
 
   if( index == Property::INVALID_INDEX )
   {
     // Is it a shader property?
     Shader shader = mImpl->mRenderer.GetShader();
-    index = DevelHandle::GetPropertyIndex( shader, key );
+    index = shader.GetPropertyIndex( key );
     if( index != Property::INVALID_INDEX )
     {
       // Yes - we should register it in the Renderer so it can be set / animated
@@ -581,7 +583,7 @@ Property::Index Visual::Base::GetPropertyIndex( Property::Key key )
         // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
       }
       Property::Value value = shader.GetProperty( index );
-      index = DevelHandle::RegisterProperty( mImpl->mRenderer, keyIndex, keyName, value );
+      index = mImpl->mRenderer.RegisterProperty( keyIndex, keyName, value );
     }
   }
   return index;
@@ -773,7 +775,8 @@ void Visual::Base::SetupBlendMode( Animation& transition, bool isInitialOpaque,
 {
   // Ensure the blend mode is turned on if we are animating opacity, and
   // turned off after the animation ends if the final value is opaque
-  if( ! isInitialOpaque || mImpl->mMixColor.a < 1.0f )
+  if( ( ! isInitialOpaque || mImpl->mMixColor.a < 1.0f ) ||
+      ( mImpl->mRenderer && IsAdvancedBlendEquationApplied() ) )
   {
     if( mImpl->mRenderer )
     {
@@ -798,8 +801,16 @@ void Visual::Base::OnMixColorFinished( Animation& animation )
   if( mImpl->mRenderer )
   {
     DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::OnMixColorFinished()\n");
-    mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE,
-                                  ( mImpl->mMixColor.a < 1.0 ) ? BlendMode::ON : BlendMode::AUTO );
+
+    if( mImpl->mMixColor.a >= 1.f &&
+        !IsAdvancedBlendEquationApplied() )
+    {
+      mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO );
+    }
+    else
+    {
+      mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
+    }
   }
   delete mImpl->mBlendSlotDelegate;
   mImpl->mBlendSlotDelegate = NULL;