[Tizen] Add log if destroyed visual get some signal
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
1 /*
2  * Copyright (c) 2022 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/rendering/renderer-devel.h>
24 #include <dali/devel-api/scripting/enum-helper.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/rendering/decorated-visual-renderer.h>
27 #include <dali/public-api/rendering/visual-renderer.h>
28
29 //INTERNAL HEARDER
30 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.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 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
37 #include <dali-toolkit/public-api/visuals/primitive-visual-properties.h>
38 #include <dali-toolkit/public-api/visuals/visual-properties.h>
39
40 namespace
41 {
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VISUAL_BASE");
44 #endif
45
46 // visual string constants contains OFFSET_SIZE_MODE instead
47 const char* const OFFSET_POLICY("offsetPolicy");
48 const char* const SIZE_POLICY("sizePolicy");
49
50 } // namespace
51
52 namespace Dali
53 {
54 namespace Toolkit
55 {
56 namespace Internal
57 {
58 namespace
59 {
60 DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_FITTING_MODE)
61   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_KEEP_ASPECT_RATIO)
62   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FILL)
63   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, OVER_FIT_KEEP_ASPECT_RATIO)
64   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, CENTER)
65   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_WIDTH)
66   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_HEIGHT)
67 DALI_ENUM_TO_STRING_TABLE_END(VISUAL_FITTING_MODE)
68
69 /**
70  * @brief Check whether this visual type can use corner radius feature or not.
71  * @param type VisualType that want to checkup
72  * @return true if type can use corner radius feature.
73  */
74 static bool IsTypeAvailableForCornerRadius(Toolkit::Visual::Type type)
75 {
76   switch(static_cast<Toolkit::DevelVisual::Type>(type))
77   {
78     case Toolkit::Visual::Type::COLOR:
79     case Toolkit::Visual::Type::GRADIENT:
80     case Toolkit::Visual::Type::IMAGE:
81     case Toolkit::Visual::Type::SVG:
82     case Toolkit::Visual::Type::ANIMATED_IMAGE:
83     case Toolkit::DevelVisual::Type::ANIMATED_VECTOR_IMAGE:
84     {
85       return true;
86     }
87     default:
88     {
89       return false;
90     }
91   }
92 }
93
94 /**
95  * @brief Check whether this visual type can use borderline feature or not.
96  * @param type VisualType that want to checkup
97  * @return true if type can use borderline feature.
98  */
99 static bool IsTypeAvailableForBorderline(Toolkit::Visual::Type type)
100 {
101   switch(static_cast<Toolkit::DevelVisual::Type>(type))
102   {
103     case Toolkit::Visual::Type::COLOR:
104     case Toolkit::Visual::Type::GRADIENT:
105     case Toolkit::Visual::Type::IMAGE:
106     case Toolkit::Visual::Type::SVG:
107     case Toolkit::Visual::Type::ANIMATED_IMAGE:
108     case Toolkit::DevelVisual::Type::ANIMATED_VECTOR_IMAGE:
109     {
110       return true;
111     }
112     default:
113     {
114       return false;
115     }
116   }
117 }
118
119 } // namespace
120
121 Visual::Base::Base(VisualFactoryCache& factoryCache, FittingMode fittingMode, Toolkit::Visual::Type type)
122 : mImpl(new Impl(fittingMode, type)),
123   mFactoryCache(factoryCache)
124 {
125 }
126
127 Visual::Base::~Base()
128 {
129   delete mImpl;
130   mImpl = nullptr;
131 }
132
133 void Visual::Base::Initialize()
134 {
135   // The Renderer should be created inside derived class here.
136   OnInitialize();
137
138   if(mImpl->mRenderer)
139   {
140     RegisterMixColor();
141     RegisterDecoration();
142
143     if(IsBorderlineRequired())
144     {
145       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
146     }
147     else if(IsRoundedCornerRequired())
148     {
149       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
150     }
151   }
152 }
153
154 void Visual::Base::SetCustomShader(const Property::Map& shaderMap)
155 {
156   if(mImpl->mCustomShader)
157   {
158     mImpl->mCustomShader->SetPropertyMap(shaderMap);
159   }
160   else
161   {
162     mImpl->mCustomShader = new Impl::CustomShader(shaderMap);
163   }
164
165   // Let derived class know
166   UpdateShader();
167 }
168
169 void Visual::Base::SetProperties(const Property::Map& propertyMap)
170 {
171   bool needUpdateShader = false;
172   for(size_t i = 0; i < propertyMap.Count(); ++i)
173   {
174     const KeyValuePair&    pair  = propertyMap.GetKeyValue(i);
175     const Property::Key&   key   = pair.first;
176     const Property::Value& value = pair.second;
177
178     Property::Key matchKey = key;
179     if(matchKey.type == Property::Key::STRING)
180     {
181       if(matchKey == CUSTOM_SHADER)
182       {
183         matchKey = Property::Key(Toolkit::Visual::Property::SHADER);
184       }
185       else if(matchKey == TRANSFORM)
186       {
187         matchKey = Property::Key(Toolkit::Visual::Property::TRANSFORM);
188       }
189       else if(matchKey == PREMULTIPLIED_ALPHA)
190       {
191         matchKey = Property::Key(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA);
192       }
193       else if(matchKey == MIX_COLOR)
194       {
195         matchKey = Property::Key(Toolkit::Visual::Property::MIX_COLOR);
196       }
197       else if(matchKey == OPACITY)
198       {
199         matchKey = Property::Key(Toolkit::Visual::Property::OPACITY);
200       }
201       else if(matchKey == VISUAL_FITTING_MODE)
202       {
203         matchKey = Property::Key(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE);
204       }
205       else if(matchKey == BORDERLINE_WIDTH)
206       {
207         matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH);
208       }
209       else if(matchKey == BORDERLINE_COLOR)
210       {
211         matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_COLOR);
212       }
213       else if(matchKey == BORDERLINE_OFFSET)
214       {
215         matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET);
216       }
217       else if(matchKey == CORNER_RADIUS)
218       {
219         matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS);
220       }
221       else if(matchKey == CORNER_RADIUS_POLICY)
222       {
223         matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY);
224       }
225     }
226
227     switch(matchKey.indexKey)
228     {
229       case Toolkit::Visual::Property::SHADER:
230       {
231         Property::Map shaderMap;
232         if(value.Get(shaderMap))
233         {
234           SetCustomShader(shaderMap);
235         }
236         break;
237       }
238
239       case Toolkit::Visual::Property::TRANSFORM:
240       {
241         Property::Map map;
242         if(value.Get(map))
243         {
244           mImpl->mTransform.SetPropertyMap(map);
245         }
246         break;
247       }
248
249       case Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
250       {
251         bool premultipliedAlpha = false;
252         if(value.Get(premultipliedAlpha))
253         {
254           EnablePreMultipliedAlpha(premultipliedAlpha);
255         }
256         break;
257       }
258
259       case Toolkit::Visual::Property::MIX_COLOR:
260       {
261         Vector4 mixColor;
262         if(value.Get(mixColor))
263         {
264           if(value.GetType() == Property::VECTOR4)
265           {
266             SetMixColor(mixColor);
267           }
268           else
269           {
270             Vector3 mixColor3(mixColor);
271             SetMixColor(mixColor3);
272           }
273         }
274         break;
275       }
276       case Toolkit::Visual::Property::OPACITY:
277       {
278         float opacity;
279         if(value.Get(opacity))
280         {
281           mImpl->mMixColor.a = opacity;
282           SetMixColor(mImpl->mMixColor);
283         }
284         break;
285       }
286       case Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE:
287       {
288         Scripting::GetEnumerationProperty<Visual::FittingMode>(
289           value, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode);
290         break;
291       }
292       case Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
293       {
294         float width;
295         if(value.Get(width))
296         {
297           if(mImpl->mDecorationData != nullptr || !Dali::EqualsZero(width))
298           {
299             mImpl->SetBorderlineWidth(width);
300           }
301         }
302
303         if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForBorderline(mImpl->mType)))
304         {
305           // Unusual case. SetProperty called after OnInitialize().
306           // Assume that DoAction call UPDATE_PROPERTY.
307           DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterBorderlineUniform();
308           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->GetBorderlineWidth());
309
310           // Check whether we must update shader.
311           if(!mImpl->mAlwaysUsingBorderline && IsBorderlineRequired())
312           {
313             // Required to change shader mean, we didn't setup BORDERLINE_COLOR and BORDERLINE_OFFSET into mRenderer before. Set property now.
314             mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->GetBorderlineColor());
315             mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->GetBorderlineOffset());
316
317             // Make Blend mode ON_WITHOUT_CULL for transparent mix color.
318             mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
319
320             // Change the shader must not be occured many times. we always have to use borderline feature.
321             mImpl->mAlwaysUsingBorderline = true;
322
323             // Change shader
324             if(!mImpl->mCustomShader)
325             {
326               needUpdateShader = true;
327             }
328           }
329         }
330         break;
331       }
332       case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
333       {
334         Vector4 color;
335         if(value.Get(color))
336         {
337           if(mImpl->mDecorationData != nullptr || color != Vector4::ZERO)
338           {
339             mImpl->SetBorderlineColor(color);
340           }
341         }
342
343         if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForBorderline(mImpl->mType)))
344         {
345           // Unusual case. SetProperty called after OnInitialize().
346           // Assume that DoAction call UPDATE_PROPERTY.
347           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->GetBorderlineColor());
348         }
349         break;
350       }
351       case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
352       {
353         float offset;
354         if(value.Get(offset))
355         {
356           if(mImpl->mDecorationData != nullptr || !Dali::EqualsZero(offset))
357           {
358             mImpl->SetBorderlineOffset(offset);
359           }
360         }
361
362         if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForBorderline(mImpl->mType)))
363         {
364           // Unusual case. SetProperty called after OnInitialize().
365           // Assume that DoAction call UPDATE_PROPERTY.
366           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->GetBorderlineOffset());
367         }
368         break;
369       }
370       case Toolkit::DevelVisual::Property::CORNER_RADIUS:
371       {
372         if(value.GetType() == Property::VECTOR4)
373         {
374           // If CORNER_RADIUS Property is Vector4,
375           // Each values mean the radius of
376           // (top-left, top-right, bottom-right, bottom-left)
377           Vector4 radius;
378           if(value.Get(radius))
379           {
380             if(mImpl->mDecorationData != nullptr || radius != Vector4::ZERO)
381             {
382               mImpl->SetCornerRadius(radius);
383             }
384           }
385         }
386         else
387         {
388           // If CORNER_RADIUS Property is float,
389           // Every corner radius have same value
390           float radius;
391           if(value.Get(radius))
392           {
393             if(mImpl->mDecorationData != nullptr || !Dali::EqualsZero(radius))
394             {
395               mImpl->SetCornerRadius(Vector4(radius, radius, radius, radius));
396             }
397           }
398         }
399
400         if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForCornerRadius(mImpl->mType)))
401         {
402           // Unusual case. SetProperty called after OnInitialize().
403           // Assume that DoAction call UPDATE_PROPERTY.
404           DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterCornerRadiusUniform();
405           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->GetCornerRadius());
406
407           // Check whether we must update shader.
408           if(!mImpl->mAlwaysUsingCornerRadius && IsRoundedCornerRequired())
409           {
410             // Required to change shader mean, we didn't setup CORNER_RADIUS_POLICY into mRenderer before. Set property now.
411             mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, static_cast<float>(mImpl->GetCornerRadiusPolicy()));
412
413             // Change the shader must not be occured many times. we always have to use corner radius feature.
414             mImpl->mAlwaysUsingCornerRadius = true;
415
416             if(!IsBorderlineRequired())
417             {
418               // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
419               mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
420             }
421
422             // Change shader
423             if(!mImpl->mCustomShader)
424             {
425               needUpdateShader = true;
426             }
427           }
428         }
429
430         break;
431       }
432       case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY:
433       {
434         int policy;
435         if(value.Get(policy))
436         {
437           switch(policy)
438           {
439             case Toolkit::Visual::Transform::Policy::RELATIVE:
440             case Toolkit::Visual::Transform::Policy::ABSOLUTE:
441             {
442               mImpl->SetCornerRadiusPolicy(policy);
443               if(DALI_UNLIKELY(mImpl->mRenderer))
444               {
445                 // Unusual case. SetProperty called after OnInitialize().
446                 // Assume that DoAction call UPDATE_PROPERTY.
447                 mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, static_cast<float>(mImpl->GetCornerRadiusPolicy()));
448               }
449               break;
450             }
451             default:
452             {
453               DALI_LOG_ERROR("Unsupported policy: %d\n", policy);
454               break;
455             }
456           }
457         }
458         break;
459       }
460     }
461   }
462
463   DoSetProperties(propertyMap);
464
465   if(DALI_UNLIKELY(needUpdateShader))
466   {
467     UpdateShader();
468   }
469 }
470
471 void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size controlSize)
472 {
473   mImpl->mControlSize = controlSize;
474   mImpl->mTransform.UpdatePropertyMap(transform);
475
476 #if defined(DEBUG_ENABLED)
477   std::ostringstream oss;
478   oss << transform;
479   DALI_LOG_INFO(gVisualBaseLogFilter, Debug::General, "Visual::Base::SetTransformAndSize(%s) - [\e[1;32mtransform: %s  controlSize: (%3.1f, %3.1f)]\e[0m\n", GetName().c_str(), oss.str().c_str(), controlSize.x, controlSize.y);
480 #endif
481
482   OnSetTransform();
483 }
484
485 void Visual::Base::SetName(const std::string& name)
486 {
487   mImpl->mName = name;
488 }
489
490 const std::string& Visual::Base::GetName() const
491 {
492   return mImpl->mName;
493 }
494
495 float Visual::Base::GetHeightForWidth(float width)
496 {
497   float   aspectCorrectedHeight = 0.f;
498   Vector2 naturalSize;
499   GetNaturalSize(naturalSize);
500   if(naturalSize.width > 0.0f)
501   {
502     aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
503   }
504   return aspectCorrectedHeight;
505 }
506
507 float Visual::Base::GetWidthForHeight(float height)
508 {
509   float   aspectCorrectedWidth = 0.f;
510   Vector2 naturalSize;
511   GetNaturalSize(naturalSize);
512   if(naturalSize.height > 0.0f)
513   {
514     aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
515   }
516   return aspectCorrectedWidth;
517 }
518
519 void Visual::Base::GetNaturalSize(Vector2& naturalSize)
520 {
521   naturalSize = Vector2::ZERO;
522 }
523
524 void Visual::Base::DoAction(const Property::Index actionId, const Property::Value attributes)
525 {
526   OnDoAction(actionId, attributes);
527
528   // Check if action is valid for this visual type and perform action if possible
529   switch(actionId)
530   {
531     case DevelVisual::Action::UPDATE_PROPERTY:
532     {
533       const Property::Map* map = attributes.GetMap();
534       if(map)
535       {
536         SetProperties(*map);
537       }
538       break;
539     }
540   }
541 }
542
543 void Visual::Base::DoActionExtension(const Dali::Property::Index actionId, const Dali::Any attributes)
544 {
545   OnDoActionExtension(actionId, attributes);
546 }
547
548 void Visual::Base::SetDepthIndex(int index)
549 {
550   mImpl->mDepthIndex = index;
551   if(mImpl->mRenderer)
552   {
553     mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
554   }
555 }
556
557 int Visual::Base::GetDepthIndex() const
558 {
559   return mImpl->mDepthIndex;
560 }
561
562 void Visual::Base::SetOnScene(Actor& actor)
563 {
564   if(!IsOnScene())
565   {
566     // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
567     // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
568     DoSetOnScene(actor);
569
570     if(mImpl->mRenderer)
571     {
572       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
573       mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
574     }
575
576     mImpl->mFlags |= Impl::IS_ON_SCENE;
577   }
578 }
579
580 void Visual::Base::SetOffScene(Actor& actor)
581 {
582   if(IsOnScene())
583   {
584     DoSetOffScene(actor);
585     mImpl->mFlags &= ~Impl::IS_ON_SCENE;
586   }
587 }
588
589 void Visual::Base::CreatePropertyMap(Property::Map& map) const
590 {
591   if(mImpl->mRenderer)
592   {
593     // Update values from Renderer
594     mImpl->mMixColor   = mImpl->mRenderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR);
595     mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
596
597     mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
598     mImpl->mTransform.mSize   = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
599
600     if(IsRoundedCornerRequired())
601     {
602       mImpl->SetCornerRadius(mImpl->mRenderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS));
603     }
604     if(IsBorderlineRequired())
605     {
606       mImpl->SetBorderlineWidth(mImpl->mRenderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH));
607       mImpl->SetBorderlineColor(mImpl->mRenderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR));
608       mImpl->SetBorderlineOffset(mImpl->mRenderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET));
609     }
610   }
611
612   DoCreatePropertyMap(map);
613
614   if(mImpl->mCustomShader)
615   {
616     mImpl->mCustomShader->CreatePropertyMap(map);
617   }
618
619   Property::Map transform;
620   mImpl->mTransform.GetPropertyMap(transform);
621   map.Insert(Toolkit::Visual::Property::TRANSFORM, transform);
622
623   bool premultipliedAlpha(IsPreMultipliedAlphaEnabled());
624   map.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha);
625
626   // Note, Color and Primitive will also insert their own mix color into the map
627   // which is ok, because they have a different key value range, but uses same cached value anyway.
628   map.Insert(Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor); // vec4
629   map.Insert(Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a);
630
631   auto fittingModeString = Scripting::GetLinearEnumerationName<FittingMode>(
632     mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT);
633   map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString);
634
635   if(IsTypeAvailableForBorderline(mImpl->mType))
636   {
637     map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->GetBorderlineWidth());
638     map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->GetBorderlineColor());
639     map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->GetBorderlineOffset());
640   }
641
642   if(IsTypeAvailableForCornerRadius(mImpl->mType))
643   {
644     map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->GetCornerRadius());
645     map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, mImpl->GetCornerRadiusPolicy());
646   }
647 }
648
649 void Visual::Base::CreateInstancePropertyMap(Property::Map& map) const
650 {
651   DoCreateInstancePropertyMap(map);
652
653   if(mImpl->mCustomShader)
654   {
655     mImpl->mCustomShader->CreatePropertyMap(map);
656   }
657 }
658
659 void Visual::Base::EnablePreMultipliedAlpha(bool preMultiplied)
660 {
661   if(preMultiplied)
662   {
663     mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
664   }
665   else
666   {
667     mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
668   }
669
670   if(mImpl->mRenderer)
671   {
672     mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultiplied);
673     mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA, preMultiplied);
674   }
675 }
676
677 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
678 {
679   return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
680 }
681
682 void Visual::Base::DoSetOffScene(Actor& actor)
683 {
684   actor.RemoveRenderer(mImpl->mRenderer);
685 }
686
687 bool Visual::Base::IsOnScene() const
688 {
689   return mImpl->mFlags & Impl::IS_ON_SCENE;
690 }
691
692 bool Visual::Base::IsRoundedCornerRequired() const
693 {
694   // If VisualType doesn't support rounded corner, always return false.
695   if(IsTypeAvailableForCornerRadius(mImpl->mType))
696   {
697     if(mImpl->mRenderer)
698     {
699       // Update values from Renderer
700       Property::Value value = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS);
701
702       Vector4 retValue = Vector4::ZERO;
703       if(value.Get(retValue))
704       {
705         if(mImpl->mDecorationData != nullptr || retValue != Vector4::ZERO)
706         {
707           mImpl->SetCornerRadius(retValue);
708         }
709       }
710     }
711     return mImpl->mAlwaysUsingCornerRadius || !(mImpl->GetCornerRadius() == Vector4::ZERO);
712   }
713   return false;
714 }
715
716 bool Visual::Base::IsBorderlineRequired() const
717 {
718   // If VisualType doesn't support borderline, always return false.
719   if(IsTypeAvailableForBorderline(mImpl->mType))
720   {
721     if(mImpl->mRenderer)
722     {
723       // Update values from Renderer
724       Property::Value value = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH);
725
726       float retValue = 0.0f;
727       if(value.Get(retValue))
728       {
729         if(mImpl->mDecorationData != nullptr || !Dali::EqualsZero(retValue))
730         {
731           mImpl->SetBorderlineWidth(retValue);
732         }
733       }
734     }
735     return mImpl->mAlwaysUsingBorderline || !EqualsZero(mImpl->GetBorderlineWidth());
736   }
737   return false;
738 }
739
740 void Visual::Base::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
741 {
742   // May be overriden by derived class
743 }
744
745 void Visual::Base::OnDoActionExtension(const Property::Index actionId, const Dali::Any attributes)
746 {
747   // May be overriden by derived class
748 }
749
750 void Visual::Base::RegisterMixColor()
751 {
752   if(mImpl->mRenderer)
753   {
754     // All visual renderers now use same mix color / opacity properties.
755     mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, Vector3(mImpl->mMixColor));
756     mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, mImpl->mMixColor.a);
757
758     float preMultipliedAlpha = 0.0f;
759     if(IsPreMultipliedAlphaEnabled())
760     {
761       preMultipliedAlpha = 1.0f;
762     }
763     mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA, preMultipliedAlpha);
764   }
765 }
766
767 void Visual::Base::RegisterDecoration()
768 {
769   if(mImpl->mRenderer)
770   {
771     if(IsTypeAvailableForCornerRadius(mImpl->mType))
772     {
773       if(mImpl->mAlwaysUsingCornerRadius || !(mImpl->GetCornerRadius() == Vector4::ZERO))
774       {
775         DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterCornerRadiusUniform();
776         mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->GetCornerRadius());
777         mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, static_cast<float>(mImpl->GetCornerRadiusPolicy()));
778       }
779     }
780     if(IsTypeAvailableForBorderline(mImpl->mType))
781     {
782       if(mImpl->mAlwaysUsingBorderline || !EqualsZero(mImpl->GetBorderlineWidth()))
783       {
784         DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterBorderlineUniform();
785         mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->GetBorderlineWidth());
786         mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->GetBorderlineColor());
787         mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->GetBorderlineOffset());
788       }
789     }
790   }
791 }
792
793 void Visual::Base::SetMixColor(const Vector4& color)
794 {
795   mImpl->mMixColor = color;
796
797   if(mImpl->mRenderer)
798   {
799     mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, Vector3(color));
800     mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, color.a);
801   }
802 }
803
804 void Visual::Base::SetMixColor(const Vector3& color)
805 {
806   mImpl->mMixColor.r = color.r;
807   mImpl->mMixColor.g = color.g;
808   mImpl->mMixColor.b = color.b;
809
810   if(mImpl->mRenderer)
811   {
812     mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, color);
813   }
814 }
815
816 void Visual::Base::AddEventObserver(Visual::EventObserver& observer)
817 {
818   mImpl->mEventObserver = &observer;
819 }
820
821 void Visual::Base::RemoveEventObserver(Visual::EventObserver& observer)
822 {
823   mImpl->mEventObserver = NULL;
824 }
825
826 void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
827 {
828   if(mImpl->mResourceStatus != resourceStatus)
829   {
830     mImpl->mResourceStatus = resourceStatus;
831
832     if(mImpl->mEventObserver)
833     {
834       // observer is currently a control impl
835       mImpl->mEventObserver->ResourceReady(*this);
836     }
837   }
838 }
839
840 bool Visual::Base::IsResourceReady() const
841 {
842   return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY ||
843           mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED);
844 }
845
846 bool Visual::Base::IsSynchronousLoadingRequired() const
847 {
848   return (mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING);
849 }
850
851 Toolkit::Visual::Type Visual::Base::GetType() const
852 {
853   return mImpl->mType;
854 }
855
856 Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
857 {
858   return mImpl->mResourceStatus;
859 }
860
861 Visual::FittingMode Visual::Base::GetFittingMode() const
862 {
863   return mImpl->mFittingMode;
864 }
865
866 Visual::Base& Visual::Base::GetVisualObject()
867 {
868   return *this;
869 }
870
871 Renderer Visual::Base::GetRenderer()
872 {
873   return mImpl->mRenderer;
874 }
875
876 Property::Index Visual::Base::GetIntKey(Property::Key key)
877 {
878   if(key.type == Property::Key::INDEX)
879   {
880     return key.indexKey;
881   }
882
883   if(key.stringKey == ANCHOR_POINT)
884   {
885     return Toolkit::Visual::Transform::Property::ANCHOR_POINT;
886   }
887   else if(key.stringKey == EXTRA_SIZE)
888   {
889     return Toolkit::DevelVisual::Transform::Property::EXTRA_SIZE;
890   }
891   else if(key.stringKey == MIX_COLOR)
892   {
893     return Toolkit::Visual::Property::MIX_COLOR;
894   }
895   else if(key.stringKey == OPACITY)
896   {
897     return Toolkit::Visual::Property::OPACITY;
898   }
899   else if(key.stringKey == OFFSET)
900   {
901     return Toolkit::Visual::Transform::Property::OFFSET;
902   }
903   else if(key.stringKey == OFFSET_POLICY)
904   {
905     return Toolkit::Visual::Transform::Property::OFFSET_POLICY;
906   }
907   else if(key.stringKey == ORIGIN)
908   {
909     return Toolkit::Visual::Transform::Property::ORIGIN;
910   }
911   else if(key.stringKey == PREMULTIPLIED_ALPHA)
912   {
913     return Toolkit::Visual::Property::PREMULTIPLIED_ALPHA;
914   }
915   else if(key.stringKey == CUSTOM_SHADER)
916   {
917     return Toolkit::Visual::Property::SHADER;
918   }
919   else if(key.stringKey == SIZE)
920   {
921     return Toolkit::Visual::Transform::Property::SIZE;
922   }
923   else if(key.stringKey == SIZE_POLICY)
924   {
925     return Toolkit::Visual::Transform::Property::SIZE_POLICY;
926   }
927   else if(key.stringKey == TRANSFORM)
928   {
929     return Toolkit::Visual::Property::TRANSFORM;
930   }
931   else if(key.stringKey == VISUAL_FITTING_MODE)
932   {
933     return Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE;
934   }
935   else if(key.stringKey == CORNER_RADIUS)
936   {
937     return Toolkit::DevelVisual::Property::CORNER_RADIUS;
938   }
939   else if(key.stringKey == CORNER_RADIUS_POLICY)
940   {
941     return Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY;
942   }
943   else if(key.stringKey == BORDERLINE_WIDTH)
944   {
945     return Toolkit::DevelVisual::Property::BORDERLINE_WIDTH;
946   }
947   else if(key.stringKey == BORDERLINE_COLOR)
948   {
949     return Toolkit::DevelVisual::Property::BORDERLINE_COLOR;
950   }
951   else if(key.stringKey == BORDERLINE_OFFSET)
952   {
953     return Toolkit::DevelVisual::Property::BORDERLINE_OFFSET;
954   }
955
956   return Property::INVALID_INDEX;
957 }
958
959 Property::Index Visual::Base::GetPropertyIndex(Property::Key key)
960 {
961   switch(GetIntKey(key))
962   {
963     case Dali::Toolkit::Visual::Transform::Property::OFFSET:
964     {
965       return VisualRenderer::Property::TRANSFORM_OFFSET;
966     }
967     case Dali::Toolkit::Visual::Transform::Property::SIZE:
968     {
969       return VisualRenderer::Property::TRANSFORM_SIZE;
970     }
971     case Dali::Toolkit::Visual::Transform::Property::ORIGIN:
972     {
973       return VisualRenderer::Property::TRANSFORM_ORIGIN;
974     }
975     case Dali::Toolkit::Visual::Transform::Property::ANCHOR_POINT:
976     {
977       return VisualRenderer::Property::TRANSFORM_ANCHOR_POINT;
978     }
979     case Dali::Toolkit::Visual::Property::MIX_COLOR:
980     {
981       return VisualRenderer::Property::VISUAL_MIX_COLOR;
982     }
983     case Dali::Toolkit::Visual::Property::OPACITY:
984     {
985       return DevelRenderer::Property::OPACITY;
986     }
987     case Dali::Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
988     {
989       return VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA;
990     }
991     case Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS:
992     {
993       return DecoratedVisualRenderer::Property::CORNER_RADIUS;
994     }
995     case Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
996     {
997       return DecoratedVisualRenderer::Property::BORDERLINE_WIDTH;
998     }
999     case Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
1000     {
1001       return DecoratedVisualRenderer::Property::BORDERLINE_COLOR;
1002     }
1003     case Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
1004     {
1005       return DecoratedVisualRenderer::Property::BORDERLINE_OFFSET;
1006     }
1007   }
1008
1009   Property::Index index = mImpl->mRenderer.GetPropertyIndex(key);
1010
1011   if(index == Property::INVALID_INDEX)
1012   {
1013     // Is it a shader property?
1014     Shader shader = mImpl->mRenderer.GetShader();
1015     index         = shader.GetPropertyIndex(key);
1016     if(index != Property::INVALID_INDEX)
1017     {
1018       // Yes - we should register it in the Renderer so it can be set / animated
1019       // independently, as shaders are shared across multiple renderers.
1020       std::string     keyName;
1021       Property::Index keyIndex(Property::INVALID_KEY);
1022       if(key.type == Property::Key::INDEX)
1023       {
1024         keyName  = shader.GetPropertyName(index);
1025         keyIndex = key.indexKey;
1026       }
1027       else
1028       {
1029         keyName = key.stringKey;
1030         // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
1031       }
1032       Property::Value value = shader.GetProperty(index);
1033
1034       // We already know that mRenderer didn't have property. So we can assume that it is unique.
1035       index = mImpl->mRenderer.RegisterUniqueProperty(keyIndex, keyName, value);
1036     }
1037   }
1038   return index;
1039 }
1040
1041 void Visual::Base::SetupTransition(
1042   Dali::Animation&                    transition,
1043   Internal::TransitionData::Animator& animator,
1044   Property::Index                     index,
1045   Property::Value&                    initialValue,
1046   Property::Value&                    targetValue)
1047 {
1048   if(index != Property::INVALID_INDEX)
1049   {
1050     if(mImpl->mRenderer)
1051     {
1052       if(animator.animate == false)
1053       {
1054         mImpl->mRenderer.SetProperty(index, targetValue);
1055       }
1056       else
1057       {
1058         if(animator.initialValue.GetType() != Property::NONE)
1059         {
1060           mImpl->mRenderer.SetProperty(index, initialValue);
1061         }
1062
1063         if(!transition)
1064         {
1065           transition = Dali::Animation::New(0.1f);
1066         }
1067
1068         transition.AnimateTo(Property(mImpl->mRenderer, index),
1069                              targetValue,
1070                              animator.alphaFunction,
1071                              TimePeriod(animator.timePeriodDelay,
1072                                         animator.timePeriodDuration));
1073       }
1074     }
1075   }
1076 }
1077
1078 void Visual::Base::AnimateProperty(
1079   Dali::Animation&                    transition,
1080   Internal::TransitionData::Animator& animator)
1081 {
1082 #if defined(DEBUG_ENABLED)
1083   if(gVisualBaseLogFilter->IsEnabledFor(Debug::General))
1084   {
1085     std::ostringstream oss;
1086     oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
1087     DALI_LOG_INFO(gVisualBaseLogFilter, Debug::General, oss.str().c_str());
1088   }
1089 #endif
1090
1091   if(animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
1092      animator.propertyKey == MIX_COLOR ||
1093      (mImpl->mType == Toolkit::Visual::COLOR &&
1094       animator.propertyKey == ColorVisual::Property::MIX_COLOR) ||
1095      (mImpl->mType == Toolkit::Visual::PRIMITIVE &&
1096       animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR))
1097   {
1098     AnimateMixColorProperty(transition, animator);
1099   }
1100   else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
1101           animator.propertyKey == OPACITY)
1102   {
1103     AnimateOpacityProperty(transition, animator);
1104   }
1105   else if(mImpl->mRenderer)
1106   {
1107     AnimateRendererProperty(transition, animator);
1108   }
1109 }
1110
1111 void Visual::Base::AnimateOpacityProperty(
1112   Dali::Animation&                    transition,
1113   Internal::TransitionData::Animator& animator)
1114 {
1115   float targetOpacity;
1116   if(animator.targetValue.Get(targetOpacity))
1117   {
1118     mImpl->mMixColor.a = targetOpacity;
1119   }
1120
1121   SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, animator.initialValue, animator.targetValue);
1122 }
1123
1124 void Visual::Base::AnimateRendererProperty(
1125   Dali::Animation&                    transition,
1126   Internal::TransitionData::Animator& animator)
1127 {
1128   // Get actual renderer index (will convert transform keys into visualproperty indices)
1129   Property::Index index = GetPropertyIndex(animator.propertyKey);
1130
1131   if(index != Property::INVALID_INDEX)
1132   {
1133     if(animator.targetValue.GetType() != Property::NONE)
1134     {
1135       // Try writing target value into transform property map
1136       // if it's not a valid key, then it won't alter mTransform
1137       Property::Map map;
1138       if(animator.propertyKey.type == Property::Key::INDEX)
1139       {
1140         map.Add(animator.propertyKey.indexKey, animator.targetValue);
1141       }
1142       else
1143       {
1144         map.Add(animator.propertyKey.stringKey, animator.targetValue);
1145       }
1146
1147       mImpl->mTransform.UpdatePropertyMap(map);
1148     }
1149     SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
1150   }
1151 }
1152
1153 void Visual::Base::AnimateMixColorProperty(
1154   Dali::Animation&                    transition,
1155   Internal::TransitionData::Animator& animator)
1156 {
1157   bool animateOpacity = false;
1158
1159   Property::Value initialOpacity;
1160   Property::Value targetOpacity;
1161   Property::Value initialMixColor;
1162   Property::Value targetMixColor;
1163
1164   Vector4 initialColor;
1165   if(animator.initialValue.Get(initialColor))
1166   {
1167     if(animator.initialValue.GetType() == Property::VECTOR4)
1168     {
1169       // if there is an initial color specifying alpha, test it
1170       initialOpacity = initialColor.a;
1171     }
1172     initialMixColor = Vector3(initialColor);
1173   }
1174
1175   // Set target value into data store
1176   if(animator.targetValue.GetType() != Property::NONE)
1177   {
1178     Vector4 mixColor;
1179     animator.targetValue.Get(mixColor);
1180     if(animator.targetValue.GetType() == Property::VECTOR4)
1181     {
1182       mImpl->mMixColor.a = mixColor.a;
1183       targetOpacity      = mixColor.a;
1184       animateOpacity     = true;
1185     }
1186
1187     mImpl->mMixColor.r = mixColor.r;
1188     mImpl->mMixColor.g = mixColor.g;
1189     mImpl->mMixColor.b = mixColor.b;
1190     targetMixColor     = Vector3(mixColor);
1191   }
1192
1193   SetupTransition(transition, animator, VisualRenderer::Property::VISUAL_MIX_COLOR, initialMixColor, targetMixColor);
1194
1195   if(animateOpacity)
1196   {
1197     SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity);
1198   }
1199 }
1200
1201 Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
1202 {
1203   if(!mImpl->mRenderer)
1204   {
1205     Handle handle;
1206     return Dali::Property(handle, Property::INVALID_INDEX);
1207   }
1208
1209   switch(GetIntKey(key))
1210   {
1211     // Default animatable properties from VisualRenderer
1212     case Toolkit::Visual::Property::MIX_COLOR:
1213     {
1214       return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR);
1215     }
1216     case Toolkit::Visual::Property::OPACITY:
1217     {
1218       return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
1219     }
1220     case Toolkit::Visual::Transform::Property::OFFSET:
1221     {
1222       return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::TRANSFORM_OFFSET);
1223     }
1224     case Toolkit::Visual::Transform::Property::SIZE:
1225     {
1226       return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::TRANSFORM_SIZE);
1227     }
1228
1229     // Default animatable properties from DecoratedVisualRenderer
1230     case Toolkit::DevelVisual::Property::CORNER_RADIUS:
1231     {
1232       if(IsTypeAvailableForCornerRadius(mImpl->mType))
1233       {
1234         const bool updateShader = !mImpl->mCustomShader && !IsRoundedCornerRequired();
1235
1236         // CornerRadius is animated now. we always have to use corner radius feature.
1237         mImpl->mAlwaysUsingCornerRadius = true;
1238
1239         if(updateShader)
1240         {
1241           // Update each values to renderer
1242           DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterCornerRadiusUniform();
1243           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->GetCornerRadius());
1244           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, static_cast<float>(mImpl->GetCornerRadiusPolicy()));
1245
1246           // Change shader
1247           UpdateShader();
1248         }
1249         if(!IsBorderlineRequired())
1250         {
1251           // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
1252           mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1253         }
1254         return Dali::Property(mImpl->mRenderer, DecoratedVisualRenderer::Property::CORNER_RADIUS);
1255       }
1256       break;
1257     }
1258     case Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
1259     case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
1260     case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
1261     {
1262       if(IsTypeAvailableForBorderline(mImpl->mType))
1263       {
1264         const bool updateShader = !mImpl->mCustomShader && !IsBorderlineRequired();
1265
1266         // Borderline is animated now. we always have to use borderline feature.
1267         mImpl->mAlwaysUsingBorderline = true;
1268
1269         if(updateShader)
1270         {
1271           // Update each values to renderer
1272           DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterBorderlineUniform();
1273           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->GetBorderlineWidth());
1274           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->GetBorderlineColor());
1275           mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->GetBorderlineOffset());
1276
1277           // Change shader
1278           UpdateShader();
1279         }
1280         mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1281
1282         return Dali::Property(mImpl->mRenderer, GetPropertyIndex(key));
1283       }
1284       break;
1285     }
1286     default:
1287     {
1288       // Special case for MIX_COLOR
1289       if(key.type == Property::Key::INDEX &&
1290          ((mImpl->mType == Toolkit::Visual::COLOR && key.indexKey == ColorVisual::Property::MIX_COLOR) ||
1291           (mImpl->mType == Toolkit::Visual::PRIMITIVE && key.indexKey == PrimitiveVisual::Property::MIX_COLOR)))
1292       {
1293         return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR);
1294       }
1295
1296       // Special case for BLUR_RADIUS
1297       if(mImpl->mType == Toolkit::Visual::COLOR &&
1298          ((key.type == Property::Key::INDEX && key.indexKey == DevelColorVisual::Property::BLUR_RADIUS) ||
1299           (key.type == Property::Key::STRING && key.stringKey == BLUR_RADIUS_NAME)))
1300       {
1301         // Request to color-visual class
1302         return OnGetPropertyObject(key);
1303       }
1304     }
1305   }
1306
1307   // If it is not VisualRenderer property, check registered Renderer and Shader property.
1308   Property::Index index = GetPropertyIndex(key);
1309   if(index != Property::INVALID_INDEX)
1310   {
1311     return Dali::Property(mImpl->mRenderer, index);
1312   }
1313
1314   // We can't find the property in the base class.
1315   // Request to child class
1316   return OnGetPropertyObject(key);
1317 }
1318
1319 } // namespace Internal
1320
1321 } // namespace Toolkit
1322
1323 } // namespace Dali