Updated ImageVisual::GetNaturalSize to work with loaded images 11/142111/4
authorDavid Steele <david.steele@samsung.com>
Wed, 2 Aug 2017 13:11:52 +0000 (14:11 +0100)
committerDavid Steele <david.steele@samsung.com>
Wed, 2 Aug 2017 16:42:13 +0000 (17:42 +0100)
Change-Id: I33d5a66aec57460e318fced5b41deb16fe9beba5

dali-toolkit/internal/visuals/image/image-visual.cpp

index b558cfde60a0ae5ad99125a952a6692f925d9169..dcb222d4b1796a657559909bba1923ca8bf1eb1e 100644 (file)
@@ -528,8 +528,20 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize )
     naturalSize.y = mDesiredSize.GetHeight();
     return;
   }
+  else if( mImpl->mRenderer ) // Check if we have a loaded image
+  {
+    auto textureSet = mImpl->mRenderer.GetTextures();
+
+    if( textureSet )
+    {
+      auto texture = textureSet.GetTexture(0);
+      naturalSize.x = texture.GetWidth();
+      naturalSize.y = texture.GetHeight();
+      return;
+    }
+  }
 
-  else if( mMaskingData != NULL && mMaskingData->mAlphaMaskUrl.IsValid() &&
+  if( mMaskingData != NULL && mMaskingData->mAlphaMaskUrl.IsValid() &&
            mMaskingData->mCropToMask )
   {
     ImageDimensions dimensions = Dali::GetClosestImageSize( mMaskingData->mAlphaMaskUrl.GetUrl() );
@@ -540,23 +552,26 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize )
     }
     return;
   }
-  else if( mImageUrl.IsValid() && mImageUrl.GetLocation() == VisualUrl::LOCAL )
+  else if( mImageUrl.IsValid() )
   {
-    ImageDimensions dimensions = Dali::GetClosestImageSize( mImageUrl.GetUrl() );
-
-    if( dimensions != ImageDimensions( 0, 0 ) )
-    {
-      naturalSize.x = dimensions.GetWidth();
-      naturalSize.y = dimensions.GetHeight();
-    }
-    else
+    if( mImageUrl.GetLocation() == VisualUrl::LOCAL )
     {
-      Image brokenImage = VisualFactoryCache::GetBrokenVisualImage();
+      ImageDimensions dimensions = Dali::GetClosestImageSize( mImageUrl.GetUrl() );
+
+      if( dimensions != ImageDimensions( 0, 0 ) )
+      {
+        naturalSize.x = dimensions.GetWidth();
+        naturalSize.y = dimensions.GetHeight();
+      }
+      else
+      {
+        Image brokenImage = VisualFactoryCache::GetBrokenVisualImage();
 
-      naturalSize.x = brokenImage.GetWidth();
-      naturalSize.y = brokenImage.GetWidth();
+        naturalSize.x = brokenImage.GetWidth();
+        naturalSize.y = brokenImage.GetWidth();
+      }
+      return;
     }
-    return;
   }
 
   naturalSize = Vector2::ZERO;