From c7ecf3ad7916ef6897fa192ea02ff7b1b2fc1bd8 Mon Sep 17 00:00:00 2001 From: "huiyu.eun" Date: Thu, 5 Apr 2018 11:29:36 +0900 Subject: [PATCH] Fix image-visual natural size issue using atlas Change-Id: Id91909d3a2d934b485723c0b1d2d21ab4b075b70 Signed-off-by: huiyu.eun --- .../src/dali-toolkit/utc-Dali-ImageView.cpp | 26 ++++++++++++++++++++++ .../visuals/animated-image/fixed-image-cache.cpp | 3 ++- .../animated-image/rolling-gif-image-cache.cpp | 3 ++- .../visuals/animated-image/rolling-image-cache.cpp | 3 ++- .../internal/visuals/image-atlas-manager.cpp | 3 ++- .../internal/visuals/image-atlas-manager.h | 4 ++-- .../internal/visuals/image/image-visual.cpp | 11 +++++++-- dali-toolkit/internal/visuals/image/image-visual.h | 1 + .../internal/visuals/texture-manager-impl.cpp | 15 ++++++++++--- .../internal/visuals/texture-manager-impl.h | 6 ++++- 10 files changed, 63 insertions(+), 12 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp index 02446a0..dcffb5b 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -1708,3 +1708,29 @@ int UtcDaliImageViewPaddingProperty02(void) 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; +} + diff --git a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp index dd06d31..2fbfee1 100644 --- a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp @@ -116,12 +116,13 @@ void FixedImageCache::LoadBatch() 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, - 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, diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp index 9f9e623..4854076 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp @@ -151,12 +151,13 @@ void RollingGifImageCache::LoadBatch() 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, - 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 ); diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp index bee7234..596ff88 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp @@ -151,12 +151,13 @@ void RollingImageCache::LoadBatch() 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, - 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, diff --git a/dali-toolkit/internal/visuals/image-atlas-manager.cpp b/dali-toolkit/internal/visuals/image-atlas-manager.cpp index d959c1a..2e4dfb4 100644 --- a/dali-toolkit/internal/visuals/image-atlas-manager.cpp +++ b/dali-toolkit/internal/visuals/image-atlas-manager.cpp @@ -49,7 +49,7 @@ ImageAtlasManager::~ImageAtlasManager() TextureSet ImageAtlasManager::Add( Vector4& textureRect, const std::string& url, - ImageDimensions size, + ImageDimensions& size, FittingMode::Type fittingMode, bool orientationCorrection, AtlasUploadObserver* atlasUploadObserver ) @@ -68,6 +68,7 @@ TextureSet ImageAtlasManager::Add( Vector4& textureRect, { return TextureSet(); } + size = dimensions; unsigned int i = 0; for( AtlasContainer::iterator iter = mAtlasList.begin(); iter != mAtlasList.end(); ++iter) diff --git a/dali-toolkit/internal/visuals/image-atlas-manager.h b/dali-toolkit/internal/visuals/image-atlas-manager.h index 5907ca2..05ed3a5 100644 --- a/dali-toolkit/internal/visuals/image-atlas-manager.h +++ b/dali-toolkit/internal/visuals/image-atlas-manager.h @@ -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 [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. @@ -72,7 +72,7 @@ public: */ TextureSet Add( Vector4& textureRect, const std::string& url, - ImageDimensions size = ImageDimensions(), + ImageDimensions& size, FittingMode::Type fittingMode = FittingMode::DEFAULT, bool orientationCorrection = true, AtlasUploadObserver* atlasUploadObserver = NULL ); diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 0e4f018..faeeaec 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -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); @@ -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); diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index 6e48997..dd63c16 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -374,6 +374,7 @@ private: 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. diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.cpp b/dali-toolkit/internal/visuals/texture-manager-impl.cpp index a08b2c5..c617a51 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.cpp +++ b/dali-toolkit/internal/visuals/texture-manager-impl.cpp @@ -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, - 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 ) { @@ -205,6 +205,11 @@ TextureSet TextureManager::LoadTexture( textureSet = TextureSet::New(); textureSet.SetTexture( 0u, texture ); } + else + { + textureRectSize.SetWidth(data.GetWidth()); + textureRectSize.SetHeight(data.GetHeight()); + } } } else @@ -212,7 +217,7 @@ TextureSet TextureManager::LoadTexture( 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 { @@ -245,6 +250,10 @@ TextureSet TextureManager::LoadTexture( textureSet = GetTextureSet( textureId ); } } + else + { + textureRectSize = desiredSize; + } } if( ! atlasingStatus && textureSet ) diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.h b/dali-toolkit/internal/visuals/texture-manager-impl.h index e56fec4..59d191e 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.h +++ b/dali-toolkit/internal/visuals/texture-manager-impl.h @@ -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[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. @@ -203,6 +206,7 @@ public: bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect, + Dali::ImageDimensions& textureRectSize, bool& atlasingStatus, bool& loadingStatus, Dali::WrapMode::Type wrapModeU, -- 2.7.4