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