ImageVisual ResourceReady signalled regardless of parent
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image / image-visual.cpp
index 9522618..57445ea 100644 (file)
@@ -303,7 +303,8 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const Image& image )
   mLoadPolicy( DevelImageVisual::LoadPolicy::ATTACHED ),
   mReleasePolicy( DevelImageVisual::ReleasePolicy::DESTROYED ),
   mAttemptAtlasing( false ),
-  mLoading( false )
+  mLoading( false ),
+  mOrientationCorrection( true )
 {
 }
 
@@ -399,6 +400,10 @@ void ImageVisual::DoSetProperties( const Property::Map& propertyMap )
       {
         DoSetProperty( Toolkit::DevelImageVisual::Property::RELEASE_POLICY, keyValue.second );
       }
+      else if( keyValue.first == ORIENTATION_CORRECTION_NAME )
+      {
+        DoSetProperty( Toolkit::DevelImageVisual::Property::ORIENTATION_CORRECTION, keyValue.second );
+      }
     }
   }
 
@@ -406,7 +411,7 @@ void ImageVisual::DoSetProperties( const Property::Map& propertyMap )
   if ( mLoadPolicy == DevelImageVisual::LoadPolicy::IMMEDIATE )
   {
     auto attemptAtlasing = mAttemptAtlasing;
-    LoadTexture( attemptAtlasing, mAtlasRect, mTextures );
+    LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection );
   }
 }
 
@@ -503,8 +508,7 @@ void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& v
 
     case Toolkit::ImageVisual::Property::ATLASING:
     {
-      bool atlasing = false;
-      mAttemptAtlasing = value.Get( atlasing );
+      value.Get( mAttemptAtlasing );
       break;
     }
 
@@ -557,6 +561,16 @@ void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& v
       int loadPolicy;
       Scripting::GetEnumerationProperty( value, LOAD_POLICY_TABLE, LOAD_POLICY_TABLE_COUNT, loadPolicy );
       mLoadPolicy = DevelImageVisual::LoadPolicy::Type( loadPolicy );
+      break;
+    }
+    case Toolkit::DevelImageVisual::Property::ORIENTATION_CORRECTION:
+    {
+      bool orientationCorrection( mOrientationCorrection );
+      if( value.Get( orientationCorrection ) )
+      {
+        mOrientationCorrection = orientationCorrection;
+      }
+      break;
     }
   }
 }
@@ -740,7 +754,7 @@ bool ImageVisual::IsSynchronousResourceLoading() const
   return mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
 }
 
-void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& textures )
+void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection )
 {
   TextureManager& textureManager = mFactoryCache.GetTextureManager();
 
@@ -757,7 +771,7 @@ void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& t
   textures = textureManager.LoadTexture( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode,
                                          mMaskingData, IsSynchronousResourceLoading(), mTextureId,
                                          atlasRect, atlasing, mLoading, mWrapModeU,
-                                         mWrapModeV, textureObserver, atlasUploadObserver, atlasManager );
+                                         mWrapModeV, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection );
 }
 
 void ImageVisual::InitializeRenderer()
@@ -769,7 +783,7 @@ void ImageVisual::InitializeRenderer()
 
   if( mTextureId == TextureManager::INVALID_TEXTURE_ID && ! mTextures ) // Only load the texture once
   {
-    LoadTexture( attemptAtlasing, mAtlasRect, mTextures );
+    LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection );
   }
 
   if( attemptAtlasing ) // Flag needs to be set before creating renderer
@@ -854,7 +868,7 @@ void ImageVisual::DoSetOnStage( Actor& actor )
     mPlacementActor.Reset();
 
     // Image loaded and ready to display
-    ResourceReady();
+    ResourceReady( Toolkit::Visual::ResourceStatus::READY );
   }
 }
 
@@ -912,6 +926,7 @@ void ImageVisual::DoCreatePropertyMap( Property::Map& map ) const
   map.Insert( Toolkit::ImageVisual::Property::WRAP_MODE_V, mWrapModeV );
 
   map.Insert( Toolkit::ImageVisual::Property::ATLASING, mAttemptAtlasing );
+
   if( mMaskingData != NULL )
   {
     map.Insert( Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mMaskingData->mAlphaMaskUrl.GetUrl() );
@@ -921,7 +936,7 @@ void ImageVisual::DoCreatePropertyMap( Property::Map& map ) const
 
   map.Insert( Toolkit::DevelImageVisual::Property::LOAD_POLICY, mLoadPolicy );
   map.Insert( Toolkit::DevelImageVisual::Property::RELEASE_POLICY, mReleasePolicy );
-
+  map.Insert( Toolkit::DevelImageVisual::Property::ORIENTATION_CORRECTION, mOrientationCorrection );
 }
 
 void ImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
@@ -948,6 +963,12 @@ void ImageVisual::OnSetTransform()
   }
 }
 
+bool ImageVisual::IsResourceReady() const
+{
+  return ( mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY ||
+           mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED );
+}
+
 Shader ImageVisual::GetImageShader( VisualFactoryCache& factoryCache, bool atlasing, bool defaultTextureWrapping )
 {
   Shader shader;
@@ -1014,12 +1035,15 @@ void ImageVisual::UploadCompleted()
     // reset the weak handle so that the renderer only get added to actor once
     mPlacementActor.Reset();
   }
+  // Image loaded
+  ResourceReady( Toolkit::Visual::ResourceStatus::READY );
   mLoading = false;
 }
 
 // From Texture Manager
 void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, TextureSet textureSet, bool usingAtlas, const Vector4& atlasRectangle )
 {
+  Toolkit::Visual::ResourceStatus resourceStatus;
   Actor actor = mPlacementActor.GetHandle();
   if( actor )
   {
@@ -1049,10 +1073,25 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur
 
         ApplyImageToSampler( brokenImage );
       }
-      // Image loaded and ready to display
-      ResourceReady();
     }
   }
+  // Storing TextureSet needed when renderer staged.
+  if( ! mImpl->mRenderer )
+  {
+    mTextures = textureSet;
+  }
+
+  // Image loaded, set status regardless of staged status.
+  if( loadingSuccess )
+  {
+    resourceStatus = Toolkit::Visual::ResourceStatus::READY;
+  }
+  else
+  {
+    resourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
+  }
+  // Signal to observers ( control ) that resources are ready. Must be all resources.
+  ResourceReady( resourceStatus );
   mLoading = false;
 }