8389fc0fb92da93445036c0c59c68e78ec519618
[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/integration-api/debug.h>
26
27 //INTERNAL HEARDER
28 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
29 #include <dali-toolkit/public-api/visuals/primitive-visual-properties.h>
30 #include <dali-toolkit/public-api/visuals/visual-properties.h>
31 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include <dali-toolkit/internal/helpers/property-helper.h>
33 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
34 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
35
36 namespace
37 {
38 #if defined(DEBUG_ENABLED)
39 Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VISUAL_BASE" );
40 #endif
41
42 const char * const PRE_MULTIPLIED_ALPHA_PROPERTY( "preMultipliedAlpha" );
43
44 } // namespace
45
46 namespace Dali
47 {
48
49 namespace Toolkit
50 {
51
52 namespace Internal
53 {
54
55 namespace
56 {
57
58 DALI_ENUM_TO_STRING_TABLE_BEGIN( VISUAL_FITTING_MODE )
59 DALI_ENUM_TO_STRING_WITH_SCOPE( Visual::FittingMode, FIT_KEEP_ASPECT_RATIO  )
60 DALI_ENUM_TO_STRING_WITH_SCOPE( Visual::FittingMode, FILL  )
61 DALI_ENUM_TO_STRING_TABLE_END( VISUAL_FITTING_MODE )
62
63 } // namespace
64
65 Visual::Base::Base( VisualFactoryCache& factoryCache, FittingMode fittingMode )
66 : mImpl( new Impl(fittingMode) ),
67   mFactoryCache( factoryCache )
68 {
69 }
70
71 Visual::Base::~Base()
72 {
73   delete mImpl;
74 }
75
76 void Visual::Base::SetCustomShader( const Property::Map& shaderMap )
77 {
78   if( mImpl->mCustomShader )
79   {
80     mImpl->mCustomShader->SetPropertyMap( shaderMap );
81   }
82   else
83   {
84     mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
85   }
86 }
87
88 void Visual::Base::SetProperties( const Property::Map& propertyMap )
89 {
90   for( size_t i = 0; i < propertyMap.Count(); ++i )
91   {
92     const KeyValuePair& pair = propertyMap.GetKeyValue( i );
93     const Property::Key& key = pair.first;
94     const Property::Value& value = pair.second;
95
96     Property::Key matchKey = key;
97     if( matchKey.type == Property::Key::STRING )
98     {
99       if( matchKey == CUSTOM_SHADER )
100       {
101         matchKey = Property::Key( Toolkit::Visual::Property::SHADER );
102       }
103       else if( matchKey == TRANSFORM )
104       {
105         matchKey = Property::Key( Toolkit::Visual::Property::TRANSFORM );
106       }
107       else if( matchKey == PREMULTIPLIED_ALPHA )
108       {
109         matchKey = Property::Key( Toolkit::Visual::Property::PREMULTIPLIED_ALPHA );
110       }
111       else if( matchKey == MIX_COLOR )
112       {
113         matchKey = Property::Key( Toolkit::Visual::Property::MIX_COLOR );
114       }
115       else if( matchKey == OPACITY )
116       {
117         matchKey = Property::Key( Toolkit::Visual::Property::OPACITY );
118       }
119       else if( matchKey == VISUAL_FITTING_MODE )
120       {
121         matchKey = Property::Key( Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE );
122       }
123     }
124
125     switch( matchKey.indexKey )
126     {
127       case Toolkit::Visual::Property::SHADER:
128       {
129         Property::Map shaderMap;
130         if( value.Get( shaderMap ) )
131         {
132           SetCustomShader( shaderMap );
133         }
134         break;
135       }
136
137       case Toolkit::Visual::Property::TRANSFORM:
138       {
139         Property::Map map;
140         if( value.Get( map ) )
141         {
142           mImpl->mTransform.SetPropertyMap( map );
143         }
144         break;
145       }
146
147       case Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
148       {
149         bool premultipliedAlpha = false;
150         if( value.Get( premultipliedAlpha ) )
151         {
152           EnablePreMultipliedAlpha( premultipliedAlpha );
153         }
154         break;
155       }
156
157       case Toolkit::Visual::Property::MIX_COLOR:
158       {
159         Vector4 mixColor;
160         if( value.Get( mixColor ) )
161         {
162           if( value.GetType() == Property::VECTOR4 )
163           {
164             SetMixColor( mixColor );
165           }
166           else
167           {
168             Vector3 mixColor3(mixColor);
169             SetMixColor( mixColor3 );
170           }
171         }
172         break;
173       }
174       case Toolkit::Visual::Property::OPACITY:
175       {
176         float opacity;
177         if( value.Get( opacity ) )
178         {
179           mImpl->mMixColor.a = opacity;
180           SetMixColor( mImpl->mMixColor );
181         }
182         break;
183       }
184       case Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE:
185       {
186         Scripting::GetEnumerationProperty< Visual::FittingMode >(
187           value, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode );
188         break;
189       }
190     }
191   }
192
193   DoSetProperties( propertyMap );
194 }
195
196 void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size controlSize )
197 {
198   mImpl->mControlSize = controlSize;
199   mImpl->mTransform.UpdatePropertyMap( transform );
200
201 #if defined(DEBUG_ENABLED)
202   std::ostringstream oss;
203   oss << transform;
204   DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::SetTransformAndSize(%s) - [\e[1;32mtransform: %s  controlSize: (%3.1f, %3.1f)]\e[0m\n",
205                  GetName().c_str(), oss.str().c_str(), controlSize.x, controlSize.y );
206 #endif
207
208   OnSetTransform();
209 }
210
211 void Visual::Base::SetName( const std::string& name )
212 {
213   mImpl->mName = name;
214 }
215
216 const std::string& Visual::Base::GetName()
217 {
218   return mImpl->mName;
219 }
220
221 float Visual::Base::GetHeightForWidth( float width )
222 {
223   float aspectCorrectedHeight = 0.f;
224   Vector2 naturalSize;
225   GetNaturalSize( naturalSize );
226   if( naturalSize.width )
227   {
228     aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
229   }
230   return aspectCorrectedHeight;
231 }
232
233 float Visual::Base::GetWidthForHeight( float height )
234 {
235   float aspectCorrectedWidth = 0.f;
236   Vector2 naturalSize;
237   GetNaturalSize( naturalSize );
238   if( naturalSize.height > 0.0f )
239   {
240     aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
241   }
242   return aspectCorrectedWidth;
243 }
244
245 void Visual::Base::GetNaturalSize( Vector2& naturalSize )
246 {
247   naturalSize = Vector2::ZERO;
248 }
249
250 void Visual::Base::DoAction( const Property::Index actionId, const Property::Value attributes )
251 {
252   OnDoAction( actionId, attributes );
253 }
254
255 void Visual::Base::SetDepthIndex( int index )
256 {
257   mImpl->mDepthIndex = index;
258   if( mImpl->mRenderer )
259   {
260     mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
261   }
262 }
263
264 int Visual::Base::GetDepthIndex() const
265 {
266   return mImpl->mDepthIndex;
267 }
268
269 void Visual::Base::SetOnStage( Actor& actor )
270 {
271   if( !IsOnStage() )
272   {
273     // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
274     // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
275     DoSetOnStage( actor );
276
277     if( mImpl->mRenderer )
278     {
279       RegisterMixColor();
280
281       mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
282       mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
283       mImpl->mFlags |= Impl::IS_ON_STAGE; // Only sets the flag if renderer exists
284     }
285   }
286 }
287
288 void Visual::Base::SetOffStage( Actor& actor )
289 {
290   if( IsOnStage() )
291   {
292     DoSetOffStage( actor );
293     mImpl->mMixColorIndex = Property::INVALID_INDEX;
294     mImpl->mOpacityIndex = 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   if( mImpl->mOpacityIndex == Property::INVALID_INDEX )
397   {
398     mImpl->mOpacityIndex = DevelHandle::RegisterProperty(
399       mImpl->mRenderer,
400       Toolkit::Visual::Property::OPACITY,
401       OPACITY,
402       mImpl->mMixColor.a );
403   }
404
405   float preMultipliedAlpha = 0.0f;
406   if( IsPreMultipliedAlphaEnabled() )
407   {
408     preMultipliedAlpha = 1.0f;
409   }
410   mImpl->mRenderer.RegisterProperty( PRE_MULTIPLIED_ALPHA_PROPERTY, preMultipliedAlpha );
411 }
412
413 void Visual::Base::SetMixColor( const Vector4& color )
414 {
415   mImpl->mMixColor = color;
416
417   if( mImpl->mRenderer )
418   {
419     mImpl->mRenderer.SetProperty( mImpl->mMixColorIndex, Vector3(color) );
420     mImpl->mRenderer.SetProperty( mImpl->mOpacityIndex, color.a );
421     if( color.a < 1.f )
422     {
423       mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
424     }
425   }
426 }
427
428 void Visual::Base::SetMixColor( const Vector3& color )
429 {
430   mImpl->mMixColor.r = color.r;
431   mImpl->mMixColor.g = color.g;
432   mImpl->mMixColor.b = color.b;
433
434   if( mImpl->mRenderer )
435   {
436     mImpl->mRenderer.SetProperty( mImpl->mMixColorIndex, color );
437   }
438 }
439
440 const Vector4& Visual::Base::GetMixColor() const
441 {
442   return mImpl->mMixColor;
443 }
444
445 void Visual::Base::AddResourceObserver( Visual::ResourceObserver& observer)
446 {
447   mImpl->mResourceObserver = &observer;
448 }
449
450 void Visual::Base::RemoveResourceObserver( Visual::ResourceObserver& observer )
451 {
452   mImpl->mResourceObserver = NULL;
453 }
454
455 void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
456 {
457   if( mImpl->mResourceStatus != resourceStatus )
458   {
459     mImpl->mResourceStatus = resourceStatus;
460
461     if( mImpl->mResourceObserver )
462     {
463       // observer is currently a control impl
464       mImpl->mResourceObserver->ResourceReady( *this );
465     }
466   }
467 }
468
469 bool Visual::Base::IsResourceReady() const
470 {
471   return ( mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY );
472 }
473
474 Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
475 {
476   return mImpl->mResourceStatus;
477 }
478
479 Visual::FittingMode Visual::Base::GetFittingMode() const
480 {
481   return mImpl->mFittingMode;
482 }
483
484 Renderer Visual::Base::GetRenderer()
485 {
486   return mImpl->mRenderer;
487 }
488
489 Property::Index Visual::Base::GetPropertyIndex( Property::Key key )
490 {
491   Property::Index index = DevelHandle::GetPropertyIndex( mImpl->mRenderer, key );
492
493   if( index == Property::INVALID_INDEX )
494   {
495     // Is it a shader property?
496     Shader shader = mImpl->mRenderer.GetShader();
497     index = DevelHandle::GetPropertyIndex( shader, key );
498     if( index != Property::INVALID_INDEX )
499     {
500       // Yes - we should register it in the Renderer so it can be set / animated
501       // independently, as shaders are shared across multiple renderers.
502       std::string keyName;
503       Property::Index keyIndex( Property::INVALID_KEY );
504       if( key.type == Property::Key::INDEX )
505       {
506         keyName = shader.GetPropertyName( index );
507         keyIndex = key.indexKey;
508       }
509       else
510       {
511         keyName = key.stringKey;
512         // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
513       }
514       Property::Value value = shader.GetProperty( index );
515       index = DevelHandle::RegisterProperty( mImpl->mRenderer, keyIndex, keyName, value );
516     }
517   }
518   return index;
519 }
520
521 void Visual::Base::SetupTransition(
522   Dali::Animation& transition,
523   Internal::TransitionData::Animator& animator,
524   Property::Index index,
525   Property::Value& initialValue,
526   Property::Value& targetValue )
527 {
528   if( index != Property::INVALID_INDEX )
529   {
530     if( mImpl->mRenderer )
531     {
532       if( animator.animate == false )
533       {
534         mImpl->mRenderer.SetProperty( index, targetValue );
535       }
536       else
537       {
538         if( animator.initialValue.GetType() != Property::NONE )
539         {
540           mImpl->mRenderer.SetProperty( index, initialValue );
541         }
542
543         if( ! transition )
544         {
545           transition = Dali::Animation::New( 0.1f );
546         }
547
548         transition.AnimateTo( Property( mImpl->mRenderer, index ),
549                               targetValue,
550                               animator.alphaFunction,
551                               TimePeriod( animator.timePeriodDelay,
552                                           animator.timePeriodDuration ) );
553       }
554     }
555   }
556 }
557
558 void Visual::Base::AnimateProperty(
559   Dali::Animation& transition,
560   Internal::TransitionData::Animator& animator )
561 {
562 #if defined(DEBUG_ENABLED)
563   {
564     std::ostringstream oss;
565     oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
566     DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, oss.str().c_str() );
567   }
568 #endif
569
570   Property::Map map;
571   DoCreatePropertyMap( map );
572   Property::Value* valuePtr = map.Find( Toolkit::Visual::Property::TYPE );
573   int visualType = -1;
574   if( valuePtr )
575   {
576     valuePtr->Get( visualType );
577   }
578
579   if( animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
580       animator.propertyKey == MIX_COLOR ||
581       ( visualType == Toolkit::Visual::COLOR &&
582         animator.propertyKey == ColorVisual::Property::MIX_COLOR ) ||
583       ( visualType == Toolkit::Visual::PRIMITIVE &&
584         animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR ) )
585   {
586     AnimateMixColorProperty( transition, animator );
587   }
588   else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
589           animator.propertyKey == OPACITY )
590   {
591     AnimateOpacityProperty( transition, animator );
592   }
593   else if( mImpl->mRenderer )
594   {
595     AnimateRendererProperty( transition, animator );
596   }
597 }
598
599 void Visual::Base::AnimateOpacityProperty(
600   Dali::Animation& transition,
601   Internal::TransitionData::Animator& animator )
602 {
603   Property::Index index = mImpl->mOpacityIndex;
604
605   bool isOpaque = mImpl->mMixColor.a >= 1.0f;
606
607   if( index != Property::INVALID_INDEX )
608   {
609     float initialOpacity;
610     if( animator.initialValue.Get( initialOpacity ) )
611     {
612       isOpaque = (initialOpacity >= 1.0f);
613     }
614
615     float targetOpacity;
616     if( animator.targetValue.Get( targetOpacity ) )
617     {
618       mImpl->mMixColor.a = targetOpacity;
619     }
620
621     SetupTransition( transition, animator, index, animator.initialValue, animator.targetValue );
622     SetupBlendMode( transition, isOpaque, animator.animate );
623   }
624 }
625
626 void Visual::Base::AnimateRendererProperty(
627   Dali::Animation& transition,
628   Internal::TransitionData::Animator& animator )
629 {
630   Property::Index index = GetPropertyIndex( animator.propertyKey );
631   if( index != Property::INVALID_INDEX )
632   {
633     if( animator.targetValue.GetType() != Property::NONE )
634     {
635       // Try writing target value into transform property map
636       // if it's not a valid key, then it won't alter mTransform
637       Property::Map map;
638       if( animator.propertyKey.type == Property::Key::INDEX )
639       {
640         map.Add( animator.propertyKey.indexKey, animator.targetValue );
641       }
642       else
643       {
644         map.Add( animator.propertyKey.stringKey, animator.targetValue );
645       }
646
647       mImpl->mTransform.UpdatePropertyMap( map );
648     }
649
650     SetupTransition( transition, animator, index, animator.initialValue, animator.targetValue );
651   }
652 }
653
654 void Visual::Base::AnimateMixColorProperty(
655   Dali::Animation& transition,
656   Internal::TransitionData::Animator& animator )
657 {
658   Property::Index index = mImpl->mMixColorIndex;
659   bool animateOpacity = false;
660   bool isOpaque = true;
661
662   Property::Value initialOpacity;
663   Property::Value targetOpacity;
664   Property::Value initialMixColor;
665   Property::Value targetMixColor;
666
667   if( index != Property::INVALID_INDEX )
668   {
669     Vector4 initialColor;
670     if( animator.initialValue.Get(initialColor) )
671     {
672       if( animator.initialValue.GetType() == Property::VECTOR4 )
673       {
674         // if there is an initial color specifying alpha, test it
675         isOpaque = initialColor.a >= 1.0f;
676         initialOpacity = initialColor.a;
677       }
678       initialMixColor = Vector3( initialColor );
679     }
680
681     // Set target value into data store
682     if( animator.targetValue.GetType() != Property::NONE )
683     {
684       Vector4 mixColor;
685       animator.targetValue.Get(mixColor);
686       if( animator.targetValue.GetType() == Property::VECTOR4 )
687       {
688         mImpl->mMixColor.a = mixColor.a;
689         targetOpacity = mixColor.a;
690         animateOpacity = true;
691       }
692
693       mImpl->mMixColor.r = mixColor.r;
694       mImpl->mMixColor.g = mixColor.g;
695       mImpl->mMixColor.b = mixColor.b;
696       targetMixColor = Vector3(mixColor);
697     }
698
699     SetupTransition( transition, animator, index, initialMixColor, targetMixColor );
700     if( animateOpacity )
701     {
702       SetupTransition( transition, animator, mImpl->mOpacityIndex, initialOpacity, targetOpacity );
703       SetupBlendMode( transition, isOpaque, animator.animate );
704     }
705   }
706 }
707
708 void Visual::Base::SetupBlendMode( Animation& transition, bool isInitialOpaque, bool animating )
709 {
710   // Ensure the blend mode is turned on if we are animating opacity, and
711   // turned off after the animation ends if the final value is opaque
712   if( ! isInitialOpaque || mImpl->mMixColor.a < 1.0f )
713   {
714     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
715
716     if( animating == true && mImpl->mMixColor.a >= 1.0f )
717     {
718       // When it becomes opaque, set the blend mode back to automatically
719       if( ! mImpl->mBlendSlotDelegate )
720       {
721         mImpl->mBlendSlotDelegate = new SlotDelegate<Visual::Base>(this);
722       }
723       transition.FinishedSignal().Connect( *(mImpl->mBlendSlotDelegate),
724                                            &Visual::Base::OnMixColorFinished );
725     }
726   }
727 }
728
729 void Visual::Base::OnMixColorFinished( Animation& animation )
730 {
731   if( mImpl->mRenderer )
732   {
733     DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::OnMixColorFinished()\n");
734     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE,
735                                   ( mImpl->mMixColor.a < 1.0 ) ? BlendMode::ON : BlendMode::AUTO );
736   }
737   delete mImpl->mBlendSlotDelegate;
738   mImpl->mBlendSlotDelegate = NULL;
739 }
740
741 } // namespace Internal
742
743 } // namespace Toolkit
744
745 } // namespace Dali