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/visual-base-data-impl.h>
36 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
37 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
38 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
39 #include <dali-toolkit/public-api/visuals/visual-properties.h>
49 const int CUSTOM_PROPERTY_COUNT(1); // pixel area,
51 const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
54 DALI_ENUM_TO_STRING_TABLE_BEGIN(STOP_BEHAVIOR)
55 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, CURRENT_FRAME)
56 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, FIRST_FRAME)
57 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, LAST_FRAME)
58 DALI_ENUM_TO_STRING_TABLE_END(STOP_BEHAVIOR)
61 DALI_ENUM_TO_STRING_TABLE_BEGIN(LOOPING_MODE)
62 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, RESTART)
63 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, AUTO_REVERSE)
64 DALI_ENUM_TO_STRING_TABLE_END(LOOPING_MODE)
66 #if defined(DEBUG_ENABLED)
67 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
70 } // unnamed namespace
72 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
74 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, ImageDimensions{}));
75 visual->SetProperties(properties);
80 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
82 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, size));
87 AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
88 : Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)),
91 mVectorAnimationTask(new VectorAnimationTask(factoryCache)),
92 mImageVisualShaderFactory(shaderFactory),
94 mVisualScale(Vector2::ONE),
97 mPlayState(DevelImageVisual::PlayState::STOPPED),
98 mEventCallback(nullptr),
100 mRendererAdded(false),
101 mCoreShutdown(false),
102 mRedrawInScalingDown(true)
104 // the rasterized image is with pre-multiplied alpha format
105 mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA;
107 // By default, load a file synchronously
108 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
111 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
115 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
116 vectorAnimationManager.RemoveObserver(*this);
120 mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
121 mEventCallback = nullptr;
124 // Finalize animation task and disconnect the signal in the main thread
125 mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady);
126 mVectorAnimationTask->Finalize();
130 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
132 // Core is shutting down. Don't talk to the plugin any more.
133 mCoreShutdown = true;
136 void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize)
138 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
140 naturalSize.x = mDesiredSize.GetWidth();
141 naturalSize.y = mDesiredSize.GetHeight();
143 else if(mVisualSize != Vector2::ZERO)
145 naturalSize = mVisualSize;
149 if(mLoadFailed && mImpl->mRenderer)
151 // Load failed, use broken image size
152 auto textureSet = mImpl->mRenderer.GetTextures();
153 if(textureSet && textureSet.GetTextureCount())
155 auto texture = textureSet.GetTexture(0);
158 naturalSize.x = texture.GetWidth();
159 naturalSize.y = texture.GetHeight();
166 uint32_t width, height;
167 mVectorAnimationTask->GetDefaultSize(width, height);
168 naturalSize.x = width;
169 naturalSize.y = height;
173 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this);
176 void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
179 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE);
182 map.Insert(Toolkit::ImageVisual::Property::URL, mUrl.GetUrl());
184 map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount);
186 uint32_t startFrame, endFrame;
187 mVectorAnimationTask->GetPlayRange(startFrame, endFrame);
189 Property::Array playRange;
190 playRange.PushBack(static_cast<int32_t>(startFrame));
191 playRange.PushBack(static_cast<int32_t>(endFrame));
192 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange);
194 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast<int32_t>(mPlayState));
195 map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetCurrentFrameNumber()));
196 map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetTotalFrameNumber()));
198 map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior);
199 map.Insert(Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode);
200 map.Insert(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, mRedrawInScalingDown);
202 Property::Map layerInfo;
203 mVectorAnimationTask->GetLayerInfo(layerInfo);
204 map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo);
206 map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired());
207 map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
208 map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
211 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
216 void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied)
218 // Make always enable pre multiplied alpha whether preMultiplied value is false.
221 DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n");
225 void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap)
227 // url already passed in from constructor
228 for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
230 KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
231 if(keyValue.first.type == Property::Key::INDEX)
233 DoSetProperty(keyValue.first.indexKey, keyValue.second);
237 if(keyValue.first == LOOP_COUNT_NAME)
239 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second);
241 else if(keyValue.first == PLAY_RANGE_NAME)
243 DoSetProperty(Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second);
245 else if(keyValue.first == STOP_BEHAVIOR_NAME)
247 DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
249 else if(keyValue.first == LOOPING_MODE_NAME)
251 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second);
253 else if(keyValue.first == REDRAW_IN_SCALING_DOWN_NAME)
255 DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second);
257 else if(keyValue.first == SYNCHRONOUS_LOADING)
259 DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
261 else if(keyValue.first == IMAGE_DESIRED_WIDTH)
263 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second);
265 else if(keyValue.first == IMAGE_DESIRED_HEIGHT)
267 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second);
272 TriggerVectorRasterization();
275 void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
279 case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
282 if(value.Get(loopCount))
284 mAnimationData.loopCount = loopCount;
285 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
289 case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
291 const Property::Array* array = value.GetArray();
294 mAnimationData.playRange = *array;
295 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
297 else if(value.GetType() == Property::STRING)
299 std::string markerName;
300 if(value.Get(markerName))
302 Property::Array array;
303 array.Add(markerName);
304 mAnimationData.playRange = std::move(array);
305 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
310 case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
312 int32_t stopBehavior = mAnimationData.stopBehavior;
313 if(Scripting::GetEnumerationProperty(value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior))
315 mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type(stopBehavior);
316 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
320 case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
322 int32_t loopingMode = mAnimationData.loopingMode;
323 if(Scripting::GetEnumerationProperty(value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode))
325 mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type(loopingMode);
326 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
330 case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
333 if(value.Get(redraw))
335 mRedrawInScalingDown = redraw;
339 case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
346 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
350 mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
355 case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
357 int32_t desiredWidth = 0;
358 if(value.Get(desiredWidth))
360 mDesiredSize.SetWidth(desiredWidth);
365 case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
367 int32_t desiredHeight = 0;
368 if(value.Get(desiredHeight))
370 mDesiredSize.SetHeight(desiredHeight);
377 void AnimatedVectorImageVisual::OnInitialize(void)
379 mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
380 mVectorAnimationTask->SetAnimationFinishedCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished));
382 mVectorAnimationTask->RequestLoad(mUrl.GetUrl(), IsSynchronousLoadingRequired());
384 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
385 vectorAnimationManager.AddObserver(*this);
387 Shader shader = GenerateShader();
389 Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
391 mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
392 mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
394 TextureSet textureSet = TextureSet::New();
395 mImpl->mRenderer.SetTextures(textureSet);
397 // Register transform properties
398 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
400 mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
403 void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
405 // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
407 // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
408 mPlacementActor = actor;
412 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
413 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
414 actor.AddRenderer(mImpl->mRenderer);
415 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
419 // Add property notification for scaling & size
420 mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
421 mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
423 mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
424 mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
426 DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
428 Window window = DevelWindow::Get(actor);
431 DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
434 if(mImpl->mEventObserver)
436 // The visual needs it's size set before it can be rasterized hence request relayout once on stage
437 mImpl->mEventObserver->RelayoutRequest(*this);
440 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY;
441 TriggerVectorRasterization();
444 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
447 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
450 TriggerVectorRasterization();
454 actor.RemoveRenderer(mImpl->mRenderer);
455 mRendererAdded = false;
458 // Remove property notification
459 actor.RemovePropertyNotification(mScaleNotification);
460 actor.RemovePropertyNotification(mSizeNotification);
462 DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
464 Window window = DevelWindow::Get(actor);
467 DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
470 mPlacementActor.Reset();
472 // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
473 mVisualSize = Vector2::ZERO;
474 mVisualScale = Vector2::ONE;
475 mAnimationData.width = 0;
476 mAnimationData.height = 0;
478 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this);
481 void AnimatedVectorImageVisual::OnSetTransform()
483 Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
485 if(IsOnScene() && visualSize != mVisualSize)
487 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this);
489 mVisualSize = visualSize;
491 SetVectorImageSize();
493 if(mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
495 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
496 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
499 TriggerVectorRasterization();
503 void AnimatedVectorImageVisual::UpdateShader()
507 Shader shader = GenerateShader();
508 mImpl->mRenderer.SetShader(shader);
512 void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
514 // Check if action is valid for this visual type and perform action if possible
517 case DevelAnimatedVectorImageVisual::Action::PLAY:
519 if(IsOnScene() && mVisualSize != Vector2::ZERO)
521 if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
523 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
524 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
527 mPlayState = DevelImageVisual::PlayState::PLAYING;
530 case DevelAnimatedVectorImageVisual::Action::PAUSE:
532 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
534 mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
535 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
537 mPlayState = DevelImageVisual::PlayState::PAUSED;
540 case DevelAnimatedVectorImageVisual::Action::STOP:
542 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
544 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
545 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
547 mPlayState = DevelImageVisual::PlayState::STOPPED;
550 case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
553 if(attributes.Get(frameNumber))
555 mAnimationData.currentFrame = frameNumber;
556 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
562 TriggerVectorRasterization();
565 void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, Dali::Any attributes)
569 case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY:
571 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>(attributes);
572 mAnimationData.dynamicProperties.push_back(info);
573 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY;
578 TriggerVectorRasterization();
581 void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
583 if(status == VectorAnimationTask::ResourceStatus::LOADED)
585 if(mImpl->mEventObserver)
587 mImpl->mEventObserver->RelayoutRequest(*this);
592 mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
594 // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
595 Actor actor = mPlacementActor.GetHandle();
596 if(actor && !mRendererAdded)
600 actor.AddRenderer(mImpl->mRenderer);
601 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
605 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
606 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
607 actor.AddRenderer(mImpl->mRenderer);
608 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
611 mRendererAdded = true;
615 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this);
618 void AnimatedVectorImageVisual::OnAnimationFinished()
620 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this);
622 if(mPlayState != DevelImageVisual::PlayState::STOPPED)
624 mPlayState = DevelImageVisual::PlayState::STOPPED;
626 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
628 if(mImpl->mEventObserver)
630 mImpl->mEventObserver->NotifyVisualEvent(*this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED);
636 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
640 void AnimatedVectorImageVisual::SendAnimationData()
642 if(mAnimationData.resendFlag)
644 mVectorAnimationTask->SetAnimationData(mAnimationData);
648 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
650 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
654 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
658 mAnimationData.resendFlag = 0;
662 void AnimatedVectorImageVisual::SetVectorImageSize()
664 uint32_t width, height;
665 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
667 width = mDesiredSize.GetWidth();
668 height = mDesiredSize.GetHeight();
672 width = static_cast<uint32_t>(mVisualSize.width * mVisualScale.width);
673 height = static_cast<uint32_t>(mVisualSize.height * mVisualScale.height);
676 if(mAnimationData.width != width || mAnimationData.height != height)
678 mAnimationData.width = width;
679 mAnimationData.height = height;
680 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
684 void AnimatedVectorImageVisual::StopAnimation()
686 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
688 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
689 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
691 mPlayState = DevelImageVisual::PlayState::STOPPED;
695 void AnimatedVectorImageVisual::TriggerVectorRasterization()
697 if(!mEventCallback && !mCoreShutdown)
699 mEventCallback = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents);
700 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
701 vectorAnimationManager.RegisterEventCallback(mEventCallback);
702 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
706 void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source)
708 Actor actor = mPlacementActor.GetHandle();
711 Vector3 scale = actor.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
713 if((!Dali::Equals(mVisualScale.width, scale.width) || !Dali::Equals(mVisualScale.height, scale.height)) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f))
715 mVisualScale.width = scale.width;
716 mVisualScale.height = scale.height;
718 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this);
720 SetVectorImageSize();
723 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
728 void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source)
730 Actor actor = mPlacementActor.GetHandle();
733 Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
735 if(!Dali::Equals(mVisualSize.width, size.width) || !Dali::Equals(mVisualSize.height, size.height))
737 mVisualSize.width = size.width;
738 mVisualSize.height = size.height;
740 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this);
742 SetVectorImageSize();
745 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
750 void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
755 TriggerVectorRasterization();
757 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
761 void AnimatedVectorImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
766 TriggerVectorRasterization();
768 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
772 void AnimatedVectorImageVisual::OnProcessEvents()
776 mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager
779 Shader AnimatedVectorImageVisual::GenerateShader() const
782 if(mImpl->mCustomShader)
784 shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
785 mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
786 mImpl->mCustomShader->mHints);
788 shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
792 shader = mImageVisualShaderFactory.GetShader(
794 ImageVisualShaderFeature::FeatureBuilder()
795 .EnableRoundedCorner(IsRoundedCornerRequired())
796 .EnableBorderline(IsBorderlineRequired()));
801 } // namespace Internal
803 } // namespace Toolkit