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