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),
104 mEnableFrameCache(false)
106 // the rasterized image is with pre-multiplied alpha format
107 mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA;
109 // By default, load a file synchronously
110 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
113 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
117 if(mImageUrl.IsBufferResource())
119 TextureManager& textureManager = mFactoryCache.GetTextureManager();
120 textureManager.RemoveEncodedImageBuffer(mImageUrl.GetUrl());
123 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
124 vectorAnimationManager.RemoveObserver(*this);
128 mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
129 mEventCallback = nullptr;
132 // Finalize animation task and disconnect the signal in the main thread
133 mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady);
134 mVectorAnimationTask->Finalize();
138 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
140 // Core is shutting down. Don't talk to the plugin any more.
141 mCoreShutdown = true;
144 void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize)
146 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
148 naturalSize.x = mDesiredSize.GetWidth();
149 naturalSize.y = mDesiredSize.GetHeight();
151 else if(mVisualSize != Vector2::ZERO)
153 naturalSize = mVisualSize;
157 if(mLoadFailed && mImpl->mRenderer)
159 // Load failed, use broken image size
160 auto textureSet = mImpl->mRenderer.GetTextures();
161 if(textureSet && textureSet.GetTextureCount())
163 auto texture = textureSet.GetTexture(0);
166 naturalSize.x = texture.GetWidth();
167 naturalSize.y = texture.GetHeight();
174 uint32_t width, height;
175 mVectorAnimationTask->GetDefaultSize(width, height);
176 naturalSize.x = width;
177 naturalSize.y = height;
181 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this);
184 void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
187 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE);
188 if(mImageUrl.IsValid())
190 map.Insert(Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl());
192 map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount);
194 uint32_t startFrame, endFrame;
195 mVectorAnimationTask->GetPlayRange(startFrame, endFrame);
197 Property::Array playRange;
198 playRange.PushBack(static_cast<int32_t>(startFrame));
199 playRange.PushBack(static_cast<int32_t>(endFrame));
200 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange);
202 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast<int32_t>(mPlayState));
203 map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetCurrentFrameNumber()));
204 map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetTotalFrameNumber()));
206 map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior);
207 map.Insert(Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode);
208 map.Insert(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, mRedrawInScalingDown);
210 Property::Map layerInfo;
211 mVectorAnimationTask->GetLayerInfo(layerInfo);
212 map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo);
214 Property::Map markerInfo;
215 mVectorAnimationTask->GetMarkerInfo(markerInfo);
216 map.Insert(Toolkit::DevelImageVisual::Property::MARKER_INFO, markerInfo);
218 map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired());
219 map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
220 map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
221 map.Insert(Toolkit::DevelImageVisual::Property::ENABLE_FRAME_CACHE, mEnableFrameCache);
224 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
229 void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied)
231 // Make always enable pre multiplied alpha whether preMultiplied value is false.
234 DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n");
238 void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap)
240 // url already passed in from constructor
241 for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
243 KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
244 if(keyValue.first.type == Property::Key::INDEX)
246 DoSetProperty(keyValue.first.indexKey, keyValue.second);
250 if(keyValue.first == LOOP_COUNT_NAME)
252 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second);
254 else if(keyValue.first == PLAY_RANGE_NAME)
256 DoSetProperty(Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second);
258 else if(keyValue.first == STOP_BEHAVIOR_NAME)
260 DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
262 else if(keyValue.first == LOOPING_MODE_NAME)
264 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second);
266 else if(keyValue.first == REDRAW_IN_SCALING_DOWN_NAME)
268 DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second);
270 else if(keyValue.first == SYNCHRONOUS_LOADING)
272 DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
274 else if(keyValue.first == IMAGE_DESIRED_WIDTH)
276 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second);
278 else if(keyValue.first == IMAGE_DESIRED_HEIGHT)
280 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second);
282 else if(keyValue.first == ENABLE_FRAME_CACHE)
284 DoSetProperty(Toolkit::DevelImageVisual::Property::ENABLE_FRAME_CACHE, keyValue.second);
289 TriggerVectorRasterization();
292 void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
296 case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
299 if(value.Get(loopCount))
301 mAnimationData.loopCount = loopCount;
302 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
306 case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
308 const Property::Array* array = value.GetArray();
311 mAnimationData.playRange = *array;
312 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
314 else if(value.GetType() == Property::STRING)
316 std::string markerName;
317 if(value.Get(markerName))
319 Property::Array array;
320 array.Add(markerName);
321 mAnimationData.playRange = std::move(array);
322 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
327 case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
329 int32_t stopBehavior = mAnimationData.stopBehavior;
330 if(Scripting::GetEnumerationProperty(value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior))
332 mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type(stopBehavior);
333 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
337 case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
339 int32_t loopingMode = mAnimationData.loopingMode;
340 if(Scripting::GetEnumerationProperty(value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode))
342 mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type(loopingMode);
343 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
347 case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
350 if(value.Get(redraw))
352 mRedrawInScalingDown = redraw;
356 case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
363 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
367 mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
372 case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
374 int32_t desiredWidth = 0;
375 if(value.Get(desiredWidth))
377 mDesiredSize.SetWidth(desiredWidth);
382 case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
384 int32_t desiredHeight = 0;
385 if(value.Get(desiredHeight))
387 mDesiredSize.SetHeight(desiredHeight);
392 case Toolkit::DevelImageVisual::Property::ENABLE_FRAME_CACHE:
394 bool enableFrameCache = false;
395 if(value.Get(enableFrameCache))
397 mEnableFrameCache = enableFrameCache;
398 if(mVectorAnimationTask)
400 mVectorAnimationTask->KeepRasterizedBuffer(mEnableFrameCache);
408 void AnimatedVectorImageVisual::OnInitialize(void)
410 mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
411 mVectorAnimationTask->SetAnimationFinishedCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished));
413 EncodedImageBuffer encodedImageBuffer;
415 if(mImageUrl.IsBufferResource())
417 // Increase reference count of External Resources :
418 // EncodedImageBuffer.
419 // Reference count will be decreased at destructor of the visual.
420 TextureManager& textureManager = mFactoryCache.GetTextureManager();
421 textureManager.UseExternalResource(mImageUrl.GetUrl());
423 encodedImageBuffer = textureManager.GetEncodedImageBuffer(mImageUrl.GetUrl());
426 mVectorAnimationTask->KeepRasterizedBuffer(mEnableFrameCache);
427 mVectorAnimationTask->RequestLoad(mImageUrl, encodedImageBuffer, IsSynchronousLoadingRequired());
429 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
430 vectorAnimationManager.AddObserver(*this);
432 Shader shader = GenerateShader();
434 Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
436 mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
437 mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
439 TextureSet textureSet = TextureSet::New();
440 mImpl->mRenderer.SetTextures(textureSet);
442 // Register transform properties
443 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
445 mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
448 void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
450 // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
452 // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
453 mPlacementActor = actor;
457 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
458 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
459 actor.AddRenderer(mImpl->mRenderer);
460 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
464 // Add property notification for scaling & size
465 mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
466 mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
468 mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
469 mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
471 DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
473 Window window = DevelWindow::Get(actor);
476 DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
479 if(mImpl->mEventObserver)
481 // The visual needs it's size set before it can be rasterized hence request relayout once on stage
482 mImpl->mEventObserver->RelayoutRequest(*this);
485 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY;
486 TriggerVectorRasterization();
489 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
492 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
495 TriggerVectorRasterization();
499 actor.RemoveRenderer(mImpl->mRenderer);
500 mRendererAdded = false;
503 // Remove property notification
504 actor.RemovePropertyNotification(mScaleNotification);
505 actor.RemovePropertyNotification(mSizeNotification);
507 DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
509 Window window = DevelWindow::Get(actor);
512 DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
515 mPlacementActor.Reset();
517 // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
518 mVisualSize = Vector2::ZERO;
519 mVisualScale = Vector2::ONE;
520 mAnimationData.width = 0;
521 mAnimationData.height = 0;
523 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this);
526 void AnimatedVectorImageVisual::OnSetTransform()
528 Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
530 if(IsOnScene() && visualSize != mVisualSize)
532 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this);
534 mVisualSize = visualSize;
536 SetVectorImageSize();
538 if(mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
540 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
541 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
544 TriggerVectorRasterization();
548 void AnimatedVectorImageVisual::UpdateShader()
552 Shader shader = GenerateShader();
553 mImpl->mRenderer.SetShader(shader);
557 void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
559 // Check if action is valid for this visual type and perform action if possible
562 case DevelAnimatedVectorImageVisual::Action::PLAY:
564 if(IsOnScene() && mVisualSize != Vector2::ZERO)
566 if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
568 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
569 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
572 mPlayState = DevelImageVisual::PlayState::PLAYING;
575 case DevelAnimatedVectorImageVisual::Action::PAUSE:
577 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
579 mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
580 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
582 mPlayState = DevelImageVisual::PlayState::PAUSED;
585 case DevelAnimatedVectorImageVisual::Action::STOP:
587 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
589 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
590 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
592 mPlayState = DevelImageVisual::PlayState::STOPPED;
595 case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
598 if(attributes.Get(frameNumber))
600 mAnimationData.currentFrame = frameNumber;
601 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
605 case DevelAnimatedVectorImageVisual::Action::FLUSH:
607 if(DALI_LIKELY(!mCoreShutdown))
615 TriggerVectorRasterization();
618 void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, Dali::Any attributes)
622 case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY:
624 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>(attributes);
625 mAnimationData.dynamicProperties.push_back(info);
626 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY;
631 TriggerVectorRasterization();
634 void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
636 AnimatedVectorImageVisualPtr self = this; // Keep reference until this API finished
638 if(status == VectorAnimationTask::ResourceStatus::LOADED)
640 if(mImpl->mEventObserver)
642 mImpl->mEventObserver->RelayoutRequest(*this);
647 mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
649 // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
650 Actor actor = mPlacementActor.GetHandle();
651 if(actor && !mRendererAdded)
655 actor.AddRenderer(mImpl->mRenderer);
656 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
660 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
661 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
662 actor.AddRenderer(mImpl->mRenderer);
663 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
666 mRendererAdded = true;
670 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this);
673 void AnimatedVectorImageVisual::OnAnimationFinished()
675 AnimatedVectorImageVisualPtr self = this; // Keep reference until this API finished
677 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this);
679 if(mPlayState != DevelImageVisual::PlayState::STOPPED)
681 mPlayState = DevelImageVisual::PlayState::STOPPED;
683 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
685 if(mImpl->mEventObserver)
687 mImpl->mEventObserver->NotifyVisualEvent(*this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED);
693 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
697 void AnimatedVectorImageVisual::SendAnimationData()
699 if(mAnimationData.resendFlag)
701 mVectorAnimationTask->SetAnimationData(mAnimationData);
705 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
707 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
711 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
715 mAnimationData.resendFlag = 0;
719 void AnimatedVectorImageVisual::SetVectorImageSize()
721 uint32_t width, height;
722 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
724 width = mDesiredSize.GetWidth();
725 height = mDesiredSize.GetHeight();
729 width = static_cast<uint32_t>(mVisualSize.width * mVisualScale.width);
730 height = static_cast<uint32_t>(mVisualSize.height * mVisualScale.height);
733 if(mAnimationData.width != width || mAnimationData.height != height)
735 mAnimationData.width = width;
736 mAnimationData.height = height;
737 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
741 void AnimatedVectorImageVisual::StopAnimation()
743 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
745 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
746 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
748 mPlayState = DevelImageVisual::PlayState::STOPPED;
752 void AnimatedVectorImageVisual::TriggerVectorRasterization()
754 if(!mEventCallback && !mCoreShutdown)
756 mEventCallback = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents);
757 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
758 vectorAnimationManager.RegisterEventCallback(mEventCallback);
759 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
763 void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source)
765 Actor actor = mPlacementActor.GetHandle();
768 Vector3 scale = actor.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
770 if((!Dali::Equals(mVisualScale.width, scale.width) || !Dali::Equals(mVisualScale.height, scale.height)) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f))
772 mVisualScale.width = scale.width;
773 mVisualScale.height = scale.height;
775 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this);
777 SetVectorImageSize();
780 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
785 void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source)
787 Actor actor = mPlacementActor.GetHandle();
790 Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
792 if(!Dali::Equals(mVisualSize.width, size.width) || !Dali::Equals(mVisualSize.height, size.height))
794 mVisualSize.width = size.width;
795 mVisualSize.height = size.height;
797 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this);
799 SetVectorImageSize();
802 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
807 void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
812 TriggerVectorRasterization();
814 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
818 void AnimatedVectorImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
823 TriggerVectorRasterization();
825 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
829 void AnimatedVectorImageVisual::OnProcessEvents()
833 mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager
836 Shader AnimatedVectorImageVisual::GenerateShader() const
839 if(mImpl->mCustomShader)
841 shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
842 mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
843 mImpl->mCustomShader->mHints);
845 shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
849 shader = mImageVisualShaderFactory.GetShader(
851 ImageVisualShaderFeatureBuilder()
852 .EnableRoundedCorner(IsRoundedCornerRequired())
853 .EnableBorderline(IsBorderlineRequired()));
858 } // namespace Internal
860 } // namespace Toolkit