X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Futc-Dali-TextureManager.cpp;h=87e9a78fd4782300b677c80b18bec5c3e44b64b7;hp=1553f97b03f2895e8f1c805fd6b76283fa43b23e;hb=e683c9fe2c2a7c0eed6b073a47c200ee23cecb36;hpb=60995c8e173400f1d080ca5f0e9385785206be29 diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp index 1553f97..87e9a78 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,15 @@ #include #include -#include #include -#include -#include -#include +#include + +#include +#include +#include #include #include ///< For VisualFactory's member TextureManager. +#include #include @@ -38,7 +40,7 @@ using namespace Dali::Toolkit::Internal; void utc_dali_toolkit_texture_manager_startup(void) { - setenv( "LOG_TEXTURE_MANAGER", "3", 1 ); + setenv("LOG_TEXTURE_MANAGER", "3", 1); test_return_value = TET_UNDEF; #if defined(ELDBUS_ENABLED) DBusWrapper::Install(std::unique_ptr(new TestDBusWrapper)); @@ -52,10 +54,8 @@ void utc_dali_toolkit_texture_manager_cleanup(void) namespace { - -const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; - -} +const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; +const char* TEST_MASK_FILE_NAME = TEST_RESOURCE_DIR "/mask.png"; class TestObserver : public Dali::Toolkit::TextureUploadObserver { @@ -69,35 +69,72 @@ public: public: TestObserver() - : mCompleteType( CompleteType::NOT_COMPLETED ), + : mCompleteType(CompleteType::NOT_COMPLETED), mLoaded(false), mObserverCalled(false), mTextureSet() { } - virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet, - bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override + virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override { - mCompleteType = CompleteType::UPLOAD_COMPLETE; - mLoaded = loadSuccess; + if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE) + { + mCompleteType = CompleteType::UPLOAD_COMPLETE; + } + else + { + mCompleteType = CompleteType::LOAD_COMPLETE; + } + mLoaded = loadSuccess; mObserverCalled = true; - mTextureSet = textureSet; + mTextureSet = textureInformation.textureSet; + } + + CompleteType mCompleteType; + bool mLoaded; + bool mObserverCalled; + TextureSet mTextureSet; +}; + +class TestObserverRemoveAndGenerateUrl : public TestObserver +{ +public: + TestObserverRemoveAndGenerateUrl(TextureManager* textureManagerPtr) + : TestObserver(), + mTextureManagerPtr(textureManagerPtr) + { } - virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override + virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override { - mCompleteType = CompleteType::LOAD_COMPLETE; - mLoaded = loadSuccess; + if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE) + { + mCompleteType = CompleteType::UPLOAD_COMPLETE; + } + else + { + mCompleteType = CompleteType::LOAD_COMPLETE; + } + mLoaded = loadSuccess; mObserverCalled = true; + mTextureSet = textureInformation.textureSet; + + // Remove during LoadComplete + mTextureManagerPtr->Remove(textureInformation.textureId, nullptr); + + // ...And generate string which using texture id. + mGeneratedExternalUrl = mTextureManagerPtr->AddExternalTexture(mTextureSet); } - CompleteType mCompleteType; - bool mLoaded; - bool mObserverCalled; - TextureSet mTextureSet; +public: + std::string mGeneratedExternalUrl; + +protected: + TextureManager* mTextureManagerPtr; // Keep the pointer of texture manager. }; +} // namespace int UtcTextureManagerRequestLoad(void) { @@ -105,23 +142,23 @@ int UtcTextureManagerRequestLoad(void) TextureManager textureManager; // Create new texture manager - TestObserver observer; - std::string filename("image.png"); - auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; - TextureManager::TextureId textureId = textureManager.RequestLoad( + TestObserver observer; + std::string filename("image.png"); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + TextureManager::TextureId textureId = textureManager.RequestLoad( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, - TextureManager::NO_ATLAS, + TextureManager::UseAtlas::NO_ATLAS, &observer, true, TextureManager::ReloadPolicy::CACHED, preMultiply); - VisualUrl url = textureManager.GetVisualUrl( textureId ); + VisualUrl url = textureManager.GetVisualUrl(textureId); - DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION ); + DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION); END_TEST; } @@ -132,23 +169,23 @@ int UtcTextureManagerGenerateHash(void) TextureManager textureManager; // Create new texture manager - TestObserver observer; - std::string filename( "image.png" ); - auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; - TextureManager::TextureId textureId = textureManager.RequestLoad( + TestObserver observer; + std::string filename("image.png"); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + TextureManager::TextureId textureId = textureManager.RequestLoad( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, - TextureManager::USE_ATLAS, + TextureManager::UseAtlas::NO_ATLAS, &observer, true, TextureManager::ReloadPolicy::CACHED, preMultiply); - VisualUrl url = textureManager.GetVisualUrl( textureId ); + VisualUrl url = textureManager.GetVisualUrl(textureId); - DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION ); + DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION); END_TEST; } @@ -156,7 +193,7 @@ int UtcTextureManagerGenerateHash(void) int UtcTextureManagerEncodedImageBuffer(void) { ToolkitTestApplication application; - tet_infoline( "UtcTextureManagerEncodedImageBuffer" ); + tet_infoline("UtcTextureManagerEncodedImageBuffer"); auto visualFactory = Toolkit::VisualFactory::Get(); auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager @@ -165,18 +202,18 @@ int UtcTextureManagerEncodedImageBuffer(void) EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME); EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME); - std::string url1 = textureManager.AddExternalEncodedImageBuffer(buffer1); - std::string url2 = textureManager.AddExternalEncodedImageBuffer(buffer1); - std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage + std::string url1 = textureManager.AddEncodedImageBuffer(buffer1); + std::string url2 = textureManager.AddEncodedImageBuffer(buffer1); + std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage // Check if same EncodedImageBuffer get same url DALI_TEST_CHECK(url1 == url2); // Reduce reference count - textureManager.RemoveExternalEncodedImageBuffer(url1); + textureManager.RemoveEncodedImageBuffer(url1); // Check whethere url1 still valid DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1)); - url2 = textureManager.AddExternalEncodedImageBuffer(buffer2); + url2 = textureManager.AddEncodedImageBuffer(buffer2); // Check if difference EncodedImageBuffer get difference url DALI_TEST_CHECK(url1 != url2); @@ -188,26 +225,26 @@ int UtcTextureManagerEncodedImageBuffer(void) ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, - TextureManager::NO_ATLAS, + TextureManager::UseAtlas::NO_ATLAS, &observer1, true, ///< orientationCorrection TextureManager::ReloadPolicy::CACHED, preMultiply); - DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); TestObserver observer2; // Syncload @@ -221,9 +258,9 @@ int UtcTextureManagerEncodedImageBuffer(void) true, ///< orientationCorrection preMultiply); - DALI_TEST_CHECK( pixelBuffer ); - DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_CHECK(pixelBuffer); + DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION); // Asyncload pixelBuffer = textureManager.LoadPixelBuffer( @@ -236,23 +273,23 @@ int UtcTextureManagerEncodedImageBuffer(void) true, ///< orientationCorrection preMultiply); - DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION); - textureManager.RemoveExternalEncodedImageBuffer(url1); - textureManager.RemoveExternalEncodedImageBuffer(url2); + textureManager.RemoveEncodedImageBuffer(url1); + textureManager.RemoveEncodedImageBuffer(url2); // Now url1 and url2 is invalid type. mLoaded will return false @@ -262,16 +299,16 @@ int UtcTextureManagerEncodedImageBuffer(void) ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, - TextureManager::NO_ATLAS, + TextureManager::UseAtlas::NO_ATLAS, &observer3, true, ///< orientationCorrection TextureManager::ReloadPolicy::CACHED, preMultiply); // Load will be success because url1 is cached - DALI_TEST_EQUALS( observer3.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer3.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); TestObserver observer4; textureManager.RequestLoad( @@ -279,26 +316,26 @@ int UtcTextureManagerEncodedImageBuffer(void) ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, - TextureManager::NO_ATLAS, + TextureManager::UseAtlas::NO_ATLAS, &observer4, true, ///< orientationCorrection TextureManager::ReloadPolicy::FORCED, preMultiply); - DALI_TEST_EQUALS( observer4.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer4.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); // Load will be failed becuase reloadpolicy is forced - DALI_TEST_EQUALS( observer4.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer4.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); TestObserver observer5; pixelBuffer = textureManager.LoadPixelBuffer( @@ -312,9 +349,9 @@ int UtcTextureManagerEncodedImageBuffer(void) preMultiply); // Load will be faild because synchronousLoading doesn't use cached texture - DALI_TEST_CHECK( !pixelBuffer ); - DALI_TEST_EQUALS( observer5.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer5.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_CHECK(!pixelBuffer); + DALI_TEST_EQUALS(observer5.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer5.mObserverCalled, false, TEST_LOCATION); TestObserver observer6; pixelBuffer = textureManager.LoadPixelBuffer( @@ -327,21 +364,21 @@ int UtcTextureManagerEncodedImageBuffer(void) true, ///< orientationCorrection preMultiply); - DALI_TEST_EQUALS( observer6.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer6.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer6.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); // Load will be failed because url3 is invalid URL - DALI_TEST_EQUALS( observer6.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer6.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer6.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION); END_TEST; } @@ -349,7 +386,7 @@ int UtcTextureManagerEncodedImageBuffer(void) int UtcTextureManagerEncodedImageBufferReferenceCount(void) { ToolkitTestApplication application; - tet_infoline( "UtcTextureManagerEncodedImageBuffer check reference count works well" ); + tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well"); auto visualFactory = Toolkit::VisualFactory::Get(); auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager @@ -358,19 +395,19 @@ int UtcTextureManagerEncodedImageBufferReferenceCount(void) EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME); EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME); - std::string url1 = textureManager.AddExternalEncodedImageBuffer(buffer1); - std::string url2 = textureManager.AddExternalEncodedImageBuffer(buffer1); + std::string url1 = textureManager.AddEncodedImageBuffer(buffer1); + std::string url2 = textureManager.AddEncodedImageBuffer(buffer1); // Check if same EncodedImageBuffer get same url DALI_TEST_CHECK(url1 == url2); // Reduce reference count - textureManager.RemoveExternalEncodedImageBuffer(url1); + textureManager.RemoveEncodedImageBuffer(url1); // Check whethere url1 still valid DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1)); // Reduce reference count - textureManager.RemoveExternalEncodedImageBuffer(url1); + textureManager.RemoveEncodedImageBuffer(url1); // Check whethere url1 is not valid anymore DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1)); @@ -379,12 +416,9 @@ int UtcTextureManagerEncodedImageBufferReferenceCount(void) textureManager.UseExternalResource(url1); DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1)); - url1 = textureManager.AddExternalEncodedImageBuffer(buffer1); - // Check if difference EncodedImageBuffer get difference url - // Previous EncodedImageBuffer was deleted, so we get new url even same buffer. - DALI_TEST_CHECK(url1 != url2); + url1 = textureManager.AddEncodedImageBuffer(buffer1); - url2 = textureManager.AddExternalEncodedImageBuffer(buffer2); + url2 = textureManager.AddEncodedImageBuffer(buffer2); // Check if difference EncodedImageBuffer get difference url DALI_TEST_CHECK(url1 != url2); @@ -397,29 +431,29 @@ int UtcTextureManagerEncodedImageBufferReferenceCount(void) ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, - TextureManager::NO_ATLAS, + TextureManager::UseAtlas::NO_ATLAS, &observer1, true, ///< orientationCorrection TextureManager::ReloadPolicy::CACHED, preMultiply); - DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); // LoadPixelBuffer doen't use cache. url2 will not be cached - TestObserver observer2; + TestObserver observer2; Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer( url2, ImageDimensions(), @@ -430,24 +464,24 @@ int UtcTextureManagerEncodedImageBufferReferenceCount(void) true, ///< orientationCorrection preMultiply); - DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION); // Decrease each url's reference count. - textureManager.RemoveExternalEncodedImageBuffer(url1); - textureManager.RemoveExternalEncodedImageBuffer(url2); + textureManager.RemoveEncodedImageBuffer(url1); + textureManager.RemoveEncodedImageBuffer(url2); // url1 buffer is still have 1 reference count because it is cached. // But url2 not valid because it is not cached. @@ -455,50 +489,49 @@ int UtcTextureManagerEncodedImageBufferReferenceCount(void) DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2)); // Check url1 buffer have 1 reference count because it is cached. - textureManager.RemoveExternalEncodedImageBuffer(url1); + textureManager.RemoveEncodedImageBuffer(url1); DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1)); END_TEST; } - int UtcTextureManagerCachingForDifferentLoadingType(void) { ToolkitTestApplication application; - tet_infoline( "UtcTextureManagerCachingForDifferentLoadingType" ); + tet_infoline("UtcTextureManagerCachingForDifferentLoadingType"); TextureManager textureManager; // Create new texture manager TestObserver observer1; - std::string filename( TEST_IMAGE_FILE_NAME ); - auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + std::string filename(TEST_IMAGE_FILE_NAME); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; textureManager.RequestLoad( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, - TextureManager::NO_ATLAS, + TextureManager::UseAtlas::NO_ATLAS, &observer1, true, TextureManager::ReloadPolicy::CACHED, preMultiply); - DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); - TestObserver observer2; + TestObserver observer2; Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer( filename, ImageDimensions(), @@ -509,20 +542,20 @@ int UtcTextureManagerCachingForDifferentLoadingType(void) true, preMultiply); - DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION); END_TEST; } @@ -530,28 +563,95 @@ int UtcTextureManagerCachingForDifferentLoadingType(void) int UtcTextureManagerUseInvalidMask(void) { ToolkitTestApplication application; - tet_infoline( "UtcTextureManagerUseInvalidMask" ); + tet_infoline("UtcTextureManagerUseInvalidMask"); TextureManager textureManager; // Create new texture manager - TestObserver observer; - std::string filename( TEST_IMAGE_FILE_NAME ); - std::string maskname(""); + TestObserver observer; + std::string filename(TEST_IMAGE_FILE_NAME); + std::string maskname(""); TextureManager::MaskingDataPointer maskInfo = nullptr; maskInfo.reset(new TextureManager::MaskingData()); - maskInfo->mAlphaMaskUrl = maskname; - maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; - maskInfo->mCropToMask = true; + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; maskInfo->mContentScaleFactor = 1.0f; - auto textureId( TextureManager::INVALID_TEXTURE_ID ); - Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f ); - Dali::ImageDimensions atlasRectSize( 0,0 ); - bool synchronousLoading(false); - bool atlasingStatus(false); - bool loadingStatus(false); - auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; - ImageAtlasManagerPtr atlasManager = nullptr; + auto textureId(TextureManager::INVALID_TEXTURE_ID); + Vector4 atlasRect(0.f, 0.f, 1.f, 1.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool synchronousLoading(false); + bool atlasingStatus(false); + bool loadingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; + Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; + + textureManager.LoadTexture( + filename, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + maskInfo, + synchronousLoading, + textureId, + atlasRect, + atlasRectSize, + atlasingStatus, + loadingStatus, + WrapMode::DEFAULT, + WrapMode::DEFAULT, + &observer, + atlasUploadObserver, + atlasManager, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); + + END_TEST; +} + +int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first"); + tet_infoline("Try to check PostLoad works well"); + + TextureManager textureManager; // Create new texture manager + + TestObserver observer; + std::string filename(TEST_IMAGE_FILE_NAME); + std::string maskname("invalid.png"); + TextureManager::MaskingDataPointer maskInfo = nullptr; + maskInfo.reset(new TextureManager::MaskingData()); + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; + maskInfo->mContentScaleFactor = 1.0f; + + auto textureId(TextureManager::INVALID_TEXTURE_ID); + Vector4 atlasRect(0.f, 0.f, 1.f, 1.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool synchronousLoading(false); + bool atlasingStatus(false); + bool loadingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; textureManager.LoadTexture( @@ -573,23 +673,110 @@ int UtcTextureManagerUseInvalidMask(void) atlasManager, true, TextureManager::ReloadPolicy::CACHED, - preMultiply - ); + preMultiply); - DALI_TEST_EQUALS( observer.mLoaded, false, TEST_LOCATION ); - DALI_TEST_EQUALS( observer.mObserverCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( observer.mLoaded, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer.mObserverCalled, true, TEST_LOCATION ); - DALI_TEST_EQUALS( observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION ); + DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); + + END_TEST; +} + +int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later"); + tet_infoline("Try to check CheckForWaitingTexture called"); + + TextureManager textureManager; // Create new texture manager + + TestObserver observer; + std::string filename(TEST_IMAGE_FILE_NAME); + std::string maskname("invalid.png"); + TextureManager::MaskingDataPointer maskInfo = nullptr; + maskInfo.reset(new TextureManager::MaskingData()); + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; + maskInfo->mContentScaleFactor = 1.0f; + + auto textureId(TextureManager::INVALID_TEXTURE_ID); + Vector4 atlasRect(0.f, 0.f, 1.f, 1.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool synchronousLoading(false); + bool atlasingStatus(false); + bool loadingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; + Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; + + textureManager.LoadTexture( + filename, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + maskInfo, + synchronousLoading, + textureId, + atlasRect, + atlasRectSize, + atlasingStatus, + loadingStatus, + WrapMode::DEFAULT, + WrapMode::DEFAULT, + &observer, + atlasUploadObserver, + atlasManager, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + // CAPTION : HARD-CODING for coverage. If you are a good boy, Do not follow this code. + { + Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer( + filename, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + true, ///< synchronousLoading + nullptr, + true, ///< orientationCorrection + preMultiply); + + std::vector pixelBuffers; + pixelBuffers.push_back(pixelBuffer); + textureManager.AsyncLoadComplete(textureId, pixelBuffers); + std::vector maskBuffers; + textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers); + textureManager.Remove(maskInfo->mAlphaMaskId, nullptr); + textureManager.Remove(textureId, &observer); + } + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); END_TEST; } @@ -597,31 +784,31 @@ int UtcTextureManagerUseInvalidMask(void) int UtcTextureManagerSynchronousLoadingFail(void) { ToolkitTestApplication application; - tet_infoline( "UtcTextureManagerSynchronousLoadingFail" ); + tet_infoline("UtcTextureManagerSynchronousLoadingFail"); TextureManager textureManager; // Create new texture manager - std::string maskname(""); + std::string maskname(""); TextureManager::MaskingDataPointer maskInfo = nullptr; maskInfo.reset(new TextureManager::MaskingData()); - maskInfo->mAlphaMaskUrl = maskname; - maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; - maskInfo->mCropToMask = true; + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; maskInfo->mContentScaleFactor = 1.0f; - std::string filename("dummy"); - auto textureId( TextureManager::INVALID_TEXTURE_ID ); - Vector4 atlasRect( 0.f, 0.f, 0.f, 0.f ); - Dali::ImageDimensions atlasRectSize( 0,0 ); - bool atlasingStatus(false); - bool loadingStatus(false); - auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; - ImageAtlasManagerPtr atlasManager = nullptr; + std::string filename("dummy"); + auto textureId(TextureManager::INVALID_TEXTURE_ID); + Vector4 atlasRect(0.f, 0.f, 0.f, 0.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool atlasingStatus(false); + bool loadingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; // load image synchronously. TestObserver observer; - TextureSet textureSet = textureManager.LoadTexture( + TextureSet textureSet = textureManager.LoadTexture( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, @@ -640,11 +827,10 @@ int UtcTextureManagerSynchronousLoadingFail(void) atlasManager, true, TextureManager::ReloadPolicy::CACHED, - preMultiply - ); + preMultiply); DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION); - DALI_TEST_CHECK(!textureSet); // texture loading fail. + DALI_TEST_CHECK(!textureSet); // texture loading fail. DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned. END_TEST; @@ -653,32 +839,32 @@ int UtcTextureManagerSynchronousLoadingFail(void) int UtcTextureManagerCachingSynchronousLoading(void) { ToolkitTestApplication application; - tet_infoline( "UtcTextureManagerCachingSynchronousLoading" ); + tet_infoline("UtcTextureManagerCachingSynchronousLoading"); TextureManager textureManager; // Create new texture manager - std::string filename( TEST_IMAGE_FILE_NAME ); + std::string filename(TEST_IMAGE_FILE_NAME); - std::string maskname(""); + std::string maskname(""); TextureManager::MaskingDataPointer maskInfo = nullptr; maskInfo.reset(new TextureManager::MaskingData()); - maskInfo->mAlphaMaskUrl = maskname; - maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; - maskInfo->mCropToMask = true; + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; maskInfo->mContentScaleFactor = 1.0f; - Vector4 atlasRect( 0.f, 0.f, 0.f, 0.f ); - Dali::ImageDimensions atlasRectSize( 0,0 ); - bool atlasingStatus(false); - bool loadingStatus(false); - auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; - ImageAtlasManagerPtr atlasManager = nullptr; + Vector4 atlasRect(0.f, 0.f, 0.f, 0.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool atlasingStatus(false); + bool loadingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; // load image synchronously. TestObserver observer; - auto textureId( TextureManager::INVALID_TEXTURE_ID ); - TextureSet textureSet = textureManager.LoadTexture( + auto textureId(TextureManager::INVALID_TEXTURE_ID); + TextureSet textureSet = textureManager.LoadTexture( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, @@ -697,21 +883,19 @@ int UtcTextureManagerCachingSynchronousLoading(void) atlasManager, true, TextureManager::ReloadPolicy::CACHED, - preMultiply - ); + preMultiply); DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION); - DALI_TEST_CHECK(textureSet); // texture is loaded. + DALI_TEST_CHECK(textureSet); // texture is loaded. // observer isn't called in synchronous loading. DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION); DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION); - // load same image asynchronously. TestObserver asyncObserver; - auto asyncTextureId( TextureManager::INVALID_TEXTURE_ID ); - loadingStatus = false; + auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID); + loadingStatus = false; TextureSet asyncTextureSet = textureManager.LoadTexture( filename, ImageDimensions(), @@ -731,12 +915,11 @@ int UtcTextureManagerCachingSynchronousLoading(void) atlasManager, true, TextureManager::ReloadPolicy::CACHED, - preMultiply - ); + preMultiply); DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded. DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION); - DALI_TEST_CHECK(asyncTextureSet); // Cached texture. + DALI_TEST_CHECK(asyncTextureSet); // Cached texture. // observer is directly called because textureSet is retrieved by cache. DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION); @@ -748,32 +931,32 @@ int UtcTextureManagerCachingSynchronousLoading(void) int UtcTextureManagerAsyncSyncAsync(void) { ToolkitTestApplication application; - tet_infoline( "UtcTextureManagerAsyncSyncAsync" ); + tet_infoline("UtcTextureManagerAsyncSyncAsync"); TextureManager textureManager; // Create new texture manager - std::string filename( TEST_IMAGE_FILE_NAME ); + std::string filename(TEST_IMAGE_FILE_NAME); - std::string maskname(""); + std::string maskname(""); TextureManager::MaskingDataPointer maskInfo = nullptr; maskInfo.reset(new TextureManager::MaskingData()); - maskInfo->mAlphaMaskUrl = maskname; - maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; - maskInfo->mCropToMask = true; + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; maskInfo->mContentScaleFactor = 1.0f; - Vector4 atlasRect( 0.f, 0.f, 0.f, 0.f ); - Dali::ImageDimensions atlasRectSize( 0,0 ); - bool atlasingStatus(false); - auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; - ImageAtlasManagerPtr atlasManager = nullptr; + Vector4 atlasRect(0.f, 0.f, 0.f, 0.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool atlasingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; // load image asynchronously. TestObserver asyncObserver1; - auto asyncTextureId1( TextureManager::INVALID_TEXTURE_ID ); - bool asyncLoadingStatus1 = false; - TextureSet asyncTextureSet1 = textureManager.LoadTexture( + auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID); + bool asyncLoadingStatus1 = false; + TextureSet asyncTextureSet1 = textureManager.LoadTexture( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, @@ -792,22 +975,20 @@ int UtcTextureManagerAsyncSyncAsync(void) atlasManager, true, TextureManager::ReloadPolicy::CACHED, - preMultiply - ); + preMultiply); DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now. - DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet. + DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet. // observer is still not called. DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION); DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION); - // load same image synchronously just after asynchronous loading. TestObserver syncObserver; - auto textureId( TextureManager::INVALID_TEXTURE_ID ); - bool syncLoadingStatus = false; - TextureSet syncTextureSet = textureManager.LoadTexture( + auto textureId(TextureManager::INVALID_TEXTURE_ID); + bool syncLoadingStatus = false; + TextureSet syncTextureSet = textureManager.LoadTexture( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, @@ -826,12 +1007,11 @@ int UtcTextureManagerAsyncSyncAsync(void) atlasManager, true, TextureManager::ReloadPolicy::CACHED, - preMultiply - ); + preMultiply); DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded. - DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded. - DALI_TEST_CHECK(syncTextureSet); // texture is loaded. + DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded. + DALI_TEST_CHECK(syncTextureSet); // texture is loaded. // syncObserver isn't called in synchronous loading. DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION); @@ -841,13 +1021,11 @@ int UtcTextureManagerAsyncSyncAsync(void) DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION); DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION); - - // load image asynchronously. TestObserver asyncObserver2; - auto asyncTextureId2( TextureManager::INVALID_TEXTURE_ID ); - bool asyncLoadingStatus2 = false; - TextureSet asyncTextureSet2 = textureManager.LoadTexture( + auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID); + bool asyncLoadingStatus2 = false; + TextureSet asyncTextureSet2 = textureManager.LoadTexture( filename, ImageDimensions(), FittingMode::SCALE_TO_FILL, @@ -866,28 +1044,27 @@ int UtcTextureManagerAsyncSyncAsync(void) atlasManager, true, TextureManager::ReloadPolicy::CACHED, - preMultiply - ); + preMultiply); DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request - DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded - DALI_TEST_CHECK(asyncTextureSet2 == syncTextureSet); // check loaded two texture is same. + DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded + DALI_TEST_CHECK(asyncTextureSet2 == syncTextureSet); // check loaded two texture is same. // observer is called synchronously because the texture is cached. DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION); DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION); - asyncObserver2.mLoaded = false; + asyncObserver2.mLoaded = false; asyncObserver2.mObserverCalled = false; application.SendNotification(); application.Render(); // Requested asynchronous loading at first is finished now and async observer is called now. - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION); DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION); - DALI_TEST_CHECK(asyncObserver1.mTextureSet == asyncTextureSet2); // check loaded two texture is same. + DALI_TEST_CHECK(asyncObserver1.mTextureSet == asyncTextureSet2); // check loaded two texture is same. // asyncObserver2 was already called so it isn't called here. DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION); @@ -895,3 +1072,160 @@ int UtcTextureManagerAsyncSyncAsync(void) END_TEST; } + +int UtcTextureManagerQueueRemoveDuringObserve(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcTextureManagerQueueRemoveDuringObserve"); + + TextureManager textureManager; // Create new texture manager + + TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC. + + std::string filename(TEST_IMAGE_FILE_NAME); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + + TextureManager::TextureId textureId = textureManager.RequestLoad( + filename, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + TextureManager::UseAtlas::NO_ATLAS, + &observer, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); + + tet_printf("loaded textureId is %d, generated url is %s\n", static_cast(textureId), observer.mGeneratedExternalUrl.c_str()); + + DALI_TEST_CHECK(static_cast(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe + + // Decrease external texture reference count who observer created + textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int UtcTextureManagerRemoveDuringApplyMasking(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcTextureManagerRemoveDuringApplyMasking"); + + TextureManager textureManager; // Create new texture manager + + TestObserver observer1; + TestObserver observer2; + + std::string filename(TEST_IMAGE_FILE_NAME); + std::string maskname(TEST_MASK_FILE_NAME); + TextureManager::MaskingDataPointer maskInfo = nullptr; + maskInfo.reset(new TextureManager::MaskingData()); + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; + maskInfo->mContentScaleFactor = 1.0f; + + auto textureId1(TextureManager::INVALID_TEXTURE_ID); + Vector4 atlasRect(0.f, 0.f, 1.f, 1.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool synchronousLoading(false); + bool atlasingStatus(false); + bool loadingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; + Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; + + textureManager.LoadTexture( + filename, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + maskInfo, + synchronousLoading, + textureId1, + atlasRect, + atlasRectSize, + atlasingStatus, + loadingStatus, + WrapMode::DEFAULT, + WrapMode::DEFAULT, + &observer1, + atlasUploadObserver, + atlasManager, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + // Load image and mask image. + // Now, LoadState become MASK_APPLYING + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast(textureId1)); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION); + + // Remove current textureId1. and request new texture again. + textureManager.Remove(textureId1, &observer1); + auto textureId2 = textureManager.RequestLoad( + filename, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + TextureManager::UseAtlas::NO_ATLAS, + &observer2, + true, ///< orientationCorrection + TextureManager::ReloadPolicy::CACHED, + preMultiply, + synchronousLoading); + + 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); + + tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast(textureId1), static_cast(textureId2)); + + // CAPTION : HARD-CODING. + { + std::vector pixelBuffers; + textureManager.AsyncLoadComplete(textureId2, pixelBuffers); + textureManager.Remove(textureId2, &observer2); + } + + DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer. + DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); + + END_TEST; +}