X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fanimated-vector-image-visual.cpp;h=ca3b93d1e8a4b2013bfde38efd7279b35daee806;hb=HEAD;hp=f4e3059d57f1a92e229f7d3f9ba4a1eb8e785402;hpb=4764ce1dc9edc7c08766e356c839278204369d73;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index f4e3059..506bd80 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,10 @@ #include #include #include +#include #include +#include +#include // INTERNAL INCLUDES #include @@ -30,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +48,7 @@ namespace Internal { namespace { -const int CUSTOM_PROPERTY_COUNT(6); // 5 transform properties + pixel area, +const int CUSTOM_PROPERTY_COUNT(1); // pixel area, const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); @@ -69,86 +73,103 @@ Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties) { - AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl)); + AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, ImageDimensions{})); visual->SetProperties(properties); visual->Initialize(); return visual; } -AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl) +AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size) { - AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl)); + AnimatedVectorImageVisualPtr visual(new AnimatedVectorImageVisual(factoryCache, shaderFactory, imageUrl, size)); visual->Initialize(); return visual; } -AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl) -: Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)), - mUrl(imageUrl), +AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size) +: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, static_cast(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)), + mImageUrl(imageUrl), mAnimationData(), mVectorAnimationTask(new VectorAnimationTask(factoryCache)), mImageVisualShaderFactory(shaderFactory), mVisualSize(), mVisualScale(Vector2::ONE), + mDesiredSize(size), mPlacementActor(), mPlayState(DevelImageVisual::PlayState::STOPPED), mEventCallback(nullptr), + mLastSentPlayStateId(0u), mLoadFailed(false), mRendererAdded(false), - mCoreShutdown(false), - mRedrawInScalingDown(true) + mRedrawInScalingDown(true), + mEnableFrameCache(false), + mUseNativeImage(false), + mNotifyAfterRasterization(false) { // the rasterized image is with pre-multiplied alpha format mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA; - if(!mVectorAnimationTask->Load(mUrl.GetUrl())) - { - mLoadFailed = true; - } - - mVectorAnimationTask->UploadCompletedSignal().Connect(this, &AnimatedVectorImageVisual::OnUploadCompleted); - mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished))); - - auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager(); - vectorAnimationManager.AddObserver(*this); + // By default, load a file synchronously + mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; } AnimatedVectorImageVisual::~AnimatedVectorImageVisual() { - if(!mCoreShutdown) + if(Dali::Adaptor::IsAvailable()) { - auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager(); - vectorAnimationManager.RemoveObserver(*this); + if(mImageUrl.IsBufferResource()) + { + TextureManager& textureManager = mFactoryCache.GetTextureManager(); + textureManager.RemoveEncodedImageBuffer(mImageUrl.GetUrl()); + } if(mEventCallback) { mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback(mEventCallback); + mEventCallback = nullptr; } // Finalize animation task and disconnect the signal in the main thread - mVectorAnimationTask->UploadCompletedSignal().Disconnect(this, &AnimatedVectorImageVisual::OnUploadCompleted); + mVectorAnimationTask->ResourceReadySignal().Disconnect(this, &AnimatedVectorImageVisual::OnResourceReady); mVectorAnimationTask->Finalize(); } } -void AnimatedVectorImageVisual::VectorAnimationManagerDestroyed() -{ - // Core is shutting down. Don't talk to the plugin any more. - mCoreShutdown = true; -} - void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize) { - if(mVisualSize != Vector2::ZERO) + if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0) + { + naturalSize.x = mDesiredSize.GetWidth(); + naturalSize.y = mDesiredSize.GetHeight(); + } + else if(mVisualSize != Vector2::ZERO) { naturalSize = mVisualSize; } else { - uint32_t width, height; - mVectorAnimationTask->GetDefaultSize(width, height); - naturalSize.x = width; - naturalSize.y = height; + if(mLoadFailed && mImpl->mRenderer) + { + // Load failed, use broken image size + auto textureSet = mImpl->mRenderer.GetTextures(); + if(textureSet && textureSet.GetTextureCount()) + { + auto texture = textureSet.GetTexture(0); + if(texture) + { + naturalSize.x = texture.GetWidth(); + naturalSize.y = texture.GetHeight(); + return; + } + } + } + else + { + uint32_t width, height; + mVectorAnimationTask->GetDefaultSize(width, height); + naturalSize.x = width; + naturalSize.y = height; + } } DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::GetNaturalSize: w = %f, h = %f [%p]\n", naturalSize.width, naturalSize.height, this); @@ -158,9 +179,9 @@ void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const { map.Clear(); map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE); - if(mUrl.IsValid()) + if(mImageUrl.IsValid()) { - map.Insert(Toolkit::ImageVisual::Property::URL, mUrl.GetUrl()); + map.Insert(Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl()); } map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, mAnimationData.loopCount); @@ -183,6 +204,16 @@ void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const Property::Map layerInfo; mVectorAnimationTask->GetLayerInfo(layerInfo); map.Insert(Toolkit::DevelImageVisual::Property::CONTENT_INFO, layerInfo); + + Property::Map markerInfo; + mVectorAnimationTask->GetMarkerInfo(markerInfo); + map.Insert(Toolkit::DevelImageVisual::Property::MARKER_INFO, markerInfo); + + map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired()); + map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth()); + map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight()); + map.Insert(Toolkit::DevelImageVisual::Property::ENABLE_FRAME_CACHE, mEnableFrameCache); + map.Insert(Toolkit::DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION, mNotifyAfterRasterization); } void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const @@ -231,6 +262,26 @@ void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap { DoSetProperty(Toolkit::DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, keyValue.second); } + else if(keyValue.first == SYNCHRONOUS_LOADING) + { + DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second); + } + else if(keyValue.first == IMAGE_DESIRED_WIDTH) + { + DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second); + } + else if(keyValue.first == IMAGE_DESIRED_HEIGHT) + { + DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second); + } + else if(keyValue.first == ENABLE_FRAME_CACHE) + { + DoSetProperty(Toolkit::DevelImageVisual::Property::ENABLE_FRAME_CACHE, keyValue.second); + } + else if(keyValue.first == NOTIFY_AFTER_RASTERIZATION) + { + DoSetProperty(Toolkit::DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION, keyValue.second); + } } } @@ -259,6 +310,17 @@ void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Prope mAnimationData.playRange = *array; mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE; } + else if(value.GetType() == Property::STRING) + { + std::string markerName; + if(value.Get(markerName)) + { + Property::Array array; + array.Add(markerName); + mAnimationData.playRange = std::move(array); + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_RANGE; + } + } break; } case Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR: @@ -290,16 +352,100 @@ void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Prope } break; } + case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING: + { + bool sync = false; + if(value.Get(sync)) + { + if(sync) + { + mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; + } + else + { + mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; + } + } + break; + } + case Toolkit::ImageVisual::Property::DESIRED_WIDTH: + { + int32_t desiredWidth = 0; + if(value.Get(desiredWidth)) + { + mDesiredSize.SetWidth(desiredWidth); + } + break; + } + + case Toolkit::ImageVisual::Property::DESIRED_HEIGHT: + { + int32_t desiredHeight = 0; + if(value.Get(desiredHeight)) + { + mDesiredSize.SetHeight(desiredHeight); + } + break; + } + + case Toolkit::DevelImageVisual::Property::ENABLE_FRAME_CACHE: + { + bool enableFrameCache = false; + if(value.Get(enableFrameCache)) + { + mEnableFrameCache = enableFrameCache; + if(mVectorAnimationTask) + { + mVectorAnimationTask->KeepRasterizedBuffer(mEnableFrameCache); + } + } + break; + } + + case Toolkit::DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION: + { + bool notifyAfterRasterization = false; + if(value.Get(notifyAfterRasterization)) + { + if(mNotifyAfterRasterization != notifyAfterRasterization) + { + mNotifyAfterRasterization = notifyAfterRasterization; + + mAnimationData.notifyAfterRasterization = mNotifyAfterRasterization; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NOTIFY_AFTER_RASTERIZATION; + } + } + break; + } } } void AnimatedVectorImageVisual::OnInitialize(void) { + mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady); + mVectorAnimationTask->SetAnimationFinishedCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished)); + + EncodedImageBuffer encodedImageBuffer; + + if(mImageUrl.IsBufferResource()) + { + // Increase reference count of External Resources : + // EncodedImageBuffer. + // Reference count will be decreased at destructor of the visual. + TextureManager& textureManager = mFactoryCache.GetTextureManager(); + textureManager.UseExternalResource(mImageUrl.GetUrl()); + + encodedImageBuffer = textureManager.GetEncodedImageBuffer(mImageUrl.GetUrl()); + } + + mVectorAnimationTask->KeepRasterizedBuffer(mEnableFrameCache); + mVectorAnimationTask->RequestLoad(mImageUrl, encodedImageBuffer, IsSynchronousLoadingRequired()); + Shader shader = GenerateShader(); Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); - mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); TextureSet textureSet = TextureSet::New(); @@ -307,6 +453,8 @@ void AnimatedVectorImageVisual::OnInitialize(void) // Register transform properties mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); + + mVectorAnimationTask->SetRenderer(mImpl->mRenderer); } void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) @@ -318,16 +466,14 @@ void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) if(mLoadFailed) { - Vector2 imageSize = Vector2::ZERO; - imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); - mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); + Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); + mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false); actor.AddRenderer(mImpl->mRenderer); + mRendererAdded = true; ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); } else { - mVectorAnimationTask->SetRenderer(mImpl->mRenderer); - // Add property notification for scaling & size mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f)); mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification); @@ -335,13 +481,23 @@ void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f)); mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification); - DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged); + actor.InheritedVisibilityChangedSignal().Connect(this, &AnimatedVectorImageVisual::OnControlInheritedVisibilityChanged); Window window = DevelWindow::Get(actor); if(window) { + mPlacementWindow = window; DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged); } + + if(mImpl->mEventObserver) + { + // The visual needs it's size set before it can be rasterized hence request relayout once on stage + mImpl->mEventObserver->RelayoutRequest(*this); + } + + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_NEED_RESOURCE_READY; + TriggerVectorRasterization(); } DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this); @@ -350,7 +506,7 @@ void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor) { StopAnimation(); - SendAnimationData(); + TriggerVectorRasterization(); if(mImpl->mRenderer) { @@ -362,19 +518,22 @@ void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor) actor.RemovePropertyNotification(mScaleNotification); actor.RemovePropertyNotification(mSizeNotification); - DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged); + actor.InheritedVisibilityChangedSignal().Disconnect(this, &AnimatedVectorImageVisual::OnControlInheritedVisibilityChanged); - Window window = DevelWindow::Get(actor); + Window window = mPlacementWindow.GetHandle(); if(window) { DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged); + mPlacementWindow.Reset(); } mPlacementActor.Reset(); // Reset the visual size to zero so that when adding the actor back to stage the rasterization is forced - mVisualSize = Vector2::ZERO; - mVisualScale = Vector2::ONE; + mVisualSize = Vector2::ZERO; + mVisualScale = Vector2::ONE; + mAnimationData.width = 0; + mAnimationData.height = 0; DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOffScene [%p]\n", this); } @@ -397,7 +556,7 @@ void AnimatedVectorImageVisual::OnSetTransform() mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; } - SendAnimationData(); + TriggerVectorRasterization(); } } @@ -419,11 +578,9 @@ void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const { if(IsOnScene() && mVisualSize != Vector2::ZERO) { - if(mAnimationData.playState != DevelImageVisual::PlayState::PLAYING) - { - mAnimationData.playState = DevelImageVisual::PlayState::PLAYING; - mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; - } + // Always resend Playing state. If task is already playing, it will be ignored at Rasterize time. + mAnimationData.playState = DevelImageVisual::PlayState::PLAYING; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE; } mPlayState = DevelImageVisual::PlayState::PLAYING; break; @@ -458,28 +615,107 @@ void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const } break; } + case DevelAnimatedVectorImageVisual::Action::FLUSH: + { + if(DALI_LIKELY(Dali::Adaptor::IsAvailable())) + { + SendAnimationData(); + } + break; + } } TriggerVectorRasterization(); } -void AnimatedVectorImageVisual::OnUploadCompleted() +void AnimatedVectorImageVisual::OnDoActionExtension(const Property::Index actionId, const Dali::Any& attributes) { - // If weak handle is holding a placement actor, it is the time to add the renderer to actor. - Actor actor = mPlacementActor.GetHandle(); - if(actor && !mRendererAdded) + switch(actionId) { - actor.AddRenderer(mImpl->mRenderer); - mRendererAdded = true; + case DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY: + { + DevelAnimatedVectorImageVisual::DynamicPropertyInfo info = AnyCast(attributes); + mAnimationData.dynamicProperties.push_back(info); + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_DYNAMIC_PROPERTY; + break; + } + } + + TriggerVectorRasterization(); +} - ResourceReady(Toolkit::Visual::ResourceStatus::READY); +void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status) +{ + AnimatedVectorImageVisualPtr self = this; // Keep reference until this API finished - DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnUploadCompleted: Renderer is added [%p]\n", this); + if(status == VectorAnimationTask::ResourceStatus::LOADED) + { + if(mImpl->mEventObserver) + { + mImpl->mEventObserver->RelayoutRequest(*this); + } } + else + { + mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false; + if(status == VectorAnimationTask::ResourceStatus::READY) + { + // Texture was ready. Change the shader if we need. + bool useNativeImage = false; + if(mImpl->mRenderer) + { + auto textureSet = mImpl->mRenderer.GetTextures(); + if(textureSet && textureSet.GetTextureCount() > 0) + { + auto texture = textureSet.GetTexture(0u); + if(texture) + { + useNativeImage = DevelTexture::IsNative(texture); + + if(mUseNativeImage != useNativeImage) + { + mUseNativeImage = useNativeImage; + UpdateShader(); + } + } + } + } + } + + // If weak handle is holding a placement actor, it is the time to add the renderer to actor. + Actor actor = mPlacementActor.GetHandle(); + if(actor && !mRendererAdded) + { + if(!mLoadFailed) + { + actor.AddRenderer(mImpl->mRenderer); + ResourceReady(Toolkit::Visual::ResourceStatus::READY); + } + else + { + Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); + mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false); + actor.AddRenderer(mImpl->mRenderer); + ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); + } + + mRendererAdded = true; + } + } + + DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "status = %d [%p]\n", status, this); } -void AnimatedVectorImageVisual::OnAnimationFinished() +void AnimatedVectorImageVisual::OnAnimationFinished(uint32_t playStateId) { + // Only send event when animation is finished by the last Play/Pause/Stop request. + if(mLastSentPlayStateId != playStateId) + { + return; + } + + AnimatedVectorImageVisualPtr self = this; // Keep reference until this API finished + DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnAnimationFinished: action state = %d [%p]\n", mPlayState, this); if(mPlayState != DevelImageVisual::PlayState::STOPPED) @@ -494,7 +730,7 @@ void AnimatedVectorImageVisual::OnAnimationFinished() } } - if(mImpl->mRenderer) + if(!mNotifyAfterRasterization && mImpl->mRenderer) { mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED); } @@ -504,16 +740,27 @@ void AnimatedVectorImageVisual::SendAnimationData() { if(mAnimationData.resendFlag) { + if(mAnimationData.resendFlag & VectorAnimationTask::RESEND_PLAY_STATE) + { + // Keep last sent playId. It will be used when we try to emit AnimationFinished signal. + // The OnAnimationFinished signal what before Play/Pause/Stop action send could be come after action sent. + // To ensure the OnAnimationFinished signal comes belong to what we sent, we need to keep last sent playId. + mAnimationData.playStateId = ++mLastSentPlayStateId; + } mVectorAnimationTask->SetAnimationData(mAnimationData); - if(mImpl->mRenderer) + if(mImpl->mRenderer && + ((mAnimationData.resendFlag & VectorAnimationTask::RESEND_PLAY_STATE) || + (mAnimationData.resendFlag & VectorAnimationTask::RESEND_NOTIFY_AFTER_RASTERIZATION))) { - if(mAnimationData.playState == DevelImageVisual::PlayState::PLAYING) + if(!mNotifyAfterRasterization && mPlayState == DevelImageVisual::PlayState::PLAYING) { + // Make rendering behaviour if we don't notify after rasterization, but animation playing. mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY); } else { + // Otherwise, notify will be sended after rasterization. Make behaviour as required. mImpl->mRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED); } } @@ -524,12 +771,24 @@ void AnimatedVectorImageVisual::SendAnimationData() void AnimatedVectorImageVisual::SetVectorImageSize() { - uint32_t width = static_cast(mVisualSize.width * mVisualScale.width); - uint32_t height = static_cast(mVisualSize.height * mVisualScale.height); + uint32_t width, height; + if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0) + { + width = mDesiredSize.GetWidth(); + height = mDesiredSize.GetHeight(); + } + else + { + width = static_cast(mVisualSize.width * mVisualScale.width); + height = static_cast(mVisualSize.height * mVisualScale.height); + } - mAnimationData.width = width; - mAnimationData.height = height; - mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE; + if(mAnimationData.width != width || mAnimationData.height != height) + { + mAnimationData.width = width; + mAnimationData.height = height; + mAnimationData.resendFlag |= VectorAnimationTask::RESEND_SIZE; + } } void AnimatedVectorImageVisual::StopAnimation() @@ -545,7 +804,7 @@ void AnimatedVectorImageVisual::StopAnimation() void AnimatedVectorImageVisual::TriggerVectorRasterization() { - if(!mEventCallback && !mCoreShutdown) + if(!mEventCallback && Dali::Adaptor::IsAvailable()) { mEventCallback = MakeCallback(this, &AnimatedVectorImageVisual::OnProcessEvents); auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager(); @@ -561,7 +820,7 @@ void AnimatedVectorImageVisual::OnScaleNotification(PropertyNotification& source { Vector3 scale = actor.GetProperty(Actor::Property::WORLD_SCALE); - if(mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f) + if((!Dali::Equals(mVisualScale.width, scale.width) || !Dali::Equals(mVisualScale.height, scale.height)) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f)) { mVisualScale.width = scale.width; mVisualScale.height = scale.height; @@ -581,27 +840,31 @@ void AnimatedVectorImageVisual::OnSizeNotification(PropertyNotification& source) Actor actor = mPlacementActor.GetHandle(); if(actor) { - Vector3 size = actor.GetCurrentProperty(Actor::Property::SIZE); - mVisualSize.width = size.width; - mVisualSize.height = size.height; + Vector3 size = actor.GetCurrentProperty(Actor::Property::SIZE); - DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this); + if(!Dali::Equals(mVisualSize.width, size.width) || !Dali::Equals(mVisualSize.height, size.height)) + { + mVisualSize.width = size.width; + mVisualSize.height = size.height; - SetVectorImageSize(); - SendAnimationData(); + DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this); - Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing + SetVectorImageSize(); + SendAnimationData(); + + Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing + } } } -void AnimatedVectorImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type) +void AnimatedVectorImageVisual::OnControlInheritedVisibilityChanged(Actor actor, bool visible) { if(!visible) { StopAnimation(); TriggerVectorRasterization(); - DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this); + DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnControlInheritedVisibilityChanged: invisibile. Pause animation [%p]\n", this); } } @@ -638,9 +901,10 @@ Shader AnimatedVectorImageVisual::GenerateShader() const { shader = mImageVisualShaderFactory.GetShader( mFactoryCache, - ImageVisualShaderFeature::FeatureBuilder() + ImageVisualShaderFeatureBuilder() .EnableRoundedCorner(IsRoundedCornerRequired()) - .EnableBorderline(IsBorderlineRequired())); + .EnableBorderline(IsBorderlineRequired()) + .SetTextureForFragmentShaderCheck(mUseNativeImage ? mImpl->mRenderer.GetTextures().GetTexture(0) : Dali::Texture())); } return shader; }