[dali_2.1.40] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextureManager.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-event-thread-callback.h>
24 #include <toolkit-timer.h>
25
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>
32
33 #include <test-encoded-image-buffer.h>
34
35 #if defined(ELDBUS_ENABLED)
36 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
37 #endif
38
39 using namespace Dali::Toolkit::Internal;
40
41 void utc_dali_toolkit_texture_manager_startup(void)
42 {
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));
47 #endif
48 }
49
50 void utc_dali_toolkit_texture_manager_cleanup(void)
51 {
52   test_return_value = TET_PASS;
53 }
54
55 namespace
56 {
57 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
58 const char* TEST_MASK_FILE_NAME  = TEST_RESOURCE_DIR "/mask.png";
59
60 class TestObserver : public Dali::Toolkit::TextureUploadObserver
61 {
62 public:
63   enum class CompleteType
64   {
65     NOT_COMPLETED = 0,
66     UPLOAD_COMPLETE,
67     LOAD_COMPLETE
68   };
69
70 public:
71   TestObserver()
72   : mCompleteType(CompleteType::NOT_COMPLETED),
73     mLoaded(false),
74     mObserverCalled(false),
75     mTextureSet()
76   {
77   }
78
79   virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
80   {
81     if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
82     {
83       mCompleteType = CompleteType::UPLOAD_COMPLETE;
84     }
85     else
86     {
87       mCompleteType = CompleteType::LOAD_COMPLETE;
88     }
89     mLoaded         = loadSuccess;
90     mObserverCalled = true;
91     mTextureSet     = textureInformation.textureSet;
92   }
93
94   CompleteType mCompleteType;
95   bool         mLoaded;
96   bool         mObserverCalled;
97   TextureSet   mTextureSet;
98 };
99
100 class TestObserverRemoveAndGenerateUrl : public TestObserver
101 {
102 public:
103   TestObserverRemoveAndGenerateUrl(TextureManager* textureManagerPtr)
104   : TestObserver(),
105     mTextureManagerPtr(textureManagerPtr)
106   {
107   }
108
109   virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override
110   {
111     if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
112     {
113       mCompleteType = CompleteType::UPLOAD_COMPLETE;
114     }
115     else
116     {
117       mCompleteType = CompleteType::LOAD_COMPLETE;
118     }
119     mLoaded         = loadSuccess;
120     mObserverCalled = true;
121     mTextureSet     = textureInformation.textureSet;
122
123     // Remove during LoadComplete
124     mTextureManagerPtr->Remove(textureInformation.textureId, nullptr);
125
126     // ...And generate string which using texture id.
127     mGeneratedExternalUrl = mTextureManagerPtr->AddExternalTexture(mTextureSet);
128   }
129
130 public:
131   std::string mGeneratedExternalUrl;
132
133 protected:
134   TextureManager* mTextureManagerPtr; // Keep the pointer of texture manager.
135 };
136
137 } // namespace
138
139 int UtcTextureManagerRequestLoad(void)
140 {
141   ToolkitTestApplication application;
142
143   TextureManager textureManager; // Create new texture manager
144
145   TestObserver              observer;
146   std::string               filename("image.png");
147   auto                      preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
148   TextureManager::TextureId textureId   = textureManager.RequestLoad(
149     filename,
150     ImageDimensions(),
151     FittingMode::SCALE_TO_FILL,
152     SamplingMode::BOX_THEN_LINEAR,
153     TextureManager::UseAtlas::NO_ATLAS,
154     &observer,
155     true,
156     TextureManager::ReloadPolicy::CACHED,
157     preMultiply);
158
159   VisualUrl url = textureManager.GetVisualUrl(textureId);
160
161   DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
162
163   END_TEST;
164 }
165
166 int UtcTextureManagerGenerateHash(void)
167 {
168   ToolkitTestApplication application;
169
170   TextureManager textureManager; // Create new texture manager
171
172   TestObserver              observer;
173   std::string               filename("image.png");
174   auto                      preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
175   TextureManager::TextureId textureId   = textureManager.RequestLoad(
176     filename,
177     ImageDimensions(),
178     FittingMode::SCALE_TO_FILL,
179     SamplingMode::BOX_THEN_LINEAR,
180     TextureManager::UseAtlas::NO_ATLAS,
181     &observer,
182     true,
183     TextureManager::ReloadPolicy::CACHED,
184     preMultiply);
185
186   VisualUrl url = textureManager.GetVisualUrl(textureId);
187
188   DALI_TEST_EQUALS(url.GetUrl().compare(filename), 0, TEST_LOCATION);
189
190   END_TEST;
191 }
192
193 int UtcTextureManagerEncodedImageBuffer(void)
194 {
195   ToolkitTestApplication application;
196   tet_infoline("UtcTextureManagerEncodedImageBuffer");
197
198   auto  visualFactory  = Toolkit::VisualFactory::Get();
199   auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
200
201   // Get encoded raw-buffer image and generate url
202   EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
203   EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
204
205   std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
206   std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
207   std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage
208
209   // Check if same EncodedImageBuffer get same url
210   DALI_TEST_CHECK(url1 == url2);
211   // Reduce reference count
212   textureManager.RemoveEncodedImageBuffer(url1);
213   // Check whethere url1 still valid
214   DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
215
216   url2 = textureManager.AddEncodedImageBuffer(buffer2);
217   // Check if difference EncodedImageBuffer get difference url
218   DALI_TEST_CHECK(url1 != url2);
219
220   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
221
222   TestObserver observer1;
223   textureManager.RequestLoad(
224     url1,
225     ImageDimensions(),
226     FittingMode::SCALE_TO_FILL,
227     SamplingMode::BOX_THEN_LINEAR,
228     TextureManager::UseAtlas::NO_ATLAS,
229     &observer1,
230     true, ///< orientationCorrection
231     TextureManager::ReloadPolicy::CACHED,
232     preMultiply);
233
234   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
235   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
236
237   application.SendNotification();
238   application.Render();
239
240   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
241
242   application.SendNotification();
243   application.Render();
244
245   DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
246   DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
247   DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
248
249   TestObserver observer2;
250   // Syncload
251   Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
252     url2,
253     ImageDimensions(),
254     FittingMode::SCALE_TO_FILL,
255     SamplingMode::BOX_THEN_LINEAR,
256     true, ///< synchronousLoading
257     &observer2,
258     true, ///< orientationCorrection
259     preMultiply);
260
261   DALI_TEST_CHECK(pixelBuffer);
262   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
263   DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
264
265   // Asyncload
266   pixelBuffer = textureManager.LoadPixelBuffer(
267     url2,
268     ImageDimensions(),
269     FittingMode::SCALE_TO_FILL,
270     SamplingMode::BOX_THEN_LINEAR,
271     false, ///< synchronousLoading
272     &observer2,
273     true, ///< orientationCorrection
274     preMultiply);
275
276   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
277   DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
278
279   application.SendNotification();
280   application.Render();
281
282   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
283
284   application.SendNotification();
285   application.Render();
286
287   DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
288   DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
289   DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
290
291   textureManager.RemoveEncodedImageBuffer(url1);
292   textureManager.RemoveEncodedImageBuffer(url2);
293
294   // Now url1 and url2 is invalid type. mLoaded will return false
295
296   TestObserver observer3;
297   textureManager.RequestLoad(
298     url1,
299     ImageDimensions(),
300     FittingMode::SCALE_TO_FILL,
301     SamplingMode::BOX_THEN_LINEAR,
302     TextureManager::UseAtlas::NO_ATLAS,
303     &observer3,
304     true, ///< orientationCorrection
305     TextureManager::ReloadPolicy::CACHED,
306     preMultiply);
307
308   // Load will be success because url1 is cached
309   DALI_TEST_EQUALS(observer3.mLoaded, true, TEST_LOCATION);
310   DALI_TEST_EQUALS(observer3.mObserverCalled, true, TEST_LOCATION);
311   DALI_TEST_EQUALS(observer3.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
312
313   TestObserver observer4;
314   textureManager.RequestLoad(
315     url2,
316     ImageDimensions(),
317     FittingMode::SCALE_TO_FILL,
318     SamplingMode::BOX_THEN_LINEAR,
319     TextureManager::UseAtlas::NO_ATLAS,
320     &observer4,
321     true, ///< orientationCorrection
322     TextureManager::ReloadPolicy::FORCED,
323     preMultiply);
324
325   DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
326   DALI_TEST_EQUALS(observer4.mObserverCalled, false, TEST_LOCATION);
327   application.SendNotification();
328   application.Render();
329
330   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
331
332   application.SendNotification();
333   application.Render();
334
335   // Load will be failed becuase reloadpolicy is forced
336   DALI_TEST_EQUALS(observer4.mLoaded, false, TEST_LOCATION);
337   DALI_TEST_EQUALS(observer4.mObserverCalled, true, TEST_LOCATION);
338   DALI_TEST_EQUALS(observer4.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
339
340   TestObserver observer5;
341   pixelBuffer = textureManager.LoadPixelBuffer(
342     url2,
343     ImageDimensions(),
344     FittingMode::SCALE_TO_FILL,
345     SamplingMode::BOX_THEN_LINEAR,
346     true, ///< synchronousLoading
347     &observer5,
348     true, ///< orientationCorrection
349     preMultiply);
350
351   // Load will be faild because synchronousLoading doesn't use cached texture
352   DALI_TEST_CHECK(!pixelBuffer);
353   DALI_TEST_EQUALS(observer5.mLoaded, false, TEST_LOCATION);
354   DALI_TEST_EQUALS(observer5.mObserverCalled, false, TEST_LOCATION);
355
356   TestObserver observer6;
357   pixelBuffer = textureManager.LoadPixelBuffer(
358     url3,
359     ImageDimensions(),
360     FittingMode::SCALE_TO_FILL,
361     SamplingMode::BOX_THEN_LINEAR,
362     false, ///< synchronousLoading
363     &observer6,
364     true, ///< orientationCorrection
365     preMultiply);
366
367   DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
368   DALI_TEST_EQUALS(observer6.mObserverCalled, false, TEST_LOCATION);
369
370   application.SendNotification();
371   application.Render();
372
373   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
374
375   application.SendNotification();
376   application.Render();
377
378   // Load will be failed because url3 is invalid URL
379   DALI_TEST_EQUALS(observer6.mLoaded, false, TEST_LOCATION);
380   DALI_TEST_EQUALS(observer6.mObserverCalled, true, TEST_LOCATION);
381   DALI_TEST_EQUALS(observer6.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
382
383   END_TEST;
384 }
385
386 int UtcTextureManagerEncodedImageBufferReferenceCount(void)
387 {
388   ToolkitTestApplication application;
389   tet_infoline("UtcTextureManagerEncodedImageBuffer check reference count works well");
390
391   auto  visualFactory  = Toolkit::VisualFactory::Get();
392   auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
393
394   // Get encoded raw-buffer image and generate url
395   EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
396   EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_IMAGE_FILE_NAME);
397
398   std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
399   std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
400
401   // Check if same EncodedImageBuffer get same url
402   DALI_TEST_CHECK(url1 == url2);
403
404   // Reduce reference count
405   textureManager.RemoveEncodedImageBuffer(url1);
406   // Check whethere url1 still valid
407   DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
408
409   // Reduce reference count
410   textureManager.RemoveEncodedImageBuffer(url1);
411   // Check whethere url1 is not valid anymore
412   DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
413
414   // UseExternalTexture doesn't create new buffer.
415   // So, reference count is still zero.
416   textureManager.UseExternalResource(url1);
417   DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
418
419   url1 = textureManager.AddEncodedImageBuffer(buffer1);
420
421   url2 = textureManager.AddEncodedImageBuffer(buffer2);
422   // Check if difference EncodedImageBuffer get difference url
423   DALI_TEST_CHECK(url1 != url2);
424
425   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
426
427   // url1 load image by cache
428   TestObserver observer1;
429   textureManager.RequestLoad(
430     url1,
431     ImageDimensions(),
432     FittingMode::SCALE_TO_FILL,
433     SamplingMode::BOX_THEN_LINEAR,
434     TextureManager::UseAtlas::NO_ATLAS,
435     &observer1,
436     true, ///< orientationCorrection
437     TextureManager::ReloadPolicy::CACHED,
438     preMultiply);
439
440   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
441   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
442
443   application.SendNotification();
444   application.Render();
445
446   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
447
448   application.SendNotification();
449   application.Render();
450
451   DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
452   DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
453   DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
454
455   // LoadPixelBuffer doen't use cache. url2 will not be cached
456   TestObserver       observer2;
457   Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
458     url2,
459     ImageDimensions(),
460     FittingMode::SCALE_TO_FILL,
461     SamplingMode::BOX_THEN_LINEAR,
462     false, ///< synchronousLoading
463     &observer2,
464     true, ///< orientationCorrection
465     preMultiply);
466
467   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
468   DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
469
470   application.SendNotification();
471   application.Render();
472
473   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
474
475   application.SendNotification();
476   application.Render();
477
478   DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
479   DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
480   DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
481
482   // Decrease each url's reference count.
483   textureManager.RemoveEncodedImageBuffer(url1);
484   textureManager.RemoveEncodedImageBuffer(url2);
485
486   // url1 buffer is still have 1 reference count because it is cached.
487   // But url2 not valid because it is not cached.
488   DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
489   DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
490
491   // Check url1 buffer have 1 reference count because it is cached.
492   textureManager.RemoveEncodedImageBuffer(url1);
493   DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1));
494
495   END_TEST;
496 }
497
498 int UtcTextureManagerCachingForDifferentLoadingType(void)
499 {
500   ToolkitTestApplication application;
501   tet_infoline("UtcTextureManagerCachingForDifferentLoadingType");
502
503   TextureManager textureManager; // Create new texture manager
504
505   TestObserver observer1;
506   std::string  filename(TEST_IMAGE_FILE_NAME);
507   auto         preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
508   textureManager.RequestLoad(
509     filename,
510     ImageDimensions(),
511     FittingMode::SCALE_TO_FILL,
512     SamplingMode::BOX_THEN_LINEAR,
513     TextureManager::UseAtlas::NO_ATLAS,
514     &observer1,
515     true,
516     TextureManager::ReloadPolicy::CACHED,
517     preMultiply);
518
519   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
520   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
521
522   application.SendNotification();
523   application.Render();
524
525   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
526
527   application.SendNotification();
528   application.Render();
529
530   DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION);
531   DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION);
532   DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
533
534   TestObserver       observer2;
535   Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
536     filename,
537     ImageDimensions(),
538     FittingMode::SCALE_TO_FILL,
539     SamplingMode::BOX_THEN_LINEAR,
540     false,
541     &observer2,
542     true,
543     preMultiply);
544
545   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
546   DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
547
548   application.SendNotification();
549   application.Render();
550
551   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
552
553   application.SendNotification();
554   application.Render();
555
556   DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION);
557   DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
558   DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION);
559
560   END_TEST;
561 }
562
563 int UtcTextureManagerUseInvalidMask(void)
564 {
565   ToolkitTestApplication application;
566   tet_infoline("UtcTextureManagerUseInvalidMask");
567
568   TextureManager textureManager; // Create new texture manager
569
570   TestObserver                       observer;
571   std::string                        filename(TEST_IMAGE_FILE_NAME);
572   std::string                        maskname("");
573   TextureManager::MaskingDataPointer maskInfo = nullptr;
574   maskInfo.reset(new TextureManager::MaskingData());
575   maskInfo->mAlphaMaskUrl       = maskname;
576   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
577   maskInfo->mCropToMask         = true;
578   maskInfo->mContentScaleFactor = 1.0f;
579
580   auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
581   Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
582   Dali::ImageDimensions         atlasRectSize(0, 0);
583   bool                          synchronousLoading(false);
584   bool                          atlasingStatus(false);
585   bool                          loadingStatus(false);
586   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
587   ImageAtlasManagerPtr          atlasManager        = nullptr;
588   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
589
590   textureManager.LoadTexture(
591     filename,
592     ImageDimensions(),
593     FittingMode::SCALE_TO_FILL,
594     SamplingMode::BOX_THEN_LINEAR,
595     maskInfo,
596     synchronousLoading,
597     textureId,
598     atlasRect,
599     atlasRectSize,
600     atlasingStatus,
601     loadingStatus,
602     &observer,
603     atlasUploadObserver,
604     atlasManager,
605     true,
606     TextureManager::ReloadPolicy::CACHED,
607     preMultiply);
608
609   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
610   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
611
612   application.SendNotification();
613   application.Render();
614
615   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
616
617   application.SendNotification();
618   application.Render();
619
620   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
621   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
622   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
623
624   END_TEST;
625 }
626
627 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
628 {
629   ToolkitTestApplication application;
630   tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
631   tet_infoline("Try to check PostLoad works well");
632
633   TextureManager textureManager; // Create new texture manager
634
635   TestObserver                       observer;
636   std::string                        filename(TEST_IMAGE_FILE_NAME);
637   std::string                        maskname("invalid.png");
638   TextureManager::MaskingDataPointer maskInfo = nullptr;
639   maskInfo.reset(new TextureManager::MaskingData());
640   maskInfo->mAlphaMaskUrl       = maskname;
641   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
642   maskInfo->mCropToMask         = true;
643   maskInfo->mContentScaleFactor = 1.0f;
644
645   auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
646   Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
647   Dali::ImageDimensions         atlasRectSize(0, 0);
648   bool                          synchronousLoading(false);
649   bool                          atlasingStatus(false);
650   bool                          loadingStatus(false);
651   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
652   ImageAtlasManagerPtr          atlasManager        = nullptr;
653   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
654
655   textureManager.LoadTexture(
656     filename,
657     ImageDimensions(),
658     FittingMode::SCALE_TO_FILL,
659     SamplingMode::BOX_THEN_LINEAR,
660     maskInfo,
661     synchronousLoading,
662     textureId,
663     atlasRect,
664     atlasRectSize,
665     atlasingStatus,
666     loadingStatus,
667     &observer,
668     atlasUploadObserver,
669     atlasManager,
670     true,
671     TextureManager::ReloadPolicy::CACHED,
672     preMultiply);
673
674   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
675   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
676
677   application.SendNotification();
678   application.Render();
679
680   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
681
682   application.SendNotification();
683   application.Render();
684
685   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
686   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
687   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
688
689   END_TEST;
690 }
691
692 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
693 {
694   ToolkitTestApplication application;
695   tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
696   tet_infoline("Try to check CheckForWaitingTexture called");
697
698   TextureManager textureManager; // Create new texture manager
699
700   TestObserver                       observer;
701   std::string                        filename(TEST_IMAGE_FILE_NAME);
702   std::string                        maskname("invalid.png");
703   TextureManager::MaskingDataPointer maskInfo = nullptr;
704   maskInfo.reset(new TextureManager::MaskingData());
705   maskInfo->mAlphaMaskUrl       = maskname;
706   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
707   maskInfo->mCropToMask         = true;
708   maskInfo->mContentScaleFactor = 1.0f;
709
710   auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
711   Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
712   Dali::ImageDimensions         atlasRectSize(0, 0);
713   bool                          synchronousLoading(false);
714   bool                          atlasingStatus(false);
715   bool                          loadingStatus(false);
716   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
717   ImageAtlasManagerPtr          atlasManager        = nullptr;
718   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
719
720   textureManager.LoadTexture(
721     filename,
722     ImageDimensions(),
723     FittingMode::SCALE_TO_FILL,
724     SamplingMode::BOX_THEN_LINEAR,
725     maskInfo,
726     synchronousLoading,
727     textureId,
728     atlasRect,
729     atlasRectSize,
730     atlasingStatus,
731     loadingStatus,
732     &observer,
733     atlasUploadObserver,
734     atlasManager,
735     true,
736     TextureManager::ReloadPolicy::CACHED,
737     preMultiply);
738
739   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
740   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
741
742   application.SendNotification();
743   application.Render();
744
745   // CAPTION : HARD-CODING for coverage. If you are a good boy, Do not follow this code.
746   {
747     Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
748       filename,
749       ImageDimensions(),
750       FittingMode::SCALE_TO_FILL,
751       SamplingMode::BOX_THEN_LINEAR,
752       true, ///< synchronousLoading
753       nullptr,
754       true, ///< orientationCorrection
755       preMultiply);
756
757     std::vector<Devel::PixelBuffer> pixelBuffers;
758     pixelBuffers.push_back(pixelBuffer);
759     textureManager.AsyncLoadComplete(textureId, pixelBuffers);
760     std::vector<Devel::PixelBuffer> maskBuffers;
761     textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
762     textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
763     textureManager.Remove(textureId, &observer);
764   }
765
766   application.SendNotification();
767   application.Render();
768
769   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
770   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
771   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
772
773   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
774
775   END_TEST;
776 }
777
778 int UtcTextureManagerSynchronousLoadingFail(void)
779 {
780   ToolkitTestApplication application;
781   tet_infoline("UtcTextureManagerSynchronousLoadingFail");
782
783   TextureManager textureManager; // Create new texture manager
784
785   std::string                        maskname("");
786   TextureManager::MaskingDataPointer maskInfo = nullptr;
787   maskInfo.reset(new TextureManager::MaskingData());
788   maskInfo->mAlphaMaskUrl       = maskname;
789   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
790   maskInfo->mCropToMask         = true;
791   maskInfo->mContentScaleFactor = 1.0f;
792
793   std::string                   filename("dummy");
794   auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
795   Vector4                       atlasRect(0.f, 0.f, 0.f, 0.f);
796   Dali::ImageDimensions         atlasRectSize(0, 0);
797   bool                          atlasingStatus(false);
798   bool                          loadingStatus(false);
799   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
800   ImageAtlasManagerPtr          atlasManager        = nullptr;
801   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
802
803   // load image synchronously.
804   TestObserver observer;
805   TextureSet   textureSet = textureManager.LoadTexture(
806     filename,
807     ImageDimensions(),
808     FittingMode::SCALE_TO_FILL,
809     SamplingMode::BOX_THEN_LINEAR,
810     maskInfo,
811     true, // synchronous loading.
812     textureId,
813     atlasRect,
814     atlasRectSize,
815     atlasingStatus,
816     loadingStatus,
817     &observer,
818     atlasUploadObserver,
819     atlasManager,
820     true,
821     TextureManager::ReloadPolicy::CACHED,
822     preMultiply);
823
824   DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
825   DALI_TEST_CHECK(!textureSet);                                     // texture loading fail.
826   DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
827
828   END_TEST;
829 }
830
831 int UtcTextureManagerCachingSynchronousLoading(void)
832 {
833   ToolkitTestApplication application;
834   tet_infoline("UtcTextureManagerCachingSynchronousLoading");
835
836   TextureManager textureManager; // Create new texture manager
837
838   std::string filename(TEST_IMAGE_FILE_NAME);
839
840   std::string                        maskname("");
841   TextureManager::MaskingDataPointer maskInfo = nullptr;
842   maskInfo.reset(new TextureManager::MaskingData());
843   maskInfo->mAlphaMaskUrl       = maskname;
844   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
845   maskInfo->mCropToMask         = true;
846   maskInfo->mContentScaleFactor = 1.0f;
847
848   Vector4                       atlasRect(0.f, 0.f, 0.f, 0.f);
849   Dali::ImageDimensions         atlasRectSize(0, 0);
850   bool                          atlasingStatus(false);
851   bool                          loadingStatus(false);
852   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
853   ImageAtlasManagerPtr          atlasManager        = nullptr;
854   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
855
856   // load image synchronously.
857   TestObserver observer;
858   auto         textureId(TextureManager::INVALID_TEXTURE_ID);
859   TextureSet   textureSet = textureManager.LoadTexture(
860     filename,
861     ImageDimensions(),
862     FittingMode::SCALE_TO_FILL,
863     SamplingMode::BOX_THEN_LINEAR,
864     maskInfo,
865     true, // synchronous loading.
866     textureId,
867     atlasRect,
868     atlasRectSize,
869     atlasingStatus,
870     loadingStatus,
871     &observer,
872     atlasUploadObserver,
873     atlasManager,
874     true,
875     TextureManager::ReloadPolicy::CACHED,
876     preMultiply);
877
878   DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
879   DALI_TEST_CHECK(textureSet); // texture is loaded.
880
881   // observer isn't called in synchronous loading.
882   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
883   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
884
885   // load same image asynchronously.
886   TestObserver asyncObserver;
887   auto         asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
888   loadingStatus              = false;
889   TextureSet asyncTextureSet = textureManager.LoadTexture(
890     filename,
891     ImageDimensions(),
892     FittingMode::SCALE_TO_FILL,
893     SamplingMode::BOX_THEN_LINEAR,
894     maskInfo,
895     false, // asynchronous loading.
896     asyncTextureId,
897     atlasRect,
898     atlasRectSize,
899     atlasingStatus,
900     loadingStatus,
901     &asyncObserver,
902     atlasUploadObserver,
903     atlasManager,
904     true,
905     TextureManager::ReloadPolicy::CACHED,
906     preMultiply);
907
908   DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
909   DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
910   DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
911
912   // observer is directly called because textureSet is retrieved by cache.
913   DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
914   DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
915
916   END_TEST;
917 }
918
919 int UtcTextureManagerAsyncSyncAsync(void)
920 {
921   ToolkitTestApplication application;
922   tet_infoline("UtcTextureManagerAsyncSyncAsync");
923
924   TextureManager textureManager; // Create new texture manager
925
926   std::string filename(TEST_IMAGE_FILE_NAME);
927
928   std::string                        maskname("");
929   TextureManager::MaskingDataPointer maskInfo = nullptr;
930   maskInfo.reset(new TextureManager::MaskingData());
931   maskInfo->mAlphaMaskUrl       = maskname;
932   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
933   maskInfo->mCropToMask         = true;
934   maskInfo->mContentScaleFactor = 1.0f;
935
936   Vector4                       atlasRect(0.f, 0.f, 0.f, 0.f);
937   Dali::ImageDimensions         atlasRectSize(0, 0);
938   bool                          atlasingStatus(false);
939   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
940   ImageAtlasManagerPtr          atlasManager        = nullptr;
941   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
942
943   // load image asynchronously.
944   TestObserver asyncObserver1;
945   auto         asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
946   bool         asyncLoadingStatus1 = false;
947   TextureSet   asyncTextureSet1    = textureManager.LoadTexture(
948     filename,
949     ImageDimensions(),
950     FittingMode::SCALE_TO_FILL,
951     SamplingMode::BOX_THEN_LINEAR,
952     maskInfo,
953     false, // asynchronous loading.
954     asyncTextureId1,
955     atlasRect,
956     atlasRectSize,
957     atlasingStatus,
958     asyncLoadingStatus1,
959     &asyncObserver1,
960     atlasUploadObserver,
961     atlasManager,
962     true,
963     TextureManager::ReloadPolicy::CACHED,
964     preMultiply);
965
966   DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
967   DALI_TEST_CHECK(!asyncTextureSet1);                         // texture is not loaded yet.
968
969   // observer is still not called.
970   DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
971   DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
972
973   // load same image synchronously just after asynchronous loading.
974   TestObserver syncObserver;
975   auto         textureId(TextureManager::INVALID_TEXTURE_ID);
976   bool         syncLoadingStatus = false;
977   TextureSet   syncTextureSet    = textureManager.LoadTexture(
978     filename,
979     ImageDimensions(),
980     FittingMode::SCALE_TO_FILL,
981     SamplingMode::BOX_THEN_LINEAR,
982     maskInfo,
983     true, // synchronous loading.
984     textureId,
985     atlasRect,
986     atlasRectSize,
987     atlasingStatus,
988     syncLoadingStatus,
989     &syncObserver,
990     atlasUploadObserver,
991     atlasManager,
992     true,
993     TextureManager::ReloadPolicy::CACHED,
994     preMultiply);
995
996   DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
997   DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION);   // texture is loaded.
998   DALI_TEST_CHECK(syncTextureSet);                             // texture is loaded.
999
1000   // syncObserver isn't called in synchronous loading.
1001   DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1002   DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1003
1004   // asyncObserver1 is still not called too.
1005   DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1006   DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1007
1008   // load image asynchronously.
1009   TestObserver asyncObserver2;
1010   auto         asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1011   bool         asyncLoadingStatus2 = false;
1012   TextureSet   asyncTextureSet2    = textureManager.LoadTexture(
1013     filename,
1014     ImageDimensions(),
1015     FittingMode::SCALE_TO_FILL,
1016     SamplingMode::BOX_THEN_LINEAR,
1017     maskInfo,
1018     false, // asynchronous loading.
1019     asyncTextureId2,
1020     atlasRect,
1021     atlasRectSize,
1022     atlasingStatus,
1023     asyncLoadingStatus2,
1024     &asyncObserver2,
1025     atlasUploadObserver,
1026     atlasManager,
1027     true,
1028     TextureManager::ReloadPolicy::CACHED,
1029     preMultiply);
1030
1031   DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1032   DALI_TEST_CHECK(asyncTextureSet2);                           // texture is loaded
1033   Texture syncTexture   = syncTextureSet.GetTexture(0u);
1034   Texture asyncTexture2 = asyncTextureSet2.GetTexture(0u);
1035   DALI_TEST_CHECK(syncTexture);
1036   DALI_TEST_CHECK(asyncTexture2);
1037   DALI_TEST_CHECK(asyncTexture2 == syncTexture);               // check loaded two texture is same.
1038
1039   // observer is called synchronously because the texture is cached.
1040   DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1041   DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1042
1043   asyncObserver2.mLoaded         = false;
1044   asyncObserver2.mObserverCalled = false;
1045
1046   application.SendNotification();
1047   application.Render();
1048
1049   // Requested asynchronous loading at first is finished now and async observer is called now.
1050   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1051   DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1052   DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1053   DALI_TEST_CHECK(asyncObserver1.mTextureSet);
1054
1055   Texture observerTexture = asyncObserver1.mTextureSet.GetTexture(0u);
1056   DALI_TEST_CHECK(observerTexture == asyncTexture2); // check loaded two texture is same.
1057
1058   // asyncObserver2 was already called so it isn't called here.
1059   DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1060   DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1061
1062   END_TEST;
1063 }
1064
1065 int UtcTextureManagerQueueRemoveDuringObserve(void)
1066 {
1067   ToolkitTestApplication application;
1068   tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1069
1070   TextureManager textureManager; // Create new texture manager
1071
1072   TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1073
1074   std::string filename(TEST_IMAGE_FILE_NAME);
1075   auto        preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1076
1077   TextureManager::TextureId textureId = textureManager.RequestLoad(
1078     filename,
1079     ImageDimensions(),
1080     FittingMode::SCALE_TO_FILL,
1081     SamplingMode::BOX_THEN_LINEAR,
1082     TextureManager::UseAtlas::NO_ATLAS,
1083     &observer,
1084     true,
1085     TextureManager::ReloadPolicy::CACHED,
1086     preMultiply);
1087
1088   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1089   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1090
1091   application.SendNotification();
1092   application.Render();
1093
1094   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1095
1096   application.SendNotification();
1097   application.Render();
1098
1099   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1100   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1101   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1102
1103   tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1104
1105   DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1106
1107   // Decrease external texture reference count who observer created
1108   textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1109
1110   application.SendNotification();
1111   application.Render();
1112
1113   END_TEST;
1114 }
1115
1116 int UtcTextureManagerRemoveDuringApplyMasking(void)
1117 {
1118   ToolkitTestApplication application;
1119   tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1120
1121   TextureManager textureManager; // Create new texture manager
1122
1123   TestObserver observer1;
1124   TestObserver observer2;
1125
1126   std::string                        filename(TEST_IMAGE_FILE_NAME);
1127   std::string                        maskname(TEST_MASK_FILE_NAME);
1128   TextureManager::MaskingDataPointer maskInfo = nullptr;
1129   maskInfo.reset(new TextureManager::MaskingData());
1130   maskInfo->mAlphaMaskUrl       = maskname;
1131   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
1132   maskInfo->mCropToMask         = true;
1133   maskInfo->mContentScaleFactor = 1.0f;
1134
1135   auto                          textureId1(TextureManager::INVALID_TEXTURE_ID);
1136   Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
1137   Dali::ImageDimensions         atlasRectSize(0, 0);
1138   bool                          synchronousLoading(false);
1139   bool                          atlasingStatus(false);
1140   bool                          loadingStatus(false);
1141   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1142   ImageAtlasManagerPtr          atlasManager        = nullptr;
1143   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1144
1145   textureManager.LoadTexture(
1146     filename,
1147     ImageDimensions(),
1148     FittingMode::SCALE_TO_FILL,
1149     SamplingMode::BOX_THEN_LINEAR,
1150     maskInfo,
1151     synchronousLoading,
1152     textureId1,
1153     atlasRect,
1154     atlasRectSize,
1155     atlasingStatus,
1156     loadingStatus,
1157     &observer1,
1158     atlasUploadObserver,
1159     atlasManager,
1160     true,
1161     TextureManager::ReloadPolicy::CACHED,
1162     preMultiply);
1163
1164   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1165   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1166
1167   application.SendNotification();
1168   application.Render();
1169
1170   // Load image and mask image.
1171   // Now, LoadState become MASK_APPLYING
1172   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1173
1174   tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1175
1176   application.SendNotification();
1177   application.Render();
1178
1179   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1180   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1181
1182   // Remove current textureId1. and request new texture again.
1183   textureManager.Remove(textureId1, &observer1);
1184   auto textureId2 = textureManager.RequestLoad(
1185     filename,
1186     ImageDimensions(),
1187     FittingMode::SCALE_TO_FILL,
1188     SamplingMode::BOX_THEN_LINEAR,
1189     TextureManager::UseAtlas::NO_ATLAS,
1190     &observer2,
1191     true, ///< orientationCorrection
1192     TextureManager::ReloadPolicy::CACHED,
1193     preMultiply,
1194     synchronousLoading);
1195
1196   application.SendNotification();
1197   application.Render();
1198
1199   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1200   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1201   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1202   DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1203
1204   tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1205
1206   // CAPTION : HARD-CODING.
1207   {
1208     std::vector<Devel::PixelBuffer> pixelBuffers;
1209     textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1210     textureManager.Remove(textureId2, &observer2);
1211   }
1212
1213   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1214   DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1215   DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1216
1217   END_TEST;
1218 }