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 UtcTextureManagerEncodedImageBufferReferenceCount(void)
588 ToolkitTestApplication application;
589 tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well");
591 auto visualFactory = Toolkit::VisualFactory::Get();
592 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
594 // Get encoded raw-buffer image and generate url
595 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
596 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
598 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
599 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
601 // Check if same EncodedImageBuffer get same url
602 DALI_TEST_CHECK(url1 == url2);
604 // Reduce reference count
605 textureManager.RemoveEncodedImageBuffer(url1);
606 // Check whethere url1 still valid
607 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
609 // Reduce reference count
610 textureManager.RemoveEncodedImageBuffer(url1);
611 // Check whethere url1 is not valid anymore
612 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
614 // UseExternalTexture doesn't create new buffer.
615 // So, reference count is still zero.
616 textureManager.UseExternalResource(url1);
617 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
619 url1 = textureManager.AddEncodedImageBuffer(buffer1);
621 url2 = textureManager.AddEncodedImageBuffer(buffer2);
622 // Check if difference EncodedImageBuffer get difference url
623 DALI_TEST_CHECK(url1 != url2);
625 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
627 // url1 load image by cache
628 TestObserver observer1;
629 textureManager.RequestLoad(
632 FittingMode::SCALE_TO_FILL,
633 SamplingMode::BOX_THEN_LINEAR,
634 TextureManager::UseAtlas::NO_ATLAS,
636 true, ///< orientationCorrection
637 TextureManager::ReloadPolicy::CACHED,
640 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
641 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
643 application.SendNotification();
644 application.Render();
646 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
648 application.SendNotification();
649 application.Render();
651 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
652 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
653 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
655 // LoadPixelBuffer doen't use cache. url2 will not be cached
656 TestObserver observer2;
657 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
660 FittingMode::SCALE_TO_FILL,
661 SamplingMode::BOX_THEN_LINEAR,
662 false, ///< synchronousLoading
664 true, ///< orientationCorrection
667 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
668 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
670 application.SendNotification();
671 application.Render();
673 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
675 application.SendNotification();
676 application.Render();
678 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
679 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
680 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
682 // Decrease each url's reference count.
683 textureManager.RemoveEncodedImageBuffer(url1);
684 textureManager.RemoveEncodedImageBuffer(url2);
686 // url1 buffer is still have 1 reference count because it is cached.
687 // But url2 not valid because it is not cached.
688 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
689 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
691 // Check url1 buffer have 1 reference count because it is cached.
692 textureManager.RemoveEncodedImageBuffer(url1);
693 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
698 int UtcTextureManagerCachingForDifferentLoadingType(void)
700 ToolkitTestApplication application;
701 tet_infoline("UtcTextureManagerCachingForDifferentLoadingType");
703 TextureManager textureManager; // Create new texture manager
705 TestObserver observer1;
706 std::string filename(TEST_IMAGE_FILE_NAME);
707 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
708 textureManager.RequestLoad(
711 FittingMode::SCALE_TO_FILL,
712 SamplingMode::BOX_THEN_LINEAR,
713 TextureManager::UseAtlas::NO_ATLAS,
716 TextureManager::ReloadPolicy::CACHED,
719 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
720 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
722 application.SendNotification();
723 application.Render();
725 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
727 application.SendNotification();
728 application.Render();
730 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
731 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
732 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
734 TestObserver observer2;
735 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
738 FittingMode::SCALE_TO_FILL,
739 SamplingMode::BOX_THEN_LINEAR,
745 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
746 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
748 application.SendNotification();
749 application.Render();
751 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
753 application.SendNotification();
754 application.Render();
756 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
757 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
758 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
763 int UtcTextureManagerUseInvalidMask(void)
765 ToolkitTestApplication application;
766 tet_infoline("UtcTextureManagerUseInvalidMask");
768 TextureManager textureManager; // Create new texture manager
770 TestObserver observer;
771 std::string filename(TEST_IMAGE_FILE_NAME);
772 std::string maskname("");
773 TextureManager::MaskingDataPointer maskInfo = nullptr;
774 maskInfo.reset(new TextureManager::MaskingData());
775 maskInfo->mAlphaMaskUrl = maskname;
776 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
777 maskInfo->mCropToMask = true;
778 maskInfo->mContentScaleFactor = 1.0f;
780 auto textureId(TextureManager::INVALID_TEXTURE_ID);
781 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
782 Dali::ImageDimensions atlasRectSize(0, 0);
783 bool synchronousLoading(false);
784 bool atlasingStatus(false);
785 bool loadingStatus(false);
786 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
787 ImageAtlasManagerPtr atlasManager = nullptr;
788 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
790 textureManager.LoadTexture(
793 FittingMode::SCALE_TO_FILL,
794 SamplingMode::BOX_THEN_LINEAR,
806 TextureManager::ReloadPolicy::CACHED,
809 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
810 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
812 application.SendNotification();
813 application.Render();
815 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
817 application.SendNotification();
818 application.Render();
820 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
821 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
822 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
827 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
829 ToolkitTestApplication application;
830 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
831 tet_infoline("Try to check PostLoad works well");
833 TextureManager textureManager; // Create new texture manager
835 TestObserver observer;
836 std::string filename(TEST_IMAGE_FILE_NAME);
837 std::string maskname("invalid.png");
838 TextureManager::MaskingDataPointer maskInfo = nullptr;
839 maskInfo.reset(new TextureManager::MaskingData());
840 maskInfo->mAlphaMaskUrl = maskname;
841 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
842 maskInfo->mCropToMask = true;
843 maskInfo->mContentScaleFactor = 1.0f;
845 auto textureId(TextureManager::INVALID_TEXTURE_ID);
846 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
847 Dali::ImageDimensions atlasRectSize(0, 0);
848 bool synchronousLoading(false);
849 bool atlasingStatus(false);
850 bool loadingStatus(false);
851 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
852 ImageAtlasManagerPtr atlasManager = nullptr;
853 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
855 textureManager.LoadTexture(
858 FittingMode::SCALE_TO_FILL,
859 SamplingMode::BOX_THEN_LINEAR,
871 TextureManager::ReloadPolicy::CACHED,
874 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
875 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
877 application.SendNotification();
878 application.Render();
880 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
882 application.SendNotification();
883 application.Render();
885 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
886 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
887 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
892 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
894 ToolkitTestApplication application;
895 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
896 tet_infoline("Try to check CheckForWaitingTexture called");
898 TextureManager textureManager; // Create new texture manager
900 TestObserver observer;
901 std::string filename(TEST_IMAGE_FILE_NAME);
902 std::string maskname("invalid.png");
903 TextureManager::MaskingDataPointer maskInfo = nullptr;
904 maskInfo.reset(new TextureManager::MaskingData());
905 maskInfo->mAlphaMaskUrl = maskname;
906 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
907 maskInfo->mCropToMask = true;
908 maskInfo->mContentScaleFactor = 1.0f;
910 auto textureId(TextureManager::INVALID_TEXTURE_ID);
911 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
912 Dali::ImageDimensions atlasRectSize(0, 0);
913 bool synchronousLoading(false);
914 bool atlasingStatus(false);
915 bool loadingStatus(false);
916 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
917 ImageAtlasManagerPtr atlasManager = nullptr;
918 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
920 textureManager.LoadTexture(
923 FittingMode::SCALE_TO_FILL,
924 SamplingMode::BOX_THEN_LINEAR,
936 TextureManager::ReloadPolicy::CACHED,
939 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
940 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
942 application.SendNotification();
943 application.Render();
945 // CAPTION : HARD-CODING for coverage.
947 Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
950 FittingMode::SCALE_TO_FILL,
951 SamplingMode::BOX_THEN_LINEAR,
952 true, ///< synchronousLoading
954 true, ///< orientationCorrection
957 std::vector<Devel::PixelBuffer> pixelBuffers;
958 pixelBuffers.push_back(pixelBuffer);
959 textureManager.AsyncLoadComplete(textureId, pixelBuffers);
960 std::vector<Devel::PixelBuffer> maskBuffers;
961 textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
962 textureManager.RequestRemove(maskInfo->mAlphaMaskId, nullptr);
963 textureManager.RequestRemove(textureId, &observer);
966 application.SendNotification();
967 application.Render();
969 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
970 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
971 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
973 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
978 int UtcTextureManagerSynchronousLoadingFail(void)
980 ToolkitTestApplication application;
981 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
983 TextureManager textureManager; // Create new texture manager
985 std::string maskname("");
986 TextureManager::MaskingDataPointer maskInfo = nullptr;
987 maskInfo.reset(new TextureManager::MaskingData());
988 maskInfo->mAlphaMaskUrl = maskname;
989 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
990 maskInfo->mCropToMask = true;
991 maskInfo->mContentScaleFactor = 1.0f;
993 std::string filename("dummy");
994 auto textureId(TextureManager::INVALID_TEXTURE_ID);
995 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
996 Dali::ImageDimensions atlasRectSize(0, 0);
997 bool atlasingStatus(false);
998 bool loadingStatus(false);
999 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1000 ImageAtlasManagerPtr atlasManager = nullptr;
1001 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1003 // load image synchronously.
1004 TestObserver observer;
1005 TextureSet textureSet = textureManager.LoadTexture(
1008 FittingMode::SCALE_TO_FILL,
1009 SamplingMode::BOX_THEN_LINEAR,
1011 true, // synchronous loading.
1018 atlasUploadObserver,
1021 TextureManager::ReloadPolicy::CACHED,
1024 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1025 DALI_TEST_CHECK(!textureSet); // texture loading fail.
1026 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
1031 int UtcTextureManagerCachingSynchronousLoading(void)
1033 ToolkitTestApplication application;
1034 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
1036 TextureManager textureManager; // Create new texture manager
1038 std::string filename(TEST_IMAGE_FILE_NAME);
1040 std::string maskname("");
1041 TextureManager::MaskingDataPointer maskInfo = nullptr;
1042 maskInfo.reset(new TextureManager::MaskingData());
1043 maskInfo->mAlphaMaskUrl = maskname;
1044 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1045 maskInfo->mCropToMask = true;
1046 maskInfo->mContentScaleFactor = 1.0f;
1048 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1049 Dali::ImageDimensions atlasRectSize(0, 0);
1050 bool atlasingStatus(false);
1051 bool loadingStatus(false);
1052 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1053 ImageAtlasManagerPtr atlasManager = nullptr;
1054 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1056 // load image synchronously.
1057 TestObserver observer;
1058 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1059 TextureSet textureSet = textureManager.LoadTexture(
1062 FittingMode::SCALE_TO_FILL,
1063 SamplingMode::BOX_THEN_LINEAR,
1065 true, // synchronous loading.
1072 atlasUploadObserver,
1075 TextureManager::ReloadPolicy::CACHED,
1078 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1079 DALI_TEST_CHECK(textureSet); // texture is loaded.
1081 // observer isn't called in synchronous loading.
1082 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1083 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1085 // load same image asynchronously.
1086 TestObserver asyncObserver;
1087 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
1088 loadingStatus = false;
1089 TextureSet asyncTextureSet = textureManager.LoadTexture(
1092 FittingMode::SCALE_TO_FILL,
1093 SamplingMode::BOX_THEN_LINEAR,
1095 false, // asynchronous loading.
1102 atlasUploadObserver,
1105 TextureManager::ReloadPolicy::CACHED,
1108 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
1109 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1110 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
1112 // observer is directly called because textureSet is retrieved by cache.
1113 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
1114 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
1119 int UtcTextureManagerAsyncSyncAsync(void)
1121 ToolkitTestApplication application;
1122 tet_infoline("UtcTextureManagerAsyncSyncAsync");
1124 TextureManager textureManager; // Create new texture manager
1126 std::string filename(TEST_IMAGE_FILE_NAME);
1128 std::string maskname("");
1129 TextureManager::MaskingDataPointer maskInfo = nullptr;
1130 maskInfo.reset(new TextureManager::MaskingData());
1131 maskInfo->mAlphaMaskUrl = maskname;
1132 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1133 maskInfo->mCropToMask = true;
1134 maskInfo->mContentScaleFactor = 1.0f;
1136 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1137 Dali::ImageDimensions atlasRectSize(0, 0);
1138 bool atlasingStatus(false);
1139 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1140 ImageAtlasManagerPtr atlasManager = nullptr;
1141 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1143 // load image asynchronously.
1144 TestObserver asyncObserver1;
1145 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
1146 bool asyncLoadingStatus1 = false;
1147 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
1150 FittingMode::SCALE_TO_FILL,
1151 SamplingMode::BOX_THEN_LINEAR,
1153 false, // asynchronous loading.
1158 asyncLoadingStatus1,
1160 atlasUploadObserver,
1163 TextureManager::ReloadPolicy::CACHED,
1166 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
1167 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
1169 // observer is still not called.
1170 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1171 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1173 // load same image synchronously just after asynchronous loading.
1174 TestObserver syncObserver;
1175 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1176 bool syncLoadingStatus = false;
1177 TextureSet syncTextureSet = textureManager.LoadTexture(
1180 FittingMode::SCALE_TO_FILL,
1181 SamplingMode::BOX_THEN_LINEAR,
1183 true, // synchronous loading.
1190 atlasUploadObserver,
1193 TextureManager::ReloadPolicy::CACHED,
1196 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
1197 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
1198 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
1200 // syncObserver isn't called in synchronous loading.
1201 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1202 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1204 // asyncObserver1 is still not called too.
1205 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1206 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1208 // load image asynchronously.
1209 TestObserver asyncObserver2;
1210 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1211 bool asyncLoadingStatus2 = false;
1212 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
1215 FittingMode::SCALE_TO_FILL,
1216 SamplingMode::BOX_THEN_LINEAR,
1218 false, // asynchronous loading.
1223 asyncLoadingStatus2,
1225 atlasUploadObserver,
1228 TextureManager::ReloadPolicy::CACHED,
1231 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1232 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
1233 Texture syncTexture = syncTextureSet.GetTexture(0u);
1234 Texture asyncTexture2 = asyncTextureSet2.GetTexture(0u);
1235 DALI_TEST_CHECK(syncTexture);
1236 DALI_TEST_CHECK(asyncTexture2);
1237 DALI_TEST_CHECK(asyncTexture2 == syncTexture); // check loaded two texture is same.
1239 // observer is called synchronously because the texture is cached.
1240 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1241 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1243 asyncObserver2.mLoaded = false;
1244 asyncObserver2.mObserverCalled = false;
1246 application.SendNotification();
1247 application.Render();
1249 // Requested asynchronous loading at first is finished now and async observer is called now.
1250 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1251 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1252 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1253 DALI_TEST_CHECK(asyncObserver1.mTextureSet);
1255 Texture observerTexture = asyncObserver1.mTextureSet.GetTexture(0u);
1256 DALI_TEST_CHECK(observerTexture == asyncTexture2); // check loaded two texture is same.
1258 // asyncObserver2 was already called so it isn't called here.
1259 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1260 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1265 int UtcTextureManagerQueueRemoveDuringObserve(void)
1267 ToolkitTestApplication application;
1268 tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1270 TextureManager textureManager; // Create new texture manager
1272 TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1274 std::string filename(TEST_IMAGE_FILE_NAME);
1275 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1277 TextureManager::TextureId textureId = textureManager.RequestLoad(
1280 FittingMode::SCALE_TO_FILL,
1281 SamplingMode::BOX_THEN_LINEAR,
1282 TextureManager::UseAtlas::NO_ATLAS,
1285 TextureManager::ReloadPolicy::CACHED,
1288 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1289 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1291 application.SendNotification();
1292 application.Render();
1294 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1296 application.SendNotification();
1297 application.Render();
1299 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1300 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1301 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1303 tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1305 DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1307 // Decrease external texture reference count who observer created
1308 textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1310 application.SendNotification();
1311 application.Render();
1316 int UtcTextureManagerRemoveDuringApplyMasking(void)
1318 ToolkitTestApplication application;
1319 tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1321 TextureManager textureManager; // Create new texture manager
1323 TestObserver observer1;
1324 TestObserver observer2;
1326 std::string filename(TEST_IMAGE_FILE_NAME);
1327 std::string maskname(TEST_MASK_FILE_NAME);
1328 TextureManager::MaskingDataPointer maskInfo = nullptr;
1329 maskInfo.reset(new TextureManager::MaskingData());
1330 maskInfo->mAlphaMaskUrl = maskname;
1331 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1332 maskInfo->mCropToMask = true;
1333 maskInfo->mContentScaleFactor = 1.0f;
1335 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1336 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1337 Dali::ImageDimensions atlasRectSize(0, 0);
1338 bool synchronousLoading(false);
1339 bool atlasingStatus(false);
1340 bool loadingStatus(false);
1341 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1342 ImageAtlasManagerPtr atlasManager = nullptr;
1343 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1345 textureManager.LoadTexture(
1348 FittingMode::SCALE_TO_FILL,
1349 SamplingMode::BOX_THEN_LINEAR,
1358 atlasUploadObserver,
1361 TextureManager::ReloadPolicy::CACHED,
1364 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1365 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1367 application.SendNotification();
1368 application.Render();
1370 // Load image and mask image.
1371 // Now, LoadState become MASK_APPLYING
1372 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1374 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1376 application.SendNotification();
1377 application.Render();
1379 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1380 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1382 // Remove current textureId1. and request new texture again.
1383 textureManager.RequestRemove(textureId1, &observer1);
1384 auto textureId2 = textureManager.RequestLoad(
1387 FittingMode::SCALE_TO_FILL,
1388 SamplingMode::BOX_THEN_LINEAR,
1389 TextureManager::UseAtlas::NO_ATLAS,
1391 true, ///< orientationCorrection
1392 TextureManager::ReloadPolicy::CACHED,
1394 synchronousLoading);
1396 application.SendNotification();
1397 application.Render();
1399 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1400 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1401 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1402 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1404 tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1406 // CAPTION : HARD-CODING.
1408 std::vector<Devel::PixelBuffer> pixelBuffers;
1409 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1410 textureManager.RequestRemove(textureId2, &observer2);
1413 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1414 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1415 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1420 int UtcTextureManagerMaskCacheTest(void)
1422 ToolkitTestApplication application;
1423 tet_infoline("UtcTextureManagerMaskCacheTest");
1425 TextureManager textureManager; // Create new texture manager
1427 TestObserver observer1;
1428 TestObserver observer2;
1430 std::string filename(TEST_IMAGE_FILE_NAME);
1431 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1432 std::string maskname(TEST_MASK_FILE_NAME);
1433 TextureManager::MaskingDataPointer maskInfo = nullptr;
1434 maskInfo.reset(new TextureManager::MaskingData());
1435 maskInfo->mAlphaMaskUrl = maskname;
1436 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1437 maskInfo->mCropToMask = true;
1438 maskInfo->mContentScaleFactor = 1.0f;
1440 TextureManager::MaskingDataPointer maskInfo2 = nullptr;
1441 maskInfo2.reset(new TextureManager::MaskingData());
1442 maskInfo2->mAlphaMaskUrl = maskname;
1443 maskInfo2->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1444 maskInfo2->mCropToMask = true;
1445 maskInfo2->mContentScaleFactor = 1.0f;
1447 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1448 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1449 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1450 Dali::ImageDimensions atlasRectSize(0, 0);
1451 bool synchronousLoading(false);
1452 bool atlasingStatus(false);
1453 bool loadingStatus(false);
1454 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1455 ImageAtlasManagerPtr atlasManager = nullptr;
1456 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1458 textureManager.LoadTexture(
1461 FittingMode::SCALE_TO_FILL,
1462 SamplingMode::BOX_THEN_LINEAR,
1471 atlasUploadObserver,
1474 TextureManager::ReloadPolicy::CACHED,
1477 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1478 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1480 application.SendNotification();
1481 application.Render();
1483 // Load image and mask image.
1484 // Now, LoadState become MASK_APPLYING
1485 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1487 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1489 textureManager.LoadTexture(
1492 FittingMode::SCALE_TO_FILL,
1493 SamplingMode::BOX_THEN_LINEAR,
1502 atlasUploadObserver,
1505 TextureManager::ReloadPolicy::CACHED,
1508 application.SendNotification();
1509 application.Render();
1511 // Load image2 + image1 apply mask + image2 apply mask = total 3 event trigger required.
1512 // Note that we use cached mask image.
1513 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1515 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1516 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1517 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1518 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1522 // Remove textureId1 first, and then remove textureId2. Check whether segfault occured.
1523 textureManager.RequestRemove(textureId1, &observer1);
1525 application.SendNotification();
1526 application.Render();
1528 textureManager.RequestRemove(textureId2, &observer2);
1530 application.SendNotification();
1531 application.Render();
1533 TestObserver observer3;
1534 maskInfo.reset(new TextureManager::MaskingData());
1535 maskInfo->mAlphaMaskUrl = maskname;
1536 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1537 maskInfo->mCropToMask = true;
1538 maskInfo->mContentScaleFactor = 1.0f;
1540 textureManager.LoadTexture(
1543 FittingMode::SCALE_TO_FILL,
1544 SamplingMode::BOX_THEN_LINEAR,
1553 atlasUploadObserver,
1556 TextureManager::ReloadPolicy::CACHED,
1559 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1560 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1562 application.SendNotification();
1563 application.Render();
1565 // Load image and mask image.
1566 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1567 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1569 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1570 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1573 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1575 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
1576 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
1580 DALI_TEST_CHECK(false);
1586 int UtcTextureManagerRemoveDuringGPUMasking(void)
1588 ToolkitTestApplication application;
1589 tet_infoline("UtcTextureManagerRemoveDuringGPUMasking");
1590 tet_infoline("Request 3 different GPU masking image.");
1591 tet_infoline("Control to mask image load last. and then, check execute result.");
1593 TextureManager textureManager; // Create new texture manager
1595 TestObserverWithCustomFunction observer1;
1596 TestObserverWithCustomFunction observer2;
1597 TestObserverWithCustomFunction* observer3 = new TestObserverWithCustomFunction(); // Deleted in observer1 loaded signal
1598 TestObserver observer4;
1600 std::string filename1(TEST_IMAGE_FILE_NAME);
1601 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1602 std::string filename3(TEST_IMAGE_3_FILE_NAME);
1603 std::string filename4(TEST_IMAGE_4_FILE_NAME);
1605 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1606 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1607 auto textureId3(TextureManager::INVALID_TEXTURE_ID);
1608 auto textureId4(TextureManager::INVALID_TEXTURE_ID);
1610 std::string maskname(TEST_MASK_FILE_NAME);
1611 TextureManager::MaskingDataPointer maskInfo[3] = {nullptr, nullptr, nullptr};
1612 for(int i = 0; i < 3; i++)
1614 maskInfo[i].reset(new TextureManager::MaskingData());
1615 maskInfo[i]->mAlphaMaskUrl = maskname;
1616 maskInfo[i]->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1617 maskInfo[i]->mCropToMask = true;
1618 maskInfo[i]->mPreappliedMasking = false; // To make GPU masking
1619 maskInfo[i]->mContentScaleFactor = 1.0f;
1621 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1622 Dali::ImageDimensions atlasRectSize(0, 0);
1623 bool synchronousLoading(false);
1624 bool atlasingStatus(false);
1625 bool loadingStatus(false);
1626 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1627 ImageAtlasManagerPtr atlasManager = nullptr;
1628 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1630 // Request image 1, 2, 3 with GPU masking
1631 textureManager.LoadTexture(
1634 FittingMode::SCALE_TO_FILL,
1635 SamplingMode::BOX_THEN_LINEAR,
1644 atlasUploadObserver,
1647 TextureManager::ReloadPolicy::CACHED,
1650 textureManager.LoadTexture(
1653 FittingMode::SCALE_TO_FILL,
1654 SamplingMode::BOX_THEN_LINEAR,
1663 atlasUploadObserver,
1666 TextureManager::ReloadPolicy::CACHED,
1669 textureManager.LoadTexture(
1672 FittingMode::SCALE_TO_FILL,
1673 SamplingMode::BOX_THEN_LINEAR,
1682 atlasUploadObserver,
1685 TextureManager::ReloadPolicy::CACHED,
1688 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1689 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1690 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1691 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1692 DALI_TEST_EQUALS(observer3->mLoaded, false, TEST_LOCATION);
1693 DALI_TEST_EQUALS(observer3->mObserverCalled, false, TEST_LOCATION);
1694 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1695 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1697 // Check we use cached mask image
1698 DALI_TEST_CHECK(maskInfo[0]->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID);
1699 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[1]->mAlphaMaskId, TEST_LOCATION);
1700 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[2]->mAlphaMaskId, TEST_LOCATION);
1702 // Connect observer1 custom function
1705 TextureManager* textureManagerPtr{nullptr};
1706 TextureManager::TextureId removeTextureId{TextureManager::INVALID_TEXTURE_ID};
1707 TestObserver* removeTextureObserver{nullptr};
1710 data1.textureManagerPtr = &textureManager;
1711 data1.removeTextureId = textureId3;
1712 data1.removeTextureObserver = observer3;
1714 observer1.mData = &data1;
1715 observer1.ConnectFunction(
1717 DALI_TEST_CHECK(data);
1718 CustomData1 data1 = *(CustomData1*)data;
1720 DALI_TEST_CHECK(data1.textureManagerPtr);
1721 DALI_TEST_CHECK(data1.removeTextureId != TextureManager::INVALID_TEXTURE_ID);
1722 DALI_TEST_CHECK(data1.removeTextureObserver);
1724 // Remove textureId3.
1725 data1.textureManagerPtr->RequestRemove(data1.removeTextureId, data1.removeTextureObserver);
1727 // Destroy observer3
1728 delete data1.removeTextureObserver;
1731 // Connect observer2 custom function
1734 TextureManager* textureManagerPtr{nullptr};
1735 std::string addTextureUrl{};
1736 TextureManager::TextureId* addTextureIdPtr{nullptr};
1737 TestObserver* addTextureObserver{nullptr};
1740 data2.textureManagerPtr = &textureManager;
1741 data2.addTextureUrl = filename4;
1742 data2.addTextureIdPtr = &textureId4;
1743 data2.addTextureObserver = &observer4;
1745 observer2.mData = &data2;
1746 observer2.ConnectFunction(
1748 DALI_TEST_CHECK(data);
1749 CustomData2 data2 = *(CustomData2*)data;
1751 DALI_TEST_CHECK(data2.textureManagerPtr);
1752 DALI_TEST_CHECK(!data2.addTextureUrl.empty());
1753 DALI_TEST_CHECK(data2.addTextureIdPtr);
1754 DALI_TEST_CHECK(data2.addTextureObserver);
1756 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1759 (*data2.addTextureIdPtr) = data2.textureManagerPtr->RequestLoad(
1760 data2.addTextureUrl,
1762 FittingMode::SCALE_TO_FILL,
1763 SamplingMode::BOX_THEN_LINEAR,
1764 TextureManager::UseAtlas::NO_ATLAS,
1765 data2.addTextureObserver,
1767 TextureManager::ReloadPolicy::CACHED,
1771 // Connect observer3 custom function
1774 TestObserver* self{nullptr};
1775 bool* observerLoadedPtr{nullptr};
1776 bool* observerCalleddPtr{nullptr};
1779 bool observer3Loaded = false;
1780 bool observer3Called = false;
1781 data3.self = observer3;
1782 data3.observerLoadedPtr = &observer3Loaded;
1783 data3.observerCalleddPtr = &observer3Called;
1785 observer3->mData = &data3;
1786 observer3->ConnectFunction(
1788 DALI_TEST_CHECK(data);
1789 CustomData3 data3 = *(CustomData3*)data;
1791 DALI_TEST_CHECK(data3.self);
1792 DALI_TEST_CHECK(data3.observerLoadedPtr);
1793 DALI_TEST_CHECK(data3.observerCalleddPtr);
1795 *data3.observerLoadedPtr = data3.self->mLoaded;
1796 *data3.observerCalleddPtr = data3.self->mObserverCalled;
1799 application.SendNotification();
1800 application.Render();
1802 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));
1804 // CAPTION : HARD-CODING.
1806 // Complete async load 1, 2, 3.
1807 std::vector<Devel::PixelBuffer> pixelBuffers;
1809 pixelBuffers.clear();
1810 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1811 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
1812 pixelBuffers.clear();
1813 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1814 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1815 pixelBuffers.clear();
1816 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1817 textureManager.AsyncLoadComplete(textureId3, pixelBuffers);
1819 // Ensure textureId3 remove request processed.
1821 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1822 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1823 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1824 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1825 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
1826 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
1827 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1828 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1830 // Complete mask load.
1831 pixelBuffers.clear();
1832 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::L8));
1833 textureManager.AsyncLoadComplete(maskInfo[0]->mAlphaMaskId, pixelBuffers);
1835 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));
1837 // Check observer 1 and 2 called, but 3 and 4 not called.
1838 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1839 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1840 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1841 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1842 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
1843 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
1844 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1845 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1848 DALI_TEST_CHECK(textureId4 != TextureManager::INVALID_TEXTURE_ID);
1851 pixelBuffers.clear();
1852 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1853 textureManager.AsyncLoadComplete(textureId4, pixelBuffers);
1855 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1856 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1857 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1858 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1859 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
1860 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
1861 DALI_TEST_EQUALS(observer4.mLoaded, true, TEST_LOCATION);
1862 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
1868 int UtcTextureManagerDestroyObserverDuringObserve(void)
1870 ToolkitTestApplication application;
1871 tet_infoline("UtcTextureManagerDestroyObserverDuringObserve");
1872 tet_infoline("Request 3 different image.");
1873 tet_infoline("Complete textureId1. After observer1 loaded done,");
1874 tet_infoline(" - Remove and destroy observer2");
1875 tet_infoline(" - Re-generate observer2 which has same address pointer with before.");
1876 tet_infoline(" - Remove and Reqeust third file by observer3");
1877 tet_infoline("Complete textureId2. and check old observer2 not emmited, and newly observer2 works.");
1878 tet_infoline("Complete textureId3. and check observer3 comes");
1880 TextureManager textureManager; // Create new texture manager
1882 TestObserverWithCustomFunction observer1;
1883 TestObserverWithCustomFunction* observer2 = new TestObserverWithCustomFunction(); // Deleted in observer1 loaded signal.
1884 TestObserver observer3;
1886 std::string filename1(TEST_IMAGE_FILE_NAME);
1887 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1888 std::string filename3(TEST_IMAGE_3_FILE_NAME);
1889 std::string filename4(TEST_IMAGE_4_FILE_NAME);
1891 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1892 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1893 auto textureId3(TextureManager::INVALID_TEXTURE_ID);
1894 auto textureId4(TextureManager::INVALID_TEXTURE_ID);
1896 // Dummy reference value
1897 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1899 // Request image 1, 2, 3.
1900 textureId1 = textureManager.RequestLoad(
1903 FittingMode::SCALE_TO_FILL,
1904 SamplingMode::BOX_THEN_LINEAR,
1905 TextureManager::UseAtlas::NO_ATLAS,
1908 TextureManager::ReloadPolicy::CACHED,
1911 textureId2 = textureManager.RequestLoad(
1914 FittingMode::SCALE_TO_FILL,
1915 SamplingMode::BOX_THEN_LINEAR,
1916 TextureManager::UseAtlas::NO_ATLAS,
1919 TextureManager::ReloadPolicy::CACHED,
1922 textureId3 = textureManager.RequestLoad(
1925 FittingMode::SCALE_TO_FILL,
1926 SamplingMode::BOX_THEN_LINEAR,
1927 TextureManager::UseAtlas::NO_ATLAS,
1930 TextureManager::ReloadPolicy::CACHED,
1935 TextureManager* textureManagerPtr{nullptr};
1936 TextureManager::TextureId removeTextureId{TextureManager::INVALID_TEXTURE_ID};
1937 TestObserverWithCustomFunction** removeTextureObserver{nullptr};
1938 std::string resendFilename{};
1939 TextureManager::TextureId resendTextureId{TextureManager::INVALID_TEXTURE_ID};
1940 TestObserver* resendTextureObserver{nullptr};
1941 std::string newlyFilename{};
1942 TextureManager::TextureId* newlyTextureIdPtr{nullptr};
1946 TextureManager* textureManagerPtr{nullptr};
1947 TestObserver* self{nullptr};
1948 bool* observerLoadedPtr{nullptr};
1949 bool* observerCalledPtr{nullptr};
1952 bool observer2Loaded = false;
1953 bool observer2Called = false;
1954 bool newObserver2Loaded = false;
1955 bool newObserver2Called = false;
1956 CustomData2 newData2; // Used on observer1 function
1958 // Connect observer1 custom function
1960 data1.textureManagerPtr = &textureManager;
1961 data1.removeTextureId = textureId2;
1962 data1.removeTextureObserver = &observer2;
1963 data1.resendFilename = filename3;
1964 data1.resendTextureId = textureId3;
1965 data1.resendTextureObserver = &observer3;
1966 data1.newlyFilename = filename2; // Same as observer2 filename
1967 data1.newlyTextureIdPtr = &textureId4;
1969 observer1.mData = &data1;
1970 observer1.ConnectFunction(
1972 DALI_TEST_CHECK(data);
1973 CustomData1 data1 = *(CustomData1*)data;
1975 DALI_TEST_CHECK(data1.textureManagerPtr);
1976 DALI_TEST_CHECK(data1.removeTextureId != TextureManager::INVALID_TEXTURE_ID);
1977 DALI_TEST_CHECK(data1.removeTextureObserver);
1978 DALI_TEST_CHECK(*data1.removeTextureObserver);
1979 DALI_TEST_CHECK(!data1.resendFilename.empty());
1980 DALI_TEST_CHECK(data1.resendTextureId != TextureManager::INVALID_TEXTURE_ID);
1981 DALI_TEST_CHECK(data1.resendTextureObserver);
1982 DALI_TEST_CHECK(!data1.newlyFilename.empty());
1983 DALI_TEST_CHECK(data1.newlyTextureIdPtr);
1984 DALI_TEST_CHECK(*data1.newlyTextureIdPtr == TextureManager::INVALID_TEXTURE_ID);
1986 // Remove textureId2.
1987 data1.textureManagerPtr->RequestRemove(data1.removeTextureId, *data1.removeTextureObserver);
1989 auto removedObserver = *data1.removeTextureObserver;
1991 // Destroy observer2.
1992 delete removedObserver;
1994 // Create new observer. Make we use same pointer if we can.
1995 uint32_t maxTryCount = 100u;
1996 uint32_t tryCount = 0u;
1998 while(tryCount < maxTryCount)
2000 *data1.removeTextureObserver = new TestObserverWithCustomFunction();
2001 if(removedObserver == *data1.removeTextureObserver) break;
2003 delete *data1.removeTextureObserver;
2006 tet_printf("TryCount[%u] / Old observer2 : %p, newly observer2 : %p\n", tryCount, removedObserver, *data1.removeTextureObserver);
2008 // Connect new observer2 custom function
2009 newData2.textureManagerPtr = &textureManager;
2010 newData2.self = (*data1.removeTextureObserver);
2011 newData2.observerLoadedPtr = &newObserver2Loaded;
2012 newData2.observerCalledPtr = &newObserver2Called;
2014 (*data1.removeTextureObserver)->mData = &newData2;
2015 (*data1.removeTextureObserver)->ConnectFunction([](void* data) {
2016 DALI_TEST_CHECK(data);
2017 CustomData2 data2 = *(CustomData2*)data;
2019 tet_printf("New created observer running\n");
2021 DALI_TEST_CHECK(data2.self);
2022 DALI_TEST_CHECK(data2.observerLoadedPtr);
2023 DALI_TEST_CHECK(data2.observerCalledPtr);
2025 *data2.observerLoadedPtr = data2.self->mLoaded;
2026 *data2.observerCalledPtr = data2.self->mObserverCalled;
2029 // Dummy reference value
2030 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
2032 // Resend textureId3
2033 data1.textureManagerPtr->RequestRemove(data1.resendTextureId, data1.resendTextureObserver);
2035 TextureManager::TextureId tempId;
2036 tempId = data1.textureManagerPtr->RequestLoad(
2037 data1.resendFilename,
2039 FittingMode::SCALE_TO_FILL,
2040 SamplingMode::BOX_THEN_LINEAR,
2041 TextureManager::UseAtlas::NO_ATLAS,
2042 data1.resendTextureObserver,
2044 TextureManager::ReloadPolicy::CACHED,
2047 DALI_TEST_CHECK(tempId == data1.resendTextureId);
2051 tempId = data1.textureManagerPtr->RequestLoad(
2052 data1.newlyFilename,
2054 FittingMode::SCALE_TO_FILL,
2055 SamplingMode::BOX_THEN_LINEAR,
2056 TextureManager::UseAtlas::NO_ATLAS,
2057 *data1.removeTextureObserver,
2059 TextureManager::ReloadPolicy::CACHED,
2062 DALI_TEST_CHECK(tempId != TextureManager::INVALID_TEXTURE_ID);
2063 *data1.newlyTextureIdPtr = tempId;
2066 // Connect observer2 custom function
2068 data2.textureManagerPtr = &textureManager;
2069 data2.self = observer2;
2070 data2.observerLoadedPtr = &observer2Loaded;
2071 data2.observerCalledPtr = &observer2Called;
2073 observer2->mData = &data2;
2074 observer2->ConnectFunction(
2076 DALI_TEST_CHECK(data);
2077 CustomData2 data2 = *(CustomData2*)data;
2079 tet_printf("Old created observer running. Something error occured!\n");
2081 DALI_TEST_CHECK(data2.self);
2082 DALI_TEST_CHECK(data2.observerLoadedPtr);
2083 DALI_TEST_CHECK(data2.observerCalledPtr);
2085 *data2.observerLoadedPtr = data2.self->mLoaded;
2086 *data2.observerCalledPtr = data2.self->mObserverCalled;
2089 application.SendNotification();
2090 application.Render();
2092 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));
2094 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
2095 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
2096 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2097 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2098 DALI_TEST_EQUALS(newObserver2Loaded, false, TEST_LOCATION);
2099 DALI_TEST_EQUALS(newObserver2Called, false, TEST_LOCATION);
2100 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2101 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2103 DALI_TEST_CHECK(textureId4 == TextureManager::INVALID_TEXTURE_ID);
2105 // CAPTION : HARD-CODING.
2106 // Run codes without exception.
2109 tet_printf("Complete async load 1 first.\n");
2110 std::vector<Devel::PixelBuffer> pixelBuffers;
2112 pixelBuffers.clear();
2113 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2114 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
2116 tet_printf("Now observer2 deleted, observer3 resended, observer2 re-created.\n");
2117 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2118 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2119 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2120 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2121 DALI_TEST_EQUALS(newObserver2Loaded, false, TEST_LOCATION);
2122 DALI_TEST_EQUALS(newObserver2Called, false, TEST_LOCATION);
2123 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2124 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2126 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));
2128 DALI_TEST_CHECK(textureId4 == textureId2);
2130 // Remove processor excute.
2131 application.SendNotification();
2132 application.Render();
2134 tet_printf("Complete async load 2. Let we check old version observer2 ignored and newly observer2 loaded.\n");
2135 pixelBuffers.clear();
2136 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2137 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
2139 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2140 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2141 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2142 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2143 DALI_TEST_EQUALS(newObserver2Loaded, true, TEST_LOCATION);
2144 DALI_TEST_EQUALS(newObserver2Called, true, TEST_LOCATION);
2145 // We don't check observer3 not loaded case because SendNotification can process AsyncTask.
2146 //DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2147 //DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2149 tet_printf("Complete async load 3.\n");
2150 pixelBuffers.clear();
2151 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2152 textureManager.AsyncLoadComplete(textureId3, pixelBuffers);
2154 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2155 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2156 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2157 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2158 DALI_TEST_EQUALS(newObserver2Loaded, true, TEST_LOCATION);
2159 DALI_TEST_EQUALS(newObserver2Called, true, TEST_LOCATION);
2160 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
2161 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
2165 DALI_TEST_CHECK(false);