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 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
66 const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
68 class TestObserver : public Dali::Toolkit::TextureUploadObserver
71 enum class CompleteType
80 : mCompleteType(CompleteType::NOT_COMPLETED),
82 mObserverCalled(false),
87 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
89 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
91 mCompleteType = CompleteType::UPLOAD_COMPLETE;
95 mCompleteType = CompleteType::LOAD_COMPLETE;
97 mLoaded = loadSuccess;
98 mObserverCalled = true;
99 mTextureSet = textureInformation.textureSet;
102 CompleteType mCompleteType;
104 bool mObserverCalled;
105 TextureSet mTextureSet;
108 class TestObserverRemoveAndGenerateUrl : public TestObserver
111 TestObserverRemoveAndGenerateUrl(TextureManager* textureManagerPtr)
113 mTextureManagerPtr(textureManagerPtr)
117 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
119 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
121 mCompleteType = CompleteType::UPLOAD_COMPLETE;
125 mCompleteType = CompleteType::LOAD_COMPLETE;
127 mLoaded = loadSuccess;
128 mObserverCalled = true;
129 mTextureSet = textureInformation.textureSet;
131 // Remove during LoadComplete
132 mTextureManagerPtr->RequestRemove(textureInformation.textureId, nullptr);
134 // ...And generate string which using texture id.
135 mGeneratedExternalUrl = mTextureManagerPtr->AddExternalTexture(mTextureSet);
139 std::string mGeneratedExternalUrl;
142 TextureManager* mTextureManagerPtr; // Keep the pointer of texture manager.
145 class TestObserverWithCustomFunction : public TestObserver
148 TestObserverWithCustomFunction()
156 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
158 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
160 mCompleteType = CompleteType::UPLOAD_COMPLETE;
164 mCompleteType = CompleteType::LOAD_COMPLETE;
166 mLoaded = loadSuccess;
167 mObserverCalled = true;
168 mTextureSet = textureInformation.textureSet;
171 for(size_t i = 0; i < mSignals.size(); i++)
183 void ConnectFunction(std::function<void(void*)> signal)
185 mSignals.push_back(signal);
189 std::vector<std::function<void(void*)>> mSignals;
196 int UtcTextureManagerRequestLoad(void)
198 ToolkitTestApplication application;
200 TextureManager textureManager; // Create new texture manager
202 TestObserver observer;
203 std::string filename("image.png");
204 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
205 TextureManager::TextureId textureId = textureManager.RequestLoad(
208 FittingMode::SCALE_TO_FILL,
209 SamplingMode::BOX_THEN_LINEAR,
212 TextureManager::ReloadPolicy::CACHED,
215 VisualUrl url = textureManager.GetVisualUrl(textureId);
217 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
222 int UtcTextureManagerGenerateHash(void)
224 ToolkitTestApplication application;
226 TextureManager textureManager; // Create new texture manager
228 TestObserver observer;
229 std::string filename("image.png");
230 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
231 TextureManager::TextureId textureId = textureManager.RequestLoad(
234 FittingMode::SCALE_TO_FILL,
235 SamplingMode::BOX_THEN_LINEAR,
238 TextureManager::ReloadPolicy::CACHED,
241 VisualUrl url = textureManager.GetVisualUrl(textureId);
243 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
248 int UtcTextureManagerEncodedImageBuffer(void)
250 ToolkitTestApplication application;
251 tet_infoline("UtcTextureManagerEncodedImageBuffer");
253 auto visualFactory = Toolkit::VisualFactory::Get();
254 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
256 // Get encoded raw-buffer image and generate url
257 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
258 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
260 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
261 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
262 std::string url3 = VisualUrl::CreateBufferUrl("", ""); ///< Impossible Buffer URL. for coverage
264 // Check if same EncodedImageBuffer get same url
265 DALI_TEST_CHECK(url1 == url2);
266 // Reduce reference count
267 textureManager.RemoveEncodedImageBuffer(url1);
268 // Check whethere url1 still valid
269 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
271 url2 = textureManager.AddEncodedImageBuffer(buffer2);
272 // Check if difference EncodedImageBuffer get difference url
273 DALI_TEST_CHECK(url1 != url2);
275 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
277 TestObserver observer1;
278 textureManager.RequestLoad(
281 FittingMode::SCALE_TO_FILL,
282 SamplingMode::BOX_THEN_LINEAR,
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,
357 true, ///< orientationCorrection
358 TextureManager::ReloadPolicy::CACHED,
361 // Load will be success because url1 is cached
362 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
363 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
364 DALI_TEST_EQUALS(observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
366 TestObserver observer4;
367 textureManager.RequestLoad(
370 FittingMode::SCALE_TO_FILL,
371 SamplingMode::BOX_THEN_LINEAR,
373 true, ///< orientationCorrection
374 TextureManager::ReloadPolicy::FORCED,
377 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
378 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
379 application.SendNotification();
380 application.Render();
382 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
384 application.SendNotification();
385 application.Render();
387 // Load will be failed becuase reloadpolicy is forced
388 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
389 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
390 DALI_TEST_EQUALS(observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
392 TestObserver observer5;
393 pixelBuffer = textureManager.LoadPixelBuffer(
396 FittingMode::SCALE_TO_FILL,
397 SamplingMode::BOX_THEN_LINEAR,
398 true, ///< synchronousLoading
400 true, ///< orientationCorrection
403 // Load will be faild because synchronousLoading doesn't use cached texture
404 DALI_TEST_CHECK(!pixelBuffer);
405 DALI_TEST_EQUALS(observer5.mLoaded, false, TEST_LOCATION);
406 DALI_TEST_EQUALS(observer5.mObserverCalled, false, TEST_LOCATION);
408 TestObserver observer6;
409 pixelBuffer = textureManager.LoadPixelBuffer(
412 FittingMode::SCALE_TO_FILL,
413 SamplingMode::BOX_THEN_LINEAR,
414 false, ///< synchronousLoading
416 true, ///< orientationCorrection
419 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
420 DALI_TEST_EQUALS(observer6.mObserverCalled, false, TEST_LOCATION);
422 application.SendNotification();
423 application.Render();
425 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
427 application.SendNotification();
428 application.Render();
430 // Load will be failed because url3 is invalid URL
431 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
432 DALI_TEST_EQUALS(observer6.mObserverCalled, true, TEST_LOCATION);
433 DALI_TEST_EQUALS(observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
438 int UtcTextureManagerEncodedImageBufferWithImageType(void)
440 ToolkitTestApplication application;
441 tet_infoline("UtcTextureManagerEncodedImageBufferWithImageType");
443 auto visualFactory = Toolkit::VisualFactory::Get();
444 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
446 // Get encoded raw-buffer image and generate url
447 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_SVG_FILE_NAME);
448 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME);
450 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
451 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
453 // Check if same EncodedImageBuffer get same url
454 DALI_TEST_CHECK(url1 == url2);
455 // Reduce reference count
456 textureManager.RemoveEncodedImageBuffer(url1);
457 // Check whethere url1 still valid
458 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
460 url2 = textureManager.AddEncodedImageBuffer(buffer2);
461 // Check if difference EncodedImageBuffer get difference url
462 DALI_TEST_CHECK(url1 != url2);
464 buffer1.SetImageType(EncodedImageBuffer::ImageType::VECTOR_IMAGE);
465 buffer2.SetImageType(EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE);
467 std::string url1AfterType = textureManager.AddEncodedImageBuffer(buffer1);
468 std::string url2AfterType = textureManager.AddEncodedImageBuffer(buffer2);
470 // Check if EncodedImageBuffer with imagetype get difference url.
471 DALI_TEST_CHECK(url1 != url1AfterType);
472 DALI_TEST_CHECK(url2 != url2AfterType);
473 DALI_TEST_CHECK(url1AfterType != url2AfterType);
475 int bufferId = std::atoi(VisualUrl::GetLocationWithoutExtension(url1AfterType).c_str());
476 auto urlFromBuffer = textureManager.GetVisualUrl(bufferId);
478 // Check url from buffer id is equal with what we know.
479 DALI_TEST_CHECK(url1AfterType == urlFromBuffer.GetUrl());
481 // Reduce reference count
482 textureManager.RemoveEncodedImageBuffer(url1AfterType);
483 // Check whethere url1 still valid
484 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1AfterType));
486 // Reduce reference count
487 textureManager.RemoveEncodedImageBuffer(url1AfterType);
488 // Check whethere url1 is invalid
489 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1AfterType));
491 // Reduce reference count
492 textureManager.RemoveEncodedImageBuffer(url2);
493 // Check whethere url2 is still valid
494 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url2));
496 // Reduce reference count
497 textureManager.RemoveEncodedImageBuffer(url2);
498 // Check whethere url2 is invalid
499 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
504 int UtcTextureManagerExternalTexture(void)
506 ToolkitTestApplication application;
507 tet_infoline("UtcTextureManagerExternalTexture check TextureManager using external texture works well");
509 auto visualFactory = Toolkit::VisualFactory::Get();
510 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
512 TestObserver observer1;
513 TestObserver observer2;
515 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
516 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
517 std::string maskname(TEST_MASK_FILE_NAME);
518 TextureManager::MaskingDataPointer maskInfo = nullptr;
519 maskInfo.reset(new TextureManager::MaskingData());
520 maskInfo->mAlphaMaskUrl = maskname;
521 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
522 maskInfo->mCropToMask = true;
523 maskInfo->mContentScaleFactor = 1.0f;
524 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
525 Dali::ImageDimensions atlasRectSize(0, 0);
526 bool synchronousLoading(false);
527 bool atlasingStatus(false);
528 bool loadingStatus(false);
529 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
530 ImageAtlasManagerPtr atlasManager = nullptr;
531 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
535 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
537 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
538 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
540 DALI_TEST_CHECK(pixelData);
542 Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
543 std::string url = imageUrl.GetUrl();
545 TextureSet texture1 = textureManager.LoadTexture(
548 FittingMode::SCALE_TO_FILL,
549 SamplingMode::BOX_THEN_LINEAR,
561 TextureManager::ReloadPolicy::CACHED,
564 TextureSet texture2 = textureManager.LoadTexture(
567 FittingMode::SCALE_TO_FILL,
568 SamplingMode::BOX_THEN_LINEAR,
580 TextureManager::ReloadPolicy::CACHED,
583 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
584 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
585 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
586 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
588 application.SendNotification();
589 application.Render();
591 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
593 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
594 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
595 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
597 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
598 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
599 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
601 DALI_TEST_EQUALS(textureId1 == textureId2, true, TEST_LOCATION);
603 texture1 = textureManager.LoadTexture(
606 FittingMode::SCALE_TO_FILL,
607 SamplingMode::BOX_THEN_LINEAR,
619 TextureManager::ReloadPolicy::CACHED,
622 texture2 = textureManager.LoadTexture(
625 FittingMode::SCALE_TO_FILL,
626 SamplingMode::BOX_THEN_LINEAR,
638 TextureManager::ReloadPolicy::CACHED,
641 application.SendNotification();
642 application.Render();
644 DALI_TEST_EQUALS(textureId1 == textureId2, true, TEST_LOCATION);
645 DALI_TEST_EQUALS(texture1 != texture2, true, TEST_LOCATION);
650 int UtcTextureManagerRemoveExternalTextureAndLoadAgain(void)
652 ToolkitTestApplication application;
653 tet_infoline("UtcTextureManagerRemoveExternalTextureAndLoadAgain check TextureManager RequestRemove and RemoveExternalTexture lifecycle works well");
655 auto visualFactory = Toolkit::VisualFactory::Get();
656 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
658 TestObserver observer1;
659 TestObserver observer2;
661 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
662 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
663 TextureManager::MaskingDataPointer maskInfo = nullptr;
665 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
666 Dali::ImageDimensions atlasRectSize(0, 0);
667 bool synchronousLoading(false);
668 bool atlasingStatus(false);
669 bool loadingStatus(false);
670 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
671 ImageAtlasManagerPtr atlasManager = nullptr;
672 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
676 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
678 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
679 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
681 DALI_TEST_CHECK(pixelData);
683 Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
684 std::string url1 = imageUrl.GetUrl();
685 std::string url2 = TEST_IMAGE_FILE_NAME;
687 // Step 1 : Load request for external url
688 TextureSet texture1 = textureManager.LoadTexture(
691 FittingMode::SCALE_TO_FILL,
692 SamplingMode::BOX_THEN_LINEAR,
704 TextureManager::ReloadPolicy::CACHED,
707 DALI_TEST_CHECK(textureId1 != TextureManager::INVALID_TEXTURE_ID);
709 // Step 2 : Request remove for external url
710 textureManager.RequestRemove(textureId1, &observer1);
712 // Step 3 : Reduce imageUrl reference count.
715 // Step 4 : Request new load by normal image.
716 TextureSet texture2 = textureManager.LoadTexture(
719 FittingMode::SCALE_TO_FILL,
720 SamplingMode::BOX_THEN_LINEAR,
732 TextureManager::ReloadPolicy::CACHED,
735 DALI_TEST_CHECK(textureId2 != TextureManager::INVALID_TEXTURE_ID);
737 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
738 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
739 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
740 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
742 application.SendNotification();
743 application.Render();
745 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
747 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
748 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
750 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
751 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
752 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
757 int UtcTextureManagerEncodedImageBufferReferenceCount(void)
759 ToolkitTestApplication application;
760 tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well");
762 auto visualFactory = Toolkit::VisualFactory::Get();
763 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
765 // Get encoded raw-buffer image and generate url
766 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
767 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
769 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
770 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
772 // Check if same EncodedImageBuffer get same url
773 DALI_TEST_CHECK(url1 == url2);
775 // Reduce reference count
776 textureManager.RemoveEncodedImageBuffer(url1);
777 // Check whethere url1 still valid
778 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
780 // Reduce reference count
781 textureManager.RemoveEncodedImageBuffer(url1);
782 // Check whethere url1 is not valid anymore
783 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
785 // UseExternalTexture doesn't create new buffer.
786 // So, reference count is still zero.
787 textureManager.UseExternalResource(url1);
788 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
790 url1 = textureManager.AddEncodedImageBuffer(buffer1);
792 url2 = textureManager.AddEncodedImageBuffer(buffer2);
793 // Check if difference EncodedImageBuffer get difference url
794 DALI_TEST_CHECK(url1 != url2);
796 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
798 // url1 load image by cache
799 TestObserver observer1;
800 textureManager.RequestLoad(
803 FittingMode::SCALE_TO_FILL,
804 SamplingMode::BOX_THEN_LINEAR,
806 true, ///< orientationCorrection
807 TextureManager::ReloadPolicy::CACHED,
810 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
811 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
813 application.SendNotification();
814 application.Render();
816 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
818 application.SendNotification();
819 application.Render();
821 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
822 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
823 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
825 // LoadPixelBuffer doen't use cache. url2 will not be cached
826 TestObserver observer2;
827 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
830 FittingMode::SCALE_TO_FILL,
831 SamplingMode::BOX_THEN_LINEAR,
832 false, ///< synchronousLoading
834 true, ///< orientationCorrection
837 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
838 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
840 application.SendNotification();
841 application.Render();
843 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
845 application.SendNotification();
846 application.Render();
848 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
849 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
850 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
852 // Decrease each url's reference count.
853 textureManager.RemoveEncodedImageBuffer(url1);
854 textureManager.RemoveEncodedImageBuffer(url2);
856 // url1 buffer is still have 1 reference count because it is cached.
857 // But url2 not valid because it is not cached.
858 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
859 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
861 // Check url1 buffer have 1 reference count because it is cached.
862 textureManager.RemoveEncodedImageBuffer(url1);
863 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
868 int UtcTextureManagerCachingForDifferentLoadingType(void)
870 ToolkitTestApplication application;
871 tet_infoline("UtcTextureManagerCachingForDifferentLoadingType");
873 TextureManager textureManager; // Create new texture manager
875 TestObserver observer1;
876 std::string filename(TEST_IMAGE_FILE_NAME);
877 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
878 textureManager.RequestLoad(
881 FittingMode::SCALE_TO_FILL,
882 SamplingMode::BOX_THEN_LINEAR,
885 TextureManager::ReloadPolicy::CACHED,
888 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
889 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
891 application.SendNotification();
892 application.Render();
894 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
896 application.SendNotification();
897 application.Render();
899 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
900 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
901 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
903 TestObserver observer2;
904 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
907 FittingMode::SCALE_TO_FILL,
908 SamplingMode::BOX_THEN_LINEAR,
914 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
915 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
917 application.SendNotification();
918 application.Render();
920 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
922 application.SendNotification();
923 application.Render();
925 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
926 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
927 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
932 int UtcTextureManagerUseInvalidMask(void)
934 ToolkitTestApplication application;
935 tet_infoline("UtcTextureManagerUseInvalidMask");
937 TextureManager textureManager; // Create new texture manager
939 TestObserver observer;
940 std::string filename(TEST_IMAGE_FILE_NAME);
941 std::string maskname("");
942 TextureManager::MaskingDataPointer maskInfo = nullptr;
943 maskInfo.reset(new TextureManager::MaskingData());
944 maskInfo->mAlphaMaskUrl = maskname;
945 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
946 maskInfo->mCropToMask = true;
947 maskInfo->mContentScaleFactor = 1.0f;
949 auto textureId(TextureManager::INVALID_TEXTURE_ID);
950 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
951 Dali::ImageDimensions atlasRectSize(0, 0);
952 bool synchronousLoading(false);
953 bool atlasingStatus(false);
954 bool loadingStatus(false);
955 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
956 ImageAtlasManagerPtr atlasManager = nullptr;
957 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
959 textureManager.LoadTexture(
962 FittingMode::SCALE_TO_FILL,
963 SamplingMode::BOX_THEN_LINEAR,
975 TextureManager::ReloadPolicy::CACHED,
978 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
979 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
981 application.SendNotification();
982 application.Render();
984 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
986 application.SendNotification();
987 application.Render();
989 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
990 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
991 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
996 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
998 ToolkitTestApplication application;
999 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
1000 tet_infoline("Try to check PostLoad works well");
1002 TextureManager textureManager; // Create new texture manager
1004 TestObserver observer;
1005 std::string filename(TEST_IMAGE_FILE_NAME);
1006 std::string maskname("invalid.png");
1007 TextureManager::MaskingDataPointer maskInfo = nullptr;
1008 maskInfo.reset(new TextureManager::MaskingData());
1009 maskInfo->mAlphaMaskUrl = maskname;
1010 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1011 maskInfo->mCropToMask = true;
1012 maskInfo->mContentScaleFactor = 1.0f;
1014 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1015 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1016 Dali::ImageDimensions atlasRectSize(0, 0);
1017 bool synchronousLoading(false);
1018 bool atlasingStatus(false);
1019 bool loadingStatus(false);
1020 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1021 ImageAtlasManagerPtr atlasManager = nullptr;
1022 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1024 textureManager.LoadTexture(
1027 FittingMode::SCALE_TO_FILL,
1028 SamplingMode::BOX_THEN_LINEAR,
1037 atlasUploadObserver,
1040 TextureManager::ReloadPolicy::CACHED,
1043 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1044 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1046 application.SendNotification();
1047 application.Render();
1049 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1051 application.SendNotification();
1052 application.Render();
1054 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1055 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1056 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1061 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
1063 ToolkitTestApplication application;
1064 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
1065 tet_infoline("Try to check CheckForWaitingTexture called");
1067 TextureManager textureManager; // Create new texture manager
1069 TestObserver observer;
1070 std::string filename(TEST_IMAGE_FILE_NAME);
1071 std::string maskname("invalid.png");
1072 TextureManager::MaskingDataPointer maskInfo = nullptr;
1073 maskInfo.reset(new TextureManager::MaskingData());
1074 maskInfo->mAlphaMaskUrl = maskname;
1075 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1076 maskInfo->mCropToMask = true;
1077 maskInfo->mContentScaleFactor = 1.0f;
1079 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1080 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1081 Dali::ImageDimensions atlasRectSize(0, 0);
1082 bool synchronousLoading(false);
1083 bool atlasingStatus(false);
1084 bool loadingStatus(false);
1085 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1086 ImageAtlasManagerPtr atlasManager = nullptr;
1087 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1089 textureManager.LoadTexture(
1092 FittingMode::SCALE_TO_FILL,
1093 SamplingMode::BOX_THEN_LINEAR,
1102 atlasUploadObserver,
1105 TextureManager::ReloadPolicy::CACHED,
1108 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1109 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1111 // CAPTION : HARD-CODING for coverage.
1113 Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
1116 FittingMode::SCALE_TO_FILL,
1117 SamplingMode::BOX_THEN_LINEAR,
1118 true, ///< synchronousLoading
1120 true, ///< orientationCorrection
1123 std::vector<Devel::PixelBuffer> pixelBuffers;
1124 pixelBuffers.push_back(pixelBuffer);
1125 textureManager.AsyncLoadComplete(textureId, pixelBuffers);
1126 std::vector<Devel::PixelBuffer> maskBuffers;
1127 textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
1128 textureManager.RequestRemove(maskInfo->mAlphaMaskId, nullptr);
1129 textureManager.RequestRemove(textureId, &observer);
1132 application.SendNotification();
1133 application.Render();
1135 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1136 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1137 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1139 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1144 int UtcTextureManagerSynchronousLoadingFail(void)
1146 ToolkitTestApplication application;
1147 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
1149 TextureManager textureManager; // Create new texture manager
1151 std::string maskname("");
1152 TextureManager::MaskingDataPointer maskInfo = nullptr;
1153 maskInfo.reset(new TextureManager::MaskingData());
1154 maskInfo->mAlphaMaskUrl = maskname;
1155 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1156 maskInfo->mCropToMask = true;
1157 maskInfo->mContentScaleFactor = 1.0f;
1159 std::string filename("dummy");
1160 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1161 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1162 Dali::ImageDimensions atlasRectSize(0, 0);
1163 bool atlasingStatus(false);
1164 bool loadingStatus(false);
1165 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1166 ImageAtlasManagerPtr atlasManager = nullptr;
1167 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1169 // load image synchronously.
1170 TestObserver observer;
1171 TextureSet textureSet = textureManager.LoadTexture(
1174 FittingMode::SCALE_TO_FILL,
1175 SamplingMode::BOX_THEN_LINEAR,
1177 true, // synchronous loading.
1184 atlasUploadObserver,
1187 TextureManager::ReloadPolicy::CACHED,
1190 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1191 DALI_TEST_CHECK(!textureSet); // texture loading fail.
1192 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
1197 int UtcTextureManagerCachingSynchronousLoading(void)
1199 ToolkitTestApplication application;
1200 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
1202 TextureManager textureManager; // Create new texture manager
1204 std::string filename(TEST_IMAGE_FILE_NAME);
1206 std::string maskname("");
1207 TextureManager::MaskingDataPointer maskInfo = nullptr;
1208 maskInfo.reset(new TextureManager::MaskingData());
1209 maskInfo->mAlphaMaskUrl = maskname;
1210 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1211 maskInfo->mCropToMask = true;
1212 maskInfo->mContentScaleFactor = 1.0f;
1214 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1215 Dali::ImageDimensions atlasRectSize(0, 0);
1216 bool atlasingStatus(false);
1217 bool loadingStatus(false);
1218 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1219 ImageAtlasManagerPtr atlasManager = nullptr;
1220 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1222 // load image synchronously.
1223 TestObserver observer;
1224 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1225 TextureSet textureSet = textureManager.LoadTexture(
1228 FittingMode::SCALE_TO_FILL,
1229 SamplingMode::BOX_THEN_LINEAR,
1231 true, // synchronous loading.
1238 atlasUploadObserver,
1241 TextureManager::ReloadPolicy::CACHED,
1244 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1245 DALI_TEST_CHECK(textureSet); // texture is loaded.
1247 // observer isn't called in synchronous loading.
1248 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1249 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1251 // load same image asynchronously.
1252 TestObserver asyncObserver;
1253 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
1254 loadingStatus = false;
1255 TextureSet asyncTextureSet = textureManager.LoadTexture(
1258 FittingMode::SCALE_TO_FILL,
1259 SamplingMode::BOX_THEN_LINEAR,
1261 false, // asynchronous loading.
1268 atlasUploadObserver,
1271 TextureManager::ReloadPolicy::CACHED,
1274 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
1275 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
1276 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
1278 // observer is directly called because textureSet is retrieved by cache.
1279 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
1280 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
1285 int UtcTextureManagerAsyncSyncAsync(void)
1287 ToolkitTestApplication application;
1288 tet_infoline("UtcTextureManagerAsyncSyncAsync");
1290 TextureManager textureManager; // Create new texture manager
1292 std::string filename(TEST_IMAGE_FILE_NAME);
1294 std::string maskname("");
1295 TextureManager::MaskingDataPointer maskInfo = nullptr;
1296 maskInfo.reset(new TextureManager::MaskingData());
1297 maskInfo->mAlphaMaskUrl = maskname;
1298 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1299 maskInfo->mCropToMask = true;
1300 maskInfo->mContentScaleFactor = 1.0f;
1302 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
1303 Dali::ImageDimensions atlasRectSize(0, 0);
1304 bool atlasingStatus(false);
1305 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1306 ImageAtlasManagerPtr atlasManager = nullptr;
1307 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1309 // load image asynchronously.
1310 TestObserver asyncObserver1;
1311 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
1312 bool asyncLoadingStatus1 = false;
1313 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
1316 FittingMode::SCALE_TO_FILL,
1317 SamplingMode::BOX_THEN_LINEAR,
1319 false, // asynchronous loading.
1324 asyncLoadingStatus1,
1326 atlasUploadObserver,
1329 TextureManager::ReloadPolicy::CACHED,
1332 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
1333 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
1335 // observer is still not called.
1336 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1337 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1339 // load same image synchronously just after asynchronous loading.
1340 TestObserver syncObserver;
1341 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1342 bool syncLoadingStatus = false;
1343 TextureSet syncTextureSet = textureManager.LoadTexture(
1346 FittingMode::SCALE_TO_FILL,
1347 SamplingMode::BOX_THEN_LINEAR,
1349 true, // synchronous loading.
1356 atlasUploadObserver,
1359 TextureManager::ReloadPolicy::CACHED,
1362 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
1363 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
1364 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
1366 // syncObserver isn't called in synchronous loading.
1367 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1368 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1370 // asyncObserver1 is still not called too.
1371 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1372 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1374 // load image asynchronously.
1375 TestObserver asyncObserver2;
1376 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1377 bool asyncLoadingStatus2 = false;
1378 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
1381 FittingMode::SCALE_TO_FILL,
1382 SamplingMode::BOX_THEN_LINEAR,
1384 false, // asynchronous loading.
1389 asyncLoadingStatus2,
1391 atlasUploadObserver,
1394 TextureManager::ReloadPolicy::CACHED,
1397 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1398 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
1399 Texture syncTexture = syncTextureSet.GetTexture(0u);
1400 Texture asyncTexture2 = asyncTextureSet2.GetTexture(0u);
1401 DALI_TEST_CHECK(syncTexture);
1402 DALI_TEST_CHECK(asyncTexture2);
1403 DALI_TEST_CHECK(asyncTexture2 == syncTexture); // check loaded two texture is same.
1405 // observer is called synchronously because the texture is cached.
1406 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1407 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1409 asyncObserver2.mLoaded = false;
1410 asyncObserver2.mObserverCalled = false;
1412 application.SendNotification();
1413 application.Render();
1415 // Requested asynchronous loading at first is finished now and async observer is called now.
1416 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1417 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1418 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1419 DALI_TEST_CHECK(asyncObserver1.mTextureSet);
1421 Texture observerTexture = asyncObserver1.mTextureSet.GetTexture(0u);
1422 DALI_TEST_CHECK(observerTexture == asyncTexture2); // check loaded two texture is same.
1424 // asyncObserver2 was already called so it isn't called here.
1425 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1426 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1431 int UtcTextureManagerQueueRemoveDuringObserve(void)
1433 ToolkitTestApplication application;
1434 tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1436 TextureManager textureManager; // Create new texture manager
1438 TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1440 std::string filename(TEST_IMAGE_FILE_NAME);
1441 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1443 TextureManager::TextureId textureId = textureManager.RequestLoad(
1446 FittingMode::SCALE_TO_FILL,
1447 SamplingMode::BOX_THEN_LINEAR,
1450 TextureManager::ReloadPolicy::CACHED,
1453 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1454 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1456 application.SendNotification();
1457 application.Render();
1459 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1461 application.SendNotification();
1462 application.Render();
1464 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1465 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1466 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1468 tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1470 DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1472 // Decrease external texture reference count who observer created
1473 textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1475 application.SendNotification();
1476 application.Render();
1481 int UtcTextureManagerRemoveDuringApplyMasking(void)
1483 ToolkitTestApplication application;
1484 tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1486 TextureManager textureManager; // Create new texture manager
1488 TestObserver observer1;
1489 TestObserver observer2;
1491 std::string filename(TEST_IMAGE_FILE_NAME);
1492 std::string maskname(TEST_MASK_FILE_NAME);
1493 TextureManager::MaskingDataPointer maskInfo = nullptr;
1494 maskInfo.reset(new TextureManager::MaskingData());
1495 maskInfo->mAlphaMaskUrl = maskname;
1496 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1497 maskInfo->mCropToMask = true;
1498 maskInfo->mContentScaleFactor = 1.0f;
1500 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1501 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1502 Dali::ImageDimensions atlasRectSize(0, 0);
1503 bool synchronousLoading(false);
1504 bool atlasingStatus(false);
1505 bool loadingStatus(false);
1506 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1507 ImageAtlasManagerPtr atlasManager = nullptr;
1508 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1510 textureManager.LoadTexture(
1513 FittingMode::SCALE_TO_FILL,
1514 SamplingMode::BOX_THEN_LINEAR,
1523 atlasUploadObserver,
1526 TextureManager::ReloadPolicy::CACHED,
1529 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1530 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1532 application.SendNotification();
1533 application.Render();
1535 // Load image and mask image.
1536 // Now, LoadState become MASK_APPLYING
1537 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1539 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1541 application.SendNotification();
1542 application.Render();
1544 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1545 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1547 // Remove current textureId1. and request new texture again.
1548 textureManager.RequestRemove(textureId1, &observer1);
1549 auto textureId2 = textureManager.RequestLoad(
1552 FittingMode::SCALE_TO_FILL,
1553 SamplingMode::BOX_THEN_LINEAR,
1555 true, ///< orientationCorrection
1556 TextureManager::ReloadPolicy::CACHED,
1558 synchronousLoading);
1560 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1561 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1562 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1563 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1565 tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1567 // CAPTION : HARD-CODING.
1569 std::vector<Devel::PixelBuffer> pixelBuffers;
1570 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1571 textureManager.RequestRemove(textureId2, &observer2);
1574 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1575 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1576 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1581 int UtcTextureManagerMaskCacheTest(void)
1583 ToolkitTestApplication application;
1584 tet_infoline("UtcTextureManagerMaskCacheTest");
1586 TextureManager textureManager; // Create new texture manager
1588 TestObserver observer1;
1589 TestObserver observer2;
1591 std::string filename(TEST_IMAGE_FILE_NAME);
1592 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1593 std::string maskname(TEST_MASK_FILE_NAME);
1594 TextureManager::MaskingDataPointer maskInfo = nullptr;
1595 maskInfo.reset(new TextureManager::MaskingData());
1596 maskInfo->mAlphaMaskUrl = maskname;
1597 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1598 maskInfo->mCropToMask = true;
1599 maskInfo->mContentScaleFactor = 1.0f;
1601 TextureManager::MaskingDataPointer maskInfo2 = nullptr;
1602 maskInfo2.reset(new TextureManager::MaskingData());
1603 maskInfo2->mAlphaMaskUrl = maskname;
1604 maskInfo2->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1605 maskInfo2->mCropToMask = true;
1606 maskInfo2->mContentScaleFactor = 1.0f;
1608 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1609 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1610 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1611 Dali::ImageDimensions atlasRectSize(0, 0);
1612 bool synchronousLoading(false);
1613 bool atlasingStatus(false);
1614 bool loadingStatus(false);
1615 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1616 ImageAtlasManagerPtr atlasManager = nullptr;
1617 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1619 textureManager.LoadTexture(
1622 FittingMode::SCALE_TO_FILL,
1623 SamplingMode::BOX_THEN_LINEAR,
1632 atlasUploadObserver,
1635 TextureManager::ReloadPolicy::CACHED,
1638 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1639 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1641 application.SendNotification();
1642 application.Render();
1644 // Load image and mask image.
1645 // Now, LoadState become MASK_APPLYING
1646 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1648 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1650 textureManager.LoadTexture(
1653 FittingMode::SCALE_TO_FILL,
1654 SamplingMode::BOX_THEN_LINEAR,
1663 atlasUploadObserver,
1666 TextureManager::ReloadPolicy::CACHED,
1669 application.SendNotification();
1670 application.Render();
1672 // Load image2 + image1 apply mask + image2 apply mask = total 3 event trigger required.
1673 // Note that we use cached mask image.
1674 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1676 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1677 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1678 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1679 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1683 // Remove textureId1 first, and then remove textureId2. Check whether segfault occured.
1684 textureManager.RequestRemove(textureId1, &observer1);
1686 application.SendNotification();
1687 application.Render();
1689 textureManager.RequestRemove(textureId2, &observer2);
1691 application.SendNotification();
1692 application.Render();
1694 TestObserver observer3;
1695 maskInfo.reset(new TextureManager::MaskingData());
1696 maskInfo->mAlphaMaskUrl = maskname;
1697 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1698 maskInfo->mCropToMask = true;
1699 maskInfo->mContentScaleFactor = 1.0f;
1701 textureManager.LoadTexture(
1704 FittingMode::SCALE_TO_FILL,
1705 SamplingMode::BOX_THEN_LINEAR,
1714 atlasUploadObserver,
1717 TextureManager::ReloadPolicy::CACHED,
1720 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1721 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1723 application.SendNotification();
1724 application.Render();
1726 // Load image and mask image.
1727 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1728 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1730 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1731 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1734 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1736 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
1737 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
1741 DALI_TEST_CHECK(false);
1747 int UtcTextureManagerRemoveDuringGPUMasking(void)
1749 ToolkitTestApplication application;
1750 tet_infoline("UtcTextureManagerRemoveDuringGPUMasking");
1751 tet_infoline("Request 3 different GPU masking image.");
1752 tet_infoline("Control to mask image load last. and then, check execute result.");
1754 TextureManager textureManager; // Create new texture manager
1756 TestObserverWithCustomFunction observer1;
1757 TestObserverWithCustomFunction observer2;
1758 TestObserverWithCustomFunction* observer3 = new TestObserverWithCustomFunction(); // Deleted in observer1 loaded signal
1759 TestObserver observer4;
1761 std::string filename1(TEST_IMAGE_FILE_NAME);
1762 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1763 std::string filename3(TEST_IMAGE_3_FILE_NAME);
1764 std::string filename4(TEST_IMAGE_4_FILE_NAME);
1766 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1767 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1768 auto textureId3(TextureManager::INVALID_TEXTURE_ID);
1769 auto textureId4(TextureManager::INVALID_TEXTURE_ID);
1771 std::string maskname(TEST_MASK_FILE_NAME);
1772 TextureManager::MaskingDataPointer maskInfo[3] = {nullptr, nullptr, nullptr};
1773 for(int i = 0; i < 3; i++)
1775 maskInfo[i].reset(new TextureManager::MaskingData());
1776 maskInfo[i]->mAlphaMaskUrl = maskname;
1777 maskInfo[i]->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1778 maskInfo[i]->mCropToMask = true;
1779 maskInfo[i]->mPreappliedMasking = false; // To make GPU masking
1780 maskInfo[i]->mContentScaleFactor = 1.0f;
1782 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1783 Dali::ImageDimensions atlasRectSize(0, 0);
1784 bool synchronousLoading(false);
1785 bool atlasingStatus(false);
1786 bool loadingStatus(false);
1787 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1788 ImageAtlasManagerPtr atlasManager = nullptr;
1789 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1791 // Request image 1, 2, 3 with GPU masking
1792 textureManager.LoadTexture(
1795 FittingMode::SCALE_TO_FILL,
1796 SamplingMode::BOX_THEN_LINEAR,
1805 atlasUploadObserver,
1808 TextureManager::ReloadPolicy::CACHED,
1811 textureManager.LoadTexture(
1814 FittingMode::SCALE_TO_FILL,
1815 SamplingMode::BOX_THEN_LINEAR,
1824 atlasUploadObserver,
1827 TextureManager::ReloadPolicy::CACHED,
1830 textureManager.LoadTexture(
1833 FittingMode::SCALE_TO_FILL,
1834 SamplingMode::BOX_THEN_LINEAR,
1843 atlasUploadObserver,
1846 TextureManager::ReloadPolicy::CACHED,
1849 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1850 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1851 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1852 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1853 DALI_TEST_EQUALS(observer3->mLoaded, false, TEST_LOCATION);
1854 DALI_TEST_EQUALS(observer3->mObserverCalled, false, TEST_LOCATION);
1855 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1856 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1858 // Check we use cached mask image
1859 DALI_TEST_CHECK(maskInfo[0]->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID);
1860 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[1]->mAlphaMaskId, TEST_LOCATION);
1861 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[2]->mAlphaMaskId, TEST_LOCATION);
1863 // Connect observer1 custom function
1866 TextureManager* textureManagerPtr{nullptr};
1867 TextureManager::TextureId removeTextureId{TextureManager::INVALID_TEXTURE_ID};
1868 TestObserver* removeTextureObserver{nullptr};
1871 data1.textureManagerPtr = &textureManager;
1872 data1.removeTextureId = textureId3;
1873 data1.removeTextureObserver = observer3;
1875 observer1.mData = &data1;
1876 observer1.ConnectFunction(
1878 DALI_TEST_CHECK(data);
1879 CustomData1 data1 = *(CustomData1*)data;
1881 DALI_TEST_CHECK(data1.textureManagerPtr);
1882 DALI_TEST_CHECK(data1.removeTextureId != TextureManager::INVALID_TEXTURE_ID);
1883 DALI_TEST_CHECK(data1.removeTextureObserver);
1885 // Remove textureId3.
1886 data1.textureManagerPtr->RequestRemove(data1.removeTextureId, data1.removeTextureObserver);
1888 // Destroy observer3
1889 delete data1.removeTextureObserver;
1892 // Connect observer2 custom function
1895 TextureManager* textureManagerPtr{nullptr};
1896 std::string addTextureUrl{};
1897 TextureManager::TextureId* addTextureIdPtr{nullptr};
1898 TestObserver* addTextureObserver{nullptr};
1901 data2.textureManagerPtr = &textureManager;
1902 data2.addTextureUrl = filename4;
1903 data2.addTextureIdPtr = &textureId4;
1904 data2.addTextureObserver = &observer4;
1906 observer2.mData = &data2;
1907 observer2.ConnectFunction(
1909 DALI_TEST_CHECK(data);
1910 CustomData2 data2 = *(CustomData2*)data;
1912 DALI_TEST_CHECK(data2.textureManagerPtr);
1913 DALI_TEST_CHECK(!data2.addTextureUrl.empty());
1914 DALI_TEST_CHECK(data2.addTextureIdPtr);
1915 DALI_TEST_CHECK(data2.addTextureObserver);
1917 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1920 (*data2.addTextureIdPtr) = data2.textureManagerPtr->RequestLoad(
1921 data2.addTextureUrl,
1923 FittingMode::SCALE_TO_FILL,
1924 SamplingMode::BOX_THEN_LINEAR,
1925 data2.addTextureObserver,
1927 TextureManager::ReloadPolicy::CACHED,
1931 // Connect observer3 custom function
1934 TestObserver* self{nullptr};
1935 bool* observerLoadedPtr{nullptr};
1936 bool* observerCalleddPtr{nullptr};
1939 bool observer3Loaded = false;
1940 bool observer3Called = false;
1941 data3.self = observer3;
1942 data3.observerLoadedPtr = &observer3Loaded;
1943 data3.observerCalleddPtr = &observer3Called;
1945 observer3->mData = &data3;
1946 observer3->ConnectFunction(
1948 DALI_TEST_CHECK(data);
1949 CustomData3 data3 = *(CustomData3*)data;
1951 DALI_TEST_CHECK(data3.self);
1952 DALI_TEST_CHECK(data3.observerLoadedPtr);
1953 DALI_TEST_CHECK(data3.observerCalleddPtr);
1955 *data3.observerLoadedPtr = data3.self->mLoaded;
1956 *data3.observerCalleddPtr = data3.self->mObserverCalled;
1959 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));
1961 // CAPTION : HARD-CODING.
1963 // Complete async load 1, 2, 3.
1964 std::vector<Devel::PixelBuffer> pixelBuffers;
1966 pixelBuffers.clear();
1967 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1968 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
1969 pixelBuffers.clear();
1970 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1971 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1972 pixelBuffers.clear();
1973 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1974 textureManager.AsyncLoadComplete(textureId3, pixelBuffers);
1976 // Ensure textureId3 remove request processed.
1978 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1979 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1980 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1981 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1982 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
1983 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
1984 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1985 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1987 // Complete mask load.
1988 pixelBuffers.clear();
1989 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::L8));
1990 textureManager.AsyncLoadComplete(maskInfo[0]->mAlphaMaskId, pixelBuffers);
1992 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));
1994 // Check observer 1 and 2 called, but 3 and 4 not called.
1995 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1996 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1997 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1998 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1999 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
2000 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
2001 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
2002 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
2005 DALI_TEST_CHECK(textureId4 != TextureManager::INVALID_TEXTURE_ID);
2008 pixelBuffers.clear();
2009 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2010 textureManager.AsyncLoadComplete(textureId4, pixelBuffers);
2012 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2013 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2014 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
2015 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
2016 DALI_TEST_EQUALS(observer3Loaded, false, TEST_LOCATION);
2017 DALI_TEST_EQUALS(observer3Called, false, TEST_LOCATION);
2018 DALI_TEST_EQUALS(observer4.mLoaded, true, TEST_LOCATION);
2019 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
2025 int UtcTextureManagerDestroyObserverDuringObserve(void)
2027 ToolkitTestApplication application;
2028 tet_infoline("UtcTextureManagerDestroyObserverDuringObserve");
2029 tet_infoline("Request 3 different image.");
2030 tet_infoline("Complete textureId1. After observer1 loaded done,");
2031 tet_infoline(" - Remove and destroy observer2");
2032 tet_infoline(" - Re-generate observer2 which has same address pointer with before.");
2033 tet_infoline(" - Remove and Reqeust third file by observer3");
2034 tet_infoline("Complete textureId2. and check old observer2 not emmited, and newly observer2 works.");
2035 tet_infoline("Complete textureId3. and check observer3 comes");
2037 TextureManager textureManager; // Create new texture manager
2039 TestObserverWithCustomFunction observer1;
2040 TestObserverWithCustomFunction* observer2 = new TestObserverWithCustomFunction(); // Deleted in observer1 loaded signal.
2041 TestObserver observer3;
2043 std::string filename1(TEST_IMAGE_FILE_NAME);
2044 std::string filename2(TEST_IMAGE_2_FILE_NAME);
2045 std::string filename3(TEST_IMAGE_3_FILE_NAME);
2046 std::string filename4(TEST_IMAGE_4_FILE_NAME);
2048 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
2049 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
2050 auto textureId3(TextureManager::INVALID_TEXTURE_ID);
2051 auto textureId4(TextureManager::INVALID_TEXTURE_ID);
2053 // Dummy reference value
2054 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
2056 // Request image 1, 2, 3.
2057 textureId1 = textureManager.RequestLoad(
2060 FittingMode::SCALE_TO_FILL,
2061 SamplingMode::BOX_THEN_LINEAR,
2064 TextureManager::ReloadPolicy::CACHED,
2067 textureId2 = textureManager.RequestLoad(
2070 FittingMode::SCALE_TO_FILL,
2071 SamplingMode::BOX_THEN_LINEAR,
2074 TextureManager::ReloadPolicy::CACHED,
2077 textureId3 = textureManager.RequestLoad(
2080 FittingMode::SCALE_TO_FILL,
2081 SamplingMode::BOX_THEN_LINEAR,
2084 TextureManager::ReloadPolicy::CACHED,
2089 TextureManager* textureManagerPtr{nullptr};
2090 TextureManager::TextureId removeTextureId{TextureManager::INVALID_TEXTURE_ID};
2091 TestObserverWithCustomFunction** removeTextureObserver{nullptr};
2092 std::string resendFilename{};
2093 TextureManager::TextureId resendTextureId{TextureManager::INVALID_TEXTURE_ID};
2094 TestObserver* resendTextureObserver{nullptr};
2095 std::string newlyFilename{};
2096 TextureManager::TextureId* newlyTextureIdPtr{nullptr};
2100 TextureManager* textureManagerPtr{nullptr};
2101 TestObserver* self{nullptr};
2102 bool* observerLoadedPtr{nullptr};
2103 bool* observerCalledPtr{nullptr};
2106 bool observer2Loaded = false;
2107 bool observer2Called = false;
2108 bool newObserver2Loaded = false;
2109 bool newObserver2Called = false;
2110 CustomData2 newData2; // Used on observer1 function
2112 // Connect observer1 custom function
2114 data1.textureManagerPtr = &textureManager;
2115 data1.removeTextureId = textureId2;
2116 data1.removeTextureObserver = &observer2;
2117 data1.resendFilename = filename3;
2118 data1.resendTextureId = textureId3;
2119 data1.resendTextureObserver = &observer3;
2120 data1.newlyFilename = filename2; // Same as observer2 filename
2121 data1.newlyTextureIdPtr = &textureId4;
2123 observer1.mData = &data1;
2124 observer1.ConnectFunction(
2126 DALI_TEST_CHECK(data);
2127 CustomData1 data1 = *(CustomData1*)data;
2129 DALI_TEST_CHECK(data1.textureManagerPtr);
2130 DALI_TEST_CHECK(data1.removeTextureId != TextureManager::INVALID_TEXTURE_ID);
2131 DALI_TEST_CHECK(data1.removeTextureObserver);
2132 DALI_TEST_CHECK(*data1.removeTextureObserver);
2133 DALI_TEST_CHECK(!data1.resendFilename.empty());
2134 DALI_TEST_CHECK(data1.resendTextureId != TextureManager::INVALID_TEXTURE_ID);
2135 DALI_TEST_CHECK(data1.resendTextureObserver);
2136 DALI_TEST_CHECK(!data1.newlyFilename.empty());
2137 DALI_TEST_CHECK(data1.newlyTextureIdPtr);
2138 DALI_TEST_CHECK(*data1.newlyTextureIdPtr == TextureManager::INVALID_TEXTURE_ID);
2140 // Remove textureId2.
2141 data1.textureManagerPtr->RequestRemove(data1.removeTextureId, *data1.removeTextureObserver);
2143 auto removedObserver = *data1.removeTextureObserver;
2145 // Destroy observer2.
2146 delete removedObserver;
2148 // Create new observer. Make we use same pointer if we can.
2149 uint32_t maxTryCount = 100u;
2150 uint32_t tryCount = 0u;
2152 while(tryCount < maxTryCount)
2154 *data1.removeTextureObserver = new TestObserverWithCustomFunction();
2155 if(removedObserver == *data1.removeTextureObserver) break;
2157 delete *data1.removeTextureObserver;
2160 tet_printf("TryCount[%u] / Old observer2 : %p, newly observer2 : %p\n", tryCount, removedObserver, *data1.removeTextureObserver);
2162 // Connect new observer2 custom function
2163 newData2.textureManagerPtr = &textureManager;
2164 newData2.self = (*data1.removeTextureObserver);
2165 newData2.observerLoadedPtr = &newObserver2Loaded;
2166 newData2.observerCalledPtr = &newObserver2Called;
2168 (*data1.removeTextureObserver)->mData = &newData2;
2169 (*data1.removeTextureObserver)->ConnectFunction([](void* data) {
2170 DALI_TEST_CHECK(data);
2171 CustomData2 data2 = *(CustomData2*)data;
2173 tet_printf("New created observer running\n");
2175 DALI_TEST_CHECK(data2.self);
2176 DALI_TEST_CHECK(data2.observerLoadedPtr);
2177 DALI_TEST_CHECK(data2.observerCalledPtr);
2179 *data2.observerLoadedPtr = data2.self->mLoaded;
2180 *data2.observerCalledPtr = data2.self->mObserverCalled;
2183 // Dummy reference value
2184 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
2186 // Resend textureId3
2187 data1.textureManagerPtr->RequestRemove(data1.resendTextureId, data1.resendTextureObserver);
2189 TextureManager::TextureId tempId;
2190 tempId = data1.textureManagerPtr->RequestLoad(
2191 data1.resendFilename,
2193 FittingMode::SCALE_TO_FILL,
2194 SamplingMode::BOX_THEN_LINEAR,
2195 data1.resendTextureObserver,
2197 TextureManager::ReloadPolicy::CACHED,
2200 DALI_TEST_CHECK(tempId == data1.resendTextureId);
2204 tempId = data1.textureManagerPtr->RequestLoad(
2205 data1.newlyFilename,
2207 FittingMode::SCALE_TO_FILL,
2208 SamplingMode::BOX_THEN_LINEAR,
2209 *data1.removeTextureObserver,
2211 TextureManager::ReloadPolicy::CACHED,
2214 DALI_TEST_CHECK(tempId != TextureManager::INVALID_TEXTURE_ID);
2215 *data1.newlyTextureIdPtr = tempId;
2218 // Connect observer2 custom function
2220 data2.textureManagerPtr = &textureManager;
2221 data2.self = observer2;
2222 data2.observerLoadedPtr = &observer2Loaded;
2223 data2.observerCalledPtr = &observer2Called;
2225 observer2->mData = &data2;
2226 observer2->ConnectFunction(
2228 DALI_TEST_CHECK(data);
2229 CustomData2 data2 = *(CustomData2*)data;
2231 tet_printf("Old created observer running. Something error occured!\n");
2233 DALI_TEST_CHECK(data2.self);
2234 DALI_TEST_CHECK(data2.observerLoadedPtr);
2235 DALI_TEST_CHECK(data2.observerCalledPtr);
2237 *data2.observerLoadedPtr = data2.self->mLoaded;
2238 *data2.observerCalledPtr = data2.self->mObserverCalled;
2241 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));
2243 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
2244 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
2245 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2246 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2247 DALI_TEST_EQUALS(newObserver2Loaded, false, TEST_LOCATION);
2248 DALI_TEST_EQUALS(newObserver2Called, false, TEST_LOCATION);
2249 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2250 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2252 DALI_TEST_CHECK(textureId4 == TextureManager::INVALID_TEXTURE_ID);
2254 // CAPTION : HARD-CODING.
2255 // Run codes without exception.
2258 tet_printf("Complete async load 1 first.\n");
2259 std::vector<Devel::PixelBuffer> pixelBuffers;
2261 pixelBuffers.clear();
2262 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2263 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
2265 tet_printf("Now observer2 deleted, observer3 resended, observer2 re-created.\n");
2266 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2267 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2268 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2269 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2270 DALI_TEST_EQUALS(newObserver2Loaded, false, TEST_LOCATION);
2271 DALI_TEST_EQUALS(newObserver2Called, false, TEST_LOCATION);
2272 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2273 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2275 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));
2277 DALI_TEST_CHECK(textureId4 == textureId2);
2279 // Remove processor excute.
2280 application.SendNotification();
2281 application.Render();
2283 tet_printf("Complete async load 2. Let we check old version observer2 ignored and newly observer2 loaded.\n");
2284 pixelBuffers.clear();
2285 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2286 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
2288 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2289 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2290 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2291 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2292 DALI_TEST_EQUALS(newObserver2Loaded, true, TEST_LOCATION);
2293 DALI_TEST_EQUALS(newObserver2Called, true, TEST_LOCATION);
2294 // We don't check observer3 not loaded case because SendNotification can process AsyncTask.
2295 //DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
2296 //DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
2298 tet_printf("Complete async load 3.\n");
2299 pixelBuffers.clear();
2300 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
2301 textureManager.AsyncLoadComplete(textureId3, pixelBuffers);
2303 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
2304 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
2305 DALI_TEST_EQUALS(observer2Loaded, false, TEST_LOCATION);
2306 DALI_TEST_EQUALS(observer2Called, false, TEST_LOCATION);
2307 DALI_TEST_EQUALS(newObserver2Loaded, true, TEST_LOCATION);
2308 DALI_TEST_EQUALS(newObserver2Called, true, TEST_LOCATION);
2309 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
2310 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
2314 DALI_TEST_CHECK(false);