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 if(mImageUrl.IsBufferResource())
118 TextureManager& textureManager = mFactoryCache.GetTextureManager();
119 textureManager.RemoveEncodedImageBuffer(mImageUrl.GetUrl());
122 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
123 vectorAnimationManager.RemoveObserver(*this);
127 mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
128 mEventCallback = nullptr;
131 // Finalize animation task and disconnect the signal in the main thread
132 mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady);
133 mVectorAnimationTask->Finalize();
137 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
139 // Core is shutting down. Don't talk to the plugin any more.
140 mCoreShutdown = true;
143 void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize)
145 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
147 naturalSize.x = mDesiredSize.GetWidth();
148 naturalSize.y = mDesiredSize.GetHeight();
150 else if(mVisualSize != Vector2::ZERO)
152 naturalSize = mVisualSize;
156 if(mLoadFailed && mImpl->mRenderer)
158 // Load failed, use broken image size
159 auto textureSet = mImpl->mRenderer.GetTextures();
160 if(textureSet && textureSet.GetTextureCount())
162 auto texture = textureSet.GetTexture(0);
165 naturalSize.x = texture.GetWidth();
166 naturalSize.y = texture.GetHeight();
173 uint32_t width, height;
174 mVectorAnimationTask->GetDefaultSize(width, height);
175 naturalSize.x = width;
176 naturalSize.y = height;
180 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this);
183 void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
186 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE);
187 if(mImageUrl.IsValid())
189 map.Insert(Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl());
191 map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount);
193 uint32_t startFrame, endFrame;
194 mVectorAnimationTask->GetPlayRange(startFrame, endFrame);
196 Property::Array playRange;
197 playRange.PushBack(static_cast<int32_t>(startFrame));
198 playRange.PushBack(static_cast<int32_t>(endFrame));
199 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange);
201 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast<int32_t>(mPlayState));
202 map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetCurrentFrameNumber()));
203 map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetTotalFrameNumber()));
205 map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior);
206 map.Insert(Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode);
207 map.Insert(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, mRedrawInScalingDown);
209 Property::Map layerInfo;
210 mVectorAnimationTask->GetLayerInfo(layerInfo);
211 map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo);
213 Property::Map markerInfo;
214 mVectorAnimationTask->GetMarkerInfo(markerInfo);
215 map.Insert(Toolkit::DevelImageVisual::Property::MARKER_INFO, markerInfo);
217 map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired());
218 map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
219 map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
222 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
227 void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied)
229 // Make always enable pre multiplied alpha whether preMultiplied value is false.
232 DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n");
236 void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap)
238 // url already passed in from constructor
239 for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
241 KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
242 if(keyValue.first.type == Property::Key::INDEX)
244 DoSetProperty(keyValue.first.indexKey, keyValue.second);
248 if(keyValue.first == LOOP_COUNT_NAME)
250 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second);
252 else if(keyValue.first == PLAY_RANGE_NAME)
254 DoSetProperty(Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second);
256 else if(keyValue.first == STOP_BEHAVIOR_NAME)
258 DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
260 else if(keyValue.first == LOOPING_MODE_NAME)
262 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second);
264 else if(keyValue.first == REDRAW_IN_SCALING_DOWN_NAME)
266 DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second);
268 else if(keyValue.first == SYNCHRONOUS_LOADING)
270 DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
272 else if(keyValue.first == IMAGE_DESIRED_WIDTH)
274 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second);
276 else if(keyValue.first == IMAGE_DESIRED_HEIGHT)
278 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second);
283 TriggerVectorRasterization();
286 void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
290 case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
293 if(value.Get(loopCount))
295 mAnimationData.loopCount = loopCount;
296 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
300 case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
302 const Property::Array* array = value.GetArray();
305 mAnimationData.playRange = *array;
306 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
308 else if(value.GetType() == Property::STRING)
310 std::string markerName;
311 if(value.Get(markerName))
313 Property::Array array;
314 array.Add(markerName);
315 mAnimationData.playRange = std::move(array);
316 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
321 case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
323 int32_t stopBehavior = mAnimationData.stopBehavior;
324 if(Scripting::GetEnumerationProperty(value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior))
326 mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type(stopBehavior);
327 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
331 case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
333 int32_t loopingMode = mAnimationData.loopingMode;
334 if(Scripting::GetEnumerationProperty(value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode))
336 mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type(loopingMode);
337 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
341 case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
344 if(value.Get(redraw))
346 mRedrawInScalingDown = redraw;
350 case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
357 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
361 mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
366 case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
368 int32_t desiredWidth = 0;
369 if(value.Get(desiredWidth))
371 mDesiredSize.SetWidth(desiredWidth);
376 case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
378 int32_t desiredHeight = 0;
379 if(value.Get(desiredHeight))
381 mDesiredSize.SetHeight(desiredHeight);
388 void AnimatedVectorImageVisual::OnInitialize(void)
390 mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
391 mVectorAnimationTask->SetAnimationFinishedCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished));
393 EncodedImageBuffer encodedImageBuffer;
395 if(mImageUrl.IsBufferResource())
397 // Increase reference count of External Resources :
398 // EncodedImageBuffer.
399 // Reference count will be decreased at destructor of the visual.
400 TextureManager& textureManager = mFactoryCache.GetTextureManager();
401 textureManager.UseExternalResource(mImageUrl.GetUrl());
403 encodedImageBuffer = textureManager.GetEncodedImageBuffer(mImageUrl.GetUrl());
406 mVectorAnimationTask->RequestLoad(mImageUrl, encodedImageBuffer, IsSynchronousLoadingRequired());
408 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
409 vectorAnimationManager.AddObserver(*this);
411 Shader shader = GenerateShader();
413 Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
415 mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
416 mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
418 TextureSet textureSet = TextureSet::New();
419 mImpl->mRenderer.SetTextures(textureSet);
421 // Register transform properties
422 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
424 mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
427 void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
429 // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
431 // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
432 mPlacementActor = actor;
436 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
437 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
438 actor.AddRenderer(mImpl->mRenderer);
439 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
443 // Add property notification for scaling & size
444 mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
445 mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
447 mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
448 mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
450 DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
452 Window window = DevelWindow::Get(actor);
455 DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
458 if(mImpl->mEventObserver)
460 // The visual needs it's size set before it can be rasterized hence request relayout once on stage
461 mImpl->mEventObserver->RelayoutRequest(*this);
464 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY;
465 TriggerVectorRasterization();
468 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
471 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
474 TriggerVectorRasterization();
478 actor.RemoveRenderer(mImpl->mRenderer);
479 mRendererAdded = false;
482 // Remove property notification
483 actor.RemovePropertyNotification(mScaleNotification);
484 actor.RemovePropertyNotification(mSizeNotification);
486 DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
488 Window window = DevelWindow::Get(actor);
491 DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
494 mPlacementActor.Reset();
496 // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
497 mVisualSize = Vector2::ZERO;
498 mVisualScale = Vector2::ONE;
499 mAnimationData.width = 0;
500 mAnimationData.height = 0;
502 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this);
505 void AnimatedVectorImageVisual::OnSetTransform()
507 Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
509 if(IsOnScene() && visualSize != mVisualSize)
511 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this);
513 mVisualSize = visualSize;
515 SetVectorImageSize();
517 if(mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
519 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
520 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
523 TriggerVectorRasterization();
527 void AnimatedVectorImageVisual::UpdateShader()
531 Shader shader = GenerateShader();
532 mImpl->mRenderer.SetShader(shader);
536 void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
538 // Check if action is valid for this visual type and perform action if possible
541 case DevelAnimatedVectorImageVisual::Action::PLAY:
543 if(IsOnScene() && mVisualSize != Vector2::ZERO)
545 if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
547 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
548 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
551 mPlayState = DevelImageVisual::PlayState::PLAYING;
554 case DevelAnimatedVectorImageVisual::Action::PAUSE:
556 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
558 mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
559 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
561 mPlayState = DevelImageVisual::PlayState::PAUSED;
564 case DevelAnimatedVectorImageVisual::Action::STOP:
566 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
568 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
569 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
571 mPlayState = DevelImageVisual::PlayState::STOPPED;
574 case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
577 if(attributes.Get(frameNumber))
579 mAnimationData.currentFrame = frameNumber;
580 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
584 case DevelAnimatedVectorImageVisual::Action::FLUSH:
586 if(DALI_LIKELY(!mCoreShutdown))
594 TriggerVectorRasterization();
597 void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, Dali::Any attributes)
601 case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY:
603 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>(attributes);
604 mAnimationData.dynamicProperties.push_back(info);
605 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY;
610 TriggerVectorRasterization();
613 void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
615 AnimatedVectorImageVisualPtr self = this; // Keep reference until this API finished
617 if(status == VectorAnimationTask::ResourceStatus::LOADED)
619 if(mImpl->mEventObserver)
621 mImpl->mEventObserver->RelayoutRequest(*this);
626 mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
628 // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
629 Actor actor = mPlacementActor.GetHandle();
630 if(actor && !mRendererAdded)
634 actor.AddRenderer(mImpl->mRenderer);
635 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
639 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
640 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
641 actor.AddRenderer(mImpl->mRenderer);
642 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
645 mRendererAdded = true;
649 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this);
652 void AnimatedVectorImageVisual::OnAnimationFinished()
654 AnimatedVectorImageVisualPtr self = this; // Keep reference until this API finished
656 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this);
658 if(mPlayState != DevelImageVisual::PlayState::STOPPED)
660 mPlayState = DevelImageVisual::PlayState::STOPPED;
662 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
664 if(mImpl->mEventObserver)
666 mImpl->mEventObserver->NotifyVisualEvent(*this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED);
672 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
676 void AnimatedVectorImageVisual::SendAnimationData()
678 if(mAnimationData.resendFlag)
680 mVectorAnimationTask->SetAnimationData(mAnimationData);
684 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
686 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
690 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
694 mAnimationData.resendFlag = 0;
698 void AnimatedVectorImageVisual::SetVectorImageSize()
700 uint32_t width, height;
701 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
703 width = mDesiredSize.GetWidth();
704 height = mDesiredSize.GetHeight();
708 width = static_cast<uint32_t>(mVisualSize.width * mVisualScale.width);
709 height = static_cast<uint32_t>(mVisualSize.height * mVisualScale.height);
712 if(mAnimationData.width != width || mAnimationData.height != height)
714 mAnimationData.width = width;
715 mAnimationData.height = height;
716 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
720 void AnimatedVectorImageVisual::StopAnimation()
722 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
724 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
725 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
727 mPlayState = DevelImageVisual::PlayState::STOPPED;
731 void AnimatedVectorImageVisual::TriggerVectorRasterization()
733 if(!mEventCallback && !mCoreShutdown)
735 mEventCallback = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents);
736 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
737 vectorAnimationManager.RegisterEventCallback(mEventCallback);
738 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
742 void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source)
744 Actor actor = mPlacementActor.GetHandle();
747 Vector3 scale = actor.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
749 if((!Dali::Equals(mVisualScale.width, scale.width) || !Dali::Equals(mVisualScale.height, scale.height)) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f))
751 mVisualScale.width = scale.width;
752 mVisualScale.height = scale.height;
754 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this);
756 SetVectorImageSize();
759 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
764 void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source)
766 Actor actor = mPlacementActor.GetHandle();
769 Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
771 if(!Dali::Equals(mVisualSize.width, size.width) || !Dali::Equals(mVisualSize.height, size.height))
773 mVisualSize.width = size.width;
774 mVisualSize.height = size.height;
776 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this);
778 SetVectorImageSize();
781 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
786 void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
791 TriggerVectorRasterization();
793 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
797 void AnimatedVectorImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
802 TriggerVectorRasterization();
804 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
808 void AnimatedVectorImageVisual::OnProcessEvents()
812 mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager
815 Shader AnimatedVectorImageVisual::GenerateShader() const
818 if(mImpl->mCustomShader)
820 shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
821 mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
822 mImpl->mCustomShader->mHints);
824 shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
828 shader = mImageVisualShaderFactory.GetShader(
830 ImageVisualShaderFeatureBuilder()
831 .EnableRoundedCorner(IsRoundedCornerRequired())
832 .EnableBorderline(IsBorderlineRequired()));
837 } // namespace Internal
839 } // namespace Toolkit