tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
- // ApplyMask event come back, and do nothing.
- // CAPTION : HARD-CODING.
- {
- std::vector<Devel::PixelBuffer> pixelBuffers;
- textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
- textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
- }
-
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
- DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
- DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
- DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
-
// CAPTION : HARD-CODING.
{
std::vector<Devel::PixelBuffer> pixelBuffers;
const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
+const char* TEST_WEBP_FILE_NAME = TEST_RESOURCE_DIR "/dali-logo.webp";
void TestUrl(ImageView imageView, const std::string url)
{
}
}
+int gResourceReadySignal06ComesOrder = 0;
+
+void OnResourceReadySignal06(Control control)
+{
+ gResourceReadySignalCounter++;
+ if(gResourceReadySignalCounter == 1)
+ {
+ auto scene = gImageView1.GetParent();
+
+ // Request load something
+ // We hope this request result is return later than gImageView2.
+
+ Property::Map map1;
+ map1[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
+ map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
+
+ gImageView3 = ImageView::New();
+ gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
+ gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal06);
+
+ Property::Map map2;
+ map2[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
+ map2[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_S;
+ gImageView4 = ImageView::New();
+ gImageView4.SetProperty(Toolkit::ImageView::Property::IMAGE, map2);
+ gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal06);
+
+ if(control == gImageView1)
+ {
+ gResourceReadySignal06ComesOrder = 1;
+ }
+ else
+ {
+ gResourceReadySignal06ComesOrder = 2;
+ }
+ }
+ if(gResourceReadySignalCounter == 2)
+ {
+ if(gResourceReadySignal06ComesOrder == 1 && control == gImageView2)
+ {
+ // Scene off first one.
+ gImageView1.Unparent();
+
+ // Scene off second one.
+ gImageView2.Unparent();
+ }
+ else if(gResourceReadySignal06ComesOrder == 2 && control == gImageView1)
+ {
+ // Scene off first one.
+ gImageView2.Unparent();
+
+ // Scene off second one.
+ gImageView1.Unparent();
+ }
+ else
+ {
+ // We can't check that this utc fail case. just pass always when we come here.
+ gResourceReadySignal06ComesOrder = -1;
+ }
+
+ // If we don't seperate index of FreeList area
+ // and if we don't queue remove during obversing,
+ // cache index become something invalid data.
+ // In this case, some strange observer can be called.
+ // For example, gImageView4.LoadComplete will be called.
+ }
+}
+
} // namespace
int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
END_TEST;
}
+int UtcDaliImageViewSetImageOnResourceReadySignal06(void)
+{
+ tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler.");
+
+ ToolkitTestApplication application;
+
+ gResourceReadySignalCounter = 0;
+ gResourceReadySignal06ComesOrder = 0;
+
+ Property::Map map;
+ map[Toolkit::ImageVisual::Property::URL] = "invalid.jpg";
+ map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
+
+ gImageView1 = ImageView::New(); // request invalid image, to make loading failed fast.
+ gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
+ gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal06);
+ application.GetScene().Add(gImageView1);
+
+ gImageView2 = ImageView::New(); // request invalid image, to make loading failed fast.
+ gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
+ gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal06);
+ application.GetScene().Add(gImageView2);
+
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline("Try to load 2 invalid image");
+
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
+
+ tet_infoline("load done");
+
+ // We can test this UTC only if gImageView1 and gImageView2 loaded done.
+ if(gResourceReadySignal06ComesOrder == -1)
+ {
+ tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
+ }
+ else
+ {
+ // gImageView3 and gImageView4 load must not be successed yet.
+ DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
+ DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(gImageView3);
+ application.GetScene().Add(gImageView4);
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline("Try to load 2 valid image");
+
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
+
+ tet_infoline("load done");
+ }
+ END_TEST;
+}
+
+int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
+{
+ tet_infoline("Test multiple views with same image in animated image visual");
+ ToolkitTestApplication application;
+
+ gImageView1 = ImageView::New(TEST_WEBP_FILE_NAME);
+ application.GetScene().Add(gImageView1);
+
+ tet_infoline("Remove imageView and Create new imageView with same url");
+ application.GetScene().Remove(gImageView1);
+ gImageView2 = ImageView::New(TEST_WEBP_FILE_NAME);
+ application.GetScene().Add(gImageView2);
+
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline("Check the ImageView load image successfully");
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ END_TEST;
+}
return cacheIndex;
}
-void TextureCacheManager::RemoveCache(const TextureCacheManager::TextureId& textureId)
+void TextureCacheManager::RemoveCache(TextureCacheManager::TextureInfo& textureInfo)
{
- TextureCacheIndex textureInfoIndex = GetCacheIndexFromId(textureId);
-
+ TextureCacheIndex textureInfoIndex = GetCacheIndexFromId(textureInfo.textureId);
bool removeTextureInfo = false;
- if(textureInfoIndex != INVALID_CACHE_INDEX)
- {
- TextureInfo& textureInfo(mTextureInfoContainer[textureInfoIndex.GetIndex()]);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureCacheManager::Remove(textureId:%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), textureInfoIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState), textureInfo.referenceCount);
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureCacheManager::Remove(textureId:%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n", textureId, textureInfo.url.GetUrl().c_str(), textureInfoIndex.GetIndex(), 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)
+ {
+ // This is the last remove for this Texture.
+ textureInfo.referenceCount = 0;
- // Decrement the reference count and check if this is the last user of this Texture.
- if(--textureInfo.referenceCount <= 0)
+ // If loaded, we can remove the TextureInfo and the Atlas (if atlased).
+ if(textureInfo.loadState == LoadState::UPLOADED)
{
- // This is the last remove for this Texture.
- textureInfo.referenceCount = 0;
-
- // If loaded, we can remove the TextureInfo and the Atlas (if atlased).
- if(textureInfo.loadState == LoadState::UPLOADED)
- {
- if(textureInfo.atlas)
- {
- textureInfo.atlas.Remove(textureInfo.atlasRect);
- }
- removeTextureInfo = true;
- }
- else if(textureInfo.loadState == LoadState::LOADING || textureInfo.loadState == LoadState::MASK_APPLYING)
- {
- // We mark the textureInfo for removal.
- // Once the load has completed, this method will be called again.
- textureInfo.loadState = LoadState::CANCELLED;
- }
- else
+ if(textureInfo.atlas)
{
- // In other states, we are not waiting for a load so we are safe to remove the TextureInfo data.
- removeTextureInfo = true;
+ textureInfo.atlas.Remove(textureInfo.atlasRect);
}
+ removeTextureInfo = true;
+ }
+ else if(textureInfo.loadState == LoadState::LOADING || textureInfo.loadState == LoadState::MASK_APPLYING)
+ {
+ // We mark the textureInfo for removal.
+ // Once the load has completed, this method will be called again.
+ textureInfo.loadState = LoadState::CANCELLED;
+ }
+ else
+ {
+ // In other states, we are not waiting for a load so we are safe to remove the TextureInfo data.
+ removeTextureInfo = true;
+ }
- // If the state allows us to remove the TextureInfo data, we do so.
- if(removeTextureInfo)
+ // If the state allows us to remove the TextureInfo data, we do so.
+ if(removeTextureInfo)
+ {
+ // If url location is BUFFER, decrease reference count of EncodedImageBuffer.
+ if(textureInfo.url.IsBufferResource())
{
- // If url location is BUFFER, decrease reference count of EncodedImageBuffer.
- if(textureInfo.url.IsBufferResource())
- {
- RemoveEncodedImageBuffer(textureInfo.url.GetUrl());
- }
+ RemoveEncodedImageBuffer(textureInfo.url.GetUrl());
+ }
- // Permanently remove the textureInfo struct.
+ // Permanently remove the textureInfo struct.
- // Step 1. remove current textureId information in mTextureHashContainer.
- RemoveHashId(textureInfo.hash, textureId);
- // Step 2. make textureId is not using anymore. After this job, we can reuse textureId.
- mTextureIdConverter.Remove(textureId);
- }
+ // Step 1. remove current textureId information in mTextureHashContainer.
+ RemoveHashId(textureInfo.hash, textureInfo.textureId);
+ // Step 2. make textureId is not using anymore. After this job, we can reuse textureId.
+ mTextureIdConverter.Remove(textureInfo.textureId);
}
}
* Textures are cached and therefore only the removal of the last
* occurrence of a Texture will cause its removal internally.
*
- * @param[in] textureId The Id of the Texture to remove at Cache.
+ * @param[in] textureInfo TextureInfo that want to cache in container.
*/
- void RemoveCache(const TextureCacheManager::TextureId& textureId);
+ void RemoveCache(TextureCacheManager::TextureInfo& textureInfo);
public:
/**
mLifecycleObservers(),
mLoadQueue(),
mRemoveQueue(),
- mQueueLoadFlag(false),
+ mLoadingQueueTextureId(INVALID_TEXTURE_ID),
mLoadYuvPlanes(NeedToLoadYuvPlanes())
{
// Initialize the AddOn
loadState == TextureManager::LoadState::MASK_APPLYING ||
loadState == TextureManager::LoadState::MASK_APPLIED ||
loadState == TextureManager::LoadState::NOT_STARTED ||
- mQueueLoadFlag);
+ mLoadingQueueTextureId != INVALID_TEXTURE_ID);
}
else
{
{
if(textureId != INVALID_TEXTURE_ID)
{
- if(mQueueLoadFlag)
+ TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+ if(textureCacheIndex != INVALID_CACHE_INDEX)
{
- // Remove textureId after NotifyObserver finished
- mRemoveQueue.PushBack(textureId);
- }
- else
- {
- // Remove textureId in CacheManager.
- mTextureCacheManager.RemoveCache(textureId);
+ TextureManager::TextureId maskTextureId = INVALID_TEXTURE_ID;
+ TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+ if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
+ {
+ maskTextureId = textureInfo.maskTextureId;
+ }
+
+ // the case that LoadingQueue is working.
+ if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
+ {
+ // If textureId is not same, this observer need to delete when ProcessRemoveQueue() is called.
+ TextureUploadObserver* queueObserver = nullptr;
+ if(mLoadingQueueTextureId != textureId)
+ {
+ queueObserver = observer;
+ }
+
+ // Remove textureId after NotifyObserver finished
+ if(maskTextureId != INVALID_TEXTURE_ID)
+ {
+ if(textureInfo.loadState != LoadState::CANCELLED)
+ {
+ mRemoveQueue.PushBack(QueueElement(maskTextureId, nullptr));
+ }
+ }
+ mRemoveQueue.PushBack(QueueElement(textureId, queueObserver));
+ }
+ else
+ {
+ // Remove its observer
+ RemoveTextureObserver(textureInfo, observer);
+
+ // Remove maskTextureId in CacheManager
+ if(maskTextureId != INVALID_TEXTURE_ID)
+ {
+ TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
+ if(maskCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
+
+ // Only Remove maskTexture when texture's loadState is not CANCELLED. because it is already deleted.
+ if(textureInfo.loadState != LoadState::CANCELLED)
+ {
+ mTextureCacheManager.RemoveCache(maskTextureInfo);
+ }
+ }
+ }
+
+ // Remove textureId in CacheManager
+ mTextureCacheManager.RemoveCache(textureInfo);
+ }
}
if(observer)
case LoadState::NOT_STARTED:
case LoadState::LOAD_FAILED:
{
- if(mQueueLoadFlag)
+ if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
{
QueueLoadTexture(textureInfo, observer);
}
}
case LoadState::UPLOADED:
{
- if(mQueueLoadFlag)
+ if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
{
QueueLoadTexture(textureInfo, observer);
}
void TextureManager::QueueLoadTexture(const TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
{
const auto& textureId = textureInfo.textureId;
- mLoadQueue.PushBack(LoadQueueElement(textureId, observer));
+ mLoadQueue.PushBack(QueueElement(textureId, observer));
observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
}
void TextureManager::ProcessRemoveQueue()
{
- for(const auto& textureId : mRemoveQueue)
+ TextureCacheIndex textureCacheIndex = INVALID_CACHE_INDEX;
+ for(auto&& element : mRemoveQueue)
{
- mTextureCacheManager.RemoveCache(textureId);
+ textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(element.mTextureId);
+ if(textureCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+ RemoveTextureObserver(textureInfo, element.mObserver);
+ mTextureCacheManager.RemoveCache(textureInfo);
+ }
}
mRemoveQueue.Clear();
}
info->animatedImageLoading.Reset();
}
- mQueueLoadFlag = true;
+ mLoadingQueueTextureId = textureId;
// Reverse observer list that we can pop_back the observer.
std::reverse(info->observerList.Begin(), info->observerList.End());
info = &mTextureCacheManager[textureInfoIndex];
}
- mQueueLoadFlag = false;
+ mLoadingQueueTextureId = INVALID_TEXTURE_ID;
ProcessLoadQueue();
ProcessRemoveQueue();
}
}
+void TextureManager::RemoveTextureObserver(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
+{
+ // Remove its observer
+ if(observer)
+ {
+ const auto iterEnd = textureInfo.observerList.End();
+ const auto iter = std::find(textureInfo.observerList.Begin(), iterEnd, observer);
+ if(iter != iterEnd)
+ {
+ // Disconnect and remove the observer.
+ observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
+ textureInfo.observerList.Erase(iter);
+ }
+ }
+}
+
} // namespace Internal
} // namespace Toolkit
/**
* Structure to hold info about a texture load queued during NotifyObservers
*/
- struct LoadQueueElement
+ struct QueueElement
{
- LoadQueueElement(TextureManager::TextureId textureId, TextureUploadObserver* observer)
+ QueueElement(TextureManager::TextureId textureId, TextureUploadObserver* observer)
: mTextureId(textureId),
mObserver(observer)
{
*/
void EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success);
+
+ /**
+ * @brief Remove observer in textureInfo
+ *
+ * @param textureInfo The struct associated with this Texture.
+ * @param observer The observer wishing to remove.
+ */
+ void RemoveTextureObserver(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer);
+
public:
/**
* @brief Common method to handle loading completion.
RoundRobinContainerView<TextureAsyncLoadingHelper> mAsyncLocalLoaders; ///< The Asynchronous image loaders used to provide all local async loads
RoundRobinContainerView<TextureAsyncLoadingHelper> mAsyncRemoteLoaders; ///< The Asynchronous image loaders used to provide all remote async loads
- Dali::Vector<LifecycleObserver*> mLifecycleObservers; ///< Lifecycle observers of texture manager
- Dali::Vector<LoadQueueElement> mLoadQueue; ///< Queue of textures to load after NotifyObservers
- Dali::Vector<TextureManager::TextureId> mRemoveQueue; ///< Queue of textures to remove after NotifyObservers
- bool mQueueLoadFlag; ///< Flag that causes Load Textures to be queued.
- bool mLoadYuvPlanes; ///< A global flag to specify if the image should be loaded as yuv planes
+ Dali::Vector<LifecycleObserver*> mLifecycleObservers; ///< Lifecycle observers of texture manager
+ Dali::Vector<QueueElement> mLoadQueue; ///< Queue of textures to load after NotifyObservers
+ Dali::Vector<QueueElement> mRemoveQueue; ///< Queue of textures to remove after NotifyObservers
+ TextureManager::TextureId mLoadingQueueTextureId; ///< TextureId when it is loading. it causes Load Textures to be queued.
+ bool mLoadYuvPlanes; ///< A global flag to specify if the image should be loaded as yuv planes
};
} // namespace Internal
{
mTextureManager.Remove(mImageUrls[i].mTextureId, this);
mImageUrls[i].mTextureId = TextureManager::INVALID_TEXTURE_ID;
-
- if(mMaskingData && mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID)
- {
- // In the CPU alpha masking, each frame increases reference count of masking texture.
- // We should call TextureManager::Remove to decrease reference count when each frame is removed.
- mTextureManager.Remove(mMaskingData->mAlphaMaskId, this);
- }
}
}
mReadyFlags.clear();
if(mMaskingData && mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID)
{
- mTextureManager.Remove(mMaskingData->mAlphaMaskId, this);
if(mQueue.IsEmpty())
{
mMaskingData->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
if(mMaskingData && mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID)
{
- mTextureManager.Remove(mMaskingData->mAlphaMaskId, this);
if(mQueue.IsEmpty())
{
mMaskingData->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
{
if(Stage::IsInstalled())
{
- if(mMaskingData)
- {
- // TextureManager could have been deleted before the actor that contains this
- // ImageVisual is destroyed (e.g. due to stage shutdown). Ensure the stage
- // is still valid before accessing texture manager.
- if(mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID)
- {
- TextureManager& textureManager = mFactoryCache.GetTextureManager();
- textureManager.Remove(mMaskingData->mAlphaMaskId, this);
- }
- }
-
if(mImageUrl.IsValid())
{
// Decrease reference count of External Resources :