Merge "[AT-SPI] Do not set Popup's sub-role to "Alert"" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / animated-vector-image-visual.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 <dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/window-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/rendering/renderer-devel.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/rendering/decorated-visual-renderer.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
30 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
32 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
33 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
34 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
35 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
36 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
37 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
38 #include <dali-toolkit/public-api/visuals/visual-properties.h>
39
40 namespace Dali
41 {
42 namespace Toolkit
43 {
44 namespace Internal
45 {
46 namespace
47 {
48 const int CUSTOM_PROPERTY_COUNT(1); // pixel area,
49
50 const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
51
52 // stop behavior
53 DALI_ENUM_TO_STRING_TABLE_BEGIN(STOP_BEHAVIOR)
54   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, CURRENT_FRAME)
55   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, FIRST_FRAME)
56   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, LAST_FRAME)
57 DALI_ENUM_TO_STRING_TABLE_END(STOP_BEHAVIOR)
58
59 // looping mode
60 DALI_ENUM_TO_STRING_TABLE_BEGIN(LOOPING_MODE)
61   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, RESTART)
62   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, AUTO_REVERSE)
63 DALI_ENUM_TO_STRING_TABLE_END(LOOPING_MODE)
64
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
67 #endif
68
69 } // unnamed namespace
70
71 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
72 {
73   AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl));
74   visual->SetProperties(properties);
75   visual->Initialize();
76   return visual;
77 }
78
79 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl)
80 {
81   AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl));
82   visual->Initialize();
83   return visual;
84 }
85
86 AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl)
87 : Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)),
88   mUrl(imageUrl),
89   mAnimationData(),
90   mVectorAnimationTask(new VectorAnimationTask(factoryCache)),
91   mImageVisualShaderFactory(shaderFactory),
92   mVisualSize(),
93   mVisualScale(Vector2::ONE),
94   mPlacementActor(),
95   mPlayState(DevelImageVisual::PlayState::STOPPED),
96   mEventCallback(nullptr),
97   mLoadFailed(false),
98   mRendererAdded(false),
99   mCoreShutdown(false),
100   mRedrawInScalingDown(true)
101 {
102   // the rasterized image is with pre-multiplied alpha format
103   mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA;
104
105   // By default, load a file synchronously
106   mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
107 }
108
109 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
110 {
111   if(!mCoreShutdown)
112   {
113     auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
114     vectorAnimationManager.RemoveObserver(*this);
115
116     if(mEventCallback)
117     {
118       mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
119     }
120
121     // Finalize animation task and disconnect the signal in the main thread
122     mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady);
123     mVectorAnimationTask->Finalize();
124   }
125 }
126
127 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
128 {
129   // Core is shutting down. Don't talk to the plugin any more.
130   mCoreShutdown = true;
131 }
132
133 void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize)
134 {
135   if(mVisualSize != Vector2::ZERO)
136   {
137     naturalSize = mVisualSize;
138   }
139   else
140   {
141     if(mLoadFailed && mImpl->mRenderer)
142     {
143       // Load failed, use broken image size
144       auto textureSet = mImpl->mRenderer.GetTextures();
145       if(textureSet && textureSet.GetTextureCount())
146       {
147         auto texture = textureSet.GetTexture(0);
148         if(texture)
149         {
150           naturalSize.x = texture.GetWidth();
151           naturalSize.y = texture.GetHeight();
152           return;
153         }
154       }
155     }
156     else
157     {
158       uint32_t width, height;
159       mVectorAnimationTask->GetDefaultSize(width, height);
160       naturalSize.x = width;
161       naturalSize.y = height;
162     }
163   }
164
165   DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this);
166 }
167
168 void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
169 {
170   map.Clear();
171   map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE);
172   if(mUrl.IsValid())
173   {
174     map.Insert(Toolkit::ImageVisual::Property::URL, mUrl.GetUrl());
175   }
176   map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount);
177
178   uint32_t startFrame, endFrame;
179   mVectorAnimationTask->GetPlayRange(startFrame, endFrame);
180
181   Property::Array playRange;
182   playRange.PushBack(static_cast<int32_t>(startFrame));
183   playRange.PushBack(static_cast<int32_t>(endFrame));
184   map.Insert(Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange);
185
186   map.Insert(Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast<int32_t>(mPlayState));
187   map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetCurrentFrameNumber()));
188   map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetTotalFrameNumber()));
189
190   map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior);
191   map.Insert(Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode);
192   map.Insert(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, mRedrawInScalingDown);
193
194   Property::Map layerInfo;
195   mVectorAnimationTask->GetLayerInfo(layerInfo);
196   map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo);
197 }
198
199 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
200 {
201   // Do nothing
202 }
203
204 void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied)
205 {
206   // Make always enable pre multiplied alpha whether preMultiplied value is false.
207   if(!preMultiplied)
208   {
209     DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n");
210   }
211 }
212
213 void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap)
214 {
215   // url already passed in from constructor
216   for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
217   {
218     KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
219     if(keyValue.first.type == Property::Key::INDEX)
220     {
221       DoSetProperty(keyValue.first.indexKey, keyValue.second);
222     }
223     else
224     {
225       if(keyValue.first == LOOP_COUNT_NAME)
226       {
227         DoSetProperty(Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second);
228       }
229       else if(keyValue.first == PLAY_RANGE_NAME)
230       {
231         DoSetProperty(Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second);
232       }
233       else if(keyValue.first == STOP_BEHAVIOR_NAME)
234       {
235         DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
236       }
237       else if(keyValue.first == LOOPING_MODE_NAME)
238       {
239         DoSetProperty(Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second);
240       }
241       else if(keyValue.first == REDRAW_IN_SCALING_DOWN_NAME)
242       {
243         DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second);
244       }
245       else if(keyValue.first == SYNCHRONOUS_LOADING)
246       {
247         DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
248       }
249     }
250   }
251
252   TriggerVectorRasterization();
253 }
254
255 void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
256 {
257   switch(index)
258   {
259     case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
260     {
261       int32_t loopCount;
262       if(value.Get(loopCount))
263       {
264         mAnimationData.loopCount = loopCount;
265         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
266       }
267       break;
268     }
269     case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
270     {
271       const Property::Array* array = value.GetArray();
272       if(array)
273       {
274         mAnimationData.playRange = *array;
275         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
276       }
277       break;
278     }
279     case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
280     {
281       int32_t stopBehavior = mAnimationData.stopBehavior;
282       if(Scripting::GetEnumerationProperty(value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior))
283       {
284         mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type(stopBehavior);
285         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
286       }
287       break;
288     }
289     case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
290     {
291       int32_t loopingMode = mAnimationData.loopingMode;
292       if(Scripting::GetEnumerationProperty(value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode))
293       {
294         mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type(loopingMode);
295         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
296       }
297       break;
298     }
299     case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
300     {
301       bool redraw;
302       if(value.Get(redraw))
303       {
304         mRedrawInScalingDown = redraw;
305       }
306       break;
307     }
308     case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
309     {
310       bool sync = false;
311       if(value.Get(sync))
312       {
313         if(sync)
314         {
315           mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
316         }
317         else
318         {
319           mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
320         }
321       }
322       break;
323     }
324   }
325 }
326
327 void AnimatedVectorImageVisual::OnInitialize(void)
328 {
329   mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
330   mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished)));
331
332   mVectorAnimationTask->RequestLoad(mUrl.GetUrl(), IsSynchronousLoadingRequired());
333
334   auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
335   vectorAnimationManager.AddObserver(*this);
336
337   Shader shader = GenerateShader();
338
339   Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
340
341   mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
342   mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
343
344   TextureSet textureSet = TextureSet::New();
345   mImpl->mRenderer.SetTextures(textureSet);
346
347   // Register transform properties
348   mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
349
350   mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
351 }
352
353 void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
354 {
355   // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
356
357   // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
358   mPlacementActor = actor;
359
360   if(mLoadFailed)
361   {
362     Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
363     mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
364     actor.AddRenderer(mImpl->mRenderer);
365     ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
366   }
367   else
368   {
369     // Add property notification for scaling & size
370     mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
371     mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
372
373     mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
374     mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
375
376     DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
377
378     Window window = DevelWindow::Get(actor);
379     if(window)
380     {
381       DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
382     }
383
384     if(mImpl->mEventObserver)
385     {
386       // The visual needs it's size set before it can be rasterized hence request relayout once on stage
387       mImpl->mEventObserver->RelayoutRequest(*this);
388     }
389
390     mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY;
391     TriggerVectorRasterization();
392   }
393
394   DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
395 }
396
397 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
398 {
399   StopAnimation();
400   TriggerVectorRasterization();
401
402   if(mImpl->mRenderer)
403   {
404     actor.RemoveRenderer(mImpl->mRenderer);
405     mRendererAdded = false;
406   }
407
408   // Remove property notification
409   actor.RemovePropertyNotification(mScaleNotification);
410   actor.RemovePropertyNotification(mSizeNotification);
411
412   DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
413
414   Window window = DevelWindow::Get(actor);
415   if(window)
416   {
417     DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
418   }
419
420   mPlacementActor.Reset();
421
422   // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
423   mVisualSize           = Vector2::ZERO;
424   mVisualScale          = Vector2::ONE;
425   mAnimationData.width  = 0;
426   mAnimationData.height = 0;
427
428   DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this);
429 }
430
431 void AnimatedVectorImageVisual::OnSetTransform()
432 {
433   Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
434
435   if(IsOnScene() && visualSize != mVisualSize)
436   {
437     DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this);
438
439     mVisualSize = visualSize;
440
441     SetVectorImageSize();
442
443     if(mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
444     {
445       mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
446       mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
447     }
448
449     TriggerVectorRasterization();
450   }
451 }
452
453 void AnimatedVectorImageVisual::UpdateShader()
454 {
455   if(mImpl->mRenderer)
456   {
457     Shader shader = GenerateShader();
458     mImpl->mRenderer.SetShader(shader);
459   }
460 }
461
462 void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
463 {
464   // Check if action is valid for this visual type and perform action if possible
465   switch(actionId)
466   {
467     case DevelAnimatedVectorImageVisual::Action::PLAY:
468     {
469       if(IsOnScene() && mVisualSize != Vector2::ZERO)
470       {
471         if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
472         {
473           mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
474           mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
475         }
476       }
477       mPlayState = DevelImageVisual::PlayState::PLAYING;
478       break;
479     }
480     case DevelAnimatedVectorImageVisual::Action::PAUSE:
481     {
482       if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
483       {
484         mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
485         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
486       }
487       mPlayState = DevelImageVisual::PlayState::PAUSED;
488       break;
489     }
490     case DevelAnimatedVectorImageVisual::Action::STOP:
491     {
492       if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
493       {
494         mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
495         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
496       }
497       mPlayState = DevelImageVisual::PlayState::STOPPED;
498       break;
499     }
500     case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
501     {
502       int32_t frameNumber;
503       if(attributes.Get(frameNumber))
504       {
505         mAnimationData.currentFrame = frameNumber;
506         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
507       }
508       break;
509     }
510   }
511
512   TriggerVectorRasterization();
513 }
514
515 void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, Dali::Any attributes)
516 {
517   switch(actionId)
518   {
519     case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY:
520     {
521       DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>(attributes);
522       mAnimationData.dynamicProperties.push_back(info);
523       mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY;
524       break;
525     }
526   }
527
528   TriggerVectorRasterization();
529 }
530
531 void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
532 {
533   if(status == VectorAnimationTask::ResourceStatus::LOADED)
534   {
535     if(mImpl->mEventObserver)
536     {
537       mImpl->mEventObserver->RelayoutRequest(*this);
538     }
539   }
540   else
541   {
542     mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
543
544     // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
545     Actor actor = mPlacementActor.GetHandle();
546     if(actor && !mRendererAdded)
547     {
548       if(!mLoadFailed)
549       {
550         actor.AddRenderer(mImpl->mRenderer);
551         ResourceReady(Toolkit::Visual::ResourceStatus::READY);
552       }
553       else
554       {
555         Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
556         mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
557         actor.AddRenderer(mImpl->mRenderer);
558         ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
559       }
560
561       mRendererAdded = true;
562     }
563   }
564
565   DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this);
566 }
567
568 void AnimatedVectorImageVisual::OnAnimationFinished()
569 {
570   DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this);
571
572   if(mPlayState != DevelImageVisual::PlayState::STOPPED)
573   {
574     mPlayState = DevelImageVisual::PlayState::STOPPED;
575
576     mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
577
578     if(mImpl->mEventObserver)
579     {
580       mImpl->mEventObserver->NotifyVisualEvent(*this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED);
581     }
582   }
583
584   if(mImpl->mRenderer)
585   {
586     mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
587   }
588 }
589
590 void AnimatedVectorImageVisual::SendAnimationData()
591 {
592   if(mAnimationData.resendFlag)
593   {
594     mVectorAnimationTask->SetAnimationData(mAnimationData);
595
596     if(mImpl->mRenderer)
597     {
598       if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
599       {
600         mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
601       }
602       else
603       {
604         mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
605       }
606     }
607
608     mAnimationData.resendFlag = 0;
609   }
610 }
611
612 void AnimatedVectorImageVisual::SetVectorImageSize()
613 {
614   uint32_t width  = static_cast<uint32_t>(mVisualSize.width * mVisualScale.width);
615   uint32_t height = static_cast<uint32_t>(mVisualSize.height * mVisualScale.height);
616
617   if(mAnimationData.width != width || mAnimationData.height != height)
618   {
619     mAnimationData.width  = width;
620     mAnimationData.height = height;
621     mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
622   }
623 }
624
625 void AnimatedVectorImageVisual::StopAnimation()
626 {
627   if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
628   {
629     mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
630     mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
631
632     mPlayState = DevelImageVisual::PlayState::STOPPED;
633   }
634 }
635
636 void AnimatedVectorImageVisual::TriggerVectorRasterization()
637 {
638   if(!mEventCallback && !mCoreShutdown)
639   {
640     mEventCallback               = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents);
641     auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
642     vectorAnimationManager.RegisterEventCallback(mEventCallback);
643     Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
644   }
645 }
646
647 void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source)
648 {
649   Actor actor = mPlacementActor.GetHandle();
650   if(actor)
651   {
652     Vector3 scale = actor.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
653
654     if((mVisualScale.width != scale.width || mVisualScale.height != scale.height) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f))
655     {
656       mVisualScale.width  = scale.width;
657       mVisualScale.height = scale.height;
658
659       DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this);
660
661       SetVectorImageSize();
662       SendAnimationData();
663
664       Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
665     }
666   }
667 }
668
669 void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source)
670 {
671   Actor actor = mPlacementActor.GetHandle();
672   if(actor)
673   {
674     Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
675
676     if(mVisualSize.width != size.width || mVisualSize.height != size.height)
677     {
678       mVisualSize.width  = size.width;
679       mVisualSize.height = size.height;
680
681       DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this);
682
683       SetVectorImageSize();
684       SendAnimationData();
685
686       Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
687     }
688   }
689 }
690
691 void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
692 {
693   if(!visible)
694   {
695     StopAnimation();
696     TriggerVectorRasterization();
697
698     DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
699   }
700 }
701
702 void AnimatedVectorImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
703 {
704   if(!visible)
705   {
706     StopAnimation();
707     TriggerVectorRasterization();
708
709     DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
710   }
711 }
712
713 void AnimatedVectorImageVisual::OnProcessEvents()
714 {
715   SendAnimationData();
716
717   mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager
718 }
719
720 Shader AnimatedVectorImageVisual::GenerateShader() const
721 {
722   Shader shader;
723   if(mImpl->mCustomShader)
724   {
725     shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
726                          mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
727                          mImpl->mCustomShader->mHints);
728
729     shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
730   }
731   else
732   {
733     shader = mImageVisualShaderFactory.GetShader(
734       mFactoryCache,
735       ImageVisualShaderFeature::FeatureBuilder()
736         .EnableRoundedCorner(IsRoundedCornerRequired())
737         .EnableBorderline(IsBorderlineRequired()));
738   }
739   return shader;
740 }
741
742 } // namespace Internal
743
744 } // namespace Toolkit
745
746 } // namespace Dali