2 * Copyright (c) 2020 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-timer.h>
24 #include <toolkit-event-thread-callback.h>
25 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
26 #include <dali-toolkit/internal/visuals/texture-upload-observer.h>
27 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
28 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
29 #include <dali-toolkit/internal/visuals/visual-factory-impl.h> ///< For VisualFactory's member TextureManager.
31 #include <test-encoded-image-buffer.h>
33 #if defined(ELDBUS_ENABLED)
34 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
37 using namespace Dali::Toolkit::Internal;
39 void utc_dali_toolkit_texture_manager_startup(void)
41 setenv( "LOG_TEXTURE_MANAGER", "3", 1 );
42 test_return_value = TET_UNDEF;
43 #if defined(ELDBUS_ENABLED)
44 DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
48 void utc_dali_toolkit_texture_manager_cleanup(void)
50 test_return_value = TET_PASS;
56 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
60 class TestObserver : public Dali::Toolkit::TextureUploadObserver
63 enum class CompleteType
72 : mCompleteType( CompleteType::NOT_COMPLETED ),
74 mObserverCalled(false),
79 virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet,
80 bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override
82 mCompleteType = CompleteType::UPLOAD_COMPLETE;
83 mLoaded = loadSuccess;
84 mObserverCalled = true;
85 mTextureSet = textureSet;
88 virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override
90 mCompleteType = CompleteType::LOAD_COMPLETE;
91 mLoaded = loadSuccess;
92 mObserverCalled = true;
95 CompleteType mCompleteType;
98 TextureSet mTextureSet;
102 int UtcTextureManagerRequestLoad(void)
104 ToolkitTestApplication application;
106 TextureManager textureManager; // Create new texture manager
108 TestObserver observer;
109 std::string filename("image.png");
110 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
111 TextureManager::TextureId textureId = textureManager.RequestLoad(
114 FittingMode::SCALE_TO_FILL,
115 SamplingMode::BOX_THEN_LINEAR,
116 TextureManager::NO_ATLAS,
119 TextureManager::ReloadPolicy::CACHED,
122 VisualUrl url = textureManager.GetVisualUrl( textureId );
124 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
129 int UtcTextureManagerGenerateHash(void)
131 ToolkitTestApplication application;
133 TextureManager textureManager; // Create new texture manager
135 TestObserver observer;
136 std::string filename( "image.png" );
137 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
138 TextureManager::TextureId textureId = textureManager.RequestLoad(
141 FittingMode::SCALE_TO_FILL,
142 SamplingMode::BOX_THEN_LINEAR,
143 TextureManager::USE_ATLAS,
146 TextureManager::ReloadPolicy::CACHED,
149 VisualUrl url = textureManager.GetVisualUrl( textureId );
151 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
156 int UtcTextureManagerEncodedImageBuffer(void)
158 ToolkitTestApplication application;
159 tet_infoline( "UtcTextureManagerEncodedImageBuffer" );
161 auto visualFactory = Toolkit::VisualFactory::Get();
162 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
164 // Get encoded raw-buffer image and generate url
165 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
166 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
168 std::string url1 = textureManager.AddExternalEncodedImageBuffer(buffer1);
169 std::string url2 = textureManager.AddExternalEncodedImageBuffer(buffer1);
170 std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage
172 // Check if same EncodedImageBuffer get same url
173 DALI_TEST_CHECK(url1 == url2);
174 // Reduce reference count
175 textureManager.RemoveExternalEncodedImageBuffer(url1);
176 // Check whethere url1 still valid
177 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
179 url2 = textureManager.AddExternalEncodedImageBuffer(buffer2);
180 // Check if difference EncodedImageBuffer get difference url
181 DALI_TEST_CHECK(url1 != url2);
183 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
185 TestObserver observer1;
186 textureManager.RequestLoad(
189 FittingMode::SCALE_TO_FILL,
190 SamplingMode::BOX_THEN_LINEAR,
191 TextureManager::NO_ATLAS,
193 true, ///< orientationCorrection
194 TextureManager::ReloadPolicy::CACHED,
197 DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION );
198 DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION );
200 application.SendNotification();
201 application.Render();
203 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
205 application.SendNotification();
206 application.Render();
208 DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION );
209 DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION );
210 DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
212 TestObserver observer2;
214 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
217 FittingMode::SCALE_TO_FILL,
218 SamplingMode::BOX_THEN_LINEAR,
219 true, ///< synchronousLoading
221 true, ///< orientationCorrection
224 DALI_TEST_CHECK( pixelBuffer );
225 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
226 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
229 pixelBuffer = textureManager.LoadPixelBuffer(
232 FittingMode::SCALE_TO_FILL,
233 SamplingMode::BOX_THEN_LINEAR,
234 false, ///< synchronousLoading
236 true, ///< orientationCorrection
239 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
240 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
242 application.SendNotification();
243 application.Render();
245 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
247 application.SendNotification();
248 application.Render();
250 DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION );
251 DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION );
252 DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );
254 textureManager.RemoveExternalEncodedImageBuffer(url1);
255 textureManager.RemoveExternalEncodedImageBuffer(url2);
257 // Now url1 and url2 is invalid type. mLoaded will return false
259 TestObserver observer3;
260 textureManager.RequestLoad(
263 FittingMode::SCALE_TO_FILL,
264 SamplingMode::BOX_THEN_LINEAR,
265 TextureManager::NO_ATLAS,
267 true, ///< orientationCorrection
268 TextureManager::ReloadPolicy::CACHED,
271 // Load will be success because url1 is cached
272 DALI_TEST_EQUALS( observer3.mLoaded, true, TEST_LOCATION );
273 DALI_TEST_EQUALS( observer3.mObserverCalled, true, TEST_LOCATION );
274 DALI_TEST_EQUALS( observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
276 TestObserver observer4;
277 textureManager.RequestLoad(
280 FittingMode::SCALE_TO_FILL,
281 SamplingMode::BOX_THEN_LINEAR,
282 TextureManager::NO_ATLAS,
284 true, ///< orientationCorrection
285 TextureManager::ReloadPolicy::FORCED,
288 DALI_TEST_EQUALS( observer4.mLoaded, false, TEST_LOCATION );
289 DALI_TEST_EQUALS( observer4.mObserverCalled, false, TEST_LOCATION );
290 application.SendNotification();
291 application.Render();
293 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
295 application.SendNotification();
296 application.Render();
298 // Load will be failed becuase reloadpolicy is forced
299 DALI_TEST_EQUALS( observer4.mLoaded, false, TEST_LOCATION );
300 DALI_TEST_EQUALS( observer4.mObserverCalled, true, TEST_LOCATION );
301 DALI_TEST_EQUALS( observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
303 TestObserver observer5;
304 pixelBuffer = textureManager.LoadPixelBuffer(
307 FittingMode::SCALE_TO_FILL,
308 SamplingMode::BOX_THEN_LINEAR,
309 true, ///< synchronousLoading
311 true, ///< orientationCorrection
314 // Load will be faild because synchronousLoading doesn't use cached texture
315 DALI_TEST_CHECK( !pixelBuffer );
316 DALI_TEST_EQUALS( observer5.mLoaded, false, TEST_LOCATION );
317 DALI_TEST_EQUALS( observer5.mObserverCalled, false, TEST_LOCATION );
319 TestObserver observer6;
320 pixelBuffer = textureManager.LoadPixelBuffer(
323 FittingMode::SCALE_TO_FILL,
324 SamplingMode::BOX_THEN_LINEAR,
325 false, ///< synchronousLoading
327 true, ///< orientationCorrection
330 DALI_TEST_EQUALS( observer6.mLoaded, false, TEST_LOCATION );
331 DALI_TEST_EQUALS( observer6.mObserverCalled, false, TEST_LOCATION );
333 application.SendNotification();
334 application.Render();
336 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
338 application.SendNotification();
339 application.Render();
341 // Load will be failed because url3 is invalid URL
342 DALI_TEST_EQUALS( observer6.mLoaded, false, TEST_LOCATION );
343 DALI_TEST_EQUALS( observer6.mObserverCalled, true, TEST_LOCATION );
344 DALI_TEST_EQUALS( observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );
349 int UtcTextureManagerEncodedImageBufferReferenceCount(void)
351 ToolkitTestApplication application;
352 tet_infoline( "UtcTextureManagerEncodedImageBuffer check reference count works well" );
354 auto visualFactory = Toolkit::VisualFactory::Get();
355 auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
357 // Get encoded raw-buffer image and generate url
358 EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
359 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
361 std::string url1 = textureManager.AddExternalEncodedImageBuffer(buffer1);
362 std::string url2 = textureManager.AddExternalEncodedImageBuffer(buffer1);
364 // Check if same EncodedImageBuffer get same url
365 DALI_TEST_CHECK(url1 == url2);
367 // Reduce reference count
368 textureManager.RemoveExternalEncodedImageBuffer(url1);
369 // Check whethere url1 still valid
370 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
372 // Reduce reference count
373 textureManager.RemoveExternalEncodedImageBuffer(url1);
374 // Check whethere url1 is not valid anymore
375 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
377 // UseExternalTexture doesn't create new buffer.
378 // So, reference count is still zero.
379 textureManager.UseExternalResource(url1);
380 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
382 url1 = textureManager.AddExternalEncodedImageBuffer(buffer1);
383 // Check if difference EncodedImageBuffer get difference url
384 // Previous EncodedImageBuffer was deleted, so we get new url even same buffer.
385 DALI_TEST_CHECK(url1 != url2);
387 url2 = textureManager.AddExternalEncodedImageBuffer(buffer2);
388 // Check if difference EncodedImageBuffer get difference url
389 DALI_TEST_CHECK(url1 != url2);
391 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
393 // url1 load image by cache
394 TestObserver observer1;
395 textureManager.RequestLoad(
398 FittingMode::SCALE_TO_FILL,
399 SamplingMode::BOX_THEN_LINEAR,
400 TextureManager::NO_ATLAS,
402 true, ///< orientationCorrection
403 TextureManager::ReloadPolicy::CACHED,
406 DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION );
407 DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION );
409 application.SendNotification();
410 application.Render();
412 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
414 application.SendNotification();
415 application.Render();
417 DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION );
418 DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION );
419 DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
421 // LoadPixelBuffer doen't use cache. url2 will not be cached
422 TestObserver observer2;
423 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
426 FittingMode::SCALE_TO_FILL,
427 SamplingMode::BOX_THEN_LINEAR,
428 false, ///< synchronousLoading
430 true, ///< orientationCorrection
433 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
434 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
436 application.SendNotification();
437 application.Render();
439 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
441 application.SendNotification();
442 application.Render();
444 DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION );
445 DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION );
446 DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );
448 // Decrease each url's reference count.
449 textureManager.RemoveExternalEncodedImageBuffer(url1);
450 textureManager.RemoveExternalEncodedImageBuffer(url2);
452 // url1 buffer is still have 1 reference count because it is cached.
453 // But url2 not valid because it is not cached.
454 DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
455 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
457 // Check url1 buffer have 1 reference count because it is cached.
458 textureManager.RemoveExternalEncodedImageBuffer(url1);
459 DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
465 int UtcTextureManagerCachingForDifferentLoadingType(void)
467 ToolkitTestApplication application;
468 tet_infoline( "UtcTextureManagerCachingForDifferentLoadingType" );
470 TextureManager textureManager; // Create new texture manager
472 TestObserver observer1;
473 std::string filename( TEST_IMAGE_FILE_NAME );
474 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
475 textureManager.RequestLoad(
478 FittingMode::SCALE_TO_FILL,
479 SamplingMode::BOX_THEN_LINEAR,
480 TextureManager::NO_ATLAS,
483 TextureManager::ReloadPolicy::CACHED,
486 DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION );
487 DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION );
489 application.SendNotification();
490 application.Render();
492 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
494 application.SendNotification();
495 application.Render();
497 DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION );
498 DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION );
499 DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
501 TestObserver observer2;
502 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
505 FittingMode::SCALE_TO_FILL,
506 SamplingMode::BOX_THEN_LINEAR,
512 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
513 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
515 application.SendNotification();
516 application.Render();
518 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
520 application.SendNotification();
521 application.Render();
523 DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION );
524 DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION );
525 DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );
530 int UtcTextureManagerUseInvalidMask(void)
532 ToolkitTestApplication application;
533 tet_infoline( "UtcTextureManagerUseInvalidMask" );
535 TextureManager textureManager; // Create new texture manager
537 TestObserver observer;
538 std::string filename( TEST_IMAGE_FILE_NAME );
539 std::string maskname("");
540 TextureManager::MaskingDataPointer maskInfo = nullptr;
541 maskInfo.reset(new TextureManager::MaskingData());
542 maskInfo->mAlphaMaskUrl = maskname;
543 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
544 maskInfo->mCropToMask = true;
545 maskInfo->mContentScaleFactor = 1.0f;
547 auto textureId( TextureManager::INVALID_TEXTURE_ID );
548 Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f );
549 Dali::ImageDimensions atlasRectSize( 0,0 );
550 bool synchronousLoading(false);
551 bool atlasingStatus(false);
552 bool loadingStatus(false);
553 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
554 ImageAtlasManagerPtr atlasManager = nullptr;
555 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
557 textureManager.LoadTexture(
560 FittingMode::SCALE_TO_FILL,
561 SamplingMode::BOX_THEN_LINEAR,
575 TextureManager::ReloadPolicy::CACHED,
579 DALI_TEST_EQUALS( observer.mLoaded, false, TEST_LOCATION );
580 DALI_TEST_EQUALS( observer.mObserverCalled, false, TEST_LOCATION );
582 application.SendNotification();
583 application.Render();
585 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
587 application.SendNotification();
588 application.Render();
590 DALI_TEST_EQUALS( observer.mLoaded, true, TEST_LOCATION );
591 DALI_TEST_EQUALS( observer.mObserverCalled, true, TEST_LOCATION );
592 DALI_TEST_EQUALS( observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
597 int UtcTextureManagerSynchronousLoadingFail(void)
599 ToolkitTestApplication application;
600 tet_infoline( "UtcTextureManagerSynchronousLoadingFail" );
602 TextureManager textureManager; // Create new texture manager
604 std::string maskname("");
605 TextureManager::MaskingDataPointer maskInfo = nullptr;
606 maskInfo.reset(new TextureManager::MaskingData());
607 maskInfo->mAlphaMaskUrl = maskname;
608 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
609 maskInfo->mCropToMask = true;
610 maskInfo->mContentScaleFactor = 1.0f;
612 std::string filename("dummy");
613 auto textureId( TextureManager::INVALID_TEXTURE_ID );
614 Vector4 atlasRect( 0.f, 0.f, 0.f, 0.f );
615 Dali::ImageDimensions atlasRectSize( 0,0 );
616 bool atlasingStatus(false);
617 bool loadingStatus(false);
618 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
619 ImageAtlasManagerPtr atlasManager = nullptr;
620 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
622 // load image synchronously.
623 TestObserver observer;
624 TextureSet textureSet = textureManager.LoadTexture(
627 FittingMode::SCALE_TO_FILL,
628 SamplingMode::BOX_THEN_LINEAR,
630 true, // synchronous loading.
642 TextureManager::ReloadPolicy::CACHED,
646 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
647 DALI_TEST_CHECK(!textureSet); // texture loading fail.
648 DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
653 int UtcTextureManagerCachingSynchronousLoading(void)
655 ToolkitTestApplication application;
656 tet_infoline( "UtcTextureManagerCachingSynchronousLoading" );
658 TextureManager textureManager; // Create new texture manager
660 std::string filename( TEST_IMAGE_FILE_NAME );
662 std::string maskname("");
663 TextureManager::MaskingDataPointer maskInfo = nullptr;
664 maskInfo.reset(new TextureManager::MaskingData());
665 maskInfo->mAlphaMaskUrl = maskname;
666 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
667 maskInfo->mCropToMask = true;
668 maskInfo->mContentScaleFactor = 1.0f;
670 Vector4 atlasRect( 0.f, 0.f, 0.f, 0.f );
671 Dali::ImageDimensions atlasRectSize( 0,0 );
672 bool atlasingStatus(false);
673 bool loadingStatus(false);
674 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
675 ImageAtlasManagerPtr atlasManager = nullptr;
676 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
678 // load image synchronously.
679 TestObserver observer;
680 auto textureId( TextureManager::INVALID_TEXTURE_ID );
681 TextureSet textureSet = textureManager.LoadTexture(
684 FittingMode::SCALE_TO_FILL,
685 SamplingMode::BOX_THEN_LINEAR,
687 true, // synchronous loading.
699 TextureManager::ReloadPolicy::CACHED,
703 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
704 DALI_TEST_CHECK(textureSet); // texture is loaded.
706 // observer isn't called in synchronous loading.
707 DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
708 DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
711 // load same image asynchronously.
712 TestObserver asyncObserver;
713 auto asyncTextureId( TextureManager::INVALID_TEXTURE_ID );
714 loadingStatus = false;
715 TextureSet asyncTextureSet = textureManager.LoadTexture(
718 FittingMode::SCALE_TO_FILL,
719 SamplingMode::BOX_THEN_LINEAR,
721 false, // asynchronous loading.
733 TextureManager::ReloadPolicy::CACHED,
737 DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
738 DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
739 DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
741 // observer is directly called because textureSet is retrieved by cache.
742 DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
743 DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
748 int UtcTextureManagerAsyncSyncAsync(void)
750 ToolkitTestApplication application;
751 tet_infoline( "UtcTextureManagerAsyncSyncAsync" );
753 TextureManager textureManager; // Create new texture manager
755 std::string filename( TEST_IMAGE_FILE_NAME );
757 std::string maskname("");
758 TextureManager::MaskingDataPointer maskInfo = nullptr;
759 maskInfo.reset(new TextureManager::MaskingData());
760 maskInfo->mAlphaMaskUrl = maskname;
761 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
762 maskInfo->mCropToMask = true;
763 maskInfo->mContentScaleFactor = 1.0f;
765 Vector4 atlasRect( 0.f, 0.f, 0.f, 0.f );
766 Dali::ImageDimensions atlasRectSize( 0,0 );
767 bool atlasingStatus(false);
768 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
769 ImageAtlasManagerPtr atlasManager = nullptr;
770 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
772 // load image asynchronously.
773 TestObserver asyncObserver1;
774 auto asyncTextureId1( TextureManager::INVALID_TEXTURE_ID );
775 bool asyncLoadingStatus1 = false;
776 TextureSet asyncTextureSet1 = textureManager.LoadTexture(
779 FittingMode::SCALE_TO_FILL,
780 SamplingMode::BOX_THEN_LINEAR,
782 false, // asynchronous loading.
794 TextureManager::ReloadPolicy::CACHED,
798 DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
799 DALI_TEST_CHECK(!asyncTextureSet1); // texture is not loaded yet.
801 // observer is still not called.
802 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
803 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
806 // load same image synchronously just after asynchronous loading.
807 TestObserver syncObserver;
808 auto textureId( TextureManager::INVALID_TEXTURE_ID );
809 bool syncLoadingStatus = false;
810 TextureSet syncTextureSet = textureManager.LoadTexture(
813 FittingMode::SCALE_TO_FILL,
814 SamplingMode::BOX_THEN_LINEAR,
816 true, // synchronous loading.
828 TextureManager::ReloadPolicy::CACHED,
832 DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
833 DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION); // texture is loaded.
834 DALI_TEST_CHECK(syncTextureSet); // texture is loaded.
836 // syncObserver isn't called in synchronous loading.
837 DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
838 DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
840 // asyncObserver1 is still not called too.
841 DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
842 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
846 // load image asynchronously.
847 TestObserver asyncObserver2;
848 auto asyncTextureId2( TextureManager::INVALID_TEXTURE_ID );
849 bool asyncLoadingStatus2 = false;
850 TextureSet asyncTextureSet2 = textureManager.LoadTexture(
853 FittingMode::SCALE_TO_FILL,
854 SamplingMode::BOX_THEN_LINEAR,
856 false, // asynchronous loading.
868 TextureManager::ReloadPolicy::CACHED,
872 DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
873 DALI_TEST_CHECK(asyncTextureSet2); // texture is loaded
874 DALI_TEST_CHECK(asyncTextureSet2 == syncTextureSet); // check loaded two texture is same.
876 // observer is called synchronously because the texture is cached.
877 DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
878 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
880 asyncObserver2.mLoaded = false;
881 asyncObserver2.mObserverCalled = false;
883 application.SendNotification();
884 application.Render();
886 // Requested asynchronous loading at first is finished now and async observer is called now.
887 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
888 DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
889 DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
890 DALI_TEST_CHECK(asyncObserver1.mTextureSet == asyncTextureSet2); // check loaded two texture is same.
892 // asyncObserver2 was already called so it isn't called here.
893 DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
894 DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);