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