(Vector) Reset the current frame when stopped
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "visual-base-impl.h"
20
21 // EXTERNAL HEADER
22 #include <dali-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali/devel-api/object/handle-devel.h>
24 #include <dali/devel-api/scripting/enum-helper.h>
25 #include <dali/devel-api/rendering/renderer-devel.h>
26 #include <dali/integration-api/debug.h>
27
28 //INTERNAL HEARDER
29 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
30 #include <dali-toolkit/public-api/visuals/primitive-visual-properties.h>
31 #include <dali-toolkit/public-api/visuals/visual-properties.h>
32 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
33 #include <dali-toolkit/internal/helpers/property-helper.h>
34 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
35 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
36
37 namespace
38 {
39 #if defined(DEBUG_ENABLED)
40 Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VISUAL_BASE" );
41 #endif
42
43 const char * const PRE_MULTIPLIED_ALPHA_PROPERTY( "preMultipliedAlpha" );
44
45 } // namespace
46
47 namespace Dali
48 {
49
50 namespace Toolkit
51 {
52
53 namespace Internal
54 {
55
56 namespace
57 {
58
59 DALI_ENUM_TO_STRING_TABLE_BEGIN( VISUAL_FITTING_MODE )
60 DALI_ENUM_TO_STRING_WITH_SCOPE( Visual::FittingMode, FIT_KEEP_ASPECT_RATIO  )
61 DALI_ENUM_TO_STRING_WITH_SCOPE( Visual::FittingMode, FILL  )
62 DALI_ENUM_TO_STRING_TABLE_END( VISUAL_FITTING_MODE )
63
64 } // namespace
65
66 Visual::Base::Base( VisualFactoryCache& factoryCache, FittingMode fittingMode )
67 : mImpl( new Impl(fittingMode) ),
68   mFactoryCache( factoryCache )
69 {
70 }
71
72 Visual::Base::~Base()
73 {
74   delete mImpl;
75 }
76
77 void Visual::Base::SetCustomShader( const Property::Map& shaderMap )
78 {
79   if( mImpl->mCustomShader )
80   {
81     mImpl->mCustomShader->SetPropertyMap( shaderMap );
82   }
83   else
84   {
85     mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
86   }
87 }
88
89 void Visual::Base::SetProperties( const Property::Map& propertyMap )
90 {
91   for( size_t i = 0; i < propertyMap.Count(); ++i )
92   {
93     const KeyValuePair& pair = propertyMap.GetKeyValue( i );
94     const Property::Key& key = pair.first;
95     const Property::Value& value = pair.second;
96
97     Property::Key matchKey = key;
98     if( matchKey.type == Property::Key::STRING )
99     {
100       if( matchKey == CUSTOM_SHADER )
101       {
102         matchKey = Property::Key( Toolkit::Visual::Property::SHADER );
103       }
104       else if( matchKey == TRANSFORM )
105       {
106         matchKey = Property::Key( Toolkit::Visual::Property::TRANSFORM );
107       }
108       else if( matchKey == PREMULTIPLIED_ALPHA )
109       {
110         matchKey = Property::Key( Toolkit::Visual::Property::PREMULTIPLIED_ALPHA );
111       }
112       else if( matchKey == MIX_COLOR )
113       {
114         matchKey = Property::Key( Toolkit::Visual::Property::MIX_COLOR );
115       }
116       else if( matchKey == OPACITY )
117       {
118         matchKey = Property::Key( Toolkit::Visual::Property::OPACITY );
119       }
120       else if( matchKey == VISUAL_FITTING_MODE )
121       {
122         matchKey = Property::Key( Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE );
123       }
124     }
125
126     switch( matchKey.indexKey )
127     {
128       case Toolkit::Visual::Property::SHADER:
129       {
130         Property::Map shaderMap;
131         if( value.Get( shaderMap ) )
132         {
133           SetCustomShader( shaderMap );
134         }
135         break;
136       }
137
138       case Toolkit::Visual::Property::TRANSFORM:
139       {
140         Property::Map map;
141         if( value.Get( map ) )
142         {
143           mImpl->mTransform.SetPropertyMap( map );
144         }
145         break;
146       }
147
148       case Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
149       {
150         bool premultipliedAlpha = false;
151         if( value.Get( premultipliedAlpha ) )
152         {
153           EnablePreMultipliedAlpha( premultipliedAlpha );
154         }
155         break;
156       }
157
158       case Toolkit::Visual::Property::MIX_COLOR:
159       {
160         Vector4 mixColor;
161         if( value.Get( mixColor ) )
162         {
163           if( value.GetType() == Property::VECTOR4 )
164           {
165             SetMixColor( mixColor );
166           }
167           else
168           {
169             Vector3 mixColor3(mixColor);
170             SetMixColor( mixColor3 );
171           }
172         }
173         break;
174       }
175       case Toolkit::Visual::Property::OPACITY:
176       {
177         float opacity;
178         if( value.Get( opacity ) )
179         {
180           mImpl->mMixColor.a = opacity;
181           SetMixColor( mImpl->mMixColor );
182         }
183         break;
184       }
185       case Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE:
186       {
187         Scripting::GetEnumerationProperty< Visual::FittingMode >(
188           value, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode );
189         break;
190       }
191     }
192   }
193
194   DoSetProperties( propertyMap );
195 }
196
197 void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size controlSize )
198 {
199   mImpl->mControlSize = controlSize;
200   mImpl->mTransform.UpdatePropertyMap( transform );
201
202 #if defined(DEBUG_ENABLED)
203   std::ostringstream oss;
204   oss << transform;
205   DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::SetTransformAndSize(%s) - [\e[1;32mtransform: %s  controlSize: (%3.1f, %3.1f)]\e[0m\n",
206                  GetName().c_str(), oss.str().c_str(), controlSize.x, controlSize.y );
207 #endif
208
209   OnSetTransform();
210 }
211
212 void Visual::Base::SetName( const std::string& name )
213 {
214   mImpl->mName = name;
215 }
216
217 const std::string& Visual::Base::GetName() const
218 {
219   return mImpl->mName;
220 }
221
222 float Visual::Base::GetHeightForWidth( float width )
223 {
224   float aspectCorrectedHeight = 0.f;
225   Vector2 naturalSize;
226   GetNaturalSize( naturalSize );
227   if( naturalSize.width )
228   {
229     aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
230   }
231   return aspectCorrectedHeight;
232 }
233
234 float Visual::Base::GetWidthForHeight( float height )
235 {
236   float aspectCorrectedWidth = 0.f;
237   Vector2 naturalSize;
238   GetNaturalSize( naturalSize );
239   if( naturalSize.height > 0.0f )
240   {
241     aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
242   }
243   return aspectCorrectedWidth;
244 }
245
246 void Visual::Base::GetNaturalSize( Vector2& naturalSize )
247 {
248   naturalSize = Vector2::ZERO;
249 }
250
251 void Visual::Base::DoAction( const Property::Index actionId, const Property::Value attributes )
252 {
253   OnDoAction( actionId, attributes );
254 }
255
256 void Visual::Base::SetDepthIndex( int index )
257 {
258   mImpl->mDepthIndex = index;
259   if( mImpl->mRenderer )
260   {
261     mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
262   }
263 }
264
265 int Visual::Base::GetDepthIndex() const
266 {
267   return mImpl->mDepthIndex;
268 }
269
270 void Visual::Base::SetOnStage( Actor& actor )
271 {
272   if( !IsOnStage() )
273   {
274     // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
275     // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
276     DoSetOnStage( actor );
277
278     if( mImpl->mRenderer )
279     {
280       RegisterMixColor();
281
282       mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
283       mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
284       mImpl->mFlags |= Impl::IS_ON_STAGE; // Only sets the flag if renderer exists
285     }
286   }
287 }
288
289 void Visual::Base::SetOffStage( Actor& actor )
290 {
291   if( IsOnStage() )
292   {
293     DoSetOffStage( actor );
294     mImpl->mMixColorIndex = Property::INVALID_INDEX;
295     mImpl->mFlags &= ~Impl::IS_ON_STAGE;
296   }
297 }
298
299 void Visual::Base::CreatePropertyMap( Property::Map& map ) const
300 {
301   DoCreatePropertyMap( map );
302
303   if( mImpl->mCustomShader )
304   {
305     mImpl->mCustomShader->CreatePropertyMap( map );
306   }
307
308   Property::Map transform;
309   mImpl->mTransform.GetPropertyMap( transform );
310   map.Insert( Toolkit::Visual::Property::TRANSFORM, transform );
311
312   bool premultipliedAlpha( IsPreMultipliedAlphaEnabled() );
313   map.Insert( Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha );
314
315   // Note, Color and Primitive will also insert their own mix color into the map
316   // which is ok, because they have a different key value range.
317   map.Insert( Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor ); // vec4
318   map.Insert( Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a );
319
320   auto fittingModeString = Scripting::GetLinearEnumerationName< FittingMode >(
321     mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT );
322   map.Insert( Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString );
323 }
324
325 void Visual::Base::CreateInstancePropertyMap( Property::Map& map ) const
326 {
327   DoCreateInstancePropertyMap( map );
328
329   if( mImpl->mCustomShader )
330   {
331     mImpl->mCustomShader->CreatePropertyMap( map );
332   }
333
334   //map.Insert( Toolkit::Visual::Property::DEPTH_INDEX, mImpl->mDepthIndex );
335   //map.Insert( Toolkit::Visual::Property::ENABLED, (bool) mImpl->mRenderer );
336 }
337
338
339 void Visual::Base::EnablePreMultipliedAlpha( bool preMultiplied )
340 {
341   if( preMultiplied )
342   {
343     mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
344   }
345   else
346   {
347     mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
348   }
349
350   if( mImpl->mRenderer )
351   {
352     mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultiplied);
353     mImpl->mRenderer.RegisterProperty( PRE_MULTIPLIED_ALPHA_PROPERTY, static_cast<float>( preMultiplied ) );
354   }
355 }
356
357 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
358 {
359   return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
360 }
361
362 void Visual::Base::DoSetOffStage( Actor& actor )
363 {
364   actor.RemoveRenderer( mImpl->mRenderer );
365   mImpl->mRenderer.Reset();
366 }
367
368 bool Visual::Base::IsOnStage() const
369 {
370   return mImpl->mFlags & Impl::IS_ON_STAGE;
371 }
372
373 void Visual::Base::OnDoAction( const Property::Index actionId, const Property::Value& attributes )
374 {
375   // May be overriden by derived class
376 }
377
378 void Visual::Base::RegisterMixColor()
379 {
380   // Only register if not already registered.
381   // (Color and Primitive visuals will register their own and save to this index)
382   if( mImpl->mMixColorIndex == Property::INVALID_INDEX )
383   {
384     mImpl->mMixColorIndex = DevelHandle::RegisterProperty(
385       mImpl->mRenderer,
386       Toolkit::Visual::Property::MIX_COLOR,
387       MIX_COLOR,
388       Vector3(mImpl->mMixColor) );
389   }
390
391   if( mImpl->mMixColor.a < 1.f )
392   {
393     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
394   }
395
396   mImpl->mRenderer.SetProperty( DevelRenderer::Property::OPACITY, mImpl->mMixColor.a );
397
398   float preMultipliedAlpha = 0.0f;
399   if( IsPreMultipliedAlphaEnabled() )
400   {
401     preMultipliedAlpha = 1.0f;
402   }
403   mImpl->mRenderer.RegisterProperty( PRE_MULTIPLIED_ALPHA_PROPERTY, preMultipliedAlpha );
404 }
405
406 void Visual::Base::SetMixColor( const Vector4& color )
407 {
408   mImpl->mMixColor = color;
409
410   if( mImpl->mRenderer )
411   {
412     mImpl->mRenderer.SetProperty( mImpl->mMixColorIndex, Vector3(color) );
413     mImpl->mRenderer.SetProperty( DevelRenderer::Property::OPACITY, color.a );
414     if( color.a < 1.f )
415     {
416       mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
417     }
418   }
419 }
420
421 void Visual::Base::SetMixColor( const Vector3& color )
422 {
423   mImpl->mMixColor.r = color.r;
424   mImpl->mMixColor.g = color.g;
425   mImpl->mMixColor.b = color.b;
426
427   if( mImpl->mRenderer )
428   {
429     mImpl->mRenderer.SetProperty( mImpl->mMixColorIndex, color );
430   }
431 }
432
433 const Vector4& Visual::Base::GetMixColor() const
434 {
435   return mImpl->mMixColor;
436 }
437
438 void Visual::Base::AddEventObserver( Visual::EventObserver& observer)
439 {
440   mImpl->mEventObserver = &observer;
441 }
442
443 void Visual::Base::RemoveEventObserver( Visual::EventObserver& observer )
444 {
445   mImpl->mEventObserver = NULL;
446 }
447
448 void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
449 {
450   if( mImpl->mResourceStatus != resourceStatus )
451   {
452     mImpl->mResourceStatus = resourceStatus;
453
454     if( mImpl->mEventObserver )
455     {
456       // observer is currently a control impl
457       mImpl->mEventObserver->ResourceReady( *this );
458     }
459   }
460 }
461
462 bool Visual::Base::IsResourceReady() const
463 {
464   return ( mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY );
465 }
466
467 Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
468 {
469   return mImpl->mResourceStatus;
470 }
471
472 Visual::FittingMode Visual::Base::GetFittingMode() const
473 {
474   return mImpl->mFittingMode;
475 }
476
477 Visual::Base& Visual::Base::GetVisualObject()
478 {
479   return *this;
480 }
481
482 Renderer Visual::Base::GetRenderer()
483 {
484   return mImpl->mRenderer;
485 }
486
487 Property::Index Visual::Base::GetPropertyIndex( Property::Key key )
488 {
489   Property::Index index = DevelHandle::GetPropertyIndex( mImpl->mRenderer, key );
490
491   if( index == Property::INVALID_INDEX )
492   {
493     // Is it a shader property?
494     Shader shader = mImpl->mRenderer.GetShader();
495     index = DevelHandle::GetPropertyIndex( shader, key );
496     if( index != Property::INVALID_INDEX )
497     {
498       // Yes - we should register it in the Renderer so it can be set / animated
499       // independently, as shaders are shared across multiple renderers.
500       std::string keyName;
501       Property::Index keyIndex( Property::INVALID_KEY );
502       if( key.type == Property::Key::INDEX )
503       {
504         keyName = shader.GetPropertyName( index );
505         keyIndex = key.indexKey;
506       }
507       else
508       {
509         keyName = key.stringKey;
510         // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
511       }
512       Property::Value value = shader.GetProperty( index );
513       index = DevelHandle::RegisterProperty( mImpl->mRenderer, keyIndex, keyName, value );
514     }
515   }
516   return index;
517 }
518
519 void Visual::Base::SetupTransition(
520   Dali::Animation& transition,
521   Internal::TransitionData::Animator& animator,
522   Property::Index index,
523   Property::Value& initialValue,
524   Property::Value& targetValue )
525 {
526   if( index != Property::INVALID_INDEX )
527   {
528     if( mImpl->mRenderer )
529     {
530       if( animator.animate == false )
531       {
532         mImpl->mRenderer.SetProperty( index, targetValue );
533       }
534       else
535       {
536         if( animator.initialValue.GetType() != Property::NONE )
537         {
538           mImpl->mRenderer.SetProperty( index, initialValue );
539         }
540
541         if( ! transition )
542         {
543           transition = Dali::Animation::New( 0.1f );
544         }
545
546         transition.AnimateTo( Property( mImpl->mRenderer, index ),
547                               targetValue,
548                               animator.alphaFunction,
549                               TimePeriod( animator.timePeriodDelay,
550                                           animator.timePeriodDuration ) );
551       }
552     }
553   }
554 }
555
556 void Visual::Base::AnimateProperty(
557   Dali::Animation& transition,
558   Internal::TransitionData::Animator& animator )
559 {
560 #if defined(DEBUG_ENABLED)
561   {
562     std::ostringstream oss;
563     oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
564     DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, oss.str().c_str() );
565   }
566 #endif
567
568   Property::Map map;
569   DoCreatePropertyMap( map );
570   Property::Value* valuePtr = map.Find( Toolkit::Visual::Property::TYPE );
571   int visualType = -1;
572   if( valuePtr )
573   {
574     valuePtr->Get( visualType );
575   }
576
577   if( animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
578       animator.propertyKey == MIX_COLOR ||
579       ( visualType == Toolkit::Visual::COLOR &&
580         animator.propertyKey == ColorVisual::Property::MIX_COLOR ) ||
581       ( visualType == Toolkit::Visual::PRIMITIVE &&
582         animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR ) )
583   {
584     AnimateMixColorProperty( transition, animator );
585   }
586   else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
587           animator.propertyKey == OPACITY )
588   {
589     AnimateOpacityProperty( transition, animator );
590   }
591   else if( mImpl->mRenderer )
592   {
593     AnimateRendererProperty( transition, animator );
594   }
595 }
596
597 void Visual::Base::AnimateOpacityProperty(
598   Dali::Animation& transition,
599   Internal::TransitionData::Animator& animator )
600 {
601   bool isOpaque = mImpl->mMixColor.a >= 1.0f;
602
603   float initialOpacity;
604   if( animator.initialValue.Get( initialOpacity ) )
605   {
606     isOpaque = (initialOpacity >= 1.0f);
607   }
608
609   float targetOpacity;
610   if( animator.targetValue.Get( targetOpacity ) )
611   {
612     mImpl->mMixColor.a = targetOpacity;
613   }
614
615   SetupTransition( transition, animator, DevelRenderer::Property::OPACITY, animator.initialValue, animator.targetValue );
616   SetupBlendMode( transition, isOpaque, animator.animate );
617 }
618
619 void Visual::Base::AnimateRendererProperty(
620   Dali::Animation& transition,
621   Internal::TransitionData::Animator& animator )
622 {
623   Property::Index index = GetPropertyIndex( animator.propertyKey );
624   if( index != Property::INVALID_INDEX )
625   {
626     if( animator.targetValue.GetType() != Property::NONE )
627     {
628       // Try writing target value into transform property map
629       // if it's not a valid key, then it won't alter mTransform
630       Property::Map map;
631       if( animator.propertyKey.type == Property::Key::INDEX )
632       {
633         map.Add( animator.propertyKey.indexKey, animator.targetValue );
634       }
635       else
636       {
637         map.Add( animator.propertyKey.stringKey, animator.targetValue );
638       }
639
640       mImpl->mTransform.UpdatePropertyMap( map );
641     }
642
643     SetupTransition( transition, animator, index, animator.initialValue, animator.targetValue );
644   }
645 }
646
647 void Visual::Base::AnimateMixColorProperty(
648   Dali::Animation& transition,
649   Internal::TransitionData::Animator& animator )
650 {
651   Property::Index index = mImpl->mMixColorIndex;
652   bool animateOpacity = false;
653   bool isOpaque = true;
654
655   Property::Value initialOpacity;
656   Property::Value targetOpacity;
657   Property::Value initialMixColor;
658   Property::Value targetMixColor;
659
660   if( index != Property::INVALID_INDEX )
661   {
662     Vector4 initialColor;
663     if( animator.initialValue.Get(initialColor) )
664     {
665       if( animator.initialValue.GetType() == Property::VECTOR4 )
666       {
667         // if there is an initial color specifying alpha, test it
668         isOpaque = initialColor.a >= 1.0f;
669         initialOpacity = initialColor.a;
670       }
671       initialMixColor = Vector3( initialColor );
672     }
673
674     // Set target value into data store
675     if( animator.targetValue.GetType() != Property::NONE )
676     {
677       Vector4 mixColor;
678       animator.targetValue.Get(mixColor);
679       if( animator.targetValue.GetType() == Property::VECTOR4 )
680       {
681         mImpl->mMixColor.a = mixColor.a;
682         targetOpacity = mixColor.a;
683         animateOpacity = true;
684       }
685
686       mImpl->mMixColor.r = mixColor.r;
687       mImpl->mMixColor.g = mixColor.g;
688       mImpl->mMixColor.b = mixColor.b;
689       targetMixColor = Vector3(mixColor);
690     }
691
692     SetupTransition( transition, animator, index, initialMixColor, targetMixColor );
693     if( animateOpacity )
694     {
695       SetupTransition( transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity );
696       SetupBlendMode( transition, isOpaque, animator.animate );
697     }
698   }
699 }
700
701 void Visual::Base::SetupBlendMode( Animation& transition, bool isInitialOpaque, bool animating )
702 {
703   // Ensure the blend mode is turned on if we are animating opacity, and
704   // turned off after the animation ends if the final value is opaque
705   if( ! isInitialOpaque || mImpl->mMixColor.a < 1.0f )
706   {
707     if( mImpl->mRenderer )
708     {
709       mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
710
711       if( animating == true && mImpl->mMixColor.a >= 1.0f )
712       {
713         // When it becomes opaque, set the blend mode back to automatically
714         if( ! mImpl->mBlendSlotDelegate )
715         {
716           mImpl->mBlendSlotDelegate = new SlotDelegate<Visual::Base>(this);
717         }
718         transition.FinishedSignal().Connect( *(mImpl->mBlendSlotDelegate),
719                                              &Visual::Base::OnMixColorFinished );
720       }
721     }
722   }
723 }
724
725 void Visual::Base::OnMixColorFinished( Animation& animation )
726 {
727   if( mImpl->mRenderer )
728   {
729     DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::OnMixColorFinished()\n");
730     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE,
731                                   ( mImpl->mMixColor.a < 1.0 ) ? BlendMode::ON : BlendMode::AUTO );
732   }
733   delete mImpl->mBlendSlotDelegate;
734   mImpl->mBlendSlotDelegate = NULL;
735 }
736
737 } // namespace Internal
738
739 } // namespace Toolkit
740
741 } // namespace Dali