X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fanimated-vector-image-visual.cpp;h=f4e3059d57f1a92e229f7d3f9ba4a1eb8e785402;hb=528ee21711fc507b20ddb031cf6b1d71f1f44e75;hp=ee5b0f3d423801877c84284bf38f2ac6d81c7164;hpb=2ca1c3856ce848a94f54444f1014a820e91ee207;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 ee5b0f3..f4e3059 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. @@ -27,6 +27,7 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -43,6 +44,8 @@ namespace Internal { namespace { +const int CUSTOM_PROPERTY_COUNT(6); // 5 transform properties + pixel area, + const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); // stop behavior @@ -83,19 +86,25 @@ 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; + + if(!mVectorAnimationTask->Load(mUrl.GetUrl())) + { + mLoadFailed = true; + } mVectorAnimationTask->UploadCompletedSignal().Connect(this, &AnimatedVectorImageVisual::OnUploadCompleted); mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished))); @@ -181,6 +190,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 +295,18 @@ 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 = VisualRenderer::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); } void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) @@ -310,21 +316,32 @@ 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 = Vector2::ZERO; + imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); + mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); + actor.AddRenderer(mImpl->mRenderer); + 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); + // 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); + } } DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this); @@ -384,6 +401,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,15 +458,6 @@ 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(); @@ -606,6 +623,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