Add observer during ProcessLoadQueue 26/276326/6
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 14 Jun 2022 12:21:44 +0000 (21:21 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 15 Jun 2022 17:25:27 +0000 (02:25 +0900)
Due to we request LoadTexture multiple time during ProcessLoadQueue,
same AnimatedImageLoading can be requested on multiple ImageLoadThread.

Decode same textureId in multiple thread is just waste the CPU resource.

This patch make we add observer in ProcessLoadQueue.

Change-Id: I5656befa209db967e0a6f1ccd90959f38ff731fc
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/texture-manager/texture-manager-impl.cpp

index 80836e3..6e8c9d7 100644 (file)
@@ -927,9 +927,8 @@ int UtcDaliAnimatedImageVisualAnimatedImage01(void)
     // Note that we only re-load 0 frame.
     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
 
-    // To do: we need to fix caching bug in animated-visual
-    //tet_infoline("Test that we don't try to re-load new image cause it cached");
-    //DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
+    tet_infoline("Test that we don't try to re-load new image cause it cached");
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
 
     // Batch 2 frames. Now visual frame 1, 2, 3 cached and visual2 frame 0, 1 cached.
     application.SendNotification();
index 120f570..c8f1422 100644 (file)
@@ -3439,6 +3439,19 @@ void OnResourceReadySignal04(Control control)
   }
 }
 
+void OnResourceReadySignal05(Control control)
+{
+  gResourceReadySignalCounter++;
+
+  // Request load with same image
+  // NOTE : The url must not be same as gImageView1
+  const int viewCount = 4;
+  for(int i = 0; i < viewCount; ++i)
+  {
+    gImageView1.Add(ImageView::New("invalid2.jpg"));
+  }
+}
+
 } // namespace
 
 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
@@ -3838,3 +3851,33 @@ int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
 
   END_TEST;
 }
+int UtcDaliImageViewSetImageOnResourceReadySignal05(void)
+{
+  tet_infoline("Test multiple views with same image during ResourceReady load the image only 1 times");
+
+  ToolkitTestApplication application;
+
+  gResourceReadySignalCounter = 0;
+
+  gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
+  gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal05);
+  application.GetScene().Add(gImageView1);
+
+  application.SendNotification();
+  application.Render();
+
+  tet_infoline("Try to load 1 invalid.jpg image");
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
+
+  tet_infoline("Try to load 1 invalid2.jpg image");
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  tet_infoline("Now we don't have any image to be loaded. Check event thread trigger failed.");
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
+
+  gImageView1.Unparent();
+  gImageView1.Reset();
+
+  END_TEST;
+}
index 445ad65..92031ae 100644 (file)
@@ -121,10 +121,8 @@ TextureManager::MaskingData::MaskingData()
 
 TextureManager::TextureManager()
 : mTextureCacheManager(),
-  mAsyncLocalLoaders(GetNumberOfLocalLoaderThreads(), [&]()
-                     { return TextureAsyncLoadingHelper(*this); }),
-  mAsyncRemoteLoaders(GetNumberOfRemoteLoaderThreads(), [&]()
-                      { return TextureAsyncLoadingHelper(*this); }),
+  mAsyncLocalLoaders(GetNumberOfLocalLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
+  mAsyncRemoteLoaders(GetNumberOfRemoteLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
   mLifecycleObservers(),
   mLoadQueue(),
   mRemoveQueue(),
@@ -533,7 +531,7 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
 {
   TextureHash       textureHash = INITIAL_HASH_NUMBER;
   TextureCacheIndex cacheIndex  = INVALID_CACHE_INDEX;
-  if(storageType != StorageType::RETURN_PIXEL_BUFFER && frameIndex == 0)
+  if(storageType != StorageType::RETURN_PIXEL_BUFFER)
   {
     textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask, frameIndex);
 
@@ -568,7 +566,7 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
     // Cache new texutre, and get cacheIndex.
     cacheIndex = mTextureCacheManager.AppendCache(TextureInfo(textureId, maskTextureId, url, desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, useAtlas, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex));
 
-    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d, frameindex=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, frameIndex);
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d, frameindex=%d premultiply=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, frameIndex, preMultiply);
   }
 
   // The below code path is common whether we are using the cache or not.
@@ -878,6 +876,12 @@ void TextureManager::ProcessLoadQueue()
       {
         EmitLoadComplete(element.mObserver, textureInfo, true);
       }
+      else if(textureInfo.loadState == LoadState::LOADING)
+      {
+        // Note : LOADING state texture cannot be queue.
+        // This case be occured when same texture id are queue in mLoadQueue.
+        ObserveTexture(textureInfo, element.mObserver);
+      }
       else
       {
         LoadTexture(textureInfo, element.mObserver);