Fix image-visual natural size issue using atlas 16/174916/20
authorhuiyu.eun <huiyu.eun@samsung.com>
Thu, 5 Apr 2018 02:29:36 +0000 (11:29 +0900)
committerhuiyu.eun <huiyu.eun@samsung.com>
Mon, 23 Jul 2018 05:35:30 +0000 (14:35 +0900)
Change-Id: Id91909d3a2d934b485723c0b1d2d21ab4b075b70
Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp
dali-toolkit/internal/visuals/image-atlas-manager.cpp
dali-toolkit/internal/visuals/image-atlas-manager.h
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h
dali-toolkit/internal/visuals/texture-manager-impl.cpp
dali-toolkit/internal/visuals/texture-manager-impl.h

index 02446a0..dcffb5b 100644 (file)
@@ -1708,3 +1708,29 @@ int UtcDaliImageViewPaddingProperty02(void)
 
   END_TEST;
 }
 
   END_TEST;
 }
+
+int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
+{
+  ToolkitTestApplication application;
+
+  // Check ImageView with background and main image, to ensure both visuals are marked as loaded
+  ImageView imageView = ImageView::New();
+  Property::Map imageMap;
+  imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
+  imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
+  imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
+  imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
+  Stage::GetCurrent().Add( imageView );
+
+  // Trigger a potential relayout
+  application.SendNotification();
+  application.Render();
+
+  Vector3 naturalSize = imageView.GetNaturalSize();
+
+  DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
+
+  END_TEST;
+}
+
index dd06d31..2fbfee1 100644 (file)
@@ -116,12 +116,13 @@ void FixedImageCache::LoadBatch()
     AtlasUploadObserver* atlasObserver = nullptr;
     ImageAtlasManagerPtr imageAtlasManager = nullptr;
     Vector4 textureRect;
     AtlasUploadObserver* atlasObserver = nullptr;
     ImageAtlasManagerPtr imageAtlasManager = nullptr;
     Vector4 textureRect;
+    Dali::ImageDimensions textureRectSize;
     auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     mTextureManager.LoadTexture(
       url, ImageDimensions(), FittingMode::SCALE_TO_FILL,
       SamplingMode::BOX_THEN_LINEAR, maskInfo,
     auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     mTextureManager.LoadTexture(
       url, ImageDimensions(), FittingMode::SCALE_TO_FILL,
       SamplingMode::BOX_THEN_LINEAR, maskInfo,
-      synchronousLoading, mImageUrls[ mUrlIndex ].mTextureId, textureRect,
+      synchronousLoading, mImageUrls[ mUrlIndex ].mTextureId, textureRect, textureRectSize,
       atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT,
       Dali::WrapMode::Type::DEFAULT, this,
       atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED,
       atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT,
       Dali::WrapMode::Type::DEFAULT, this,
       atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED,
index 9f9e623..4854076 100644 (file)
@@ -151,12 +151,13 @@ void RollingGifImageCache::LoadBatch()
       AtlasUploadObserver* atlasObserver = nullptr;
       ImageAtlasManagerPtr imageAtlasManager = nullptr;
       Vector4 textureRect;
       AtlasUploadObserver* atlasObserver = nullptr;
       ImageAtlasManagerPtr imageAtlasManager = nullptr;
       Vector4 textureRect;
+      Dali::ImageDimensions textureRectSize;
       auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
       mTextureManager.LoadTexture(
         mImageUrls[ imageFrame.mFrameNumber ].mUrl, ImageDimensions(), FittingMode::SCALE_TO_FILL,
         SamplingMode::BOX_THEN_LINEAR, maskInfo,
       auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
       mTextureManager.LoadTexture(
         mImageUrls[ imageFrame.mFrameNumber ].mUrl, ImageDimensions(), FittingMode::SCALE_TO_FILL,
         SamplingMode::BOX_THEN_LINEAR, maskInfo,
-        synchronousLoading, mImageUrls[ imageFrame.mFrameNumber ].mTextureId, textureRect,
+        synchronousLoading, mImageUrls[ imageFrame.mFrameNumber ].mTextureId, textureRect, textureRectSize,
         atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT,
         Dali::WrapMode::Type::DEFAULT, NULL,
         atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply );
         atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT,
         Dali::WrapMode::Type::DEFAULT, NULL,
         atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply );
index bee7234..596ff88 100644 (file)
@@ -151,12 +151,13 @@ void RollingImageCache::LoadBatch()
     AtlasUploadObserver* atlasObserver = nullptr;
     ImageAtlasManagerPtr imageAtlasManager = nullptr;
     Vector4 textureRect;
     AtlasUploadObserver* atlasObserver = nullptr;
     ImageAtlasManagerPtr imageAtlasManager = nullptr;
     Vector4 textureRect;
+    Dali::ImageDimensions textureRectSize;
     auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     mTextureManager.LoadTexture(
       url, ImageDimensions(), FittingMode::SCALE_TO_FILL,
       SamplingMode::BOX_THEN_LINEAR, maskInfo,
     auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     mTextureManager.LoadTexture(
       url, ImageDimensions(), FittingMode::SCALE_TO_FILL,
       SamplingMode::BOX_THEN_LINEAR, maskInfo,
-      synchronousLoading, mImageUrls[ imageFrame.mUrlIndex ].mTextureId, textureRect,
+      synchronousLoading, mImageUrls[ imageFrame.mUrlIndex ].mTextureId, textureRect, textureRectSize,
       atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT,
       Dali::WrapMode::Type::DEFAULT, this,
       atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED,
       atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT,
       Dali::WrapMode::Type::DEFAULT, this,
       atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED,
index d959c1a..2e4dfb4 100644 (file)
@@ -49,7 +49,7 @@ ImageAtlasManager::~ImageAtlasManager()
 
 TextureSet ImageAtlasManager::Add( Vector4& textureRect,
                                  const std::string& url,
 
 TextureSet ImageAtlasManager::Add( Vector4& textureRect,
                                  const std::string& url,
-                                 ImageDimensions size,
+                                 ImageDimensions& size,
                                  FittingMode::Type fittingMode,
                                  bool orientationCorrection,
                                  AtlasUploadObserver* atlasUploadObserver )
                                  FittingMode::Type fittingMode,
                                  bool orientationCorrection,
                                  AtlasUploadObserver* atlasUploadObserver )
@@ -68,6 +68,7 @@ TextureSet ImageAtlasManager::Add( Vector4& textureRect,
   {
     return TextureSet();
   }
   {
     return TextureSet();
   }
+  size = dimensions;
 
   unsigned int i = 0;
   for( AtlasContainer::iterator iter = mAtlasList.begin(); iter != mAtlasList.end(); ++iter)
 
   unsigned int i = 0;
   for( AtlasContainer::iterator iter = mAtlasList.begin(); iter != mAtlasList.end(); ++iter)
index 5907ca2..05ed3a5 100644 (file)
@@ -64,7 +64,7 @@ public:
    *
    * @param [out] textureRect The texture area of the resource image in the atlas.
    * @param [in] url The URL of the resource image file to use.
    *
    * @param [out] textureRect The texture area of the resource image in the atlas.
    * @param [in] url The URL of the resource image file to use.
-   * @param [in] size The width and height to fit the loaded image to.
+   * @param [in, out] size The width and height to fit the loaded image to.
    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
    * @param [in] atlasUploadObserver The object to observe the uploading state inside ImageAtlas.
    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
    * @param [in] atlasUploadObserver The object to observe the uploading state inside ImageAtlas.
@@ -72,7 +72,7 @@ public:
    */
   TextureSet Add( Vector4& textureRect,
                   const std::string& url,
    */
   TextureSet Add( Vector4& textureRect,
                   const std::string& url,
-                  ImageDimensions size = ImageDimensions(),
+                  ImageDimensions& size,
                   FittingMode::Type fittingMode = FittingMode::DEFAULT,
                   bool orientationCorrection = true,
                   AtlasUploadObserver* atlasUploadObserver = NULL );
                   FittingMode::Type fittingMode = FittingMode::DEFAULT,
                   bool orientationCorrection = true,
                   AtlasUploadObserver* atlasUploadObserver = NULL );
index 0e4f018..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 ),
   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 )
   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
   {
   }
   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);
     if( textureSet )
     {
       auto texture = textureSet.GetTexture(0);
@@ -768,7 +775,7 @@ void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& t
 
   textures = textureManager.LoadTexture( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode,
                                          mMaskingData, IsSynchronousResourceLoading(), mTextureId,
 
   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);
 
                                          mWrapModeV, textureObserver, atlasUploadObserver, atlasManager,
                                          mOrientationCorrection, forceReload, preMultiplyOnLoad);
 
index 6e48997..dd63c16 100644 (file)
@@ -374,6 +374,7 @@ private:
   Dali::Toolkit::ImageVisual::LoadPolicy::Type mLoadPolicy;
   Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
   Vector4 mAtlasRect;
   Dali::Toolkit::ImageVisual::LoadPolicy::Type mLoadPolicy;
   Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
   Vector4 mAtlasRect;
+  Dali::ImageDimensions mAtlasRectSize;
   bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
   bool mLoading;  ///< True if the texture is still loading.
   bool mOrientationCorrection; ///< true if the image will have it's orientation corrected.
   bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
   bool mLoading;  ///< True if the texture is still loading.
   bool mOrientationCorrection; ///< true if the image will have it's orientation corrected.
index a08b2c5..c617a51 100644 (file)
@@ -134,8 +134,8 @@ TextureSet TextureManager::LoadTexture(
   const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode,
   Dali::SamplingMode::Type samplingMode, const MaskingDataPointer& maskInfo,
   bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect,
   const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode,
   Dali::SamplingMode::Type samplingMode, const MaskingDataPointer& maskInfo,
   bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect,
-  bool& atlasingStatus, bool& loadingStatus, Dali::WrapMode::Type wrapModeU,
-  Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver,
+  Dali::ImageDimensions& textureRectSize, bool& atlasingStatus, bool& loadingStatus,
+  Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver,
   AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection,
   TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
 {
   AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection,
   TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
 {
@@ -205,6 +205,11 @@ TextureSet TextureManager::LoadTexture(
         textureSet = TextureSet::New();
         textureSet.SetTexture( 0u, texture );
       }
         textureSet = TextureSet::New();
         textureSet.SetTexture( 0u, texture );
       }
+      else
+      {
+        textureRectSize.SetWidth(data.GetWidth());
+        textureRectSize.SetHeight(data.GetHeight());
+      }
     }
   }
   else
     }
   }
   else
@@ -212,7 +217,7 @@ TextureSet TextureManager::LoadTexture(
     loadingStatus = true;
     if( atlasingStatus )
     {
     loadingStatus = true;
     if( atlasingStatus )
     {
-      textureSet = imageAtlasManager->Add( textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver );
+      textureSet = imageAtlasManager->Add( textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver);
     }
     if( !textureSet ) // big image, no atlasing or atlasing failed
     {
     }
     if( !textureSet ) // big image, no atlasing or atlasing failed
     {
@@ -245,6 +250,10 @@ TextureSet TextureManager::LoadTexture(
         textureSet = GetTextureSet( textureId );
       }
     }
         textureSet = GetTextureSet( textureId );
       }
     }
+    else
+    {
+      textureRectSize = desiredSize;
+    }
   }
 
   if( ! atlasingStatus && textureSet )
   }
 
   if( ! atlasingStatus && textureSet )
index e56fec4..59d191e 100644 (file)
@@ -175,7 +175,10 @@ public:
    * @param[in] maskInfo              Mask info structure
    * @param[in] synchronousLoading    true if the URL should be loaded synchronously
    * @param[out] textureId,           The textureId of the URL
    * @param[in] maskInfo              Mask info structure
    * @param[in] synchronousLoading    true if the URL should be loaded synchronously
    * @param[out] textureId,           The textureId of the URL
-   * @param[out] textureRect          The rectangle within the texture atlas that this URL occupies
+   * @param[out] textureRect          The rectangle within the texture atlas that this URL occupies,
+   *                                  this is the rectangle in normalized coordinates.
+   * @param[out] textureRectSize      The rectangle within the texture atlas that this URL occupies,
+   *                                  this is the same rectangle in pixels.
    * @param[in,out] atlasingStatus    Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
    *                                  be loaded, and marked successful, but this will be set to false.
    *                                  If atlasing succeeds, this will be set to true.
    * @param[in,out] atlasingStatus    Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
    *                                  be loaded, and marked successful, but this will be set to false.
    *                                  If atlasing succeeds, this will be set to true.
@@ -203,6 +206,7 @@ public:
                           bool                         synchronousLoading,
                           TextureManager::TextureId&   textureId,
                           Vector4&                     textureRect,
                           bool                         synchronousLoading,
                           TextureManager::TextureId&   textureId,
                           Vector4&                     textureRect,
+                          Dali::ImageDimensions&       textureRectSize,
                           bool&                        atlasingStatus,
                           bool&                        loadingStatus,
                           Dali::WrapMode::Type         wrapModeU,
                           bool&                        atlasingStatus,
                           bool&                        loadingStatus,
                           Dali::WrapMode::Type         wrapModeU,