Fix image-visual natural size issue using atlas
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image / image-visual.cpp
index 6aaa271..faeeaec 100644 (file)
@@ -268,6 +268,7 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
   mLoadPolicy( Toolkit::ImageVisual::LoadPolicy::ATTACHED ),
   mReleasePolicy( Toolkit::ImageVisual::ReleasePolicy::DETACHED ),
   mAtlasRect( 0.0f, 0.0f, 0.0f, 0.0f ),
+  mAtlasRectSize( 0, 0 ),
   mAttemptAtlasing( false ),
   mLoading( false ),
   mOrientationCorrection( true )
@@ -588,8 +589,14 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize )
   }
   else if( mImpl->mRenderer ) // Check if we have a loaded image
   {
-    auto textureSet = mImpl->mRenderer.GetTextures();
+    if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED )
+    {
+      naturalSize.x = mAtlasRectSize.GetWidth();
+      naturalSize.y = mAtlasRectSize.GetHeight();
+      return;
+    }
 
+    auto textureSet = mImpl->mRenderer.GetTextures();
     if( textureSet )
     {
       auto texture = textureSet.GetTexture(0);
@@ -623,7 +630,7 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize )
       }
       else
       {
-        Image brokenImage = VisualFactoryCache::GetBrokenVisualImage();
+        Image brokenImage = mFactoryCache.GetBrokenVisualImage();
 
         naturalSize.x = brokenImage.GetWidth();
         naturalSize.y = brokenImage.GetWidth();
@@ -768,7 +775,7 @@ void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& t
 
   textures = textureManager.LoadTexture( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode,
                                          mMaskingData, IsSynchronousResourceLoading(), mTextureId,
-                                         atlasRect, atlasing, mLoading, mWrapModeU,
+                                         atlasRect, mAtlasRectSize, atlasing, mLoading, mWrapModeU,
                                          mWrapModeV, textureObserver, atlasUploadObserver, atlasManager,
                                          mOrientationCorrection, forceReload, preMultiplyOnLoad);
 
@@ -1097,7 +1104,7 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur
       }
       else
       {
-        Image brokenImage = VisualFactoryCache::GetBrokenVisualImage();
+        Image brokenImage = mFactoryCache.GetBrokenVisualImage();
 
         textureSet = TextureSet::New();
         mImpl->mRenderer.SetTextures( textureSet );