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