Merge "Revert "Move Some Devel Properties & APIs to the Public API"" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image / image-visual.cpp
index 59cccd5..8845541 100644 (file)
@@ -33,6 +33,7 @@
 // INTERNAL HEADERS
 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
@@ -276,14 +277,17 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
   mMaskingData( ),
   mDesiredSize( size ),
   mTextureId( TextureManager::INVALID_TEXTURE_ID ),
+  mTextures(),
   mFittingMode( fittingMode ),
   mSamplingMode( samplingMode ),
   mWrapModeU( WrapMode::DEFAULT ),
   mWrapModeV( WrapMode::DEFAULT ),
   mLoadPolicy( DevelImageVisual::LoadPolicy::ATTACHED ),
   mReleasePolicy( DevelImageVisual::ReleasePolicy::DETACHED ),
+  mAtlasRect( 0.0f, 0.0f, 0.0f, 0.0f ),
   mAttemptAtlasing( false ),
-  mLoading( false )
+  mLoading( false ),
+  mOrientationCorrection( true )
 {
 }
 
@@ -296,12 +300,14 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const Image& image )
   mMaskingData( ),
   mDesiredSize(),
   mTextureId( TextureManager::INVALID_TEXTURE_ID ),
+  mTextures(),
   mFittingMode( FittingMode::DEFAULT ),
   mSamplingMode( SamplingMode::DEFAULT ),
   mWrapModeU( WrapMode::DEFAULT ),
   mWrapModeV( WrapMode::DEFAULT ),
   mLoadPolicy( DevelImageVisual::LoadPolicy::ATTACHED ),
   mReleasePolicy( DevelImageVisual::ReleasePolicy::DESTROYED ),
+  mAtlasRect( 0.0f, 0.0f, 0.0f, 0.0f ),
   mAttemptAtlasing( false ),
   mLoading( false ),
   mOrientationCorrection( true )
@@ -406,12 +412,12 @@ void ImageVisual::DoSetProperties( const Property::Map& propertyMap )
       }
     }
   }
-
   // Load image immediately if LOAD_POLICY requires it
   if ( mLoadPolicy == DevelImageVisual::LoadPolicy::IMMEDIATE )
   {
-    auto attemptAtlasing = mAttemptAtlasing;
-    LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection );
+    auto attemptAtlasing = AttemptAtlasing();
+    LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection,
+                 TextureManager::ReloadPolicy::CACHED  );
   }
 }
 
@@ -508,8 +514,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;
     }
 
@@ -755,7 +760,8 @@ bool ImageVisual::IsSynchronousResourceLoading() const
   return mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
 }
 
-void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection )
+void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection,
+                               TextureManager::ReloadPolicy forceReload )
 {
   TextureManager& textureManager = mFactoryCache.GetTextureManager();
 
@@ -772,28 +778,35 @@ 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, mOrientationCorrection );
+                                         mWrapModeV, textureObserver, atlasUploadObserver, atlasManager,
+                                         mOrientationCorrection,
+                                         forceReload );
+
+  if( atlasing ) // Flag needs to be set before creating renderer
+  {
+    mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
+  }
+  else
+  {
+    mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
+  }
 }
 
-void ImageVisual::InitializeRenderer()
+bool ImageVisual::AttemptAtlasing()
 {
-  auto attemptAtlasing = ( ! mImpl->mCustomShader && mImageUrl.GetProtocolType() == VisualUrl::LOCAL && mAttemptAtlasing );
+  return ( ! mImpl->mCustomShader && mImageUrl.GetProtocolType() == VisualUrl::LOCAL && mAttemptAtlasing );
+}
 
+void ImageVisual::InitializeRenderer()
+{
+  auto attemptAtlasing = AttemptAtlasing();
   // texture set has to be created first as we need to know if atlasing succeeded or not
   // when selecting the shader
 
   if( mTextureId == TextureManager::INVALID_TEXTURE_ID && ! mTextures ) // Only load the texture once
   {
-    LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection );
-  }
-
-  if( attemptAtlasing ) // Flag needs to be set before creating renderer
-  {
-    mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
-  }
-  else
-  {
-    mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
+    LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection,
+                 TextureManager::ReloadPolicy::CACHED );
   }
 
   CreateRenderer( mTextures );
@@ -956,6 +969,22 @@ void ImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
   }
 }
 
+void ImageVisual::OnDoAction( const Dali::Property::Index actionName, const Dali::Property::Value& attributes )
+{
+  // Check if action is valid for this visual type and perform action if possible
+
+  switch ( actionName )
+  {
+    case DevelImageVisual::Action::RELOAD:
+    {
+      auto attemptAtlasing = AttemptAtlasing();
+      LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection,
+                   TextureManager::ReloadPolicy::FORCED );
+      break;
+    }
+  }
+}
+
 void ImageVisual::OnSetTransform()
 {
   if( mImpl->mRenderer )
@@ -1027,7 +1056,8 @@ void ImageVisual::ApplyImageToSampler( const Image& image )
 // From existing atlas manager
 void ImageVisual::UploadCompleted()
 {
-  // Texture has been uploaded. If weak handle is holding a placement actor, it is the time to add the renderer to actor.
+  // Texture has been uploaded. If weak handle is holding a placement actor,
+  // it is the time to add the renderer to actor.
   Actor actor = mPlacementActor.GetHandle();
   if( actor )
   {
@@ -1036,11 +1066,14 @@ 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 )
+void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, TextureSet textureSet, bool usingAtlas,
+                                  const Vector4& atlasRectangle )
 {
   Toolkit::Visual::ResourceStatus resourceStatus;
   Actor actor = mPlacementActor.GetHandle();
@@ -1062,8 +1095,6 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur
         sampler.SetWrapMode(  mWrapModeU, mWrapModeV  );
         textureSet.SetSampler( 0u, sampler );
         mImpl->mRenderer.SetTextures(textureSet);
-
-        resourceStatus = Toolkit::Visual::ResourceStatus::READY;
       }
       else
       {
@@ -1073,13 +1104,26 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur
         mImpl->mRenderer.SetTextures( textureSet );
 
         ApplyImageToSampler( brokenImage );
-
-        resourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
       }
-      // Image loaded and ready to display
-      ResourceReady( resourceStatus );
     }
   }
+  // 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;
 }