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