Remove the texture element from the load queue 85/222685/3
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 16 Jan 2020 05:55:02 +0000 (14:55 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Tue, 4 Feb 2020 01:39:04 +0000 (10:39 +0900)
The observer can be deleted before the load queue is processed.
Remove the load element from the queue when the texture is removed.

Change-Id: I290d82b1f6b77db915f400af4cd2c05e0bd9558b

automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/texture-manager-impl.cpp
dali-toolkit/internal/visuals/texture-manager-impl.h

index bdf031d3a74b155cd41998344e74b0b829460c40..a59b0ff1b938daf7dec12530d9e3238972005bc3 100644 (file)
@@ -2488,3 +2488,47 @@ int UtcDaliImageViewSvgLoadingFailure(void)
 
   END_TEST;
 }
+
+namespace
+{
+
+static int gResourceReadySignalCounter = 0;
+
+void OnResourceReadySignal( Control control )
+{
+  gResourceReadySignalCounter++;
+
+  if( gResourceReadySignalCounter == 1 )
+  {
+    // Set image twice
+    ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
+    ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
+  }
+}
+
+}
+
+int UtcDaliImageViewSetImageOnResourceReadySignal(void)
+{
+  tet_infoline("Test setting image from within signal handler.");
+
+  ToolkitTestApplication application;
+
+  gResourceReadySignalCounter = 0;
+
+  ImageView imageView = ImageView::New( gImage_34_RGBA );
+  imageView.ResourceReadySignal().Connect( &OnResourceReadySignal );
+
+  Stage::GetCurrent().Add( imageView );
+
+  DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
+
+  END_TEST;
+}
index 2fbfee1547bc90c08514dccd2f94a593f3328ba7..e64a51b22d92ec6847c6863922e88e8e96b62bd3 100644 (file)
@@ -49,7 +49,7 @@ FixedImageCache::~FixedImageCache()
   {
     for( std::size_t i = 0; i < mImageUrls.size() ; ++i )
     {
-      mTextureManager.Remove( mImageUrls[i].mTextureId );
+      mTextureManager.Remove( mImageUrls[i].mTextureId, this );
     }
   }
 }
index 596ff88d2e5ef82b8d63780bd107eca30e3f5935..c39be7eff73ab8563fb5ac36ad341ac2c6c73ab4 100644 (file)
@@ -75,7 +75,7 @@ RollingImageCache::~RollingImageCache()
     while( !mQueue.IsEmpty() )
     {
       ImageFrame imageFrame = mQueue.PopFront();
-      mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId );
+      mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId, this );
     }
   }
 }
@@ -97,7 +97,7 @@ TextureSet RollingImageCache::NextFrame()
   TextureSet textureSet;
 
   ImageFrame imageFrame = mQueue.PopFront();
-  mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId );
+  mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId, this );
   mImageUrls[ imageFrame.mUrlIndex ].mTextureId = TextureManager::INVALID_TEXTURE_ID;
 
   if( IsFrontReady() == true )
index f656e2d1b5aa8ff4a966c70456698724bb133398..ceb366928377f5a2e282752f50b0937cb39df158 100644 (file)
@@ -227,7 +227,7 @@ ImageVisual::~ImageVisual()
       if( mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID )
       {
         TextureManager& textureManager = mFactoryCache.GetTextureManager();
-        textureManager.Remove( mMaskingData->mAlphaMaskId );
+        textureManager.Remove( mMaskingData->mAlphaMaskId, this );
       }
     }
 
@@ -1011,7 +1011,7 @@ void ImageVisual::RemoveTexture()
 {
   if( mTextureId != TextureManager::INVALID_TEXTURE_ID )
   {
-    mFactoryCache.GetTextureManager().Remove( mTextureId );
+    mFactoryCache.GetTextureManager().Remove( mTextureId, this );
     mTextureId = TextureManager::INVALID_TEXTURE_ID;
   }
   else
index a2381e84e54761142eee055350554339219b9e28..bf78d250949cce9bb714b97e44abd0f291d5071a 100644 (file)
@@ -467,7 +467,7 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
   return textureId;
 }
 
-void TextureManager::Remove( const TextureManager::TextureId textureId )
+void TextureManager::Remove( const TextureManager::TextureId textureId, TextureUploadObserver* observer )
 {
   int textureInfoIndex = GetCacheIndexFromId( textureId );
   if( textureInfoIndex != INVALID_INDEX )
@@ -475,9 +475,9 @@ void TextureManager::Remove( const TextureManager::TextureId textureId )
     TextureInfo& textureInfo( mTextureInfoContainer[ textureInfoIndex ] );
 
     DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise,
-                   "TextureManager::Remove(%d) url:%s\n  cacheIdx:%d loadState:%s\n",
+                   "TextureManager::Remove(%d) url:%s\n  cacheIdx:%d loadState:%s reference count = %d\n",
                    textureId, textureInfo.url.GetUrl().c_str(),
-                   textureInfoIndex, GET_LOAD_STATE_STRING( textureInfo.loadState ) );
+                   textureInfoIndex, GET_LOAD_STATE_STRING( textureInfo.loadState ), textureInfo.referenceCount );
 
     // Decrement the reference count and check if this is the last user of this Texture.
     if( --textureInfo.referenceCount <= 0 )
@@ -514,6 +514,19 @@ void TextureManager::Remove( const TextureManager::TextureId textureId )
         mTextureInfoContainer.erase( mTextureInfoContainer.begin() + textureInfoIndex );
       }
     }
+
+    if( observer )
+    {
+      // Remove element from the LoadQueue
+      for( auto&& element : mLoadQueue )
+      {
+        if( element.mObserver == observer )
+        {
+          mLoadQueue.Erase( &element );
+          break;
+        }
+      }
+    }
   }
 }
 
@@ -791,7 +804,7 @@ void TextureManager::AsyncLoadComplete( AsyncLoadingInfoContainerType& loadingCo
         }
         else
         {
-          Remove( textureInfo.textureId );
+          Remove( textureInfo.textureId, nullptr );
         }
       }
     }
index 651bc44aa9cb6fac2f479963902ce4a4e1431972..7d66256d7cac2379ba04e9de397672dcaa1d4b3a 100755 (executable)
@@ -309,8 +309,9 @@ public:
    * occurrence of a Texture will cause its removal internally.
    *
    * @param[in] textureId The ID of the Texture to remove.
+   * @param[in] textureObserver The texture observer.
    */
-  void Remove( const TextureManager::TextureId textureId );
+  void Remove( const TextureManager::TextureId textureId, TextureUploadObserver* textureObserver );
 
   /**
    * @brief Get the visualUrl associated with the texture id.