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,
606 TextureManager::ReloadPolicy::CACHED,
609 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
610 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
612 application.SendNotification();
613 application.Render();
615 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
617 application.SendNotification();
618 application.Render();
620 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
621 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
622 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
627 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
629 ToolkitTestApplication application;
630 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
631 tet_infoline("Try to check PostLoad works well");
633 TextureManager textureManager; // Create new texture manager
635 TestObserver observer;
636 std::string filename(TEST_IMAGE_FILE_NAME);
637 std::string maskname("invalid.png");
638 TextureManager::MaskingDataPointer maskInfo = nullptr;
639 maskInfo.reset(new TextureManager::MaskingData());
640 maskInfo->mAlphaMaskUrl = maskname;
641 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
642 maskInfo->mCropToMask = true;
643 maskInfo->mContentScaleFactor = 1.0f;
645 auto textureId(TextureManager::INVALID_TEXTURE_ID);
646 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
647 Dali::ImageDimensions atlasRectSize(0, 0);
648 bool synchronousLoading(false);
649 bool atlasingStatus(false);
650 bool loadingStatus(false);
651 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
652 ImageAtlasManagerPtr atlasManager = nullptr;
653 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
655 textureManager.LoadTexture(
658 FittingMode::SCALE_TO_FILL,
659 SamplingMode::BOX_THEN_LINEAR,
671 TextureManager::ReloadPolicy::CACHED,
674 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
675 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
677 application.SendNotification();
678 application.Render();
680 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
682 application.SendNotification();
683 application.Render();
685 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
686 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
687 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
692 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
694 ToolkitTestApplication application;
695 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
696 tet_infoline("Try to check CheckForWaitingTexture called");
698 TextureManager textureManager; // Create new texture manager
700 TestObserver observer;
701 std::string filename(TEST_IMAGE_FILE_NAME);
702 std::string maskname("invalid.png");
703 TextureManager::MaskingDataPointer maskInfo = nullptr;
704 maskInfo.reset(new TextureManager::MaskingData());
705 maskInfo->mAlphaMaskUrl = maskname;
706 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
707 maskInfo->mCropToMask = true;
708 maskInfo->mContentScaleFactor = 1.0f;
710 auto textureId(TextureManager::INVALID_TEXTURE_ID);
711 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
712 Dali::ImageDimensions atlasRectSize(0, 0);
713 bool synchronousLoading(false);
714 bool atlasingStatus(false);
715 bool loadingStatus(false);
716 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
717 ImageAtlasManagerPtr atlasManager = nullptr;
718 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
720 textureManager.LoadTexture(
723 FittingMode::SCALE_TO_FILL,
724 SamplingMode::BOX_THEN_LINEAR,
736 TextureManager::ReloadPolicy::CACHED,
739 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
740 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
742 application.SendNotification();
743 application.Render();
745 // CAPTION : HARD-CODING for coverage. If you are a good boy, Do not follow this code.
747 Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
750 FittingMode::SCALE_TO_FILL,
751 SamplingMode::BOX_THEN_LINEAR,
752 true, ///< synchronousLoading
754 true, ///< orientationCorrection
757 std::vector<Devel::PixelBuffer> pixelBuffers;
758 pixelBuffers.push_back(pixelBuffer);
759 textureManager.AsyncLoadComplete(textureId, pixelBuffers);
760 std::vector<Devel::PixelBuffer> maskBuffers;
761 textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
762 textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
763 textureManager.Remove(textureId, &observer);
766 application.SendNotification();
767 application.Render();
769 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
770 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
771 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
773 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
778 int UtcTextureManagerSynchronousLoadingFail(void)
780 ToolkitTestApplication application;
781 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
783 TextureManager textureManager; // Create new texture manager
785 std::string maskname("");
786 TextureManager::MaskingDataPointer maskInfo = nullptr;
787 maskInfo.reset(new TextureManager::MaskingData());
788 maskInfo->mAlphaMaskUrl = maskname;
789 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
790 maskInfo->mCropToMask = true;
791 maskInfo->mContentScaleFactor = 1.0f;
793 std::string filename("dummy");
794 auto textureId(TextureManager::INVALID_TEXTURE_ID);
795 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
796 Dali::ImageDimensions atlasRectSize(0, 0);
797 bool atlasingStatus(false);
798 bool loadingStatus(false);
799 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
800 ImageAtlasManagerPtr atlasManager = nullptr;
801 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
803 // load image synchronously.
804 TestObserver observer;
805 TextureSet textureSet = textureManager.LoadTexture(
808 FittingMode::SCALE_TO_FILL,
809 SamplingMode::BOX_THEN_LINEAR,
811 true, // synchronous loading.
821 TextureManager::ReloadPolicy::CACHED,
824 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
825 DALI_TEST_CHECK(!textureSet); // texture loading fail.
826 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
831 int UtcTextureManagerCachingSynchronousLoading(void)
833 ToolkitTestApplication application;
834 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
836 TextureManager textureManager; // Create new texture manager
838 std::string filename(TEST_IMAGE_FILE_NAME);
840 std::string maskname("");
841 TextureManager::MaskingDataPointer maskInfo = nullptr;
842 maskInfo.reset(new TextureManager::MaskingData());
843 maskInfo->mAlphaMaskUrl = maskname;
844 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
845 maskInfo->mCropToMask = true;
846 maskInfo->mContentScaleFactor = 1.0f;
848 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
849 Dali::ImageDimensions atlasRectSize(0, 0);
850 bool atlasingStatus(false);
851 bool loadingStatus(false);
852 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
853 ImageAtlasManagerPtr atlasManager = nullptr;
854 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
856 // load image synchronously.
857 TestObserver observer;
858 auto textureId(TextureManager::INVALID_TEXTURE_ID);
859 TextureSet textureSet = textureManager.LoadTexture(
862 FittingMode::SCALE_TO_FILL,
863 SamplingMode::BOX_THEN_LINEAR,
865 true, // synchronous loading.
875 TextureManager::ReloadPolicy::CACHED,
878 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
879 DALI_TEST_CHECK(textureSet); // texture is loaded.
881 // observer isn't called in synchronous loading.
882 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
883 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
885 // load same image asynchronously.
886 TestObserver asyncObserver;
887 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
888 loadingStatus = false;
889 TextureSet asyncTextureSet = textureManager.LoadTexture(
892 FittingMode::SCALE_TO_FILL,
893 SamplingMode::BOX_THEN_LINEAR,
895 false, // asynchronous loading.
905 TextureManager::ReloadPolicy::CACHED,
908 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
909 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
910 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
912 // observer is directly called because textureSet is retrieved by cache.
913 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
914 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
919 int UtcTextureManagerAsyncSyncAsync(void)
921 ToolkitTestApplication application;
922 tet_infoline("UtcTextureManagerAsyncSyncAsync");
924 TextureManager textureManager; // Create new texture manager
926 std::string filename(TEST_IMAGE_FILE_NAME);
928 std::string maskname("");
929 TextureManager::MaskingDataPointer maskInfo = nullptr;
930 maskInfo.reset(new TextureManager::MaskingData());
931 maskInfo->mAlphaMaskUrl = maskname;
932 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
933 maskInfo->mCropToMask = true;
934 maskInfo->mContentScaleFactor = 1.0f;
936 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
937 Dali::ImageDimensions atlasRectSize(0, 0);
938 bool atlasingStatus(false);
939 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
940 ImageAtlasManagerPtr atlasManager = nullptr;
941 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
943 // load image asynchronously.
944 TestObserver asyncObserver1;
945 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
946 bool asyncLoadingStatus1 = false;
947 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
950 FittingMode::SCALE_TO_FILL,
951 SamplingMode::BOX_THEN_LINEAR,
953 false, // asynchronous loading.
963 TextureManager::ReloadPolicy::CACHED,
966 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
967 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
969 // observer is still not called.
970 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
971 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
973 // load same image synchronously just after asynchronous loading.
974 TestObserver syncObserver;
975 auto textureId(TextureManager::INVALID_TEXTURE_ID);
976 bool syncLoadingStatus = false;
977 TextureSet syncTextureSet = textureManager.LoadTexture(
980 FittingMode::SCALE_TO_FILL,
981 SamplingMode::BOX_THEN_LINEAR,
983 true, // synchronous loading.
993 TextureManager::ReloadPolicy::CACHED,
996 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
997 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
998 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
1000 // syncObserver isn't called in synchronous loading.
1001 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1002 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1004 // asyncObserver1 is still not called too.
1005 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1006 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1008 // load image asynchronously.
1009 TestObserver asyncObserver2;
1010 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1011 bool asyncLoadingStatus2 = false;
1012 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
1015 FittingMode::SCALE_TO_FILL,
1016 SamplingMode::BOX_THEN_LINEAR,
1018 false, // asynchronous loading.
1023 asyncLoadingStatus2,
1025 atlasUploadObserver,
1028 TextureManager::ReloadPolicy::CACHED,
1031 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1032 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
1033 Texture syncTexture = syncTextureSet.GetTexture(0u);
1034 Texture asyncTexture2 = asyncTextureSet2.GetTexture(0u);
1035 DALI_TEST_CHECK(syncTexture);
1036 DALI_TEST_CHECK(asyncTexture2);
1037 DALI_TEST_CHECK(asyncTexture2 == syncTexture); // check loaded two texture is same.
1039 // observer is called synchronously because the texture is cached.
1040 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1041 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1043 asyncObserver2.mLoaded = false;
1044 asyncObserver2.mObserverCalled = false;
1046 application.SendNotification();
1047 application.Render();
1049 // Requested asynchronous loading at first is finished now and async observer is called now.
1050 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1051 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1052 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1053 DALI_TEST_CHECK(asyncObserver1.mTextureSet);
1055 Texture observerTexture = asyncObserver1.mTextureSet.GetTexture(0u);
1056 DALI_TEST_CHECK(observerTexture == asyncTexture2); // check loaded two texture is same.
1058 // asyncObserver2 was already called so it isn't called here.
1059 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1060 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1065 int UtcTextureManagerQueueRemoveDuringObserve(void)
1067 ToolkitTestApplication application;
1068 tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1070 TextureManager textureManager; // Create new texture manager
1072 TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1074 std::string filename(TEST_IMAGE_FILE_NAME);
1075 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1077 TextureManager::TextureId textureId = textureManager.RequestLoad(
1080 FittingMode::SCALE_TO_FILL,
1081 SamplingMode::BOX_THEN_LINEAR,
1082 TextureManager::UseAtlas::NO_ATLAS,
1085 TextureManager::ReloadPolicy::CACHED,
1088 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1089 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1091 application.SendNotification();
1092 application.Render();
1094 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1096 application.SendNotification();
1097 application.Render();
1099 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1100 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1101 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1103 tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1105 DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1107 // Decrease external texture reference count who observer created
1108 textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1110 application.SendNotification();
1111 application.Render();
1116 int UtcTextureManagerRemoveDuringApplyMasking(void)
1118 ToolkitTestApplication application;
1119 tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1121 TextureManager textureManager; // Create new texture manager
1123 TestObserver observer1;
1124 TestObserver observer2;
1126 std::string filename(TEST_IMAGE_FILE_NAME);
1127 std::string maskname(TEST_MASK_FILE_NAME);
1128 TextureManager::MaskingDataPointer maskInfo = nullptr;
1129 maskInfo.reset(new TextureManager::MaskingData());
1130 maskInfo->mAlphaMaskUrl = maskname;
1131 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1132 maskInfo->mCropToMask = true;
1133 maskInfo->mContentScaleFactor = 1.0f;
1135 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1136 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1137 Dali::ImageDimensions atlasRectSize(0, 0);
1138 bool synchronousLoading(false);
1139 bool atlasingStatus(false);
1140 bool loadingStatus(false);
1141 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1142 ImageAtlasManagerPtr atlasManager = nullptr;
1143 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1145 textureManager.LoadTexture(
1148 FittingMode::SCALE_TO_FILL,
1149 SamplingMode::BOX_THEN_LINEAR,
1158 atlasUploadObserver,
1161 TextureManager::ReloadPolicy::CACHED,
1164 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1165 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1167 application.SendNotification();
1168 application.Render();
1170 // Load image and mask image.
1171 // Now, LoadState become MASK_APPLYING
1172 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1174 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1176 application.SendNotification();
1177 application.Render();
1179 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1180 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1182 // Remove current textureId1. and request new texture again.
1183 textureManager.Remove(textureId1, &observer1);
1184 auto textureId2 = textureManager.RequestLoad(
1187 FittingMode::SCALE_TO_FILL,
1188 SamplingMode::BOX_THEN_LINEAR,
1189 TextureManager::UseAtlas::NO_ATLAS,
1191 true, ///< orientationCorrection
1192 TextureManager::ReloadPolicy::CACHED,
1194 synchronousLoading);
1196 application.SendNotification();
1197 application.Render();
1199 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1200 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1201 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1202 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1204 tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1206 // CAPTION : HARD-CODING.
1208 std::vector<Devel::PixelBuffer> pixelBuffers;
1209 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1210 textureManager.Remove(textureId2, &observer2);
1213 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1214 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1215 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);