2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h>
22 #include <dali/devel-api/adaptor-framework/window-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/rendering/renderer-devel.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/rendering/decorated-visual-renderer.h>
29 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
30 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
32 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
33 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
34 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
35 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
36 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
37 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
38 #include <dali-toolkit/public-api/visuals/visual-properties.h>
48 const int CUSTOM_PROPERTY_COUNT(1); // pixel area,
50 const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
53 DALI_ENUM_TO_STRING_TABLE_BEGIN(STOP_BEHAVIOR)
54 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, CURRENT_FRAME)
55 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, FIRST_FRAME)
56 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, LAST_FRAME)
57 DALI_ENUM_TO_STRING_TABLE_END(STOP_BEHAVIOR)
60 DALI_ENUM_TO_STRING_TABLE_BEGIN(LOOPING_MODE)
61 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, RESTART)
62 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::LoopingMode, AUTO_REVERSE)
63 DALI_ENUM_TO_STRING_TABLE_END(LOOPING_MODE)
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
69 } // unnamed namespace
71 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
73 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, ImageDimensions{}));
74 visual->SetProperties(properties);
79 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
81 AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, size));
86 AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
87 : Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)),
90 mVectorAnimationTask(new VectorAnimationTask(factoryCache)),
91 mImageVisualShaderFactory(shaderFactory),
93 mVisualScale(Vector2::ONE),
96 mPlayState(DevelImageVisual::PlayState::STOPPED),
97 mEventCallback(nullptr),
99 mRendererAdded(false),
100 mCoreShutdown(false),
101 mRedrawInScalingDown(true)
103 // the rasterized image is with pre-multiplied alpha format
104 mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA;
106 // By default, load a file synchronously
107 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
110 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
114 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
115 vectorAnimationManager.RemoveObserver(*this);
119 mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback);
122 // Finalize animation task and disconnect the signal in the main thread
123 mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady);
124 mVectorAnimationTask->Finalize();
128 void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed()
130 // Core is shutting down. Don't talk to the plugin any more.
131 mCoreShutdown = true;
134 void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize)
136 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
138 naturalSize.x = mDesiredSize.GetWidth();
139 naturalSize.y = mDesiredSize.GetHeight();
141 else if(mVisualSize != Vector2::ZERO)
143 naturalSize = mVisualSize;
147 if(mLoadFailed && mImpl->mRenderer)
149 // Load failed, use broken image size
150 auto textureSet = mImpl->mRenderer.GetTextures();
151 if(textureSet && textureSet.GetTextureCount())
153 auto texture = textureSet.GetTexture(0);
156 naturalSize.x = texture.GetWidth();
157 naturalSize.y = texture.GetHeight();
164 uint32_t width, height;
165 mVectorAnimationTask->GetDefaultSize(width, height);
166 naturalSize.x = width;
167 naturalSize.y = height;
171 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this);
174 void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
177 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE);
180 map.Insert(Toolkit::ImageVisual::Property::URL, mUrl.GetUrl());
182 map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount);
184 uint32_t startFrame, endFrame;
185 mVectorAnimationTask->GetPlayRange(startFrame, endFrame);
187 Property::Array playRange;
188 playRange.PushBack(static_cast<int32_t>(startFrame));
189 playRange.PushBack(static_cast<int32_t>(endFrame));
190 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_RANGE, playRange);
192 map.Insert(Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast<int32_t>(mPlayState));
193 map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetCurrentFrameNumber()));
194 map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, static_cast<int32_t>(mVectorAnimationTask->GetTotalFrameNumber()));
196 map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mAnimationData.stopBehavior);
197 map.Insert(Toolkit::DevelImageVisual::Property::LOOPING_MODE, mAnimationData.loopingMode);
198 map.Insert(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, mRedrawInScalingDown);
200 Property::Map layerInfo;
201 mVectorAnimationTask->GetLayerInfo(layerInfo);
202 map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo);
204 map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired());
205 map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
206 map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
209 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
214 void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied)
216 // Make always enable pre multiplied alpha whether preMultiplied value is false.
219 DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n");
223 void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap)
225 // url already passed in from constructor
226 for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
228 KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
229 if(keyValue.first.type == Property::Key::INDEX)
231 DoSetProperty(keyValue.first.indexKey, keyValue.second);
235 if(keyValue.first == LOOP_COUNT_NAME)
237 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOP_COUNT, keyValue.second);
239 else if(keyValue.first == PLAY_RANGE_NAME)
241 DoSetProperty(Toolkit::DevelImageVisual::Property::PLAY_RANGE, keyValue.second);
243 else if(keyValue.first == STOP_BEHAVIOR_NAME)
245 DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
247 else if(keyValue.first == LOOPING_MODE_NAME)
249 DoSetProperty(Toolkit::DevelImageVisual::Property::LOOPING_MODE, keyValue.second);
251 else if(keyValue.first == REDRAW_IN_SCALING_DOWN_NAME)
253 DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second);
255 else if(keyValue.first == SYNCHRONOUS_LOADING)
257 DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
259 else if(keyValue.first == IMAGE_DESIRED_WIDTH)
261 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second);
263 else if(keyValue.first == IMAGE_DESIRED_HEIGHT)
265 DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second);
270 TriggerVectorRasterization();
273 void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
277 case Toolkit::DevelImageVisual::Property::LOOP_COUNT:
280 if(value.Get(loopCount))
282 mAnimationData.loopCount = loopCount;
283 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOP_COUNT;
287 case Toolkit::DevelImageVisual::Property::PLAY_RANGE:
289 const Property::Array* array = value.GetArray();
292 mAnimationData.playRange = *array;
293 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE;
297 case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR:
299 int32_t stopBehavior = mAnimationData.stopBehavior;
300 if(Scripting::GetEnumerationProperty(value, STOP_BEHAVIOR_TABLE, STOP_BEHAVIOR_TABLE_COUNT, stopBehavior))
302 mAnimationData.stopBehavior = DevelImageVisual::StopBehavior::Type(stopBehavior);
303 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_STOP_BEHAVIOR;
307 case Toolkit::DevelImageVisual::Property::LOOPING_MODE:
309 int32_t loopingMode = mAnimationData.loopingMode;
310 if(Scripting::GetEnumerationProperty(value, LOOPING_MODE_TABLE, LOOPING_MODE_TABLE_COUNT, loopingMode))
312 mAnimationData.loopingMode = DevelImageVisual::LoopingMode::Type(loopingMode);
313 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_LOOPING_MODE;
317 case Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN:
320 if(value.Get(redraw))
322 mRedrawInScalingDown = redraw;
326 case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
333 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
337 mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
342 case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
344 int32_t desiredWidth = 0;
345 if(value.Get(desiredWidth))
347 mDesiredSize.SetWidth(desiredWidth);
352 case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
354 int32_t desiredHeight = 0;
355 if(value.Get(desiredHeight))
357 mDesiredSize.SetHeight(desiredHeight);
364 void AnimatedVectorImageVisual::OnInitialize(void)
366 mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
367 mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished)));
369 mVectorAnimationTask->RequestLoad(mUrl.GetUrl(), IsSynchronousLoadingRequired());
371 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
372 vectorAnimationManager.AddObserver(*this);
374 Shader shader = GenerateShader();
376 Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
378 mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
379 mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
381 TextureSet textureSet = TextureSet::New();
382 mImpl->mRenderer.SetTextures(textureSet);
384 // Register transform properties
385 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
387 mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
390 void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
392 // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
394 // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
395 mPlacementActor = actor;
399 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
400 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
401 actor.AddRenderer(mImpl->mRenderer);
402 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
406 // Add property notification for scaling & size
407 mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
408 mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
410 mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
411 mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
413 DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
415 Window window = DevelWindow::Get(actor);
418 DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
421 if(mImpl->mEventObserver)
423 // The visual needs it's size set before it can be rasterized hence request relayout once on stage
424 mImpl->mEventObserver->RelayoutRequest(*this);
427 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY;
428 TriggerVectorRasterization();
431 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
434 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
437 TriggerVectorRasterization();
441 actor.RemoveRenderer(mImpl->mRenderer);
442 mRendererAdded = false;
445 // Remove property notification
446 actor.RemovePropertyNotification(mScaleNotification);
447 actor.RemovePropertyNotification(mSizeNotification);
449 DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
451 Window window = DevelWindow::Get(actor);
454 DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
457 mPlacementActor.Reset();
459 // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced
460 mVisualSize = Vector2::ZERO;
461 mVisualScale = Vector2::ONE;
462 mAnimationData.width = 0;
463 mAnimationData.height = 0;
465 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this);
468 void AnimatedVectorImageVisual::OnSetTransform()
470 Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
472 if(IsOnScene() && visualSize != mVisualSize)
474 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSetTransform: width = %f, height = %f [%p]\n", visualSize.width, visualSize.height, this);
476 mVisualSize = visualSize;
478 SetVectorImageSize();
480 if(mPlayState == DevelImageVisual::PlayState::PLAYING && mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
482 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
483 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
486 TriggerVectorRasterization();
490 void AnimatedVectorImageVisual::UpdateShader()
494 Shader shader = GenerateShader();
495 mImpl->mRenderer.SetShader(shader);
499 void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
501 // Check if action is valid for this visual type and perform action if possible
504 case DevelAnimatedVectorImageVisual::Action::PLAY:
506 if(IsOnScene() && mVisualSize != Vector2::ZERO)
508 if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING)
510 mAnimationData.playState = DevelImageVisual::PlayState::PLAYING;
511 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
514 mPlayState = DevelImageVisual::PlayState::PLAYING;
517 case DevelAnimatedVectorImageVisual::Action::PAUSE:
519 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
521 mAnimationData.playState = DevelImageVisual::PlayState::PAUSED;
522 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
524 mPlayState = DevelImageVisual::PlayState::PAUSED;
527 case DevelAnimatedVectorImageVisual::Action::STOP:
529 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
531 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
532 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
534 mPlayState = DevelImageVisual::PlayState::STOPPED;
537 case DevelAnimatedVectorImageVisual::Action::JUMP_TO:
540 if(attributes.Get(frameNumber))
542 mAnimationData.currentFrame = frameNumber;
543 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_CURRENT_FRAME;
549 TriggerVectorRasterization();
552 void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, Dali::Any attributes)
556 case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY:
558 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast<DevelAnimatedVectorImageVisual::DynamicPropertyInfo>(attributes);
559 mAnimationData.dynamicProperties.push_back(info);
560 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY;
565 TriggerVectorRasterization();
568 void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
570 if(status == VectorAnimationTask::ResourceStatus::LOADED)
572 if(mImpl->mEventObserver)
574 mImpl->mEventObserver->RelayoutRequest(*this);
579 mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
581 // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
582 Actor actor = mPlacementActor.GetHandle();
583 if(actor && !mRendererAdded)
587 actor.AddRenderer(mImpl->mRenderer);
588 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
592 Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
593 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
594 actor.AddRenderer(mImpl->mRenderer);
595 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
598 mRendererAdded = true;
602 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this);
605 void AnimatedVectorImageVisual::OnAnimationFinished()
607 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this);
609 if(mPlayState != DevelImageVisual::PlayState::STOPPED)
611 mPlayState = DevelImageVisual::PlayState::STOPPED;
613 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
615 if(mImpl->mEventObserver)
617 mImpl->mEventObserver->NotifyVisualEvent(*this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED);
623 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
627 void AnimatedVectorImageVisual::SendAnimationData()
629 if(mAnimationData.resendFlag)
631 mVectorAnimationTask->SetAnimationData(mAnimationData);
635 if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING)
637 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
641 mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
645 mAnimationData.resendFlag = 0;
649 void AnimatedVectorImageVisual::SetVectorImageSize()
651 uint32_t width, height;
652 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
654 width = mDesiredSize.GetWidth();
655 height = mDesiredSize.GetHeight();
659 width = static_cast<uint32_t>(mVisualSize.width * mVisualScale.width);
660 height = static_cast<uint32_t>(mVisualSize.height * mVisualScale.height);
663 if(mAnimationData.width != width || mAnimationData.height != height)
665 mAnimationData.width = width;
666 mAnimationData.height = height;
667 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE;
671 void AnimatedVectorImageVisual::StopAnimation()
673 if(mAnimationData.playState != DevelImageVisual::PlayState::STOPPED)
675 mAnimationData.playState = DevelImageVisual::PlayState::STOPPED;
676 mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
678 mPlayState = DevelImageVisual::PlayState::STOPPED;
682 void AnimatedVectorImageVisual::TriggerVectorRasterization()
684 if(!mEventCallback && !mCoreShutdown)
686 mEventCallback = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents);
687 auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
688 vectorAnimationManager.RegisterEventCallback(mEventCallback);
689 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
693 void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source)
695 Actor actor = mPlacementActor.GetHandle();
698 Vector3 scale = actor.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
700 if((mVisualScale.width != scale.width || mVisualScale.height != scale.height) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f))
702 mVisualScale.width = scale.width;
703 mVisualScale.height = scale.height;
705 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnScaleNotification: scale = %f, %f [%p]\n", mVisualScale.width, mVisualScale.height, this);
707 SetVectorImageSize();
710 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
715 void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source)
717 Actor actor = mPlacementActor.GetHandle();
720 Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
722 if(mVisualSize.width != size.width || mVisualSize.height != size.height)
724 mVisualSize.width = size.width;
725 mVisualSize.height = size.height;
727 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this);
729 SetVectorImageSize();
732 Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing
737 void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
742 TriggerVectorRasterization();
744 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
748 void AnimatedVectorImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
753 TriggerVectorRasterization();
755 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
759 void AnimatedVectorImageVisual::OnProcessEvents()
763 mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager
766 Shader AnimatedVectorImageVisual::GenerateShader() const
769 if(mImpl->mCustomShader)
771 shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
772 mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
773 mImpl->mCustomShader->mHints);
775 shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
779 shader = mImageVisualShaderFactory.GetShader(
781 ImageVisualShaderFeature::FeatureBuilder()
782 .EnableRoundedCorner(IsRoundedCornerRequired())
783 .EnableBorderline(IsBorderlineRequired()));
788 } // namespace Internal
790 } // namespace Toolkit