Merge "Fix resource ready state" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / texture-manager-impl.cpp
index 00b8eca..1db057b 100644 (file)
@@ -38,6 +38,7 @@
 namespace
 {
 
+constexpr auto INITIAL_CACHE_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};
 
@@ -131,7 +132,6 @@ TextureManager::TextureManager()
   mExternalTextures(),
   mLifecycleObservers(),
   mLoadQueue(),
-  mBrokenImageUrl(""),
   mCurrentTextureId( 0 ),
   mQueueLoadFlag(false)
 {
@@ -162,18 +162,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
     }
     if( !pixelBuffer )
     {
-      // use broken image
-      pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
-      PixelData pixelData;
-      if( pixelBuffer )
-      {
-        pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
-      }
-      Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(),
-                                      pixelData.GetWidth(), pixelData.GetHeight() );
-      texture.Upload( pixelData );
-      textureSet = TextureSet::New();
-      textureSet.SetTexture( 0u, texture );
+      DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
     }
     else
     {
@@ -293,18 +282,7 @@ TextureSet TextureManager::LoadTexture(
     }
     if( !data )
     {
-      // use broken image
-      Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
-      if( pixelBuffer )
-      {
-        PreMultiply( pixelBuffer, preMultiplyOnLoad );
-        data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
-      }
-      Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(),
-                                      data.GetWidth(), data.GetHeight() );
-      texture.Upload( data );
-      textureSet = TextureSet::New();
-      textureSet.SetTexture( 0u, texture );
+      DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous loading is failed\n");
     }
     else
     {
@@ -454,14 +432,18 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
 {
   // First check if the requested Texture is cached.
   bool isAnimatedImage = ( animatedImageLoading ) ? true : false;
-  const TextureHash textureHash = GenerateHash( url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
-                                                maskTextureId, storageType, isAnimatedImage, frameIndex );
 
-  TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
-  // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
-  int cacheIndex = FindCachedTexture( textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
-                                      maskTextureId, preMultiplyOnLoad, storageType, isAnimatedImage, frameIndex );
+  TextureHash textureHash = INITIAL_CACHE_NUMBER;
+  int cacheIndex = INVALID_CACHE_INDEX;
+  if(storageType != StorageType::RETURN_PIXEL_BUFFER && !isAnimatedImage)
+  {
+    textureHash = GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId);
+
+    // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
+    cacheIndex = FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad);
+  }
 
+  TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
   // Check if the requested Texture exists in the cache.
   if( cacheIndex != INVALID_CACHE_INDEX )
   {
@@ -994,7 +976,6 @@ void TextureManager::PostLoad( TextureInfo& textureInfo, Devel::PixelBuffer& pix
   }
   else
   {
-    // @todo If the load was unsuccessful, upload the broken image.
     textureInfo.loadState = LoadState::LOAD_FAILED;
     CheckForWaitingTexture( textureInfo );
     NotifyObservers( textureInfo, false );
@@ -1169,10 +1150,7 @@ TextureManager::TextureHash TextureManager::GenerateHash(
   const FittingMode::Type        fittingMode,
   const Dali::SamplingMode::Type samplingMode,
   const UseAtlas                 useAtlas,
-  TextureId                      maskTextureId,
-  StorageType                    storageType,
-  bool                           isAnimationImage,
-  uint32_t                       frameIndex )
+  TextureId                      maskTextureId)
 {
   std::string hashTarget( url );
   const size_t urlLength = hashTarget.length();
@@ -1193,8 +1171,8 @@ TextureManager::TextureHash TextureManager::GenerateHash(
     *hashTargetPtr++ = ( size.GetHeight() >> 8u ) & 0xff;
 
     // Bit-pack the FittingMode, SamplingMode and atlasing.
-    // FittingMode=2bits, SamplingMode=3bits, useAtlas=1bit, storageType=2bits
-    *hashTargetPtr   = ( fittingMode << 6u ) | ( samplingMode << 3 ) | ( useAtlas << 2 ) | static_cast<unsigned int>(storageType);
+    // FittingMode=2bits, SamplingMode=3bits, useAtlas=1bit
+    *hashTargetPtr   = ( fittingMode << 4u ) | ( samplingMode << 1 ) | useAtlas;
   }
   else
   {
@@ -1217,19 +1195,6 @@ TextureManager::TextureHash TextureManager::GenerateHash(
     }
   }
 
-  if( isAnimationImage )
-  {
-    auto textureIdIndex = hashTarget.length();
-    hashTarget.resize( hashTarget.length() + sizeof( uint32_t ) );
-    char* hashTargetPtr = &( hashTarget[ textureIdIndex ] );
-
-    for( size_t byteIter = 0; byteIter < sizeof( uint32_t ); ++byteIter )
-    {
-      *hashTargetPtr++ = frameIndex & 0xff;
-      frameIndex >>= 8u;
-    }
-  }
-
   if( maskTextureId != INVALID_TEXTURE_ID )
   {
     auto textureIdIndex = hashTarget.length();
@@ -1256,10 +1221,7 @@ int TextureManager::FindCachedTexture(
   const Dali::SamplingMode::Type    samplingMode,
   const bool                        useAtlas,
   TextureId                         maskTextureId,
-  TextureManager::MultiplyOnLoad    preMultiplyOnLoad,
-  StorageType                       storageType,
-  bool                              isAnimatedImage,
-  uint32_t                          frameIndex )
+  TextureManager::MultiplyOnLoad    preMultiplyOnLoad)
 {
   // Default to an invalid ID, in case we do not find a match.
   int cacheIndex = INVALID_CACHE_INDEX;
@@ -1279,10 +1241,7 @@ int TextureManager::FindCachedTexture(
           ( size == textureInfo.desiredSize ) &&
           ( ( size.GetWidth() == 0 && size.GetHeight() == 0 ) ||
             ( fittingMode == textureInfo.fittingMode &&
-              samplingMode == textureInfo.samplingMode ) ) &&
-          ( storageType == textureInfo.storageType ) &&
-          ( isAnimatedImage == ( ( textureInfo.animatedImageLoading ) ? true : false ) ) &&
-          ( frameIndex == textureInfo.frameIndex ) )
+              samplingMode == textureInfo.samplingMode ) ) )
       {
         // 1. If preMultiplyOnLoad is MULTIPLY_ON_LOAD, then textureInfo.preMultiplyOnLoad should be true. The premultiplication result can be different.
         // 2. If preMultiplyOnLoad is LOAD_WITHOUT_MULTIPLY, then textureInfo.preMultiplied should be false.
@@ -1394,11 +1353,6 @@ void TextureManager::AsyncLoadingHelper::AsyncLoadComplete(uint32_t           id
   mTextureManager.AsyncLoadComplete( mLoadingInfoContainer, id, pixelBuffer );
 }
 
-void TextureManager::SetBrokenImageUrl(const std::string& brokenImageUrl)
-{
-  mBrokenImageUrl = brokenImageUrl;
-}
-
 Geometry TextureManager::GetRenderGeometry(TextureId textureId, uint32_t& frontElements, uint32_t& backElements )
 {
   return RenderingAddOn::Get().IsValid() ?