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