2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h>
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>
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>
48 const int CUSTOM_PROPERTY_COUNT(1); // pixel area,
50 const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
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)
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)
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
69 } // unnamed namespace
71 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
73 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl));
74 visual->SetProperties(properties);
79 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl)
81 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl));
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)),
90 mVectorAnimationTask(new VectorAnimationTask(factoryCache)),
91 mImageVisualShaderFactory(shaderFactory),
93 mVisualScale(Vector2::ONE),
95 mPlayState(DevelImageVisual::PlayState::STOPPED),
96 mEventCallback(nullptr),
98 mRendererAdded(false),
100 mRedrawInScalingDown(true)
102 // the rasterized image is with pre-multiplied alpha format
103 mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA;
105 // By default, load a file synchronously
106 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
109 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
113 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
114 vectorAnimationManager.RemoveObserver(*this);
118 mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
121 // Finalize animation task and disconnect the signal in the main thread
122 mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady);
123 mVectorAnimationTask->Finalize();
127 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
129 // Core is shutting down. Don't talk to the plugin any more.
130 mCoreShutdown = true;
133 void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize)
135 if(mVisualSize != Vector2::ZERO)
137 naturalSize = mVisualSize;
141 if(mLoadFailed && mImpl->mRenderer)
143 // Load failed, use broken image size
144 auto textureSet = mImpl->mRenderer.GetTextures();
145 if(textureSet && textureSet.GetTextureCount())
147 auto texture = textureSet.GetTexture(0);
150 naturalSize.x = texture.GetWidth();
151 naturalSize.y = texture.GetHeight();
158 uint32_t width, height;
159 mVectorAnimationTask->GetDefaultSize(width, height);
160 naturalSize.x = width;
161 naturalSize.y = height;
165 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this);
168 void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
171 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE);
174 map.Insert(Toolkit::ImageVisual::Property::URL, mUrl.GetUrl());
176 map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount);
178 uint32_t startFrame, endFrame;
179 mVectorAnimationTask->GetPlayRange(startFrame, endFrame);
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);
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()));
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);
194 Property::Map layerInfo;
195 mVectorAnimationTask->GetLayerInfo(layerInfo);
196 map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo);
199 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
204 void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied)
206 // Make always enable pre multiplied alpha whether preMultiplied value is false.
209 DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n");
213 void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap)
215 // url already passed in from constructor
216 for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
218 KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
219 if(keyValue.first.type == Property::Key::INDEX)
221 DoSetProperty(keyValue.first.indexKey, keyValue.second);
225 if(keyValue.first == LOOP_COUNT_NAME)
227 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second);
229 else if(keyValue.first == PLAY_RANGE_NAME)
231 DoSetProperty(Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second);
233 else if(keyValue.first == STOP_BEHAVIOR_NAME)
235 DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
237 else if(keyValue.first == LOOPING_MODE_NAME)
239 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second);
241 else if(keyValue.first == REDRAW_IN_SCALING_DOWN_NAME)
243 DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second);
245 else if(keyValue.first == SYNCHRONOUS_LOADING)
247 DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
252 TriggerVectorRasterization();
255 void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
259 case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
262 if(value.Get(loopCount))
264 mAnimationData.loopCount = loopCount;
265 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
269 case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
271 const Property::Array* array = value.GetArray();
274 mAnimationData.playRange = *array;
275 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
279 case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
281 int32_t stopBehavior = mAnimationData.stopBehavior;
282 if(Scripting::GetEnumerationProperty(value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior))
284 mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type(stopBehavior);
285 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
289 case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
291 int32_t loopingMode = mAnimationData.loopingMode;
292 if(Scripting::GetEnumerationProperty(value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode))
294 mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type(loopingMode);
295 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
299 case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
302 if(value.Get(redraw))
304 mRedrawInScalingDown = redraw;
308 case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
315 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
319 mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
327 void AnimatedVectorImageVisual::OnInitialize(void)
329 mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
330 mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished)));
332 mVectorAnimationTask->RequestLoad(mUrl.GetUrl(), IsSynchronousLoadingRequired());
334 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
335 vectorAnimationManager.AddObserver(*this);
337 Shader shader = GenerateShader();
339 Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
341 mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
342 mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
344 TextureSet textureSet = TextureSet::New();
345 mImpl->mRenderer.SetTextures(textureSet);
347 // Register transform properties
348 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
350 mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
353 void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
355 // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
357 // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
358 mPlacementActor = actor;
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);
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);
373 mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
374 mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
376 DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
378 Window window = DevelWindow::Get(actor);
381 DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
384 if(mImpl->mEventObserver)
386 // The visual needs it's size set before it can be rasterized hence request relayout once on stage
387 mImpl->mEventObserver->RelayoutRequest(*this);
390 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY;
391 TriggerVectorRasterization();
394 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
397 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
400 TriggerVectorRasterization();
404 actor.RemoveRenderer(mImpl->mRenderer);
405 mRendererAdded = false;
408 // Remove property notification
409 actor.RemovePropertyNotification(mScaleNotification);
410 actor.RemovePropertyNotification(mSizeNotification);
412 DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
414 Window window = DevelWindow::Get(actor);
417 DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
420 mPlacementActor.Reset();
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;
428 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this);
431 void AnimatedVectorImageVisual::OnSetTransform()
433 Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
435 if(IsOnScene() && visualSize != mVisualSize)
437 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this);
439 mVisualSize = visualSize;
441 SetVectorImageSize();
443 if(mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
445 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
446 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
449 TriggerVectorRasterization();
453 void AnimatedVectorImageVisual::UpdateShader()
457 Shader shader = GenerateShader();
458 mImpl->mRenderer.SetShader(shader);
462 void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
464 // Check if action is valid for this visual type and perform action if possible
467 case DevelAnimatedVectorImageVisual::Action::PLAY:
469 if(IsOnScene() && mVisualSize != Vector2::ZERO)
471 if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
473 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
474 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
477 mPlayState = DevelImageVisual::PlayState::PLAYING;
480 case DevelAnimatedVectorImageVisual::Action::PAUSE:
482 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
484 mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
485 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
487 mPlayState = DevelImageVisual::PlayState::PAUSED;
490 case DevelAnimatedVectorImageVisual::Action::STOP:
492 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
494 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
495 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
497 mPlayState = DevelImageVisual::PlayState::STOPPED;
500 case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
503 if(attributes.Get(frameNumber))
505 mAnimationData.currentFrame = frameNumber;
506 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
512 TriggerVectorRasterization();
515 void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, Dali::Any attributes)
519 case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY:
521 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>(attributes);
522 mAnimationData.dynamicProperties.push_back(info);
523 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY;
528 TriggerVectorRasterization();
531 void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
533 if(status == VectorAnimationTask::ResourceStatus::LOADED)
535 if(mImpl->mEventObserver)
537 mImpl->mEventObserver->RelayoutRequest(*this);
542 mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
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)
550 actor.AddRenderer(mImpl->mRenderer);
551 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
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);
561 mRendererAdded = true;
565 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this);
568 void AnimatedVectorImageVisual::OnAnimationFinished()
570 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this);
572 if(mPlayState != DevelImageVisual::PlayState::STOPPED)
574 mPlayState = DevelImageVisual::PlayState::STOPPED;
576 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
578 if(mImpl->mEventObserver)
580 mImpl->mEventObserver->NotifyVisualEvent(*this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED);
586 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
590 void AnimatedVectorImageVisual::SendAnimationData()
592 if(mAnimationData.resendFlag)
594 mVectorAnimationTask->SetAnimationData(mAnimationData);
598 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
600 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
604 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
608 mAnimationData.resendFlag = 0;
612 void AnimatedVectorImageVisual::SetVectorImageSize()
614 uint32_t width = static_cast<uint32_t>(mVisualSize.width * mVisualScale.width);
615 uint32_t height = static_cast<uint32_t>(mVisualSize.height * mVisualScale.height);
617 if(mAnimationData.width != width || mAnimationData.height != height)
619 mAnimationData.width = width;
620 mAnimationData.height = height;
621 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
625 void AnimatedVectorImageVisual::StopAnimation()
627 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
629 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
630 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
632 mPlayState = DevelImageVisual::PlayState::STOPPED;
636 void AnimatedVectorImageVisual::TriggerVectorRasterization()
638 if(!mEventCallback && !mCoreShutdown)
640 mEventCallback = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents);
641 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
642 vectorAnimationManager.RegisterEventCallback(mEventCallback);
643 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
647 void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source)
649 Actor actor = mPlacementActor.GetHandle();
652 Vector3 scale = actor.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
654 if((mVisualScale.width != scale.width || mVisualScale.height != scale.height) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f))
656 mVisualScale.width = scale.width;
657 mVisualScale.height = scale.height;
659 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this);
661 SetVectorImageSize();
664 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
669 void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source)
671 Actor actor = mPlacementActor.GetHandle();
674 Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
676 if(mVisualSize.width != size.width || mVisualSize.height != size.height)
678 mVisualSize.width = size.width;
679 mVisualSize.height = size.height;
681 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this);
683 SetVectorImageSize();
686 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
691 void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
696 TriggerVectorRasterization();
698 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
702 void AnimatedVectorImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
707 TriggerVectorRasterization();
709 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
713 void AnimatedVectorImageVisual::OnProcessEvents()
717 mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager
720 Shader AnimatedVectorImageVisual::GenerateShader() const
723 if(mImpl->mCustomShader)
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);
729 shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
733 shader = mImageVisualShaderFactory.GetShader(
735 ImageVisualShaderFeature::FeatureBuilder()
736 .EnableRoundedCorner(IsRoundedCornerRequired())
737 .EnableBorderline(IsBorderlineRequired()));
742 } // namespace Internal
744 } // namespace Toolkit