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";
61 class TestObserver : public Dali::Toolkit::TextureUploadObserver
64 enum class CompleteType
73 : mCompleteType(CompleteType::NOT_COMPLETED),
75 mObserverCalled(false),
80 virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
82 if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
84 mCompleteType = CompleteType::UPLOAD_COMPLETE;
88 mCompleteType = CompleteType::LOAD_COMPLETE;
90 mLoaded = loadSuccess;
91 mObserverCalled = true;
92 mTextureSet = textureInformation.textureSet;
95 CompleteType mCompleteType;
98 TextureSet mTextureSet;
101 int UtcTextureManagerRequestLoad(void)
103 ToolkitTestApplication application;
105 TextureManager textureManager; // Create new texture manager
107 TestObserver observer;
108 std::string filename("image.png");
109 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
110 TextureManager::TextureId textureId = textureManager.RequestLoad(
113 FittingMode::SCALE_TO_FILL,
114 SamplingMode::BOX_THEN_LINEAR,
115 TextureManager::UseAtlas::NO_ATLAS,
118 TextureManager::ReloadPolicy::CACHED,
121 VisualUrl url = textureManager.GetVisualUrl(textureId);
123 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
128 int UtcTextureManagerGenerateHash(void)
130 ToolkitTestApplication application;
132 TextureManager textureManager; // Create new texture manager
134 TestObserver observer;
135 std::string filename("image.png");
136 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
137 TextureManager::TextureId textureId = textureManager.RequestLoad(
140 FittingMode::SCALE_TO_FILL,
141 SamplingMode::BOX_THEN_LINEAR,
142 TextureManager::UseAtlas::NO_ATLAS,
145 TextureManager::ReloadPolicy::CACHED,
148 VisualUrl url = textureManager.GetVisualUrl(textureId);
150 DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
155 int UtcTextureManagerEncodedImageBuffer(void)
157 ToolkitTestApplication application;
158 tet_infoline("UtcTextureManagerEncodedImageBuffer");
160 auto visualFactory = Toolkit::VisualFactory::Get();
161 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
163 // Get encoded raw-buffer image and generate url
164 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
165 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
167 std::string url1 = textureManager.AddExternalEncodedImageBuffer(buffer1);
168 std::string url2 = textureManager.AddExternalEncodedImageBuffer(buffer1);
169 std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage
171 // Check if same EncodedImageBuffer get same url
172 DALI_TEST_CHECK(url1 == url2);
173 // Reduce reference count
174 textureManager.RemoveExternalEncodedImageBuffer(url1);
175 // Check whethere url1 still valid
176 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
178 url2 = textureManager.AddExternalEncodedImageBuffer(buffer2);
179 // Check if difference EncodedImageBuffer get difference url
180 DALI_TEST_CHECK(url1 != url2);
182 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
184 TestObserver observer1;
185 textureManager.RequestLoad(
188 FittingMode::SCALE_TO_FILL,
189 SamplingMode::BOX_THEN_LINEAR,
190 TextureManager::UseAtlas::NO_ATLAS,
192 true, ///< orientationCorrection
193 TextureManager::ReloadPolicy::CACHED,
196 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
197 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
199 application.SendNotification();
200 application.Render();
202 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
204 application.SendNotification();
205 application.Render();
207 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
208 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
209 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
211 TestObserver observer2;
213 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
216 FittingMode::SCALE_TO_FILL,
217 SamplingMode::BOX_THEN_LINEAR,
218 true, ///< synchronousLoading
220 true, ///< orientationCorrection
223 DALI_TEST_CHECK(pixelBuffer);
224 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
225 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
228 pixelBuffer = textureManager.LoadPixelBuffer(
231 FittingMode::SCALE_TO_FILL,
232 SamplingMode::BOX_THEN_LINEAR,
233 false, ///< synchronousLoading
235 true, ///< orientationCorrection
238 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
239 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
241 application.SendNotification();
242 application.Render();
244 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
246 application.SendNotification();
247 application.Render();
249 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
250 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
251 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
253 textureManager.RemoveExternalEncodedImageBuffer(url1);
254 textureManager.RemoveExternalEncodedImageBuffer(url2);
256 // Now url1 and url2 is invalid type. mLoaded will return false
258 TestObserver observer3;
259 textureManager.RequestLoad(
262 FittingMode::SCALE_TO_FILL,
263 SamplingMode::BOX_THEN_LINEAR,
264 TextureManager::UseAtlas::NO_ATLAS,
266 true, ///< orientationCorrection
267 TextureManager::ReloadPolicy::CACHED,
270 // Load will be success because url1 is cached
271 DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
272 DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
273 DALI_TEST_EQUALS(observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
275 TestObserver observer4;
276 textureManager.RequestLoad(
279 FittingMode::SCALE_TO_FILL,
280 SamplingMode::BOX_THEN_LINEAR,
281 TextureManager::UseAtlas::NO_ATLAS,
283 true, ///< orientationCorrection
284 TextureManager::ReloadPolicy::FORCED,
287 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
288 DALI_TEST_EQUALS(observer4.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 // Load will be failed becuase reloadpolicy is forced
298 DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
299 DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
300 DALI_TEST_EQUALS(observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
302 TestObserver observer5;
303 pixelBuffer = textureManager.LoadPixelBuffer(
306 FittingMode::SCALE_TO_FILL,
307 SamplingMode::BOX_THEN_LINEAR,
308 true, ///< synchronousLoading
310 true, ///< orientationCorrection
313 // Load will be faild because synchronousLoading doesn't use cached texture
314 DALI_TEST_CHECK(!pixelBuffer);
315 DALI_TEST_EQUALS(observer5.mLoaded, false, TEST_LOCATION);
316 DALI_TEST_EQUALS(observer5.mObserverCalled, false, TEST_LOCATION);
318 TestObserver observer6;
319 pixelBuffer = textureManager.LoadPixelBuffer(
322 FittingMode::SCALE_TO_FILL,
323 SamplingMode::BOX_THEN_LINEAR,
324 false, ///< synchronousLoading
326 true, ///< orientationCorrection
329 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
330 DALI_TEST_EQUALS(observer6.mObserverCalled, false, TEST_LOCATION);
332 application.SendNotification();
333 application.Render();
335 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
337 application.SendNotification();
338 application.Render();
340 // Load will be failed because url3 is invalid URL
341 DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
342 DALI_TEST_EQUALS(observer6.mObserverCalled, true, TEST_LOCATION);
343 DALI_TEST_EQUALS(observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
348 int UtcTextureManagerEncodedImageBufferReferenceCount(void)
350 ToolkitTestApplication application;
351 tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well");
353 auto visualFactory = Toolkit::VisualFactory::Get();
354 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
356 // Get encoded raw-buffer image and generate url
357 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
358 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
360 std::string url1 = textureManager.AddExternalEncodedImageBuffer(buffer1);
361 std::string url2 = textureManager.AddExternalEncodedImageBuffer(buffer1);
363 // Check if same EncodedImageBuffer get same url
364 DALI_TEST_CHECK(url1 == url2);
366 // Reduce reference count
367 textureManager.RemoveExternalEncodedImageBuffer(url1);
368 // Check whethere url1 still valid
369 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
371 // Reduce reference count
372 textureManager.RemoveExternalEncodedImageBuffer(url1);
373 // Check whethere url1 is not valid anymore
374 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
376 // UseExternalTexture doesn't create new buffer.
377 // So, reference count is still zero.
378 textureManager.UseExternalResource(url1);
379 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
381 url1 = textureManager.AddExternalEncodedImageBuffer(buffer1);
382 // Check if difference EncodedImageBuffer get difference url
383 // Previous EncodedImageBuffer was deleted, so we get new url even same buffer.
384 DALI_TEST_CHECK(url1 != url2);
386 url2 = textureManager.AddExternalEncodedImageBuffer(buffer2);
387 // Check if difference EncodedImageBuffer get difference url
388 DALI_TEST_CHECK(url1 != url2);
390 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
392 // url1 load image by cache
393 TestObserver observer1;
394 textureManager.RequestLoad(
397 FittingMode::SCALE_TO_FILL,
398 SamplingMode::BOX_THEN_LINEAR,
399 TextureManager::UseAtlas::NO_ATLAS,
401 true, ///< orientationCorrection
402 TextureManager::ReloadPolicy::CACHED,
405 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
406 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
408 application.SendNotification();
409 application.Render();
411 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
413 application.SendNotification();
414 application.Render();
416 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
417 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
418 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
420 // LoadPixelBuffer doen't use cache. url2 will not be cached
421 TestObserver observer2;
422 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
425 FittingMode::SCALE_TO_FILL,
426 SamplingMode::BOX_THEN_LINEAR,
427 false, ///< synchronousLoading
429 true, ///< orientationCorrection
432 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
433 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
435 application.SendNotification();
436 application.Render();
438 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
440 application.SendNotification();
441 application.Render();
443 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
444 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
445 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
447 // Decrease each url's reference count.
448 textureManager.RemoveExternalEncodedImageBuffer(url1);
449 textureManager.RemoveExternalEncodedImageBuffer(url2);
451 // url1 buffer is still have 1 reference count because it is cached.
452 // But url2 not valid because it is not cached.
453 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
454 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
456 // Check url1 buffer have 1 reference count because it is cached.
457 textureManager.RemoveExternalEncodedImageBuffer(url1);
458 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
463 int UtcTextureManagerCachingForDifferentLoadingType(void)
465 ToolkitTestApplication application;
466 tet_infoline("UtcTextureManagerCachingForDifferentLoadingType");
468 TextureManager textureManager; // Create new texture manager
470 TestObserver observer1;
471 std::string filename(TEST_IMAGE_FILE_NAME);
472 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
473 textureManager.RequestLoad(
476 FittingMode::SCALE_TO_FILL,
477 SamplingMode::BOX_THEN_LINEAR,
478 TextureManager::UseAtlas::NO_ATLAS,
481 TextureManager::ReloadPolicy::CACHED,
484 DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
485 DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
487 application.SendNotification();
488 application.Render();
490 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
492 application.SendNotification();
493 application.Render();
495 DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
496 DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
497 DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
499 TestObserver observer2;
500 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
503 FittingMode::SCALE_TO_FILL,
504 SamplingMode::BOX_THEN_LINEAR,
510 DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
511 DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
513 application.SendNotification();
514 application.Render();
516 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
518 application.SendNotification();
519 application.Render();
521 DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
522 DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
523 DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
528 int UtcTextureManagerUseInvalidMask(void)
530 ToolkitTestApplication application;
531 tet_infoline("UtcTextureManagerUseInvalidMask");
533 TextureManager textureManager; // Create new texture manager
535 TestObserver observer;
536 std::string filename(TEST_IMAGE_FILE_NAME);
537 std::string maskname("");
538 TextureManager::MaskingDataPointer maskInfo = nullptr;
539 maskInfo.reset(new TextureManager::MaskingData());
540 maskInfo->mAlphaMaskUrl = maskname;
541 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
542 maskInfo->mCropToMask = true;
543 maskInfo->mContentScaleFactor = 1.0f;
545 auto textureId(TextureManager::INVALID_TEXTURE_ID);
546 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
547 Dali::ImageDimensions atlasRectSize(0, 0);
548 bool synchronousLoading(false);
549 bool atlasingStatus(false);
550 bool loadingStatus(false);
551 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
552 ImageAtlasManagerPtr atlasManager = nullptr;
553 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
555 textureManager.LoadTexture(
558 FittingMode::SCALE_TO_FILL,
559 SamplingMode::BOX_THEN_LINEAR,
573 TextureManager::ReloadPolicy::CACHED,
576 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
577 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
579 application.SendNotification();
580 application.Render();
582 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
584 application.SendNotification();
585 application.Render();
587 DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
588 DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
589 DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
594 int UtcTextureManagerSynchronousLoadingFail(void)
596 ToolkitTestApplication application;
597 tet_infoline("UtcTextureManagerSynchronousLoadingFail");
599 TextureManager textureManager; // Create new texture manager
601 std::string maskname("");
602 TextureManager::MaskingDataPointer maskInfo = nullptr;
603 maskInfo.reset(new TextureManager::MaskingData());
604 maskInfo->mAlphaMaskUrl = maskname;
605 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
606 maskInfo->mCropToMask = true;
607 maskInfo->mContentScaleFactor = 1.0f;
609 std::string filename("dummy");
610 auto textureId(TextureManager::INVALID_TEXTURE_ID);
611 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
612 Dali::ImageDimensions atlasRectSize(0, 0);
613 bool atlasingStatus(false);
614 bool loadingStatus(false);
615 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
616 ImageAtlasManagerPtr atlasManager = nullptr;
617 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
619 // load image synchronously.
620 TestObserver observer;
621 TextureSet textureSet = textureManager.LoadTexture(
624 FittingMode::SCALE_TO_FILL,
625 SamplingMode::BOX_THEN_LINEAR,
627 true, // synchronous loading.
639 TextureManager::ReloadPolicy::CACHED,
642 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
643 DALI_TEST_CHECK(!textureSet); // texture loading fail.
644 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
649 int UtcTextureManagerCachingSynchronousLoading(void)
651 ToolkitTestApplication application;
652 tet_infoline("UtcTextureManagerCachingSynchronousLoading");
654 TextureManager textureManager; // Create new texture manager
656 std::string filename(TEST_IMAGE_FILE_NAME);
658 std::string maskname("");
659 TextureManager::MaskingDataPointer maskInfo = nullptr;
660 maskInfo.reset(new TextureManager::MaskingData());
661 maskInfo->mAlphaMaskUrl = maskname;
662 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
663 maskInfo->mCropToMask = true;
664 maskInfo->mContentScaleFactor = 1.0f;
666 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
667 Dali::ImageDimensions atlasRectSize(0, 0);
668 bool atlasingStatus(false);
669 bool loadingStatus(false);
670 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
671 ImageAtlasManagerPtr atlasManager = nullptr;
672 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
674 // load image synchronously.
675 TestObserver observer;
676 auto textureId(TextureManager::INVALID_TEXTURE_ID);
677 TextureSet textureSet = textureManager.LoadTexture(
680 FittingMode::SCALE_TO_FILL,
681 SamplingMode::BOX_THEN_LINEAR,
683 true, // synchronous loading.
695 TextureManager::ReloadPolicy::CACHED,
698 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
699 DALI_TEST_CHECK(textureSet); // texture is loaded.
701 // observer isn't called in synchronous loading.
702 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
703 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
705 // load same image asynchronously.
706 TestObserver asyncObserver;
707 auto asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
708 loadingStatus = false;
709 TextureSet asyncTextureSet = textureManager.LoadTexture(
712 FittingMode::SCALE_TO_FILL,
713 SamplingMode::BOX_THEN_LINEAR,
715 false, // asynchronous loading.
727 TextureManager::ReloadPolicy::CACHED,
730 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
731 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
732 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
734 // observer is directly called because textureSet is retrieved by cache.
735 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
736 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
741 int UtcTextureManagerAsyncSyncAsync(void)
743 ToolkitTestApplication application;
744 tet_infoline("UtcTextureManagerAsyncSyncAsync");
746 TextureManager textureManager; // Create new texture manager
748 std::string filename(TEST_IMAGE_FILE_NAME);
750 std::string maskname("");
751 TextureManager::MaskingDataPointer maskInfo = nullptr;
752 maskInfo.reset(new TextureManager::MaskingData());
753 maskInfo->mAlphaMaskUrl = maskname;
754 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
755 maskInfo->mCropToMask = true;
756 maskInfo->mContentScaleFactor = 1.0f;
758 Vector4 atlasRect(0.f, 0.f, 0.f, 0.f);
759 Dali::ImageDimensions atlasRectSize(0, 0);
760 bool atlasingStatus(false);
761 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
762 ImageAtlasManagerPtr atlasManager = nullptr;
763 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
765 // load image asynchronously.
766 TestObserver asyncObserver1;
767 auto asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
768 bool asyncLoadingStatus1 = false;
769 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
772 FittingMode::SCALE_TO_FILL,
773 SamplingMode::BOX_THEN_LINEAR,
775 false, // asynchronous loading.
787 TextureManager::ReloadPolicy::CACHED,
790 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
791 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
793 // observer is still not called.
794 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
795 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
797 // load same image synchronously just after asynchronous loading.
798 TestObserver syncObserver;
799 auto textureId(TextureManager::INVALID_TEXTURE_ID);
800 bool syncLoadingStatus = false;
801 TextureSet syncTextureSet = textureManager.LoadTexture(
804 FittingMode::SCALE_TO_FILL,
805 SamplingMode::BOX_THEN_LINEAR,
807 true, // synchronous loading.
819 TextureManager::ReloadPolicy::CACHED,
822 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
823 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
824 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
826 // syncObserver isn't called in synchronous loading.
827 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
828 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
830 // asyncObserver1 is still not called too.
831 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
832 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
834 // load image asynchronously.
835 TestObserver asyncObserver2;
836 auto asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
837 bool asyncLoadingStatus2 = false;
838 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
841 FittingMode::SCALE_TO_FILL,
842 SamplingMode::BOX_THEN_LINEAR,
844 false, // asynchronous loading.
856 TextureManager::ReloadPolicy::CACHED,
859 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
860 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
861 DALI_TEST_CHECK(asyncTextureSet2 == syncTextureSet); // check loaded two texture is same.
863 // observer is called synchronously because the texture is cached.
864 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
865 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
867 asyncObserver2.mLoaded = false;
868 asyncObserver2.mObserverCalled = false;
870 application.SendNotification();
871 application.Render();
873 // Requested asynchronous loading at first is finished now and async observer is called now.
874 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
875 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
876 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
877 DALI_TEST_CHECK(asyncObserver1.mTextureSet == asyncTextureSet2); // check loaded two texture is same.
879 // asyncObserver2 was already called so it isn't called here.
880 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
881 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);