Remove the texture element from the load queue
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image / image-visual.cpp
index 3f4e763..ceb3669 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -187,6 +187,7 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
   mLoading( false ),
   mOrientationCorrection( true )
 {
+  EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() );
 }
 
 ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const Image& image )
@@ -211,6 +212,7 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFac
   mLoading( false ),
   mOrientationCorrection( true )
 {
+  EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() );
 }
 
 ImageVisual::~ImageVisual()
@@ -225,7 +227,7 @@ ImageVisual::~ImageVisual()
       if( mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID )
       {
         TextureManager& textureManager = mFactoryCache.GetTextureManager();
-        textureManager.Remove( mMaskingData->mAlphaMaskId );
+        textureManager.Remove( mMaskingData->mAlphaMaskId, this );
       }
     }
 
@@ -423,10 +425,7 @@ void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& v
       if( value.Get( alphaUrl ) )
       {
         AllocateMaskData();
-        // Immediately trigger the alpha mask loading (it may just get a cached value)
         mMaskingData->mAlphaMaskUrl = alphaUrl;
-        TextureManager& textureManager = mFactoryCache.GetTextureManager();
-        mMaskingData->mAlphaMaskId = textureManager.RequestMaskLoad( alphaUrl );
       }
       break;
     }
@@ -683,7 +682,7 @@ void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& t
     atlasUploadObserver = this;
   }
 
-  auto preMultiplyOnLoad = mFactoryCache.GetPreMultiplyOnLoad() && !mImpl->mCustomShader
+  auto preMultiplyOnLoad = IsPreMultipliedAlphaEnabled() && !mImpl->mCustomShader
     ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
     : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
@@ -811,6 +810,7 @@ void ImageVisual::DoSetOffStage( Actor& actor )
   if( mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED )
   {
     RemoveTexture(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
+    mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
   }
 
   if( mImageUrl.IsValid() )
@@ -952,39 +952,41 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur
                                   const Vector4& atlasRectangle, bool preMultiplied )
 {
   Toolkit::Visual::ResourceStatus resourceStatus;
-  Actor actor = mPlacementActor.GetHandle();
-  if( actor )
+  if( mImpl->mRenderer )
   {
-    if( mImpl->mRenderer )
+    if( usingAtlas )
     {
-      if( usingAtlas )
-      {
-        mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, mAtlasRect );
-      }
+      mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, mAtlasRect );
+    }
 
-      EnablePreMultipliedAlpha( preMultiplied );
+    EnablePreMultipliedAlpha( preMultiplied );
 
+    Actor actor = mPlacementActor.GetHandle();
+    if( actor )
+    {
       actor.AddRenderer( mImpl->mRenderer );
       // reset the weak handle so that the renderer only get added to actor once
       mPlacementActor.Reset();
-      if( loadingSuccess )
-      {
-        Sampler sampler = Sampler::New();
-        sampler.SetWrapMode(  mWrapModeU, mWrapModeV  );
-        textureSet.SetSampler( 0u, sampler );
-        mImpl->mRenderer.SetTextures(textureSet);
-      }
-      else
-      {
-        Image brokenImage = mFactoryCache.GetBrokenVisualImage();
+    }
+
+    if( loadingSuccess )
+    {
+      Sampler sampler = Sampler::New();
+      sampler.SetWrapMode(  mWrapModeU, mWrapModeV  );
+      textureSet.SetSampler( 0u, sampler );
+      mImpl->mRenderer.SetTextures(textureSet);
+    }
+    else
+    {
+      Image brokenImage = mFactoryCache.GetBrokenVisualImage();
 
-        textureSet = TextureSet::New();
-        mImpl->mRenderer.SetTextures( textureSet );
+      textureSet = TextureSet::New();
+      mImpl->mRenderer.SetTextures( textureSet );
 
-        ApplyImageToSampler( brokenImage );
-      }
+      ApplyImageToSampler( brokenImage );
     }
   }
+
   // Storing TextureSet needed when renderer staged.
   if( ! mImpl->mRenderer )
   {
@@ -1009,7 +1011,7 @@ void ImageVisual::RemoveTexture()
 {
   if( mTextureId != TextureManager::INVALID_TEXTURE_ID )
   {
-    mFactoryCache.GetTextureManager().Remove( mTextureId );
+    mFactoryCache.GetTextureManager().Remove( mTextureId, this );
     mTextureId = TextureManager::INVALID_TEXTURE_ID;
   }
   else