From 4b11a25bb26aeb1eaef96ac024de6009a790387f Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Thu, 16 Jan 2020 14:55:02 +0900 Subject: [PATCH] Remove the texture element from the load queue The observer can be deleted before the load queue is processed. Remove the load element from the queue when the texture is removed. Change-Id: I290d82b1f6b77db915f400af4cd2c05e0bd9558b --- .../src/dali-toolkit/utc-Dali-ImageView.cpp | 44 ++++++++++++++++++++++ .../visuals/animated-image/fixed-image-cache.cpp | 2 +- .../visuals/animated-image/rolling-image-cache.cpp | 4 +- .../internal/visuals/image/image-visual.cpp | 4 +- .../internal/visuals/texture-manager-impl.cpp | 21 +++++++++-- .../internal/visuals/texture-manager-impl.h | 3 +- 6 files changed, 68 insertions(+), 10 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp index bdf031d..a59b0ff 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -2488,3 +2488,47 @@ int UtcDaliImageViewSvgLoadingFailure(void) END_TEST; } + +namespace +{ + +static int gResourceReadySignalCounter = 0; + +void OnResourceReadySignal( Control control ) +{ + gResourceReadySignalCounter++; + + if( gResourceReadySignalCounter == 1 ) + { + // Set image twice + ImageView::DownCast( control ).SetImage( gImage_34_RGBA ); + ImageView::DownCast( control ).SetImage( gImage_34_RGBA ); + } +} + +} + +int UtcDaliImageViewSetImageOnResourceReadySignal(void) +{ + tet_infoline("Test setting image from within signal handler."); + + ToolkitTestApplication application; + + gResourceReadySignalCounter = 0; + + ImageView imageView = ImageView::New( gImage_34_RGBA ); + imageView.ResourceReadySignal().Connect( &OnResourceReadySignal ); + + Stage::GetCurrent().Add( imageView ); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION ); + + DALI_TEST_EQUALS( imageView.IsResourceReady(), true, 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 2fbfee1..e64a51b 100644 --- a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp @@ -49,7 +49,7 @@ FixedImageCache::~FixedImageCache() { for( std::size_t i = 0; i < mImageUrls.size() ; ++i ) { - mTextureManager.Remove( mImageUrls[i].mTextureId ); + mTextureManager.Remove( mImageUrls[i].mTextureId, this ); } } } 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 596ff88..c39be7e 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp @@ -75,7 +75,7 @@ RollingImageCache::~RollingImageCache() while( !mQueue.IsEmpty() ) { ImageFrame imageFrame = mQueue.PopFront(); - mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId ); + mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId, this ); } } } @@ -97,7 +97,7 @@ TextureSet RollingImageCache::NextFrame() TextureSet textureSet; ImageFrame imageFrame = mQueue.PopFront(); - mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId ); + mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId, this ); mImageUrls[ imageFrame.mUrlIndex ].mTextureId = TextureManager::INVALID_TEXTURE_ID; if( IsFrontReady() == true ) diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index f656e2d..ceb3669 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -227,7 +227,7 @@ ImageVisual::~ImageVisual() if( mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID ) { TextureManager& textureManager = mFactoryCache.GetTextureManager(); - textureManager.Remove( mMaskingData->mAlphaMaskId ); + textureManager.Remove( mMaskingData->mAlphaMaskId, this ); } } @@ -1011,7 +1011,7 @@ void ImageVisual::RemoveTexture() { if( mTextureId != TextureManager::INVALID_TEXTURE_ID ) { - mFactoryCache.GetTextureManager().Remove( mTextureId ); + mFactoryCache.GetTextureManager().Remove( mTextureId, this ); mTextureId = TextureManager::INVALID_TEXTURE_ID; } else diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.cpp b/dali-toolkit/internal/visuals/texture-manager-impl.cpp index a2381e8..bf78d25 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.cpp +++ b/dali-toolkit/internal/visuals/texture-manager-impl.cpp @@ -467,7 +467,7 @@ TextureManager::TextureId TextureManager::RequestLoadInternal( return textureId; } -void TextureManager::Remove( const TextureManager::TextureId textureId ) +void TextureManager::Remove( const TextureManager::TextureId textureId, TextureUploadObserver* observer ) { int textureInfoIndex = GetCacheIndexFromId( textureId ); if( textureInfoIndex != INVALID_INDEX ) @@ -475,9 +475,9 @@ void TextureManager::Remove( const TextureManager::TextureId textureId ) TextureInfo& textureInfo( mTextureInfoContainer[ textureInfoIndex ] ); DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, - "TextureManager::Remove(%d) url:%s\n cacheIdx:%d loadState:%s\n", + "TextureManager::Remove(%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n", textureId, textureInfo.url.GetUrl().c_str(), - textureInfoIndex, GET_LOAD_STATE_STRING( textureInfo.loadState ) ); + textureInfoIndex, GET_LOAD_STATE_STRING( textureInfo.loadState ), textureInfo.referenceCount ); // Decrement the reference count and check if this is the last user of this Texture. if( --textureInfo.referenceCount <= 0 ) @@ -514,6 +514,19 @@ void TextureManager::Remove( const TextureManager::TextureId textureId ) mTextureInfoContainer.erase( mTextureInfoContainer.begin() + textureInfoIndex ); } } + + if( observer ) + { + // Remove element from the LoadQueue + for( auto&& element : mLoadQueue ) + { + if( element.mObserver == observer ) + { + mLoadQueue.Erase( &element ); + break; + } + } + } } } @@ -791,7 +804,7 @@ void TextureManager::AsyncLoadComplete( AsyncLoadingInfoContainerType& loadingCo } else { - Remove( textureInfo.textureId ); + Remove( textureInfo.textureId, nullptr ); } } } diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.h b/dali-toolkit/internal/visuals/texture-manager-impl.h index 651bc44..7d66256 100755 --- a/dali-toolkit/internal/visuals/texture-manager-impl.h +++ b/dali-toolkit/internal/visuals/texture-manager-impl.h @@ -309,8 +309,9 @@ public: * occurrence of a Texture will cause its removal internally. * * @param[in] textureId The ID of the Texture to remove. + * @param[in] textureObserver The texture observer. */ - void Remove( const TextureManager::TextureId textureId ); + void Remove( const TextureManager::TextureId textureId, TextureUploadObserver* textureObserver ); /** * @brief Get the visualUrl associated with the texture id. -- 2.7.4