X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fanimated-vector-image-visual.cpp;h=96367759e5f920550577ba2365f94445956f26ea;hp=ee5b0f3d423801877c84284bf38f2ac6d81c7164;hb=23446c257d6ae1977bb69e53353fb1ccd5409432;hpb=c052b6678e2c6d8a65545dbbe4531ea7057c1999 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 ee5b0f3..9636775 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) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -23,10 +23,12 @@ #include #include #include +#include // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -43,6 +45,8 @@ namespace Internal { namespace { +const int CUSTOM_PROPERTY_COUNT(1); // pixel area, + const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); // stop behavior @@ -83,21 +87,24 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factory : Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)), mUrl(imageUrl), mAnimationData(), - mVectorAnimationTask(new VectorAnimationTask(factoryCache, imageUrl.GetUrl())), + mVectorAnimationTask(new VectorAnimationTask(factoryCache)), mImageVisualShaderFactory(shaderFactory), mVisualSize(), mVisualScale(Vector2::ONE), mPlacementActor(), mPlayState(DevelImageVisual::PlayState::STOPPED), mEventCallback(nullptr), + mLoadFailed(false), mRendererAdded(false), mCoreShutdown(false), mRedrawInScalingDown(true) { // the rasterized image is with pre-multiplied alpha format - mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; + mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA; + + mVectorAnimationTask->RequestLoad(mUrl.GetUrl()); - mVectorAnimationTask->UploadCompletedSignal().Connect(this, &AnimatedVectorImageVisual::OnUploadCompleted); + mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady); mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished))); auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager(); @@ -117,7 +124,7 @@ AnimatedVectorImageVisual::~AnimatedVectorImageVisual() } // 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(); } } @@ -136,10 +143,28 @@ void AnimatedVectorImageVisual::GetNaturalSize(Vector2& naturalSize) } 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); @@ -181,6 +206,15 @@ void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) // Do nothing } +void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied) +{ + // Make always enable pre multiplied alpha whether preMultiplied value is false. + if(!preMultiplied) + { + DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n"); + } +} + void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap) { // url already passed in from constructor @@ -277,30 +311,20 @@ void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Prope void AnimatedVectorImageVisual::OnInitialize(void) { - Shader shader; - - if(mImpl->mCustomShader) - { - shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader, - mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader, - mImpl->mCustomShader->mHints); - - shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT); - } - else - { - shader = mImageVisualShaderFactory.GetShader(mFactoryCache, false, true, IsRoundedCornerRequired()); - } + Shader shader = GenerateShader(); Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); - mImpl->mRenderer = Renderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); + mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); TextureSet textureSet = TextureSet::New(); mImpl->mRenderer.SetTextures(textureSet); // Register transform properties - mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); + mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); + + mVectorAnimationTask->SetRenderer(mImpl->mRenderer); } void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) @@ -310,21 +334,38 @@ void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished. mPlacementActor = actor; - mVectorAnimationTask->SetRenderer(mImpl->mRenderer); + if(mLoadFailed) + { + Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); + mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); + actor.AddRenderer(mImpl->mRenderer); + ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); + } + else + { + // Add property notification for scaling & size + mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f)); + mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification); - // Add property notification for scaling & size - mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f)); - mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification); + mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f)); + mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification); - mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f)); - mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification); + DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged); - DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged); + Window window = DevelWindow::Get(actor); + if(window) + { + DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged); + } - Window window = DevelWindow::Get(actor); - if(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); @@ -356,8 +397,10 @@ void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor) 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); } @@ -384,6 +427,15 @@ void AnimatedVectorImageVisual::OnSetTransform() } } +void AnimatedVectorImageVisual::UpdateShader() +{ + if(mImpl->mRenderer) + { + Shader shader = GenerateShader(); + mImpl->mRenderer.SetShader(shader); + } +} + void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const Property::Value& attributes) { // Check if action is valid for this visual type and perform action if possible @@ -432,32 +484,35 @@ void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const } break; } - case DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY: - { - const Property::Map* map = attributes.GetMap(); - if(map) - { - DoSetProperties(*map); - } - break; - } } TriggerVectorRasterization(); } -void AnimatedVectorImageVisual::OnUploadCompleted() +void AnimatedVectorImageVisual::OnResourceReady(bool success) { + mLoadFailed = !success; + // 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) { - actor.AddRenderer(mImpl->mRenderer); - mRendererAdded = true; + if(success) + { + actor.AddRenderer(mImpl->mRenderer); + ResourceReady(Toolkit::Visual::ResourceStatus::READY); + } + else + { + Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); + mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); + actor.AddRenderer(mImpl->mRenderer); + ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); + } - ResourceReady(Toolkit::Visual::ResourceStatus::READY); + mRendererAdded = true; - DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnUploadCompleted: Renderer is added [%p]\n", this); + DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Renderer is added (success = %d) [%p]\n", success, this); } } @@ -510,9 +565,12 @@ void AnimatedVectorImageVisual::SetVectorImageSize() uint32_t width = static_cast(mVisualSize.width * mVisualScale.width); uint32_t 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() @@ -544,7 +602,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((mVisualScale.width != scale.width || mVisualScale.height != scale.height) && (mRedrawInScalingDown || scale.width >= 1.0f || scale.height >= 1.0f)) { mVisualScale.width = scale.width; mVisualScale.height = scale.height; @@ -564,16 +622,20 @@ 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); + + if(mVisualSize.width != size.width || mVisualSize.height != size.height) + { + mVisualSize.width = size.width; + mVisualSize.height = size.height; - DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this); + DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnSizeNotification: size = %f, %f [%p]\n", mVisualSize.width, mVisualSize.height, this); - SetVectorImageSize(); - SendAnimationData(); + SetVectorImageSize(); + SendAnimationData(); - Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing + Stage::GetCurrent().KeepRendering(0.0f); // Trigger event processing + } } } @@ -606,6 +668,28 @@ void AnimatedVectorImageVisual::OnProcessEvents() mEventCallback = nullptr; // The callback will be deleted in the VectorAnimationManager } +Shader AnimatedVectorImageVisual::GenerateShader() const +{ + Shader shader; + if(mImpl->mCustomShader) + { + shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader, + mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader, + mImpl->mCustomShader->mHints); + + shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT); + } + else + { + shader = mImageVisualShaderFactory.GetShader( + mFactoryCache, + ImageVisualShaderFeature::FeatureBuilder() + .EnableRoundedCorner(IsRoundedCornerRequired()) + .EnableBorderline(IsBorderlineRequired())); + } + return shader; +} + } // namespace Internal } // namespace Toolkit