2 * Copyright (c) 2023 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/math/math-utils.h>
27 #include <dali/public-api/rendering/decorated-visual-renderer.h>
30 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
31 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
32 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
33 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
34 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
35 #include <dali-toolkit/internal/visuals/image-visual-shader-feature-builder.h>
36 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
37 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
38 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
39 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
50 const int CUSTOM_PROPERTY_COUNT(1); // pixel area,
52 const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
55 DALI_ENUM_TO_STRING_TABLE_BEGIN(STOP_BEHAVIOR)
56 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, CURRENT_FRAME)
57 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, FIRST_FRAME)
58 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, LAST_FRAME)
59 DALI_ENUM_TO_STRING_TABLE_END(STOP_BEHAVIOR)
62 DALI_ENUM_TO_STRING_TABLE_BEGIN(LOOPING_MODE)
63 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, RESTART)
64 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, AUTO_REVERSE)
65 DALI_ENUM_TO_STRING_TABLE_END(LOOPING_MODE)
67 #if defined(DEBUG_ENABLED)
68 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
71 } // unnamed namespace
73 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
75 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, ImageDimensions{}));
76 visual->SetProperties(properties);
81 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
83 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, size));
88 AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
89 : Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)),
92 mVectorAnimationTask(new VectorAnimationTask(factoryCache)),
93 mImageVisualShaderFactory(shaderFactory),
95 mVisualScale(Vector2::ONE),
98 mPlayState(DevelImageVisual::PlayState::STOPPED),
99 mEventCallback(nullptr),
101 mRendererAdded(false),
102 mCoreShutdown(false),
103 mRedrawInScalingDown(true)
105 // the rasterized image is with pre-multiplied alpha format
106 mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA;
108 // By default, load a file synchronously
109 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
112 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
116 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
117 vectorAnimationManager.RemoveObserver(*this);
121 mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
122 mEventCallback = nullptr;
125 // Finalize animation task and disconnect the signal in the main thread
126 mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady);
127 mVectorAnimationTask->Finalize();
131 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
133 // Core is shutting down. Don't talk to the plugin any more.
134 mCoreShutdown = true;
137 void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize)
139 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
141 naturalSize.x = mDesiredSize.GetWidth();
142 naturalSize.y = mDesiredSize.GetHeight();
144 else if(mVisualSize != Vector2::ZERO)
146 naturalSize = mVisualSize;
150 if(mLoadFailed && mImpl->mRenderer)
152 // Load failed, use broken image size
153 auto textureSet = mImpl->mRenderer.GetTextures();
154 if(textureSet && textureSet.GetTextureCount())
156 auto texture = textureSet.GetTexture(0);
159 naturalSize.x = texture.GetWidth();
160 naturalSize.y = texture.GetHeight();
167 uint32_t width, height;
168 mVectorAnimationTask->GetDefaultSize(width, height);
169 naturalSize.x = width;
170 naturalSize.y = height;
174 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this);
177 void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
180 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE);
183 map.Insert(Toolkit::ImageVisual::Property::URL, mUrl.GetUrl());
185 map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount);
187 uint32_t startFrame, endFrame;
188 mVectorAnimationTask->GetPlayRange(startFrame, endFrame);
190 Property::Array playRange;
191 playRange.PushBack(static_cast<int32_t>(startFrame));
192 playRange.PushBack(static_cast<int32_t>(endFrame));
193 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange);
195 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast<int32_t>(mPlayState));
196 map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetCurrentFrameNumber()));
197 map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetTotalFrameNumber()));
199 map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior);
200 map.Insert(Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode);
201 map.Insert(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, mRedrawInScalingDown);
203 Property::Map layerInfo;
204 mVectorAnimationTask->GetLayerInfo(layerInfo);
205 map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo);
207 map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired());
208 map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
209 map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
212 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
217 void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied)
219 // Make always enable pre multiplied alpha whether preMultiplied value is false.
222 DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n");
226 void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap)
228 // url already passed in from constructor
229 for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
231 KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
232 if(keyValue.first.type == Property::Key::INDEX)
234 DoSetProperty(keyValue.first.indexKey, keyValue.second);
238 if(keyValue.first == LOOP_COUNT_NAME)
240 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second);
242 else if(keyValue.first == PLAY_RANGE_NAME)
244 DoSetProperty(Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second);
246 else if(keyValue.first == STOP_BEHAVIOR_NAME)
248 DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
250 else if(keyValue.first == LOOPING_MODE_NAME)
252 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second);
254 else if(keyValue.first == REDRAW_IN_SCALING_DOWN_NAME)
256 DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second);
258 else if(keyValue.first == SYNCHRONOUS_LOADING)
260 DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
262 else if(keyValue.first == IMAGE_DESIRED_WIDTH)
264 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second);
266 else if(keyValue.first == IMAGE_DESIRED_HEIGHT)
268 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second);
273 TriggerVectorRasterization();
276 void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
280 case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
283 if(value.Get(loopCount))
285 mAnimationData.loopCount = loopCount;
286 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
290 case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
292 const Property::Array* array = value.GetArray();
295 mAnimationData.playRange = *array;
296 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
298 else if(value.GetType() == Property::STRING)
300 std::string markerName;
301 if(value.Get(markerName))
303 Property::Array array;
304 array.Add(markerName);
305 mAnimationData.playRange = std::move(array);
306 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
311 case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
313 int32_t stopBehavior = mAnimationData.stopBehavior;
314 if(Scripting::GetEnumerationProperty(value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior))
316 mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type(stopBehavior);
317 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
321 case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
323 int32_t loopingMode = mAnimationData.loopingMode;
324 if(Scripting::GetEnumerationProperty(value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode))
326 mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type(loopingMode);
327 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
331 case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
334 if(value.Get(redraw))
336 mRedrawInScalingDown = redraw;
340 case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
347 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
351 mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
356 case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
358 int32_t desiredWidth = 0;
359 if(value.Get(desiredWidth))
361 mDesiredSize.SetWidth(desiredWidth);
366 case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
368 int32_t desiredHeight = 0;
369 if(value.Get(desiredHeight))
371 mDesiredSize.SetHeight(desiredHeight);
378 void AnimatedVectorImageVisual::OnInitialize(void)
380 mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
381 mVectorAnimationTask->SetAnimationFinishedCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished));
383 mVectorAnimationTask->RequestLoad(mUrl.GetUrl(), IsSynchronousLoadingRequired());
385 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
386 vectorAnimationManager.AddObserver(*this);
388 Shader shader = GenerateShader();
390 Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
392 mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
393 mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
395 TextureSet textureSet = TextureSet::New();
396 mImpl->mRenderer.SetTextures(textureSet);
398 // Register transform properties
399 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
401 mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
404 void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
406 // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
408 // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
409 mPlacementActor = actor;
413 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
414 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
415 actor.AddRenderer(mImpl->mRenderer);
416 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
420 // Add property notification for scaling & size
421 mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
422 mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
424 mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
425 mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
427 DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
429 Window window = DevelWindow::Get(actor);
432 DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
435 if(mImpl->mEventObserver)
437 // The visual needs it's size set before it can be rasterized hence request relayout once on stage
438 mImpl->mEventObserver->RelayoutRequest(*this);
441 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY;
442 TriggerVectorRasterization();
445 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
448 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
451 TriggerVectorRasterization();
455 actor.RemoveRenderer(mImpl->mRenderer);
456 mRendererAdded = false;
459 // Remove property notification
460 actor.RemovePropertyNotification(mScaleNotification);
461 actor.RemovePropertyNotification(mSizeNotification);
463 DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
465 Window window = DevelWindow::Get(actor);
468 DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
471 mPlacementActor.Reset();
473 // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
474 mVisualSize = Vector2::ZERO;
475 mVisualScale = Vector2::ONE;
476 mAnimationData.width = 0;
477 mAnimationData.height = 0;
479 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this);
482 void AnimatedVectorImageVisual::OnSetTransform()
484 Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
486 if(IsOnScene() && visualSize != mVisualSize)
488 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this);
490 mVisualSize = visualSize;
492 SetVectorImageSize();
494 if(mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
496 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
497 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
500 TriggerVectorRasterization();
504 void AnimatedVectorImageVisual::UpdateShader()
508 Shader shader = GenerateShader();
509 mImpl->mRenderer.SetShader(shader);
513 void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
515 // Check if action is valid for this visual type and perform action if possible
518 case DevelAnimatedVectorImageVisual::Action::PLAY:
520 if(IsOnScene() && mVisualSize != Vector2::ZERO)
522 if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
524 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
525 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
528 mPlayState = DevelImageVisual::PlayState::PLAYING;
531 case DevelAnimatedVectorImageVisual::Action::PAUSE:
533 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
535 mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
536 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
538 mPlayState = DevelImageVisual::PlayState::PAUSED;
541 case DevelAnimatedVectorImageVisual::Action::STOP:
543 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
545 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
546 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
548 mPlayState = DevelImageVisual::PlayState::STOPPED;
551 case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
554 if(attributes.Get(frameNumber))
556 mAnimationData.currentFrame = frameNumber;
557 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
561 case DevelAnimatedVectorImageVisual::Action::FLUSH:
563 if(DALI_LIKELY(!mCoreShutdown))
571 TriggerVectorRasterization();
574 void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, Dali::Any attributes)
578 case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY:
580 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>(attributes);
581 mAnimationData.dynamicProperties.push_back(info);
582 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY;
587 TriggerVectorRasterization();
590 void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
592 if(status == VectorAnimationTask::ResourceStatus::LOADED)
594 if(mImpl->mEventObserver)
596 mImpl->mEventObserver->RelayoutRequest(*this);
601 mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
603 // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
604 Actor actor = mPlacementActor.GetHandle();
605 if(actor && !mRendererAdded)
609 actor.AddRenderer(mImpl->mRenderer);
610 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
614 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
615 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
616 actor.AddRenderer(mImpl->mRenderer);
617 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
620 mRendererAdded = true;
624 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this);
627 void AnimatedVectorImageVisual::OnAnimationFinished()
629 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this);
631 if(mPlayState != DevelImageVisual::PlayState::STOPPED)
633 mPlayState = DevelImageVisual::PlayState::STOPPED;
635 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
637 if(mImpl->mEventObserver)
639 mImpl->mEventObserver->NotifyVisualEvent(*this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED);
645 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
649 void AnimatedVectorImageVisual::SendAnimationData()
651 if(mAnimationData.resendFlag)
653 mVectorAnimationTask->SetAnimationData(mAnimationData);
657 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
659 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
663 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
667 mAnimationData.resendFlag = 0;
671 void AnimatedVectorImageVisual::SetVectorImageSize()
673 uint32_t width, height;
674 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
676 width = mDesiredSize.GetWidth();
677 height = mDesiredSize.GetHeight();
681 width = static_cast<uint32_t>(mVisualSize.width * mVisualScale.width);
682 height = static_cast<uint32_t>(mVisualSize.height * mVisualScale.height);
685 if(mAnimationData.width != width || mAnimationData.height != height)
687 mAnimationData.width = width;
688 mAnimationData.height = height;
689 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
693 void AnimatedVectorImageVisual::StopAnimation()
695 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
697 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
698 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
700 mPlayState = DevelImageVisual::PlayState::STOPPED;
704 void AnimatedVectorImageVisual::TriggerVectorRasterization()
706 if(!mEventCallback && !mCoreShutdown)
708 mEventCallback = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents);
709 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
710 vectorAnimationManager.RegisterEventCallback(mEventCallback);
711 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
715 void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source)
717 Actor actor = mPlacementActor.GetHandle();
720 Vector3 scale = actor.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
722 if((!Dali::Equals(mVisualScale.width, scale.width) || !Dali::Equals(mVisualScale.height, scale.height)) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f))
724 mVisualScale.width = scale.width;
725 mVisualScale.height = scale.height;
727 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this);
729 SetVectorImageSize();
732 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
737 void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source)
739 Actor actor = mPlacementActor.GetHandle();
742 Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
744 if(!Dali::Equals(mVisualSize.width, size.width) || !Dali::Equals(mVisualSize.height, size.height))
746 mVisualSize.width = size.width;
747 mVisualSize.height = size.height;
749 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this);
751 SetVectorImageSize();
754 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
759 void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
764 TriggerVectorRasterization();
766 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
770 void AnimatedVectorImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
775 TriggerVectorRasterization();
777 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
781 void AnimatedVectorImageVisual::OnProcessEvents()
785 mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager
788 Shader AnimatedVectorImageVisual::GenerateShader() const
791 if(mImpl->mCustomShader)
793 shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
794 mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
795 mImpl->mCustomShader->mHints);
797 shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
801 shader = mImageVisualShaderFactory.GetShader(
803 ImageVisualShaderFeatureBuilder()
804 .EnableRoundedCorner(IsRoundedCornerRequired())
805 .EnableBorderline(IsBorderlineRequired()));
810 } // namespace Internal
812 } // namespace Toolkit