Fix resource ready state 54/251554/2
authorHeeyong Song <heeyong.song@samsung.com>
Fri, 15 Jan 2021 00:33:43 +0000 (09:33 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Fri, 15 Jan 2021 07:19:14 +0000 (16:19 +0900)
In case of synchronous loading, ResourceStatus::FAILED was not set.

Change-Id: I8a59da45a506941939d69de0f009ff7e75137a5b

automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h
dali-toolkit/internal/visuals/texture-manager-impl.cpp
dali-toolkit/internal/visuals/texture-manager-impl.h
dali-toolkit/internal/visuals/visual-factory-cache.cpp

index 706f8da..2ad46f4 100644 (file)
@@ -1247,6 +1247,11 @@ int UtcDaliImageVisualSetInvalidSyncImage(void)
   application.SendNotification();
   application.Render();
 
+  // Check resource status
+  Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
+  DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
+
+  // The broken image should be shown.
   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
 
index 0cd4c1b..3a91784 100644 (file)
@@ -143,32 +143,32 @@ ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache,
   return new ImageVisual( factoryCache, shaderFactory, imageUrl, size, fittingMode, samplingMode );
 }
 
-ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
-                          ImageVisualShaderFactory& shaderFactory,
-                          const VisualUrl& imageUrl,
-                          ImageDimensions size,
-                          FittingMode::Type fittingMode,
-                          Dali::SamplingMode::Type samplingMode )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE ),
-  mPixelArea( FULL_TEXTURE_RECT ),
+ImageVisual::ImageVisual(VisualFactoryCache&       factoryCache,
+                         ImageVisualShaderFactory& shaderFactory,
+                         const VisualUrl&          imageUrl,
+                         ImageDimensions           size,
+                         FittingMode::Type         fittingMode,
+                         Dali::SamplingMode::Type  samplingMode)
+: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE),
+  mPixelArea(FULL_TEXTURE_RECT),
   mPlacementActor(),
-  mImageUrl( imageUrl ),
-  mMaskingData( ),
-  mDesiredSize( size ),
-  mTextureId( TextureManager::INVALID_TEXTURE_ID ),
+  mImageUrl(imageUrl),
+  mMaskingData(),
+  mDesiredSize(size),
+  mTextureId(TextureManager::INVALID_TEXTURE_ID),
   mTextures(),
-  mImageVisualShaderFactory( shaderFactory ),
-  mFittingMode( fittingMode ),
-  mSamplingMode( samplingMode ),
-  mWrapModeU( WrapMode::DEFAULT ),
-  mWrapModeV( WrapMode::DEFAULT ),
-  mLoadPolicy( Toolkit::ImageVisual::LoadPolicy::ATTACHED ),
-  mReleasePolicy( Toolkit::ImageVisual::ReleasePolicy::DETACHED ),
-  mAtlasRect( 0.0f, 0.0f, 0.0f, 0.0f ),
-  mAtlasRectSize( 0, 0 ),
-  mAttemptAtlasing( false ),
-  mLoading( false ),
-  mOrientationCorrection( true )
+  mImageVisualShaderFactory(shaderFactory),
+  mFittingMode(fittingMode),
+  mSamplingMode(samplingMode),
+  mWrapModeU(WrapMode::DEFAULT),
+  mWrapModeV(WrapMode::DEFAULT),
+  mLoadPolicy(Toolkit::ImageVisual::LoadPolicy::ATTACHED),
+  mReleasePolicy(Toolkit::ImageVisual::ReleasePolicy::DETACHED),
+  mAtlasRect(0.0f, 0.0f, 0.0f, 0.0f),
+  mAtlasRectSize(0, 0),
+  mLoadState(TextureManager::LoadState::NOT_STARTED),
+  mAttemptAtlasing(false),
+  mOrientationCorrection(true)
 {
   EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() );
 }
@@ -570,16 +570,29 @@ void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& t
     ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
     : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
-  textures = textureManager.LoadTexture( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode,
-                                         mMaskingData, IsSynchronousLoadingRequired(), mTextureId,
-                                         atlasRect, mAtlasRectSize, atlasing, mLoading, mWrapModeU,
-                                         mWrapModeV, textureObserver, atlasUploadObserver, atlasManager,
-                                         mOrientationCorrection, forceReload, preMultiplyOnLoad);
+  bool synchronousLoading = IsSynchronousLoadingRequired();
+  bool loadingStatus;
+
+  textures = textureManager.LoadTexture(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mTextureId, atlasRect, mAtlasRectSize, atlasing, loadingStatus, mWrapModeU, mWrapModeV, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection, forceReload, preMultiplyOnLoad);
 
   if( textures )
   {
+    if(loadingStatus)
+    {
+      mLoadState = TextureManager::LoadState::LOADING;
+    }
+    else
+    {
+      mLoadState = TextureManager::LoadState::LOAD_FINISHED;
+    }
+
     EnablePreMultipliedAlpha( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD );
   }
+  else if(synchronousLoading)
+  {
+    // Synchronous loading is failed
+    mLoadState = TextureManager::LoadState::LOAD_FAILED;
+  }
 
   if( atlasing ) // Flag needs to be set before creating renderer
   {
@@ -666,7 +679,7 @@ void ImageVisual::DoSetOnScene( Actor& actor )
     mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea );
   }
 
-  if( mLoading == false )
+  if(mLoadState == TextureManager::LoadState::LOAD_FINISHED)
   {
     actor.AddRenderer( mImpl->mRenderer );
     mPlacementActor.Reset();
@@ -674,6 +687,19 @@ void ImageVisual::DoSetOnScene( Actor& actor )
     // Image loaded and ready to display
     ResourceReady( Toolkit::Visual::ResourceStatus::READY );
   }
+  else if(mLoadState == TextureManager::LoadState::LOAD_FAILED)
+  {
+    Texture brokenImage = mFactoryCache.GetBrokenVisualImage();
+
+    mTextures = TextureSet::New();
+    mTextures.SetTexture(0u, brokenImage);
+    mImpl->mRenderer.SetTextures(mTextures);
+
+    actor.AddRenderer(mImpl->mRenderer);
+    mPlacementActor.Reset();
+
+    ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+  }
 }
 
 void ImageVisual::DoSetOffScene( Actor& actor )
@@ -686,9 +712,10 @@ void ImageVisual::DoSetOffScene( Actor& actor )
   {
     RemoveTexture(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
     mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
+
+    mLoadState = TextureManager::LoadState::NOT_STARTED;
   }
 
-  mLoading = false;
   mImpl->mRenderer.Reset();
   mPlacementActor.Reset();
 }
@@ -791,9 +818,10 @@ void ImageVisual::UploadCompleted()
     // reset the weak handle so that the renderer only get added to actor once
     mPlacementActor.Reset();
   }
+
   // Image loaded
   ResourceReady( Toolkit::Visual::ResourceStatus::READY );
-  mLoading = false;
+  mLoadState = TextureManager::LoadState::LOAD_FINISHED;
 }
 
 // From Texture Manager
@@ -844,10 +872,12 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur
   if( loadingSuccess )
   {
     resourceStatus = Toolkit::Visual::ResourceStatus::READY;
+    mLoadState     = TextureManager::LoadState::LOAD_FINISHED;
   }
   else
   {
     resourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
+    mLoadState     = TextureManager::LoadState::LOAD_FAILED;
   }
 
   // use geometry if needed
@@ -882,7 +912,6 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur
 
   // Signal to observers ( control ) that resources are ready. Must be all resources.
   ResourceReady( resourceStatus );
-  mLoading = false;
 }
 
 void ImageVisual::RemoveTexture()
index 9ae50df..fb1a529 100644 (file)
@@ -350,13 +350,11 @@ private:
   Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
   Vector4 mAtlasRect;
   Dali::ImageDimensions mAtlasRectSize;
+  TextureManager::LoadState                       mLoadState;       ///< The texture loading state
   bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
-  bool mLoading;  ///< True if the texture is still loading.
   bool mOrientationCorrection; ///< true if the image will have it's orientation corrected.
 };
 
-
-
 } // namespace Internal
 
 } // namespace Toolkit
index bcde348..1db057b 100644 (file)
@@ -132,7 +132,6 @@ TextureManager::TextureManager()
   mExternalTextures(),
   mLifecycleObservers(),
   mLoadQueue(),
-  mBrokenImageUrl(""),
   mCurrentTextureId( 0 ),
   mQueueLoadFlag(false)
 {
@@ -163,18 +162,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
     }
     if( !pixelBuffer )
     {
-      // use broken image
-      pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
-      PixelData pixelData;
-      if( pixelBuffer )
-      {
-        pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
-      }
-      Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(),
-                                      pixelData.GetWidth(), pixelData.GetHeight() );
-      texture.Upload( pixelData );
-      textureSet = TextureSet::New();
-      textureSet.SetTexture( 0u, texture );
+      DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
     }
     else
     {
@@ -294,18 +282,7 @@ TextureSet TextureManager::LoadTexture(
     }
     if( !data )
     {
-      // use broken image
-      Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
-      if( pixelBuffer )
-      {
-        PreMultiply( pixelBuffer, preMultiplyOnLoad );
-        data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
-      }
-      Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(),
-                                      data.GetWidth(), data.GetHeight() );
-      texture.Upload( data );
-      textureSet = TextureSet::New();
-      textureSet.SetTexture( 0u, texture );
+      DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous loading is failed\n");
     }
     else
     {
@@ -1376,11 +1353,6 @@ void TextureManager::AsyncLoadingHelper::AsyncLoadComplete(uint32_t           id
   mTextureManager.AsyncLoadComplete( mLoadingInfoContainer, id, pixelBuffer );
 }
 
-void TextureManager::SetBrokenImageUrl(const std::string& brokenImageUrl)
-{
-  mBrokenImageUrl = brokenImageUrl;
-}
-
 Geometry TextureManager::GetRenderGeometry(TextureId textureId, uint32_t& frontElements, uint32_t& backElements )
 {
   return RenderingAddOn::Get().IsValid() ?
index 89a8ed0..6e17945 100644 (file)
@@ -422,12 +422,6 @@ public:
   void RemoveObserver( TextureManager::LifecycleObserver& observer );
 
   /**
-   * @brief Set an image to be used when a visual has failed to correctly render
-   * @param[in] brokenImageUrl The broken image url.
-   */
-  void SetBrokenImageUrl(const std::string& brokenImageUrl);
-
-  /**
    * @brief Returns the geometry associated with texture.
    * @param[in] textureId Id of the texture
    * @param[out] frontElements number of front elements
@@ -897,7 +891,6 @@ private:  // Member Variables:
   std::vector< ExternalTextureInfo >            mExternalTextures;     ///< Externally provided textures
   Dali::Vector<LifecycleObserver*>              mLifecycleObservers;   ///< Lifecycle observers of texture manager
   Dali::Vector<LoadQueueElement>                mLoadQueue;            ///< Queue of textures to load after NotifyObservers
-  std::string                                   mBrokenImageUrl;       ///< Broken image url
   TextureId                                     mCurrentTextureId;     ///< The current value used for the unique Texture Id generation
   bool                                          mQueueLoadFlag;        ///< Flag that causes Load Textures to be queued.
 };
index bb6eb81..e6a0efd 100644 (file)
@@ -246,7 +246,6 @@ void VisualFactoryCache::SetBrokenImageUrl(const std::string& brokenImageUrl)
   }
 
   mAtlasManager->SetBrokenImage( mBrokenImageUrl );
-  mTextureManager.SetBrokenImageUrl( mBrokenImageUrl );
 }
 
 } // namespace Internal