Merge "use string_view to avoid string copy" 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) 2020 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/common/stage.h>
23 #include <dali/devel-api/rendering/renderer-devel.h>
24 #include <dali/devel-api/adaptor-framework/window-devel.h>
25 #include <dali/integration-api/debug.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
29 #include <dali-toolkit/public-api/visuals/visual-properties.h>
30 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
32 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
33 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
34 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
35 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
36 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
37
38 namespace Dali
39 {
40
41 namespace Toolkit
42 {
43
44 namespace Internal
45 {
46
47 namespace
48 {
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
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
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, imageUrl.GetUrl() ) ),
91   mImageVisualShaderFactory( shaderFactory ),
92   mVisualSize(),
93   mVisualScale( Vector2::ONE ),
94   mPlacementActor(),
95   mPlayState( DevelImageVisual::PlayState::STOPPED ),
96   mEventCallback( nullptr ),
97   mRendererAdded( false ),
98   mCoreShutdown(false),
99   mRedrawInScalingDown(true)
100 {
101   // the rasterized image is with pre-multiplied alpha format
102   mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
103
104   mVectorAnimationTask->UploadCompletedSignal().Connect( this, &AnimatedVectorImageVisual::OnUploadCompleted );
105   mVectorAnimationTask->SetAnimationFinishedCallback( new EventThreadCallback( MakeCallback( this, &AnimatedVectorImageVisual::OnAnimationFinished ) ) );
106
107   auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
108   vectorAnimationManager.AddObserver(*this);
109 }
110
111 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
112 {
113   if( ! mCoreShutdown )
114   {
115     auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
116     vectorAnimationManager.RemoveObserver(*this);
117
118     if( mEventCallback )
119     {
120       mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback( mEventCallback );
121     }
122
123     // Finalize animation task and disconnect the signal in the main thread
124     mVectorAnimationTask->UploadCompletedSignal().Disconnect( this, &AnimatedVectorImageVisual::OnUploadCompleted );
125     mVectorAnimationTask->Finalize();
126   }
127 }
128
129 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
130 {
131   // Core is shutting down. Don't talk to the plugin any more.
132   mCoreShutdown = true;
133 }
134
135 void AnimatedVectorImageVisual::GetNaturalSize( Vector2& naturalSize )
136 {
137   if( mVisualSize != Vector2::ZERO )
138   {
139     naturalSize = mVisualSize;
140   }
141   else
142   {
143     uint32_t width, height;
144     mVectorAnimationTask->GetDefaultSize( width, height );
145     naturalSize.x = width;
146     naturalSize.y = height;
147   }
148
149   DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this );
150 }
151
152 void AnimatedVectorImageVisual::DoCreatePropertyMap( Property::Map& map ) const
153 {
154   map.Clear();
155   map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE );
156   if( mUrl.IsValid() )
157   {
158     map.Insert( Toolkit::ImageVisual::Property::URL, mUrl.GetUrl() );
159   }
160   map.Insert( Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount );
161
162   uint32_t startFrame, endFrame;
163   mVectorAnimationTask->GetPlayRange( startFrame, endFrame );
164
165   Property::Array playRange;
166   playRange.PushBack( static_cast< int32_t >( startFrame ) );
167   playRange.PushBack( static_cast< int32_t >( endFrame ) );
168   map.Insert( Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange );
169
170   map.Insert( Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast< int32_t >( mPlayState ) );
171   map.Insert( Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast< int32_t >( mVectorAnimationTask->GetCurrentFrameNumber() ) );
172   map.Insert( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast< int32_t >( mVectorAnimationTask->GetTotalFrameNumber() ) );
173
174   map.Insert( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior );
175   map.Insert( Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode );
176   map.Insert( Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, mRedrawInScalingDown );
177
178   Property::Map layerInfo;
179   mVectorAnimationTask->GetLayerInfo( layerInfo );
180   map.Insert( Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo );
181 }
182
183 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
184 {
185   // Do nothing
186 }
187
188 void AnimatedVectorImageVisual::DoSetProperties( const Property::Map& propertyMap )
189 {
190   // url already passed in from constructor
191   for( Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter )
192   {
193     KeyValuePair keyValue = propertyMap.GetKeyValue( iter );
194     if( keyValue.first.type == Property::Key::INDEX )
195     {
196       DoSetProperty( keyValue.first.indexKey, keyValue.second );
197     }
198     else
199     {
200        if( keyValue.first == LOOP_COUNT_NAME )
201        {
202           DoSetProperty( Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second );
203        }
204        else if( keyValue.first == PLAY_RANGE_NAME )
205        {
206           DoSetProperty( Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second );
207        }
208        else if( keyValue.first == STOP_BEHAVIOR_NAME )
209        {
210           DoSetProperty( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second );
211        }
212        else if( keyValue.first == LOOPING_MODE_NAME )
213        {
214           DoSetProperty( Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second );
215        }
216        else if( keyValue.first == REDRAW_IN_SCALING_DOWN_NAME )
217        {
218           DoSetProperty( Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second );
219        }
220     }
221   }
222
223   TriggerVectorRasterization();
224 }
225
226 void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Property::Value& value )
227 {
228   switch(index)
229   {
230     case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
231     {
232       int32_t loopCount;
233       if( value.Get( loopCount ) )
234       {
235         mAnimationData.loopCount = loopCount;
236         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
237       }
238       break;
239     }
240     case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
241     {
242       const Property::Array* array = value.GetArray();
243       if( array )
244       {
245         mAnimationData.playRange = *array;
246         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
247       }
248       break;
249     }
250     case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
251     {
252       int32_t stopBehavior = mAnimationData.stopBehavior;
253       if( Scripting::GetEnumerationProperty( value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior ) )
254       {
255         mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type( stopBehavior );
256         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
257       }
258       break;
259     }
260     case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
261     {
262       int32_t loopingMode = mAnimationData.loopingMode;
263       if( Scripting::GetEnumerationProperty( value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode ) )
264       {
265         mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type( loopingMode );
266         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
267       }
268       break;
269     }
270     case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
271     {
272       bool redraw;
273       if( value.Get( redraw ) )
274       {
275         mRedrawInScalingDown = redraw;
276       }
277       break;
278     }
279   }
280 }
281
282 void AnimatedVectorImageVisual::DoSetOnScene( Actor& actor )
283 {
284   Shader shader;
285
286   if( mImpl->mCustomShader )
287   {
288     shader = Shader::New( mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
289                           mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
290                           mImpl->mCustomShader->mHints );
291
292     shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
293   }
294   else
295   {
296     shader = mImageVisualShaderFactory.GetShader( mFactoryCache, false, true, false );
297   }
298
299   Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
300
301   mImpl->mRenderer = Renderer::New( geometry, shader );
302
303   TextureSet textureSet = TextureSet::New();
304   mImpl->mRenderer.SetTextures( textureSet );
305
306   // Register transform properties
307   mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
308
309   // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
310
311   // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
312   mPlacementActor = actor;
313
314   mVectorAnimationTask->SetRenderer( mImpl->mRenderer );
315
316   // Add property notification for scaling & size
317   mScaleNotification = actor.AddPropertyNotification( Actor::Property::WORLD_SCALE, StepCondition( 0.1f, 1.0f ) );
318   mScaleNotification.NotifySignal().Connect( this, &AnimatedVectorImageVisual::OnScaleNotification );
319
320   mSizeNotification = actor.AddPropertyNotification( Actor::Property::SIZE, StepCondition( 3.0f ) );
321   mSizeNotification.NotifySignal().Connect( this, &AnimatedVectorImageVisual::OnSizeNotification );
322
323   DevelActor::VisibilityChangedSignal( actor ).Connect( this, &AnimatedVectorImageVisual::OnControlVisibilityChanged );
324
325   Window window = DevelWindow::Get( actor );
326   if( window )
327   {
328     DevelWindow::VisibilityChangedSignal( window ).Connect( this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged );
329   }
330
331   DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this );
332 }
333
334 void AnimatedVectorImageVisual::DoSetOffScene( Actor& actor )
335 {
336   StopAnimation();
337   SendAnimationData();
338
339   if( mImpl->mRenderer )
340   {
341     actor.RemoveRenderer( mImpl->mRenderer );
342     mImpl->mRenderer.Reset();
343
344     mRendererAdded = false;
345   }
346
347   // Remove property notification
348   actor.RemovePropertyNotification( mScaleNotification );
349   actor.RemovePropertyNotification( mSizeNotification );
350
351   DevelActor::VisibilityChangedSignal( actor ).Disconnect( this, &AnimatedVectorImageVisual::OnControlVisibilityChanged );
352
353   Window window = DevelWindow::Get( actor );
354   if( window )
355   {
356     DevelWindow::VisibilityChangedSignal( window ).Disconnect( this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged );
357   }
358
359   mPlacementActor.Reset();
360
361   // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
362   mVisualSize = Vector2::ZERO;
363   mVisualScale = Vector2::ONE;
364
365   DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this );
366 }
367
368 void AnimatedVectorImageVisual::OnSetTransform()
369 {
370   Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize );
371
372   if( IsOnScene() && visualSize != mVisualSize )
373   {
374     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this );
375
376     mVisualSize = visualSize;
377
378     SetVectorImageSize();
379
380     if( mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING )
381     {
382       mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
383       mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
384     }
385
386     SendAnimationData();
387   }
388 }
389
390 void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, const Property::Value& attributes )
391 {
392   // Check if action is valid for this visual type and perform action if possible
393   switch( actionId )
394   {
395     case DevelAnimatedVectorImageVisual::Action::PLAY:
396     {
397       if( IsOnScene() && mVisualSize != Vector2::ZERO )
398       {
399         if( mAnimationData.playState != DevelImageVisual::PlayState::PLAYING )
400         {
401           mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
402           mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
403         }
404       }
405       mPlayState = DevelImageVisual::PlayState::PLAYING;
406       break;
407     }
408     case DevelAnimatedVectorImageVisual::Action::PAUSE:
409     {
410       if( mAnimationData.playState == DevelImageVisual::PlayState::PLAYING )
411       {
412         mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
413         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
414       }
415       mPlayState = DevelImageVisual::PlayState::PAUSED;
416       break;
417     }
418     case DevelAnimatedVectorImageVisual::Action::STOP:
419     {
420       if( mAnimationData.playState != DevelImageVisual::PlayState::STOPPED )
421       {
422         mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
423         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
424       }
425       mPlayState = DevelImageVisual::PlayState::STOPPED;
426       break;
427     }
428     case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
429     {
430       int32_t frameNumber;
431       if( attributes.Get( frameNumber ) )
432       {
433         mAnimationData.currentFrame = frameNumber;
434         mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
435       }
436       break;
437     }
438     case DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY:
439     {
440       const Property::Map* map = attributes.GetMap();
441       if( map )
442       {
443         DoSetProperties( *map );
444       }
445       break;
446     }
447   }
448
449   TriggerVectorRasterization();
450 }
451
452 void AnimatedVectorImageVisual::OnUploadCompleted()
453 {
454   // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
455   Actor actor = mPlacementActor.GetHandle();
456   if( actor && !mRendererAdded )
457   {
458     actor.AddRenderer( mImpl->mRenderer );
459     mRendererAdded = true;
460
461     ResourceReady( Toolkit::Visual::ResourceStatus::READY );
462
463     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnUploadCompleted: Renderer is added [%p]\n", this );
464   }
465 }
466
467 void AnimatedVectorImageVisual::OnAnimationFinished()
468 {
469   DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this );
470
471   if( mPlayState != DevelImageVisual::PlayState::STOPPED )
472   {
473     mPlayState = DevelImageVisual::PlayState::STOPPED;
474
475     mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
476
477     if( mImpl->mEventObserver )
478     {
479       mImpl->mEventObserver->NotifyVisualEvent( *this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED );
480     }
481   }
482
483   if( mImpl->mRenderer )
484   {
485     mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED );
486   }
487 }
488
489 void AnimatedVectorImageVisual::SendAnimationData()
490 {
491   if( mAnimationData.resendFlag )
492   {
493     mVectorAnimationTask->SetAnimationData( mAnimationData );
494
495     if( mImpl->mRenderer )
496     {
497       if( mAnimationData.playState == DevelImageVisual::PlayState::PLAYING )
498       {
499         mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY );
500       }
501       else
502       {
503         mImpl->mRenderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED );
504       }
505     }
506
507     mAnimationData.resendFlag = 0;
508   }
509 }
510
511 void AnimatedVectorImageVisual::SetVectorImageSize()
512 {
513   uint32_t width = static_cast< uint32_t >( mVisualSize.width * mVisualScale.width );
514   uint32_t height = static_cast< uint32_t >( mVisualSize.height * mVisualScale.height );
515
516   mAnimationData.width = width;
517   mAnimationData.height = height;
518   mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
519 }
520
521 void AnimatedVectorImageVisual::StopAnimation()
522 {
523   if( mAnimationData.playState != DevelImageVisual::PlayState::STOPPED )
524   {
525     mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
526     mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
527
528     mPlayState = DevelImageVisual::PlayState::STOPPED;
529   }
530 }
531
532 void AnimatedVectorImageVisual::TriggerVectorRasterization()
533 {
534   if( !mEventCallback && !mCoreShutdown )
535   {
536     mEventCallback = MakeCallback( this, &AnimatedVectorImageVisual::OnProcessEvents );
537     auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
538     vectorAnimationManager.RegisterEventCallback( mEventCallback );
539     Stage::GetCurrent().KeepRendering( 0.0f );  // Trigger event processing
540   }
541 }
542
543 void AnimatedVectorImageVisual::OnScaleNotification( PropertyNotification& source )
544 {
545   Actor actor = mPlacementActor.GetHandle();
546   if( actor )
547   {
548     Vector3 scale = actor.GetProperty< Vector3 >( Actor::Property::WORLD_SCALE );
549
550     if(mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f)
551     {
552       mVisualScale.width = scale.width;
553       mVisualScale.height = scale.height;
554
555       DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this );
556
557       SetVectorImageSize();
558       SendAnimationData();
559
560       Stage::GetCurrent().KeepRendering( 0.0f );  // Trigger event processing
561     }
562   }
563 }
564
565 void AnimatedVectorImageVisual::OnSizeNotification( PropertyNotification& source )
566 {
567   Actor actor = mPlacementActor.GetHandle();
568   if( actor )
569   {
570     Vector3 size = actor.GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
571     mVisualSize.width = size.width;
572     mVisualSize.height = size.height;
573
574     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this );
575
576     SetVectorImageSize();
577     SendAnimationData();
578
579     Stage::GetCurrent().KeepRendering( 0.0f );  // Trigger event processing
580   }
581 }
582
583 void AnimatedVectorImageVisual::OnControlVisibilityChanged( Actor actor, bool visible, DevelActor::VisibilityChange::Type type )
584 {
585   if( !visible )
586   {
587     StopAnimation();
588     TriggerVectorRasterization();
589
590     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this );
591   }
592 }
593
594 void AnimatedVectorImageVisual::OnWindowVisibilityChanged( Window window, bool visible )
595 {
596   if( !visible )
597   {
598     StopAnimation();
599     TriggerVectorRasterization();
600
601     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this );
602   }
603 }
604
605 void AnimatedVectorImageVisual::OnProcessEvents()
606 {
607   SendAnimationData();
608
609   mEventCallback = nullptr;  // The callback will be deleted in the VectorAnimationManager
610 }
611
612 } // namespace Internal
613
614 } // namespace Toolkit
615
616 } // namespace Dali