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 std::vector<Devel::PixelBuffer> pixelBuffers;
764 pixelBuffers.push_back(pixelBuffer);
765 textureManager.AsyncLoadComplete(textureId, pixelBuffers);
766 std::vector<Devel::PixelBuffer> maskBuffers;
767 textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
768 textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
769 textureManager.Remove(textureId, &observer);
772 application.SendNotification();
773 application.Render();
775 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
776 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
777 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
779 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
784 int UtcTextureManagerSynchronousLoadingFail(void)
786 ToolkitTestApplication application;
787 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
789 TextureManager textureManager; // Create new texture manager
791 std::string maskname("");
792 TextureManager::MaskingDataPointer maskInfo = nullptr;
793 maskInfo.reset(new TextureManager::MaskingData());
794 maskInfo->mAlphaMaskUrl = maskname;
795 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
796 maskInfo->mCropToMask = true;
797 maskInfo->mContentScaleFactor = 1.0f;
799 std::string filename("dummy");
800 auto textureId(TextureManager::INVALID_TEXTURE_ID);
801 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
802 Dali::ImageDimensions atlasRectSize(0, 0);
803 bool atlasingStatus(false);
804 bool loadingStatus(false);
805 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
806 ImageAtlasManagerPtr atlasManager = nullptr;
807 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
809 // load image synchronously.
810 TestObserver observer;
811 TextureSet textureSet = textureManager.LoadTexture(
814 FittingMode::SCALE_TO_FILL,
815 SamplingMode::BOX_THEN_LINEAR,
817 true, // synchronous loading.
829 TextureManager::ReloadPolicy::CACHED,
832 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
833 DALI_TEST_CHECK(!textureSet); // texture loading fail.
834 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
839 int UtcTextureManagerCachingSynchronousLoading(void)
841 ToolkitTestApplication application;
842 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
844 TextureManager textureManager; // Create new texture manager
846 std::string filename(TEST_IMAGE_FILE_NAME);
848 std::string maskname("");
849 TextureManager::MaskingDataPointer maskInfo = nullptr;
850 maskInfo.reset(new TextureManager::MaskingData());
851 maskInfo->mAlphaMaskUrl = maskname;
852 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
853 maskInfo->mCropToMask = true;
854 maskInfo->mContentScaleFactor = 1.0f;
856 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
857 Dali::ImageDimensions atlasRectSize(0, 0);
858 bool atlasingStatus(false);
859 bool loadingStatus(false);
860 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
861 ImageAtlasManagerPtr atlasManager = nullptr;
862 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
864 // load image synchronously.
865 TestObserver observer;
866 auto textureId(TextureManager::INVALID_TEXTURE_ID);
867 TextureSet textureSet = textureManager.LoadTexture(
870 FittingMode::SCALE_TO_FILL,
871 SamplingMode::BOX_THEN_LINEAR,
873 true, // synchronous loading.
885 TextureManager::ReloadPolicy::CACHED,
888 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
889 DALI_TEST_CHECK(textureSet); // texture is loaded.
891 // observer isn't called in synchronous loading.
892 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
893 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
895 // load same image asynchronously.
896 TestObserver asyncObserver;
897 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
898 loadingStatus = false;
899 TextureSet asyncTextureSet = textureManager.LoadTexture(
902 FittingMode::SCALE_TO_FILL,
903 SamplingMode::BOX_THEN_LINEAR,
905 false, // asynchronous loading.
917 TextureManager::ReloadPolicy::CACHED,
920 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
921 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
922 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
924 // observer is directly called because textureSet is retrieved by cache.
925 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
926 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
931 int UtcTextureManagerAsyncSyncAsync(void)
933 ToolkitTestApplication application;
934 tet_infoline("UtcTextureManagerAsyncSyncAsync");
936 TextureManager textureManager; // Create new texture manager
938 std::string filename(TEST_IMAGE_FILE_NAME);
940 std::string maskname("");
941 TextureManager::MaskingDataPointer maskInfo = nullptr;
942 maskInfo.reset(new TextureManager::MaskingData());
943 maskInfo->mAlphaMaskUrl = maskname;
944 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
945 maskInfo->mCropToMask = true;
946 maskInfo->mContentScaleFactor = 1.0f;
948 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
949 Dali::ImageDimensions atlasRectSize(0, 0);
950 bool atlasingStatus(false);
951 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
952 ImageAtlasManagerPtr atlasManager = nullptr;
953 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
955 // load image asynchronously.
956 TestObserver asyncObserver1;
957 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
958 bool asyncLoadingStatus1 = false;
959 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
962 FittingMode::SCALE_TO_FILL,
963 SamplingMode::BOX_THEN_LINEAR,
965 false, // asynchronous loading.
977 TextureManager::ReloadPolicy::CACHED,
980 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
981 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
983 // observer is still not called.
984 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
985 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
987 // load same image synchronously just after asynchronous loading.
988 TestObserver syncObserver;
989 auto textureId(TextureManager::INVALID_TEXTURE_ID);
990 bool syncLoadingStatus = false;
991 TextureSet syncTextureSet = textureManager.LoadTexture(
994 FittingMode::SCALE_TO_FILL,
995 SamplingMode::BOX_THEN_LINEAR,
997 true, // synchronous loading.
1006 atlasUploadObserver,
1009 TextureManager::ReloadPolicy::CACHED,
1012 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
1013 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
1014 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
1016 // syncObserver isn't called in synchronous loading.
1017 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1018 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1020 // asyncObserver1 is still not called too.
1021 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1022 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1024 // load image asynchronously.
1025 TestObserver asyncObserver2;
1026 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1027 bool asyncLoadingStatus2 = false;
1028 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
1031 FittingMode::SCALE_TO_FILL,
1032 SamplingMode::BOX_THEN_LINEAR,
1034 false, // asynchronous loading.
1039 asyncLoadingStatus2,
1043 atlasUploadObserver,
1046 TextureManager::ReloadPolicy::CACHED,
1049 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1050 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
1051 DALI_TEST_CHECK(asyncTextureSet2 == syncTextureSet); // check loaded two texture is same.
1053 // observer is called synchronously because the texture is cached.
1054 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1055 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1057 asyncObserver2.mLoaded = false;
1058 asyncObserver2.mObserverCalled = false;
1060 application.SendNotification();
1061 application.Render();
1063 // Requested asynchronous loading at first is finished now and async observer is called now.
1064 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1065 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1066 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1067 DALI_TEST_CHECK(asyncObserver1.mTextureSet == asyncTextureSet2); // check loaded two texture is same.
1069 // asyncObserver2 was already called so it isn't called here.
1070 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1071 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1076 int UtcTextureManagerQueueRemoveDuringObserve(void)
1078 ToolkitTestApplication application;
1079 tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1081 TextureManager textureManager; // Create new texture manager
1083 TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1085 std::string filename(TEST_IMAGE_FILE_NAME);
1086 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1088 TextureManager::TextureId textureId = textureManager.RequestLoad(
1091 FittingMode::SCALE_TO_FILL,
1092 SamplingMode::BOX_THEN_LINEAR,
1093 TextureManager::UseAtlas::NO_ATLAS,
1096 TextureManager::ReloadPolicy::CACHED,
1099 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1100 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1102 application.SendNotification();
1103 application.Render();
1105 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1107 application.SendNotification();
1108 application.Render();
1110 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1111 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1112 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1114 tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1116 DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1118 // Decrease external texture reference count who observer created
1119 textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1121 application.SendNotification();
1122 application.Render();
1127 int UtcTextureManagerRemoveDuringApplyMasking(void)
1129 ToolkitTestApplication application;
1130 tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1132 TextureManager textureManager; // Create new texture manager
1134 TestObserver observer1;
1135 TestObserver observer2;
1137 std::string filename(TEST_IMAGE_FILE_NAME);
1138 std::string maskname(TEST_MASK_FILE_NAME);
1139 TextureManager::MaskingDataPointer maskInfo = nullptr;
1140 maskInfo.reset(new TextureManager::MaskingData());
1141 maskInfo->mAlphaMaskUrl = maskname;
1142 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1143 maskInfo->mCropToMask = true;
1144 maskInfo->mContentScaleFactor = 1.0f;
1146 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1147 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1148 Dali::ImageDimensions atlasRectSize(0, 0);
1149 bool synchronousLoading(false);
1150 bool atlasingStatus(false);
1151 bool loadingStatus(false);
1152 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1153 ImageAtlasManagerPtr atlasManager = nullptr;
1154 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1156 textureManager.LoadTexture(
1159 FittingMode::SCALE_TO_FILL,
1160 SamplingMode::BOX_THEN_LINEAR,
1171 atlasUploadObserver,
1174 TextureManager::ReloadPolicy::CACHED,
1177 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1178 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1180 application.SendNotification();
1181 application.Render();
1183 // Load image and mask image.
1184 // Now, LoadState become MASK_APPLYING
1185 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1187 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1189 application.SendNotification();
1190 application.Render();
1192 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1193 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1195 // Remove current textureId1. and request new texture again.
1196 textureManager.Remove(textureId1, &observer1);
1197 auto textureId2 = textureManager.RequestLoad(
1200 FittingMode::SCALE_TO_FILL,
1201 SamplingMode::BOX_THEN_LINEAR,
1202 TextureManager::UseAtlas::NO_ATLAS,
1204 true, ///< orientationCorrection
1205 TextureManager::ReloadPolicy::CACHED,
1207 synchronousLoading);
1209 application.SendNotification();
1210 application.Render();
1212 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1213 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1214 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1215 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1217 tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1219 // ApplyMask event come back, and do nothing.
1220 // CAPTION : HARD-CODING.
1222 std::vector<Devel::PixelBuffer> pixelBuffers;
1223 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
1224 textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
1227 application.SendNotification();
1228 application.Render();
1230 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1231 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1232 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1233 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1235 // CAPTION : HARD-CODING.
1237 std::vector<Devel::PixelBuffer> pixelBuffers;
1238 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1239 textureManager.Remove(textureId2, &observer2);
1242 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1243 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1244 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);