0bd455b847da4a6fb59e3e920e2181f29d6bed8d
[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 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1388 {
1389   ToolkitTestApplication application;
1390   tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1391
1392   static std::vector<UniformData> customUniforms =
1393     {
1394       UniformData("pixelArea", Property::Type::VECTOR4),
1395     };
1396
1397   TestGraphicsController& graphics = application.GetGraphicsController();
1398   graphics.AddCustomUniforms(customUniforms);
1399
1400   VisualFactory factory = VisualFactory::Get();
1401   DALI_TEST_CHECK(factory);
1402
1403   // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1404   const int     width  = 600;
1405   const int     height = 600;
1406   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1407
1408   Property::Map propertyMap;
1409   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1410   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1411   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1412   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1413   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1414   propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1415   propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1416   propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1417
1418   Visual::Base visual = factory.CreateVisual(propertyMap);
1419   DALI_TEST_CHECK(visual);
1420
1421   TestGlAbstraction& gl           = application.GetGlAbstraction();
1422   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1423   textureTrace.Enable(true);
1424   textureTrace.EnableLogging(true);
1425   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1426   texParameterTrace.Enable(true);
1427   texParameterTrace.EnableLogging(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   application.SendNotification();
1440
1441   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1442
1443   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1444
1445   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1446   std::stringstream out;
1447   out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1448   DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1449   out.str("");
1450   out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1451   DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1452
1453   // test the uniforms which used to handle the wrap mode
1454   Renderer renderer = actor.GetRendererAt(0u);
1455   DALI_TEST_CHECK(renderer);
1456
1457   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1458   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1459   Vector4 pixelAreaUniform;
1460   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1461   DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1462
1463   Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1464   DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1465
1466   actor.Unparent();
1467   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1468
1469   END_TEST;
1470 }
1471
1472 int UtcDaliImageVisualAnimateMixColor(void)
1473 {
1474   ToolkitTestApplication application;
1475   tet_infoline("Animate mix color");
1476
1477   static std::vector<UniformData> customUniforms =
1478     {
1479       UniformData("mixColor", Property::Type::VECTOR3),
1480     };
1481
1482   TestGraphicsController& graphics = application.GetGraphicsController();
1483   graphics.AddCustomUniforms(customUniforms);
1484
1485   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1486
1487   VisualFactory factory = VisualFactory::Get();
1488   Property::Map propertyMap;
1489   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1490   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1491   propertyMap.Insert("mixColor", Color::BLUE);
1492   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1493   Visual::Base visual = factory.CreateVisual(propertyMap);
1494
1495   DummyControl        actor     = DummyControl::New(true);
1496   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1497   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1498
1499   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1500   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1501   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1502   application.GetScene().Add(actor);
1503
1504   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1505
1506   Renderer renderer = actor.GetRendererAt(0);
1507
1508   // @todo Should we add API to make this code work again?
1509   // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1510
1511   Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1512   DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1513
1514   const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1515
1516   Property::Map map;
1517   map["target"]       = "testVisual";
1518   map["property"]     = "mixColor";
1519   map["initialValue"] = Color::MAGENTA;
1520   map["targetValue"]  = TARGET_MIX_COLOR;
1521   map["animator"]     = Property::Map()
1522                       .Add("alphaFunction", "LINEAR")
1523                       .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1524
1525   Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1526
1527   Animation animation = dummyImpl.CreateTransition(transition);
1528
1529   animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1530   animation.Play();
1531
1532   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1533   glAbstraction.EnableEnableDisableCallTrace(true);
1534   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1535   std::ostringstream blendStr;
1536   blendStr << std::hex << GL_BLEND;
1537
1538   application.SendNotification();
1539   application.Render(0);     // Ensure animation starts
1540   application.Render(2000u); // Halfway point
1541   Vector3 testColor(1.0f, 0.0f, 0.5f);
1542
1543   // uColor.a should be actor's alpha * mixColor.a.
1544   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1545   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1546
1547   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1548
1549   glEnableStack.Reset();
1550
1551   application.SendNotification();
1552   application.Render(2000u);
1553
1554   application.SendNotification();
1555   application.Render();
1556   application.SendNotification();
1557
1558   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1559   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1560   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1561
1562   // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1563
1564   TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1565
1566   END_TEST;
1567 }
1568
1569 int UtcDaliImageVisualAnimateOpacity(void)
1570 {
1571   ToolkitTestApplication application;
1572   tet_infoline("Animate image visual opacity");
1573
1574   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1575
1576   VisualFactory factory = VisualFactory::Get();
1577   Property::Map propertyMap;
1578   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1579   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1580   propertyMap.Insert("opacity", 0.5f);
1581   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1582   Visual::Base visual = factory.CreateVisual(propertyMap);
1583
1584   DummyControl        actor     = DummyControl::New(true);
1585   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1586   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1587
1588   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1589   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1590   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1591   application.GetScene().Add(actor);
1592
1593   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1594
1595   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1596   glAbstraction.EnableEnableDisableCallTrace(true);
1597   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1598   std::ostringstream blendStr;
1599   blendStr << std::hex << GL_BLEND;
1600
1601   application.SendNotification();
1602   application.Render();
1603
1604   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1605
1606   {
1607     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.");
1608
1609     Property::Map map;
1610     map["target"]      = "testVisual";
1611     map["property"]    = "opacity";
1612     map["targetValue"] = 1.0f;
1613     map["animator"]    = Property::Map()
1614                         .Add("alphaFunction", "LINEAR")
1615                         .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1616
1617     Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1618     Animation                     animation  = dummyImpl.CreateTransition(transition);
1619     animation.Play();
1620
1621     glEnableStack.Reset();
1622
1623     application.SendNotification();
1624     application.Render(0);          // Ensure animation starts
1625     application.Render(2000u);      // Halfway point through animation
1626     application.SendNotification(); // Handle any signals
1627
1628     Vector4 color;
1629     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1630     DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1631
1632     application.Render(2001u);      // end
1633     application.SendNotification(); // ensure animation finished signal is sent
1634
1635     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1636     DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1637
1638     // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1639     DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1640   }
1641
1642   {
1643     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.");
1644
1645     Property::Map map;
1646     map["target"]      = "testVisual";
1647     map["property"]    = Visual::Property::OPACITY;
1648     map["targetValue"] = 0.1f;
1649     map["animator"]    = Property::Map()
1650                         .Add("alphaFunction", "LINEAR")
1651                         .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1652
1653     Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1654     Animation                     animation  = dummyImpl.CreateTransition(transition);
1655     animation.Play();
1656
1657     glEnableStack.Reset();
1658
1659     application.SendNotification();
1660     application.Render(0);     // Ensure animation starts
1661     application.Render(2000u); // Halfway point
1662     application.SendNotification();
1663
1664     Vector4 color;
1665     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1666     DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1667
1668     DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1669
1670     glEnableStack.Reset();
1671
1672     application.Render(2016u); // end
1673     application.SendNotification();
1674
1675     DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1676     DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1677
1678     // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1679     DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1680   }
1681
1682   END_TEST;
1683 }
1684
1685 int UtcDaliImageVisualAnimateOpacity02(void)
1686 {
1687   ToolkitTestApplication application;
1688   tet_infoline("Animate image visual opacity");
1689
1690   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1691
1692   VisualFactory factory = VisualFactory::Get();
1693   Property::Map propertyMap;
1694   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1695   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1696   propertyMap.Insert("opacity", 0.5f);
1697   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1698   Visual::Base visual = factory.CreateVisual(propertyMap);
1699
1700   DummyControl        actor     = DummyControl::New(true);
1701   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1702   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1703
1704   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1705   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1706   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1707
1708   tet_infoline("Test that the opacity doesn't animate when actor not staged");
1709
1710   Property::Array array;
1711
1712   Property::Map map;
1713   map["target"]       = "testVisual";
1714   map["property"]     = "opacity";
1715   map["initialValue"] = 0.0f;
1716   map["targetValue"]  = 1.0f;
1717   map["animator"]     = Property::Map()
1718                       .Add("alphaFunction", "LINEAR")
1719                       .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1720
1721   Property::Map map2;
1722   map2["target"]      = "testVisual";
1723   map2["property"]    = "size";
1724   map2["targetValue"] = Vector2(1.0f, 1.0f);
1725
1726   array.Add(map).Add(map2);
1727
1728   Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1729   Animation                     animation  = dummyImpl.CreateTransition(transition);
1730
1731   application.GetScene().Add(actor);
1732   application.SendNotification();
1733   application.Render(0); // Ensure animation starts
1734
1735   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1736
1737   Renderer        renderer       = actor.GetRendererAt(0);
1738   Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1739   DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1740
1741   animation = dummyImpl.CreateTransition(transition);
1742   animation.Play();
1743
1744   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1745   glAbstraction.EnableEnableDisableCallTrace(true);
1746   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1747   std::ostringstream blendStr;
1748   blendStr << std::hex << GL_BLEND;
1749
1750   application.SendNotification();
1751   application.Render(0);          // Ensure animation starts
1752   application.Render(2000u);      // Halfway point through animation
1753   application.SendNotification(); // Handle any signals
1754
1755   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1756
1757   Vector4 color;
1758   DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1759   DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1760
1761   glEnableStack.Reset();
1762
1763   application.Render(2001u);      // end
1764   application.SendNotification(); // ensure animation finished signal is sent
1765
1766   DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1767   DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1768
1769   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1770
1771   END_TEST;
1772 }
1773
1774 int UtcDaliImageVisualAnimatePixelArea(void)
1775 {
1776   ToolkitTestApplication application;
1777   tet_infoline("ImageVisual animate pixel area");
1778
1779   static std::vector<UniformData> customUniforms =
1780     {
1781       UniformData("pixelArea", Property::Type::VECTOR4),
1782     };
1783
1784   TestGraphicsController& graphics = application.GetGraphicsController();
1785   graphics.AddCustomUniforms(customUniforms);
1786
1787   application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1788
1789   VisualFactory factory = VisualFactory::Get();
1790   Property::Map propertyMap;
1791   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1792   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1793   propertyMap.Insert("mixColor", Color::BLUE);
1794   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1795   Visual::Base visual = factory.CreateVisual(propertyMap);
1796
1797   DummyControl        actor     = DummyControl::New(true);
1798   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1799   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1800
1801   actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1802   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1803   actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1804   application.GetScene().Add(actor);
1805
1806   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1807
1808   Renderer renderer = actor.GetRendererAt(0);
1809   // @todo Implement this feature?
1810   //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1811   //tet_infoline("Test that the renderer has the mixColor property");
1812   //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1813
1814   // TransitionData only takes string keys
1815   Property::Map map;
1816   map["target"]       = "testVisual";
1817   map["property"]     = "pixelArea";
1818   map["initialValue"] = Vector4(0, 0, 0, 1);
1819   map["targetValue"]  = Vector4(0, 0, 1, 1); // Animate width from zero to full
1820   map["animator"]     = Property::Map()
1821                       .Add("alphaFunction", "LINEAR")
1822                       .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1823
1824   Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1825
1826   Animation animation = dummyImpl.CreateTransition(transition);
1827   animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1828   animation.Play();
1829
1830   application.SendNotification();
1831   application.Render(0);     // Ensure animation starts
1832   application.Render(2000u); // Halfway point
1833
1834   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1835
1836   application.Render(2000u); // End of animation
1837
1838   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1839
1840   END_TEST;
1841 }
1842
1843 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1844 {
1845   ToolkitTestApplication application;
1846   tet_infoline("Request remote image visual, then destroy visual to cancel load");
1847
1848   Property::Map propertyMap;
1849   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1850   propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1851
1852   TestGlAbstraction& gl           = application.GetGlAbstraction();
1853   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1854   textureTrace.Enable(true);
1855   TraceCallStack& drawTrace = gl.GetDrawTrace();
1856   drawTrace.Enable(true);
1857
1858   Actor actor = CreateActorWithImageVisual(propertyMap);
1859   application.GetScene().Add(actor);
1860   application.SendNotification();
1861
1862   application.GetScene().Remove(actor);
1863   application.SendNotification();
1864
1865   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1866   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1867   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1868   DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1869
1870   END_TEST;
1871 }
1872
1873 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1874 {
1875   ToolkitTestApplication application;
1876   tet_infoline("Load image asynchronously, cancel loading, then load again");
1877
1878   VisualFactory factory = VisualFactory::Get();
1879   DALI_TEST_CHECK(factory);
1880
1881   Property::Map propertyMap;
1882   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1883   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1884
1885   Visual::Base visual = factory.CreateVisual(propertyMap);
1886   DALI_TEST_CHECK(visual);
1887
1888   TestGlAbstraction& gl           = application.GetGlAbstraction();
1889   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1890   textureTrace.Enable(true);
1891   TraceCallStack& drawTrace = gl.GetDrawTrace();
1892   drawTrace.Enable(true);
1893
1894   DummyControl      actor     = DummyControl::New();
1895   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1896   dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1897
1898   application.GetScene().Add(actor);
1899
1900   // Cancel loading
1901   application.GetScene().Remove(actor);
1902
1903   application.GetScene().Add(actor);
1904
1905   // Create another visual with the same image
1906   visual = factory.CreateVisual(propertyMap);
1907   DALI_TEST_CHECK(visual);
1908
1909   dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1910
1911   application.SendNotification();
1912   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1913
1914   application.SendNotification();
1915   application.Render();
1916
1917   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1918   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1919   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1920   DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1921
1922   END_TEST;
1923 }
1924
1925 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1926 {
1927   ToolkitTestApplication application;
1928   tet_infoline("Request image visual with invalid images - should draw broken.png");
1929
1930   VisualFactory factory = VisualFactory::Get();
1931   DALI_TEST_CHECK(factory);
1932
1933   Property::Map propertyMap;
1934   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1935   propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1936
1937   Visual::Base visual = factory.CreateVisual(propertyMap);
1938   DALI_TEST_CHECK(visual);
1939
1940   TestGlAbstraction& gl           = application.GetGlAbstraction();
1941   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1942   textureTrace.Enable(true);
1943
1944   DummyControl      actor     = DummyControl::New();
1945   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1946   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1947
1948   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1949   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1950
1951   application.GetScene().Add(actor);
1952
1953   application.SendNotification();
1954   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1955
1956   application.SendNotification();
1957   application.Render();
1958
1959   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1960   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1961
1962   application.GetScene().Remove(actor);
1963   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1964
1965   END_TEST;
1966 }
1967
1968 int UtcDaliImageVisualSetInvalidSyncImage(void)
1969 {
1970   ToolkitTestApplication application;
1971   tet_infoline("Request image visual with invalid images - should draw broken.png");
1972
1973   VisualFactory factory = VisualFactory::Get();
1974   DALI_TEST_CHECK(factory);
1975
1976   Property::Map propertyMap;
1977   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1978   propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1979   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1980
1981   Visual::Base visual = factory.CreateVisual(propertyMap);
1982   DALI_TEST_CHECK(visual);
1983
1984   TestGlAbstraction& gl           = application.GetGlAbstraction();
1985   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1986   textureTrace.Enable(true);
1987
1988   DummyControl      actor     = DummyControl::New();
1989   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1990   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1991
1992   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1993   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1994
1995   application.GetScene().Add(actor);
1996
1997   application.SendNotification();
1998   application.Render();
1999
2000   // Check resource status
2001   Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
2002   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2003
2004   // The broken image should be shown.
2005   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2006   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2007
2008   application.GetScene().Remove(actor);
2009   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2010
2011   END_TEST;
2012 }
2013
2014 int UtcDaliImageVisualSetInvalidRemoteImage(void)
2015 {
2016   ToolkitTestApplication application;
2017   tet_infoline("Request image visual with invalid images - should draw broken.png");
2018
2019   VisualFactory factory = VisualFactory::Get();
2020   DALI_TEST_CHECK(factory);
2021
2022   // Local invalid file, asynchronous loading
2023   Property::Map propertyMap;
2024   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2025   propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
2026
2027   Visual::Base visual = factory.CreateVisual(propertyMap);
2028   DALI_TEST_CHECK(visual);
2029
2030   TestGlAbstraction& gl           = application.GetGlAbstraction();
2031   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2032   textureTrace.Enable(true);
2033
2034   DummyControl      actor     = DummyControl::New();
2035   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2036   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2037
2038   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2039   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2040
2041   application.GetScene().Add(actor);
2042
2043   application.SendNotification();
2044   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2045
2046   application.SendNotification();
2047   application.Render();
2048
2049   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2050   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2051
2052   application.GetScene().Remove(actor);
2053   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2054
2055   END_TEST;
2056 }
2057
2058 int UtcDaliImageVisualSetInvalidImageWithDisabledBroken(void)
2059 {
2060   ToolkitTestApplication application;
2061   tet_infoline("Request image visual with invalid images - should draw broken.png");
2062
2063   VisualFactory factory = VisualFactory::Get();
2064   DALI_TEST_CHECK(factory);
2065
2066   // Load invalid file
2067   Property::Map propertyMap;
2068   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2069   propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2070
2071   Visual::Base visual = factory.CreateVisual(propertyMap);
2072   DALI_TEST_CHECK(visual);
2073
2074   TestGlAbstraction& gl           = application.GetGlAbstraction();
2075   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2076   textureTrace.Enable(true);
2077
2078   DummyControl      actor     = DummyControl::New();
2079   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2080   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2081
2082   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2083   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2084
2085   application.GetScene().Add(actor);
2086
2087   application.SendNotification();
2088   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2089
2090   application.SendNotification();
2091   application.Render();
2092
2093   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2094   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2095
2096   application.GetScene().Remove(actor);
2097   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2098   textureTrace.Reset();
2099
2100   // Load invalid file with disabled broken
2101   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2102   propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2103   propertyMap.Insert(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, false);
2104
2105   visual = factory.CreateVisual(propertyMap);
2106   DALI_TEST_CHECK(visual);
2107
2108   actor                        = DummyControl::New();
2109   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor.GetImplementation());
2110   dummyImpl2.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2111
2112   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2113   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2114
2115   application.GetScene().Add(actor);
2116
2117   application.SendNotification();
2118   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2119
2120   application.SendNotification();
2121   application.Render();
2122
2123   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2124   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
2125
2126   application.GetScene().Remove(actor);
2127   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2128
2129   END_TEST;
2130 }
2131
2132 int UtcDaliImageVisualAlphaMask01(void)
2133 {
2134   ToolkitTestApplication application;
2135   tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2136
2137   VisualFactory factory = VisualFactory::Get();
2138   DALI_TEST_CHECK(factory);
2139
2140   Property::Map propertyMap;
2141   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2142   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2143   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2144
2145   Visual::Base visual = factory.CreateVisual(propertyMap);
2146   DALI_TEST_CHECK(visual);
2147
2148   Property::Map testMap;
2149   visual.CreatePropertyMap(testMap);
2150   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2151
2152   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2153   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2154
2155   TestGlAbstraction& gl           = application.GetGlAbstraction();
2156   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2157   textureTrace.Enable(true);
2158
2159   DummyControl      actor     = DummyControl::New();
2160   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2161   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2162
2163   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2164   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2165   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2166
2167   application.GetScene().Add(actor);
2168   application.SendNotification();
2169   application.Render();
2170
2171   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2172
2173   application.SendNotification();
2174   application.Render();
2175
2176   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2177   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2178   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2179
2180   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2181   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2182
2183   END_TEST;
2184 }
2185
2186 int UtcDaliImageVisualAlphaMask02(void)
2187 {
2188   ToolkitTestApplication application;
2189   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2190
2191   VisualFactory factory = VisualFactory::Get();
2192   DALI_TEST_CHECK(factory);
2193
2194   Property::Map propertyMap;
2195   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2196   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2197   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2198   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2199   propertyMap.Insert(DevelImageVisual::Property::CROP_TO_MASK, false);
2200
2201   Visual::Base visual = factory.CreateVisual(propertyMap);
2202   DALI_TEST_CHECK(visual);
2203
2204   Property::Map testMap;
2205   visual.CreatePropertyMap(testMap);
2206   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2207   DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2208
2209   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2210   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2211
2212   TestGlAbstraction& gl           = application.GetGlAbstraction();
2213   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2214   textureTrace.Enable(true);
2215
2216   DummyControl      actor     = DummyControl::New();
2217   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2218   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2219
2220   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2221   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2222   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2223
2224   application.GetScene().Add(actor);
2225   application.SendNotification();
2226   application.Render();
2227
2228   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2229
2230   application.SendNotification();
2231   application.Render();
2232
2233   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2234   Renderer   renderer = actor.GetRendererAt(0u);
2235   TextureSet textures = renderer.GetTextures();
2236   DALI_TEST_CHECK(textures);
2237   DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2238
2239   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2240   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2241
2242   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2243   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2244
2245   auto index = renderer.GetPropertyIndex("maskTextureRatio");
2246   DALI_TEST_NOT_EQUALS(index, Property::INVALID_INDEX, 0.1f, TEST_LOCATION);
2247   DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2::ONE, TEST_LOCATION);
2248
2249   END_TEST;
2250 }
2251
2252 int UtcDaliImageVisualAlphaMask03(void)
2253 {
2254   ToolkitTestApplication application;
2255   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2256
2257   VisualFactory factory = VisualFactory::Get();
2258   DALI_TEST_CHECK(factory);
2259
2260   Property::Map propertyMap;
2261   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2262   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2263   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2264   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2265
2266   Visual::Base visual = factory.CreateVisual(propertyMap);
2267   DALI_TEST_CHECK(visual);
2268
2269   Property::Map testMap;
2270   visual.CreatePropertyMap(testMap);
2271
2272   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2273   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2274
2275   TestGlAbstraction& gl           = application.GetGlAbstraction();
2276   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2277   textureTrace.Enable(true);
2278
2279   DummyControl      actor     = DummyControl::New();
2280   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2281   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2282
2283   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2284   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2285   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2286
2287   application.GetScene().Add(actor);
2288   application.SendNotification();
2289   application.Render();
2290
2291   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2292
2293   application.SendNotification();
2294   application.Render();
2295
2296   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2297   Renderer   renderer = actor.GetRendererAt(0u);
2298   TextureSet textures = renderer.GetTextures();
2299   DALI_TEST_CHECK(textures);
2300   DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2301
2302   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2303   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2304
2305   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2306   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2307
2308   END_TEST;
2309 }
2310
2311 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2312 {
2313   ToolkitTestApplication application;
2314   tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2315
2316   VisualFactory factory = VisualFactory::Get();
2317   DALI_TEST_CHECK(factory);
2318
2319   Property::Map propertyMap;
2320   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2321   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2322   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2323   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2324
2325   Visual::Base visual = factory.CreateVisual(propertyMap);
2326   DALI_TEST_CHECK(visual);
2327
2328   Property::Map testMap;
2329   visual.CreatePropertyMap(testMap);
2330   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2331
2332   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2333   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2334
2335   TestGlAbstraction& gl           = application.GetGlAbstraction();
2336   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2337   textureTrace.Enable(true);
2338
2339   DummyControl      actor     = DummyControl::New();
2340   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2341   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2342
2343   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2344   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2345   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2346
2347   application.GetScene().Add(actor);
2348
2349   // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2350
2351   application.SendNotification();
2352   application.Render();
2353
2354   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2355   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2356   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2357
2358   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2359   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2360
2361   END_TEST;
2362 }
2363
2364 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2365 {
2366   ToolkitTestApplication application;
2367   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2368
2369   VisualFactory factory = VisualFactory::Get();
2370   DALI_TEST_CHECK(factory);
2371
2372   Property::Map propertyMap;
2373   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2374   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2375   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2376   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2377   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2378
2379   Visual::Base visual = factory.CreateVisual(propertyMap);
2380   DALI_TEST_CHECK(visual);
2381
2382   Property::Map testMap;
2383   visual.CreatePropertyMap(testMap);
2384   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2385
2386   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2387   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2388
2389   TestGlAbstraction& gl           = application.GetGlAbstraction();
2390   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2391   textureTrace.Enable(true);
2392
2393   DummyControl      actor     = DummyControl::New();
2394   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2395   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2396
2397   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2398   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2399   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2400
2401   application.GetScene().Add(actor);
2402
2403   // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2404
2405   application.SendNotification();
2406   application.Render();
2407
2408   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2409   Renderer   renderer = actor.GetRendererAt(0u);
2410   TextureSet textures = renderer.GetTextures();
2411   DALI_TEST_CHECK(textures);
2412   DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2413
2414   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2415   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2416
2417   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2418   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2419
2420   END_TEST;
2421 }
2422
2423 int UtcDaliImageVisualRemoteAlphaMask(void)
2424 {
2425   ToolkitTestApplication application;
2426   tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2427
2428   VisualFactory factory = VisualFactory::Get();
2429   DALI_TEST_CHECK(factory);
2430
2431   const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2432
2433   Property::Map propertyMap;
2434   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2435   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2436   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2437
2438   Visual::Base visual = factory.CreateVisual(propertyMap);
2439   DALI_TEST_CHECK(visual);
2440
2441   Property::Map testMap;
2442   visual.CreatePropertyMap(testMap);
2443
2444   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2445
2446   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2447   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2448
2449   TestGlAbstraction& gl           = application.GetGlAbstraction();
2450   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2451   textureTrace.Enable(true);
2452
2453   DummyControl      actor     = DummyControl::New();
2454   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2455   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2456
2457   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2458
2459   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2460   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2461
2462   application.GetScene().Add(actor);
2463   application.SendNotification();
2464   application.Render();
2465
2466   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2467
2468   application.SendNotification();
2469   application.Render();
2470
2471   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2472   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2473   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2474
2475   END_TEST;
2476 }
2477
2478 int UtcDaliImageVisualAlphaMaskCrop(void)
2479 {
2480   ToolkitTestApplication application;
2481   tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2482
2483   VisualFactory factory = VisualFactory::Get();
2484   DALI_TEST_CHECK(factory);
2485
2486   Property::Map propertyMap;
2487   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2488   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2489   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2490   propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2491   propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2492
2493   Visual::Base visual = factory.CreateVisual(propertyMap);
2494   DALI_TEST_CHECK(visual);
2495
2496   Property::Map testMap;
2497   visual.CreatePropertyMap(testMap);
2498   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2499   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2500   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2501
2502   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2503   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2504
2505   TestGlAbstraction& gl           = application.GetGlAbstraction();
2506   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2507   textureTrace.Enable(true);
2508
2509   DummyControl      actor     = DummyControl::New();
2510   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2511   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2512
2513   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2514   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2515   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2516
2517   application.GetScene().Add(actor);
2518   application.SendNotification();
2519   application.Render();
2520
2521   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2522
2523   application.SendNotification();
2524   application.Render();
2525
2526   Vector2 size;
2527   visual.GetNaturalSize(size);
2528
2529   DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2530   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2531   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2532   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2533
2534   END_TEST;
2535 }
2536
2537 int UtcDaliImageVisualReleasePolicy01(void)
2538 {
2539   ToolkitTestApplication application;
2540   tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2541
2542   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2543   DALI_TEST_CHECK(imageVisual);
2544
2545   // Set up debug trace
2546   TestGlAbstraction& gl           = application.GetGlAbstraction();
2547   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2548   textureTrace.Enable(true);
2549
2550   tet_infoline("Register visual with control and ensure it has the only handle");
2551   DummyControl        actor     = DummyControl::New(true);
2552   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2553   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2554   imageVisual.Reset();
2555
2556   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2557
2558   application.SendNotification();
2559   application.Render(0);
2560   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2561   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2562
2563   application.GetScene().Add(actor);
2564
2565   // Wait for image to load
2566   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2567
2568   application.SendNotification();
2569   application.Render(0);
2570   // Test renderer and texture created
2571   tet_infoline("Confirm texture created");
2572   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2573   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2574
2575   tet_infoline("Disable visual causing the texture to be deleted");
2576   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2577
2578   application.SendNotification();
2579   application.Render(0);
2580   // Test renderer and textures removed.
2581   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2582   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2583
2584   END_TEST;
2585 }
2586
2587 int UtcDaliImageVisualReleasePolicy02(void)
2588 {
2589   ToolkitTestApplication application;
2590   tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2591
2592   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2593   DALI_TEST_CHECK(imageVisual);
2594
2595   // Setup debug trace
2596   TestGlAbstraction& gl           = application.GetGlAbstraction();
2597   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2598   textureTrace.Enable(true);
2599
2600   tet_infoline("Register visual with control and ensure it has the only handle");
2601   DummyControl        actor     = DummyControl::New(true);
2602   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2603   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2604   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2605
2606   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2607
2608   application.SendNotification();
2609   application.Render(0);
2610   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2611   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2612
2613   application.GetScene().Add(actor);
2614
2615   // Wait for image to load
2616   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2617
2618   application.SendNotification();
2619   application.Render(0);
2620   // Test renderer and texture created
2621   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2622   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2623
2624   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2625   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2626   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2627   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2628   application.SendNotification();
2629   application.Render();
2630
2631   // Test texture removed after visual destroyed.
2632   tet_infoline("Ensure texture is deleted after visual destroyed");
2633   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2634
2635   END_TEST;
2636 }
2637
2638 int UtcDaliImageVisualReleasePolicy03(void)
2639 {
2640   ToolkitTestApplication application;
2641   tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2642
2643   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2644   DALI_TEST_CHECK(imageVisual);
2645
2646   TestGlAbstraction& gl           = application.GetGlAbstraction();
2647   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2648   textureTrace.Enable(true);
2649
2650   tet_infoline("Register visual with control and ensure it has the only handle");
2651   DummyControl        actor     = DummyControl::New(true);
2652   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2653   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2654   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2655
2656   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2657
2658   application.SendNotification();
2659   application.Render(0);
2660   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2661   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2662
2663   application.GetScene().Add(actor);
2664
2665   // Wait for image to load
2666   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2667
2668   application.SendNotification();
2669   application.Render(0);
2670   // Test renderer and texture created
2671   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2672   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2673
2674   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2675   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2676   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2677   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2678   application.SendNotification();
2679   application.Render();
2680
2681   tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2682   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2683
2684   END_TEST;
2685 }
2686
2687 int UtcDaliImageVisualReleasePolicy04(void)
2688 {
2689   ToolkitTestApplication application;
2690   tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2691
2692   tet_infoline("Create first visual with Never release policy");
2693   Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2694
2695   tet_infoline("Create second visual with Destroyed release policy");
2696   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2697
2698   // Set up trace debug
2699   TestGlAbstraction& gl           = application.GetGlAbstraction();
2700   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2701   textureTrace.Enable(true);
2702
2703   tet_infoline("Register visuals with control and ensure it has the only handles");
2704   DummyControl        actor     = DummyControl::New(true);
2705   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2706   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2707   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2708   imageVisualNever.Reset();     // reduce ref count so only the control keeps the visual alive.
2709   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2710
2711   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2712
2713   // Test initially zero renderers
2714   application.SendNotification();
2715   application.Render(0);
2716   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2717   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2718
2719   application.GetScene().Add(actor);
2720
2721   // Wait for image to load
2722   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2723
2724   application.SendNotification();
2725   application.Render(0);
2726   tet_infoline("Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer");
2727   DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2728   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2729
2730   // Test renderer removed when visual destroyed
2731   DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2732   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2733   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2734   application.SendNotification();
2735   application.Render();
2736
2737   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2738   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2739
2740   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2741   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2742   application.SendNotification();
2743   application.Render();
2744
2745   tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2746   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2747   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2748
2749   END_TEST;
2750 }
2751
2752 int UtcDaliImageVisualReleasePolicy05(void)
2753 {
2754   ToolkitTestApplication application;
2755   tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2756
2757   VisualFactory factory = VisualFactory::Get();
2758
2759   Property::Map propertyMapNeverReleasePolicy;
2760   propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2761   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2762   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2763   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2764   propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2765
2766   Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2767
2768   Property::Map resultMap;
2769   imageVisualNever.CreatePropertyMap(resultMap);
2770   DALI_TEST_CHECK(!resultMap.Empty());
2771
2772   DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2773
2774   END_TEST;
2775 }
2776
2777 int UtcDaliImageVisualReleasePolicy06(void)
2778 {
2779   ToolkitTestApplication application;
2780   tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2781
2782   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2783   DALI_TEST_CHECK(imageVisual);
2784
2785   TestGlAbstraction& gl           = application.GetGlAbstraction();
2786   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2787   textureTrace.Enable(true);
2788
2789   tet_infoline("Register visual with control and ensure it has the only handle");
2790   DummyControl        actor     = DummyControl::New(true);
2791   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2792   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2793   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2794
2795   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2796
2797   application.SendNotification();
2798   application.Render(0);
2799   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2800   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2801
2802   application.GetScene().Add(actor);
2803
2804   // Wait for image to load
2805   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2806
2807   application.SendNotification();
2808   application.Render(0);
2809   // Test renderer and texture created
2810   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2811   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2812   textureTrace.Reset();
2813
2814   tet_infoline("Disable Visual and check texture not affected");
2815   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2816   application.SendNotification();
2817   application.Render(0);
2818   tet_infoline("Check renderer is destroyed when visual off stage");
2819   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2820   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2821   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2822   textureTrace.Reset();
2823
2824   tet_infoline("Re-enable Visual and check texture not affected");
2825   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2826   application.SendNotification();
2827   application.Render(0);
2828   tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2829   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2830   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2831   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2832
2833   END_TEST;
2834 }
2835
2836 int UtcDaliImageVisualReleasePolicy07(void)
2837 {
2838   ToolkitTestApplication application;
2839   tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2840
2841   tet_infoline("Create first visual with DESTROYED release policy");
2842   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2843
2844   tet_infoline("Create second visual with DETACHED release policy");
2845   Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2846
2847   // Set up trace debug
2848   TestGlAbstraction& gl           = application.GetGlAbstraction();
2849   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2850   textureTrace.Enable(true);
2851
2852   tet_infoline("Register visuals with control and ensure it has the only handles");
2853   DummyControl        actor     = DummyControl::New(true);
2854   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2855   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2856   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2857   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2858   imageVisualDetached.Reset();  // reduce ref count so only the control keeps the visual alive.
2859
2860   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2861
2862   // Test initially zero renderers
2863   application.SendNotification();
2864   application.Render(0);
2865   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2866   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2867
2868   application.GetScene().Add(actor);
2869
2870   // Wait for image to load
2871   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2872
2873   application.SendNotification();
2874   application.Render(0);
2875   tet_infoline("Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer");
2876   DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2877   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2878
2879   // Test renderer removed when visual destroyed
2880   DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2881   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2882   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2883   application.SendNotification();
2884   application.Render();
2885
2886   // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2887   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2888
2889   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2890   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2891   application.SendNotification();
2892   application.Render();
2893
2894   tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2895   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2896
2897   END_TEST;
2898 }
2899
2900 int UtcDaliImageVisualReleasePolicy08(void)
2901 {
2902   ToolkitTestApplication application;
2903   tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2904
2905   tet_infoline("Create first visual with DESTROYED release policy");
2906   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2907
2908   // Set up trace debug
2909   TestGlAbstraction& gl           = application.GetGlAbstraction();
2910   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2911   textureTrace.Enable(true);
2912
2913   tet_infoline("Register visuals with control and ensure it has the only handles");
2914   DummyControl        actor     = DummyControl::New(true);
2915   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2916   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2917   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2918
2919   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2920
2921   // Test initially zero renderers
2922   application.SendNotification();
2923   application.Render(0);
2924   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2925   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2926   textureTrace.Reset();
2927
2928   application.GetScene().Add(actor);
2929
2930   // Wait for image to load
2931   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2932
2933   application.SendNotification();
2934   application.Render(0);
2935   tet_infoline("Ensure a texture is created");
2936   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2937   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2938   textureTrace.Reset();
2939
2940   // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2941   // 1. Get Texture
2942   Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2943
2944   // 2.Remove actor from stage. In this case, renderer also is deleted.
2945   tet_infoline("Remove actor from stage");
2946   application.GetScene().Remove(actor);
2947   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2948   application.SendNotification();
2949   application.Render();
2950
2951   tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2952   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2953   textureTrace.Reset();
2954
2955   // 3.Add actor in stage. In this case, renderer is created.
2956   tet_infoline("Add actor in stage");
2957   application.GetScene().Add(actor);
2958   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2959   application.SendNotification();
2960   application.Render();
2961   tet_infoline("Ensure a texture is not created again");
2962   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2963   textureTrace.Reset();
2964
2965   // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2966   tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2967   Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2968   DALI_TEST_CHECK(textureBefore == textureAfter);
2969   textureBefore.Reset();
2970   textureAfter.Reset();
2971
2972   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2973   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2974   application.SendNotification();
2975   application.Render();
2976   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2977
2978   END_TEST;
2979 }
2980
2981 int UtcDaliImageVisualReleasePolicy09(void)
2982 {
2983   ToolkitTestApplication application;
2984   tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2985
2986   Property::Map propertyMapNPatchReleasePolicy;
2987   propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2988   propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2989   propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2990   propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2991   propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2992
2993   VisualFactory factory     = VisualFactory::Get();
2994   Visual::Base  imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2995   DALI_TEST_CHECK(imageVisual);
2996
2997   // Setup debug trace
2998   TestGlAbstraction& gl           = application.GetGlAbstraction();
2999   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3000   textureTrace.Enable(true);
3001
3002   tet_infoline("Register visual with control and ensure it has the only handle");
3003   DummyControl        actor     = DummyControl::New(true);
3004   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3005   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3006   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3007
3008   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3009
3010   application.SendNotification();
3011   application.Render(0);
3012   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3013   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3014
3015   application.GetScene().Add(actor);
3016
3017   // Wait for image to load
3018   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3019
3020   application.SendNotification();
3021   application.Render(0);
3022   // Test renderer and texture created
3023   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3024   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3025
3026   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
3027   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
3028   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3029   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3030   application.SendNotification();
3031   application.Render();
3032
3033   // Test texture removed after visual destroyed.
3034   tet_infoline("Ensure texture is deleted after visual destroyed");
3035   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
3036
3037   END_TEST;
3038 }
3039
3040 int UtcDaliImageVisualLoadPolicy01(void)
3041 {
3042   ToolkitTestApplication application;
3043   tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
3044
3045   // Set up trace debug
3046   TestGlAbstraction& gl           = application.GetGlAbstraction();
3047   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3048   textureTrace.Enable(true);
3049
3050   tet_infoline("Create visual with IMMEDIATE load policy");
3051   VisualFactory factory = VisualFactory::Get();
3052
3053   Property::Map propertyMap;
3054   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3055   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3056   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
3057   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
3058   propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
3059
3060   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3061
3062   Property::Map resultMap;
3063   imageVisual.CreatePropertyMap(resultMap);
3064   DALI_TEST_CHECK(!resultMap.Empty());
3065   DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
3066
3067   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3068
3069   // Ensure texture has been uploaded
3070   application.SendNotification();
3071   application.Render();
3072
3073   tet_infoline("Ensure texture loading starts after visual created");
3074   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3075   textureTrace.Reset();
3076
3077   tet_infoline("Register visuals with control and ensure it has the only handles");
3078   DummyControl        actor     = DummyControl::New(true);
3079   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3080   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3081   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3082
3083   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3084   application.GetScene().Add(actor);
3085   tet_infoline("Ensure nothing triggers another load as texure already loaded");
3086   const unsigned int TIME_OUT_3_SECONDS = 3;
3087   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3088
3089   application.SendNotification();
3090   application.Render();
3091
3092   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3093   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3094
3095   // Ensure texture is deleted when no longer needed (ref count was correct )
3096   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3097
3098   application.SendNotification();
3099   application.Render();
3100
3101   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3102   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3103
3104   END_TEST;
3105 }
3106
3107 int UtcDaliImageVisualLoadPolicy02(void)
3108 {
3109   ToolkitTestApplication application;
3110   tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
3111
3112   // Set up trace debug
3113   TestGlAbstraction& gl           = application.GetGlAbstraction();
3114   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3115   textureTrace.Enable(true);
3116
3117   tet_infoline("Create visual with IMMEDIATE load policy");
3118   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3119
3120   const unsigned int TIME_OUT_3_SECONDS = 3;
3121   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3122
3123   // Act on meeage queue even although nothing expected to load
3124   application.SendNotification();
3125   application.Render();
3126
3127   tet_infoline("Ensure texture is not generated yet");
3128   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3129   textureTrace.Reset();
3130
3131   tet_infoline("Register visuals with control and ensure it has the only handles");
3132   DummyControl        actor     = DummyControl::New(true);
3133   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3134   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3135   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3136
3137   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3138   application.GetScene().Add(actor);
3139   tet_infoline("Allow image time to load");
3140   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3141
3142   application.SendNotification();
3143   application.Render();
3144
3145   tet_infoline("Ensure texture generated and renderer created");
3146   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3147   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3148
3149   // Ensure texture is delete when no longer needed
3150   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3151
3152   application.SendNotification();
3153   application.Render();
3154
3155   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3156   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3157
3158   END_TEST;
3159 }
3160
3161 int UtcDaliImageVisualLoadPolicy03(void)
3162 {
3163   ToolkitTestApplication application;
3164   tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
3165
3166   const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
3167
3168   // Set up trace debug
3169   TestGlAbstraction& gl           = application.GetGlAbstraction();
3170   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3171   textureTrace.Enable(true);
3172
3173   tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3174   DummyControl actor = DummyControl::New(true);
3175   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3176   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3177   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3178
3179   tet_infoline("Create visual with IMMEDIATE load policy");
3180   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3181
3182   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3183   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3184   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3185
3186   tet_infoline("Allow image time to load resource");
3187   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3188   application.SendNotification();
3189   application.Render();
3190
3191   // Ensure texture has been uploaded
3192   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3193   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3194
3195   END_TEST;
3196 }
3197
3198 int UtcDaliImageVisualLoadPolicy04(void)
3199 {
3200   ToolkitTestApplication application;
3201   tet_infoline("UtcDaliImageVisualLoadPolicy04 First part  Load a visual image before attaching to stage");
3202   tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3203
3204   const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3205
3206   // Set up trace debug
3207   TestGlAbstraction& gl           = application.GetGlAbstraction();
3208   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3209   textureTrace.Enable(true);
3210
3211   tet_infoline("Create a control and connect to resource ready signal");
3212   DummyControl actor = DummyControl::New(true);
3213   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3214   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3215   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3216
3217   tet_infoline("Create visual with IMMEDIATE load policy");
3218   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3219
3220   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3221   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3222   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3223
3224   tet_infoline("Allow image time to load");
3225   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3226   application.SendNotification();
3227   application.Render();
3228
3229   tet_infoline("Testing texture is loaded and resource ready signal fired");
3230   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3231   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3232
3233   tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3234
3235   gResourceReadySignalFired        = false; // Reset signal check ready for testing next Control
3236   Visual::Base        imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3237   DummyControl        actor2       = DummyControl::New(true);
3238   Impl::DummyControl& dummyImpl2   = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3239   actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3240
3241   tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3242   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3243   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3244   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3245   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3246   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3247
3248   END_TEST;
3249 }
3250
3251 int UtcDaliImageVisualLoadPolicy05(void)
3252 {
3253   ToolkitTestApplication application;
3254   tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part  Load a visual image before attaching to stage");
3255   tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3256   // Set up trace debug
3257   TestGlAbstraction& gl           = application.GetGlAbstraction();
3258   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3259   textureTrace.Enable(true);
3260
3261   tet_infoline("Create a control and connect to resource ready signal");
3262   DummyControl actor = DummyControl::New(true);
3263   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3264   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3265   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3266   application.GetScene().Add(actor);
3267
3268   tet_infoline("Create visual with ATTACHED load policy");
3269   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3270
3271   tet_infoline("Registering visual allows control to get a signal once loaded");
3272   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3273   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3274
3275   tet_infoline("Allow image time to load");
3276   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3277   application.SendNotification();
3278   application.Render();
3279
3280   tet_infoline("Testing texture is loaded and resource ready signal fired");
3281   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3282   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3283
3284   tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3285
3286   gResourceReadySignalFired        = false; // Reset signal check ready for testing next Control
3287   Visual::Base        imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3288   DummyControl        actor2       = DummyControl::New(true);
3289   Impl::DummyControl& dummyImpl2   = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3290   actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3291
3292   tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3293   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3294   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3295   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3296   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3297   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3298
3299   END_TEST;
3300 }
3301
3302 int UtcDaliImageVisualOrientationCorrection(void)
3303 {
3304   ToolkitTestApplication application;
3305   tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3306
3307   VisualFactory factory = VisualFactory::Get();
3308   tet_infoline("Create visual with Orientation correction set OFF");
3309   Property::Map propertyMap;
3310   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3311   propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3312   propertyMap.Insert("orientationCorrection", false);
3313   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3314
3315   tet_infoline("Create control for visual, need to loaded it");
3316   DummyControl        actor     = DummyControl::New(true);
3317   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3318   application.GetScene().Add(actor);
3319
3320   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3321   // Wait for image to load
3322   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3323
3324   Vector2 originalImageSize;
3325   tet_infoline("Get size of original visual to compare later with rotated image");
3326   imageVisual.GetNaturalSize(originalImageSize);
3327   DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3328   imageVisual.Reset();                                                                 // remove handle so can unregister it and remove from cache
3329   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3330   application.SendNotification();
3331   application.Render();
3332
3333   tet_infoline("Create visual with Orientation correction set ON ");
3334   propertyMap.Clear();
3335   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3336   propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3337   propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3338   imageVisual = factory.CreateVisual(propertyMap);
3339
3340   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3341   // Wait for image to load
3342   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3343
3344   Vector2 rotatedImageSize;
3345   imageVisual.GetNaturalSize(rotatedImageSize);
3346   tet_infoline("Confirm that visual has rotated");
3347   DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3348   DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3349
3350   Property::Map resultMap;
3351   imageVisual.CreatePropertyMap(resultMap);
3352
3353   // check the Property::ORIENTATION_CORRECTION value from the returned map
3354   Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3355   DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3356
3357   END_TEST;
3358 }
3359
3360 int UtcDaliImageVisualCustomShader(void)
3361 {
3362   ToolkitTestApplication application;
3363   tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3364
3365   VisualFactory     factory = VisualFactory::Get();
3366   Property::Map     properties;
3367   Property::Map     shader;
3368   const std::string vertexShader                    = "Foobar";
3369   const std::string fragmentShader                  = "Foobar";
3370   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3371   shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
3372
3373   properties[Visual::Property::TYPE]     = Visual::IMAGE;
3374   properties[Visual::Property::SHADER]   = shader;
3375   properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3376
3377   Visual::Base visual = factory.CreateVisual(properties);
3378
3379   // trigger creation through setting on stage
3380   DummyControl        dummy     = DummyControl::New(true);
3381   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3382   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3383
3384   dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3385   dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3386   application.GetScene().Add(dummy);
3387
3388   application.SendNotification();
3389   application.Render();
3390
3391   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3392
3393   Renderer        renderer = dummy.GetRendererAt(0);
3394   Shader          shader2  = renderer.GetShader();
3395   Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
3396   Property::Map*  map      = value.GetMap();
3397   DALI_TEST_CHECK(map);
3398
3399   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3400   DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3401
3402   Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3403   DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3404
3405   shader.Clear();
3406
3407   shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3408   properties[Visual::Property::SHADER]    = shader;
3409
3410   Visual::Base visual1 = factory.CreateVisual(properties);
3411
3412   // trigger creation through setting on stage
3413   DummyControl        dummy1     = DummyControl::New(true);
3414   Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3415   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3416   dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3417   dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3418   application.GetScene().Add(dummy1);
3419
3420   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3421   glAbstraction.EnableEnableDisableCallTrace(true);
3422
3423   application.SendNotification();
3424   application.Render();
3425
3426   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
3427   std::ostringstream blendStr;
3428   blendStr << std::hex << GL_BLEND;
3429   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3430
3431   END_TEST;
3432 }
3433
3434 void ResourceReadyLoadNext(Control control)
3435 {
3436   static int callNumber = 0;
3437
3438   gResourceReadySignalFired = true;
3439   gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3440
3441   if(callNumber == 0)
3442   {
3443     DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3444
3445     tet_infoline("Create visual with loaded image from within the signal handler");
3446     VisualFactory factory     = VisualFactory::Get();
3447     Visual::Base  imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3448
3449     Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3450     controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3451     callNumber = 1;
3452   }
3453   else
3454   {
3455     tet_infoline("3rd signal called");
3456     DALI_TEST_CHECK(true);
3457   }
3458 }
3459
3460 int UtcDaliImageVisualLoadReady01(void)
3461 {
3462   ToolkitTestApplication application;
3463   tet_infoline("UtcDaliImageVisualLoadReady01");
3464   tet_infoline("First part:  Load an image visual for one resource, then another image visual for a second resource.");
3465   tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3466   tet_infoline("Should get a ready signal for all three visuals");
3467
3468   ClearReadyIds();
3469
3470   tet_infoline("Create a control and connect to resource ready signal");
3471   DummyControl actor    = DummyControl::New(true);
3472   int          actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3473   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3474   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3475   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3476   application.GetScene().Add(actor);
3477
3478   tet_infoline("Create visual with IMMEDIATE load policy");
3479   Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3480
3481   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3482   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3483
3484   tet_infoline("Allow image time to load");
3485   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3486   application.SendNotification();
3487   application.Render();
3488
3489   tet_infoline("Testing texture is loaded and resource ready signal fired");
3490   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3491   DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3492
3493   tet_infoline("Original control correctly signalled, now testing failing image");
3494
3495   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3496   ClearReadyIds();
3497
3498   Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3499
3500   DummyControl        actor2     = DummyControl::New(true);
3501   int                 actor2Id   = actor2.GetProperty<int>(Actor::Property::ID);
3502   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3503   actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3504
3505   tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3506   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3507
3508   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3509   application.GetScene().Add(actor2);
3510
3511   tet_infoline("Wait for loading thread to finish");
3512   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3513   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3514
3515   DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3516
3517   tet_infoline("Check for 3rd signal");
3518   application.SendNotification();
3519   DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3520   DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3521
3522   END_TEST;
3523 }
3524
3525 int UtcDaliImageVisualLoadImagePlanes01(void)
3526 {
3527   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3528   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3529
3530   ToolkitTestApplication application;
3531
3532   VisualFactory factory = VisualFactory::Get();
3533   DALI_TEST_CHECK(factory);
3534
3535   Property::Map propertyMap;
3536   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3537   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3538
3539   Visual::Base visual = factory.CreateVisual(propertyMap);
3540   DALI_TEST_CHECK(visual);
3541
3542   DummyControl      actor     = DummyControl::New();
3543   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3544   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3545   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3546   application.GetScene().Add(actor);
3547
3548   application.SendNotification();
3549   application.Render();
3550
3551   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3552
3553   TestGlAbstraction& gl           = application.GetGlAbstraction();
3554   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3555   textureTrace.Enable(true);
3556
3557   application.SendNotification();
3558   application.Render();
3559
3560   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3561   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3562   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3563
3564   Renderer renderer           = actor.GetRendererAt(0);
3565   auto     preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3566   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3567
3568   END_TEST;
3569 }
3570
3571 int UtcDaliImageVisualLoadImagePlanes02(void)
3572 {
3573   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3574   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3575
3576   ToolkitTestApplication application;
3577
3578   VisualFactory factory = VisualFactory::Get();
3579   DALI_TEST_CHECK(factory);
3580
3581   // Alpha masking case - not support yuv planes
3582   Property::Map propertyMap;
3583   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3584   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3585   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3586
3587   Visual::Base visual = factory.CreateVisual(propertyMap);
3588   DALI_TEST_CHECK(visual);
3589
3590   DummyControl      actor     = DummyControl::New();
3591   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3592   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3593   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3594   application.GetScene().Add(actor);
3595
3596   application.SendNotification();
3597   application.Render();
3598
3599   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3600
3601   TestGlAbstraction& gl           = application.GetGlAbstraction();
3602   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3603   textureTrace.Enable(true);
3604
3605   application.SendNotification();
3606   application.Render();
3607
3608   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3609   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3610   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3611
3612   END_TEST;
3613 }
3614
3615 int UtcDaliImageVisualLoadImagePlanes03(void)
3616 {
3617   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3618   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3619
3620   ToolkitTestApplication application;
3621
3622   VisualFactory factory = VisualFactory::Get();
3623   DALI_TEST_CHECK(factory);
3624
3625   TestGlAbstraction& gl           = application.GetGlAbstraction();
3626   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3627   textureTrace.Enable(true);
3628
3629   Property::Map propertyMap;
3630   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3631   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3632   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3633
3634   Visual::Base visual = factory.CreateVisual(propertyMap);
3635   DALI_TEST_CHECK(visual);
3636
3637   DummyControl      actor     = DummyControl::New();
3638   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3639   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3640   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3641   application.GetScene().Add(actor);
3642
3643   application.SendNotification();
3644   application.Render();
3645
3646   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3647   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3648   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3649
3650   END_TEST;
3651 }
3652
3653 int UtcDaliImageVisualLoadFastTrackImage01(void)
3654 {
3655   tet_infoline("Test worker thread uploading with Local URL");
3656   ToolkitTestApplication application;
3657
3658   Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3659
3660   VisualFactory factory = VisualFactory::Get();
3661   DALI_TEST_CHECK(factory);
3662
3663   // Pair of filename - expect GenTextures count.
3664   std::vector<std::pair<std::string, int>> testCases = {
3665     {TEST_IMAGE_FILE_NAME, 1},
3666     {TEST_REMOTE_IMAGE_FILE_NAME, 1},
3667     {TEST_INVALID_FILE_NAME, 0},
3668   };
3669
3670   for(auto&& tc : testCases)
3671   {
3672     auto& filename    = tc.first;
3673     auto& expectValue = tc.second;
3674
3675     tet_printf("Test %s\n", filename.c_str());
3676
3677     Property::Map propertyMap;
3678     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3679     propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3680     propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3681
3682     Visual::Base visual = factory.CreateVisual(propertyMap);
3683     DALI_TEST_CHECK(visual);
3684
3685     DummyControl      actor     = DummyControl::New();
3686     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3687     dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3688     actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3689
3690     TestGlAbstraction& gl           = application.GetGlAbstraction();
3691     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3692     textureTrace.Enable(true);
3693
3694     application.GetScene().Add(actor);
3695
3696     application.SendNotification();
3697     application.Render();
3698
3699     // EventThread without callback
3700     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3701
3702     DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3703
3704     {
3705       // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3706       // How can we make it? Should it be integration-api?
3707       auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3708       DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3709     }
3710     // Render only without SendNotification(). And check whether glTexImage2D called or not.
3711     application.Render();
3712
3713     DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3714
3715     application.SendNotification();
3716     application.Render();
3717
3718     textureTrace.Reset();
3719   }
3720
3721   END_TEST;
3722 }
3723
3724 int UtcDaliImageVisualLoadFastTrackImage02(void)
3725 {
3726   tet_infoline("Test worker thread uploading with Local URL");
3727   ToolkitTestApplication application;
3728
3729   Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3730
3731   VisualFactory factory = VisualFactory::Get();
3732   DALI_TEST_CHECK(factory);
3733
3734   {
3735     auto filename    = std::string(TEST_IMAGE_FILE_NAME);
3736     auto expectValue = 1;
3737
3738     tet_printf("Test %s\n", filename.c_str());
3739
3740     Property::Map propertyMap;
3741     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3742     propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3743     propertyMap.Insert("fastTrackUploading", true);
3744
3745     Visual::Base visual = factory.CreateVisual(propertyMap);
3746     DALI_TEST_CHECK(visual);
3747
3748     DummyControl      actor     = DummyControl::New();
3749     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3750     dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3751     actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3752
3753     TestGlAbstraction& gl           = application.GetGlAbstraction();
3754     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3755     textureTrace.Enable(true);
3756
3757     application.GetScene().Add(actor);
3758
3759     application.SendNotification();
3760     application.Render();
3761
3762     // EventThread without callback
3763     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3764
3765     DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3766
3767     {
3768       // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3769       // How can we make it? Should it be integration-api?
3770       auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3771       DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3772     }
3773     // Render only without SendNotification(). And check whether glTexImage2D called or not.
3774     application.Render();
3775
3776     DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3777
3778     application.SendNotification();
3779     application.Render();
3780
3781     textureTrace.Reset();
3782   }
3783
3784   END_TEST;
3785 }
3786
3787 int UtcDaliImageVisualLoadFastTrackImageResourceReady(void)
3788 {
3789   tet_infoline("Test worker thread uploading with Local URL");
3790   ToolkitTestApplication application;
3791
3792   VisualFactory factory = VisualFactory::Get();
3793   DALI_TEST_CHECK(factory);
3794
3795   Property::Map propertyMap;
3796   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3797   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3798   propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3799
3800   Visual::Base visual = factory.CreateVisual(propertyMap);
3801   DALI_TEST_CHECK(visual);
3802
3803   DummyControl      actor     = DummyControl::New();
3804   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3805   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3806   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3807
3808   TestGlAbstraction& gl           = application.GetGlAbstraction();
3809   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3810   textureTrace.Enable(true);
3811
3812   application.GetScene().Add(actor);
3813
3814   application.SendNotification();
3815   application.Render();
3816
3817   // EventThread with callback
3818   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3819
3820   // Check resource ready comes after
3821   application.SendNotification();
3822   application.Render();
3823
3824   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3825   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3826
3827   END_TEST;
3828 }
3829
3830 int UtcDaliImageVisualLoadFastTrackImageReload(void)
3831 {
3832   tet_infoline("Test worker thread uploading with Local URL");
3833   ToolkitTestApplication application;
3834
3835   Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3836
3837   VisualFactory factory = VisualFactory::Get();
3838   DALI_TEST_CHECK(factory);
3839
3840   Property::Map propertyMap;
3841   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3842   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3843   propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3844
3845   Visual::Base visual = factory.CreateVisual(propertyMap);
3846   DALI_TEST_CHECK(visual);
3847
3848   DummyControl      actor     = DummyControl::New();
3849   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3850   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3851   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3852
3853   TestGlAbstraction& gl           = application.GetGlAbstraction();
3854   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3855   textureTrace.Enable(true);
3856
3857   application.GetScene().Add(actor);
3858
3859   application.SendNotification();
3860   application.Render();
3861
3862   // EventThread without callback
3863   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3864
3865   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3866
3867   {
3868     // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3869     // How can we make it? Should it be integration-api?
3870     auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3871     DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), true, TEST_LOCATION);
3872   }
3873   // Render only without SendNotification(). And check whether glTexImage2D called or not.
3874   application.Render();
3875
3876   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3877
3878   // Reload
3879   Property::Map attributes;
3880   DevelControl::DoAction(actor, Control::CONTROL_PROPERTY_END_INDEX + 1, DevelImageVisual::Action::RELOAD, attributes);
3881
3882   // EventThread with callback
3883   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3884
3885   // Check resource ready comes after
3886   application.SendNotification();
3887   application.Render();
3888
3889   // Check whether renderer count is 1 or not.
3890   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3891   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3892
3893   END_TEST;
3894 }
3895
3896 int UtcDaliImageVisualLoadFastTrackImagePlanes01(void)
3897 {
3898   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3899   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3900
3901   ToolkitTestApplication application;
3902
3903   Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3904
3905   VisualFactory factory = VisualFactory::Get();
3906   DALI_TEST_CHECK(factory);
3907
3908   Property::Map propertyMap;
3909   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3910   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3911   propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3912
3913   Visual::Base visual = factory.CreateVisual(propertyMap);
3914   DALI_TEST_CHECK(visual);
3915
3916   DummyControl      actor     = DummyControl::New();
3917   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3918   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3919   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3920
3921   TestGlAbstraction& gl           = application.GetGlAbstraction();
3922   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3923   textureTrace.Enable(true);
3924
3925   application.GetScene().Add(actor);
3926
3927   application.SendNotification();
3928   application.Render();
3929
3930   // EventThread without callback
3931   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3932
3933   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3934
3935   {
3936     // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3937     // How can we make it? Should it be integration-api?
3938     auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3939     textureUploadManager.ResourceUpload();
3940     application.Render();
3941   }
3942   // Render only without SendNotification(). And check whether glTexImage2D called or not.
3943   application.Render();
3944
3945   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3946
3947   application.SendNotification();
3948   application.Render();
3949
3950   END_TEST;
3951 }
3952
3953 int UtcDaliImageVisualLoadFastTrackImagePlanes02(void)
3954 {
3955   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3956   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3957
3958   ToolkitTestApplication application;
3959
3960   Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3961
3962   VisualFactory factory = VisualFactory::Get();
3963   DALI_TEST_CHECK(factory);
3964
3965   Property::Map propertyMap;
3966   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3967   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3968   propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3969
3970   Visual::Base visual = factory.CreateVisual(propertyMap);
3971   DALI_TEST_CHECK(visual);
3972
3973   DummyControl      actor     = DummyControl::New();
3974   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3975   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3976   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3977
3978   TestGlAbstraction& gl           = application.GetGlAbstraction();
3979   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3980   textureTrace.Enable(true);
3981
3982   application.GetScene().Add(actor);
3983
3984   application.SendNotification();
3985   application.Render();
3986
3987   // EventThread without callback
3988   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3989
3990   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3991
3992   {
3993     // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3994     // How can we make it? Should it be integration-api?
3995     auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3996     textureUploadManager.ResourceUpload();
3997     application.Render();
3998   }
3999   // Render only without SendNotification(). And check whether glTexImage2D called or not.
4000   application.Render();
4001
4002   DALI_TEST_GREATER(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
4003
4004   application.SendNotification();
4005   application.Render();
4006
4007   END_TEST;
4008 }
4009
4010 int UtcDaliImageVisualDebugImageVisualShaderP1(void)
4011 {
4012   EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4013   EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "validFile"); // Try to load not exist file.
4014
4015   // Set valid script file
4016   Test::StyleMonitor::SetThemeFileOutput("validFile", VALID_DEBUG_SHADER_SCRIPT);
4017
4018   ToolkitTestApplication application;
4019
4020   VisualFactory factory = VisualFactory::Get();
4021   DALI_TEST_CHECK(factory);
4022
4023   Property::Map propertyMap;
4024   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4025   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4026
4027   Visual::Base visual = factory.CreateVisual(propertyMap);
4028   DALI_TEST_CHECK(visual);
4029
4030   DummyControl      actor     = DummyControl::New();
4031   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4032   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4033   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4034   application.GetScene().Add(actor);
4035
4036   application.SendNotification();
4037   application.Render();
4038
4039   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4040
4041   TestGlAbstraction& gl           = application.GetGlAbstraction();
4042   TraceCallStack&    textureTrace = gl.GetTextureTrace();
4043   textureTrace.Enable(true);
4044
4045   application.SendNotification();
4046   application.Render();
4047
4048   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4049   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4050   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4051
4052   END_TEST;
4053 }
4054
4055 int UtcDaliImageVisualDebugImageVisualShaderN1(void)
4056 {
4057   EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4058   EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "notJsonFile"); // Try to load exist file, but not a json
4059
4060   // Set invalid script file
4061   Test::StyleMonitor::SetThemeFileOutput("notJsonFile", "1");
4062
4063   ToolkitTestApplication application;
4064
4065   VisualFactory factory = VisualFactory::Get();
4066   DALI_TEST_CHECK(factory);
4067
4068   Property::Map propertyMap;
4069   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4070   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4071
4072   Visual::Base visual = factory.CreateVisual(propertyMap);
4073   DALI_TEST_CHECK(visual);
4074
4075   DummyControl      actor     = DummyControl::New();
4076   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4077   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4078   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4079   application.GetScene().Add(actor);
4080
4081   application.SendNotification();
4082   application.Render();
4083
4084   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4085
4086   TestGlAbstraction& gl           = application.GetGlAbstraction();
4087   TraceCallStack&    textureTrace = gl.GetTextureTrace();
4088   textureTrace.Enable(true);
4089
4090   application.SendNotification();
4091   application.Render();
4092
4093   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4094   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4095   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4096
4097   END_TEST;
4098 }
4099
4100 int UtcDaliImageVisualDebugImageVisualShaderN2(void)
4101 {
4102   EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4103   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
4104
4105   // Set throw exception script file
4106   Test::StyleMonitor::SetThemeFileOutput(std::string(THROW_EXCEPTION_STYLE_FILE_NAME), "1");
4107
4108   ToolkitTestApplication application;
4109
4110   VisualFactory factory = VisualFactory::Get();
4111   DALI_TEST_CHECK(factory);
4112
4113   Property::Map propertyMap;
4114   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4115   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4116
4117   Visual::Base visual = factory.CreateVisual(propertyMap);
4118   DALI_TEST_CHECK(visual);
4119
4120   DummyControl      actor     = DummyControl::New();
4121   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4122   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4123   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4124   application.GetScene().Add(actor);
4125
4126   application.SendNotification();
4127   application.Render();
4128
4129   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4130
4131   TestGlAbstraction& gl           = application.GetGlAbstraction();
4132   TraceCallStack&    textureTrace = gl.GetTextureTrace();
4133   textureTrace.Enable(true);
4134
4135   application.SendNotification();
4136   application.Render();
4137
4138   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4139   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4140   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4141
4142   END_TEST;
4143 }