[dali_1.3.17] Merge branch 'devel/master'
[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/public-api/common/dali-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()
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::AddResourceObserver( Visual::ResourceObserver& observer)
439 {
440   mImpl->mResourceObserver = &observer;
441 }
442
443 void Visual::Base::RemoveResourceObserver( Visual::ResourceObserver& observer )
444 {
445   mImpl->mResourceObserver = 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->mResourceObserver )
455     {
456       // observer is currently a control impl
457       mImpl->mResourceObserver->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 Renderer Visual::Base::GetRenderer()
478 {
479   return mImpl->mRenderer;
480 }
481
482 Property::Index Visual::Base::GetPropertyIndex( Property::Key key )
483 {
484   Property::Index index = DevelHandle::GetPropertyIndex( mImpl->mRenderer, key );
485
486   if( index == Property::INVALID_INDEX )
487   {
488     // Is it a shader property?
489     Shader shader = mImpl->mRenderer.GetShader();
490     index = DevelHandle::GetPropertyIndex( shader, key );
491     if( index != Property::INVALID_INDEX )
492     {
493       // Yes - we should register it in the Renderer so it can be set / animated
494       // independently, as shaders are shared across multiple renderers.
495       std::string keyName;
496       Property::Index keyIndex( Property::INVALID_KEY );
497       if( key.type == Property::Key::INDEX )
498       {
499         keyName = shader.GetPropertyName( index );
500         keyIndex = key.indexKey;
501       }
502       else
503       {
504         keyName = key.stringKey;
505         // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
506       }
507       Property::Value value = shader.GetProperty( index );
508       index = DevelHandle::RegisterProperty( mImpl->mRenderer, keyIndex, keyName, value );
509     }
510   }
511   return index;
512 }
513
514 void Visual::Base::SetupTransition(
515   Dali::Animation& transition,
516   Internal::TransitionData::Animator& animator,
517   Property::Index index,
518   Property::Value& initialValue,
519   Property::Value& targetValue )
520 {
521   if( index != Property::INVALID_INDEX )
522   {
523     if( mImpl->mRenderer )
524     {
525       if( animator.animate == false )
526       {
527         mImpl->mRenderer.SetProperty( index, targetValue );
528       }
529       else
530       {
531         if( animator.initialValue.GetType() != Property::NONE )
532         {
533           mImpl->mRenderer.SetProperty( index, initialValue );
534         }
535
536         if( ! transition )
537         {
538           transition = Dali::Animation::New( 0.1f );
539         }
540
541         transition.AnimateTo( Property( mImpl->mRenderer, index ),
542                               targetValue,
543                               animator.alphaFunction,
544                               TimePeriod( animator.timePeriodDelay,
545                                           animator.timePeriodDuration ) );
546       }
547     }
548   }
549 }
550
551 void Visual::Base::AnimateProperty(
552   Dali::Animation& transition,
553   Internal::TransitionData::Animator& animator )
554 {
555 #if defined(DEBUG_ENABLED)
556   {
557     std::ostringstream oss;
558     oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
559     DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, oss.str().c_str() );
560   }
561 #endif
562
563   Property::Map map;
564   DoCreatePropertyMap( map );
565   Property::Value* valuePtr = map.Find( Toolkit::Visual::Property::TYPE );
566   int visualType = -1;
567   if( valuePtr )
568   {
569     valuePtr->Get( visualType );
570   }
571
572   if( animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
573       animator.propertyKey == MIX_COLOR ||
574       ( visualType == Toolkit::Visual::COLOR &&
575         animator.propertyKey == ColorVisual::Property::MIX_COLOR ) ||
576       ( visualType == Toolkit::Visual::PRIMITIVE &&
577         animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR ) )
578   {
579     AnimateMixColorProperty( transition, animator );
580   }
581   else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
582           animator.propertyKey == OPACITY )
583   {
584     AnimateOpacityProperty( transition, animator );
585   }
586   else if( mImpl->mRenderer )
587   {
588     AnimateRendererProperty( transition, animator );
589   }
590 }
591
592 void Visual::Base::AnimateOpacityProperty(
593   Dali::Animation& transition,
594   Internal::TransitionData::Animator& animator )
595 {
596   bool isOpaque = mImpl->mMixColor.a >= 1.0f;
597
598   float initialOpacity;
599   if( animator.initialValue.Get( initialOpacity ) )
600   {
601     isOpaque = (initialOpacity >= 1.0f);
602   }
603
604   float targetOpacity;
605   if( animator.targetValue.Get( targetOpacity ) )
606   {
607     mImpl->mMixColor.a = targetOpacity;
608   }
609
610   SetupTransition( transition, animator, DevelRenderer::Property::OPACITY, animator.initialValue, animator.targetValue );
611   SetupBlendMode( transition, isOpaque, animator.animate );
612 }
613
614 void Visual::Base::AnimateRendererProperty(
615   Dali::Animation& transition,
616   Internal::TransitionData::Animator& animator )
617 {
618   Property::Index index = GetPropertyIndex( animator.propertyKey );
619   if( index != Property::INVALID_INDEX )
620   {
621     if( animator.targetValue.GetType() != Property::NONE )
622     {
623       // Try writing target value into transform property map
624       // if it's not a valid key, then it won't alter mTransform
625       Property::Map map;
626       if( animator.propertyKey.type == Property::Key::INDEX )
627       {
628         map.Add( animator.propertyKey.indexKey, animator.targetValue );
629       }
630       else
631       {
632         map.Add( animator.propertyKey.stringKey, animator.targetValue );
633       }
634
635       mImpl->mTransform.UpdatePropertyMap( map );
636     }
637
638     SetupTransition( transition, animator, index, animator.initialValue, animator.targetValue );
639   }
640 }
641
642 void Visual::Base::AnimateMixColorProperty(
643   Dali::Animation& transition,
644   Internal::TransitionData::Animator& animator )
645 {
646   Property::Index index = mImpl->mMixColorIndex;
647   bool animateOpacity = false;
648   bool isOpaque = true;
649
650   Property::Value initialOpacity;
651   Property::Value targetOpacity;
652   Property::Value initialMixColor;
653   Property::Value targetMixColor;
654
655   if( index != Property::INVALID_INDEX )
656   {
657     Vector4 initialColor;
658     if( animator.initialValue.Get(initialColor) )
659     {
660       if( animator.initialValue.GetType() == Property::VECTOR4 )
661       {
662         // if there is an initial color specifying alpha, test it
663         isOpaque = initialColor.a >= 1.0f;
664         initialOpacity = initialColor.a;
665       }
666       initialMixColor = Vector3( initialColor );
667     }
668
669     // Set target value into data store
670     if( animator.targetValue.GetType() != Property::NONE )
671     {
672       Vector4 mixColor;
673       animator.targetValue.Get(mixColor);
674       if( animator.targetValue.GetType() == Property::VECTOR4 )
675       {
676         mImpl->mMixColor.a = mixColor.a;
677         targetOpacity = mixColor.a;
678         animateOpacity = true;
679       }
680
681       mImpl->mMixColor.r = mixColor.r;
682       mImpl->mMixColor.g = mixColor.g;
683       mImpl->mMixColor.b = mixColor.b;
684       targetMixColor = Vector3(mixColor);
685     }
686
687     SetupTransition( transition, animator, index, initialMixColor, targetMixColor );
688     if( animateOpacity )
689     {
690       SetupTransition( transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity );
691       SetupBlendMode( transition, isOpaque, animator.animate );
692     }
693   }
694 }
695
696 void Visual::Base::SetupBlendMode( Animation& transition, bool isInitialOpaque, bool animating )
697 {
698   // Ensure the blend mode is turned on if we are animating opacity, and
699   // turned off after the animation ends if the final value is opaque
700   if( ! isInitialOpaque || mImpl->mMixColor.a < 1.0f )
701   {
702     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
703
704     if( animating == true && mImpl->mMixColor.a >= 1.0f )
705     {
706       // When it becomes opaque, set the blend mode back to automatically
707       if( ! mImpl->mBlendSlotDelegate )
708       {
709         mImpl->mBlendSlotDelegate = new SlotDelegate<Visual::Base>(this);
710       }
711       transition.FinishedSignal().Connect( *(mImpl->mBlendSlotDelegate),
712                                            &Visual::Base::OnMixColorFinished );
713     }
714   }
715 }
716
717 void Visual::Base::OnMixColorFinished( Animation& animation )
718 {
719   if( mImpl->mRenderer )
720   {
721     DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::OnMixColorFinished()\n");
722     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE,
723                                   ( mImpl->mMixColor.a < 1.0 ) ? BlendMode::ON : BlendMode::AUTO );
724   }
725   delete mImpl->mBlendSlotDelegate;
726   mImpl->mBlendSlotDelegate = NULL;
727 }
728
729 } // namespace Internal
730
731 } // namespace Toolkit
732
733 } // namespace Dali