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_IMAGE_2_FILE_NAME = TEST_RESOURCE_DIR "/icon-delete.png";
59 const char* TEST_IMAGE_3_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
60 const char* TEST_IMAGE_4_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-20.png";
61 const char* TEST_MASK_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
63 class TestObserver : public Dali::Toolkit::TextureUploadObserver
66 enum class CompleteType
75 : mCompleteType(CompleteType::NOT_COMPLETED),
77 mObserverCalled(false),
82 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
84 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
86 mCompleteType = CompleteType::UPLOAD_COMPLETE;
90 mCompleteType = CompleteType::LOAD_COMPLETE;
92 mLoaded = loadSuccess;
93 mObserverCalled = true;
94 mTextureSet = textureInformation.textureSet;
97 CompleteType mCompleteType;
100 TextureSet mTextureSet;
103 class TestObserverRemoveAndGenerateUrl : public TestObserver
106 TestObserverRemoveAndGenerateUrl(TextureManager* textureManagerPtr)
108 mTextureManagerPtr(textureManagerPtr)
112 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
114 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
116 mCompleteType = CompleteType::UPLOAD_COMPLETE;
120 mCompleteType = CompleteType::LOAD_COMPLETE;
122 mLoaded = loadSuccess;
123 mObserverCalled = true;
124 mTextureSet = textureInformation.textureSet;
126 // Remove during LoadComplete
127 mTextureManagerPtr->Remove(textureInformation.textureId, nullptr);
129 // ...And generate string which using texture id.
130 mGeneratedExternalUrl = mTextureManagerPtr->AddExternalTexture(mTextureSet);
134 std::string mGeneratedExternalUrl;
137 TextureManager* mTextureManagerPtr; // Keep the pointer of texture manager.
140 class TestObserverWithCustomFunction : public TestObserver
143 TestObserverWithCustomFunction()
151 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
153 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
155 mCompleteType = CompleteType::UPLOAD_COMPLETE;
159 mCompleteType = CompleteType::LOAD_COMPLETE;
161 mLoaded = loadSuccess;
162 mObserverCalled = true;
163 mTextureSet = textureInformation.textureSet;
166 for(size_t i = 0; i < mSignals.size(); i++)
178 void ConnectFunction(std::function<void(void*)> signal)
180 mSignals.push_back(signal);
184 std::vector<std::function<void(void*)>> mSignals;
191 int UtcTextureManagerRequestLoad(void)
193 ToolkitTestApplication application;
195 TextureManager textureManager; // Create new texture manager
197 TestObserver observer;
198 std::string filename("image.png");
199 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
200 TextureManager::TextureId textureId = textureManager.RequestLoad(
203 FittingMode::SCALE_TO_FILL,
204 SamplingMode::BOX_THEN_LINEAR,
205 TextureManager::UseAtlas::NO_ATLAS,
208 TextureManager::ReloadPolicy::CACHED,
211 VisualUrl url = textureManager.GetVisualUrl(textureId);
213 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
218 int UtcTextureManagerGenerateHash(void)
220 ToolkitTestApplication application;
222 TextureManager textureManager; // Create new texture manager
224 TestObserver observer;
225 std::string filename("image.png");
226 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
227 TextureManager::TextureId textureId = textureManager.RequestLoad(
230 FittingMode::SCALE_TO_FILL,
231 SamplingMode::BOX_THEN_LINEAR,
232 TextureManager::UseAtlas::NO_ATLAS,
235 TextureManager::ReloadPolicy::CACHED,
238 VisualUrl url = textureManager.GetVisualUrl(textureId);
240 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
245 int UtcTextureManagerEncodedImageBuffer(void)
247 ToolkitTestApplication application;
248 tet_infoline("UtcTextureManagerEncodedImageBuffer");
250 auto visualFactory = Toolkit::VisualFactory::Get();
251 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
253 // Get encoded raw-buffer image and generate url
254 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
255 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
257 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
258 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
259 std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage
261 // Check if same EncodedImageBuffer get same url
262 DALI_TEST_CHECK(url1 == url2);
263 // Reduce reference count
264 textureManager.RemoveEncodedImageBuffer(url1);
265 // Check whethere url1 still valid
266 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
268 url2 = textureManager.AddEncodedImageBuffer(buffer2);
269 // Check if difference EncodedImageBuffer get difference url
270 DALI_TEST_CHECK(url1 != url2);
272 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
274 TestObserver observer1;
275 textureManager.RequestLoad(
278 FittingMode::SCALE_TO_FILL,
279 SamplingMode::BOX_THEN_LINEAR,
280 TextureManager::UseAtlas::NO_ATLAS,
282 true, ///< orientationCorrection
283 TextureManager::ReloadPolicy::CACHED,
286 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
287 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
289 application.SendNotification();
290 application.Render();
292 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
294 application.SendNotification();
295 application.Render();
297 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
298 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
299 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
301 TestObserver observer2;
303 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
306 FittingMode::SCALE_TO_FILL,
307 SamplingMode::BOX_THEN_LINEAR,
308 true, ///< synchronousLoading
310 true, ///< orientationCorrection
313 DALI_TEST_CHECK(pixelBuffer);
314 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
315 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
318 pixelBuffer = textureManager.LoadPixelBuffer(
321 FittingMode::SCALE_TO_FILL,
322 SamplingMode::BOX_THEN_LINEAR,
323 false, ///< synchronousLoading
325 true, ///< orientationCorrection
328 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
329 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
331 application.SendNotification();
332 application.Render();
334 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
336 application.SendNotification();
337 application.Render();
339 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
340 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
341 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
343 textureManager.RemoveEncodedImageBuffer(url1);
344 textureManager.RemoveEncodedImageBuffer(url2);
346 // Now url1 and url2 is invalid type. mLoaded will return false
348 TestObserver observer3;
349 textureManager.RequestLoad(
352 FittingMode::SCALE_TO_FILL,
353 SamplingMode::BOX_THEN_LINEAR,
354 TextureManager::UseAtlas::NO_ATLAS,
356 true, ///< orientationCorrection
357 TextureManager::ReloadPolicy::CACHED,
360 // Load will be success because url1 is cached
361 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
362 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
363 DALI_TEST_EQUALS(observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
365 TestObserver observer4;
366 textureManager.RequestLoad(
369 FittingMode::SCALE_TO_FILL,
370 SamplingMode::BOX_THEN_LINEAR,
371 TextureManager::UseAtlas::NO_ATLAS,
373 true, ///< orientationCorrection
374 TextureManager::ReloadPolicy::FORCED,
377 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
378 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
379 application.SendNotification();
380 application.Render();
382 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
384 application.SendNotification();
385 application.Render();
387 // Load will be failed becuase reloadpolicy is forced
388 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
389 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
390 DALI_TEST_EQUALS(observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
392 TestObserver observer5;
393 pixelBuffer = textureManager.LoadPixelBuffer(
396 FittingMode::SCALE_TO_FILL,
397 SamplingMode::BOX_THEN_LINEAR,
398 true, ///< synchronousLoading
400 true, ///< orientationCorrection
403 // Load will be faild because synchronousLoading doesn't use cached texture
404 DALI_TEST_CHECK(!pixelBuffer);
405 DALI_TEST_EQUALS(observer5.mLoaded, false, TEST_LOCATION);
406 DALI_TEST_EQUALS(observer5.mObserverCalled, false, TEST_LOCATION);
408 TestObserver observer6;
409 pixelBuffer = textureManager.LoadPixelBuffer(
412 FittingMode::SCALE_TO_FILL,
413 SamplingMode::BOX_THEN_LINEAR,
414 false, ///< synchronousLoading
416 true, ///< orientationCorrection
419 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
420 DALI_TEST_EQUALS(observer6.mObserverCalled, false, TEST_LOCATION);
422 application.SendNotification();
423 application.Render();
425 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
427 application.SendNotification();
428 application.Render();
430 // Load will be failed because url3 is invalid URL
431 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
432 DALI_TEST_EQUALS(observer6.mObserverCalled, true, TEST_LOCATION);
433 DALI_TEST_EQUALS(observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
438 int UtcTextureManagerEncodedImageBufferReferenceCount(void)
440 ToolkitTestApplication application;
441 tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well");
443 auto visualFactory = Toolkit::VisualFactory::Get();
444 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
446 // Get encoded raw-buffer image and generate url
447 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
448 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
450 std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
451 std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
453 // Check if same EncodedImageBuffer get same url
454 DALI_TEST_CHECK(url1 == url2);
456 // Reduce reference count
457 textureManager.RemoveEncodedImageBuffer(url1);
458 // Check whethere url1 still valid
459 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
461 // Reduce reference count
462 textureManager.RemoveEncodedImageBuffer(url1);
463 // Check whethere url1 is not valid anymore
464 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
466 // UseExternalTexture doesn't create new buffer.
467 // So, reference count is still zero.
468 textureManager.UseExternalResource(url1);
469 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
471 url1 = textureManager.AddEncodedImageBuffer(buffer1);
473 url2 = textureManager.AddEncodedImageBuffer(buffer2);
474 // Check if difference EncodedImageBuffer get difference url
475 DALI_TEST_CHECK(url1 != url2);
477 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
479 // url1 load image by cache
480 TestObserver observer1;
481 textureManager.RequestLoad(
484 FittingMode::SCALE_TO_FILL,
485 SamplingMode::BOX_THEN_LINEAR,
486 TextureManager::UseAtlas::NO_ATLAS,
488 true, ///< orientationCorrection
489 TextureManager::ReloadPolicy::CACHED,
492 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
493 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
495 application.SendNotification();
496 application.Render();
498 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
500 application.SendNotification();
501 application.Render();
503 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
504 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
505 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
507 // LoadPixelBuffer doen't use cache. url2 will not be cached
508 TestObserver observer2;
509 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
512 FittingMode::SCALE_TO_FILL,
513 SamplingMode::BOX_THEN_LINEAR,
514 false, ///< synchronousLoading
516 true, ///< orientationCorrection
519 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
520 DALI_TEST_EQUALS(observer2.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(observer2.mLoaded, true, TEST_LOCATION);
531 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
532 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
534 // Decrease each url's reference count.
535 textureManager.RemoveEncodedImageBuffer(url1);
536 textureManager.RemoveEncodedImageBuffer(url2);
538 // url1 buffer is still have 1 reference count because it is cached.
539 // But url2 not valid because it is not cached.
540 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
541 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
543 // Check url1 buffer have 1 reference count because it is cached.
544 textureManager.RemoveEncodedImageBuffer(url1);
545 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
550 int UtcTextureManagerCachingForDifferentLoadingType(void)
552 ToolkitTestApplication application;
553 tet_infoline("UtcTextureManagerCachingForDifferentLoadingType");
555 TextureManager textureManager; // Create new texture manager
557 TestObserver observer1;
558 std::string filename(TEST_IMAGE_FILE_NAME);
559 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
560 textureManager.RequestLoad(
563 FittingMode::SCALE_TO_FILL,
564 SamplingMode::BOX_THEN_LINEAR,
565 TextureManager::UseAtlas::NO_ATLAS,
568 TextureManager::ReloadPolicy::CACHED,
571 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
572 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
574 application.SendNotification();
575 application.Render();
577 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
579 application.SendNotification();
580 application.Render();
582 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
583 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
584 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
586 TestObserver observer2;
587 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
590 FittingMode::SCALE_TO_FILL,
591 SamplingMode::BOX_THEN_LINEAR,
597 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
598 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
600 application.SendNotification();
601 application.Render();
603 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
605 application.SendNotification();
606 application.Render();
608 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
609 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
610 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
615 int UtcTextureManagerUseInvalidMask(void)
617 ToolkitTestApplication application;
618 tet_infoline("UtcTextureManagerUseInvalidMask");
620 TextureManager textureManager; // Create new texture manager
622 TestObserver observer;
623 std::string filename(TEST_IMAGE_FILE_NAME);
624 std::string maskname("");
625 TextureManager::MaskingDataPointer maskInfo = nullptr;
626 maskInfo.reset(new TextureManager::MaskingData());
627 maskInfo->mAlphaMaskUrl = maskname;
628 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
629 maskInfo->mCropToMask = true;
630 maskInfo->mContentScaleFactor = 1.0f;
632 auto textureId(TextureManager::INVALID_TEXTURE_ID);
633 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
634 Dali::ImageDimensions atlasRectSize(0, 0);
635 bool synchronousLoading(false);
636 bool atlasingStatus(false);
637 bool loadingStatus(false);
638 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
639 ImageAtlasManagerPtr atlasManager = nullptr;
640 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
642 textureManager.LoadTexture(
645 FittingMode::SCALE_TO_FILL,
646 SamplingMode::BOX_THEN_LINEAR,
658 TextureManager::ReloadPolicy::CACHED,
661 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
662 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
664 application.SendNotification();
665 application.Render();
667 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
669 application.SendNotification();
670 application.Render();
672 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
673 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
674 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
679 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
681 ToolkitTestApplication application;
682 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
683 tet_infoline("Try to check PostLoad works well");
685 TextureManager textureManager; // Create new texture manager
687 TestObserver observer;
688 std::string filename(TEST_IMAGE_FILE_NAME);
689 std::string maskname("invalid.png");
690 TextureManager::MaskingDataPointer maskInfo = nullptr;
691 maskInfo.reset(new TextureManager::MaskingData());
692 maskInfo->mAlphaMaskUrl = maskname;
693 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
694 maskInfo->mCropToMask = true;
695 maskInfo->mContentScaleFactor = 1.0f;
697 auto textureId(TextureManager::INVALID_TEXTURE_ID);
698 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
699 Dali::ImageDimensions atlasRectSize(0, 0);
700 bool synchronousLoading(false);
701 bool atlasingStatus(false);
702 bool loadingStatus(false);
703 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
704 ImageAtlasManagerPtr atlasManager = nullptr;
705 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
707 textureManager.LoadTexture(
710 FittingMode::SCALE_TO_FILL,
711 SamplingMode::BOX_THEN_LINEAR,
723 TextureManager::ReloadPolicy::CACHED,
726 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
727 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
729 application.SendNotification();
730 application.Render();
732 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
734 application.SendNotification();
735 application.Render();
737 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
738 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
739 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
744 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
746 ToolkitTestApplication application;
747 tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
748 tet_infoline("Try to check CheckForWaitingTexture called");
750 TextureManager textureManager; // Create new texture manager
752 TestObserver observer;
753 std::string filename(TEST_IMAGE_FILE_NAME);
754 std::string maskname("invalid.png");
755 TextureManager::MaskingDataPointer maskInfo = nullptr;
756 maskInfo.reset(new TextureManager::MaskingData());
757 maskInfo->mAlphaMaskUrl = maskname;
758 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
759 maskInfo->mCropToMask = true;
760 maskInfo->mContentScaleFactor = 1.0f;
762 auto textureId(TextureManager::INVALID_TEXTURE_ID);
763 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
764 Dali::ImageDimensions atlasRectSize(0, 0);
765 bool synchronousLoading(false);
766 bool atlasingStatus(false);
767 bool loadingStatus(false);
768 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
769 ImageAtlasManagerPtr atlasManager = nullptr;
770 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
772 textureManager.LoadTexture(
775 FittingMode::SCALE_TO_FILL,
776 SamplingMode::BOX_THEN_LINEAR,
788 TextureManager::ReloadPolicy::CACHED,
791 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
792 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
794 application.SendNotification();
795 application.Render();
797 // CAPTION : HARD-CODING for coverage. If you are a good boy, Do not follow this code.
799 Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
802 FittingMode::SCALE_TO_FILL,
803 SamplingMode::BOX_THEN_LINEAR,
804 true, ///< synchronousLoading
806 true, ///< orientationCorrection
809 std::vector<Devel::PixelBuffer> pixelBuffers;
810 pixelBuffers.push_back(pixelBuffer);
811 textureManager.AsyncLoadComplete(textureId, pixelBuffers);
812 std::vector<Devel::PixelBuffer> maskBuffers;
813 textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
814 textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
815 textureManager.Remove(textureId, &observer);
818 application.SendNotification();
819 application.Render();
821 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
822 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
823 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
825 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
830 int UtcTextureManagerSynchronousLoadingFail(void)
832 ToolkitTestApplication application;
833 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
835 TextureManager textureManager; // Create new texture manager
837 std::string maskname("");
838 TextureManager::MaskingDataPointer maskInfo = nullptr;
839 maskInfo.reset(new TextureManager::MaskingData());
840 maskInfo->mAlphaMaskUrl = maskname;
841 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
842 maskInfo->mCropToMask = true;
843 maskInfo->mContentScaleFactor = 1.0f;
845 std::string filename("dummy");
846 auto textureId(TextureManager::INVALID_TEXTURE_ID);
847 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
848 Dali::ImageDimensions atlasRectSize(0, 0);
849 bool atlasingStatus(false);
850 bool loadingStatus(false);
851 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
852 ImageAtlasManagerPtr atlasManager = nullptr;
853 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
855 // load image synchronously.
856 TestObserver observer;
857 TextureSet textureSet = textureManager.LoadTexture(
860 FittingMode::SCALE_TO_FILL,
861 SamplingMode::BOX_THEN_LINEAR,
863 true, // synchronous loading.
873 TextureManager::ReloadPolicy::CACHED,
876 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
877 DALI_TEST_CHECK(!textureSet); // texture loading fail.
878 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
883 int UtcTextureManagerCachingSynchronousLoading(void)
885 ToolkitTestApplication application;
886 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
888 TextureManager textureManager; // Create new texture manager
890 std::string filename(TEST_IMAGE_FILE_NAME);
892 std::string maskname("");
893 TextureManager::MaskingDataPointer maskInfo = nullptr;
894 maskInfo.reset(new TextureManager::MaskingData());
895 maskInfo->mAlphaMaskUrl = maskname;
896 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
897 maskInfo->mCropToMask = true;
898 maskInfo->mContentScaleFactor = 1.0f;
900 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
901 Dali::ImageDimensions atlasRectSize(0, 0);
902 bool atlasingStatus(false);
903 bool loadingStatus(false);
904 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
905 ImageAtlasManagerPtr atlasManager = nullptr;
906 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
908 // load image synchronously.
909 TestObserver observer;
910 auto textureId(TextureManager::INVALID_TEXTURE_ID);
911 TextureSet textureSet = textureManager.LoadTexture(
914 FittingMode::SCALE_TO_FILL,
915 SamplingMode::BOX_THEN_LINEAR,
917 true, // synchronous loading.
927 TextureManager::ReloadPolicy::CACHED,
930 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
931 DALI_TEST_CHECK(textureSet); // texture is loaded.
933 // observer isn't called in synchronous loading.
934 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
935 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
937 // load same image asynchronously.
938 TestObserver asyncObserver;
939 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
940 loadingStatus = false;
941 TextureSet asyncTextureSet = textureManager.LoadTexture(
944 FittingMode::SCALE_TO_FILL,
945 SamplingMode::BOX_THEN_LINEAR,
947 false, // asynchronous loading.
957 TextureManager::ReloadPolicy::CACHED,
960 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
961 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
962 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
964 // observer is directly called because textureSet is retrieved by cache.
965 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
966 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
971 int UtcTextureManagerAsyncSyncAsync(void)
973 ToolkitTestApplication application;
974 tet_infoline("UtcTextureManagerAsyncSyncAsync");
976 TextureManager textureManager; // Create new texture manager
978 std::string filename(TEST_IMAGE_FILE_NAME);
980 std::string maskname("");
981 TextureManager::MaskingDataPointer maskInfo = nullptr;
982 maskInfo.reset(new TextureManager::MaskingData());
983 maskInfo->mAlphaMaskUrl = maskname;
984 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
985 maskInfo->mCropToMask = true;
986 maskInfo->mContentScaleFactor = 1.0f;
988 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
989 Dali::ImageDimensions atlasRectSize(0, 0);
990 bool atlasingStatus(false);
991 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
992 ImageAtlasManagerPtr atlasManager = nullptr;
993 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
995 // load image asynchronously.
996 TestObserver asyncObserver1;
997 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
998 bool asyncLoadingStatus1 = false;
999 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
1002 FittingMode::SCALE_TO_FILL,
1003 SamplingMode::BOX_THEN_LINEAR,
1005 false, // asynchronous loading.
1010 asyncLoadingStatus1,
1012 atlasUploadObserver,
1015 TextureManager::ReloadPolicy::CACHED,
1018 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
1019 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
1021 // observer is still not called.
1022 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1023 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1025 // load same image synchronously just after asynchronous loading.
1026 TestObserver syncObserver;
1027 auto textureId(TextureManager::INVALID_TEXTURE_ID);
1028 bool syncLoadingStatus = false;
1029 TextureSet syncTextureSet = textureManager.LoadTexture(
1032 FittingMode::SCALE_TO_FILL,
1033 SamplingMode::BOX_THEN_LINEAR,
1035 true, // synchronous loading.
1042 atlasUploadObserver,
1045 TextureManager::ReloadPolicy::CACHED,
1048 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
1049 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
1050 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
1052 // syncObserver isn't called in synchronous loading.
1053 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1054 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1056 // asyncObserver1 is still not called too.
1057 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1058 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1060 // load image asynchronously.
1061 TestObserver asyncObserver2;
1062 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1063 bool asyncLoadingStatus2 = false;
1064 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
1067 FittingMode::SCALE_TO_FILL,
1068 SamplingMode::BOX_THEN_LINEAR,
1070 false, // asynchronous loading.
1075 asyncLoadingStatus2,
1077 atlasUploadObserver,
1080 TextureManager::ReloadPolicy::CACHED,
1083 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1084 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
1085 Texture syncTexture = syncTextureSet.GetTexture(0u);
1086 Texture asyncTexture2 = asyncTextureSet2.GetTexture(0u);
1087 DALI_TEST_CHECK(syncTexture);
1088 DALI_TEST_CHECK(asyncTexture2);
1089 DALI_TEST_CHECK(asyncTexture2 == syncTexture); // check loaded two texture is same.
1091 // observer is called synchronously because the texture is cached.
1092 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1093 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1095 asyncObserver2.mLoaded = false;
1096 asyncObserver2.mObserverCalled = false;
1098 application.SendNotification();
1099 application.Render();
1101 // Requested asynchronous loading at first is finished now and async observer is called now.
1102 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1103 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1104 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1105 DALI_TEST_CHECK(asyncObserver1.mTextureSet);
1107 Texture observerTexture = asyncObserver1.mTextureSet.GetTexture(0u);
1108 DALI_TEST_CHECK(observerTexture == asyncTexture2); // check loaded two texture is same.
1110 // asyncObserver2 was already called so it isn't called here.
1111 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1112 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1117 int UtcTextureManagerQueueRemoveDuringObserve(void)
1119 ToolkitTestApplication application;
1120 tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1122 TextureManager textureManager; // Create new texture manager
1124 TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1126 std::string filename(TEST_IMAGE_FILE_NAME);
1127 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1129 TextureManager::TextureId textureId = textureManager.RequestLoad(
1132 FittingMode::SCALE_TO_FILL,
1133 SamplingMode::BOX_THEN_LINEAR,
1134 TextureManager::UseAtlas::NO_ATLAS,
1137 TextureManager::ReloadPolicy::CACHED,
1140 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1141 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1143 application.SendNotification();
1144 application.Render();
1146 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1148 application.SendNotification();
1149 application.Render();
1151 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1152 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1153 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1155 tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1157 DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1159 // Decrease external texture reference count who observer created
1160 textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1162 application.SendNotification();
1163 application.Render();
1168 int UtcTextureManagerRemoveDuringApplyMasking(void)
1170 ToolkitTestApplication application;
1171 tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1173 TextureManager textureManager; // Create new texture manager
1175 TestObserver observer1;
1176 TestObserver observer2;
1178 std::string filename(TEST_IMAGE_FILE_NAME);
1179 std::string maskname(TEST_MASK_FILE_NAME);
1180 TextureManager::MaskingDataPointer maskInfo = nullptr;
1181 maskInfo.reset(new TextureManager::MaskingData());
1182 maskInfo->mAlphaMaskUrl = maskname;
1183 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1184 maskInfo->mCropToMask = true;
1185 maskInfo->mContentScaleFactor = 1.0f;
1187 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1188 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1189 Dali::ImageDimensions atlasRectSize(0, 0);
1190 bool synchronousLoading(false);
1191 bool atlasingStatus(false);
1192 bool loadingStatus(false);
1193 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1194 ImageAtlasManagerPtr atlasManager = nullptr;
1195 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1197 textureManager.LoadTexture(
1200 FittingMode::SCALE_TO_FILL,
1201 SamplingMode::BOX_THEN_LINEAR,
1210 atlasUploadObserver,
1213 TextureManager::ReloadPolicy::CACHED,
1216 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1217 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1219 application.SendNotification();
1220 application.Render();
1222 // Load image and mask image.
1223 // Now, LoadState become MASK_APPLYING
1224 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1226 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1228 application.SendNotification();
1229 application.Render();
1231 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1232 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1234 // Remove current textureId1. and request new texture again.
1235 textureManager.Remove(textureId1, &observer1);
1236 auto textureId2 = textureManager.RequestLoad(
1239 FittingMode::SCALE_TO_FILL,
1240 SamplingMode::BOX_THEN_LINEAR,
1241 TextureManager::UseAtlas::NO_ATLAS,
1243 true, ///< orientationCorrection
1244 TextureManager::ReloadPolicy::CACHED,
1246 synchronousLoading);
1248 application.SendNotification();
1249 application.Render();
1251 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1252 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1253 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1254 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1256 tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1258 // CAPTION : HARD-CODING.
1260 std::vector<Devel::PixelBuffer> pixelBuffers;
1261 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1262 textureManager.Remove(textureId2, &observer2);
1265 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1266 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1267 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1272 int UtcTextureManagerMaskCacheTest(void)
1274 ToolkitTestApplication application;
1275 tet_infoline("UtcTextureManagerMaskCacheTest");
1277 TextureManager textureManager; // Create new texture manager
1279 TestObserver observer1;
1280 TestObserver observer2;
1282 std::string filename(TEST_IMAGE_FILE_NAME);
1283 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1284 std::string maskname(TEST_MASK_FILE_NAME);
1285 TextureManager::MaskingDataPointer maskInfo = nullptr;
1286 maskInfo.reset(new TextureManager::MaskingData());
1287 maskInfo->mAlphaMaskUrl = maskname;
1288 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1289 maskInfo->mCropToMask = true;
1290 maskInfo->mContentScaleFactor = 1.0f;
1292 TextureManager::MaskingDataPointer maskInfo2 = nullptr;
1293 maskInfo2.reset(new TextureManager::MaskingData());
1294 maskInfo2->mAlphaMaskUrl = maskname;
1295 maskInfo2->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1296 maskInfo2->mCropToMask = true;
1297 maskInfo2->mContentScaleFactor = 1.0f;
1299 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1300 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1301 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1302 Dali::ImageDimensions atlasRectSize(0, 0);
1303 bool synchronousLoading(false);
1304 bool atlasingStatus(false);
1305 bool loadingStatus(false);
1306 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1307 ImageAtlasManagerPtr atlasManager = nullptr;
1308 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1310 textureManager.LoadTexture(
1313 FittingMode::SCALE_TO_FILL,
1314 SamplingMode::BOX_THEN_LINEAR,
1323 atlasUploadObserver,
1326 TextureManager::ReloadPolicy::CACHED,
1329 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1330 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1332 application.SendNotification();
1333 application.Render();
1335 // Load image and mask image.
1336 // Now, LoadState become MASK_APPLYING
1337 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1339 tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1341 textureManager.LoadTexture(
1344 FittingMode::SCALE_TO_FILL,
1345 SamplingMode::BOX_THEN_LINEAR,
1354 atlasUploadObserver,
1357 TextureManager::ReloadPolicy::CACHED,
1360 application.SendNotification();
1361 application.Render();
1363 // Load image2 + image1 apply mask + image2 apply mask = total 3 event trigger required.
1364 // Note that we use cached mask image.
1365 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1367 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1368 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1369 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1370 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1374 // Remove textureId1 first, and then remove textureId2. Check whether segfault occured.
1375 textureManager.Remove(textureId1, &observer1);
1376 textureManager.Remove(textureId2, &observer2);
1378 TestObserver observer3;
1379 maskInfo.reset(new TextureManager::MaskingData());
1380 maskInfo->mAlphaMaskUrl = maskname;
1381 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1382 maskInfo->mCropToMask = true;
1383 maskInfo->mContentScaleFactor = 1.0f;
1385 textureManager.LoadTexture(
1388 FittingMode::SCALE_TO_FILL,
1389 SamplingMode::BOX_THEN_LINEAR,
1398 atlasUploadObserver,
1401 TextureManager::ReloadPolicy::CACHED,
1404 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1405 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1407 application.SendNotification();
1408 application.Render();
1410 // Load image and mask image.
1411 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1412 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1414 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1415 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1418 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1420 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
1421 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
1425 DALI_TEST_CHECK(false);
1431 int UtcTextureManagerRemoveDuringGPUMasking(void)
1433 ToolkitTestApplication application;
1434 tet_infoline("UtcTextureManagerRemoveDuringGPUMasking");
1435 tet_infoline("Request 3 different GPU masking image.");
1436 tet_infoline("Control to mask image load last. and then, check execute result.");
1438 TextureManager textureManager; // Create new texture manager
1440 TestObserverWithCustomFunction observer1;
1441 TestObserverWithCustomFunction observer2;
1442 TestObserver observer3;
1443 TestObserver observer4;
1445 std::string filename1(TEST_IMAGE_FILE_NAME);
1446 std::string filename2(TEST_IMAGE_2_FILE_NAME);
1447 std::string filename3(TEST_IMAGE_3_FILE_NAME);
1448 std::string filename4(TEST_IMAGE_4_FILE_NAME);
1450 auto textureId1(TextureManager::INVALID_TEXTURE_ID);
1451 auto textureId2(TextureManager::INVALID_TEXTURE_ID);
1452 auto textureId3(TextureManager::INVALID_TEXTURE_ID);
1453 auto textureId4(TextureManager::INVALID_TEXTURE_ID);
1455 std::string maskname(TEST_MASK_FILE_NAME);
1456 TextureManager::MaskingDataPointer maskInfo[3] = {nullptr, nullptr, nullptr};
1457 for(int i = 0; i < 3; i++)
1459 maskInfo[i].reset(new TextureManager::MaskingData());
1460 maskInfo[i]->mAlphaMaskUrl = maskname;
1461 maskInfo[i]->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
1462 maskInfo[i]->mCropToMask = true;
1463 maskInfo[i]->mPreappliedMasking = false; // To make GPU masking
1464 maskInfo[i]->mContentScaleFactor = 1.0f;
1466 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1467 Dali::ImageDimensions atlasRectSize(0, 0);
1468 bool synchronousLoading(false);
1469 bool atlasingStatus(false);
1470 bool loadingStatus(false);
1471 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1472 ImageAtlasManagerPtr atlasManager = nullptr;
1473 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1475 // Request image 1, 2, 3 with GPU masking
1476 textureManager.LoadTexture(
1479 FittingMode::SCALE_TO_FILL,
1480 SamplingMode::BOX_THEN_LINEAR,
1489 atlasUploadObserver,
1492 TextureManager::ReloadPolicy::CACHED,
1495 textureManager.LoadTexture(
1498 FittingMode::SCALE_TO_FILL,
1499 SamplingMode::BOX_THEN_LINEAR,
1508 atlasUploadObserver,
1511 TextureManager::ReloadPolicy::CACHED,
1514 textureManager.LoadTexture(
1517 FittingMode::SCALE_TO_FILL,
1518 SamplingMode::BOX_THEN_LINEAR,
1527 atlasUploadObserver,
1530 TextureManager::ReloadPolicy::CACHED,
1533 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1534 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1535 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1536 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1537 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1538 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1539 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1540 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1542 // Check we use cached mask image
1543 DALI_TEST_CHECK(maskInfo[0]->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID);
1544 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[1]->mAlphaMaskId, TEST_LOCATION);
1545 DALI_TEST_EQUALS(maskInfo[0]->mAlphaMaskId, maskInfo[2]->mAlphaMaskId, TEST_LOCATION);
1547 // Connect observer1 custom function
1550 TextureManager* textureManagerPtr{nullptr};
1551 TextureManager::TextureId removeTextureId{TextureManager::INVALID_TEXTURE_ID};
1552 TestObserver* removeTextureObserver{nullptr};
1555 data1.textureManagerPtr = &textureManager;
1556 data1.removeTextureId = textureId3;
1557 data1.removeTextureObserver = &observer3;
1559 observer1.mData = &data1;
1560 observer1.ConnectFunction(
1562 DALI_TEST_CHECK(data);
1563 CustomData1 data1 = *(CustomData1*)data;
1565 DALI_TEST_CHECK(data1.textureManagerPtr);
1566 DALI_TEST_CHECK(data1.removeTextureId != TextureManager::INVALID_TEXTURE_ID);
1567 DALI_TEST_CHECK(data1.removeTextureObserver);
1569 // Remove textureId3
1570 data1.textureManagerPtr->Remove(data1.removeTextureId, data1.removeTextureObserver);
1573 // Connect observer2 custom function
1576 TextureManager* textureManagerPtr{nullptr};
1577 std::string addTextureUrl{};
1578 TextureManager::TextureId* addTextureIdPtr{nullptr};
1579 TestObserver* addTextureObserver{nullptr};
1582 data2.textureManagerPtr = &textureManager;
1583 data2.addTextureUrl = filename4;
1584 data2.addTextureIdPtr = &textureId4;
1585 data2.addTextureObserver = &observer4;
1587 observer2.mData = &data2;
1588 observer2.ConnectFunction(
1590 DALI_TEST_CHECK(data);
1591 CustomData2 data2 = *(CustomData2*)data;
1593 DALI_TEST_CHECK(data2.textureManagerPtr);
1594 DALI_TEST_CHECK(!data2.addTextureUrl.empty());
1595 DALI_TEST_CHECK(data2.addTextureIdPtr);
1596 DALI_TEST_CHECK(data2.addTextureObserver);
1598 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1601 (*data2.addTextureIdPtr) = data2.textureManagerPtr->RequestLoad(
1602 data2.addTextureUrl,
1604 FittingMode::SCALE_TO_FILL,
1605 SamplingMode::BOX_THEN_LINEAR,
1606 TextureManager::UseAtlas::NO_ATLAS,
1607 data2.addTextureObserver,
1609 TextureManager::ReloadPolicy::CACHED,
1613 application.SendNotification();
1614 application.Render();
1616 tet_printf("Id info - mask : {%d}, 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(maskInfo[0]->mAlphaMaskId), static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
1618 // CAPTION : HARD-CODING.
1620 // Complete async load 1, 2, 3.
1621 std::vector<Devel::PixelBuffer> pixelBuffers;
1623 pixelBuffers.clear();
1624 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1625 textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
1626 pixelBuffers.clear();
1627 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1628 textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1629 pixelBuffers.clear();
1630 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1631 textureManager.AsyncLoadComplete(textureId3, pixelBuffers);
1633 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1634 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1635 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1636 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1637 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1638 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1639 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1640 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1642 // Complete mask load.
1643 pixelBuffers.clear();
1644 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::L8));
1645 textureManager.AsyncLoadComplete(maskInfo[0]->mAlphaMaskId, pixelBuffers);
1647 tet_printf("Id info after observer notify - mask : {%d}, 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(maskInfo[0]->mAlphaMaskId), static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
1649 // Check observer 1 and 2 called, but 3 and 4 not called.
1650 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1651 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1652 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1653 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1654 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1655 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1656 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
1657 DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
1660 DALI_TEST_CHECK(textureId4 != TextureManager::INVALID_TEXTURE_ID);
1663 pixelBuffers.clear();
1664 pixelBuffers.push_back(Devel::PixelBuffer::New(1, 1, Pixel::Format::RGB888));
1665 textureManager.AsyncLoadComplete(textureId4, pixelBuffers);
1667 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
1668 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
1669 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
1670 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1671 DALI_TEST_EQUALS(observer3.mLoaded, false, TEST_LOCATION);
1672 DALI_TEST_EQUALS(observer3.mObserverCalled, false, TEST_LOCATION);
1673 DALI_TEST_EQUALS(observer4.mLoaded, true, TEST_LOCATION);
1674 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);