[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-manager-impl.cpp
index 3156f9e..f3b5028 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 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.
  */
 
 // CLASS HEADER
-#include "texture-manager-impl.h"
+#include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
 
 // EXTERNAL HEADERS
-#include <dali/devel-api/adaptor-framework/environment-variable.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
+#include <dali/integration-api/trace.h>
 #include <dali/public-api/rendering/geometry.h>
 
 // INTERNAL HEADERS
 
 namespace
 {
-constexpr auto INITIAL_HASH_NUMBER                     = size_t{0u};
-constexpr auto DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS  = size_t{4u};
-constexpr auto DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS = size_t{8u};
+constexpr auto INITIAL_HASH_NUMBER = size_t{0u};
 
-constexpr auto NUMBER_OF_LOCAL_LOADER_THREADS_ENV  = "DALI_TEXTURE_LOCAL_THREADS";
-constexpr auto NUMBER_OF_REMOTE_LOADER_THREADS_ENV = "DALI_TEXTURE_REMOTE_THREADS";
-constexpr auto LOAD_IMAGE_YUV_PLANES_ENV           = "DALI_LOAD_IMAGE_YUV_PLANES";
+constexpr auto TEXTURE_INDEX      = 0u; ///< The Index for texture
+constexpr auto MASK_TEXTURE_INDEX = 1u; ///< The Index for mask texture
 
-size_t GetNumberOfThreads(const char* environmentVariable, size_t defaultValue)
-{
-  using Dali::EnvironmentVariable::GetEnvironmentVariable;
-  auto           numberString          = GetEnvironmentVariable(environmentVariable);
-  auto           numberOfThreads       = numberString ? std::strtoul(numberString, nullptr, 10) : 0;
-  constexpr auto MAX_NUMBER_OF_THREADS = 100u;
-  DALI_ASSERT_DEBUG(numberOfThreads < MAX_NUMBER_OF_THREADS);
-  return (numberOfThreads > 0 && numberOfThreads < MAX_NUMBER_OF_THREADS) ? numberOfThreads : defaultValue;
-}
-
-size_t GetNumberOfLocalLoaderThreads()
-{
-  return GetNumberOfThreads(NUMBER_OF_LOCAL_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS);
-}
-
-size_t GetNumberOfRemoteLoaderThreads()
-{
-  return GetNumberOfThreads(NUMBER_OF_REMOTE_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS);
-}
-
-bool NeedToLoadYuvPlanes()
-{
-  auto loadYuvPlanesString = Dali::EnvironmentVariable::GetEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV);
-  bool loadYuvPlanes       = loadYuvPlanesString ? std::atoi(loadYuvPlanesString) : false;
-  return loadYuvPlanes;
-}
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_IMAGE_PERFORMANCE_MARKER, false);
 } // namespace
 
 namespace Dali
@@ -89,6 +62,7 @@ Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New(Debug::NoLogging, f
   loadState == TextureManagerType::LoadState::MASK_APPLIED     ? "MASK_APPLIED"     : \
   loadState == TextureManagerType::LoadState::UPLOADED         ? "UPLOADED"         : \
   loadState == TextureManagerType::LoadState::CANCELLED        ? "CANCELLED"        : \
+  loadState == TextureManagerType::LoadState::MASK_CANCELLED   ? "MASK_CANCELLED"   : \
   loadState == TextureManagerType::LoadState::LOAD_FAILED      ? "LOAD_FAILED"      : \
                                                                  "Unknown"
 // clang-format on
@@ -96,8 +70,7 @@ Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New(Debug::NoLogging, f
 
 namespace
 {
-const uint32_t DEFAULT_ATLAS_SIZE(1024u);               ///< This size can fit 8 by 8 images of average size 128 * 128
-const Vector4  FULL_ATLAS_RECT(0.0f, 0.0f, 1.0f, 1.0f); ///< UV Rectangle that covers the full Texture
+const Vector4 FULL_ATLAS_RECT(0.0f, 0.0f, 1.0f, 1.0f); ///< UV Rectangle that covers the full Texture
 
 void PreMultiply(Devel::PixelBuffer pixelBuffer, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
 {
@@ -126,15 +99,14 @@ TextureManager::MaskingData::MaskingData()
 {
 }
 
-TextureManager::TextureManager()
+TextureManager::TextureManager(bool loadYuvPlanes)
 : mTextureCacheManager(),
-  mAsyncLocalLoaders(GetNumberOfLocalLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
-  mAsyncRemoteLoaders(GetNumberOfRemoteLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
-  mLifecycleObservers(),
+  mAsyncLoader(std::unique_ptr<TextureAsyncLoadingHelper>(new TextureAsyncLoadingHelper(*this))),
   mLoadQueue(),
-  mRemoveQueue(),
   mLoadingQueueTextureId(INVALID_TEXTURE_ID),
-  mLoadYuvPlanes(NeedToLoadYuvPlanes())
+  mRemoveQueue(),
+  mLoadYuvPlanes(loadYuvPlanes),
+  mRemoveProcessorRegistered(false)
 {
   // Initialize the AddOn
   RenderingAddOn::Get();
@@ -142,22 +114,23 @@ TextureManager::TextureManager()
 
 TextureManager::~TextureManager()
 {
-  for(auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
+  if(mRemoveProcessorRegistered && Adaptor::IsAvailable())
   {
-    (*iter)->TextureManagerDestroyed();
+    Adaptor::Get().UnregisterProcessor(*this, true);
+    mRemoveProcessorRegistered = false;
   }
 }
 
 TextureSet TextureManager::LoadAnimatedImageTexture(
   const VisualUrl&                url,
   Dali::AnimatedImageLoading      animatedImageLoading,
-  const uint32_t&                 frameIndex,
+  const uint32_t                  frameIndex,
   TextureManager::TextureId&      textureId,
   MaskingDataPointer&             maskInfo,
-  const Dali::SamplingMode::Type& samplingMode,
-  const Dali::WrapMode::Type&     wrapModeU,
-  const Dali::WrapMode::Type&     wrapModeV,
-  const bool&                     synchronousLoading,
+  const Dali::ImageDimensions&    desiredSize,
+  const Dali::FittingMode::Type   fittingMode,
+  const Dali::SamplingMode::Type  samplingMode,
+  const bool                      synchronousLoading,
   TextureUploadObserver*          textureObserver,
   TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
 {
@@ -168,7 +141,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
     Devel::PixelBuffer pixelBuffer;
     if(animatedImageLoading)
     {
-      pixelBuffer = animatedImageLoading.LoadFrame(frameIndex);
+      pixelBuffer = animatedImageLoading.LoadFrame(frameIndex, desiredSize, fittingMode, samplingMode);
     }
     if(!pixelBuffer)
     {
@@ -179,7 +152,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
       Texture maskTexture;
       if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
       {
-        Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
+        Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), desiredSize, fittingMode, samplingMode, true);
         if(maskPixelBuffer)
         {
           if(!maskInfo->mPreappliedMasking)
@@ -210,10 +183,10 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
         Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
         texture.Upload(pixelData);
         textureSet = TextureSet::New();
-        textureSet.SetTexture(0u, texture);
+        textureSet.SetTexture(TEXTURE_INDEX, texture);
         if(maskTexture)
         {
-          textureSet.SetTexture(1u, maskTexture);
+          textureSet.SetTexture(MASK_TEXTURE_INDEX, maskTexture);
         }
       }
     }
@@ -225,7 +198,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
     bool      cropToMask         = false;
     if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
     {
-      maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE);
+      maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? TextureManager::StorageType::KEEP_PIXEL_BUFFER : TextureManager::StorageType::KEEP_TEXTURE);
       alphaMaskId            = maskInfo->mAlphaMaskId;
       if(maskInfo->mPreappliedMasking)
       {
@@ -234,7 +207,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
       }
     }
 
-    textureId = RequestLoadInternal(url, alphaMaskId, contentScaleFactor, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, UseAtlas::NO_ATLAS, cropToMask, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoad, animatedImageLoading, frameIndex, false);
+    textureId = RequestLoadInternal(url, alphaMaskId, textureId, contentScaleFactor, desiredSize, fittingMode, samplingMode, cropToMask, TextureManager::StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoad, animatedImageLoading, frameIndex, false);
 
     TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
     if(loadState == TextureManager::LoadState::UPLOADED)
@@ -244,24 +217,17 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
     }
   }
 
-  if(textureSet)
-  {
-    Sampler sampler = Sampler::New();
-    sampler.SetWrapMode(wrapModeU, wrapModeV);
-    textureSet.SetSampler(0u, sampler);
-  }
-
   return textureSet;
 }
 
 Devel::PixelBuffer TextureManager::LoadPixelBuffer(
   const VisualUrl&                url,
   const Dali::ImageDimensions&    desiredSize,
-  const Dali::FittingMode::Type&  fittingMode,
-  const Dali::SamplingMode::Type& samplingMode,
-  const bool&                     synchronousLoading,
+  const Dali::FittingMode::Type   fittingMode,
+  const Dali::SamplingMode::Type  samplingMode,
+  const bool                      synchronousLoading,
   TextureUploadObserver*          textureObserver,
-  const bool&                     orientationCorrection,
+  const bool                      orientationCorrection,
   TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
 {
   Devel::PixelBuffer pixelBuffer;
@@ -289,32 +255,30 @@ Devel::PixelBuffer TextureManager::LoadPixelBuffer(
   }
   else
   {
-    RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
+    RequestLoadInternal(url, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, false, TextureManager::StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
   }
 
   return pixelBuffer;
 }
 
 TextureSet TextureManager::LoadTexture(
-  const VisualUrl&                    url,
-  const Dali::ImageDimensions&        desiredSize,
-  const Dali::FittingMode::Type&      fittingMode,
-  const Dali::SamplingMode::Type&     samplingMode,
-  MaskingDataPointer&                 maskInfo,
-  const bool&                         synchronousLoading,
-  TextureManager::TextureId&          textureId,
-  Vector4&                            textureRect,
-  Dali::ImageDimensions&              textureRectSize,
-  bool&                               atlasingStatus,
-  bool&                               loadingStatus,
-  const Dali::WrapMode::Type&         wrapModeU,
-  const Dali::WrapMode::Type&         wrapModeV,
-  TextureUploadObserver*              textureObserver,
-  AtlasUploadObserver*                atlasObserver,
-  ImageAtlasManagerPtr                imageAtlasManager,
-  const bool&                         orientationCorrection,
-  const TextureManager::ReloadPolicy& reloadPolicy,
-  TextureManager::MultiplyOnLoad&     preMultiplyOnLoad)
+  const VisualUrl&                   url,
+  const Dali::ImageDimensions&       desiredSize,
+  const Dali::FittingMode::Type      fittingMode,
+  const Dali::SamplingMode::Type     samplingMode,
+  MaskingDataPointer&                maskInfo,
+  const bool                         synchronousLoading,
+  TextureManager::TextureId&         textureId,
+  Vector4&                           textureRect,
+  Dali::ImageDimensions&             textureRectSize,
+  bool&                              atlasingStatus,
+  bool&                              loadingStatus,
+  TextureUploadObserver*             textureObserver,
+  AtlasUploadObserver*               atlasObserver,
+  ImageAtlasManagerPtr               imageAtlasManager,
+  const bool                         orientationCorrection,
+  const TextureManager::ReloadPolicy reloadPolicy,
+  TextureManager::MultiplyOnLoad&    preMultiplyOnLoad)
 {
   TextureSet textureSet;
 
@@ -326,13 +290,40 @@ TextureSet TextureManager::LoadTexture(
     std::string location = url.GetLocation();
     if(location.size() > 0u)
     {
-      TextureId id = std::stoi(location);
-      textureSet   = mTextureCacheManager.GetExternalTextureSet(id);
-      if(textureSet)
+      TextureId id                  = std::stoi(location);
+      auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
+      if(externalTextureInfo.textureSet)
       {
-        preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
-        textureId         = id;
-        return textureSet;
+        if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
+        {
+          // Change preMultiplyOnLoad value so make caller determine to preMultiplyAlpha or not.
+          // TODO : Should we seperate input and output value?
+          preMultiplyOnLoad = externalTextureInfo.preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+        }
+
+        TextureId alphaMaskId = INVALID_TEXTURE_ID;
+        if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
+        {
+          maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, TextureManager::StorageType::KEEP_TEXTURE, synchronousLoading);
+          alphaMaskId            = maskInfo->mAlphaMaskId;
+
+          // Create new textureId. this textureId is not same as location
+          textureId = RequestLoad(url, alphaMaskId, textureId, 1.0f, desiredSize, fittingMode, samplingMode, false, textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad, synchronousLoading);
+
+          TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
+          if(loadState == TextureManager::LoadState::UPLOADED)
+          {
+            textureSet = GetTextureSet(textureId);
+          }
+        }
+        else
+        {
+          // TextureId is same as location
+          textureId = id;
+
+          textureSet = TextureSet::New();
+          textureSet.SetTexture(TEXTURE_INDEX, externalTextureInfo.textureSet.GetTexture(TEXTURE_INDEX));
+        }
       }
     }
   }
@@ -416,7 +407,7 @@ TextureSet TextureManager::LoadTexture(
         bool      cropToMask         = false;
         if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
         {
-          maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE, synchronousLoading);
+          maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? TextureManager::StorageType::KEEP_PIXEL_BUFFER : TextureManager::StorageType::KEEP_TEXTURE, synchronousLoading);
           alphaMaskId            = maskInfo->mAlphaMaskId;
           if(maskInfo && maskInfo->mPreappliedMasking)
           {
@@ -428,11 +419,11 @@ TextureSet TextureManager::LoadTexture(
         textureId = RequestLoad(
           url,
           alphaMaskId,
+          textureId,
           contentScaleFactor,
           desiredSize,
           fittingMode,
           samplingMode,
-          UseAtlas::NO_ATLAS,
           cropToMask,
           textureObserver,
           orientationCorrection,
@@ -444,7 +435,7 @@ TextureSet TextureManager::LoadTexture(
         if(loadState == TextureManager::LoadState::UPLOADED)
         {
           // LoadComplete has already been called - keep the same texture set
-          textureSet = mTextureCacheManager.GetTextureSet(textureId);
+          textureSet = GetTextureSet(textureId);
         }
 
         // If we are loading the texture, or waiting for the ready signal handler to complete, inform
@@ -463,13 +454,6 @@ TextureSet TextureManager::LoadTexture(
     }
   }
 
-  if(!atlasingStatus && textureSet)
-  {
-    Sampler sampler = Sampler::New();
-    sampler.SetWrapMode(wrapModeU, wrapModeV);
-    textureSet.SetSampler(0u, sampler);
-  }
-
   if(synchronousLoading)
   {
     loadingStatus = false;
@@ -479,85 +463,85 @@ TextureSet TextureManager::LoadTexture(
 }
 
 TextureManager::TextureId TextureManager::RequestLoad(
-  const VisualUrl&                    url,
-  const ImageDimensions&              desiredSize,
-  const Dali::FittingMode::Type&      fittingMode,
-  const Dali::SamplingMode::Type&     samplingMode,
-  const UseAtlas&                     useAtlas,
-  TextureUploadObserver*              observer,
-  const bool&                         orientationCorrection,
-  const TextureManager::ReloadPolicy& reloadPolicy,
-  TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
-  const bool&                         synchronousLoading)
+  const VisualUrl&                   url,
+  const ImageDimensions&             desiredSize,
+  const Dali::FittingMode::Type      fittingMode,
+  const Dali::SamplingMode::Type     samplingMode,
+  TextureUploadObserver*             observer,
+  const bool                         orientationCorrection,
+  const TextureManager::ReloadPolicy reloadPolicy,
+  TextureManager::MultiplyOnLoad&    preMultiplyOnLoad,
+  const bool                         synchronousLoading)
 {
-  return RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+  return RequestLoadInternal(url, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, false, TextureManager::StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
 }
 
 TextureManager::TextureId TextureManager::RequestLoad(
-  const VisualUrl&                    url,
-  const TextureManager::TextureId&    maskTextureId,
-  const float&                        contentScale,
-  const Dali::ImageDimensions&        desiredSize,
-  const Dali::FittingMode::Type&      fittingMode,
-  const Dali::SamplingMode::Type&     samplingMode,
-  const TextureManager::UseAtlas&     useAtlas,
-  const bool&                         cropToMask,
-  TextureUploadObserver*              observer,
-  const bool&                         orientationCorrection,
-  const TextureManager::ReloadPolicy& reloadPolicy,
-  TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
-  const bool&                         synchronousLoading)
+  const VisualUrl&                   url,
+  const TextureManager::TextureId    maskTextureId,
+  const TextureManager::TextureId    previousTextureId,
+  const float                        contentScale,
+  const Dali::ImageDimensions&       desiredSize,
+  const Dali::FittingMode::Type      fittingMode,
+  const Dali::SamplingMode::Type     samplingMode,
+  const bool                         cropToMask,
+  TextureUploadObserver*             observer,
+  const bool                         orientationCorrection,
+  const TextureManager::ReloadPolicy reloadPolicy,
+  TextureManager::MultiplyOnLoad&    preMultiplyOnLoad,
+  const bool                         synchronousLoading)
 {
-  return RequestLoadInternal(url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+  return RequestLoadInternal(url, maskTextureId, previousTextureId, contentScale, desiredSize, fittingMode, samplingMode, cropToMask, TextureManager::StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
 }
 
 TextureManager::TextureId TextureManager::RequestMaskLoad(
-  const VisualUrl& maskUrl,
-  StorageType      storageType,
-  const bool&      synchronousLoading)
+  const VisualUrl&                  maskUrl,
+  const TextureManager::StorageType storageType,
+  const bool                        synchronousLoading)
 {
   // Use the normal load procedure to get the alpha mask.
   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
-  return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, UseAtlas::NO_ATLAS, false, storageType, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+  return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::NO_FILTER, false, storageType, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
 }
 
 TextureManager::TextureId TextureManager::RequestLoadInternal(
-  const VisualUrl&                    url,
-  const TextureManager::TextureId&    maskTextureId,
-  const float&                        contentScale,
-  const Dali::ImageDimensions&        desiredSize,
-  const Dali::FittingMode::Type&      fittingMode,
-  const Dali::SamplingMode::Type&     samplingMode,
-  const TextureManager::UseAtlas&     useAtlas,
-  const bool&                         cropToMask,
-  const TextureManager::StorageType&  storageType,
-  TextureUploadObserver*              observer,
-  const bool&                         orientationCorrection,
-  const TextureManager::ReloadPolicy& reloadPolicy,
-  TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
-  Dali::AnimatedImageLoading          animatedImageLoading,
-  const std::uint32_t&                frameIndex,
-  const bool&                         synchronousLoading)
+  const VisualUrl&                   url,
+  const TextureManager::TextureId    maskTextureId,
+  const TextureManager::TextureId    previousTextureId,
+  const float                        contentScale,
+  const Dali::ImageDimensions&       desiredSize,
+  const Dali::FittingMode::Type      fittingMode,
+  const Dali::SamplingMode::Type     samplingMode,
+  const bool                         cropToMask,
+  const TextureManager::StorageType  storageType,
+  TextureUploadObserver*             observer,
+  const bool                         orientationCorrection,
+  const TextureManager::ReloadPolicy reloadPolicy,
+  TextureManager::MultiplyOnLoad&    preMultiplyOnLoad,
+  Dali::AnimatedImageLoading         animatedImageLoading,
+  const uint32_t                     frameIndex,
+  const bool                         synchronousLoading)
 {
   TextureHash       textureHash   = INITIAL_HASH_NUMBER;
   TextureCacheIndex cacheIndex    = INVALID_CACHE_INDEX;
-  bool              loadYuvPlanes = (mLoadYuvPlanes && maskTextureId == INVALID_TEXTURE_ID && storageType == StorageType::UPLOAD_TO_TEXTURE);
+  bool              loadYuvPlanes = (mLoadYuvPlanes && maskTextureId == INVALID_TEXTURE_ID && storageType == TextureManager::StorageType::UPLOAD_TO_TEXTURE);
 
-  if(storageType != StorageType::RETURN_PIXEL_BUFFER)
+  if(storageType != TextureManager::StorageType::RETURN_PIXEL_BUFFER)
   {
-    textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask, frameIndex);
+    textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, maskTextureId, cropToMask, frameIndex);
 
     // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
-    cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, useAtlas, storageType, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
+    cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, storageType, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
   }
 
   TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
   // Check if the requested Texture exists in the cache.
   if(cacheIndex != INVALID_CACHE_INDEX)
   {
-    if(TextureManager::ReloadPolicy::CACHED == reloadPolicy)
+    if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
     {
-      // Mark this texture being used by another client resource. Forced reload would replace the current texture
+      // Mark this texture being used by another client resource, or Reload forced without request load before.
+      // Forced reload which have current texture before, would replace the current texture.
       // without the need for incrementing the reference count.
       ++(mTextureCacheManager[cacheIndex].referenceCount);
     }
@@ -565,8 +549,7 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
 
     // Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
     preMultiplyOnLoad = mTextureCacheManager[cacheIndex].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
-
-    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d, frameindex=%d, premultiplied=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, frameIndex, mTextureCacheManager[cacheIndex].preMultiplied ? 1 : 0);
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d, maskTextureId=%d, prevTextureId=%d, frameindex=%d, premultiplied=%d, refCount=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, previousTextureId, frameIndex, mTextureCacheManager[cacheIndex].preMultiplied ? 1 : 0, static_cast<int>(mTextureCacheManager[cacheIndex].referenceCount));
   }
 
   if(textureId == INVALID_TEXTURE_ID) // There was no caching, or caching not required
@@ -576,9 +559,8 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
     bool preMultiply = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
 
     // 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, loadYuvPlanes));
-
-    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);
+    cacheIndex = mTextureCacheManager.AppendCache(TextureInfo(textureId, maskTextureId, url, desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex, loadYuvPlanes));
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d, maskTextureId=%d, frameindex=%d premultiply=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, frameIndex, preMultiply);
   }
 
   // The below code path is common whether we are using the cache or not.
@@ -589,6 +571,16 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
   textureInfo.storageType           = storageType;
   textureInfo.orientationCorrection = orientationCorrection;
 
+  // the case using external texture has already been loaded texture, so change its status to WAITING_FOR_MASK.
+  if(url.GetProtocolType() == VisualUrl::TEXTURE)
+  {
+    if(textureInfo.loadState != TextureManager::LoadState::UPLOADED)
+    {
+      textureInfo.preMultiplied = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
+      textureInfo.loadState     = TextureManager::LoadState::WAITING_FOR_MASK;
+    }
+  }
+
   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n", GET_LOAD_STATE_STRING(textureInfo.loadState));
 
   // Force reloading of texture by setting loadState unless already loading or cancelled.
@@ -597,10 +589,10 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
      TextureManager::LoadState::WAITING_FOR_MASK != textureInfo.loadState &&
      TextureManager::LoadState::MASK_APPLYING != textureInfo.loadState &&
      TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
-     TextureManager::LoadState::CANCELLED != textureInfo.loadState)
+     TextureManager::LoadState::CANCELLED != textureInfo.loadState &&
+     TextureManager::LoadState::MASK_CANCELLED != textureInfo.loadState)
   {
-    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId);
-
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d, maskTextureId=%d, prevTextureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, previousTextureId);
     textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
   }
 
@@ -621,7 +613,11 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
       case TextureManager::LoadState::MASK_APPLYING:
       case TextureManager::LoadState::MASK_APPLIED:
       {
-        ObserveTexture(textureInfo, observer);
+        // Do not observe even we reload forced when texture is already loading state.
+        if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
+        {
+          ObserveTexture(textureInfo, observer);
+        }
         break;
       }
       case TextureManager::LoadState::UPLOADED:
@@ -640,10 +636,18 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
         ObserveTexture(textureInfo, observer);
         break;
       }
+      case TextureManager::LoadState::MASK_CANCELLED:
+      {
+        // A cancelled texture hasn't finished mask applying yet. Treat as a mask applying texture
+        // (it's ref count has already been incremented, above)
+        textureInfo.loadState = TextureManager::LoadState::MASK_APPLYING;
+        ObserveTexture(textureInfo, observer);
+        break;
+      }
       case TextureManager::LoadState::LOAD_FINISHED:
       {
         // Loading has already completed.
-        if(observer && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
+        if(observer && textureInfo.storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER)
         {
           LoadOrQueueTexture(textureInfo, observer);
         }
@@ -658,152 +662,181 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
     if(!(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
          textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED))
     {
-      std::vector<Devel::PixelBuffer> pixelBuffers;
-      LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, loadYuvPlanes, pixelBuffers);
-
-      if(pixelBuffers.empty())
-      {
-        // If pixelBuffer loading is failed in synchronously, call Remove() method.
-        Remove(textureId, nullptr);
-        return INVALID_TEXTURE_ID;
-      }
-
-      if(storageType == StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
+      if(url.GetProtocolType() == VisualUrl::TEXTURE)
       {
-        textureInfo.pixelBuffer = pixelBuffers[0]; // Store the pixel data
-        textureInfo.loadState   = LoadState::LOAD_FINISHED;
+        // Get external textureSet from cacheManager.
+        std::string location = textureInfo.url.GetLocation();
+        if(!location.empty())
+        {
+          TextureId id                  = std::stoi(location);
+          auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
+          textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0));
+          textureInfo.loadState = TextureManager::LoadState::UPLOADED;
+        }
       }
-      else // For the image loading.
+      else
       {
-        Texture maskTexture;
-        if(maskTextureId != INVALID_TEXTURE_ID)
+        std::vector<Devel::PixelBuffer> pixelBuffers;
+        LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, loadYuvPlanes, pixelBuffers);
+
+        if(pixelBuffers.empty())
+        {
+          // If pixelBuffer loading is failed in synchronously, call RequestRemove() method.
+          RequestRemove(textureId, nullptr);
+          return INVALID_TEXTURE_ID;
+        }
+
+        if(storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
         {
-          TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
-          if(maskCacheIndex != INVALID_CACHE_INDEX)
+          textureInfo.pixelBuffer = pixelBuffers[0]; // Store the pixel data
+          textureInfo.loadState   = TextureManager::LoadState::LOAD_FINISHED;
+        }
+        else // For the image loading.
+        {
+          Texture maskTexture;
+          if(maskTextureId != INVALID_TEXTURE_ID)
           {
-            if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_TEXTURE)
+            TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
+            if(maskCacheIndex != INVALID_CACHE_INDEX)
             {
-              TextureSet maskTextures = mTextureCacheManager[maskCacheIndex].textureSet;
-              if(maskTextures && maskTextures.GetTextureCount())
+              if(mTextureCacheManager[maskCacheIndex].storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER)
               {
-                maskTexture = maskTextures.GetTexture(0u);
+                Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
+                if(maskPixelBuffer)
+                {
+                  pixelBuffers[0].ApplyMask(maskPixelBuffer, contentScale, cropToMask);
+                }
+                else
+                {
+                  DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
+                }
               }
             }
-            else if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER)
+            else
             {
-              Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
-              if(maskPixelBuffer)
-              {
-                pixelBuffers[0].ApplyMask(maskPixelBuffer, contentScale, cropToMask);
-              }
-              else
-              {
-                DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
-              }
+              DALI_LOG_ERROR("Mask image is not stored in cache.\n");
             }
           }
-          else
-          {
-            DALI_LOG_ERROR("Mask image is not stored in cache.\n");
-          }
-        }
-        PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
+          PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
 
-        // Upload texture
-        UploadTextures(pixelBuffers, textureInfo);
-        if(maskTexture && textureInfo.textureSet)
-        {
-          textureInfo.textureSet.SetTexture(1u, maskTexture);
+          // Upload texture
+          UploadTextures(pixelBuffers, textureInfo);
         }
       }
     }
   }
+
   return textureId;
 }
 
-void TextureManager::Remove(const TextureManager::TextureId& textureId, TextureUploadObserver* observer)
+void TextureManager::RequestRemove(const TextureManager::TextureId textureId, TextureUploadObserver* observer)
 {
+  DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestRemove( textureId=%d observer=%p )\n", textureId, observer);
+
+  // Queue to remove.
   if(textureId != INVALID_TEXTURE_ID)
   {
     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
     if(textureCacheIndex != INVALID_CACHE_INDEX)
     {
-      TextureManager::TextureId maskTextureId = INVALID_TEXTURE_ID;
-      TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
-      if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
+      if(observer)
       {
-        maskTextureId = textureInfo.maskTextureId;
+        // Remove observer from cached texture info
+        TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+        RemoveTextureObserver(textureInfo, observer);
       }
 
-      // the case that LoadingQueue is working.
-      if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
+      mRemoveQueue.PushBack(textureId);
+
+      if(!mRemoveProcessorRegistered && Adaptor::IsAvailable())
       {
-        // If textureId is not same, this observer need to delete when ProcessRemoveQueue() is called.
-        TextureUploadObserver* queueObserver = nullptr;
-        if(mLoadingQueueTextureId != textureId)
-        {
-          queueObserver = observer;
-        }
+        mRemoveProcessorRegistered = true;
+        Adaptor::Get().RegisterProcessor(*this, true);
+      }
+    }
+  }
+}
 
-        // Remove textureId after NotifyObserver finished
-        if(maskTextureId != INVALID_TEXTURE_ID)
+void TextureManager::Remove(const TextureManager::TextureId textureId)
+{
+  if(textureId != INVALID_TEXTURE_ID)
+  {
+    TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+    if(textureCacheIndex != INVALID_CACHE_INDEX)
+    {
+      TextureManager::TextureId maskTextureId = INVALID_TEXTURE_ID;
+      TextureInfo&              textureInfo(mTextureCacheManager[textureCacheIndex]);
+      // We only need to consider maskTextureId when texture's loadState is not cancelled. Because it is already deleted.
+      if(textureInfo.loadState != TextureManager::LoadState::CANCELLED && textureInfo.loadState != TextureManager::LoadState::MASK_CANCELLED)
+      {
+        if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
         {
-          if(textureInfo.loadState != LoadState::CANCELLED)
-          {
-            mRemoveQueue.PushBack(QueueElement(maskTextureId, nullptr));
-          }
+          maskTextureId = textureInfo.maskTextureId;
         }
-        mRemoveQueue.PushBack(QueueElement(textureId, queueObserver));
       }
-      else
-      {
-        // Remove its observer
-        RemoveTextureObserver(textureInfo, observer);
 
-        // Remove maskTextureId in CacheManager
-        if(maskTextureId != INVALID_TEXTURE_ID)
+      DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Remove( textureId=%d ) cacheIndex:%d removal maskTextureId=%d, loadState=%s\n", textureId, textureCacheIndex.GetIndex(), maskTextureId, GET_LOAD_STATE_STRING(textureInfo.loadState));
+
+      // Remove textureId in CacheManager. Now, textureInfo is invalidate.
+      mTextureCacheManager.RemoveCache(textureInfo);
+
+      // Remove maskTextureId in CacheManager
+      if(maskTextureId != INVALID_TEXTURE_ID)
+      {
+        TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
+        if(maskCacheIndex != INVALID_CACHE_INDEX)
         {
-          TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
-          if(maskCacheIndex != INVALID_CACHE_INDEX)
-          {
-            TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
+          TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
 
-            // Only Remove maskTexture when texture's loadState is not CANCELLED. because it is already deleted.
-            if(textureInfo.loadState != LoadState::CANCELLED)
-            {
-              mTextureCacheManager.RemoveCache(maskTextureInfo);
-            }
-          }
-        }
+          DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Remove mask texture( maskTextureId=%d ) cacheIndex:%d, loadState=%s\n", maskTextureId, maskCacheIndex.GetIndex(), GET_LOAD_STATE_STRING(maskTextureInfo.loadState));
 
-        // Remove textureId in CacheManager
-        mTextureCacheManager.RemoveCache(textureInfo);
+          mTextureCacheManager.RemoveCache(maskTextureInfo);
+        }
       }
     }
+  }
+}
+
+void TextureManager::ProcessRemoveQueue()
+{
+  DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_TEXTURE_MANAGER_PROCESS_REMOVE_QUEUE", [&](std::ostringstream& oss) {
+    oss << "[" << mRemoveQueue.Count() << "]";
+  });
 
-    if(observer)
+  // Note that RemoveQueue is not be changed during Remove().
+  for(auto&& textureId : mRemoveQueue)
+  {
+    if(textureId != INVALID_TEXTURE_ID)
     {
-      // Remove element from the LoadQueue
-      for(auto&& element : mLoadQueue)
-      {
-        if(element.mObserver == observer)
-        {
-          // Do not erase the item. We will clear it later in ProcessLoadQueue().
-          element.mObserver = nullptr;
-          break;
-        }
-      }
+      Remove(textureId);
     }
   }
+
+  mRemoveQueue.Clear();
+
+  DALI_TRACE_END(gTraceFilter, "DALI_TEXTURE_MANAGER_PROCESS_REMOVE_QUEUE");
+}
+
+void TextureManager::Process(bool postProcessor)
+{
+  DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Process()\n");
+
+  ProcessRemoveQueue();
+
+  if(Adaptor::IsAvailable())
+  {
+    Adaptor::Get().UnregisterProcessor(*this, true);
+    mRemoveProcessorRegistered = false;
+  }
 }
 
 void TextureManager::LoadImageSynchronously(
   const VisualUrl&                 url,
   const Dali::ImageDimensions&     desiredSize,
-  const Dali::FittingMode::Type&   fittingMode,
-  const Dali::SamplingMode::Type&  samplingMode,
-  const bool&                      orientationCorrection,
-  const bool&                      loadYuvPlanes,
+  const Dali::FittingMode::Type    fittingMode,
+  const Dali::SamplingMode::Type   samplingMode,
+  const bool                       orientationCorrection,
+  const bool                       loadYuvPlanes,
   std::vector<Devel::PixelBuffer>& pixelBuffers)
 {
   Devel::PixelBuffer pixelBuffer;
@@ -833,35 +866,12 @@ void TextureManager::LoadImageSynchronously(
   }
 }
 
-void TextureManager::AddObserver(TextureManager::LifecycleObserver& observer)
-{
-  // make sure an observer doesn't observe the same object twice
-  // otherwise it will get multiple calls to ObjectDestroyed()
-  DALI_ASSERT_DEBUG(mLifecycleObservers.End() == std::find(mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
-  mLifecycleObservers.PushBack(&observer);
-}
-
-void TextureManager::RemoveObserver(TextureManager::LifecycleObserver& observer)
-{
-  // Find the observer...
-  auto endIter = mLifecycleObservers.End();
-  for(auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
-  {
-    if((*iter) == &observer)
-    {
-      mLifecycleObservers.Erase(iter);
-      break;
-    }
-  }
-  DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
-}
-
 void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
 {
   switch(textureInfo.loadState)
   {
-    case LoadState::NOT_STARTED:
-    case LoadState::LOAD_FAILED:
+    case TextureManager::LoadState::NOT_STARTED:
+    case TextureManager::LoadState::LOAD_FAILED:
     {
       if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
       {
@@ -873,7 +883,7 @@ void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo
       }
       break;
     }
-    case LoadState::UPLOADED:
+    case TextureManager::LoadState::UPLOADED:
     {
       if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
       {
@@ -883,16 +893,20 @@ void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo
       {
         // The Texture has already loaded. The other observers have already been notified.
         // We need to send a "late" loaded notification for this observer.
-        EmitLoadComplete(observer, textureInfo, true);
+        if(observer)
+        {
+          EmitLoadComplete(observer, textureInfo, true);
+        }
       }
       break;
     }
-    case LoadState::LOADING:
-    case LoadState::CANCELLED:
-    case LoadState::LOAD_FINISHED:
-    case LoadState::WAITING_FOR_MASK:
-    case LoadState::MASK_APPLYING:
-    case LoadState::MASK_APPLIED:
+    case TextureManager::LoadState::LOADING:
+    case TextureManager::LoadState::CANCELLED:
+    case TextureManager::LoadState::MASK_CANCELLED:
+    case TextureManager::LoadState::LOAD_FINISHED:
+    case TextureManager::LoadState::WAITING_FOR_MASK:
+    case TextureManager::LoadState::MASK_APPLYING:
+    case TextureManager::LoadState::MASK_APPLIED:
     {
       break;
     }
@@ -901,30 +915,32 @@ void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo
 
 void TextureManager::QueueLoadTexture(const TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
 {
+  DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Add observer to observer queue (textureId:%d, observer:%p)\n", textureInfo.textureId, observer);
+
   const auto& textureId = textureInfo.textureId;
   mLoadQueue.PushBack(QueueElement(textureId, observer));
 
-  observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
+  if(observer)
+  {
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Connect DestructionSignal to observer:%p\n", observer);
+    observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
+  }
 }
 
 void TextureManager::LoadTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
 {
   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::LoadTexture(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
-
-  textureInfo.loadState = LoadState::LOADING;
+  textureInfo.loadState = TextureManager::LoadState::LOADING;
   if(!textureInfo.loadSynchronously)
   {
-    auto& loadersContainer  = (textureInfo.url.IsLocalResource() || textureInfo.url.IsBufferResource()) ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
-    auto  loadingHelperIt   = loadersContainer.GetNext();
-    auto  premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
-    DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
+    auto premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
     if(textureInfo.animatedImageLoading)
     {
-      loadingHelperIt->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, premultiplyOnLoad);
+      mAsyncLoader->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, premultiplyOnLoad);
     }
     else
     {
-      loadingHelperIt->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad, textureInfo.loadYuvPlanes);
+      mAsyncLoader->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad, textureInfo.loadYuvPlanes);
     }
   }
   ObserveTexture(textureInfo, observer);
@@ -934,7 +950,7 @@ void TextureManager::ProcessLoadQueue()
 {
   for(auto&& element : mLoadQueue)
   {
-    if(!element.mObserver)
+    if(element.mTextureId == INVALID_TEXTURE_ID)
     {
       continue;
     }
@@ -943,11 +959,22 @@ void TextureManager::ProcessLoadQueue()
     if(cacheIndex != INVALID_CACHE_INDEX)
     {
       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
-      if((textureInfo.loadState == LoadState::UPLOADED) || (textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER))
+
+      DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::ProcessLoadQueue() textureId=%d, observer=%p, cacheIndex=@%d, loadState:%s\n", element.mTextureId, element.mObserver, cacheIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState));
+
+      if((textureInfo.loadState == TextureManager::LoadState::UPLOADED) ||
+         (textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED &&
+          textureInfo.storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER))
       {
-        EmitLoadComplete(element.mObserver, textureInfo, true);
+        if(element.mObserver)
+        {
+          DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", element.mObserver);
+          element.mObserver->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
+
+          EmitLoadComplete(element.mObserver, textureInfo, true);
+        }
       }
-      else if(textureInfo.loadState == LoadState::LOADING)
+      else if(textureInfo.loadState == TextureManager::LoadState::LOADING)
       {
         // Note : LOADING state texture cannot be queue.
         // This case be occured when same texture id are queue in mLoadQueue.
@@ -959,23 +986,8 @@ void TextureManager::ProcessLoadQueue()
       }
     }
   }
-  mLoadQueue.Clear();
-}
 
-void TextureManager::ProcessRemoveQueue()
-{
-  TextureCacheIndex textureCacheIndex = INVALID_CACHE_INDEX;
-  for(auto&& element : mRemoveQueue)
-  {
-    textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(element.mTextureId);
-    if(textureCacheIndex != INVALID_CACHE_INDEX)
-    {
-      TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
-      RemoveTextureObserver(textureInfo, element.mObserver);
-      mTextureCacheManager.RemoveCache(textureInfo);
-    }
-  }
-  mRemoveQueue.Clear();
+  mLoadQueue.Clear();
 }
 
 void TextureManager::ObserveTexture(TextureManager::TextureInfo& textureInfo,
@@ -986,11 +998,13 @@ void TextureManager::ObserveTexture(TextureManager::TextureInfo& textureInfo,
   if(observer)
   {
     textureInfo.observerList.PushBack(observer);
+
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Connect DestructionSignal to observer:%p\n", observer);
     observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
   }
 }
 
-void TextureManager::AsyncLoadComplete(const TextureManager::TextureId& textureId, std::vector<Devel::PixelBuffer>& pixelBuffers)
+void TextureManager::AsyncLoadComplete(const TextureManager::TextureId textureId, std::vector<Devel::PixelBuffer>& pixelBuffers)
 {
   TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( textureId:%d CacheIndex:%d )\n", textureId, cacheIndex.GetIndex());
@@ -999,46 +1013,42 @@ void TextureManager::AsyncLoadComplete(const TextureManager::TextureId& textureI
     TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
 
     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "  textureId:%d Url:%s CacheIndex:%d LoadState: %s\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState));
-
-    if(textureInfo.loadState != LoadState::CANCELLED)
+    if(textureInfo.loadState != TextureManager::LoadState::CANCELLED && textureInfo.loadState != TextureManager::LoadState::MASK_CANCELLED)
     {
       // textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
       PostLoad(textureInfo, pixelBuffers);
     }
     else
     {
-      Remove(textureInfo.textureId, nullptr);
+      Remove(textureInfo.textureId);
     }
   }
 }
 
 void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vector<Devel::PixelBuffer>& pixelBuffers)
 {
-  // Was the load successful?
-  if(!pixelBuffers.empty())
+  if(!pixelBuffers.empty()) ///< Load success
   {
     if(pixelBuffers.size() == 1)
     {
       Devel::PixelBuffer pixelBuffer = pixelBuffers[0];
       if(pixelBuffer && (pixelBuffer.GetWidth() != 0) && (pixelBuffer.GetHeight() != 0))
       {
-        // No atlas support for now
-        textureInfo.useAtlas      = UseAtlas::NO_ATLAS;
         textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
 
-        if(textureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE)
+        if(textureInfo.storageType == TextureManager::StorageType::UPLOAD_TO_TEXTURE)
         {
           // If there is a mask texture ID associated with this texture, then apply the mask
           // if it's already loaded. If it hasn't, and the mask is still loading,
           // wait for the mask to finish loading.
           // note, If the texture is already uploaded synchronously during loading,
           // we don't need to apply mask.
-          if(textureInfo.loadState != LoadState::UPLOADED &&
+          if(textureInfo.loadState != TextureManager::LoadState::UPLOADED &&
              textureInfo.maskTextureId != INVALID_TEXTURE_ID)
           {
-            if(textureInfo.loadState == LoadState::MASK_APPLYING)
+            if(textureInfo.loadState == TextureManager::LoadState::MASK_APPLYING)
             {
-              textureInfo.loadState = LoadState::MASK_APPLIED;
+              textureInfo.loadState = TextureManager::LoadState::MASK_APPLIED;
               UploadTextures(pixelBuffers, textureInfo);
               NotifyObservers(textureInfo, true);
             }
@@ -1046,37 +1056,31 @@ void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vec
             {
               LoadState maskLoadState = mTextureCacheManager.GetTextureStateInternal(textureInfo.maskTextureId);
               textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
-              if(maskLoadState == LoadState::LOADING)
+              if(maskLoadState == TextureManager::LoadState::LOADING)
               {
-                textureInfo.loadState = LoadState::WAITING_FOR_MASK;
+                textureInfo.loadState = TextureManager::LoadState::WAITING_FOR_MASK;
               }
-              else if(maskLoadState == LoadState::LOAD_FINISHED || maskLoadState == LoadState::UPLOADED)
+              else if(maskLoadState == TextureManager::LoadState::LOAD_FINISHED || maskLoadState == TextureManager::LoadState::UPLOADED)
               {
-                // Send New Task to Thread
                 TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
                 if(maskCacheIndex != INVALID_CACHE_INDEX)
                 {
                   TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
-                  if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
+                  if(maskTextureInfo.storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER)
                   {
-                    // Send New Task to Thread
                     ApplyMask(textureInfo, textureInfo.maskTextureId);
                   }
-                  else if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
+                  else if(maskTextureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
                   {
                     // Upload image texture. textureInfo.loadState will be UPLOADED.
                     UploadTextures(pixelBuffers, textureInfo);
-                    if(maskTextureInfo.textureSet.GetTextureCount() > 0u)
-                    {
-                      Texture maskTexture = maskTextureInfo.textureSet.GetTexture(0u);
-                      textureInfo.textureSet.SetTexture(1u, maskTexture);
-                    }
+
                     // notify mask texture set.
                     NotifyObservers(textureInfo, true);
                   }
                 }
               }
-              else // maskLoadState == LoadState::LOAD_FAILED
+              else // maskLoadState == TextureManager::LoadState::LOAD_FAILED
               {
                 // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
                 DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
@@ -1094,13 +1098,13 @@ void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vec
         else
         {
           textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
-          textureInfo.loadState   = LoadState::LOAD_FINISHED;
+          textureInfo.loadState   = TextureManager::LoadState::LOAD_FINISHED;
 
-          if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
+          if(textureInfo.storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER)
           {
             NotifyObservers(textureInfo, true);
           }
-          else // for the StorageType::KEEP_PIXEL_BUFFER and StorageType::KEEP_TEXTURE
+          else // for the TextureManager::StorageType::KEEP_PIXEL_BUFFER and TextureManager::StorageType::KEEP_TEXTURE
           {
             // Check if there was another texture waiting for this load to complete
             // (e.g. if this was an image mask, and its load is on a different thread)
@@ -1112,18 +1116,16 @@ void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vec
     else
     {
       // YUV case
-      // No atlas support for now
-      textureInfo.useAtlas      = UseAtlas::NO_ATLAS;
       textureInfo.preMultiplied = false;
 
       UploadTextures(pixelBuffers, textureInfo);
       NotifyObservers(textureInfo, true);
     }
   }
-  else
+  else ///< Load fail
   {
-    textureInfo.loadState = LoadState::LOAD_FAILED;
-    if(textureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER || textureInfo.storageType == StorageType::KEEP_TEXTURE)
+    textureInfo.loadState = TextureManager::LoadState::LOAD_FAILED;
+    if(textureInfo.storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER || textureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
     {
       // Check if there was another texture waiting for this load to complete
       // (e.g. if this was an image mask, and its load is on a different thread)
@@ -1138,8 +1140,8 @@ void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vec
 
 void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTextureInfo)
 {
-  if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED &&
-     maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
+  if(maskTextureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED &&
+     maskTextureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
   {
     // Upload mask texture. textureInfo.loadState will be UPLOADED.
     std::vector<Devel::PixelBuffer> pixelBuffers;
@@ -1147,57 +1149,105 @@ void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTex
     UploadTextures(pixelBuffers, maskTextureInfo);
   }
 
-  // Search the cache, checking if any texture has this texture id as a
-  // maskTextureId:
-  const std::size_t size = mTextureCacheManager.size();
+  DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): maskTextureId=%d, maskTextureUrl=%s\n", maskTextureInfo.textureId, maskTextureInfo.url.GetUrl().c_str());
+
+  // Search the cache, checking if any texture has this texture id as a maskTextureId
+  const size_t size = mTextureCacheManager.size();
+
+  // Keep notify observer required textureIds.
+  // Note : NotifyObservers can change mTextureCacheManager cache struct. We should check id's validation before notify.
+  std::vector<TextureId> notifyRequiredTextureIds;
 
   // TODO : Refactorize here to not iterate whole cached image.
   for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
   {
     if(mTextureCacheManager[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
-       mTextureCacheManager[cacheIndex].loadState == LoadState::WAITING_FOR_MASK)
+       mTextureCacheManager[cacheIndex].loadState == TextureManager::LoadState::WAITING_FOR_MASK)
     {
       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
 
-      if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED)
+      if(maskTextureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED)
       {
-        if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
+        if(maskTextureInfo.storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER)
         {
-          // Send New Task to Thread
           ApplyMask(textureInfo, maskTextureInfo.textureId);
         }
       }
-      else if(maskTextureInfo.loadState == LoadState::UPLOADED)
+      else if(maskTextureInfo.loadState == TextureManager::LoadState::UPLOADED)
       {
-        if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
+        if(maskTextureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
         {
-          // Upload image texture. textureInfo.loadState will be UPLOADED.
-          std::vector<Devel::PixelBuffer> pixelBuffers;
-          pixelBuffers.push_back(textureInfo.pixelBuffer);
-          UploadTextures(pixelBuffers, textureInfo);
-          if(maskTextureInfo.textureSet.GetTextureCount() > 0u)
+          if(textureInfo.url.GetProtocolType() == VisualUrl::TEXTURE)
+          {
+            // Get external textureSet from cacheManager.
+            std::string location = textureInfo.url.GetLocation();
+            if(!location.empty())
+            {
+              TextureId id                  = std::stoi(location);
+              auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
+              textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0));
+              textureInfo.loadState = TextureManager::LoadState::UPLOADED;
+            }
+          }
+          else
           {
-            Texture maskTexture = maskTextureInfo.textureSet.GetTexture(0u);
-            textureInfo.textureSet.SetTexture(1u, maskTexture);
+            // Upload image texture. textureInfo.loadState will be UPLOADED.
+            std::vector<Devel::PixelBuffer> pixelBuffers;
+            pixelBuffers.push_back(textureInfo.pixelBuffer);
+            UploadTextures(pixelBuffers, textureInfo);
           }
-          // notify mask texture set.
-          NotifyObservers(textureInfo, true);
+
+          // Increase reference counts for notify required textureId.
+          // Now we can assume that we don't remove & re-assign this textureId
+          // during NotifyObserver signal emit.
+          maskTextureInfo.referenceCount++;
+          textureInfo.referenceCount++;
+
+          DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): Ready to notify textureId=%d\n", textureInfo.textureId);
+
+          notifyRequiredTextureIds.push_back(textureInfo.textureId);
         }
       }
-      else
+      else // maskTextureInfo.loadState == TextureManager::LoadState::LOAD_FAILED
       {
         // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
         DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
         std::vector<Devel::PixelBuffer> pixelBuffers;
         pixelBuffers.push_back(textureInfo.pixelBuffer);
         UploadTextures(pixelBuffers, textureInfo);
-        NotifyObservers(textureInfo, true);
+
+        // Increase reference counts for notify required textureId.
+        // Now we can assume that we don't remove & re-assign this textureId
+        // during NotifyObserver signal emit.
+        maskTextureInfo.referenceCount++;
+        textureInfo.referenceCount++;
+
+        DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): Ready to notify textureId=%d\n", textureInfo.textureId);
+
+        notifyRequiredTextureIds.push_back(textureInfo.textureId);
       }
     }
   }
+
+  // Notify textures are masked
+  for(const auto textureId : notifyRequiredTextureIds)
+  {
+    TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+    if(textureCacheIndex != INVALID_CACHE_INDEX)
+    {
+      TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+      NotifyObservers(textureInfo, true);
+    }
+  }
+
+  // Decrease reference count
+  for(const auto textureId : notifyRequiredTextureIds)
+  {
+    RequestRemove(textureId, nullptr);
+  }
 }
 
-void TextureManager::ApplyMask(TextureManager::TextureInfo& textureInfo, const TextureManager::TextureId& maskTextureId)
+void TextureManager::ApplyMask(TextureManager::TextureInfo& textureInfo, const TextureManager::TextureId maskTextureId)
 {
   TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
   if(maskCacheIndex != INVALID_CACHE_INDEX)
@@ -1208,18 +1258,15 @@ void TextureManager::ApplyMask(TextureManager::TextureInfo& textureInfo, const T
 
     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ApplyMask(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
 
-    textureInfo.loadState   = LoadState::MASK_APPLYING;
-    auto& loadersContainer  = (textureInfo.url.IsLocalResource() || textureInfo.url.IsBufferResource()) ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
-    auto  loadingHelperIt   = loadersContainer.GetNext();
-    auto  premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
-    DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
-    loadingHelperIt->ApplyMask(textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad);
+    textureInfo.loadState  = TextureManager::LoadState::MASK_APPLYING;
+    auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
+    mAsyncLoader->ApplyMask(textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad);
   }
 }
 
 void TextureManager::UploadTextures(std::vector<Devel::PixelBuffer>& pixelBuffers, TextureManager::TextureInfo& textureInfo)
 {
-  if(!pixelBuffers.empty() && textureInfo.loadState != LoadState::UPLOADED && textureInfo.useAtlas != UseAtlas::USE_ATLAS)
+  if(!pixelBuffers.empty() && textureInfo.loadState != TextureManager::LoadState::UPLOADED)
   {
     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "  TextureManager::UploadTextures() New Texture for textureId:%d\n", textureInfo.textureId);
 
@@ -1232,19 +1279,15 @@ void TextureManager::UploadTextures(std::vector<Devel::PixelBuffer>& pixelBuffer
       renderingAddOn.CreateGeometry(textureInfo.textureId, pixelBuffers[0]);
     }
 
-    if(!textureInfo.textureSet)
-    {
-      textureInfo.textureSet = TextureSet::New();
-    }
+    // Remove previous textures and insert new textures
+    textureInfo.textures.clear();
 
-    uint32_t index = 0;
     for(auto&& pixelBuffer : pixelBuffers)
     {
-      Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight());
-
+      Texture   texture   = Texture::New(Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight());
       PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
       texture.Upload(pixelData);
-      textureInfo.textureSet.SetTexture(index++, texture);
+      textureInfo.textures.push_back(texture);
     }
   }
 
@@ -1252,10 +1295,10 @@ void TextureManager::UploadTextures(std::vector<Devel::PixelBuffer>& pixelBuffer
   // Note: This is regardless of success as we care about whether a
   // load attempt is in progress or not.  If unsuccessful, a broken
   // image is still loaded.
-  textureInfo.loadState = LoadState::UPLOADED;
+  textureInfo.loadState = TextureManager::LoadState::UPLOADED;
 }
 
-void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, const bool& success)
+void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, const bool success)
 {
   TextureId textureId = textureInfo.textureId;
 
@@ -1291,10 +1334,10 @@ void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, c
     // invalidating the reference to the textureInfo struct.
     // Texture load requests for the same URL are deferred until the end of this
     // method.
-    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::NotifyObservers() textureId:%d url:%s loadState:%s\n", textureId, info->url.GetUrl().c_str(), GET_LOAD_STATE_STRING(info->loadState));
-
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::NotifyObservers() observer:%p textureId:%d url:%s loadState:%s\n", observer, textureId, info->url.GetUrl().c_str(), GET_LOAD_STATE_STRING(info->loadState));
     // It is possible for the observer to be deleted.
     // Disconnect and remove the observer first.
+    DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
     observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
 
     info->observerList.Erase(info->observerList.End() - 1u);
@@ -1312,16 +1355,17 @@ void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, c
 
   mLoadingQueueTextureId = INVALID_TEXTURE_ID;
   ProcessLoadQueue();
-  ProcessRemoveQueue();
 
-  if(info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0)
+  if(info->storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0)
   {
-    Remove(info->textureId, nullptr);
+    RequestRemove(info->textureId, nullptr);
   }
 }
 
 void TextureManager::ObserverDestroyed(TextureUploadObserver* observer)
 {
+  DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::ObserverDestroyed() observer:%p\n", observer);
+
   const std::size_t size = mTextureCacheManager.size();
   for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
   {
@@ -1345,45 +1389,124 @@ void TextureManager::ObserverDestroyed(TextureUploadObserver* observer)
   {
     if(element.mObserver == observer)
     {
-      element.mObserver = nullptr;
+      DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Remove observer from observer queue (textureId:%d, observer:%p)\n", element.mTextureId, element.mObserver);
+      element.mTextureId = INVALID_TEXTURE_ID;
+      element.mObserver  = nullptr;
     }
   }
 }
 
-Dali::Geometry TextureManager::GetRenderGeometry(const TextureManager::TextureId& textureId, std::uint32_t& frontElements, std::uint32_t& backElements)
+Dali::Geometry TextureManager::GetRenderGeometry(const TextureManager::TextureId textureId, uint32_t& frontElements, uint32_t& backElements)
 {
   return RenderingAddOn::Get().IsValid() ? RenderingAddOn::Get().GetGeometry(textureId, frontElements, backElements) : Geometry();
 }
 
-void TextureManager::EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success)
+void TextureManager::EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool success)
 {
-  if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
+  if(textureInfo.storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER)
   {
     observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, textureInfo.pixelBuffer, textureInfo.url.GetUrl(), textureInfo.preMultiplied));
   }
-  else if(textureInfo.isAnimatedImageFormat)
+  else
   {
-    observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::ANIMATED_IMAGE_TEXTURE, textureInfo.textureId, textureInfo.frameCount, textureInfo.frameInterval));
+    TextureSet textureSet = GetTextureSet(textureInfo);
+    if(textureInfo.isAnimatedImageFormat)
+    {
+      observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::ANIMATED_IMAGE_TEXTURE, textureInfo.textureId, textureSet, textureInfo.frameCount, textureInfo.frameInterval, textureInfo.preMultiplied));
+    }
+    else
+    {
+      observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureSet, textureInfo.preMultiplied));
+    }
+  }
+}
+
+TextureSet TextureManager::GetTextureSet(const TextureManager::TextureId textureId)
+{
+  TextureSet                textureSet;
+  TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
+  if(loadState == TextureManager::LoadState::UPLOADED)
+  {
+    TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+    if(textureCacheIndex != INVALID_CACHE_INDEX)
+    {
+      TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+      textureSet = GetTextureSet(textureInfo);
+    }
   }
   else
   {
-    observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
+    DALI_LOG_ERROR("GetTextureSet is failed. texture is not uploaded \n");
   }
+  return textureSet;
+}
+
+TextureSet TextureManager::GetTextureSet(const TextureManager::TextureInfo& textureInfo)
+{
+  TextureSet textureSet;
+
+  // Always create new TextureSet here, so we don't share same TextureSets for multiple visuals.
+  textureSet = TextureSet::New();
+
+  if(!textureInfo.textures.empty())
+  {
+    if(textureInfo.textures.size() > 1) // For YUV case
+    {
+      uint32_t index = 0u;
+      for(auto&& texture : textureInfo.textures)
+      {
+        textureSet.SetTexture(index++, texture);
+      }
+    }
+    else
+    {
+      textureSet.SetTexture(TEXTURE_INDEX, textureInfo.textures[0]);
+      TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
+      if(maskCacheIndex != INVALID_CACHE_INDEX)
+      {
+        TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
+        if(maskTextureInfo.storageType == TextureManager::StorageType::UPLOAD_TO_TEXTURE || maskTextureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
+        {
+          if(!maskTextureInfo.textures.empty())
+          {
+            textureSet.SetTexture(MASK_TEXTURE_INDEX, maskTextureInfo.textures[0]);
+          }
+        }
+      }
+    }
+  }
+  return textureSet;
 }
 
 void TextureManager::RemoveTextureObserver(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
 {
-  // Remove its observer
   if(observer)
   {
-    const auto   iterEnd = textureInfo.observerList.End();
-    const auto   iter    = std::find(textureInfo.observerList.Begin(), iterEnd, observer);
+    const auto iterEnd = textureInfo.observerList.End();
+    const auto iter    = std::find(textureInfo.observerList.Begin(), iterEnd, observer);
     if(iter != iterEnd)
     {
       // Disconnect and remove the observer.
+      DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
       observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
       textureInfo.observerList.Erase(iter);
     }
+    else
+    {
+      // Given textureId might exist at load queue.
+      // Remove observer from the LoadQueue
+      for(auto&& element : mLoadQueue)
+      {
+        if(element.mTextureId == textureInfo.textureId && element.mObserver == observer)
+        {
+          DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Remove observer from observer queue (textureId:%d, observer:%p)\n", element.mTextureId, element.mObserver);
+          DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
+          observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
+          element.mObserver = nullptr;
+          break;
+        }
+      }
+    }
   }
 }