[dali_2.3.41] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / fixed-image-cache.cpp
index adf8da8..96f0f3e 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
 #include <dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h>
 
 // INTERNAL HEADERS
 #include <dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h>
 
 // INTERNAL HEADERS
-#include <dali-toolkit/internal/visuals/image-atlas-manager.h> // For ImageAtlasManagerPtr
+#include <dali-toolkit/internal/visuals/image/image-atlas-manager.h> // For ImageAtlasManagerPtr
 
 // EXTERNAL HEADERS
 
 // EXTERNAL HEADERS
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 
 namespace Dali
 #include <dali/integration-api/debug.h>
 
 namespace Dali
@@ -66,14 +67,22 @@ TextureSet FixedImageCache::Frame(uint32_t frameIndex)
     return textureSet;
   }
 
     return textureSet;
   }
 
-  while(mReadyFlags.size() < mImageUrls.size() &&
-        (frameIndex > mCurrentFrameIndex || mReadyFlags.empty()))
+  mCurrentFrameIndex = frameIndex;
+
+  bool batchRequested = false;
+
+  // Make ensure that current frameIndex load requested.
+  while(mReadyFlags.size() <= frameIndex)
   {
   {
-    ++mCurrentFrameIndex;
+    batchRequested = true;
     LoadBatch();
   }
 
     LoadBatch();
   }
 
-  mCurrentFrameIndex = frameIndex;
+  // Request batch only 1 times for this function.
+  if(!batchRequested && mReadyFlags.size() < mImageUrls.size())
+  {
+    LoadBatch();
+  }
 
   if(IsFrameReady(mCurrentFrameIndex) && mLoadState != TextureManager::LoadState::LOAD_FAILED)
   {
 
   if(IsFrameReady(mCurrentFrameIndex) && mLoadState != TextureManager::LoadState::LOAD_FAILED)
   {
@@ -107,7 +116,7 @@ int32_t FixedImageCache::GetTotalFrameCount() const
 
 bool FixedImageCache::IsFrameReady(uint32_t frameIndex) const
 {
 
 bool FixedImageCache::IsFrameReady(uint32_t frameIndex) const
 {
-  return (mReadyFlags.size() > 0 && mReadyFlags[frameIndex] == true);
+  return ((mReadyFlags.size() > 0) && (mReadyFlags[frameIndex] == true));
 }
 
 void FixedImageCache::LoadBatch()
 }
 
 void FixedImageCache::LoadBatch()
@@ -138,20 +147,16 @@ void FixedImageCache::LoadBatch()
     auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
                                                    : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
                                                    : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
-    mTextureManager.LoadTexture(url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoading);
-    mRequestingLoad = false;
+    TextureManager::TextureId loadTextureId = TextureManager::INVALID_TEXTURE_ID;
+    mTextureManager.LoadTexture(url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, loadTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoading);
+    mImageUrls[frameIndex].mTextureId = loadTextureId;
+    mRequestingLoad                   = false;
   }
 }
 
 TextureSet FixedImageCache::GetTextureSet(uint32_t frameIndex) const
 {
   TextureSet textureSet = mTextureManager.GetTextureSet(mImageUrls[frameIndex].mTextureId);
   }
 }
 
 TextureSet FixedImageCache::GetTextureSet(uint32_t frameIndex) const
 {
   TextureSet textureSet = mTextureManager.GetTextureSet(mImageUrls[frameIndex].mTextureId);
-  if(textureSet)
-  {
-    Sampler sampler = Sampler::New();
-    sampler.SetWrapMode(Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT);
-    textureSet.SetSampler(0u, sampler);
-  }
   return textureSet;
 }
 
   return textureSet;
 }
 
@@ -165,7 +170,7 @@ void FixedImageCache::MakeReady(bool wasReady, uint32_t frameIndex, bool preMult
 
 void FixedImageCache::ClearCache()
 {
 
 void FixedImageCache::ClearCache()
 {
-  if(mTextureManagerAlive)
+  if(Dali::Adaptor::IsAvailable())
   {
     for(std::size_t i = 0; i < mImageUrls.size(); ++i)
     {
   {
     for(std::size_t i = 0; i < mImageUrls.size(); ++i)
     {
@@ -185,8 +190,8 @@ void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureI
 {
   if(loadSuccess)
   {
 {
   if(loadSuccess)
   {
-    mLoadState           = TextureManager::LoadState::LOAD_FINISHED;
-    bool isCurrentFrameReady = IsFrameReady(mCurrentFrameIndex);
+    mLoadState                = TextureManager::LoadState::LOAD_FINISHED;
+    bool wasCurrentFrameReady = IsFrameReady(mCurrentFrameIndex);
     if(!mRequestingLoad)
     {
       for(std::size_t i = 0; i < mImageUrls.size(); ++i)
     if(!mRequestingLoad)
     {
       for(std::size_t i = 0; i < mImageUrls.size(); ++i)
@@ -200,9 +205,14 @@ void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureI
     }
     else
     {
     }
     else
     {
-      mReadyFlags.back() = true;
+      DALI_ASSERT_ALWAYS(mReadyFlags.size() > 0u && "Some FixedImageCache::LoadBatch() called mismatched!");
+      size_t i = mReadyFlags.size() - 1u;
+
+      // texture id might not setup yet. Update it now.
+      mImageUrls[i].mTextureId = textureInformation.textureId;
+      mReadyFlags[i]           = true;
     }
     }
-    MakeReady(isCurrentFrameReady, mCurrentFrameIndex, textureInformation.preMultiplied);
+    MakeReady(wasCurrentFrameReady, mCurrentFrameIndex, textureInformation.preMultiplied);
   }
   else
   {
   }
   else
   {