2 * Copyright (c) 2022 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/devel-api/adaptor-framework/pixel-buffer.h>
33 #include <test-encoded-image-buffer.h>
35 #if defined(ELDBUS_ENABLED)
36 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
39 using namespace Dali::Toolkit::Internal;
41 void utc_dali_toolkit_texture_manager_startup(void)
43 setenv("LOG_TEXTURE_MANAGER", "3", 1);
44 test_return_value = TET_UNDEF;
45 #if defined(ELDBUS_ENABLED)
46 DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
50 void utc_dali_toolkit_texture_manager_cleanup(void)
52 test_return_value = TET_PASS;
57 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
58 const char* TEST_MASK_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
60 class TestObserver : public Dali::Toolkit::TextureUploadObserver
63 enum class CompleteType
72 : mCompleteType(CompleteType::NOT_COMPLETED),
74 mObserverCalled(false),
79 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
81 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
83 mCompleteType = CompleteType::UPLOAD_COMPLETE;
87 mCompleteType = CompleteType::LOAD_COMPLETE;
89 mLoaded = loadSuccess;
90 mObserverCalled = true;
91 mTextureSet = textureInformation.textureSet;
94 CompleteType mCompleteType;
97 TextureSet mTextureSet;
100 class TestObserverRemoveAndGenerateUrl : public TestObserver
103 TestObserverRemoveAndGenerateUrl(TextureManager* textureManagerPtr)
105 mTextureManagerPtr(textureManagerPtr)
109 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
111 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
113 mCompleteType = CompleteType::UPLOAD_COMPLETE;
117 mCompleteType = CompleteType::LOAD_COMPLETE;
119 mLoaded = loadSuccess;
120 mObserverCalled = true;
121 mTextureSet = textureInformation.textureSet;
123 // Remove during LoadComplete
124 mTextureManagerPtr->Remove(textureInformation.textureId, nullptr);
126 // ...And generate string which using texture id.
127 mGeneratedExternalUrl = mTextureManagerPtr->AddExternalTexture(mTextureSet);
131 std::string mGeneratedExternalUrl;
134 TextureManager* mTextureManagerPtr; // Keep the pointer of texture manager.
139 int UtcTextureManagerRequestLoad(void)
141 ToolkitTestApplication application;
143 TextureManager textureManager; // Create new texture manager
145 TestObserver observer;
146 std::string filename("image.png");
147 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
148 TextureManager::TextureId textureId = textureManager.RequestLoad(
151 FittingMode::SCALE_TO_FILL,
152 SamplingMode::BOX_THEN_LINEAR,
153 TextureManager::UseAtlas::NO_ATLAS,
156 TextureManager::ReloadPolicy::CACHED,
159 VisualUrl url = textureManager.GetVisualUrl(textureId);
161 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
166 int UtcTextureManagerGenerateHash(void)
168 ToolkitTestApplication application;
170 TextureManager textureManager; // Create new texture manager
172 TestObserver observer;
173 std::string filename("image.png");
174 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
175 TextureManager::TextureId textureId = textureManager.RequestLoad(
178 FittingMode::SCALE_TO_FILL,
179 SamplingMode::BOX_THEN_LINEAR,
180 TextureManager::UseAtlas::NO_ATLAS,
183 TextureManager::ReloadPolicy::CACHED,
186 VisualUrl url = textureManager.GetVisualUrl(textureId);
188 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
193 int UtcTextureManagerEncodedImageBuffer(void)
195 ToolkitTestApplication application;
196 tet_infoline("UtcTextureManagerEncodedImageBuffer");
198 auto visualFactory = Toolkit::VisualFactory::Get();
199 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
201 // Get encoded raw-buffer image and generate url
202 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
203 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
205 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
206 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
207 std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage
209 // Check if same EncodedImageBuffer get same url
210 DALI_TEST_CHECK(url1 == url2);
211 // Reduce reference count
212 textureManager.RemoveEncodedImageBuffer(url1);
213 // Check whethere url1 still valid
214 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
216 url2 = textureManager.AddEncodedImageBuffer(buffer2);
217 // Check if difference EncodedImageBuffer get difference url
218 DALI_TEST_CHECK(url1 != url2);
220 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
222 TestObserver observer1;
223 textureManager.RequestLoad(
226 FittingMode::SCALE_TO_FILL,
227 SamplingMode::BOX_THEN_LINEAR,
228 TextureManager::UseAtlas::NO_ATLAS,
230 true, ///< orientationCorrection
231 TextureManager::ReloadPolicy::CACHED,
234 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
235 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
237 application.SendNotification();
238 application.Render();
240 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
242 application.SendNotification();
243 application.Render();
245 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
246 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
247 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
249 TestObserver observer2;
251 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
254 FittingMode::SCALE_TO_FILL,
255 SamplingMode::BOX_THEN_LINEAR,
256 true, ///< synchronousLoading
258 true, ///< orientationCorrection
261 DALI_TEST_CHECK(pixelBuffer);
262 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
263 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
266 pixelBuffer = textureManager.LoadPixelBuffer(
269 FittingMode::SCALE_TO_FILL,
270 SamplingMode::BOX_THEN_LINEAR,
271 false, ///< synchronousLoading
273 true, ///< orientationCorrection
276 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
277 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
279 application.SendNotification();
280 application.Render();
282 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
284 application.SendNotification();
285 application.Render();
287 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
288 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
289 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
291 textureManager.RemoveEncodedImageBuffer(url1);
292 textureManager.RemoveEncodedImageBuffer(url2);
294 // Now url1 and url2 is invalid type. mLoaded will return false
296 TestObserver observer3;
297 textureManager.RequestLoad(
300 FittingMode::SCALE_TO_FILL,
301 SamplingMode::BOX_THEN_LINEAR,
302 TextureManager::UseAtlas::NO_ATLAS,
304 true, ///< orientationCorrection
305 TextureManager::ReloadPolicy::CACHED,
308 // Load will be success because url1 is cached
309 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
310 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
311 DALI_TEST_EQUALS(observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
313 TestObserver observer4;
314 textureManager.RequestLoad(
317 FittingMode::SCALE_TO_FILL,
318 SamplingMode::BOX_THEN_LINEAR,
319 TextureManager::UseAtlas::NO_ATLAS,
321 true, ///< orientationCorrection
322 TextureManager::ReloadPolicy::FORCED,
325 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
326 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
327 application.SendNotification();
328 application.Render();
330 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
332 application.SendNotification();
333 application.Render();
335 // Load will be failed becuase reloadpolicy is forced
336 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
337 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
338 DALI_TEST_EQUALS(observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
340 TestObserver observer5;
341 pixelBuffer = textureManager.LoadPixelBuffer(
344 FittingMode::SCALE_TO_FILL,
345 SamplingMode::BOX_THEN_LINEAR,
346 true, ///< synchronousLoading
348 true, ///< orientationCorrection
351 // Load will be faild because synchronousLoading doesn't use cached texture
352 DALI_TEST_CHECK(!pixelBuffer);
353 DALI_TEST_EQUALS(observer5.mLoaded, false, TEST_LOCATION);
354 DALI_TEST_EQUALS(observer5.mObserverCalled, false, TEST_LOCATION);
356 TestObserver observer6;
357 pixelBuffer = textureManager.LoadPixelBuffer(
360 FittingMode::SCALE_TO_FILL,
361 SamplingMode::BOX_THEN_LINEAR,
362 false, ///< synchronousLoading
364 true, ///< orientationCorrection
367 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
368 DALI_TEST_EQUALS(observer6.mObserverCalled, false, TEST_LOCATION);
370 application.SendNotification();
371 application.Render();
373 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
375 application.SendNotification();
376 application.Render();
378 // Load will be failed because url3 is invalid URL
379 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
380 DALI_TEST_EQUALS(observer6.mObserverCalled, true, TEST_LOCATION);
381 DALI_TEST_EQUALS(observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
386 int UtcTextureManagerEncodedImageBufferReferenceCount(void)
388 ToolkitTestApplication application;
389 tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well");
391 auto visualFactory = Toolkit::VisualFactory::Get();
392 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
394 // Get encoded raw-buffer image and generate url
395 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
396 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
398 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
399 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
401 // Check if same EncodedImageBuffer get same url
402 DALI_TEST_CHECK(url1 == url2);
404 // Reduce reference count
405 textureManager.RemoveEncodedImageBuffer(url1);
406 // Check whethere url1 still valid
407 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
409 // Reduce reference count
410 textureManager.RemoveEncodedImageBuffer(url1);
411 // Check whethere url1 is not valid anymore
412 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
414 // UseExternalTexture doesn't create new buffer.
415 // So, reference count is still zero.
416 textureManager.UseExternalResource(url1);
417 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
419 url1 = textureManager.AddEncodedImageBuffer(buffer1);
421 url2 = textureManager.AddEncodedImageBuffer(buffer2);
422 // Check if difference EncodedImageBuffer get difference url
423 DALI_TEST_CHECK(url1 != url2);
425 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
427 // url1 load image by cache
428 TestObserver observer1;
429 textureManager.RequestLoad(
432 FittingMode::SCALE_TO_FILL,
433 SamplingMode::BOX_THEN_LINEAR,
434 TextureManager::UseAtlas::NO_ATLAS,
436 true, ///< orientationCorrection
437 TextureManager::ReloadPolicy::CACHED,
440 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
441 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
443 application.SendNotification();
444 application.Render();
446 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
448 application.SendNotification();
449 application.Render();
451 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
452 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
453 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
455 // LoadPixelBuffer doen't use cache. url2 will not be cached
456 TestObserver observer2;
457 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
460 FittingMode::SCALE_TO_FILL,
461 SamplingMode::BOX_THEN_LINEAR,
462 false, ///< synchronousLoading
464 true, ///< orientationCorrection
467 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
468 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
470 application.SendNotification();
471 application.Render();
473 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
475 application.SendNotification();
476 application.Render();
478 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
479 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
480 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
482 // Decrease each url's reference count.
483 textureManager.RemoveEncodedImageBuffer(url1);
484 textureManager.RemoveEncodedImageBuffer(url2);
486 // url1 buffer is still have 1 reference count because it is cached.
487 // But url2 not valid because it is not cached.
488 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
489 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
491 // Check url1 buffer have 1 reference count because it is cached.
492 textureManager.RemoveEncodedImageBuffer(url1);
493 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
498 int UtcTextureManagerCachingForDifferentLoadingType(void)
500 ToolkitTestApplication application;
501 tet_infoline("UtcTextureManagerCachingForDifferentLoadingType");
503 TextureManager textureManager; // Create new texture manager
505 TestObserver observer1;
506 std::string filename(TEST_IMAGE_FILE_NAME);
507 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
508 textureManager.RequestLoad(
511 FittingMode::SCALE_TO_FILL,
512 SamplingMode::BOX_THEN_LINEAR,
513 TextureManager::UseAtlas::NO_ATLAS,
516 TextureManager::ReloadPolicy::CACHED,
519 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
520 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
522 application.SendNotification();
523 application.Render();
525 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
527 application.SendNotification();
528 application.Render();
530 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
531 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
532 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
534 TestObserver observer2;
535 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
538 FittingMode::SCALE_TO_FILL,
539 SamplingMode::BOX_THEN_LINEAR,
545 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
546 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
548 application.SendNotification();
549 application.Render();
551 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
553 application.SendNotification();
554 application.Render();
556 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
557 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
558 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
563 int UtcTextureManagerUseInvalidMask(void)
565 ToolkitTestApplication application;
566 tet_infoline("UtcTextureManagerUseInvalidMask");
568 TextureManager textureManager; // Create new texture manager
570 TestObserver observer;
571 std::string filename(TEST_IMAGE_FILE_NAME);
572 std::string maskname("");
573 TextureManager::MaskingDataPointer maskInfo = nullptr;
574 maskInfo.reset(new TextureManager::MaskingData());
575 maskInfo->mAlphaMaskUrl = maskname;
576 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
577 maskInfo->mCropToMask = true;
578 maskInfo->mContentScaleFactor = 1.0f;
580 auto textureId(TextureManager::INVALID_TEXTURE_ID);
581 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
582 Dali::ImageDimensions atlasRectSize(0, 0);
583 bool synchronousLoading(false);
584 bool atlasingStatus(false);
585 bool loadingStatus(false);
586 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
587 ImageAtlasManagerPtr atlasManager = nullptr;
588 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
590 textureManager.LoadTexture(
593 FittingMode::SCALE_TO_FILL,
594 SamplingMode::BOX_THEN_LINEAR,
608 TextureManager::ReloadPolicy::CACHED,
611 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
612 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
614 application.SendNotification();
615 application.Render();
617 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
619 application.SendNotification();
620 application.Render();
622 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
623 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
624 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
629 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
631 ToolkitTestApplication application;
632 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
633 tet_infoline("Try to check PostLoad works well");
635 TextureManager textureManager; // Create new texture manager
637 TestObserver observer;
638 std::string filename(TEST_IMAGE_FILE_NAME);
639 std::string maskname("invalid.png");
640 TextureManager::MaskingDataPointer maskInfo = nullptr;
641 maskInfo.reset(new TextureManager::MaskingData());
642 maskInfo->mAlphaMaskUrl = maskname;
643 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
644 maskInfo->mCropToMask = true;
645 maskInfo->mContentScaleFactor = 1.0f;
647 auto textureId(TextureManager::INVALID_TEXTURE_ID);
648 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
649 Dali::ImageDimensions atlasRectSize(0, 0);
650 bool synchronousLoading(false);
651 bool atlasingStatus(false);
652 bool loadingStatus(false);
653 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
654 ImageAtlasManagerPtr atlasManager = nullptr;
655 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
657 textureManager.LoadTexture(
660 FittingMode::SCALE_TO_FILL,
661 SamplingMode::BOX_THEN_LINEAR,
675 TextureManager::ReloadPolicy::CACHED,
678 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
679 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
681 application.SendNotification();
682 application.Render();
684 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
686 application.SendNotification();
687 application.Render();
689 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
690 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
691 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
696 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
698 ToolkitTestApplication application;
699 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
700 tet_infoline("Try to check CheckForWaitingTexture called");
702 TextureManager textureManager; // Create new texture manager
704 TestObserver observer;
705 std::string filename(TEST_IMAGE_FILE_NAME);
706 std::string maskname("invalid.png");
707 TextureManager::MaskingDataPointer maskInfo = nullptr;
708 maskInfo.reset(new TextureManager::MaskingData());
709 maskInfo->mAlphaMaskUrl = maskname;
710 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
711 maskInfo->mCropToMask = true;
712 maskInfo->mContentScaleFactor = 1.0f;
714 auto textureId(TextureManager::INVALID_TEXTURE_ID);
715 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
716 Dali::ImageDimensions atlasRectSize(0, 0);
717 bool synchronousLoading(false);
718 bool atlasingStatus(false);
719 bool loadingStatus(false);
720 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
721 ImageAtlasManagerPtr atlasManager = nullptr;
722 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
724 textureManager.LoadTexture(
727 FittingMode::SCALE_TO_FILL,
728 SamplingMode::BOX_THEN_LINEAR,
742 TextureManager::ReloadPolicy::CACHED,
745 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
746 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
748 application.SendNotification();
749 application.Render();
751 // CAPTION : HARD-CODING for coverage. If you are a good boy, Do not follow this code.
753 Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
756 FittingMode::SCALE_TO_FILL,
757 SamplingMode::BOX_THEN_LINEAR,
758 true, ///< synchronousLoading
760 true, ///< orientationCorrection
763 textureManager.AsyncLoadComplete(textureId, pixelBuffer);
764 textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, Dali::Devel::PixelBuffer());
765 textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
766 textureManager.Remove(textureId, &observer);
769 application.SendNotification();
770 application.Render();
772 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
773 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
774 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
776 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
781 int UtcTextureManagerSynchronousLoadingFail(void)
783 ToolkitTestApplication application;
784 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
786 TextureManager textureManager; // Create new texture manager
788 std::string maskname("");
789 TextureManager::MaskingDataPointer maskInfo = nullptr;
790 maskInfo.reset(new TextureManager::MaskingData());
791 maskInfo->mAlphaMaskUrl = maskname;
792 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
793 maskInfo->mCropToMask = true;
794 maskInfo->mContentScaleFactor = 1.0f;
796 std::string filename("dummy");
797 auto textureId(TextureManager::INVALID_TEXTURE_ID);
798 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
799 Dali::ImageDimensions atlasRectSize(0, 0);
800 bool atlasingStatus(false);
801 bool loadingStatus(false);
802 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
803 ImageAtlasManagerPtr atlasManager = nullptr;
804 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
806 // load image synchronously.
807 TestObserver observer;
808 TextureSet textureSet = textureManager.LoadTexture(
811 FittingMode::SCALE_TO_FILL,
812 SamplingMode::BOX_THEN_LINEAR,
814 true, // synchronous loading.
826 TextureManager::ReloadPolicy::CACHED,
829 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
830 DALI_TEST_CHECK(!textureSet); // texture loading fail.
831 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
836 int UtcTextureManagerCachingSynchronousLoading(void)
838 ToolkitTestApplication application;
839 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
841 TextureManager textureManager; // Create new texture manager
843 std::string filename(TEST_IMAGE_FILE_NAME);
845 std::string maskname("");
846 TextureManager::MaskingDataPointer maskInfo = nullptr;
847 maskInfo.reset(new TextureManager::MaskingData());
848 maskInfo->mAlphaMaskUrl = maskname;
849 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
850 maskInfo->mCropToMask = true;
851 maskInfo->mContentScaleFactor = 1.0f;
853 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
854 Dali::ImageDimensions atlasRectSize(0, 0);
855 bool atlasingStatus(false);
856 bool loadingStatus(false);
857 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
858 ImageAtlasManagerPtr atlasManager = nullptr;
859 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
861 // load image synchronously.
862 TestObserver observer;
863 auto textureId(TextureManager::INVALID_TEXTURE_ID);
864 TextureSet textureSet = textureManager.LoadTexture(
867 FittingMode::SCALE_TO_FILL,
868 SamplingMode::BOX_THEN_LINEAR,
870 true, // synchronous loading.
882 TextureManager::ReloadPolicy::CACHED,
885 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
886 DALI_TEST_CHECK(textureSet); // texture is loaded.
888 // observer isn't called in synchronous loading.
889 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
890 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
892 // load same image asynchronously.
893 TestObserver asyncObserver;
894 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
895 loadingStatus = false;
896 TextureSet asyncTextureSet = textureManager.LoadTexture(
899 FittingMode::SCALE_TO_FILL,
900 SamplingMode::BOX_THEN_LINEAR,
902 false, // asynchronous loading.
914 TextureManager::ReloadPolicy::CACHED,
917 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
918 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
919 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
921 // observer is directly called because textureSet is retrieved by cache.
922 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
923 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
928 int UtcTextureManagerAsyncSyncAsync(void)
930 ToolkitTestApplication application;
931 tet_infoline("UtcTextureManagerAsyncSyncAsync");
933 TextureManager textureManager; // Create new texture manager
935 std::string filename(TEST_IMAGE_FILE_NAME);
937 std::string maskname("");
938 TextureManager::MaskingDataPointer maskInfo = nullptr;
939 maskInfo.reset(new TextureManager::MaskingData());
940 maskInfo->mAlphaMaskUrl = maskname;
941 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
942 maskInfo->mCropToMask = true;
943 maskInfo->mContentScaleFactor = 1.0f;
945 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
946 Dali::ImageDimensions atlasRectSize(0, 0);
947 bool atlasingStatus(false);
948 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
949 ImageAtlasManagerPtr atlasManager = nullptr;
950 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
952 // load image asynchronously.
953 TestObserver asyncObserver1;
954 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
955 bool asyncLoadingStatus1 = false;
956 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
959 FittingMode::SCALE_TO_FILL,
960 SamplingMode::BOX_THEN_LINEAR,
962 false, // asynchronous loading.
974 TextureManager::ReloadPolicy::CACHED,
977 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
978 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
980 // observer is still not called.
981 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
982 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
984 // load same image synchronously just after asynchronous loading.
985 TestObserver syncObserver;
986 auto textureId(TextureManager::INVALID_TEXTURE_ID);
987 bool syncLoadingStatus = false;
988 TextureSet syncTextureSet = textureManager.LoadTexture(
991 FittingMode::SCALE_TO_FILL,
992 SamplingMode::BOX_THEN_LINEAR,
994 true, // synchronous loading.
1003 atlasUploadObserver,
1006 TextureManager::ReloadPolicy::CACHED,
1009 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
1010 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
1011 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
1013 // syncObserver isn't called in synchronous loading.
1014 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1015 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1017 // asyncObserver1 is still not called too.
1018 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1019 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1021 // load image asynchronously.
1022 TestObserver asyncObserver2;
1023 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1024 bool asyncLoadingStatus2 = false;
1025 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
1028 FittingMode::SCALE_TO_FILL,
1029 SamplingMode::BOX_THEN_LINEAR,
1031 false, // asynchronous loading.
1036 asyncLoadingStatus2,
1040 atlasUploadObserver,
1043 TextureManager::ReloadPolicy::CACHED,
1046 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1047 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
1048 DALI_TEST_CHECK(asyncTextureSet2 == syncTextureSet); // check loaded two texture is same.
1050 // observer is called synchronously because the texture is cached.
1051 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1052 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1054 asyncObserver2.mLoaded = false;
1055 asyncObserver2.mObserverCalled = false;
1057 application.SendNotification();
1058 application.Render();
1060 // Requested asynchronous loading at first is finished now and async observer is called now.
1061 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1062 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1063 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1064 DALI_TEST_CHECK(asyncObserver1.mTextureSet == asyncTextureSet2); // check loaded two texture is same.
1066 // asyncObserver2 was already called so it isn't called here.
1067 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1068 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1073 int UtcTextureManagerQueueRemoveDuringObserve(void)
1075 ToolkitTestApplication application;
1076 tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1078 TextureManager textureManager; // Create new texture manager
1080 TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1082 std::string filename(TEST_IMAGE_FILE_NAME);
1083 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1085 TextureManager::TextureId textureId = textureManager.RequestLoad(
1088 FittingMode::SCALE_TO_FILL,
1089 SamplingMode::BOX_THEN_LINEAR,
1090 TextureManager::UseAtlas::NO_ATLAS,
1093 TextureManager::ReloadPolicy::CACHED,
1096 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1097 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1099 application.SendNotification();
1100 application.Render();
1102 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1104 application.SendNotification();
1105 application.Render();
1107 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1108 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1109 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1111 tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1113 DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1115 // Decrease external texture reference count who observer created
1116 textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1118 application.SendNotification();
1119 application.Render();
1124 int UtcTextureManagerRemoveDuringApplyMasking(void)
1126 ToolkitTestApplication application;
1127 tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1129 TextureManager textureManager; // Create new texture manager
1131 TestObserver observer1;
1132 TestObserver observer2;
1134 std::string filename(TEST_IMAGE_FILE_NAME);
1135 std::string maskname(TEST_MASK_FILE_NAME);
1136 TextureManager::MaskingDataPointer maskInfo = nullptr;
1137 maskInfo.reset(new TextureManager::MaskingData());
1138 maskInfo->mAlphaMaskUrl = maskname;
1139 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1140 maskInfo->mCropToMask = true;
1141 maskInfo->mContentScaleFactor = 1.0f;
1143 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1144 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1145 Dali::ImageDimensions atlasRectSize(0, 0);
1146 bool synchronousLoading(false);
1147 bool atlasingStatus(false);
1148 bool loadingStatus(false);
1149 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1150 ImageAtlasManagerPtr atlasManager = nullptr;
1151 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1153 textureManager.LoadTexture(
1156 FittingMode::SCALE_TO_FILL,
1157 SamplingMode::BOX_THEN_LINEAR,
1168 atlasUploadObserver,
1171 TextureManager::ReloadPolicy::CACHED,
1174 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1175 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1177 application.SendNotification();
1178 application.Render();
1180 // Load image and mask image.
1181 // Now, LoadState become MASK_APPLYING
1182 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1184 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1186 application.SendNotification();
1187 application.Render();
1189 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1190 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1192 // Remove current textureId1. and request new texture again.
1193 textureManager.Remove(textureId1, &observer1);
1194 auto textureId2 = textureManager.RequestLoad(
1197 FittingMode::SCALE_TO_FILL,
1198 SamplingMode::BOX_THEN_LINEAR,
1199 TextureManager::UseAtlas::NO_ATLAS,
1201 true, ///< orientationCorrection
1202 TextureManager::ReloadPolicy::CACHED,
1204 synchronousLoading);
1206 application.SendNotification();
1207 application.Render();
1209 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1210 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1211 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1212 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1214 tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1216 // ApplyMask event come back, and do nothing.
1217 // CAPTION : HARD-CODING.
1219 textureManager.AsyncLoadComplete(textureId1, Dali::Devel::PixelBuffer());
1220 textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
1223 application.SendNotification();
1224 application.Render();
1226 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1227 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1228 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1229 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1231 // CAPTION : HARD-CODING.
1233 textureManager.AsyncLoadComplete(textureId2, Dali::Devel::PixelBuffer());
1234 textureManager.Remove(textureId2, &observer2);
1237 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1238 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1239 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);