Use broken image when animated image loading is failed. 40/253540/10
authorseungho <sbsh.baek@samsung.com>
Mon, 15 Feb 2021 06:47:14 +0000 (15:47 +0900)
committerseungho <sbsh.baek@samsung.com>
Mon, 8 Mar 2021 06:28:19 +0000 (15:28 +0900)
Change-Id: I7b2e10ec89e4eeff2eacf5823691ff11874dc43e
Signed-off-by: seungho <sbsh.baek@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.h

index 243a73b..c77b4ac 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -293,6 +293,52 @@ int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
   END_TEST;
 }
 
   END_TEST;
 }
 
+int UtcDaliAnimatedImageVisualImageLoadingFail01(void)
+{
+  ToolkitTestApplication application;
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  {
+    Property::Map propertyMap;
+    propertyMap.Insert( Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
+    propertyMap.Insert( ImageVisual::Property::URL, "dummy.gif" );
+    propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2 );
+    propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2 );
+    propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20 );
+    propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
+    propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS, 0.23f );
+    propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE );
+
+    VisualFactory factory = VisualFactory::Get();
+    Visual::Base visual = factory.CreateVisual( propertyMap );
+
+    DummyControl dummyControl = DummyControl::New(true);
+    Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+    dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+
+    dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    application.GetScene().Add( dummyControl );
+
+    TraceCallStack& textureTrace = gl.GetTextureTrace();
+    textureTrace.Enable(true);
+
+    application.SendNotification();
+    application.Render(20);
+
+    DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
+
+    DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
+
+    application.SendNotification();
+    application.Render(20);
+
+    DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
+
+    dummyControl.Unparent();
+  }
+
+  END_TEST;
+}
 
 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
 {
 
 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
 {
index 9952c55..c9623a6 100644 (file)
@@ -265,8 +265,13 @@ void AnimatedImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
 
 void AnimatedImageVisual::OnDoAction(const Dali::Property::Index actionId, const Dali::Property::Value& attributes)
 {
 
 void AnimatedImageVisual::OnDoAction(const Dali::Property::Index actionId, const Dali::Property::Value& attributes)
 {
-  // Check if action is valid for this visual type and perform action if possible
+  // Make not set any action when the resource status is already failed.
+  if(mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED)
+  {
+    return;
+  }
 
 
+  // Check if action is valid for this visual type and perform action if possible
   switch(actionId)
   {
     case DevelAnimatedImageVisual::Action::PAUSE:
   switch(actionId)
   {
     case DevelAnimatedImageVisual::Action::PAUSE:
@@ -322,7 +327,6 @@ void AnimatedImageVisual::OnDoAction(const Dali::Property::Index actionId, const
 void AnimatedImageVisual::DoSetProperties(const Property::Map& propertyMap)
 {
   // url[s] already passed in from constructor
 void AnimatedImageVisual::DoSetProperties(const Property::Map& propertyMap)
 {
   // url[s] already passed in from constructor
-
   for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
   {
     KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
   for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
   {
     KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
@@ -491,6 +495,13 @@ void AnimatedImageVisual::DoSetOnScene(Actor& actor)
   mPlacementActor       = actor;
   TextureSet textureSet = PrepareTextureSet();
 
   mPlacementActor       = actor;
   TextureSet textureSet = PrepareTextureSet();
 
+  // Loading animated image file is failed.
+  if(!mImageCache ||
+     (mAnimatedImageLoading && !mAnimatedImageLoading.HasLoadingSucceeded()))
+  {
+    textureSet = SetLoadingFailed();
+  }
+
   if(textureSet) // if the image loading is successful
   {
     StartFirstFrame(textureSet);
   if(textureSet) // if the image loading is successful
   {
     StartFirstFrame(textureSet);
@@ -632,8 +643,12 @@ void AnimatedImageVisual::StartFirstFrame(TextureSet& textureSet)
     mFrameDelayTimer.TickSignal().Connect(this, &AnimatedImageVisual::DisplayNextFrame);
     mFrameDelayTimer.Start();
   }
     mFrameDelayTimer.TickSignal().Connect(this, &AnimatedImageVisual::DisplayNextFrame);
     mFrameDelayTimer.Start();
   }
-  DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "ResourceReady(ResourceStatus::READY)\n");
-  ResourceReady(Toolkit::Visual::ResourceStatus::READY);
+
+  if(mImpl->mResourceStatus != Toolkit::Visual::ResourceStatus::FAILED)
+  {
+    DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "ResourceReady(ResourceStatus::READY)\n");
+    ResourceReady(Toolkit::Visual::ResourceStatus::READY);
+  }
 }
 
 TextureSet AnimatedImageVisual::PrepareTextureSet()
 }
 
 TextureSet AnimatedImageVisual::PrepareTextureSet()
@@ -667,32 +682,31 @@ void AnimatedImageVisual::SetImageSize(TextureSet& textureSet)
 
 void AnimatedImageVisual::FrameReady(TextureSet textureSet)
 {
 
 void AnimatedImageVisual::FrameReady(TextureSet textureSet)
 {
-  if(textureSet)
+  // When image visual requested to load new frame to mImageCache and it is failed.
+  if(!textureSet)
   {
   {
-    SetImageSize(textureSet);
+    textureSet = SetLoadingFailed();
+  }
 
 
-    if(mStartFirstFrame)
-    {
-      StartFirstFrame(textureSet);
-    }
-    else
-    {
-      if(mImpl->mRenderer)
-      {
-        mImpl->mRenderer.SetTextures(textureSet);
-      }
-    }
+  SetImageSize(textureSet);
+
+  if(mStartFirstFrame)
+  {
+    StartFirstFrame(textureSet);
   }
   else
   {
   }
   else
   {
-    DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "ResourceReady(ResourceStatus::FAILED)\n");
-    ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+    if(mImpl->mRenderer)
+    {
+      mImpl->mRenderer.SetTextures(textureSet);
+    }
   }
 }
 
 bool AnimatedImageVisual::DisplayNextFrame()
 {
   }
 }
 
 bool AnimatedImageVisual::DisplayNextFrame()
 {
-  bool continueTimer = false;
+  TextureSet textureSet;
+  bool       continueTimer = false;
 
   if(mImageCache)
   {
 
   if(mImageCache)
   {
@@ -756,7 +770,6 @@ bool AnimatedImageVisual::DisplayNextFrame()
 
     DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::DisplayNextFrame(this:%p) CurrentFrameIndex:%d\n", this, frameIndex);
 
 
     DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::DisplayNextFrame(this:%p) CurrentFrameIndex:%d\n", this, frameIndex);
 
-    TextureSet textureSet;
     if(nextFrame)
     {
       textureSet = mImageCache->NextFrame();
     if(nextFrame)
     {
       textureSet = mImageCache->NextFrame();
@@ -766,21 +779,41 @@ bool AnimatedImageVisual::DisplayNextFrame()
       textureSet = mImageCache->Frame(frameIndex);
     }
 
       textureSet = mImageCache->Frame(frameIndex);
     }
 
-    if(textureSet)
+    continueTimer = (mActionStatus == DevelAnimatedImageVisual::Action::PLAY) ? true : false;
+  }
+
+  if(textureSet)
+  {
+    SetImageSize(textureSet);
+    if(mImpl->mRenderer)
     {
     {
-      SetImageSize(textureSet);
-      if(mImpl->mRenderer)
-      {
-        mImpl->mRenderer.SetTextures(textureSet);
-      }
+      mImpl->mRenderer.SetTextures(textureSet);
     }
     }
-
-    continueTimer = (mActionStatus == DevelAnimatedImageVisual::Action::PLAY) ? true : false;
   }
 
   return continueTimer;
 }
 
   }
 
   return continueTimer;
 }
 
+TextureSet AnimatedImageVisual::SetLoadingFailed()
+{
+  DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "ResourceReady(ResourceStatus::FAILED)\n");
+  ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+
+  TextureSet textureSet  = TextureSet::New();
+  Texture    brokenImage = mFactoryCache.GetBrokenVisualImage();
+  textureSet.SetTexture(0u, brokenImage);
+
+  if(mFrameDelayTimer)
+  {
+    mFrameDelayTimer.Stop();
+    mFrameDelayTimer.Reset();
+  }
+
+  SetImageSize(textureSet);
+
+  return textureSet;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
 } // namespace Internal
 
 } // namespace Toolkit
index 6ccdcbb..608b43f 100644 (file)
@@ -228,6 +228,12 @@ private:
    */
   void InitializeAnimatedImage(const VisualUrl& imageUrl);
 
    */
   void InitializeAnimatedImage(const VisualUrl& imageUrl);
 
+  /**
+   * Set the state of loading fail of an image or a frame.
+   * Returns TextureSet of broken image.
+   */
+  TextureSet SetLoadingFailed();
+
   // Undefined
   AnimatedImageVisual(const AnimatedImageVisual& animatedImageVisual);
 
   // Undefined
   AnimatedImageVisual(const AnimatedImageVisual& animatedImageVisual);