Support YUV decoding for JPEG
[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     WrapMode::DEFAULT,
603     WrapMode::DEFAULT,
604     &observer,
605     atlasUploadObserver,
606     atlasManager,
607     true,
608     TextureManager::ReloadPolicy::CACHED,
609     preMultiply);
610
611   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
612   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
613
614   application.SendNotification();
615   application.Render();
616
617   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
618
619   application.SendNotification();
620   application.Render();
621
622   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
623   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
624   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
625
626   END_TEST;
627 }
628
629 int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
630 {
631   ToolkitTestApplication application;
632   tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
633   tet_infoline("Try to check PostLoad works well");
634
635   TextureManager textureManager; // Create new texture manager
636
637   TestObserver                       observer;
638   std::string                        filename(TEST_IMAGE_FILE_NAME);
639   std::string                        maskname("invalid.png");
640   TextureManager::MaskingDataPointer maskInfo = nullptr;
641   maskInfo.reset(new TextureManager::MaskingData());
642   maskInfo->mAlphaMaskUrl       = maskname;
643   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
644   maskInfo->mCropToMask         = true;
645   maskInfo->mContentScaleFactor = 1.0f;
646
647   auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
648   Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
649   Dali::ImageDimensions         atlasRectSize(0, 0);
650   bool                          synchronousLoading(false);
651   bool                          atlasingStatus(false);
652   bool                          loadingStatus(false);
653   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
654   ImageAtlasManagerPtr          atlasManager        = nullptr;
655   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
656
657   textureManager.LoadTexture(
658     filename,
659     ImageDimensions(),
660     FittingMode::SCALE_TO_FILL,
661     SamplingMode::BOX_THEN_LINEAR,
662     maskInfo,
663     synchronousLoading,
664     textureId,
665     atlasRect,
666     atlasRectSize,
667     atlasingStatus,
668     loadingStatus,
669     WrapMode::DEFAULT,
670     WrapMode::DEFAULT,
671     &observer,
672     atlasUploadObserver,
673     atlasManager,
674     true,
675     TextureManager::ReloadPolicy::CACHED,
676     preMultiply);
677
678   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
679   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
680
681   application.SendNotification();
682   application.Render();
683
684   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
685
686   application.SendNotification();
687   application.Render();
688
689   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
690   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
691   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
692
693   END_TEST;
694 }
695
696 int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
697 {
698   ToolkitTestApplication application;
699   tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
700   tet_infoline("Try to check CheckForWaitingTexture called");
701
702   TextureManager textureManager; // Create new texture manager
703
704   TestObserver                       observer;
705   std::string                        filename(TEST_IMAGE_FILE_NAME);
706   std::string                        maskname("invalid.png");
707   TextureManager::MaskingDataPointer maskInfo = nullptr;
708   maskInfo.reset(new TextureManager::MaskingData());
709   maskInfo->mAlphaMaskUrl       = maskname;
710   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
711   maskInfo->mCropToMask         = true;
712   maskInfo->mContentScaleFactor = 1.0f;
713
714   auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
715   Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
716   Dali::ImageDimensions         atlasRectSize(0, 0);
717   bool                          synchronousLoading(false);
718   bool                          atlasingStatus(false);
719   bool                          loadingStatus(false);
720   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
721   ImageAtlasManagerPtr          atlasManager        = nullptr;
722   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
723
724   textureManager.LoadTexture(
725     filename,
726     ImageDimensions(),
727     FittingMode::SCALE_TO_FILL,
728     SamplingMode::BOX_THEN_LINEAR,
729     maskInfo,
730     synchronousLoading,
731     textureId,
732     atlasRect,
733     atlasRectSize,
734     atlasingStatus,
735     loadingStatus,
736     WrapMode::DEFAULT,
737     WrapMode::DEFAULT,
738     &observer,
739     atlasUploadObserver,
740     atlasManager,
741     true,
742     TextureManager::ReloadPolicy::CACHED,
743     preMultiply);
744
745   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
746   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
747
748   application.SendNotification();
749   application.Render();
750
751   // CAPTION : HARD-CODING for coverage. If you are a good boy, Do not follow this code.
752   {
753     Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
754       filename,
755       ImageDimensions(),
756       FittingMode::SCALE_TO_FILL,
757       SamplingMode::BOX_THEN_LINEAR,
758       true, ///< synchronousLoading
759       nullptr,
760       true, ///< orientationCorrection
761       preMultiply);
762
763     std::vector<Devel::PixelBuffer> pixelBuffers;
764     pixelBuffers.push_back(pixelBuffer);
765     textureManager.AsyncLoadComplete(textureId, pixelBuffers);
766     std::vector<Devel::PixelBuffer> maskBuffers;
767     textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, maskBuffers);
768     textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
769     textureManager.Remove(textureId, &observer);
770   }
771
772   application.SendNotification();
773   application.Render();
774
775   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
776   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
777   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
778
779   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
780
781   END_TEST;
782 }
783
784 int UtcTextureManagerSynchronousLoadingFail(void)
785 {
786   ToolkitTestApplication application;
787   tet_infoline("UtcTextureManagerSynchronousLoadingFail");
788
789   TextureManager textureManager; // Create new texture manager
790
791   std::string                        maskname("");
792   TextureManager::MaskingDataPointer maskInfo = nullptr;
793   maskInfo.reset(new TextureManager::MaskingData());
794   maskInfo->mAlphaMaskUrl       = maskname;
795   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
796   maskInfo->mCropToMask         = true;
797   maskInfo->mContentScaleFactor = 1.0f;
798
799   std::string                   filename("dummy");
800   auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
801   Vector4                       atlasRect(0.f, 0.f, 0.f, 0.f);
802   Dali::ImageDimensions         atlasRectSize(0, 0);
803   bool                          atlasingStatus(false);
804   bool                          loadingStatus(false);
805   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
806   ImageAtlasManagerPtr          atlasManager        = nullptr;
807   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
808
809   // load image synchronously.
810   TestObserver observer;
811   TextureSet   textureSet = textureManager.LoadTexture(
812     filename,
813     ImageDimensions(),
814     FittingMode::SCALE_TO_FILL,
815     SamplingMode::BOX_THEN_LINEAR,
816     maskInfo,
817     true, // synchronous loading.
818     textureId,
819     atlasRect,
820     atlasRectSize,
821     atlasingStatus,
822     loadingStatus,
823     WrapMode::DEFAULT,
824     WrapMode::DEFAULT,
825     &observer,
826     atlasUploadObserver,
827     atlasManager,
828     true,
829     TextureManager::ReloadPolicy::CACHED,
830     preMultiply);
831
832   DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
833   DALI_TEST_CHECK(!textureSet);                                     // texture loading fail.
834   DALI_TEST_CHECK(textureId == TextureManager::INVALID_TEXTURE_ID); // invalid texture id is returned.
835
836   END_TEST;
837 }
838
839 int UtcTextureManagerCachingSynchronousLoading(void)
840 {
841   ToolkitTestApplication application;
842   tet_infoline("UtcTextureManagerCachingSynchronousLoading");
843
844   TextureManager textureManager; // Create new texture manager
845
846   std::string filename(TEST_IMAGE_FILE_NAME);
847
848   std::string                        maskname("");
849   TextureManager::MaskingDataPointer maskInfo = nullptr;
850   maskInfo.reset(new TextureManager::MaskingData());
851   maskInfo->mAlphaMaskUrl       = maskname;
852   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
853   maskInfo->mCropToMask         = true;
854   maskInfo->mContentScaleFactor = 1.0f;
855
856   Vector4                       atlasRect(0.f, 0.f, 0.f, 0.f);
857   Dali::ImageDimensions         atlasRectSize(0, 0);
858   bool                          atlasingStatus(false);
859   bool                          loadingStatus(false);
860   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
861   ImageAtlasManagerPtr          atlasManager        = nullptr;
862   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
863
864   // load image synchronously.
865   TestObserver observer;
866   auto         textureId(TextureManager::INVALID_TEXTURE_ID);
867   TextureSet   textureSet = textureManager.LoadTexture(
868     filename,
869     ImageDimensions(),
870     FittingMode::SCALE_TO_FILL,
871     SamplingMode::BOX_THEN_LINEAR,
872     maskInfo,
873     true, // synchronous loading.
874     textureId,
875     atlasRect,
876     atlasRectSize,
877     atlasingStatus,
878     loadingStatus,
879     WrapMode::DEFAULT,
880     WrapMode::DEFAULT,
881     &observer,
882     atlasUploadObserver,
883     atlasManager,
884     true,
885     TextureManager::ReloadPolicy::CACHED,
886     preMultiply);
887
888   DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
889   DALI_TEST_CHECK(textureSet); // texture is loaded.
890
891   // observer isn't called in synchronous loading.
892   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
893   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
894
895   // load same image asynchronously.
896   TestObserver asyncObserver;
897   auto         asyncTextureId(TextureManager::INVALID_TEXTURE_ID);
898   loadingStatus              = false;
899   TextureSet asyncTextureSet = textureManager.LoadTexture(
900     filename,
901     ImageDimensions(),
902     FittingMode::SCALE_TO_FILL,
903     SamplingMode::BOX_THEN_LINEAR,
904     maskInfo,
905     false, // asynchronous loading.
906     asyncTextureId,
907     atlasRect,
908     atlasRectSize,
909     atlasingStatus,
910     loadingStatus,
911     WrapMode::DEFAULT,
912     WrapMode::DEFAULT,
913     &asyncObserver,
914     atlasUploadObserver,
915     atlasManager,
916     true,
917     TextureManager::ReloadPolicy::CACHED,
918     preMultiply);
919
920   DALI_TEST_EQUALS(asyncTextureId, textureId, TEST_LOCATION); // texture is loaded.
921   DALI_TEST_EQUALS(loadingStatus, false, TEST_LOCATION);
922   DALI_TEST_CHECK(asyncTextureSet); // Cached texture.
923
924   // observer is directly called because textureSet is retrieved by cache.
925   DALI_TEST_EQUALS(asyncObserver.mLoaded, true, TEST_LOCATION);
926   DALI_TEST_EQUALS(asyncObserver.mObserverCalled, true, TEST_LOCATION);
927
928   END_TEST;
929 }
930
931 int UtcTextureManagerAsyncSyncAsync(void)
932 {
933   ToolkitTestApplication application;
934   tet_infoline("UtcTextureManagerAsyncSyncAsync");
935
936   TextureManager textureManager; // Create new texture manager
937
938   std::string filename(TEST_IMAGE_FILE_NAME);
939
940   std::string                        maskname("");
941   TextureManager::MaskingDataPointer maskInfo = nullptr;
942   maskInfo.reset(new TextureManager::MaskingData());
943   maskInfo->mAlphaMaskUrl       = maskname;
944   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
945   maskInfo->mCropToMask         = true;
946   maskInfo->mContentScaleFactor = 1.0f;
947
948   Vector4                       atlasRect(0.f, 0.f, 0.f, 0.f);
949   Dali::ImageDimensions         atlasRectSize(0, 0);
950   bool                          atlasingStatus(false);
951   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
952   ImageAtlasManagerPtr          atlasManager        = nullptr;
953   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
954
955   // load image asynchronously.
956   TestObserver asyncObserver1;
957   auto         asyncTextureId1(TextureManager::INVALID_TEXTURE_ID);
958   bool         asyncLoadingStatus1 = false;
959   TextureSet   asyncTextureSet1    = textureManager.LoadTexture(
960     filename,
961     ImageDimensions(),
962     FittingMode::SCALE_TO_FILL,
963     SamplingMode::BOX_THEN_LINEAR,
964     maskInfo,
965     false, // asynchronous loading.
966     asyncTextureId1,
967     atlasRect,
968     atlasRectSize,
969     atlasingStatus,
970     asyncLoadingStatus1,
971     WrapMode::DEFAULT,
972     WrapMode::DEFAULT,
973     &asyncObserver1,
974     atlasUploadObserver,
975     atlasManager,
976     true,
977     TextureManager::ReloadPolicy::CACHED,
978     preMultiply);
979
980   DALI_TEST_EQUALS(asyncLoadingStatus1, true, TEST_LOCATION); // texture is loading now.
981   DALI_TEST_CHECK(!asyncTextureSet1);                         // texture is not loaded yet.
982
983   // observer is still not called.
984   DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
985   DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
986
987   // load same image synchronously just after asynchronous loading.
988   TestObserver syncObserver;
989   auto         textureId(TextureManager::INVALID_TEXTURE_ID);
990   bool         syncLoadingStatus = false;
991   TextureSet   syncTextureSet    = textureManager.LoadTexture(
992     filename,
993     ImageDimensions(),
994     FittingMode::SCALE_TO_FILL,
995     SamplingMode::BOX_THEN_LINEAR,
996     maskInfo,
997     true, // synchronous loading.
998     textureId,
999     atlasRect,
1000     atlasRectSize,
1001     atlasingStatus,
1002     syncLoadingStatus,
1003     WrapMode::DEFAULT,
1004     WrapMode::DEFAULT,
1005     &syncObserver,
1006     atlasUploadObserver,
1007     atlasManager,
1008     true,
1009     TextureManager::ReloadPolicy::CACHED,
1010     preMultiply);
1011
1012   DALI_TEST_EQUALS(asyncTextureId1, textureId, TEST_LOCATION); // texture is loaded.
1013   DALI_TEST_EQUALS(syncLoadingStatus, false, TEST_LOCATION);   // texture is loaded.
1014   DALI_TEST_CHECK(syncTextureSet);                             // texture is loaded.
1015
1016   // syncObserver isn't called in synchronous loading.
1017   DALI_TEST_EQUALS(syncObserver.mLoaded, false, TEST_LOCATION);
1018   DALI_TEST_EQUALS(syncObserver.mObserverCalled, false, TEST_LOCATION);
1019
1020   // asyncObserver1 is still not called too.
1021   DALI_TEST_EQUALS(asyncObserver1.mLoaded, false, TEST_LOCATION);
1022   DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, false, TEST_LOCATION);
1023
1024   // load image asynchronously.
1025   TestObserver asyncObserver2;
1026   auto         asyncTextureId2(TextureManager::INVALID_TEXTURE_ID);
1027   bool         asyncLoadingStatus2 = false;
1028   TextureSet   asyncTextureSet2    = textureManager.LoadTexture(
1029     filename,
1030     ImageDimensions(),
1031     FittingMode::SCALE_TO_FILL,
1032     SamplingMode::BOX_THEN_LINEAR,
1033     maskInfo,
1034     false, // asynchronous loading.
1035     asyncTextureId2,
1036     atlasRect,
1037     atlasRectSize,
1038     atlasingStatus,
1039     asyncLoadingStatus2,
1040     WrapMode::DEFAULT,
1041     WrapMode::DEFAULT,
1042     &asyncObserver2,
1043     atlasUploadObserver,
1044     atlasManager,
1045     true,
1046     TextureManager::ReloadPolicy::CACHED,
1047     preMultiply);
1048
1049   DALI_TEST_EQUALS(asyncLoadingStatus2, false, TEST_LOCATION); // texture is loaded by previous sync request
1050   DALI_TEST_CHECK(asyncTextureSet2);                           // texture is loaded
1051   DALI_TEST_CHECK(asyncTextureSet2 == syncTextureSet);         // check loaded two texture is same.
1052
1053   // observer is called synchronously because the texture is cached.
1054   DALI_TEST_EQUALS(asyncObserver2.mLoaded, true, TEST_LOCATION);
1055   DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, true, TEST_LOCATION);
1056
1057   asyncObserver2.mLoaded         = false;
1058   asyncObserver2.mObserverCalled = false;
1059
1060   application.SendNotification();
1061   application.Render();
1062
1063   // Requested asynchronous loading at first is finished now and async observer is called now.
1064   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1065   DALI_TEST_EQUALS(asyncObserver1.mLoaded, true, TEST_LOCATION);
1066   DALI_TEST_EQUALS(asyncObserver1.mObserverCalled, true, TEST_LOCATION);
1067   DALI_TEST_CHECK(asyncObserver1.mTextureSet == asyncTextureSet2); // check loaded two texture is same.
1068
1069   // asyncObserver2 was already called so it isn't called here.
1070   DALI_TEST_EQUALS(asyncObserver2.mLoaded, false, TEST_LOCATION);
1071   DALI_TEST_EQUALS(asyncObserver2.mObserverCalled, false, TEST_LOCATION);
1072
1073   END_TEST;
1074 }
1075
1076 int UtcTextureManagerQueueRemoveDuringObserve(void)
1077 {
1078   ToolkitTestApplication application;
1079   tet_infoline("UtcTextureManagerQueueRemoveDuringObserve");
1080
1081   TextureManager textureManager; // Create new texture manager
1082
1083   TestObserverRemoveAndGenerateUrl observer(&textureManager); // special observer for this UTC.
1084
1085   std::string filename(TEST_IMAGE_FILE_NAME);
1086   auto        preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1087
1088   TextureManager::TextureId textureId = textureManager.RequestLoad(
1089     filename,
1090     ImageDimensions(),
1091     FittingMode::SCALE_TO_FILL,
1092     SamplingMode::BOX_THEN_LINEAR,
1093     TextureManager::UseAtlas::NO_ATLAS,
1094     &observer,
1095     true,
1096     TextureManager::ReloadPolicy::CACHED,
1097     preMultiply);
1098
1099   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
1100   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
1101
1102   application.SendNotification();
1103   application.Render();
1104
1105   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1106
1107   application.SendNotification();
1108   application.Render();
1109
1110   DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
1111   DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
1112   DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1113
1114   tet_printf("loaded textureId is %d, generated url is %s\n", static_cast<int>(textureId), observer.mGeneratedExternalUrl.c_str());
1115
1116   DALI_TEST_CHECK(static_cast<int>(textureId) != std::stoi(VisualUrl::GetLocation(observer.mGeneratedExternalUrl))); // Check we don't reuse textureId during observe
1117
1118   // Decrease external texture reference count who observer created
1119   textureManager.RemoveExternalTexture(observer.mGeneratedExternalUrl);
1120
1121   application.SendNotification();
1122   application.Render();
1123
1124   END_TEST;
1125 }
1126
1127 int UtcTextureManagerRemoveDuringApplyMasking(void)
1128 {
1129   ToolkitTestApplication application;
1130   tet_infoline("UtcTextureManagerRemoveDuringApplyMasking");
1131
1132   TextureManager textureManager; // Create new texture manager
1133
1134   TestObserver observer1;
1135   TestObserver observer2;
1136
1137   std::string                        filename(TEST_IMAGE_FILE_NAME);
1138   std::string                        maskname(TEST_MASK_FILE_NAME);
1139   TextureManager::MaskingDataPointer maskInfo = nullptr;
1140   maskInfo.reset(new TextureManager::MaskingData());
1141   maskInfo->mAlphaMaskUrl       = maskname;
1142   maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
1143   maskInfo->mCropToMask         = true;
1144   maskInfo->mContentScaleFactor = 1.0f;
1145
1146   auto                          textureId1(TextureManager::INVALID_TEXTURE_ID);
1147   Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
1148   Dali::ImageDimensions         atlasRectSize(0, 0);
1149   bool                          synchronousLoading(false);
1150   bool                          atlasingStatus(false);
1151   bool                          loadingStatus(false);
1152   auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
1153   ImageAtlasManagerPtr          atlasManager        = nullptr;
1154   Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
1155
1156   textureManager.LoadTexture(
1157     filename,
1158     ImageDimensions(),
1159     FittingMode::SCALE_TO_FILL,
1160     SamplingMode::BOX_THEN_LINEAR,
1161     maskInfo,
1162     synchronousLoading,
1163     textureId1,
1164     atlasRect,
1165     atlasRectSize,
1166     atlasingStatus,
1167     loadingStatus,
1168     WrapMode::DEFAULT,
1169     WrapMode::DEFAULT,
1170     &observer1,
1171     atlasUploadObserver,
1172     atlasManager,
1173     true,
1174     TextureManager::ReloadPolicy::CACHED,
1175     preMultiply);
1176
1177   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1178   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1179
1180   application.SendNotification();
1181   application.Render();
1182
1183   // Load image and mask image.
1184   // Now, LoadState become MASK_APPLYING
1185   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1186
1187   tet_printf("Current textureId1:%d's state become MASK_APPLYING\n", static_cast<int>(textureId1));
1188
1189   application.SendNotification();
1190   application.Render();
1191
1192   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1193   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1194
1195   // Remove current textureId1. and request new texture again.
1196   textureManager.Remove(textureId1, &observer1);
1197   auto textureId2 = textureManager.RequestLoad(
1198     filename,
1199     ImageDimensions(),
1200     FittingMode::SCALE_TO_FILL,
1201     SamplingMode::BOX_THEN_LINEAR,
1202     TextureManager::UseAtlas::NO_ATLAS,
1203     &observer2,
1204     true, ///< orientationCorrection
1205     TextureManager::ReloadPolicy::CACHED,
1206     preMultiply,
1207     synchronousLoading);
1208
1209   application.SendNotification();
1210   application.Render();
1211
1212   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1213   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1214   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1215   DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1216
1217   tet_printf("textureId1:%d removed and textureId2:%d requested\n", static_cast<int>(textureId1), static_cast<int>(textureId2));
1218
1219   // ApplyMask event come back, and do nothing.
1220   // CAPTION : HARD-CODING.
1221   {
1222     std::vector<Devel::PixelBuffer> pixelBuffers;
1223     textureManager.AsyncLoadComplete(textureId1, pixelBuffers);
1224     textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
1225   }
1226
1227   application.SendNotification();
1228   application.Render();
1229
1230   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
1231   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
1232   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
1233   DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION);
1234
1235   // CAPTION : HARD-CODING.
1236   {
1237     std::vector<Devel::PixelBuffer> pixelBuffers;
1238     textureManager.AsyncLoadComplete(textureId2, pixelBuffers);
1239     textureManager.Remove(textureId2, &observer2);
1240   }
1241
1242   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); ///< Note that we call AsyncLoadComplete hardly with empty pixelbuffer.
1243   DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION);
1244   DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
1245
1246   END_TEST;
1247 }