2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-event-thread-callback.h>
24 #include <toolkit-timer.h>
26 #include <dali-toolkit/internal/texture-manager/texture-async-loading-helper.h>
27 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
28 #include <dali-toolkit/internal/texture-manager/texture-upload-observer.h>
29 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
30 #include <dali-toolkit/internal/visuals/visual-factory-impl.h> ///< For VisualFactory's member TextureManager.
31 #include <dali-toolkit/public-api/image-loader/image-url.h>
32 #include <dali-toolkit/public-api/image-loader/image.h>
33 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
35 #include <test-encoded-image-buffer.h>
37 #if defined(ELDBUS_ENABLED)
38 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
41 using namespace Dali::Toolkit::Internal;
43 void utc_dali_toolkit_texture_manager_startup(void)
45 setenv("LOG_TEXTURE_MANAGER", "3", 1);
46 test_return_value = TET_UNDEF;
47 #if defined(ELDBUS_ENABLED)
48 DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
52 void utc_dali_toolkit_texture_manager_cleanup(void)
54 test_return_value = TET_PASS;
59 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
60 const char* TEST_IMAGE_2_FILE_NAME = TEST_RESOURCE_DIR "/icon-delete.png";
61 const char* TEST_IMAGE_3_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
62 const char* TEST_IMAGE_4_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-20.png";
63 const char* TEST_MASK_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
65 class TestObserver : public Dali::Toolkit::TextureUploadObserver
68 enum class CompleteType
77 : mCompleteType(CompleteType::NOT_COMPLETED),
79 mObserverCalled(false),
84 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
86 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
88 mCompleteType = CompleteType::UPLOAD_COMPLETE;
92 mCompleteType = CompleteType::LOAD_COMPLETE;
94 mLoaded = loadSuccess;
95 mObserverCalled = true;
96 mTextureSet = textureInformation.textureSet;
99 CompleteType mCompleteType;
101 bool mObserverCalled;
102 TextureSet mTextureSet;
105 class TestObserverRemoveAndGenerateUrl : public TestObserver
108 TestObserverRemoveAndGenerateUrl(TextureManager* textureManagerPtr)
110 mTextureManagerPtr(textureManagerPtr)
114 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
116 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
118 mCompleteType = CompleteType::UPLOAD_COMPLETE;
122 mCompleteType = CompleteType::LOAD_COMPLETE;
124 mLoaded = loadSuccess;
125 mObserverCalled = true;
126 mTextureSet = textureInformation.textureSet;
128 // Remove during LoadComplete
129 mTextureManagerPtr->RequestRemove(textureInformation.textureId, nullptr);
131 // ...And generate string which using texture id.
132 mGeneratedExternalUrl = mTextureManagerPtr->AddExternalTexture(mTextureSet);
136 std::string mGeneratedExternalUrl;
139 TextureManager* mTextureManagerPtr; // Keep the pointer of texture manager.
142 class TestObserverWithCustomFunction : public TestObserver
145 TestObserverWithCustomFunction()
153 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
155 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
157 mCompleteType = CompleteType::UPLOAD_COMPLETE;
161 mCompleteType = CompleteType::LOAD_COMPLETE;
163 mLoaded = loadSuccess;
164 mObserverCalled = true;
165 mTextureSet = textureInformation.textureSet;
168 for(size_t i = 0; i < mSignals.size(); i++)
180 void ConnectFunction(std::function<void(void*)> signal)
182 mSignals.push_back(signal);
186 std::vector<std::function<void(void*)>> mSignals;
193 int UtcTextureManagerRequestLoad(void)
195 ToolkitTestApplication application;
197 TextureManager textureManager; // Create new texture manager
199 TestObserver observer;
200 std::string filename("image.png");
201 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
202 TextureManager::TextureId textureId = textureManager.RequestLoad(
205 FittingMode::SCALE_TO_FILL,
206 SamplingMode::BOX_THEN_LINEAR,
207 TextureManager::UseAtlas::NO_ATLAS,
210 TextureManager::ReloadPolicy::CACHED,
213 VisualUrl url = textureManager.GetVisualUrl(textureId);
215 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
220 int UtcTextureManagerGenerateHash(void)
222 ToolkitTestApplication application;
224 TextureManager textureManager; // Create new texture manager
226 TestObserver observer;
227 std::string filename("image.png");
228 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
229 TextureManager::TextureId textureId = textureManager.RequestLoad(
232 FittingMode::SCALE_TO_FILL,
233 SamplingMode::BOX_THEN_LINEAR,
234 TextureManager::UseAtlas::NO_ATLAS,
237 TextureManager::ReloadPolicy::CACHED,
240 VisualUrl url = textureManager.GetVisualUrl(textureId);
242 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
247 int UtcTextureManagerEncodedImageBuffer(void)
249 ToolkitTestApplication application;
250 tet_infoline("UtcTextureManagerEncodedImageBuffer");
252 auto visualFactory = Toolkit::VisualFactory::Get();
253 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
255 // Get encoded raw-buffer image and generate url
256 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
257 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
259 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
260 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
261 std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage
263 // Check if same EncodedImageBuffer get same url
264 DALI_TEST_CHECK(url1 == url2);
265 // Reduce reference count
266 textureManager.RemoveEncodedImageBuffer(url1);
267 // Check whethere url1 still valid
268 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
270 url2 = textureManager.AddEncodedImageBuffer(buffer2);
271 // Check if difference EncodedImageBuffer get difference url
272 DALI_TEST_CHECK(url1 != url2);
274 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
276 TestObserver observer1;
277 textureManager.RequestLoad(
280 FittingMode::SCALE_TO_FILL,
281 SamplingMode::BOX_THEN_LINEAR,
282 TextureManager::UseAtlas::NO_ATLAS,
284 true, ///< orientationCorrection
285 TextureManager::ReloadPolicy::CACHED,
288 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
289 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
291 application.SendNotification();
292 application.Render();
294 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
296 application.SendNotification();
297 application.Render();
299 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
300 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
301 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
303 TestObserver observer2;
305 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
308 FittingMode::SCALE_TO_FILL,
309 SamplingMode::BOX_THEN_LINEAR,
310 true, ///< synchronousLoading
312 true, ///< orientationCorrection
315 DALI_TEST_CHECK(pixelBuffer);
316 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
317 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
320 pixelBuffer = textureManager.LoadPixelBuffer(
323 FittingMode::SCALE_TO_FILL,
324 SamplingMode::BOX_THEN_LINEAR,
325 false, ///< synchronousLoading
327 true, ///< orientationCorrection
330 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
331 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
333 application.SendNotification();
334 application.Render();
336 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
338 application.SendNotification();
339 application.Render();
341 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
342 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
343 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
345 textureManager.RemoveEncodedImageBuffer(url1);
346 textureManager.RemoveEncodedImageBuffer(url2);
348 // Now url1 and url2 is invalid type. mLoaded will return false
350 TestObserver observer3;
351 textureManager.RequestLoad(
354 FittingMode::SCALE_TO_FILL,
355 SamplingMode::BOX_THEN_LINEAR,
356 TextureManager::UseAtlas::NO_ATLAS,
358 true, ///< orientationCorrection
359 TextureManager::ReloadPolicy::CACHED,
362 // Load will be success because url1 is cached
363 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
364 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
365 DALI_TEST_EQUALS(observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
367 TestObserver observer4;
368 textureManager.RequestLoad(
371 FittingMode::SCALE_TO_FILL,
372 SamplingMode::BOX_THEN_LINEAR,
373 TextureManager::UseAtlas::NO_ATLAS,
375 true, ///< orientationCorrection
376 TextureManager::ReloadPolicy::FORCED,
379 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
380 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
381 application.SendNotification();
382 application.Render();
384 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
386 application.SendNotification();
387 application.Render();
389 // Load will be failed becuase reloadpolicy is forced
390 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
391 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
392 DALI_TEST_EQUALS(observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
394 TestObserver observer5;
395 pixelBuffer = textureManager.LoadPixelBuffer(
398 FittingMode::SCALE_TO_FILL,
399 SamplingMode::BOX_THEN_LINEAR,
400 true, ///< synchronousLoading
402 true, ///< orientationCorrection
405 // Load will be faild because synchronousLoading doesn't use cached texture
406 DALI_TEST_CHECK(!pixelBuffer);
407 DALI_TEST_EQUALS(observer5.mLoaded, false, TEST_LOCATION);
408 DALI_TEST_EQUALS(observer5.mObserverCalled, false, TEST_LOCATION);
410 TestObserver observer6;
411 pixelBuffer = textureManager.LoadPixelBuffer(
414 FittingMode::SCALE_TO_FILL,
415 SamplingMode::BOX_THEN_LINEAR,
416 false, ///< synchronousLoading
418 true, ///< orientationCorrection
421 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
422 DALI_TEST_EQUALS(observer6.mObserverCalled, false, TEST_LOCATION);
424 application.SendNotification();
425 application.Render();
427 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
429 application.SendNotification();
430 application.Render();
432 // Load will be failed because url3 is invalid URL
433 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
434 DALI_TEST_EQUALS(observer6.mObserverCalled, true, TEST_LOCATION);
435 DALI_TEST_EQUALS(observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
440 int UtcTextureManagerExternalTexture(void)
442 ToolkitTestApplication application;
443 tet_infoline("UtcTextureManagerExternalTexture check TextureManager using external texture works well");
445 auto visualFactory = Toolkit::VisualFactory::Get();
446 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
448 TestObserver observer1;
449 TestObserver observer2;
451 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
452 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
453 std::string maskname(TEST_MASK_FILE_NAME);
454 TextureManager::MaskingDataPointer maskInfo = nullptr;
455 maskInfo.reset(new TextureManager::MaskingData());
456 maskInfo->mAlphaMaskUrl = maskname;
457 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
458 maskInfo->mCropToMask = true;
459 maskInfo->mContentScaleFactor = 1.0f;
460 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
461 Dali::ImageDimensions atlasRectSize(0, 0);
462 bool synchronousLoading(false);
463 bool atlasingStatus(false);
464 bool loadingStatus(false);
465 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
466 ImageAtlasManagerPtr atlasManager = nullptr;
467 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
471 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
473 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
474 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
476 DALI_TEST_CHECK(pixelData);
478 Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
479 std::string url = imageUrl.GetUrl();
481 TextureSet texture1 = textureManager.LoadTexture(
484 FittingMode::SCALE_TO_FILL,
485 SamplingMode::BOX_THEN_LINEAR,
497 TextureManager::ReloadPolicy::CACHED,
500 TextureSet texture2 = textureManager.LoadTexture(
503 FittingMode::SCALE_TO_FILL,
504 SamplingMode::BOX_THEN_LINEAR,
516 TextureManager::ReloadPolicy::CACHED,
519 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
520 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
521 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
522 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
524 application.SendNotification();
525 application.Render();
527 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
529 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
530 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
531 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
533 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
534 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
535 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
537 DALI_TEST_EQUALS(textureId1 == textureId2, true, TEST_LOCATION);
539 texture1 = textureManager.LoadTexture(
542 FittingMode::SCALE_TO_FILL,
543 SamplingMode::BOX_THEN_LINEAR,
555 TextureManager::ReloadPolicy::CACHED,
558 texture2 = textureManager.LoadTexture(
561 FittingMode::SCALE_TO_FILL,
562 SamplingMode::BOX_THEN_LINEAR,
574 TextureManager::ReloadPolicy::CACHED,
577 application.SendNotification();
578 application.Render();
580 DALI_TEST_EQUALS(textureId1 == textureId2, true, TEST_LOCATION);
581 DALI_TEST_EQUALS(texture1 != texture2, true, TEST_LOCATION);
586 int UtcTextureManagerRemoveExternalTextureAndLoadAgain(void)
588 ToolkitTestApplication application;
589 tet_infoline("UtcTextureManagerRemoveExternalTextureAndLoadAgain check TextureManager RequestRemove and RemoveExternalTexture lifecycle works well");
591 auto visualFactory = Toolkit::VisualFactory::Get();
592 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
594 TestObserver observer1;
595 TestObserver observer2;
597 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
598 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
599 TextureManager::MaskingDataPointer maskInfo = nullptr;
601 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
602 Dali::ImageDimensions atlasRectSize(0, 0);
603 bool synchronousLoading(false);
604 bool atlasingStatus(false);
605 bool loadingStatus(false);
606 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
607 ImageAtlasManagerPtr atlasManager = nullptr;
608 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
612 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
614 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
615 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
617 DALI_TEST_CHECK(pixelData);
619 Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
620 std::string url1 = imageUrl.GetUrl();
621 std::string url2 = TEST_IMAGE_FILE_NAME;
623 // Step 1 : Load request for external url
624 TextureSet texture1 = textureManager.LoadTexture(
627 FittingMode::SCALE_TO_FILL,
628 SamplingMode::BOX_THEN_LINEAR,
640 TextureManager::ReloadPolicy::CACHED,
643 DALI_TEST_CHECK(textureId1 != TextureManager::INVALID_TEXTURE_ID);
645 // Step 2 : Request remove for external url
646 textureManager.RequestRemove(textureId1, &observer1);
648 // Step 3 : Reduce imageUrl reference count.
651 // Step 4 : Request new load by normal image.
652 TextureSet texture2 = textureManager.LoadTexture(
655 FittingMode::SCALE_TO_FILL,
656 SamplingMode::BOX_THEN_LINEAR,
668 TextureManager::ReloadPolicy::CACHED,
671 DALI_TEST_CHECK(textureId2 != TextureManager::INVALID_TEXTURE_ID);
673 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
674 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
675 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
676 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
678 application.SendNotification();
679 application.Render();
681 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
683 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
684 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
686 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
687 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
688 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
693 int UtcTextureManagerEncodedImageBufferReferenceCount(void)
695 ToolkitTestApplication application;
696 tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well");
698 auto visualFactory = Toolkit::VisualFactory::Get();
699 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
701 // Get encoded raw-buffer image and generate url
702 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
703 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
705 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
706 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
708 // Check if same EncodedImageBuffer get same url
709 DALI_TEST_CHECK(url1 == url2);
711 // Reduce reference count
712 textureManager.RemoveEncodedImageBuffer(url1);
713 // Check whethere url1 still valid
714 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
716 // Reduce reference count
717 textureManager.RemoveEncodedImageBuffer(url1);
718 // Check whethere url1 is not valid anymore
719 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
721 // UseExternalTexture doesn't create new buffer.
722 // So, reference count is still zero.
723 textureManager.UseExternalResource(url1);
724 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
726 url1 = textureManager.AddEncodedImageBuffer(buffer1);
728 url2 = textureManager.AddEncodedImageBuffer(buffer2);
729 // Check if difference EncodedImageBuffer get difference url
730 DALI_TEST_CHECK(url1 != url2);
732 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
734 // url1 load image by cache
735 TestObserver observer1;
736 textureManager.RequestLoad(
739 FittingMode::SCALE_TO_FILL,
740 SamplingMode::BOX_THEN_LINEAR,
741 TextureManager::UseAtlas::NO_ATLAS,
743 true, ///< orientationCorrection
744 TextureManager::ReloadPolicy::CACHED,
747 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
748 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
750 application.SendNotification();
751 application.Render();
753 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
755 application.SendNotification();
756 application.Render();
758 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
759 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
760 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
762 // LoadPixelBuffer doen't use cache. url2 will not be cached
763 TestObserver observer2;
764 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
767 FittingMode::SCALE_TO_FILL,
768 SamplingMode::BOX_THEN_LINEAR,
769 false, ///< synchronousLoading
771 true, ///< orientationCorrection
774 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
775 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
777 application.SendNotification();
778 application.Render();
780 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
782 application.SendNotification();
783 application.Render();
785 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
786 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
787 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
789 // Decrease each url's reference count.
790 textureManager.RemoveEncodedImageBuffer(url1);
791 textureManager.RemoveEncodedImageBuffer(url2);
793 // url1 buffer is still have 1 reference count because it is cached.
794 // But url2 not valid because it is not cached.
795 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
796 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
798 // Check url1 buffer have 1 reference count because it is cached.
799 textureManager.RemoveEncodedImageBuffer(url1);
800 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
805 int UtcTextureManagerCachingForDifferentLoadingType(void)
807 ToolkitTestApplication application;
808 tet_infoline("UtcTextureManagerCachingForDifferentLoadingType");
810 TextureManager textureManager; // Create new texture manager
812 TestObserver observer1;
813 std::string filename(TEST_IMAGE_FILE_NAME);
814 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
815 textureManager.RequestLoad(
818 FittingMode::SCALE_TO_FILL,
819 SamplingMode::BOX_THEN_LINEAR,
820 TextureManager::UseAtlas::NO_ATLAS,
823 TextureManager::ReloadPolicy::CACHED,
826 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
827 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
829 application.SendNotification();
830 application.Render();
832 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
834 application.SendNotification();
835 application.Render();
837 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
838 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
839 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
841 TestObserver observer2;
842 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
845 FittingMode::SCALE_TO_FILL,
846 SamplingMode::BOX_THEN_LINEAR,
852 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
853 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
855 application.SendNotification();
856 application.Render();
858 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
860 application.SendNotification();
861 application.Render();
863 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
864 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
865 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
870 int UtcTextureManagerUseInvalidMask(void)
872 ToolkitTestApplication application;
873 tet_infoline("UtcTextureManagerUseInvalidMask");
875 TextureManager textureManager; // Create new texture manager
877 TestObserver observer;
878 std::string filename(TEST_IMAGE_FILE_NAME);
879 std::string maskname("");
880 TextureManager::MaskingDataPointer maskInfo = nullptr;
881 maskInfo.reset(new TextureManager::MaskingData());
882 maskInfo->mAlphaMaskUrl = maskname;
883 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
884 maskInfo->mCropToMask = true;
885 maskInfo->mContentScaleFactor = 1.0f;
887 auto textureId(TextureManager::INVALID_TEXTURE_ID);
888 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
889 Dali::ImageDimensions atlasRectSize(0, 0);
890 bool synchronousLoading(false);
891 bool atlasingStatus(false);
892 bool loadingStatus(false);
893 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
894 ImageAtlasManagerPtr atlasManager = nullptr;
895 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
897 textureManager.LoadTexture(
900 FittingMode::SCALE_TO_FILL,
901 SamplingMode::BOX_THEN_LINEAR,
913 TextureManager::ReloadPolicy::CACHED,
916 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
917 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
919 application.SendNotification();
920 application.Render();
922 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
924 application.SendNotification();
925 application.Render();
927 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
928 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
929 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
934 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
936 ToolkitTestApplication application;
937 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
938 tet_infoline("Try to check PostLoad works well");
940 TextureManager textureManager; // Create new texture manager
942 TestObserver observer;
943 std::string filename(TEST_IMAGE_FILE_NAME);
944 std::string maskname("invalid.png");
945 TextureManager::MaskingDataPointer maskInfo = nullptr;
946 maskInfo.reset(new TextureManager::MaskingData());
947 maskInfo->mAlphaMaskUrl = maskname;
948 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
949 maskInfo->mCropToMask = true;
950 maskInfo->mContentScaleFactor = 1.0f;
952 auto textureId(TextureManager::INVALID_TEXTURE_ID);
953 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
954 Dali::ImageDimensions atlasRectSize(0, 0);
955 bool synchronousLoading(false);
956 bool atlasingStatus(false);
957 bool loadingStatus(false);
958 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
959 ImageAtlasManagerPtr atlasManager = nullptr;
960 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
962 textureManager.LoadTexture(
965 FittingMode::SCALE_TO_FILL,
966 SamplingMode::BOX_THEN_LINEAR,
978 TextureManager::ReloadPolicy::CACHED,
981 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
982 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
984 application.SendNotification();
985 application.Render();
987 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
989 application.SendNotification();
990 application.Render();
992 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
993 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
994 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
999 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
1001 ToolkitTestApplication application;
1002 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
1003 tet_infoline("Try to check CheckForWaitingTexture called");
1005 TextureManager textureManager; // Create new texture manager
1007 TestObserver observer;
1008 std::string filename(TEST_IMAGE_FILE_NAME);
1009 std::string maskname("invalid.png");
1010 TextureManager::MaskingDataPointer maskInfo = nullptr;
1011 maskInfo.reset(new TextureManager::MaskingData());
1012 maskInfo->mAlphaMaskUrl = maskname;
1013 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1014 maskInfo->mCropToMask = true;
1015 maskInfo->mContentScaleFactor = 1.0f;
1017 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1018 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1019 Dali::ImageDimensions atlasRectSize(0, 0);
1020 bool synchronousLoading(false);
1021 bool atlasingStatus(false);
1022 bool loadingStatus(false);
1023 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1024 ImageAtlasManagerPtr atlasManager = nullptr;
1025 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1027 textureManager.LoadTexture(
1030 FittingMode::SCALE_TO_FILL,
1031 SamplingMode::BOX_THEN_LINEAR,
1040 atlasUploadObserver,
1043 TextureManager::ReloadPolicy::CACHED,
1046 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1047 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1049 // CAPTION : HARD-CODING for coverage.
1051 Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
1054 FittingMode::SCALE_TO_FILL,
1055 SamplingMode::BOX_THEN_LINEAR,
1056 true, ///< synchronousLoading
1058 true, ///< orientationCorrection
1061 std::vector<Devel::PixelBuffer> pixelBuffers;
1062 pixelBuffers.push_back(pixelBuffer);
1063 textureManager.AsyncLoadComplete(textureId, pixelBuffers);
1064 std::vector<Devel::PixelBuffer> maskBuffers;
1065 textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
1066 textureManager.RequestRemove(maskInfo->mAlphaMaskId, nullptr);
1067 textureManager.RequestRemove(textureId, &observer);
1070 application.SendNotification();
1071 application.Render();
1073 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1074 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1075 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1077 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1082 int UtcTextureManagerSynchronousLoadingFail(void)
1084 ToolkitTestApplication application;
1085 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
1087 TextureManager textureManager; // Create new texture manager
1089 std::string maskname("");
1090 TextureManager::MaskingDataPointer maskInfo = nullptr;
1091 maskInfo.reset(new TextureManager::MaskingData());
1092 maskInfo->mAlphaMaskUrl = maskname;
1093 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1094 maskInfo->mCropToMask = true;
1095 maskInfo->mContentScaleFactor = 1.0f;
1097 std::string filename("dummy");
1098 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1099 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1100 Dali::ImageDimensions atlasRectSize(0, 0);
1101 bool atlasingStatus(false);
1102 bool loadingStatus(false);
1103 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1104 ImageAtlasManagerPtr atlasManager = nullptr;
1105 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1107 // load image synchronously.
1108 TestObserver observer;
1109 TextureSet textureSet = textureManager.LoadTexture(
1112 FittingMode::SCALE_TO_FILL,
1113 SamplingMode::BOX_THEN_LINEAR,
1115 true, // synchronous loading.
1122 atlasUploadObserver,
1125 TextureManager::ReloadPolicy::CACHED,
1128 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1129 DALI_TEST_CHECK(!textureSet); // texture loading fail.
1130 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
1135 int UtcTextureManagerCachingSynchronousLoading(void)
1137 ToolkitTestApplication application;
1138 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
1140 TextureManager textureManager; // Create new texture manager
1142 std::string filename(TEST_IMAGE_FILE_NAME);
1144 std::string maskname("");
1145 TextureManager::MaskingDataPointer maskInfo = nullptr;
1146 maskInfo.reset(new TextureManager::MaskingData());
1147 maskInfo->mAlphaMaskUrl = maskname;
1148 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1149 maskInfo->mCropToMask = true;
1150 maskInfo->mContentScaleFactor = 1.0f;
1152 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1153 Dali::ImageDimensions atlasRectSize(0, 0);
1154 bool atlasingStatus(false);
1155 bool loadingStatus(false);
1156 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1157 ImageAtlasManagerPtr atlasManager = nullptr;
1158 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1160 // load image synchronously.
1161 TestObserver observer;
1162 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1163 TextureSet textureSet = textureManager.LoadTexture(
1166 FittingMode::SCALE_TO_FILL,
1167 SamplingMode::BOX_THEN_LINEAR,
1169 true, // synchronous loading.
1176 atlasUploadObserver,
1179 TextureManager::ReloadPolicy::CACHED,
1182 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1183 DALI_TEST_CHECK(textureSet); // texture is loaded.
1185 // observer isn't called in synchronous loading.
1186 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1187 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1189 // load same image asynchronously.
1190 TestObserver asyncObserver;
1191 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
1192 loadingStatus = false;
1193 TextureSet asyncTextureSet = textureManager.LoadTexture(
1196 FittingMode::SCALE_TO_FILL,
1197 SamplingMode::BOX_THEN_LINEAR,
1199 false, // asynchronous loading.
1206 atlasUploadObserver,
1209 TextureManager::ReloadPolicy::CACHED,
1212 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
1213 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1214 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
1216 // observer is directly called because textureSet is retrieved by cache.
1217 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
1218 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
1223 int UtcTextureManagerAsyncSyncAsync(void)
1225 ToolkitTestApplication application;
1226 tet_infoline("UtcTextureManagerAsyncSyncAsync");
1228 TextureManager textureManager; // Create new texture manager
1230 std::string filename(TEST_IMAGE_FILE_NAME);
1232 std::string maskname("");
1233 TextureManager::MaskingDataPointer maskInfo = nullptr;
1234 maskInfo.reset(new TextureManager::MaskingData());
1235 maskInfo->mAlphaMaskUrl = maskname;
1236 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1237 maskInfo->mCropToMask = true;
1238 maskInfo->mContentScaleFactor = 1.0f;
1240 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1241 Dali::ImageDimensions atlasRectSize(0, 0);
1242 bool atlasingStatus(false);
1243 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1244 ImageAtlasManagerPtr atlasManager = nullptr;
1245 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1247 // load image asynchronously.
1248 TestObserver asyncObserver1;
1249 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
1250 bool asyncLoadingStatus1 = false;
1251 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
1254 FittingMode::SCALE_TO_FILL,
1255 SamplingMode::BOX_THEN_LINEAR,
1257 false, // asynchronous loading.
1262 asyncLoadingStatus1,
1264 atlasUploadObserver,
1267 TextureManager::ReloadPolicy::CACHED,
1270 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
1271 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
1273 // observer is still not called.
1274 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1275 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1277 // load same image synchronously just after asynchronous loading.
1278 TestObserver syncObserver;
1279 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1280 bool syncLoadingStatus = false;
1281 TextureSet syncTextureSet = textureManager.LoadTexture(
1284 FittingMode::SCALE_TO_FILL,
1285 SamplingMode::BOX_THEN_LINEAR,
1287 true, // synchronous loading.
1294 atlasUploadObserver,
1297 TextureManager::ReloadPolicy::CACHED,
1300 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
1301 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
1302 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
1304 // syncObserver isn't called in synchronous loading.
1305 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1306 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1308 // asyncObserver1 is still not called too.
1309 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1310 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1312 // load image asynchronously.
1313 TestObserver asyncObserver2;
1314 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1315 bool asyncLoadingStatus2 = false;
1316 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
1319 FittingMode::SCALE_TO_FILL,
1320 SamplingMode::BOX_THEN_LINEAR,
1322 false, // asynchronous loading.
1327 asyncLoadingStatus2,
1329 atlasUploadObserver,
1332 TextureManager::ReloadPolicy::CACHED,
1335 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1336 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
1337 Texture syncTexture = syncTextureSet.GetTexture(0u);
1338 Texture asyncTexture2 = asyncTextureSet2.GetTexture(0u);
1339 DALI_TEST_CHECK(syncTexture);
1340 DALI_TEST_CHECK(asyncTexture2);
1341 DALI_TEST_CHECK(asyncTexture2 == syncTexture); // check loaded two texture is same.
1343 // observer is called synchronously because the texture is cached.
1344 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1345 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1347 asyncObserver2.mLoaded = false;
1348 asyncObserver2.mObserverCalled = false;
1350 application.SendNotification();
1351 application.Render();
1353 // Requested asynchronous loading at first is finished now and async observer is called now.
1354 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1355 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1356 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1357 DALI_TEST_CHECK(asyncObserver1.mTextureSet);
1359 Texture observerTexture = asyncObserver1.mTextureSet.GetTexture(0u);
1360 DALI_TEST_CHECK(observerTexture == asyncTexture2); // check loaded two texture is same.
1362 // asyncObserver2 was already called so it isn't called here.
1363 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1364 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1369 int UtcTextureManagerQueueRemoveDuringObserve(void)
1371 ToolkitTestApplication application;
1372 tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1374 TextureManager textureManager; // Create new texture manager
1376 TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1378 std::string filename(TEST_IMAGE_FILE_NAME);
1379 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1381 TextureManager::TextureId textureId = textureManager.RequestLoad(
1384 FittingMode::SCALE_TO_FILL,
1385 SamplingMode::BOX_THEN_LINEAR,
1386 TextureManager::UseAtlas::NO_ATLAS,
1389 TextureManager::ReloadPolicy::CACHED,
1392 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1393 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1395 application.SendNotification();
1396 application.Render();
1398 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1400 application.SendNotification();
1401 application.Render();
1403 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1404 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1405 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1407 tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1409 DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1411 // Decrease external texture reference count who observer created
1412 textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1414 application.SendNotification();
1415 application.Render();
1420 int UtcTextureManagerRemoveDuringApplyMasking(void)
1422 ToolkitTestApplication application;
1423 tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1425 TextureManager textureManager; // Create new texture manager
1427 TestObserver observer1;
1428 TestObserver observer2;
1430 std::string filename(TEST_IMAGE_FILE_NAME);
1431 std::string maskname(TEST_MASK_FILE_NAME);
1432 TextureManager::MaskingDataPointer maskInfo = nullptr;
1433 maskInfo.reset(new TextureManager::MaskingData());
1434 maskInfo->mAlphaMaskUrl = maskname;
1435 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1436 maskInfo->mCropToMask = true;
1437 maskInfo->mContentScaleFactor = 1.0f;
1439 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1440 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1441 Dali::ImageDimensions atlasRectSize(0, 0);
1442 bool synchronousLoading(false);
1443 bool atlasingStatus(false);
1444 bool loadingStatus(false);
1445 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1446 ImageAtlasManagerPtr atlasManager = nullptr;
1447 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1449 textureManager.LoadTexture(
1452 FittingMode::SCALE_TO_FILL,
1453 SamplingMode::BOX_THEN_LINEAR,
1462 atlasUploadObserver,
1465 TextureManager::ReloadPolicy::CACHED,
1468 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1469 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1471 application.SendNotification();
1472 application.Render();
1474 // Load image and mask image.
1475 // Now, LoadState become MASK_APPLYING
1476 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1478 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1480 application.SendNotification();
1481 application.Render();
1483 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1484 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1486 // Remove current textureId1. and request new texture again.
1487 textureManager.RequestRemove(textureId1, &observer1);
1488 auto textureId2 = textureManager.RequestLoad(
1491 FittingMode::SCALE_TO_FILL,
1492 SamplingMode::BOX_THEN_LINEAR,
1493 TextureManager::UseAtlas::NO_ATLAS,
1495 true, ///< orientationCorrection
1496 TextureManager::ReloadPolicy::CACHED,
1498 synchronousLoading);
1500 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1501 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1502 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1503 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1505 tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1507 // CAPTION : HARD-CODING.
1509 std::vector<Devel::PixelBuffer> pixelBuffers;
1510 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1511 textureManager.RequestRemove(textureId2, &observer2);
1514 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1515 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1516 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1521 int UtcTextureManagerMaskCacheTest(void)
1523 ToolkitTestApplication application;
1524 tet_infoline("UtcTextureManagerMaskCacheTest");
1526 TextureManager textureManager; // Create new texture manager
1528 TestObserver observer1;
1529 TestObserver observer2;
1531 std::string filename(TEST_IMAGE_FILE_NAME);
1532 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1533 std::string maskname(TEST_MASK_FILE_NAME);
1534 TextureManager::MaskingDataPointer maskInfo = nullptr;
1535 maskInfo.reset(new TextureManager::MaskingData());
1536 maskInfo->mAlphaMaskUrl = maskname;
1537 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1538 maskInfo->mCropToMask = true;
1539 maskInfo->mContentScaleFactor = 1.0f;
1541 TextureManager::MaskingDataPointer maskInfo2 = nullptr;
1542 maskInfo2.reset(new TextureManager::MaskingData());
1543 maskInfo2->mAlphaMaskUrl = maskname;
1544 maskInfo2->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1545 maskInfo2->mCropToMask = true;
1546 maskInfo2->mContentScaleFactor = 1.0f;
1548 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1549 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1550 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1551 Dali::ImageDimensions atlasRectSize(0, 0);
1552 bool synchronousLoading(false);
1553 bool atlasingStatus(false);
1554 bool loadingStatus(false);
1555 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1556 ImageAtlasManagerPtr atlasManager = nullptr;
1557 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1559 textureManager.LoadTexture(
1562 FittingMode::SCALE_TO_FILL,
1563 SamplingMode::BOX_THEN_LINEAR,
1572 atlasUploadObserver,
1575 TextureManager::ReloadPolicy::CACHED,
1578 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1579 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1581 application.SendNotification();
1582 application.Render();
1584 // Load image and mask image.
1585 // Now, LoadState become MASK_APPLYING
1586 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1588 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1590 textureManager.LoadTexture(
1593 FittingMode::SCALE_TO_FILL,
1594 SamplingMode::BOX_THEN_LINEAR,
1603 atlasUploadObserver,
1606 TextureManager::ReloadPolicy::CACHED,
1609 application.SendNotification();
1610 application.Render();
1612 // Load image2 + image1 apply mask + image2 apply mask = total 3 event trigger required.
1613 // Note that we use cached mask image.
1614 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1616 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1617 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1618 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1619 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1623 // Remove textureId1 first, and then remove textureId2. Check whether segfault occured.
1624 textureManager.RequestRemove(textureId1, &observer1);
1626 application.SendNotification();
1627 application.Render();
1629 textureManager.RequestRemove(textureId2, &observer2);
1631 application.SendNotification();
1632 application.Render();
1634 TestObserver observer3;
1635 maskInfo.reset(new TextureManager::MaskingData());
1636 maskInfo->mAlphaMaskUrl = maskname;
1637 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1638 maskInfo->mCropToMask = true;
1639 maskInfo->mContentScaleFactor = 1.0f;
1641 textureManager.LoadTexture(
1644 FittingMode::SCALE_TO_FILL,
1645 SamplingMode::BOX_THEN_LINEAR,
1654 atlasUploadObserver,
1657 TextureManager::ReloadPolicy::CACHED,
1660 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1661 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1663 application.SendNotification();
1664 application.Render();
1666 // Load image and mask image.
1667 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1668 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1670 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1671 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1674 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1676 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
1677 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
1681 DALI_TEST_CHECK(false);
1687 int UtcTextureManagerRemoveDuringGPUMasking(void)
1689 ToolkitTestApplication application;
1690 tet_infoline("UtcTextureManagerRemoveDuringGPUMasking");
1691 tet_infoline("Request 3 different GPU masking image.");
1692 tet_infoline("Control to mask image load last. and then, check execute result.");
1694 TextureManager textureManager; // Create new texture manager
1696 TestObserverWithCustomFunction observer1;
1697 TestObserverWithCustomFunction observer2;
1698 TestObserverWithCustomFunction* observer3 = new TestObserverWithCustomFunction(); // Deleted in observer1 loaded signal
1699 TestObserver observer4;
1701 std::string filename1(TEST_IMAGE_FILE_NAME);
1702 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1703 std::string filename3(TEST_IMAGE_3_FILE_NAME);
1704 std::string filename4(TEST_IMAGE_4_FILE_NAME);
1706 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1707 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1708 auto textureId3(TextureManager::INVALID_TEXTURE_ID);
1709 auto textureId4(TextureManager::INVALID_TEXTURE_ID);
1711 std::string maskname(TEST_MASK_FILE_NAME);
1712 TextureManager::MaskingDataPointer maskInfo[3] = {nullptr, nullptr, nullptr};
1713 for(int i = 0; i < 3; i++)
1715 maskInfo[i].reset(new TextureManager::MaskingData());
1716 maskInfo[i]->mAlphaMaskUrl = maskname;
1717 maskInfo[i]->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1718 maskInfo[i]->mCropToMask = true;
1719 maskInfo[i]->mPreappliedMasking = false; // To make GPU masking
1720 maskInfo[i]->mContentScaleFactor = 1.0f;
1722 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1723 Dali::ImageDimensions atlasRectSize(0, 0);
1724 bool synchronousLoading(false);
1725 bool atlasingStatus(false);
1726 bool loadingStatus(false);
1727 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1728 ImageAtlasManagerPtr atlasManager = nullptr;
1729 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1731 // Request image 1, 2, 3 with GPU masking
1732 textureManager.LoadTexture(
1735 FittingMode::SCALE_TO_FILL,
1736 SamplingMode::BOX_THEN_LINEAR,
1745 atlasUploadObserver,
1748 TextureManager::ReloadPolicy::CACHED,
1751 textureManager.LoadTexture(
1754 FittingMode::SCALE_TO_FILL,
1755 SamplingMode::BOX_THEN_LINEAR,
1764 atlasUploadObserver,
1767 TextureManager::ReloadPolicy::CACHED,
1770 textureManager.LoadTexture(
1773 FittingMode::SCALE_TO_FILL,
1774 SamplingMode::BOX_THEN_LINEAR,
1783 atlasUploadObserver,
1786 TextureManager::ReloadPolicy::CACHED,
1789 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1790 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1791 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1792 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1793 DALI_TEST_EQUALS(observer3->mLoaded, false, TEST_LOCATION);
1794 DALI_TEST_EQUALS(observer3->mObserverCalled, false, TEST_LOCATION);
1795 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1796 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1798 // Check we use cached mask image
1799 DALI_TEST_CHECK(maskInfo[0]->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID);
1800 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[1]->mAlphaMaskId, TEST_LOCATION);
1801 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[2]->mAlphaMaskId, TEST_LOCATION);
1803 // Connect observer1 custom function
1806 TextureManager* textureManagerPtr{nullptr};
1807 TextureManager::TextureId removeTextureId{TextureManager::INVALID_TEXTURE_ID};
1808 TestObserver* removeTextureObserver{nullptr};
1811 data1.textureManagerPtr = &textureManager;
1812 data1.removeTextureId = textureId3;
1813 data1.removeTextureObserver = observer3;
1815 observer1.mData = &data1;
1816 observer1.ConnectFunction(
1818 DALI_TEST_CHECK(data);
1819 CustomData1 data1 = *(CustomData1*)data;
1821 DALI_TEST_CHECK(data1.textureManagerPtr);
1822 DALI_TEST_CHECK(data1.removeTextureId != TextureManager::INVALID_TEXTURE_ID);
1823 DALI_TEST_CHECK(data1.removeTextureObserver);
1825 // Remove textureId3.
1826 data1.textureManagerPtr->RequestRemove(data1.removeTextureId, data1.removeTextureObserver);
1828 // Destroy observer3
1829 delete data1.removeTextureObserver;
1832 // Connect observer2 custom function
1835 TextureManager* textureManagerPtr{nullptr};
1836 std::string addTextureUrl{};
1837 TextureManager::TextureId* addTextureIdPtr{nullptr};
1838 TestObserver* addTextureObserver{nullptr};
1841 data2.textureManagerPtr = &textureManager;
1842 data2.addTextureUrl = filename4;
1843 data2.addTextureIdPtr = &textureId4;
1844 data2.addTextureObserver = &observer4;
1846 observer2.mData = &data2;
1847 observer2.ConnectFunction(
1849 DALI_TEST_CHECK(data);
1850 CustomData2 data2 = *(CustomData2*)data;
1852 DALI_TEST_CHECK(data2.textureManagerPtr);
1853 DALI_TEST_CHECK(!data2.addTextureUrl.empty());
1854 DALI_TEST_CHECK(data2.addTextureIdPtr);
1855 DALI_TEST_CHECK(data2.addTextureObserver);
1857 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1860 (*data2.addTextureIdPtr) = data2.textureManagerPtr->RequestLoad(
1861 data2.addTextureUrl,
1863 FittingMode::SCALE_TO_FILL,
1864 SamplingMode::BOX_THEN_LINEAR,
1865 TextureManager::UseAtlas::NO_ATLAS,
1866 data2.addTextureObserver,
1868 TextureManager::ReloadPolicy::CACHED,
1872 // Connect observer3 custom function
1875 TestObserver* self{nullptr};
1876 bool* observerLoadedPtr{nullptr};
1877 bool* observerCalleddPtr{nullptr};
1880 bool observer3Loaded = false;
1881 bool observer3Called = false;
1882 data3.self = observer3;
1883 data3.observerLoadedPtr = &observer3Loaded;
1884 data3.observerCalleddPtr = &observer3Called;
1886 observer3->mData = &data3;
1887 observer3->ConnectFunction(
1889 DALI_TEST_CHECK(data);
1890 CustomData3 data3 = *(CustomData3*)data;
1892 DALI_TEST_CHECK(data3.self);
1893 DALI_TEST_CHECK(data3.observerLoadedPtr);
1894 DALI_TEST_CHECK(data3.observerCalleddPtr);
1896 *data3.observerLoadedPtr = data3.self->mLoaded;
1897 *data3.observerCalleddPtr = data3.self->mObserverCalled;
1900 tet_printf("Id info - mask : {%d}, 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(maskInfo[0]->mAlphaMaskId), static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
1902 // CAPTION : HARD-CODING.
1904 // Complete async load 1, 2, 3.
1905 std::vector<Devel::PixelBuffer> pixelBuffers;
1907 pixelBuffers.clear();
1908 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1909 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
1910 pixelBuffers.clear();
1911 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1912 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1913 pixelBuffers.clear();
1914 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1915 textureManager.AsyncLoadComplete(textureId3, pixelBuffers);
1917 // Ensure textureId3 remove request processed.
1919 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1920 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1921 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1922 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1923 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
1924 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
1925 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1926 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1928 // Complete mask load.
1929 pixelBuffers.clear();
1930 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::L8));
1931 textureManager.AsyncLoadComplete(maskInfo[0]->mAlphaMaskId, pixelBuffers);
1933 tet_printf("Id info after observer notify - mask : {%d}, 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(maskInfo[0]->mAlphaMaskId), static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
1935 // Check observer 1 and 2 called, but 3 and 4 not called.
1936 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1937 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1938 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1939 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1940 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
1941 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
1942 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1943 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1946 DALI_TEST_CHECK(textureId4 != TextureManager::INVALID_TEXTURE_ID);
1949 pixelBuffers.clear();
1950 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1951 textureManager.AsyncLoadComplete(textureId4, pixelBuffers);
1953 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1954 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1955 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1956 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1957 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
1958 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
1959 DALI_TEST_EQUALS(observer4.mLoaded, true, TEST_LOCATION);
1960 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
1966 int UtcTextureManagerDestroyObserverDuringObserve(void)
1968 ToolkitTestApplication application;
1969 tet_infoline("UtcTextureManagerDestroyObserverDuringObserve");
1970 tet_infoline("Request 3 different image.");
1971 tet_infoline("Complete textureId1. After observer1 loaded done,");
1972 tet_infoline(" - Remove and destroy observer2");
1973 tet_infoline(" - Re-generate observer2 which has same address pointer with before.");
1974 tet_infoline(" - Remove and Reqeust third file by observer3");
1975 tet_infoline("Complete textureId2. and check old observer2 not emmited, and newly observer2 works.");
1976 tet_infoline("Complete textureId3. and check observer3 comes");
1978 TextureManager textureManager; // Create new texture manager
1980 TestObserverWithCustomFunction observer1;
1981 TestObserverWithCustomFunction* observer2 = new TestObserverWithCustomFunction(); // Deleted in observer1 loaded signal.
1982 TestObserver observer3;
1984 std::string filename1(TEST_IMAGE_FILE_NAME);
1985 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1986 std::string filename3(TEST_IMAGE_3_FILE_NAME);
1987 std::string filename4(TEST_IMAGE_4_FILE_NAME);
1989 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1990 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1991 auto textureId3(TextureManager::INVALID_TEXTURE_ID);
1992 auto textureId4(TextureManager::INVALID_TEXTURE_ID);
1994 // Dummy reference value
1995 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1997 // Request image 1, 2, 3.
1998 textureId1 = textureManager.RequestLoad(
2001 FittingMode::SCALE_TO_FILL,
2002 SamplingMode::BOX_THEN_LINEAR,
2003 TextureManager::UseAtlas::NO_ATLAS,
2006 TextureManager::ReloadPolicy::CACHED,
2009 textureId2 = textureManager.RequestLoad(
2012 FittingMode::SCALE_TO_FILL,
2013 SamplingMode::BOX_THEN_LINEAR,
2014 TextureManager::UseAtlas::NO_ATLAS,
2017 TextureManager::ReloadPolicy::CACHED,
2020 textureId3 = textureManager.RequestLoad(
2023 FittingMode::SCALE_TO_FILL,
2024 SamplingMode::BOX_THEN_LINEAR,
2025 TextureManager::UseAtlas::NO_ATLAS,
2028 TextureManager::ReloadPolicy::CACHED,
2033 TextureManager* textureManagerPtr{nullptr};
2034 TextureManager::TextureId removeTextureId{TextureManager::INVALID_TEXTURE_ID};
2035 TestObserverWithCustomFunction** removeTextureObserver{nullptr};
2036 std::string resendFilename{};
2037 TextureManager::TextureId resendTextureId{TextureManager::INVALID_TEXTURE_ID};
2038 TestObserver* resendTextureObserver{nullptr};
2039 std::string newlyFilename{};
2040 TextureManager::TextureId* newlyTextureIdPtr{nullptr};
2044 TextureManager* textureManagerPtr{nullptr};
2045 TestObserver* self{nullptr};
2046 bool* observerLoadedPtr{nullptr};
2047 bool* observerCalledPtr{nullptr};
2050 bool observer2Loaded = false;
2051 bool observer2Called = false;
2052 bool newObserver2Loaded = false;
2053 bool newObserver2Called = false;
2054 CustomData2 newData2; // Used on observer1 function
2056 // Connect observer1 custom function
2058 data1.textureManagerPtr = &textureManager;
2059 data1.removeTextureId = textureId2;
2060 data1.removeTextureObserver = &observer2;
2061 data1.resendFilename = filename3;
2062 data1.resendTextureId = textureId3;
2063 data1.resendTextureObserver = &observer3;
2064 data1.newlyFilename = filename2; // Same as observer2 filename
2065 data1.newlyTextureIdPtr = &textureId4;
2067 observer1.mData = &data1;
2068 observer1.ConnectFunction(
2070 DALI_TEST_CHECK(data);
2071 CustomData1 data1 = *(CustomData1*)data;
2073 DALI_TEST_CHECK(data1.textureManagerPtr);
2074 DALI_TEST_CHECK(data1.removeTextureId != TextureManager::INVALID_TEXTURE_ID);
2075 DALI_TEST_CHECK(data1.removeTextureObserver);
2076 DALI_TEST_CHECK(*data1.removeTextureObserver);
2077 DALI_TEST_CHECK(!data1.resendFilename.empty());
2078 DALI_TEST_CHECK(data1.resendTextureId != TextureManager::INVALID_TEXTURE_ID);
2079 DALI_TEST_CHECK(data1.resendTextureObserver);
2080 DALI_TEST_CHECK(!data1.newlyFilename.empty());
2081 DALI_TEST_CHECK(data1.newlyTextureIdPtr);
2082 DALI_TEST_CHECK(*data1.newlyTextureIdPtr == TextureManager::INVALID_TEXTURE_ID);
2084 // Remove textureId2.
2085 data1.textureManagerPtr->RequestRemove(data1.removeTextureId, *data1.removeTextureObserver);
2087 auto removedObserver = *data1.removeTextureObserver;
2089 // Destroy observer2.
2090 delete removedObserver;
2092 // Create new observer. Make we use same pointer if we can.
2093 uint32_t maxTryCount = 100u;
2094 uint32_t tryCount = 0u;
2096 while(tryCount < maxTryCount)
2098 *data1.removeTextureObserver = new TestObserverWithCustomFunction();
2099 if(removedObserver == *data1.removeTextureObserver) break;
2101 delete *data1.removeTextureObserver;
2104 tet_printf("TryCount[%u] / Old observer2 : %p, newly observer2 : %p\n", tryCount, removedObserver, *data1.removeTextureObserver);
2106 // Connect new observer2 custom function
2107 newData2.textureManagerPtr = &textureManager;
2108 newData2.self = (*data1.removeTextureObserver);
2109 newData2.observerLoadedPtr = &newObserver2Loaded;
2110 newData2.observerCalledPtr = &newObserver2Called;
2112 (*data1.removeTextureObserver)->mData = &newData2;
2113 (*data1.removeTextureObserver)->ConnectFunction([](void* data) {
2114 DALI_TEST_CHECK(data);
2115 CustomData2 data2 = *(CustomData2*)data;
2117 tet_printf("New created observer running\n");
2119 DALI_TEST_CHECK(data2.self);
2120 DALI_TEST_CHECK(data2.observerLoadedPtr);
2121 DALI_TEST_CHECK(data2.observerCalledPtr);
2123 *data2.observerLoadedPtr = data2.self->mLoaded;
2124 *data2.observerCalledPtr = data2.self->mObserverCalled;
2127 // Dummy reference value
2128 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
2130 // Resend textureId3
2131 data1.textureManagerPtr->RequestRemove(data1.resendTextureId, data1.resendTextureObserver);
2133 TextureManager::TextureId tempId;
2134 tempId = data1.textureManagerPtr->RequestLoad(
2135 data1.resendFilename,
2137 FittingMode::SCALE_TO_FILL,
2138 SamplingMode::BOX_THEN_LINEAR,
2139 TextureManager::UseAtlas::NO_ATLAS,
2140 data1.resendTextureObserver,
2142 TextureManager::ReloadPolicy::CACHED,
2145 DALI_TEST_CHECK(tempId == data1.resendTextureId);
2149 tempId = data1.textureManagerPtr->RequestLoad(
2150 data1.newlyFilename,
2152 FittingMode::SCALE_TO_FILL,
2153 SamplingMode::BOX_THEN_LINEAR,
2154 TextureManager::UseAtlas::NO_ATLAS,
2155 *data1.removeTextureObserver,
2157 TextureManager::ReloadPolicy::CACHED,
2160 DALI_TEST_CHECK(tempId != TextureManager::INVALID_TEXTURE_ID);
2161 *data1.newlyTextureIdPtr = tempId;
2164 // Connect observer2 custom function
2166 data2.textureManagerPtr = &textureManager;
2167 data2.self = observer2;
2168 data2.observerLoadedPtr = &observer2Loaded;
2169 data2.observerCalledPtr = &observer2Called;
2171 observer2->mData = &data2;
2172 observer2->ConnectFunction(
2174 DALI_TEST_CHECK(data);
2175 CustomData2 data2 = *(CustomData2*)data;
2177 tet_printf("Old created observer running. Something error occured!\n");
2179 DALI_TEST_CHECK(data2.self);
2180 DALI_TEST_CHECK(data2.observerLoadedPtr);
2181 DALI_TEST_CHECK(data2.observerCalledPtr);
2183 *data2.observerLoadedPtr = data2.self->mLoaded;
2184 *data2.observerCalledPtr = data2.self->mObserverCalled;
2187 tet_printf("Id info - 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
2189 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
2190 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
2191 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2192 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2193 DALI_TEST_EQUALS(newObserver2Loaded, false, TEST_LOCATION);
2194 DALI_TEST_EQUALS(newObserver2Called, false, TEST_LOCATION);
2195 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2196 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2198 DALI_TEST_CHECK(textureId4 == TextureManager::INVALID_TEXTURE_ID);
2200 // CAPTION : HARD-CODING.
2201 // Run codes without exception.
2204 tet_printf("Complete async load 1 first.\n");
2205 std::vector<Devel::PixelBuffer> pixelBuffers;
2207 pixelBuffers.clear();
2208 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2209 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
2211 tet_printf("Now observer2 deleted, observer3 resended, observer2 re-created.\n");
2212 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2213 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2214 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2215 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2216 DALI_TEST_EQUALS(newObserver2Loaded, false, TEST_LOCATION);
2217 DALI_TEST_EQUALS(newObserver2Called, false, TEST_LOCATION);
2218 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2219 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2221 tet_printf("Id info - 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
2223 DALI_TEST_CHECK(textureId4 == textureId2);
2225 // Remove processor excute.
2226 application.SendNotification();
2227 application.Render();
2229 tet_printf("Complete async load 2. Let we check old version observer2 ignored and newly observer2 loaded.\n");
2230 pixelBuffers.clear();
2231 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2232 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
2234 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2235 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2236 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2237 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2238 DALI_TEST_EQUALS(newObserver2Loaded, true, TEST_LOCATION);
2239 DALI_TEST_EQUALS(newObserver2Called, true, TEST_LOCATION);
2240 // We don't check observer3 not loaded case because SendNotification can process AsyncTask.
2241 //DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2242 //DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2244 tet_printf("Complete async load 3.\n");
2245 pixelBuffers.clear();
2246 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2247 textureManager.AsyncLoadComplete(textureId3, pixelBuffers);
2249 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2250 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2251 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2252 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2253 DALI_TEST_EQUALS(newObserver2Loaded, true, TEST_LOCATION);
2254 DALI_TEST_EQUALS(newObserver2Called, true, TEST_LOCATION);
2255 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
2256 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
2260 DALI_TEST_CHECK(false);