Particle System
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageVisual.cpp
1 /*
2  * Copyright (c) 2023 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 #include <stdlib.h>
18 #include <iostream>
19 #include <vector>
20
21 #include <dali-toolkit-test-suite-utils.h>
22
23 #include <toolkit-environment-variable.h>
24 #include <toolkit-event-thread-callback.h>
25 #include <toolkit-timer.h>
26
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
30 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
33 #include <dali-toolkit/public-api/image-loader/image-url.h>
34 #include <dali-toolkit/public-api/image-loader/image.h>
35
36 #include "dummy-control.h"
37 #include "test-encoded-image-buffer.h"
38 #include "test-native-image-source.h"
39
40 using namespace Dali;
41 using namespace Dali::Toolkit;
42
43 void dali_image_visual_startup(void)
44 {
45   test_return_value = TET_UNDEF;
46 }
47
48 void dali_image_visual_cleanup(void)
49 {
50   test_return_value = TET_PASS;
51 }
52
53 namespace
54 {
55 const char* TEST_IMAGE_FILE_NAME          = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
56 const char* TEST_BROKEN_IMAGE_FILE_NAME   = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
57 const char* TEST_LARGE_IMAGE_FILE_NAME    = TEST_RESOURCE_DIR "/tbcol.png";
58 const char* TEST_SMALL_IMAGE_FILE_NAME    = TEST_RESOURCE_DIR "/icon-edit.png";
59 const char* TEST_REMOTE_IMAGE_FILE_NAME   = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
60 const char* TEST_INVALID_FILE_NAME        = TEST_RESOURCE_DIR "/invalid.jpg";
61 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
62 const char* TEST_MASK_IMAGE_FILE_NAME     = TEST_RESOURCE_DIR "/mask.png";
63 const char* TEST_ROTATED_IMAGE            = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
64 const char* TEST_YUV420_IMAGE_FILE_NAME   = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
65 const char* TEST_N_PATCH_IMAGE_FILE_NAME  = TEST_RESOURCE_DIR "/heartsframe.9.png";
66
67 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV         = "DALI_LOAD_IMAGE_YUV_PLANES";
68 constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
69
70 bool             gResourceReadySignalFired = false;
71 std::vector<int> gReadyIds                 = {};
72 void             ResourceReadySignal(Control control)
73 {
74   gResourceReadySignalFired = true;
75   gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
76 }
77 void ClearReadyIds()
78 {
79   gReadyIds.clear();
80 }
81
82 Actor CreateActorWithImageVisual(const Property::Map& map)
83 {
84   VisualFactory     factory   = VisualFactory::Get();
85   DummyControl      actor     = DummyControl::New();
86   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
87   Visual::Base      visual    = factory.CreateVisual(map);
88   DALI_TEST_CHECK(visual);
89   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
90   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
91   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
92   return actor;
93 }
94
95 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
96 {
97   VisualFactory factory = VisualFactory::Get();
98
99   Property::Map propertyMap;
100   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
101   propertyMap.Insert(ImageVisual::Property::URL, url);
102   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
103   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
104   propertyMap.Insert(key, value);
105
106   return factory.CreateVisual(propertyMap);
107 }
108
109 } // namespace
110
111 void TestVisualRender(ToolkitTestApplication&      application,
112                       DummyControl&                actor,
113                       Visual::Base&                visual,
114                       std::size_t                  expectedSamplers = 0,
115                       ImageDimensions              imageDimensions  = ImageDimensions(),
116                       Integration::ResourcePointer resourcePtr      = Integration::ResourcePointer())
117 {
118   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
119   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
120
121   if(resourcePtr)
122   {
123     // set the image size, for test case, this needs to be set before loading started
124     application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
125   }
126
127   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
128   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
129
130   application.GetScene().Add(actor);
131
132   application.SendNotification(); // Send messages to update
133   application.Render();           // process update and render
134   application.SendNotification(); // process any signals to event
135
136   if(resourcePtr)
137   {
138     DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
139   }
140
141   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
142 }
143
144 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
145 {
146   Property::Map map;
147   visual.CreatePropertyMap(map);
148   Property::Value* value = map.Find(mixColorIndex);
149   DALI_TEST_CHECK(value);
150   Vector3 mixColor1;
151   DALI_TEST_CHECK(value->Get(mixColor1));
152   DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
153
154   value = map.Find(Visual::Property::MIX_COLOR);
155   DALI_TEST_CHECK(value);
156   Vector4 mixColor2;
157   DALI_TEST_CHECK(value->Get(mixColor2));
158   DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
159
160   value = map.Find(Visual::Property::OPACITY);
161   DALI_TEST_CHECK(value);
162   float opacity;
163   DALI_TEST_CHECK(value->Get(opacity));
164   DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
165 }
166
167 int UtcDaliImageVisualPropertyMap(void)
168 {
169   ToolkitTestApplication application;
170   tet_infoline("Request image visual with a Property::Map");
171
172   VisualFactory factory = VisualFactory::Get();
173   DALI_TEST_CHECK(factory);
174   factory.SetPreMultiplyOnLoad(true);
175
176   Property::Map propertyMap;
177   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
178   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
179
180   Visual::Base visual = factory.CreateVisual(propertyMap);
181   DALI_TEST_CHECK(visual);
182
183   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
184   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
185
186   TestGlAbstraction& gl           = application.GetGlAbstraction();
187   TraceCallStack&    textureTrace = gl.GetTextureTrace();
188   textureTrace.Enable(true);
189
190   DummyControl      actor     = DummyControl::New();
191   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
192   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
193
194   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
195   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
196
197   application.GetScene().Add(actor);
198   application.SendNotification();
199   application.Render();
200
201   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
202
203   application.SendNotification();
204   application.Render();
205
206   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
207   auto renderer           = actor.GetRendererAt(0);
208   auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
209   DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
210   auto preMultipliedAlpha  = renderer.GetProperty<float>(preMultipliedIndex);
211   auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
212   DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
213   DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
214   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
215
216   application.GetScene().Remove(actor);
217   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
218
219   END_TEST;
220 }
221
222 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
223 {
224   ToolkitTestApplication application;
225   tet_infoline("Request image visual without pre-multiplied alpha");
226
227   VisualFactory factory = VisualFactory::Get();
228   DALI_TEST_CHECK(factory);
229   factory.SetPreMultiplyOnLoad(false);
230
231   Property::Map propertyMap;
232   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
233   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
234
235   Visual::Base visual = factory.CreateVisual(propertyMap);
236   DALI_TEST_CHECK(visual);
237
238   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
239   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
240
241   TestGlAbstraction& gl           = application.GetGlAbstraction();
242   TraceCallStack&    textureTrace = gl.GetTextureTrace();
243   textureTrace.Enable(true);
244
245   DummyControl      actor     = DummyControl::New();
246   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
247   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
248
249   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
250   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
251
252   application.GetScene().Add(actor);
253   application.SendNotification();
254   application.Render();
255
256   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
257
258   application.SendNotification();
259   application.Render();
260
261   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
262   auto renderer           = actor.GetRendererAt(0);
263   auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
264   DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
265   auto preMultipliedAlpha  = renderer.GetProperty<bool>(preMultipliedIndex);
266   auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
267
268   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
269   DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
270
271   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
272
273   application.GetScene().Remove(actor);
274   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
275
276   END_TEST;
277 }
278
279 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
280 {
281   ToolkitTestApplication application;
282   tet_infoline("Request image visual with no alpha channel");
283
284   VisualFactory factory = VisualFactory::Get();
285   DALI_TEST_CHECK(factory);
286
287   Property::Map propertyMap;
288   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
289   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
290
291   Visual::Base visual = factory.CreateVisual(propertyMap);
292   DALI_TEST_CHECK(visual);
293
294   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
295   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
296
297   TestGlAbstraction& gl           = application.GetGlAbstraction();
298   TraceCallStack&    textureTrace = gl.GetTextureTrace();
299   textureTrace.Enable(true);
300
301   DummyControl      actor     = DummyControl::New();
302   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
303   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
304
305   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
306   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
307
308   application.GetScene().Add(actor);
309   application.SendNotification();
310   application.Render();
311
312   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
313
314   application.SendNotification();
315   application.Render();
316
317   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
318   auto renderer           = actor.GetRendererAt(0);
319   auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
320   DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
321   auto preMultipliedAlpha  = renderer.GetProperty<bool>(preMultipliedIndex);
322   auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
323
324   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
325   DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
326
327   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
328
329   int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
330   int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
331   int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
332   int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
333   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
334   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
335   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
336   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
337
338   textureTrace.Reset();
339
340   // Make a new visual with the same image
341   Visual::Base newVisual = factory.CreateVisual(propertyMap);
342   DALI_TEST_CHECK(newVisual);
343
344   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
345   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
346
347   DummyControl      newActor     = DummyControl::New();
348   DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
349   newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
350
351   newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
352   DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
353
354   application.GetScene().Add(newActor);
355
356   application.SendNotification();
357   application.Render();
358
359   DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
360   auto newRenderer   = newActor.GetRendererAt(0);
361   preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
362   DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
363   preMultipliedAlpha  = newRenderer.GetProperty<bool>(preMultipliedIndex);
364   preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
365
366   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
367   DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
368
369   srcFactorRgb    = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
370   destFactorRgb   = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
371   srcFactorAlpha  = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
372   destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
373   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
374   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
375   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
376   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
377
378   application.GetScene().Remove(actor);
379   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
380
381   END_TEST;
382 }
383
384 int UtcDaliImageVisualRemoteImageLoad(void)
385 {
386   ToolkitTestApplication application;
387   tet_infoline("Request remote image visual with a Property::Map");
388
389   VisualFactory factory = VisualFactory::Get();
390   DALI_TEST_CHECK(factory);
391
392   Property::Map propertyMap;
393   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
394   propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
395
396   Visual::Base visual = factory.CreateVisual(propertyMap);
397   DALI_TEST_CHECK(visual);
398
399   TestGlAbstraction& gl           = application.GetGlAbstraction();
400   TraceCallStack&    textureTrace = gl.GetTextureTrace();
401   textureTrace.Enable(true);
402
403   DummyControl      actor     = DummyControl::New();
404   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
405   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
406
407   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
408   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
409
410   application.GetScene().Add(actor);
411   application.SendNotification();
412
413   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
414
415   application.SendNotification();
416   application.Render();
417
418   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
419   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
420
421   application.GetScene().Remove(actor);
422   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
423
424   END_TEST;
425 }
426
427 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void)
428 {
429   ToolkitTestApplication application;
430   tet_infoline("Use FrameBuffer as url");
431
432   uint32_t width(64);
433   uint32_t height(64);
434   FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
435
436   DALI_TEST_CHECK(frameBuffer);
437   ImageUrl    imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
438   std::string url      = imageUrl.GetUrl();
439
440   VisualFactory factory = VisualFactory::Get();
441   DALI_TEST_CHECK(factory);
442
443   Property::Map propertyMap;
444   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
445   propertyMap.Insert(ImageVisual::Property::URL, url);
446
447   Visual::Base visual = factory.CreateVisual(propertyMap);
448   DALI_TEST_CHECK(visual);
449
450   DummyControl      actor     = DummyControl::New();
451   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
452   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
453
454   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
455
456   application.GetScene().Add(actor);
457
458   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
459
460   application.SendNotification();
461   application.Render(16);
462
463   Renderer renderer = actor.GetRendererAt(0);
464
465   // Check whether preMultipliedAlpha is true.
466   auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
467   DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
468
469   END_TEST;
470 }
471
472 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void)
473 {
474   ToolkitTestApplication application;
475   tet_infoline("Use FrameBuffer as url");
476
477   uint32_t width(64);
478   uint32_t height(64);
479   FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
480
481   DALI_TEST_CHECK(frameBuffer);
482
483   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
484   frameBuffer.AttachColorTexture(texture);
485
486   ImageUrl    imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u);
487   std::string url      = imageUrl.GetUrl();
488
489   VisualFactory factory = VisualFactory::Get();
490   DALI_TEST_CHECK(factory);
491
492   Property::Map propertyMap;
493   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
494   propertyMap.Insert(ImageVisual::Property::URL, url);
495
496   Visual::Base visual = factory.CreateVisual(propertyMap);
497   DALI_TEST_CHECK(visual);
498
499   DummyControl      actor     = DummyControl::New();
500   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
501   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
502
503   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
504
505   application.GetScene().Add(actor);
506
507   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
508
509   application.SendNotification();
510   application.Render(16);
511
512   Renderer renderer = actor.GetRendererAt(0);
513
514   // Check whether preMultipliedAlpha is true.
515   auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
516   DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
517
518   END_TEST;
519 }
520
521 int UtcDaliImageVisualWithPixelData(void)
522 {
523   ToolkitTestApplication application;
524   tet_infoline("Use PixelData as url");
525
526   uint32_t width(64);
527   uint32_t height(64);
528   uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
529
530   uint8_t*  buffer    = reinterpret_cast<uint8_t*>(malloc(bufferSize));
531   PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
532
533   DALI_TEST_CHECK(pixelData);
534
535   ImageUrl    imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData);
536   std::string url      = imageUrl.GetUrl();
537
538   VisualFactory factory = VisualFactory::Get();
539   DALI_TEST_CHECK(factory);
540
541   Property::Map propertyMap;
542   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
543   propertyMap.Insert(ImageVisual::Property::URL, url);
544
545   Visual::Base visual = factory.CreateVisual(propertyMap);
546   DALI_TEST_CHECK(visual);
547
548   DummyControl      actor     = DummyControl::New();
549   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
550   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
551
552   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
553
554   application.GetScene().Add(actor);
555
556   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
557
558   application.SendNotification();
559   application.Render(16);
560
561   Renderer renderer = actor.GetRendererAt(0);
562
563   // Check whether preMultipliedAlpha is false.
564   auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
565   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
566
567   END_TEST;
568 }
569
570 int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void)
571 {
572   ToolkitTestApplication application;
573   tet_infoline("Use PixelData as url");
574
575   uint32_t width(64);
576   uint32_t height(64);
577   uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
578
579   uint8_t*  buffer    = reinterpret_cast<uint8_t*>(malloc(bufferSize));
580   PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
581
582   DALI_TEST_CHECK(pixelData);
583
584   ImageUrl    imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
585   std::string url      = imageUrl.GetUrl();
586
587   VisualFactory factory = VisualFactory::Get();
588   DALI_TEST_CHECK(factory);
589
590   Property::Map propertyMap;
591   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
592   propertyMap.Insert(ImageVisual::Property::URL, url);
593
594   Visual::Base visual = factory.CreateVisual(propertyMap);
595   DALI_TEST_CHECK(visual);
596
597   DummyControl      actor     = DummyControl::New();
598   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
599   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
600
601   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
602
603   application.GetScene().Add(actor);
604
605   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
606
607   application.SendNotification();
608   application.Render(16);
609
610   Renderer renderer = actor.GetRendererAt(0);
611
612   // Check whether preMultipliedAlpha is true.
613   auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
614   DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
615
616   END_TEST;
617 }
618
619 int UtcDaliImageVisualWithNativeImage(void)
620 {
621   ToolkitTestApplication application;
622   tet_infoline("Use Native Image as url");
623
624   NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
625   ImageUrl             imageUrl          = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
626   std::string          url               = imageUrl.GetUrl();
627
628   VisualFactory factory = VisualFactory::Get();
629   DALI_TEST_CHECK(factory);
630
631   Property::Map propertyMap;
632   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
633   propertyMap.Insert(ImageVisual::Property::URL, url);
634
635   Visual::Base visual = factory.CreateVisual(propertyMap);
636   DALI_TEST_CHECK(visual);
637
638   DummyControl      actor     = DummyControl::New();
639   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
640   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
641
642   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
643
644   application.GetScene().Add(actor);
645
646   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
647
648   application.SendNotification();
649   application.Render(16);
650
651   Renderer renderer = actor.GetRendererAt(0);
652   Shader   shader   = renderer.GetShader();
653
654   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
655   DALI_TEST_CHECK(value.GetType() == Property::MAP);
656   const Property::Map* outMap         = value.GetMap();
657   std::string          fragmentShader = (*outMap)["fragment"].Get<std::string>();
658
659   const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
660   size_t      pos            = fragmentShader.find(fragmentPrefix);
661
662   DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
663
664   // Check whether preMultipliedAlpha is false.
665   auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
666   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
667
668   END_TEST;
669 }
670
671 int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
672 {
673   ToolkitTestApplication application;
674   tet_infoline("Use Native Image as url");
675
676   NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
677   ImageUrl             imageUrl          = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
678   std::string          url               = imageUrl.GetUrl();
679
680   VisualFactory factory = VisualFactory::Get();
681   DALI_TEST_CHECK(factory);
682
683   Property::Map propertyMap;
684   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
685   propertyMap.Insert(ImageVisual::Property::URL, url);
686
687   Visual::Base visual = factory.CreateVisual(propertyMap);
688   DALI_TEST_CHECK(visual);
689
690   DummyControl      actor     = DummyControl::New();
691   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
692   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
693
694   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
695
696   application.GetScene().Add(actor);
697
698   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
699
700   application.SendNotification();
701   application.Render(16);
702
703   Renderer renderer = actor.GetRendererAt(0);
704   Shader   shader   = renderer.GetShader();
705
706   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
707   DALI_TEST_CHECK(value.GetType() == Property::MAP);
708   const Property::Map* outMap         = value.GetMap();
709   std::string          fragmentShader = (*outMap)["fragment"].Get<std::string>();
710
711   const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
712   size_t      pos            = fragmentShader.find(fragmentPrefix);
713
714   DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
715
716   // Check whether preMultipliedAlpha is true.
717   auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
718   DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
719
720   END_TEST;
721 }
722
723 int UtcDaliImageVisualWithNativeImageCustomShader(void)
724 {
725   ToolkitTestApplication application;
726   tet_infoline("Use Native Image as url and Use custom shader");
727
728   NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
729   ImageUrl             imageUrl          = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
730   std::string          url               = imageUrl.GetUrl();
731
732   VisualFactory factory = VisualFactory::Get();
733   DALI_TEST_CHECK(factory);
734
735   Property::Map     propertyMap;
736   Property::Map     shaderMap;
737   const std::string customVertexShaderSource                    = "Foobar";
738   const std::string customFragmentShaderSource                  = "Foobar";
739   shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
740   shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER]   = customVertexShaderSource;
741
742   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
743   propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
744   propertyMap.Insert(ImageVisual::Property::URL, url);
745
746   Visual::Base visual = factory.CreateVisual(propertyMap);
747   DALI_TEST_CHECK(visual);
748
749   DummyControl      actor     = DummyControl::New();
750   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
751   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
752
753   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
754   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
755
756   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
757
758   application.GetScene().Add(actor);
759
760   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
761
762   application.SendNotification();
763   application.Render(16);
764
765   Renderer renderer = actor.GetRendererAt(0);
766   Shader   shader   = renderer.GetShader();
767
768   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
769   DALI_TEST_CHECK(value.GetType() == Property::MAP);
770   const Property::Map* outMap               = value.GetMap();
771   std::string          fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
772   std::string          vertexShaderSource   = (*outMap)["vertex"].Get<std::string>();
773
774   // Compare vertex shader is equal
775   DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
776
777   // Check fragment shader changed
778   const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
779   size_t      pos            = fragmentShaderSource.find(fragmentPrefix);
780
781   DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
782
783   DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
784
785   // Check whether preMultipliedAlpha is false.
786   // Note : We dont use preMultiplied alpha when app developer using custom shader.
787   auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
788   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
789
790   END_TEST;
791 }
792
793 int UtcDaliImageVisualWithNativeImageRemoved(void)
794 {
795   ToolkitTestApplication application;
796   tet_infoline("Use Native Image as url");
797
798   TestGlAbstraction& gl           = application.GetGlAbstraction();
799   TraceCallStack&    textureTrace = gl.GetTextureTrace();
800   textureTrace.Enable(true);
801
802   NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
803   ImageUrl             imageUrl          = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
804   std::string          url               = imageUrl.GetUrl();
805
806   VisualFactory factory = VisualFactory::Get();
807   DALI_TEST_CHECK(factory);
808
809   Property::Map propertyMap;
810   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
811   propertyMap.Insert(ImageVisual::Property::URL, url);
812
813   Visual::Base visual = factory.CreateVisual(propertyMap);
814   DALI_TEST_CHECK(visual);
815
816   DummyControl      actor     = DummyControl::New();
817   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
818   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
819
820   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
821
822   application.GetScene().Add(actor);
823   application.SendNotification();
824   application.Render();
825
826   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
827   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
828
829   tet_infoline("No delete texture because reference count is not zero");
830   imageUrl.Reset();
831   application.GetScene().Remove(actor);
832   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
833   application.SendNotification();
834   application.Render();
835
836   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
837   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
838
839   tet_infoline("Delete texture because reference count is zero");
840   visual.Reset();
841   application.SendNotification();
842   application.Render();
843
844   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
845
846   END_TEST;
847 }
848
849 int UtcDaliImageVisualWithEncodedImageBuffer(void)
850 {
851   ToolkitTestApplication application;
852   tet_infoline("Use Encoded Image Buffer as url");
853
854   EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
855   ImageUrl           url       = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
856
857   VisualFactory factory = VisualFactory::Get();
858   DALI_TEST_CHECK(factory);
859
860   Property::Map propertyMap;
861   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
862   propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
863
864   Visual::Base visual = factory.CreateVisual(propertyMap);
865   DALI_TEST_CHECK(visual);
866
867   TestGlAbstraction& gl           = application.GetGlAbstraction();
868   TraceCallStack&    textureTrace = gl.GetTextureTrace();
869   textureTrace.Enable(true);
870
871   DummyControl      actor     = DummyControl::New();
872   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
873   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
874
875   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
876   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
877
878   application.GetScene().Add(actor);
879   application.SendNotification();
880
881   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
882
883   application.SendNotification();
884   application.Render();
885
886   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
887   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
888
889   application.GetScene().Remove(actor);
890   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
891
892   END_TEST;
893 }
894
895 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
896 {
897   ToolkitTestApplication application;
898   tet_infoline("Use Encoded Image Buffer as url");
899
900   TestGlAbstraction& gl           = application.GetGlAbstraction();
901   TraceCallStack&    textureTrace = gl.GetTextureTrace();
902   textureTrace.Enable(true);
903
904   EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
905   ImageUrl           imageUrl  = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
906   std::string        url       = imageUrl.GetUrl();
907
908   VisualFactory factory = VisualFactory::Get();
909   DALI_TEST_CHECK(factory);
910
911   Property::Map propertyMap;
912   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
913   propertyMap.Insert(ImageVisual::Property::URL, url);
914
915   Visual::Base visual = factory.CreateVisual(propertyMap);
916   DALI_TEST_CHECK(visual);
917
918   DummyControl      actor     = DummyControl::New();
919   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
920   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
921
922   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
923
924   application.GetScene().Add(actor);
925   application.SendNotification();
926
927   // Wait for decode buffer and make texture.
928   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
929
930   application.SendNotification();
931   application.Render();
932
933   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
934   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
935
936   tet_infoline("Delete texture because there is no actor to use decoded texture");
937   imageUrl.Reset();
938   application.GetScene().Remove(actor);
939   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
940   application.SendNotification();
941   application.Render();
942
943   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
944   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
945
946   END_TEST;
947 }
948
949 int UtcDaliImageVisualTextureReuse1(void)
950 {
951   ToolkitTestApplication application;
952   tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
953
954   Property::Map propertyMap;
955   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
956   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
957   propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
958
959   TestGlAbstraction& gl           = application.GetGlAbstraction();
960   TraceCallStack&    textureTrace = gl.GetTextureTrace();
961   textureTrace.Enable(true);
962   TraceCallStack& drawTrace = gl.GetDrawTrace();
963   drawTrace.Enable(true);
964
965   Actor actor = CreateActorWithImageVisual(propertyMap);
966   application.GetScene().Add(actor);
967   application.SendNotification();
968
969   // Wait for image to load
970   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
971
972   application.SendNotification();
973   application.Render();
974
975   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
976   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
977   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
978   DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
979   textureTrace.Reset();
980   drawTrace.Reset();
981
982   Actor actor2 = CreateActorWithImageVisual(propertyMap);
983   application.GetScene().Add(actor2);
984
985   application.SendNotification(); // Send messages to update
986   application.Render();           // process update and render
987   application.SendNotification(); // process any signals to event
988
989   DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
990
991   // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
992   // backend here, but test graphics backend.
993   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
994   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
995
996   tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
997
998   application.GetScene().Remove(actor);
999   application.SendNotification();
1000   application.Render();
1001
1002   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1003   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1004
1005   tet_infoline("Test that removing last actor does delete the texture\n");
1006
1007   application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
1008   application.SendNotification();
1009   application.Render();
1010
1011   DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1012   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1013
1014   END_TEST;
1015 }
1016
1017 int UtcDaliImageVisualTextureReuse2(void)
1018 {
1019   ToolkitTestApplication application;
1020   tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same url but different property map - should create new texture");
1021
1022   Property::Map propertyMap;
1023   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1024   propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1025
1026   TestGlAbstraction& gl           = application.GetGlAbstraction();
1027   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1028   textureTrace.Enable(true);
1029   TraceCallStack& drawTrace = gl.GetDrawTrace();
1030   drawTrace.Enable(true);
1031
1032   Actor actor = CreateActorWithImageVisual(propertyMap);
1033   application.GetScene().Add(actor);
1034   application.SendNotification();
1035
1036   // Wait for image to load
1037   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1038
1039   application.SendNotification();
1040   application.Render();
1041
1042   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1043   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1044   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1045   DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1046   textureTrace.Reset();
1047   drawTrace.Reset();
1048
1049   propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
1050   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
1051   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
1052   Actor actor2 = CreateActorWithImageVisual(propertyMap);
1053   application.GetScene().Add(actor2);
1054
1055   application.SendNotification();
1056
1057   // Wait for image to load
1058   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1059
1060   application.SendNotification();
1061   application.Render();
1062
1063   DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1064
1065   tet_infoline(
1066     "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
1067     "renderers are using different textures\n");
1068
1069   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1070   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1071   TraceCallStack::NamedParams tex1;
1072   tex1["texture"] << 1;
1073   TraceCallStack::NamedParams tex2;
1074   tex2["texture"] << 2;
1075   DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
1076   DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
1077
1078   tet_infoline("Test that removing 1 actor deletes it's texture\n");
1079
1080   application.GetScene().Remove(actor);
1081   application.SendNotification();
1082   application.Render();
1083
1084   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1085   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1086
1087   tet_infoline("Test that removing last actor deletes it's texture\n");
1088
1089   application.GetScene().Remove(actor2);
1090   application.SendNotification();
1091   application.Render();
1092
1093   DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1094   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
1095
1096   END_TEST;
1097 }
1098
1099 int UtcDaliImageVisualCustomWrapModePixelArea(void)
1100 {
1101   ToolkitTestApplication application;
1102   tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
1103
1104   static std::vector<UniformData> customUniforms =
1105     {
1106       UniformData("pixelArea", Property::Type::VECTOR4),
1107       UniformData("wrapMode", Property::Type::VECTOR2),
1108     };
1109
1110   TestGraphicsController& graphics = application.GetGraphicsController();
1111   graphics.AddCustomUniforms(customUniforms);
1112
1113   VisualFactory factory = VisualFactory::Get();
1114   DALI_TEST_CHECK(factory);
1115
1116   // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1117   const int     width  = 34;
1118   const int     height = 34;
1119   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1120
1121   Property::Map propertyMap;
1122   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1123   propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1124   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1125   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1126   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1127   propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1128   propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1129   propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1130   propertyMap.Insert(ImageVisual::Property::ATLASING, true);
1131
1132   Visual::Base visual = factory.CreateVisual(propertyMap);
1133   DALI_TEST_CHECK(visual);
1134
1135   TestGlAbstraction& gl           = application.GetGlAbstraction();
1136   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1137   textureTrace.Enable(true);
1138   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1139   texParameterTrace.Enable(true);
1140
1141   DummyControl      actor     = DummyControl::New();
1142   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1143   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1144   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1145   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1146   application.GetScene().Add(actor);
1147
1148   // loading started
1149   application.SendNotification();
1150   application.Render();
1151
1152   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1153
1154   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1155
1156   // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
1157   std::stringstream out;
1158   out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1159   DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1160   out.str("");
1161   out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1162   DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1163
1164   // test the uniforms which used to handle the wrap mode
1165   Renderer renderer = actor.GetRendererAt(0u);
1166   DALI_TEST_CHECK(renderer);
1167
1168   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1169   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1170   Vector4 pixelAreaUniform;
1171   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1172   DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1173
1174   Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
1175   Vector2         wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
1176   DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
1177   Vector2 wrapModeUniform;
1178   DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
1179   DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1180
1181   actor.Unparent();
1182   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1183
1184   END_TEST;
1185 }
1186
1187 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1188 {
1189   ToolkitTestApplication application;
1190   tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1191
1192   static std::vector<UniformData> customUniforms =
1193     {
1194       UniformData("pixelArea", Property::Type::VECTOR4),
1195     };
1196
1197   TestGraphicsController& graphics = application.GetGraphicsController();
1198   graphics.AddCustomUniforms(customUniforms);
1199
1200   VisualFactory factory = VisualFactory::Get();
1201   DALI_TEST_CHECK(factory);
1202
1203   // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1204   const int     width  = 600;
1205   const int     height = 600;
1206   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1207
1208   Property::Map propertyMap;
1209   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1210   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1211   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1212   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1213   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1214   propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1215   propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1216   propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1217
1218   Visual::Base visual = factory.CreateVisual(propertyMap);
1219   DALI_TEST_CHECK(visual);
1220
1221   TestGlAbstraction& gl           = application.GetGlAbstraction();
1222   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1223   textureTrace.Enable(true);
1224   textureTrace.EnableLogging(true);
1225   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1226   texParameterTrace.Enable(true);
1227   texParameterTrace.EnableLogging(true);
1228
1229   DummyControl      actor     = DummyControl::New();
1230   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1231   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1232   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1233   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1234   application.GetScene().Add(actor);
1235
1236   // loading started
1237   application.SendNotification();
1238   application.Render();
1239   application.SendNotification();
1240
1241   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1242
1243   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1244
1245   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1246   std::stringstream out;
1247   out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1248   DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1249   out.str("");
1250   out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1251   DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1252
1253   // test the uniforms which used to handle the wrap mode
1254   Renderer renderer = actor.GetRendererAt(0u);
1255   DALI_TEST_CHECK(renderer);
1256
1257   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1258   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1259   Vector4 pixelAreaUniform;
1260   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1261   DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1262
1263   Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1264   DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1265
1266   actor.Unparent();
1267   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1268
1269   END_TEST;
1270 }
1271
1272 int UtcDaliImageVisualAnimateMixColor(void)
1273 {
1274   ToolkitTestApplication application;
1275   tet_infoline("Animate mix color");
1276
1277   static std::vector<UniformData> customUniforms =
1278     {
1279       UniformData("mixColor", Property::Type::VECTOR3),
1280     };
1281
1282   TestGraphicsController& graphics = application.GetGraphicsController();
1283   graphics.AddCustomUniforms(customUniforms);
1284
1285   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1286
1287   VisualFactory factory = VisualFactory::Get();
1288   Property::Map propertyMap;
1289   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1290   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1291   propertyMap.Insert("mixColor", Color::BLUE);
1292   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1293   Visual::Base visual = factory.CreateVisual(propertyMap);
1294
1295   DummyControl        actor     = DummyControl::New(true);
1296   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1297   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1298
1299   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1300   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1301   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1302   application.GetScene().Add(actor);
1303
1304   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1305
1306   Renderer renderer = actor.GetRendererAt(0);
1307
1308   // @todo Should we add API to make this code work again?
1309   // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1310
1311   Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1312   DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1313
1314   const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1315
1316   Property::Map map;
1317   map["target"]       = "testVisual";
1318   map["property"]     = "mixColor";
1319   map["initialValue"] = Color::MAGENTA;
1320   map["targetValue"]  = TARGET_MIX_COLOR;
1321   map["animator"]     = Property::Map()
1322                       .Add("alphaFunction", "LINEAR")
1323                       .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1324
1325   Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1326
1327   Animation animation = dummyImpl.CreateTransition(transition);
1328
1329   animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1330   animation.Play();
1331
1332   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1333   glAbstraction.EnableEnableDisableCallTrace(true);
1334   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1335   std::ostringstream blendStr;
1336   blendStr << std::hex << GL_BLEND;
1337
1338   application.SendNotification();
1339   application.Render(0);     // Ensure animation starts
1340   application.Render(2000u); // Halfway point
1341   Vector3 testColor(1.0f, 0.0f, 0.5f);
1342
1343   // uColor.a should be actor's alpha * mixColor.a.
1344   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1345   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1346
1347   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1348
1349   glEnableStack.Reset();
1350
1351   application.SendNotification();
1352   application.Render(2000u);
1353
1354   application.SendNotification();
1355   application.Render();
1356   application.SendNotification();
1357
1358   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1359   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1360   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1361
1362   // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1363
1364   TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1365
1366   END_TEST;
1367 }
1368
1369 int UtcDaliImageVisualAnimateOpacity(void)
1370 {
1371   ToolkitTestApplication application;
1372   tet_infoline("Animate image visual opacity");
1373
1374   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1375
1376   VisualFactory factory = VisualFactory::Get();
1377   Property::Map propertyMap;
1378   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1379   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1380   propertyMap.Insert("opacity", 0.5f);
1381   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1382   Visual::Base visual = factory.CreateVisual(propertyMap);
1383
1384   DummyControl        actor     = DummyControl::New(true);
1385   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1386   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1387
1388   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1389   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1390   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1391   application.GetScene().Add(actor);
1392
1393   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1394
1395   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1396   glAbstraction.EnableEnableDisableCallTrace(true);
1397   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1398   std::ostringstream blendStr;
1399   blendStr << std::hex << GL_BLEND;
1400
1401   application.SendNotification();
1402   application.Render();
1403
1404   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1405
1406   {
1407     tet_infoline("Test that the opacity can be increased to full via animation, and that the blend mode is set appropriately at the start and end of the animation.");
1408
1409     Property::Map map;
1410     map["target"]      = "testVisual";
1411     map["property"]    = "opacity";
1412     map["targetValue"] = 1.0f;
1413     map["animator"]    = Property::Map()
1414                         .Add("alphaFunction", "LINEAR")
1415                         .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1416
1417     Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1418     Animation                     animation  = dummyImpl.CreateTransition(transition);
1419     animation.Play();
1420
1421     glEnableStack.Reset();
1422
1423     application.SendNotification();
1424     application.Render(0);          // Ensure animation starts
1425     application.Render(2000u);      // Halfway point through animation
1426     application.SendNotification(); // Handle any signals
1427
1428     Vector4 color;
1429     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1430     DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1431
1432     application.Render(2001u);      // end
1433     application.SendNotification(); // ensure animation finished signal is sent
1434
1435     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1436     DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1437
1438     // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1439     DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1440   }
1441
1442   {
1443     tet_infoline("Test that the opacity can be reduced via animation, and that the blend mode is set appropriately at the start and end of the animation.");
1444
1445     Property::Map map;
1446     map["target"]      = "testVisual";
1447     map["property"]    = Visual::Property::OPACITY;
1448     map["targetValue"] = 0.1f;
1449     map["animator"]    = Property::Map()
1450                         .Add("alphaFunction", "LINEAR")
1451                         .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1452
1453     Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1454     Animation                     animation  = dummyImpl.CreateTransition(transition);
1455     animation.Play();
1456
1457     glEnableStack.Reset();
1458
1459     application.SendNotification();
1460     application.Render(0);     // Ensure animation starts
1461     application.Render(2000u); // Halfway point
1462     application.SendNotification();
1463
1464     Vector4 color;
1465     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1466     DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1467
1468     DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1469
1470     glEnableStack.Reset();
1471
1472     application.Render(2016u); // end
1473     application.SendNotification();
1474
1475     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1476     DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1477
1478     // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1479     DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1480   }
1481
1482   END_TEST;
1483 }
1484
1485 int UtcDaliImageVisualAnimateOpacity02(void)
1486 {
1487   ToolkitTestApplication application;
1488   tet_infoline("Animate image visual opacity");
1489
1490   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1491
1492   VisualFactory factory = VisualFactory::Get();
1493   Property::Map propertyMap;
1494   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1495   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1496   propertyMap.Insert("opacity", 0.5f);
1497   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1498   Visual::Base visual = factory.CreateVisual(propertyMap);
1499
1500   DummyControl        actor     = DummyControl::New(true);
1501   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1502   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1503
1504   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1505   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1506   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1507
1508   tet_infoline("Test that the opacity doesn't animate when actor not staged");
1509
1510   Property::Array array;
1511
1512   Property::Map map;
1513   map["target"]       = "testVisual";
1514   map["property"]     = "opacity";
1515   map["initialValue"] = 0.0f;
1516   map["targetValue"]  = 1.0f;
1517   map["animator"]     = Property::Map()
1518                       .Add("alphaFunction", "LINEAR")
1519                       .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1520
1521   Property::Map map2;
1522   map2["target"]      = "testVisual";
1523   map2["property"]    = "size";
1524   map2["targetValue"] = Vector2(1.0f, 1.0f);
1525
1526   array.Add(map).Add(map2);
1527
1528   Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1529   Animation                     animation  = dummyImpl.CreateTransition(transition);
1530
1531   application.GetScene().Add(actor);
1532   application.SendNotification();
1533   application.Render(0); // Ensure animation starts
1534
1535   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1536
1537   Renderer        renderer       = actor.GetRendererAt(0);
1538   Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1539   DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1540
1541   animation = dummyImpl.CreateTransition(transition);
1542   animation.Play();
1543
1544   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1545   glAbstraction.EnableEnableDisableCallTrace(true);
1546   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1547   std::ostringstream blendStr;
1548   blendStr << std::hex << GL_BLEND;
1549
1550   application.SendNotification();
1551   application.Render(0);          // Ensure animation starts
1552   application.Render(2000u);      // Halfway point through animation
1553   application.SendNotification(); // Handle any signals
1554
1555   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1556
1557   Vector4 color;
1558   DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1559   DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1560
1561   glEnableStack.Reset();
1562
1563   application.Render(2001u);      // end
1564   application.SendNotification(); // ensure animation finished signal is sent
1565
1566   DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1567   DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1568
1569   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1570
1571   END_TEST;
1572 }
1573
1574 int UtcDaliImageVisualAnimatePixelArea(void)
1575 {
1576   ToolkitTestApplication application;
1577   tet_infoline("ImageVisual animate pixel area");
1578
1579   static std::vector<UniformData> customUniforms =
1580     {
1581       UniformData("pixelArea", Property::Type::VECTOR4),
1582     };
1583
1584   TestGraphicsController& graphics = application.GetGraphicsController();
1585   graphics.AddCustomUniforms(customUniforms);
1586
1587   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1588
1589   VisualFactory factory = VisualFactory::Get();
1590   Property::Map propertyMap;
1591   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1592   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1593   propertyMap.Insert("mixColor", Color::BLUE);
1594   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1595   Visual::Base visual = factory.CreateVisual(propertyMap);
1596
1597   DummyControl        actor     = DummyControl::New(true);
1598   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1599   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1600
1601   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1602   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1603   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1604   application.GetScene().Add(actor);
1605
1606   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1607
1608   Renderer renderer = actor.GetRendererAt(0);
1609   // @todo Implement this feature?
1610   //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1611   //tet_infoline("Test that the renderer has the mixColor property");
1612   //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1613
1614   // TransitionData only takes string keys
1615   Property::Map map;
1616   map["target"]       = "testVisual";
1617   map["property"]     = "pixelArea";
1618   map["initialValue"] = Vector4(0, 0, 0, 1);
1619   map["targetValue"]  = Vector4(0, 0, 1, 1); // Animate width from zero to full
1620   map["animator"]     = Property::Map()
1621                       .Add("alphaFunction", "LINEAR")
1622                       .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1623
1624   Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1625
1626   Animation animation = dummyImpl.CreateTransition(transition);
1627   animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1628   animation.Play();
1629
1630   application.SendNotification();
1631   application.Render(0);     // Ensure animation starts
1632   application.Render(2000u); // Halfway point
1633
1634   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1635
1636   application.Render(2000u); // End of animation
1637
1638   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1639
1640   END_TEST;
1641 }
1642
1643 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1644 {
1645   ToolkitTestApplication application;
1646   tet_infoline("Request remote image visual, then destroy visual to cancel load");
1647
1648   Property::Map propertyMap;
1649   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1650   propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1651
1652   TestGlAbstraction& gl           = application.GetGlAbstraction();
1653   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1654   textureTrace.Enable(true);
1655   TraceCallStack& drawTrace = gl.GetDrawTrace();
1656   drawTrace.Enable(true);
1657
1658   Actor actor = CreateActorWithImageVisual(propertyMap);
1659   application.GetScene().Add(actor);
1660   application.SendNotification();
1661
1662   application.GetScene().Remove(actor);
1663   application.SendNotification();
1664
1665   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1666   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1667   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1668   DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1669
1670   END_TEST;
1671 }
1672
1673 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1674 {
1675   ToolkitTestApplication application;
1676   tet_infoline("Load image asynchronously, cancel loading, then load again");
1677
1678   VisualFactory factory = VisualFactory::Get();
1679   DALI_TEST_CHECK(factory);
1680
1681   Property::Map propertyMap;
1682   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1683   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1684
1685   Visual::Base visual = factory.CreateVisual(propertyMap);
1686   DALI_TEST_CHECK(visual);
1687
1688   TestGlAbstraction& gl           = application.GetGlAbstraction();
1689   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1690   textureTrace.Enable(true);
1691   TraceCallStack& drawTrace = gl.GetDrawTrace();
1692   drawTrace.Enable(true);
1693
1694   DummyControl      actor     = DummyControl::New();
1695   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1696   dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1697
1698   application.GetScene().Add(actor);
1699
1700   // Cancel loading
1701   application.GetScene().Remove(actor);
1702
1703   application.GetScene().Add(actor);
1704
1705   // Create another visual with the same image
1706   visual = factory.CreateVisual(propertyMap);
1707   DALI_TEST_CHECK(visual);
1708
1709   dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1710
1711   application.SendNotification();
1712   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1713
1714   application.SendNotification();
1715   application.Render();
1716
1717   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1718   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1719   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1720   DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1721
1722   END_TEST;
1723 }
1724
1725 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1726 {
1727   ToolkitTestApplication application;
1728   tet_infoline("Request image visual with invalid images - should draw broken.png");
1729
1730   VisualFactory factory = VisualFactory::Get();
1731   DALI_TEST_CHECK(factory);
1732
1733   Property::Map propertyMap;
1734   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1735   propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1736
1737   Visual::Base visual = factory.CreateVisual(propertyMap);
1738   DALI_TEST_CHECK(visual);
1739
1740   TestGlAbstraction& gl           = application.GetGlAbstraction();
1741   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1742   textureTrace.Enable(true);
1743
1744   DummyControl      actor     = DummyControl::New();
1745   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1746   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1747
1748   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1749   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1750
1751   application.GetScene().Add(actor);
1752
1753   application.SendNotification();
1754   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1755
1756   application.SendNotification();
1757   application.Render();
1758
1759   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1760   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1761
1762   application.GetScene().Remove(actor);
1763   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1764
1765   END_TEST;
1766 }
1767
1768 int UtcDaliImageVisualSetInvalidSyncImage(void)
1769 {
1770   ToolkitTestApplication application;
1771   tet_infoline("Request image visual with invalid images - should draw broken.png");
1772
1773   VisualFactory factory = VisualFactory::Get();
1774   DALI_TEST_CHECK(factory);
1775
1776   Property::Map propertyMap;
1777   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1778   propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1779   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1780
1781   Visual::Base visual = factory.CreateVisual(propertyMap);
1782   DALI_TEST_CHECK(visual);
1783
1784   TestGlAbstraction& gl           = application.GetGlAbstraction();
1785   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1786   textureTrace.Enable(true);
1787
1788   DummyControl      actor     = DummyControl::New();
1789   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1790   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1791
1792   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1793   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1794
1795   application.GetScene().Add(actor);
1796
1797   application.SendNotification();
1798   application.Render();
1799
1800   // Check resource status
1801   Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1802   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1803
1804   // The broken image should be shown.
1805   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1806   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1807
1808   application.GetScene().Remove(actor);
1809   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1810
1811   END_TEST;
1812 }
1813
1814 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1815 {
1816   ToolkitTestApplication application;
1817   tet_infoline("Request image visual with invalid images - should draw broken.png");
1818
1819   VisualFactory factory = VisualFactory::Get();
1820   DALI_TEST_CHECK(factory);
1821
1822   // Local invalid file, asynchronous loading
1823   Property::Map propertyMap;
1824   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1825   propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1826
1827   Visual::Base visual = factory.CreateVisual(propertyMap);
1828   DALI_TEST_CHECK(visual);
1829
1830   TestGlAbstraction& gl           = application.GetGlAbstraction();
1831   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1832   textureTrace.Enable(true);
1833
1834   DummyControl      actor     = DummyControl::New();
1835   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1836   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1837
1838   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1839   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1840
1841   application.GetScene().Add(actor);
1842
1843   application.SendNotification();
1844   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1845
1846   application.SendNotification();
1847   application.Render();
1848
1849   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1850   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1851
1852   application.GetScene().Remove(actor);
1853   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1854
1855   END_TEST;
1856 }
1857
1858 int UtcDaliImageVisualAlphaMask01(void)
1859 {
1860   ToolkitTestApplication application;
1861   tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1862
1863   VisualFactory factory = VisualFactory::Get();
1864   DALI_TEST_CHECK(factory);
1865
1866   Property::Map propertyMap;
1867   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1868   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1869   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1870
1871   Visual::Base visual = factory.CreateVisual(propertyMap);
1872   DALI_TEST_CHECK(visual);
1873
1874   Property::Map testMap;
1875   visual.CreatePropertyMap(testMap);
1876   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1877
1878   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1879   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1880
1881   TestGlAbstraction& gl           = application.GetGlAbstraction();
1882   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1883   textureTrace.Enable(true);
1884
1885   DummyControl      actor     = DummyControl::New();
1886   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1887   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1888
1889   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1890   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1891   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1892
1893   application.GetScene().Add(actor);
1894   application.SendNotification();
1895   application.Render();
1896
1897   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1898
1899   application.SendNotification();
1900   application.Render();
1901
1902   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1903   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1904   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1905
1906   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1907   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1908
1909   END_TEST;
1910 }
1911
1912 int UtcDaliImageVisualAlphaMask02(void)
1913 {
1914   ToolkitTestApplication application;
1915   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
1916
1917   VisualFactory factory = VisualFactory::Get();
1918   DALI_TEST_CHECK(factory);
1919
1920   Property::Map propertyMap;
1921   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1922   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1923   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1924   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1925
1926   Visual::Base visual = factory.CreateVisual(propertyMap);
1927   DALI_TEST_CHECK(visual);
1928
1929   Property::Map testMap;
1930   visual.CreatePropertyMap(testMap);
1931   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1932   DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
1933
1934   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1935   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1936
1937   TestGlAbstraction& gl           = application.GetGlAbstraction();
1938   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1939   textureTrace.Enable(true);
1940
1941   DummyControl      actor     = DummyControl::New();
1942   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1943   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1944
1945   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1946   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1947   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1948
1949   application.GetScene().Add(actor);
1950   application.SendNotification();
1951   application.Render();
1952
1953   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1954
1955   application.SendNotification();
1956   application.Render();
1957
1958   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1959   Renderer   renderer = actor.GetRendererAt(0u);
1960   TextureSet textures = renderer.GetTextures();
1961   DALI_TEST_CHECK(textures);
1962   DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1963
1964   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1965   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1966
1967   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1968   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1969
1970   END_TEST;
1971 }
1972
1973 int UtcDaliImageVisualAlphaMask03(void)
1974 {
1975   ToolkitTestApplication application;
1976   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
1977
1978   VisualFactory factory = VisualFactory::Get();
1979   DALI_TEST_CHECK(factory);
1980
1981   Property::Map propertyMap;
1982   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1983   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1984   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
1985   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1986
1987   Visual::Base visual = factory.CreateVisual(propertyMap);
1988   DALI_TEST_CHECK(visual);
1989
1990   Property::Map testMap;
1991   visual.CreatePropertyMap(testMap);
1992
1993   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1994   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1995
1996   TestGlAbstraction& gl           = application.GetGlAbstraction();
1997   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1998   textureTrace.Enable(true);
1999
2000   DummyControl      actor     = DummyControl::New();
2001   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2002   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2003
2004   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2005   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2006   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2007
2008   application.GetScene().Add(actor);
2009   application.SendNotification();
2010   application.Render();
2011
2012   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2013
2014   application.SendNotification();
2015   application.Render();
2016
2017   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2018   Renderer   renderer = actor.GetRendererAt(0u);
2019   TextureSet textures = renderer.GetTextures();
2020   DALI_TEST_CHECK(textures);
2021   DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2022
2023   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2024   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2025
2026   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2027   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2028
2029   END_TEST;
2030 }
2031
2032 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2033 {
2034   ToolkitTestApplication application;
2035   tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2036
2037   VisualFactory factory = VisualFactory::Get();
2038   DALI_TEST_CHECK(factory);
2039
2040   Property::Map propertyMap;
2041   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2042   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2043   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2044   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2045
2046   Visual::Base visual = factory.CreateVisual(propertyMap);
2047   DALI_TEST_CHECK(visual);
2048
2049   Property::Map testMap;
2050   visual.CreatePropertyMap(testMap);
2051   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2052
2053   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2054   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2055
2056   TestGlAbstraction& gl           = application.GetGlAbstraction();
2057   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2058   textureTrace.Enable(true);
2059
2060   DummyControl      actor     = DummyControl::New();
2061   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2062   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2063
2064   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2065   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2066   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2067
2068   application.GetScene().Add(actor);
2069
2070   // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2071
2072   application.SendNotification();
2073   application.Render();
2074
2075   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2076   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2077   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2078
2079   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2080   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2081
2082   END_TEST;
2083 }
2084
2085 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2086 {
2087   ToolkitTestApplication application;
2088   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2089
2090   VisualFactory factory = VisualFactory::Get();
2091   DALI_TEST_CHECK(factory);
2092
2093   Property::Map propertyMap;
2094   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2095   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2096   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2097   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2098   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2099
2100   Visual::Base visual = factory.CreateVisual(propertyMap);
2101   DALI_TEST_CHECK(visual);
2102
2103   Property::Map testMap;
2104   visual.CreatePropertyMap(testMap);
2105   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2106
2107   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2108   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2109
2110   TestGlAbstraction& gl           = application.GetGlAbstraction();
2111   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2112   textureTrace.Enable(true);
2113
2114   DummyControl      actor     = DummyControl::New();
2115   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2116   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2117
2118   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2119   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2120   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2121
2122   application.GetScene().Add(actor);
2123
2124   // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2125
2126   application.SendNotification();
2127   application.Render();
2128
2129   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2130   Renderer   renderer = actor.GetRendererAt(0u);
2131   TextureSet textures = renderer.GetTextures();
2132   DALI_TEST_CHECK(textures);
2133   DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2134
2135   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2136   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2137
2138   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2139   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2140
2141   END_TEST;
2142 }
2143
2144 int UtcDaliImageVisualRemoteAlphaMask(void)
2145 {
2146   ToolkitTestApplication application;
2147   tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2148
2149   VisualFactory factory = VisualFactory::Get();
2150   DALI_TEST_CHECK(factory);
2151
2152   const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2153
2154   Property::Map propertyMap;
2155   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2156   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2157   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2158
2159   Visual::Base visual = factory.CreateVisual(propertyMap);
2160   DALI_TEST_CHECK(visual);
2161
2162   Property::Map testMap;
2163   visual.CreatePropertyMap(testMap);
2164
2165   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2166
2167   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2168   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2169
2170   TestGlAbstraction& gl           = application.GetGlAbstraction();
2171   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2172   textureTrace.Enable(true);
2173
2174   DummyControl      actor     = DummyControl::New();
2175   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2176   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2177
2178   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2179
2180   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2181   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2182
2183   application.GetScene().Add(actor);
2184   application.SendNotification();
2185   application.Render();
2186
2187   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2188
2189   application.SendNotification();
2190   application.Render();
2191
2192   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2193   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2194   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2195
2196   END_TEST;
2197 }
2198
2199 int UtcDaliImageVisualAlphaMaskCrop(void)
2200 {
2201   ToolkitTestApplication application;
2202   tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2203
2204   VisualFactory factory = VisualFactory::Get();
2205   DALI_TEST_CHECK(factory);
2206
2207   Property::Map propertyMap;
2208   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2209   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2210   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2211   propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2212   propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2213
2214   Visual::Base visual = factory.CreateVisual(propertyMap);
2215   DALI_TEST_CHECK(visual);
2216
2217   Property::Map testMap;
2218   visual.CreatePropertyMap(testMap);
2219   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2220   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2221   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2222
2223   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2224   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2225
2226   TestGlAbstraction& gl           = application.GetGlAbstraction();
2227   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2228   textureTrace.Enable(true);
2229
2230   DummyControl      actor     = DummyControl::New();
2231   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2232   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2233
2234   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2235   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2236   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2237
2238   application.GetScene().Add(actor);
2239   application.SendNotification();
2240   application.Render();
2241
2242   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2243
2244   application.SendNotification();
2245   application.Render();
2246
2247   Vector2 size;
2248   visual.GetNaturalSize(size);
2249
2250   DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2251   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2252   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2253   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2254
2255   END_TEST;
2256 }
2257
2258 int UtcDaliImageVisualReleasePolicy01(void)
2259 {
2260   ToolkitTestApplication application;
2261   tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2262
2263   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2264   DALI_TEST_CHECK(imageVisual);
2265
2266   // Set up debug trace
2267   TestGlAbstraction& gl           = application.GetGlAbstraction();
2268   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2269   textureTrace.Enable(true);
2270
2271   tet_infoline("Register visual with control and ensure it has the only handle");
2272   DummyControl        actor     = DummyControl::New(true);
2273   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2274   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2275   imageVisual.Reset();
2276
2277   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2278
2279   application.SendNotification();
2280   application.Render(0);
2281   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2282   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2283
2284   application.GetScene().Add(actor);
2285
2286   // Wait for image to load
2287   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2288
2289   application.SendNotification();
2290   application.Render(0);
2291   // Test renderer and texture created
2292   tet_infoline("Confirm texture created");
2293   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2294   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2295
2296   tet_infoline("Disable visual causing the texture to be deleted");
2297   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2298
2299   application.SendNotification();
2300   application.Render(0);
2301   // Test renderer and textures removed.
2302   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2303   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2304
2305   END_TEST;
2306 }
2307
2308 int UtcDaliImageVisualReleasePolicy02(void)
2309 {
2310   ToolkitTestApplication application;
2311   tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2312
2313   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2314   DALI_TEST_CHECK(imageVisual);
2315
2316   // Setup debug trace
2317   TestGlAbstraction& gl           = application.GetGlAbstraction();
2318   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2319   textureTrace.Enable(true);
2320
2321   tet_infoline("Register visual with control and ensure it has the only handle");
2322   DummyControl        actor     = DummyControl::New(true);
2323   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2324   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2325   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2326
2327   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2328
2329   application.SendNotification();
2330   application.Render(0);
2331   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2332   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2333
2334   application.GetScene().Add(actor);
2335
2336   // Wait for image to load
2337   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2338
2339   application.SendNotification();
2340   application.Render(0);
2341   // Test renderer and texture created
2342   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2343   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2344
2345   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2346   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2347   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2348   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2349   application.SendNotification();
2350   application.Render();
2351
2352   // Test texture removed after visual destroyed.
2353   tet_infoline("Ensure texture is deleted after visual destroyed");
2354   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2355
2356   END_TEST;
2357 }
2358
2359 int UtcDaliImageVisualReleasePolicy03(void)
2360 {
2361   ToolkitTestApplication application;
2362   tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2363
2364   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2365   DALI_TEST_CHECK(imageVisual);
2366
2367   TestGlAbstraction& gl           = application.GetGlAbstraction();
2368   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2369   textureTrace.Enable(true);
2370
2371   tet_infoline("Register visual with control and ensure it has the only handle");
2372   DummyControl        actor     = DummyControl::New(true);
2373   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2374   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2375   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2376
2377   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2378
2379   application.SendNotification();
2380   application.Render(0);
2381   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2382   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2383
2384   application.GetScene().Add(actor);
2385
2386   // Wait for image to load
2387   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2388
2389   application.SendNotification();
2390   application.Render(0);
2391   // Test renderer and texture created
2392   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2393   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2394
2395   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2396   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2397   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2398   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2399   application.SendNotification();
2400   application.Render();
2401
2402   tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2403   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2404
2405   END_TEST;
2406 }
2407
2408 int UtcDaliImageVisualReleasePolicy04(void)
2409 {
2410   ToolkitTestApplication application;
2411   tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2412
2413   tet_infoline("Create first visual with Never release policy");
2414   Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2415
2416   tet_infoline("Create second visual with Destroyed release policy");
2417   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2418
2419   // Set up trace debug
2420   TestGlAbstraction& gl           = application.GetGlAbstraction();
2421   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2422   textureTrace.Enable(true);
2423
2424   tet_infoline("Register visuals with control and ensure it has the only handles");
2425   DummyControl        actor     = DummyControl::New(true);
2426   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2427   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2428   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2429   imageVisualNever.Reset();     // reduce ref count so only the control keeps the visual alive.
2430   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2431
2432   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2433
2434   // Test initially zero renderers
2435   application.SendNotification();
2436   application.Render(0);
2437   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2438   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2439
2440   application.GetScene().Add(actor);
2441
2442   // Wait for image to load
2443   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2444
2445   application.SendNotification();
2446   application.Render(0);
2447   tet_infoline("Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer");
2448   DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2449   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2450
2451   // Test renderer removed when visual destroyed
2452   DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2453   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2454   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2455   application.SendNotification();
2456   application.Render();
2457
2458   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2459   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2460
2461   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2462   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2463   application.SendNotification();
2464   application.Render();
2465
2466   tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2467   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2468   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2469
2470   END_TEST;
2471 }
2472
2473 int UtcDaliImageVisualReleasePolicy05(void)
2474 {
2475   ToolkitTestApplication application;
2476   tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2477
2478   VisualFactory factory = VisualFactory::Get();
2479
2480   Property::Map propertyMapNeverReleasePolicy;
2481   propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2482   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2483   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2484   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2485   propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2486
2487   Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2488
2489   Property::Map resultMap;
2490   imageVisualNever.CreatePropertyMap(resultMap);
2491   DALI_TEST_CHECK(!resultMap.Empty());
2492
2493   DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2494
2495   END_TEST;
2496 }
2497
2498 int UtcDaliImageVisualReleasePolicy06(void)
2499 {
2500   ToolkitTestApplication application;
2501   tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2502
2503   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2504   DALI_TEST_CHECK(imageVisual);
2505
2506   TestGlAbstraction& gl           = application.GetGlAbstraction();
2507   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2508   textureTrace.Enable(true);
2509
2510   tet_infoline("Register visual with control and ensure it has the only handle");
2511   DummyControl        actor     = DummyControl::New(true);
2512   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2513   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2514   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2515
2516   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2517
2518   application.SendNotification();
2519   application.Render(0);
2520   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2521   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2522
2523   application.GetScene().Add(actor);
2524
2525   // Wait for image to load
2526   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2527
2528   application.SendNotification();
2529   application.Render(0);
2530   // Test renderer and texture created
2531   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2532   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2533   textureTrace.Reset();
2534
2535   tet_infoline("Disable Visual and check texture not affected");
2536   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2537   application.SendNotification();
2538   application.Render(0);
2539   tet_infoline("Check renderer is destroyed when visual off stage");
2540   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2541   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2542   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2543   textureTrace.Reset();
2544
2545   tet_infoline("Re-enable Visual and check texture not affected");
2546   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2547   application.SendNotification();
2548   application.Render(0);
2549   tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2550   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2551   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2552   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2553
2554   END_TEST;
2555 }
2556
2557 int UtcDaliImageVisualReleasePolicy07(void)
2558 {
2559   ToolkitTestApplication application;
2560   tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2561
2562   tet_infoline("Create first visual with DESTROYED release policy");
2563   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2564
2565   tet_infoline("Create second visual with DETACHED release policy");
2566   Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2567
2568   // Set up trace debug
2569   TestGlAbstraction& gl           = application.GetGlAbstraction();
2570   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2571   textureTrace.Enable(true);
2572
2573   tet_infoline("Register visuals with control and ensure it has the only handles");
2574   DummyControl        actor     = DummyControl::New(true);
2575   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2576   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2577   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2578   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2579   imageVisualDetached.Reset();  // reduce ref count so only the control keeps the visual alive.
2580
2581   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2582
2583   // Test initially zero renderers
2584   application.SendNotification();
2585   application.Render(0);
2586   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2587   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2588
2589   application.GetScene().Add(actor);
2590
2591   // Wait for image to load
2592   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2593
2594   application.SendNotification();
2595   application.Render(0);
2596   tet_infoline("Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer");
2597   DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2598   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2599
2600   // Test renderer removed when visual destroyed
2601   DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2602   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2603   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2604   application.SendNotification();
2605   application.Render();
2606
2607   // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2608   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2609
2610   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2611   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2612   application.SendNotification();
2613   application.Render();
2614
2615   tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2616   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2617
2618   END_TEST;
2619 }
2620
2621 int UtcDaliImageVisualReleasePolicy08(void)
2622 {
2623   ToolkitTestApplication application;
2624   tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2625
2626   tet_infoline("Create first visual with DESTROYED release policy");
2627   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2628
2629   // Set up trace debug
2630   TestGlAbstraction& gl           = application.GetGlAbstraction();
2631   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2632   textureTrace.Enable(true);
2633
2634   tet_infoline("Register visuals with control and ensure it has the only handles");
2635   DummyControl        actor     = DummyControl::New(true);
2636   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2637   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2638   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2639
2640   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2641
2642   // Test initially zero renderers
2643   application.SendNotification();
2644   application.Render(0);
2645   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2646   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2647   textureTrace.Reset();
2648
2649   application.GetScene().Add(actor);
2650
2651   // Wait for image to load
2652   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2653
2654   application.SendNotification();
2655   application.Render(0);
2656   tet_infoline("Ensure a texture is created");
2657   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2658   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2659   textureTrace.Reset();
2660
2661   // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2662   // 1. Get Texture
2663   Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2664
2665   // 2.Remove actor from stage. In this case, renderer also is deleted.
2666   tet_infoline("Remove actor from stage");
2667   application.GetScene().Remove(actor);
2668   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2669   application.SendNotification();
2670   application.Render();
2671
2672   tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2673   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2674   textureTrace.Reset();
2675
2676   // 3.Add actor in stage. In this case, renderer is created.
2677   tet_infoline("Add actor in stage");
2678   application.GetScene().Add(actor);
2679   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2680   application.SendNotification();
2681   application.Render();
2682   tet_infoline("Ensure a texture is not created again");
2683   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2684   textureTrace.Reset();
2685
2686   // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2687   tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2688   Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2689   DALI_TEST_CHECK(textureBefore == textureAfter);
2690   textureBefore.Reset();
2691   textureAfter.Reset();
2692
2693   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2694   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2695   application.SendNotification();
2696   application.Render();
2697   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2698
2699   END_TEST;
2700 }
2701
2702 int UtcDaliImageVisualReleasePolicy09(void)
2703 {
2704   ToolkitTestApplication application;
2705   tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2706
2707   Property::Map propertyMapNPatchReleasePolicy;
2708   propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2709   propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2710   propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2711   propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2712   propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2713
2714   VisualFactory factory     = VisualFactory::Get();
2715   Visual::Base  imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2716   DALI_TEST_CHECK(imageVisual);
2717
2718   // Setup debug trace
2719   TestGlAbstraction& gl           = application.GetGlAbstraction();
2720   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2721   textureTrace.Enable(true);
2722
2723   tet_infoline("Register visual with control and ensure it has the only handle");
2724   DummyControl        actor     = DummyControl::New(true);
2725   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2726   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2727   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2728
2729   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2730
2731   application.SendNotification();
2732   application.Render(0);
2733   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2734   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2735
2736   application.GetScene().Add(actor);
2737
2738   // Wait for image to load
2739   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2740
2741   application.SendNotification();
2742   application.Render(0);
2743   // Test renderer and texture created
2744   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2745   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2746
2747   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2748   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2749   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2750   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2751   application.SendNotification();
2752   application.Render();
2753
2754   // Test texture removed after visual destroyed.
2755   tet_infoline("Ensure texture is deleted after visual destroyed");
2756   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2757
2758   END_TEST;
2759 }
2760
2761 int UtcDaliImageVisualLoadPolicy01(void)
2762 {
2763   ToolkitTestApplication application;
2764   tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2765
2766   // Set up trace debug
2767   TestGlAbstraction& gl           = application.GetGlAbstraction();
2768   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2769   textureTrace.Enable(true);
2770
2771   tet_infoline("Create visual with IMMEDIATE load policy");
2772   VisualFactory factory = VisualFactory::Get();
2773
2774   Property::Map propertyMap;
2775   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2776   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2777   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2778   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2779   propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2780
2781   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2782
2783   Property::Map resultMap;
2784   imageVisual.CreatePropertyMap(resultMap);
2785   DALI_TEST_CHECK(!resultMap.Empty());
2786   DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2787
2788   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2789
2790   // Ensure texture has been uploaded
2791   application.SendNotification();
2792   application.Render();
2793
2794   tet_infoline("Ensure texture loading starts after visual created");
2795   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2796   textureTrace.Reset();
2797
2798   tet_infoline("Register visuals with control and ensure it has the only handles");
2799   DummyControl        actor     = DummyControl::New(true);
2800   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2801   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2802   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2803
2804   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2805   application.GetScene().Add(actor);
2806   tet_infoline("Ensure nothing triggers another load as texure already loaded");
2807   const unsigned int TIME_OUT_3_SECONDS = 3;
2808   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2809
2810   application.SendNotification();
2811   application.Render();
2812
2813   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2814   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2815
2816   // Ensure texture is deleted when no longer needed (ref count was correct )
2817   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2818
2819   application.SendNotification();
2820   application.Render();
2821
2822   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2823   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2824
2825   END_TEST;
2826 }
2827
2828 int UtcDaliImageVisualLoadPolicy02(void)
2829 {
2830   ToolkitTestApplication application;
2831   tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2832
2833   // Set up trace debug
2834   TestGlAbstraction& gl           = application.GetGlAbstraction();
2835   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2836   textureTrace.Enable(true);
2837
2838   tet_infoline("Create visual with IMMEDIATE load policy");
2839   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2840
2841   const unsigned int TIME_OUT_3_SECONDS = 3;
2842   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2843
2844   // Act on meeage queue even although nothing expected to load
2845   application.SendNotification();
2846   application.Render();
2847
2848   tet_infoline("Ensure texture is not generated yet");
2849   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2850   textureTrace.Reset();
2851
2852   tet_infoline("Register visuals with control and ensure it has the only handles");
2853   DummyControl        actor     = DummyControl::New(true);
2854   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2855   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2856   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2857
2858   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2859   application.GetScene().Add(actor);
2860   tet_infoline("Allow image time to load");
2861   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2862
2863   application.SendNotification();
2864   application.Render();
2865
2866   tet_infoline("Ensure texture generated and renderer created");
2867   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2868   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2869
2870   // Ensure texture is delete when no longer needed
2871   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2872
2873   application.SendNotification();
2874   application.Render();
2875
2876   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2877   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2878
2879   END_TEST;
2880 }
2881
2882 int UtcDaliImageVisualLoadPolicy03(void)
2883 {
2884   ToolkitTestApplication application;
2885   tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2886
2887   const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2888
2889   // Set up trace debug
2890   TestGlAbstraction& gl           = application.GetGlAbstraction();
2891   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2892   textureTrace.Enable(true);
2893
2894   tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2895   DummyControl actor = DummyControl::New(true);
2896   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2897   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2898   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2899
2900   tet_infoline("Create visual with IMMEDIATE load policy");
2901   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2902
2903   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2904   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2905   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2906
2907   tet_infoline("Allow image time to load resource");
2908   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2909   application.SendNotification();
2910   application.Render();
2911
2912   // Ensure texture has been uploaded
2913   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2914   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2915
2916   END_TEST;
2917 }
2918
2919 int UtcDaliImageVisualLoadPolicy04(void)
2920 {
2921   ToolkitTestApplication application;
2922   tet_infoline("UtcDaliImageVisualLoadPolicy04 First part  Load a visual image before attaching to stage");
2923   tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2924
2925   const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2926
2927   // Set up trace debug
2928   TestGlAbstraction& gl           = application.GetGlAbstraction();
2929   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2930   textureTrace.Enable(true);
2931
2932   tet_infoline("Create a control and connect to resource ready signal");
2933   DummyControl actor = DummyControl::New(true);
2934   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2935   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2936   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2937
2938   tet_infoline("Create visual with IMMEDIATE load policy");
2939   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2940
2941   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2942   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2943   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2944
2945   tet_infoline("Allow image time to load");
2946   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2947   application.SendNotification();
2948   application.Render();
2949
2950   tet_infoline("Testing texture is loaded and resource ready signal fired");
2951   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2952   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2953
2954   tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2955
2956   gResourceReadySignalFired        = false; // Reset signal check ready for testing next Control
2957   Visual::Base        imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2958   DummyControl        actor2       = DummyControl::New(true);
2959   Impl::DummyControl& dummyImpl2   = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2960   actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2961
2962   tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2963   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2964   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2965   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2966   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2967   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2968
2969   END_TEST;
2970 }
2971
2972 int UtcDaliImageVisualLoadPolicy05(void)
2973 {
2974   ToolkitTestApplication application;
2975   tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part  Load a visual image before attaching to stage");
2976   tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2977   // Set up trace debug
2978   TestGlAbstraction& gl           = application.GetGlAbstraction();
2979   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2980   textureTrace.Enable(true);
2981
2982   tet_infoline("Create a control and connect to resource ready signal");
2983   DummyControl actor = DummyControl::New(true);
2984   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2985   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2986   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2987   application.GetScene().Add(actor);
2988
2989   tet_infoline("Create visual with ATTACHED load policy");
2990   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2991
2992   tet_infoline("Registering visual allows control to get a signal once loaded");
2993   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2994   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2995
2996   tet_infoline("Allow image time to load");
2997   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2998   application.SendNotification();
2999   application.Render();
3000
3001   tet_infoline("Testing texture is loaded and resource ready signal fired");
3002   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3003   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3004
3005   tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3006
3007   gResourceReadySignalFired        = false; // Reset signal check ready for testing next Control
3008   Visual::Base        imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3009   DummyControl        actor2       = DummyControl::New(true);
3010   Impl::DummyControl& dummyImpl2   = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3011   actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3012
3013   tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3014   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3015   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3016   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3017   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3018   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3019
3020   END_TEST;
3021 }
3022
3023 int UtcDaliImageVisualOrientationCorrection(void)
3024 {
3025   ToolkitTestApplication application;
3026   tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3027
3028   VisualFactory factory = VisualFactory::Get();
3029   tet_infoline("Create visual with Orientation correction set OFF");
3030   Property::Map propertyMap;
3031   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3032   propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3033   propertyMap.Insert("orientationCorrection", false);
3034   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3035
3036   tet_infoline("Create control for visual, need to loaded it");
3037   DummyControl        actor     = DummyControl::New(true);
3038   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3039   application.GetScene().Add(actor);
3040
3041   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3042   // Wait for image to load
3043   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3044
3045   Vector2 originalImageSize;
3046   tet_infoline("Get size of original visual to compare later with rotated image");
3047   imageVisual.GetNaturalSize(originalImageSize);
3048   DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3049   imageVisual.Reset();                                                                 // remove handle so can unregister it and remove from cache
3050   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3051   application.SendNotification();
3052   application.Render();
3053
3054   tet_infoline("Create visual with Orientation correction set ON ");
3055   propertyMap.Clear();
3056   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3057   propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3058   propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3059   imageVisual = factory.CreateVisual(propertyMap);
3060
3061   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3062   // Wait for image to load
3063   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3064
3065   Vector2 rotatedImageSize;
3066   imageVisual.GetNaturalSize(rotatedImageSize);
3067   tet_infoline("Confirm that visual has rotated");
3068   DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3069   DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3070
3071   Property::Map resultMap;
3072   imageVisual.CreatePropertyMap(resultMap);
3073
3074   // check the Property::ORIENTATION_CORRECTION value from the returned map
3075   Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3076   DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3077
3078   END_TEST;
3079 }
3080
3081 int UtcDaliImageVisualCustomShader(void)
3082 {
3083   ToolkitTestApplication application;
3084   tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3085
3086   VisualFactory     factory = VisualFactory::Get();
3087   Property::Map     properties;
3088   Property::Map     shader;
3089   const std::string vertexShader                    = "Foobar";
3090   const std::string fragmentShader                  = "Foobar";
3091   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3092   shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
3093
3094   properties[Visual::Property::TYPE]     = Visual::IMAGE;
3095   properties[Visual::Property::SHADER]   = shader;
3096   properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3097
3098   Visual::Base visual = factory.CreateVisual(properties);
3099
3100   // trigger creation through setting on stage
3101   DummyControl        dummy     = DummyControl::New(true);
3102   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3103   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3104
3105   dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3106   dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3107   application.GetScene().Add(dummy);
3108
3109   application.SendNotification();
3110   application.Render();
3111
3112   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3113
3114   Renderer        renderer = dummy.GetRendererAt(0);
3115   Shader          shader2  = renderer.GetShader();
3116   Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
3117   Property::Map*  map      = value.GetMap();
3118   DALI_TEST_CHECK(map);
3119
3120   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3121   DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3122
3123   Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3124   DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3125
3126   shader.Clear();
3127
3128   shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3129   properties[Visual::Property::SHADER]    = shader;
3130
3131   Visual::Base visual1 = factory.CreateVisual(properties);
3132
3133   // trigger creation through setting on stage
3134   DummyControl        dummy1     = DummyControl::New(true);
3135   Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3136   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3137   dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3138   dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3139   application.GetScene().Add(dummy1);
3140
3141   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3142   glAbstraction.EnableEnableDisableCallTrace(true);
3143
3144   application.SendNotification();
3145   application.Render();
3146
3147   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
3148   std::ostringstream blendStr;
3149   blendStr << std::hex << GL_BLEND;
3150   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3151
3152   END_TEST;
3153 }
3154
3155 void ResourceReadyLoadNext(Control control)
3156 {
3157   static int callNumber = 0;
3158
3159   gResourceReadySignalFired = true;
3160   gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3161
3162   if(callNumber == 0)
3163   {
3164     DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3165
3166     tet_infoline("Create visual with loaded image from within the signal handler");
3167     VisualFactory factory     = VisualFactory::Get();
3168     Visual::Base  imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3169
3170     Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3171     controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3172     callNumber = 1;
3173   }
3174   else
3175   {
3176     tet_infoline("3rd signal called");
3177     DALI_TEST_CHECK(true);
3178   }
3179 }
3180
3181 int UtcDaliImageVisualLoadReady01(void)
3182 {
3183   ToolkitTestApplication application;
3184   tet_infoline("UtcDaliImageVisualLoadReady01");
3185   tet_infoline("First part:  Load an image visual for one resource, then another image visual for a second resource.");
3186   tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3187   tet_infoline("Should get a ready signal for all three visuals");
3188
3189   ClearReadyIds();
3190
3191   tet_infoline("Create a control and connect to resource ready signal");
3192   DummyControl actor    = DummyControl::New(true);
3193   int          actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3194   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3195   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3196   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3197   application.GetScene().Add(actor);
3198
3199   tet_infoline("Create visual with IMMEDIATE load policy");
3200   Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3201
3202   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3203   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3204
3205   tet_infoline("Allow image time to load");
3206   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3207   application.SendNotification();
3208   application.Render();
3209
3210   tet_infoline("Testing texture is loaded and resource ready signal fired");
3211   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3212   DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3213
3214   tet_infoline("Original control correctly signalled, now testing failing image");
3215
3216   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3217   ClearReadyIds();
3218
3219   Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3220
3221   DummyControl        actor2     = DummyControl::New(true);
3222   int                 actor2Id   = actor2.GetProperty<int>(Actor::Property::ID);
3223   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3224   actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3225
3226   tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3227   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3228
3229   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3230   application.GetScene().Add(actor2);
3231
3232   tet_infoline("Wait for loading thread to finish");
3233   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3234   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3235
3236   DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3237
3238   tet_infoline("Check for 3rd signal");
3239   application.SendNotification();
3240   DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3241   DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3242
3243   END_TEST;
3244 }
3245
3246 int UtcDaliImageVisualLoadImagePlanes01(void)
3247 {
3248   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3249   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3250
3251   ToolkitTestApplication application;
3252
3253   VisualFactory factory = VisualFactory::Get();
3254   DALI_TEST_CHECK(factory);
3255
3256   Property::Map propertyMap;
3257   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3258   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3259
3260   Visual::Base visual = factory.CreateVisual(propertyMap);
3261   DALI_TEST_CHECK(visual);
3262
3263   DummyControl      actor     = DummyControl::New();
3264   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3265   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3266   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3267   application.GetScene().Add(actor);
3268
3269   application.SendNotification();
3270   application.Render();
3271
3272   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3273
3274   TestGlAbstraction& gl           = application.GetGlAbstraction();
3275   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3276   textureTrace.Enable(true);
3277
3278   application.SendNotification();
3279   application.Render();
3280
3281   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3282   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3283   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3284
3285   Renderer renderer           = actor.GetRendererAt(0);
3286   auto     preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3287   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3288
3289   END_TEST;
3290 }
3291
3292 int UtcDaliImageVisualLoadImagePlanes02(void)
3293 {
3294   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3295   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3296
3297   ToolkitTestApplication application;
3298
3299   VisualFactory factory = VisualFactory::Get();
3300   DALI_TEST_CHECK(factory);
3301
3302   // Alpha masking case - not support yuv planes
3303   Property::Map propertyMap;
3304   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3305   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3306   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3307
3308   Visual::Base visual = factory.CreateVisual(propertyMap);
3309   DALI_TEST_CHECK(visual);
3310
3311   DummyControl      actor     = DummyControl::New();
3312   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3313   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3314   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3315   application.GetScene().Add(actor);
3316
3317   application.SendNotification();
3318   application.Render();
3319
3320   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3321
3322   TestGlAbstraction& gl           = application.GetGlAbstraction();
3323   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3324   textureTrace.Enable(true);
3325
3326   application.SendNotification();
3327   application.Render();
3328
3329   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3330   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3331   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3332
3333   END_TEST;
3334 }
3335
3336 int UtcDaliImageVisualLoadImagePlanes03(void)
3337 {
3338   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3339   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3340
3341   ToolkitTestApplication application;
3342
3343   VisualFactory factory = VisualFactory::Get();
3344   DALI_TEST_CHECK(factory);
3345
3346   TestGlAbstraction& gl           = application.GetGlAbstraction();
3347   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3348   textureTrace.Enable(true);
3349
3350   Property::Map propertyMap;
3351   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3352   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3353   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3354
3355   Visual::Base visual = factory.CreateVisual(propertyMap);
3356   DALI_TEST_CHECK(visual);
3357
3358   DummyControl      actor     = DummyControl::New();
3359   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3360   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3361   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3362   application.GetScene().Add(actor);
3363
3364   application.SendNotification();
3365   application.Render();
3366
3367   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3368   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3369   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3370
3371   END_TEST;
3372 }