Add property for disable broken image
[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 UtcDaliImageVisualSetInvalidImageWithDisabledBroken(void)
1965 {
1966   ToolkitTestApplication application;
1967   tet_infoline("Request image visual with invalid images - should draw broken.png");
1968
1969   VisualFactory factory = VisualFactory::Get();
1970   DALI_TEST_CHECK(factory);
1971
1972   // Load invalid file
1973   Property::Map propertyMap;
1974   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1975   propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
1976
1977   Visual::Base visual = factory.CreateVisual(propertyMap);
1978   DALI_TEST_CHECK(visual);
1979
1980   TestGlAbstraction& gl           = application.GetGlAbstraction();
1981   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1982   textureTrace.Enable(true);
1983
1984   DummyControl      actor     = DummyControl::New();
1985   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1986   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1987
1988   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1989   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1990
1991   application.GetScene().Add(actor);
1992
1993   application.SendNotification();
1994   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1995
1996   application.SendNotification();
1997   application.Render();
1998
1999   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2000   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2001
2002   application.GetScene().Remove(actor);
2003   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2004   textureTrace.Reset();
2005
2006   // Load invalid file with disabled broken
2007   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2008   propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2009   propertyMap.Insert(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, false);
2010
2011   visual = factory.CreateVisual(propertyMap);
2012   DALI_TEST_CHECK(visual);
2013
2014   actor                        = DummyControl::New();
2015   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor.GetImplementation());
2016   dummyImpl2.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2017
2018   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2019   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2020
2021   application.GetScene().Add(actor);
2022
2023   application.SendNotification();
2024   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2025
2026   application.SendNotification();
2027   application.Render();
2028
2029   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2030   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
2031
2032   application.GetScene().Remove(actor);
2033   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2034
2035   END_TEST;
2036 }
2037
2038 int UtcDaliImageVisualAlphaMask01(void)
2039 {
2040   ToolkitTestApplication application;
2041   tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2042
2043   VisualFactory factory = VisualFactory::Get();
2044   DALI_TEST_CHECK(factory);
2045
2046   Property::Map propertyMap;
2047   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2048   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2049   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2050
2051   Visual::Base visual = factory.CreateVisual(propertyMap);
2052   DALI_TEST_CHECK(visual);
2053
2054   Property::Map testMap;
2055   visual.CreatePropertyMap(testMap);
2056   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2057
2058   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2059   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2060
2061   TestGlAbstraction& gl           = application.GetGlAbstraction();
2062   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2063   textureTrace.Enable(true);
2064
2065   DummyControl      actor     = DummyControl::New();
2066   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2067   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2068
2069   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2070   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2071   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2072
2073   application.GetScene().Add(actor);
2074   application.SendNotification();
2075   application.Render();
2076
2077   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2078
2079   application.SendNotification();
2080   application.Render();
2081
2082   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2083   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2084   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2085
2086   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2087   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2088
2089   END_TEST;
2090 }
2091
2092 int UtcDaliImageVisualAlphaMask02(void)
2093 {
2094   ToolkitTestApplication application;
2095   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2096
2097   VisualFactory factory = VisualFactory::Get();
2098   DALI_TEST_CHECK(factory);
2099
2100   Property::Map propertyMap;
2101   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2102   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2103   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2104   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2105
2106   Visual::Base visual = factory.CreateVisual(propertyMap);
2107   DALI_TEST_CHECK(visual);
2108
2109   Property::Map testMap;
2110   visual.CreatePropertyMap(testMap);
2111   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2112   DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2113
2114   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2115   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2116
2117   TestGlAbstraction& gl           = application.GetGlAbstraction();
2118   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2119   textureTrace.Enable(true);
2120
2121   DummyControl      actor     = DummyControl::New();
2122   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2123   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2124
2125   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2126   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2127   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2128
2129   application.GetScene().Add(actor);
2130   application.SendNotification();
2131   application.Render();
2132
2133   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2134
2135   application.SendNotification();
2136   application.Render();
2137
2138   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2139   Renderer   renderer = actor.GetRendererAt(0u);
2140   TextureSet textures = renderer.GetTextures();
2141   DALI_TEST_CHECK(textures);
2142   DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2143
2144   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2145   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2146
2147   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2148   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2149
2150   END_TEST;
2151 }
2152
2153 int UtcDaliImageVisualAlphaMask03(void)
2154 {
2155   ToolkitTestApplication application;
2156   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2157
2158   VisualFactory factory = VisualFactory::Get();
2159   DALI_TEST_CHECK(factory);
2160
2161   Property::Map propertyMap;
2162   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2163   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2164   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2165   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2166
2167   Visual::Base visual = factory.CreateVisual(propertyMap);
2168   DALI_TEST_CHECK(visual);
2169
2170   Property::Map testMap;
2171   visual.CreatePropertyMap(testMap);
2172
2173   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2174   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2175
2176   TestGlAbstraction& gl           = application.GetGlAbstraction();
2177   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2178   textureTrace.Enable(true);
2179
2180   DummyControl      actor     = DummyControl::New();
2181   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2182   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2183
2184   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2185   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2186   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2187
2188   application.GetScene().Add(actor);
2189   application.SendNotification();
2190   application.Render();
2191
2192   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2193
2194   application.SendNotification();
2195   application.Render();
2196
2197   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2198   Renderer   renderer = actor.GetRendererAt(0u);
2199   TextureSet textures = renderer.GetTextures();
2200   DALI_TEST_CHECK(textures);
2201   DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2202
2203   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2204   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2205
2206   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2207   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2208
2209   END_TEST;
2210 }
2211
2212 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2213 {
2214   ToolkitTestApplication application;
2215   tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2216
2217   VisualFactory factory = VisualFactory::Get();
2218   DALI_TEST_CHECK(factory);
2219
2220   Property::Map propertyMap;
2221   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2222   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2223   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2224   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2225
2226   Visual::Base visual = factory.CreateVisual(propertyMap);
2227   DALI_TEST_CHECK(visual);
2228
2229   Property::Map testMap;
2230   visual.CreatePropertyMap(testMap);
2231   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2232
2233   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2234   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2235
2236   TestGlAbstraction& gl           = application.GetGlAbstraction();
2237   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2238   textureTrace.Enable(true);
2239
2240   DummyControl      actor     = DummyControl::New();
2241   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2242   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2243
2244   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2245   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2246   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2247
2248   application.GetScene().Add(actor);
2249
2250   // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2251
2252   application.SendNotification();
2253   application.Render();
2254
2255   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2256   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2257   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2258
2259   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2260   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2261
2262   END_TEST;
2263 }
2264
2265 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2266 {
2267   ToolkitTestApplication application;
2268   tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2269
2270   VisualFactory factory = VisualFactory::Get();
2271   DALI_TEST_CHECK(factory);
2272
2273   Property::Map propertyMap;
2274   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2275   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2276   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2277   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2278   propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2279
2280   Visual::Base visual = factory.CreateVisual(propertyMap);
2281   DALI_TEST_CHECK(visual);
2282
2283   Property::Map testMap;
2284   visual.CreatePropertyMap(testMap);
2285   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2286
2287   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2288   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2289
2290   TestGlAbstraction& gl           = application.GetGlAbstraction();
2291   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2292   textureTrace.Enable(true);
2293
2294   DummyControl      actor     = DummyControl::New();
2295   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2296   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2297
2298   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2299   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2300   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2301
2302   application.GetScene().Add(actor);
2303
2304   // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2305
2306   application.SendNotification();
2307   application.Render();
2308
2309   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2310   Renderer   renderer = actor.GetRendererAt(0u);
2311   TextureSet textures = renderer.GetTextures();
2312   DALI_TEST_CHECK(textures);
2313   DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2314
2315   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2316   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2317
2318   dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2319   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2320
2321   END_TEST;
2322 }
2323
2324 int UtcDaliImageVisualRemoteAlphaMask(void)
2325 {
2326   ToolkitTestApplication application;
2327   tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2328
2329   VisualFactory factory = VisualFactory::Get();
2330   DALI_TEST_CHECK(factory);
2331
2332   const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2333
2334   Property::Map propertyMap;
2335   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2336   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2337   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2338
2339   Visual::Base visual = factory.CreateVisual(propertyMap);
2340   DALI_TEST_CHECK(visual);
2341
2342   Property::Map testMap;
2343   visual.CreatePropertyMap(testMap);
2344
2345   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2346
2347   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2348   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2349
2350   TestGlAbstraction& gl           = application.GetGlAbstraction();
2351   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2352   textureTrace.Enable(true);
2353
2354   DummyControl      actor     = DummyControl::New();
2355   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2356   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2357
2358   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2359
2360   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2361   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2362
2363   application.GetScene().Add(actor);
2364   application.SendNotification();
2365   application.Render();
2366
2367   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2368
2369   application.SendNotification();
2370   application.Render();
2371
2372   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2373   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2374   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2375
2376   END_TEST;
2377 }
2378
2379 int UtcDaliImageVisualAlphaMaskCrop(void)
2380 {
2381   ToolkitTestApplication application;
2382   tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2383
2384   VisualFactory factory = VisualFactory::Get();
2385   DALI_TEST_CHECK(factory);
2386
2387   Property::Map propertyMap;
2388   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2389   propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2390   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2391   propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2392   propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2393
2394   Visual::Base visual = factory.CreateVisual(propertyMap);
2395   DALI_TEST_CHECK(visual);
2396
2397   Property::Map testMap;
2398   visual.CreatePropertyMap(testMap);
2399   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2400   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2401   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2402
2403   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2404   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2405
2406   TestGlAbstraction& gl           = application.GetGlAbstraction();
2407   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2408   textureTrace.Enable(true);
2409
2410   DummyControl      actor     = DummyControl::New();
2411   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2412   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2413
2414   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2415   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2416   DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2417
2418   application.GetScene().Add(actor);
2419   application.SendNotification();
2420   application.Render();
2421
2422   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2423
2424   application.SendNotification();
2425   application.Render();
2426
2427   Vector2 size;
2428   visual.GetNaturalSize(size);
2429
2430   DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2431   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2432   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2433   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2434
2435   END_TEST;
2436 }
2437
2438 int UtcDaliImageVisualReleasePolicy01(void)
2439 {
2440   ToolkitTestApplication application;
2441   tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2442
2443   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2444   DALI_TEST_CHECK(imageVisual);
2445
2446   // Set up debug trace
2447   TestGlAbstraction& gl           = application.GetGlAbstraction();
2448   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2449   textureTrace.Enable(true);
2450
2451   tet_infoline("Register visual with control and ensure it has the only handle");
2452   DummyControl        actor     = DummyControl::New(true);
2453   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2454   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2455   imageVisual.Reset();
2456
2457   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2458
2459   application.SendNotification();
2460   application.Render(0);
2461   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2462   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2463
2464   application.GetScene().Add(actor);
2465
2466   // Wait for image to load
2467   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2468
2469   application.SendNotification();
2470   application.Render(0);
2471   // Test renderer and texture created
2472   tet_infoline("Confirm texture created");
2473   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2474   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2475
2476   tet_infoline("Disable visual causing the texture to be deleted");
2477   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2478
2479   application.SendNotification();
2480   application.Render(0);
2481   // Test renderer and textures removed.
2482   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2483   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2484
2485   END_TEST;
2486 }
2487
2488 int UtcDaliImageVisualReleasePolicy02(void)
2489 {
2490   ToolkitTestApplication application;
2491   tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2492
2493   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2494   DALI_TEST_CHECK(imageVisual);
2495
2496   // Setup debug trace
2497   TestGlAbstraction& gl           = application.GetGlAbstraction();
2498   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2499   textureTrace.Enable(true);
2500
2501   tet_infoline("Register visual with control and ensure it has the only handle");
2502   DummyControl        actor     = DummyControl::New(true);
2503   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2504   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2505   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2506
2507   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2508
2509   application.SendNotification();
2510   application.Render(0);
2511   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2512   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2513
2514   application.GetScene().Add(actor);
2515
2516   // Wait for image to load
2517   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2518
2519   application.SendNotification();
2520   application.Render(0);
2521   // Test renderer and texture created
2522   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2523   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2524
2525   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2526   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2527   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2528   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2529   application.SendNotification();
2530   application.Render();
2531
2532   // Test texture removed after visual destroyed.
2533   tet_infoline("Ensure texture is deleted after visual destroyed");
2534   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2535
2536   END_TEST;
2537 }
2538
2539 int UtcDaliImageVisualReleasePolicy03(void)
2540 {
2541   ToolkitTestApplication application;
2542   tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2543
2544   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2545   DALI_TEST_CHECK(imageVisual);
2546
2547   TestGlAbstraction& gl           = application.GetGlAbstraction();
2548   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2549   textureTrace.Enable(true);
2550
2551   tet_infoline("Register visual with control and ensure it has the only handle");
2552   DummyControl        actor     = DummyControl::New(true);
2553   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2554   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2555   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2556
2557   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2558
2559   application.SendNotification();
2560   application.Render(0);
2561   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2562   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2563
2564   application.GetScene().Add(actor);
2565
2566   // Wait for image to load
2567   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2568
2569   application.SendNotification();
2570   application.Render(0);
2571   // Test renderer and texture created
2572   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2573   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2574
2575   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2576   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2577   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2578   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2579   application.SendNotification();
2580   application.Render();
2581
2582   tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2583   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2584
2585   END_TEST;
2586 }
2587
2588 int UtcDaliImageVisualReleasePolicy04(void)
2589 {
2590   ToolkitTestApplication application;
2591   tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2592
2593   tet_infoline("Create first visual with Never release policy");
2594   Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2595
2596   tet_infoline("Create second visual with Destroyed release policy");
2597   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2598
2599   // Set up trace debug
2600   TestGlAbstraction& gl           = application.GetGlAbstraction();
2601   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2602   textureTrace.Enable(true);
2603
2604   tet_infoline("Register visuals with control and ensure it has the only handles");
2605   DummyControl        actor     = DummyControl::New(true);
2606   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2607   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2608   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2609   imageVisualNever.Reset();     // reduce ref count so only the control keeps the visual alive.
2610   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2611
2612   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2613
2614   // Test initially zero renderers
2615   application.SendNotification();
2616   application.Render(0);
2617   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2618   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2619
2620   application.GetScene().Add(actor);
2621
2622   // Wait for image to load
2623   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2624
2625   application.SendNotification();
2626   application.Render(0);
2627   tet_infoline("Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer");
2628   DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2629   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2630
2631   // Test renderer removed when visual destroyed
2632   DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2633   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2634   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2635   application.SendNotification();
2636   application.Render();
2637
2638   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2639   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2640
2641   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2642   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2643   application.SendNotification();
2644   application.Render();
2645
2646   tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2647   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2648   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2649
2650   END_TEST;
2651 }
2652
2653 int UtcDaliImageVisualReleasePolicy05(void)
2654 {
2655   ToolkitTestApplication application;
2656   tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2657
2658   VisualFactory factory = VisualFactory::Get();
2659
2660   Property::Map propertyMapNeverReleasePolicy;
2661   propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2662   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2663   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2664   propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2665   propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2666
2667   Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2668
2669   Property::Map resultMap;
2670   imageVisualNever.CreatePropertyMap(resultMap);
2671   DALI_TEST_CHECK(!resultMap.Empty());
2672
2673   DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2674
2675   END_TEST;
2676 }
2677
2678 int UtcDaliImageVisualReleasePolicy06(void)
2679 {
2680   ToolkitTestApplication application;
2681   tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2682
2683   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2684   DALI_TEST_CHECK(imageVisual);
2685
2686   TestGlAbstraction& gl           = application.GetGlAbstraction();
2687   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2688   textureTrace.Enable(true);
2689
2690   tet_infoline("Register visual with control and ensure it has the only handle");
2691   DummyControl        actor     = DummyControl::New(true);
2692   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2693   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2694   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2695
2696   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2697
2698   application.SendNotification();
2699   application.Render(0);
2700   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2701   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2702
2703   application.GetScene().Add(actor);
2704
2705   // Wait for image to load
2706   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2707
2708   application.SendNotification();
2709   application.Render(0);
2710   // Test renderer and texture created
2711   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2712   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2713   textureTrace.Reset();
2714
2715   tet_infoline("Disable Visual and check texture not affected");
2716   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2717   application.SendNotification();
2718   application.Render(0);
2719   tet_infoline("Check renderer is destroyed when visual off stage");
2720   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2721   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2722   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2723   textureTrace.Reset();
2724
2725   tet_infoline("Re-enable Visual and check texture not affected");
2726   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2727   application.SendNotification();
2728   application.Render(0);
2729   tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2730   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2731   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2732   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2733
2734   END_TEST;
2735 }
2736
2737 int UtcDaliImageVisualReleasePolicy07(void)
2738 {
2739   ToolkitTestApplication application;
2740   tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2741
2742   tet_infoline("Create first visual with DESTROYED release policy");
2743   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2744
2745   tet_infoline("Create second visual with DETACHED release policy");
2746   Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2747
2748   // Set up trace debug
2749   TestGlAbstraction& gl           = application.GetGlAbstraction();
2750   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2751   textureTrace.Enable(true);
2752
2753   tet_infoline("Register visuals with control and ensure it has the only handles");
2754   DummyControl        actor     = DummyControl::New(true);
2755   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2756   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2757   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2758   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2759   imageVisualDetached.Reset();  // reduce ref count so only the control keeps the visual alive.
2760
2761   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2762
2763   // Test initially zero renderers
2764   application.SendNotification();
2765   application.Render(0);
2766   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2767   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2768
2769   application.GetScene().Add(actor);
2770
2771   // Wait for image to load
2772   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2773
2774   application.SendNotification();
2775   application.Render(0);
2776   tet_infoline("Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer");
2777   DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2778   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2779
2780   // Test renderer removed when visual destroyed
2781   DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2782   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2783   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2784   application.SendNotification();
2785   application.Render();
2786
2787   // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2788   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2789
2790   dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2791   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2792   application.SendNotification();
2793   application.Render();
2794
2795   tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2796   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2797
2798   END_TEST;
2799 }
2800
2801 int UtcDaliImageVisualReleasePolicy08(void)
2802 {
2803   ToolkitTestApplication application;
2804   tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2805
2806   tet_infoline("Create first visual with DESTROYED release policy");
2807   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2808
2809   // Set up trace debug
2810   TestGlAbstraction& gl           = application.GetGlAbstraction();
2811   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2812   textureTrace.Enable(true);
2813
2814   tet_infoline("Register visuals with control and ensure it has the only handles");
2815   DummyControl        actor     = DummyControl::New(true);
2816   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2817   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2818   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2819
2820   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2821
2822   // Test initially zero renderers
2823   application.SendNotification();
2824   application.Render(0);
2825   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2826   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2827   textureTrace.Reset();
2828
2829   application.GetScene().Add(actor);
2830
2831   // Wait for image to load
2832   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2833
2834   application.SendNotification();
2835   application.Render(0);
2836   tet_infoline("Ensure a texture is created");
2837   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2838   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2839   textureTrace.Reset();
2840
2841   // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2842   // 1. Get Texture
2843   Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2844
2845   // 2.Remove actor from stage. In this case, renderer also is deleted.
2846   tet_infoline("Remove actor from stage");
2847   application.GetScene().Remove(actor);
2848   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2849   application.SendNotification();
2850   application.Render();
2851
2852   tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2853   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2854   textureTrace.Reset();
2855
2856   // 3.Add actor in stage. In this case, renderer is created.
2857   tet_infoline("Add actor in stage");
2858   application.GetScene().Add(actor);
2859   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2860   application.SendNotification();
2861   application.Render();
2862   tet_infoline("Ensure a texture is not created again");
2863   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2864   textureTrace.Reset();
2865
2866   // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2867   tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2868   Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2869   DALI_TEST_CHECK(textureBefore == textureAfter);
2870   textureBefore.Reset();
2871   textureAfter.Reset();
2872
2873   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2874   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2875   application.SendNotification();
2876   application.Render();
2877   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2878
2879   END_TEST;
2880 }
2881
2882 int UtcDaliImageVisualReleasePolicy09(void)
2883 {
2884   ToolkitTestApplication application;
2885   tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2886
2887   Property::Map propertyMapNPatchReleasePolicy;
2888   propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2889   propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2890   propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2891   propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2892   propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2893
2894   VisualFactory factory     = VisualFactory::Get();
2895   Visual::Base  imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2896   DALI_TEST_CHECK(imageVisual);
2897
2898   // Setup debug trace
2899   TestGlAbstraction& gl           = application.GetGlAbstraction();
2900   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2901   textureTrace.Enable(true);
2902
2903   tet_infoline("Register visual with control and ensure it has the only handle");
2904   DummyControl        actor     = DummyControl::New(true);
2905   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2906   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2907   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2908
2909   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2910
2911   application.SendNotification();
2912   application.Render(0);
2913   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2914   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2915
2916   application.GetScene().Add(actor);
2917
2918   // Wait for image to load
2919   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2920
2921   application.SendNotification();
2922   application.Render(0);
2923   // Test renderer and texture created
2924   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2925   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2926
2927   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2928   tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2929   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2930   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2931   application.SendNotification();
2932   application.Render();
2933
2934   // Test texture removed after visual destroyed.
2935   tet_infoline("Ensure texture is deleted after visual destroyed");
2936   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2937
2938   END_TEST;
2939 }
2940
2941 int UtcDaliImageVisualLoadPolicy01(void)
2942 {
2943   ToolkitTestApplication application;
2944   tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2945
2946   // Set up trace debug
2947   TestGlAbstraction& gl           = application.GetGlAbstraction();
2948   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2949   textureTrace.Enable(true);
2950
2951   tet_infoline("Create visual with IMMEDIATE load policy");
2952   VisualFactory factory = VisualFactory::Get();
2953
2954   Property::Map propertyMap;
2955   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2956   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2957   propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2958   propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2959   propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2960
2961   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2962
2963   Property::Map resultMap;
2964   imageVisual.CreatePropertyMap(resultMap);
2965   DALI_TEST_CHECK(!resultMap.Empty());
2966   DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2967
2968   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2969
2970   // Ensure texture has been uploaded
2971   application.SendNotification();
2972   application.Render();
2973
2974   tet_infoline("Ensure texture loading starts after visual created");
2975   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2976   textureTrace.Reset();
2977
2978   tet_infoline("Register visuals with control and ensure it has the only handles");
2979   DummyControl        actor     = DummyControl::New(true);
2980   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2981   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2982   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2983
2984   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2985   application.GetScene().Add(actor);
2986   tet_infoline("Ensure nothing triggers another load as texure already loaded");
2987   const unsigned int TIME_OUT_3_SECONDS = 3;
2988   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2989
2990   application.SendNotification();
2991   application.Render();
2992
2993   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2994   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2995
2996   // Ensure texture is deleted when no longer needed (ref count was correct )
2997   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2998
2999   application.SendNotification();
3000   application.Render();
3001
3002   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3003   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3004
3005   END_TEST;
3006 }
3007
3008 int UtcDaliImageVisualLoadPolicy02(void)
3009 {
3010   ToolkitTestApplication application;
3011   tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
3012
3013   // Set up trace debug
3014   TestGlAbstraction& gl           = application.GetGlAbstraction();
3015   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3016   textureTrace.Enable(true);
3017
3018   tet_infoline("Create visual with IMMEDIATE load policy");
3019   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3020
3021   const unsigned int TIME_OUT_3_SECONDS = 3;
3022   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3023
3024   // Act on meeage queue even although nothing expected to load
3025   application.SendNotification();
3026   application.Render();
3027
3028   tet_infoline("Ensure texture is not generated yet");
3029   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3030   textureTrace.Reset();
3031
3032   tet_infoline("Register visuals with control and ensure it has the only handles");
3033   DummyControl        actor     = DummyControl::New(true);
3034   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3035   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3036   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3037
3038   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3039   application.GetScene().Add(actor);
3040   tet_infoline("Allow image time to load");
3041   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3042
3043   application.SendNotification();
3044   application.Render();
3045
3046   tet_infoline("Ensure texture generated and renderer created");
3047   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3048   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3049
3050   // Ensure texture is delete when no longer needed
3051   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3052
3053   application.SendNotification();
3054   application.Render();
3055
3056   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3057   DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3058
3059   END_TEST;
3060 }
3061
3062 int UtcDaliImageVisualLoadPolicy03(void)
3063 {
3064   ToolkitTestApplication application;
3065   tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
3066
3067   const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
3068
3069   // Set up trace debug
3070   TestGlAbstraction& gl           = application.GetGlAbstraction();
3071   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3072   textureTrace.Enable(true);
3073
3074   tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3075   DummyControl actor = DummyControl::New(true);
3076   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3077   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3078   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3079
3080   tet_infoline("Create visual with IMMEDIATE load policy");
3081   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3082
3083   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3084   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3085   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3086
3087   tet_infoline("Allow image time to load resource");
3088   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3089   application.SendNotification();
3090   application.Render();
3091
3092   // Ensure texture has been uploaded
3093   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3094   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3095
3096   END_TEST;
3097 }
3098
3099 int UtcDaliImageVisualLoadPolicy04(void)
3100 {
3101   ToolkitTestApplication application;
3102   tet_infoline("UtcDaliImageVisualLoadPolicy04 First part  Load a visual image before attaching to stage");
3103   tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3104
3105   const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3106
3107   // Set up trace debug
3108   TestGlAbstraction& gl           = application.GetGlAbstraction();
3109   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3110   textureTrace.Enable(true);
3111
3112   tet_infoline("Create a control and connect to resource ready signal");
3113   DummyControl actor = DummyControl::New(true);
3114   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3115   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3116   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3117
3118   tet_infoline("Create visual with IMMEDIATE load policy");
3119   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3120
3121   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3122   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3123   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3124
3125   tet_infoline("Allow image time to load");
3126   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3127   application.SendNotification();
3128   application.Render();
3129
3130   tet_infoline("Testing texture is loaded and resource ready signal fired");
3131   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3132   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3133
3134   tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3135
3136   gResourceReadySignalFired        = false; // Reset signal check ready for testing next Control
3137   Visual::Base        imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3138   DummyControl        actor2       = DummyControl::New(true);
3139   Impl::DummyControl& dummyImpl2   = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3140   actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3141
3142   tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3143   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3144   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3145   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3146   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3147   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3148
3149   END_TEST;
3150 }
3151
3152 int UtcDaliImageVisualLoadPolicy05(void)
3153 {
3154   ToolkitTestApplication application;
3155   tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part  Load a visual image before attaching to stage");
3156   tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3157   // Set up trace debug
3158   TestGlAbstraction& gl           = application.GetGlAbstraction();
3159   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3160   textureTrace.Enable(true);
3161
3162   tet_infoline("Create a control and connect to resource ready signal");
3163   DummyControl actor = DummyControl::New(true);
3164   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3165   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3166   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3167   application.GetScene().Add(actor);
3168
3169   tet_infoline("Create visual with ATTACHED load policy");
3170   Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3171
3172   tet_infoline("Registering visual allows control to get a signal once loaded");
3173   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3174   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3175
3176   tet_infoline("Allow image time to load");
3177   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3178   application.SendNotification();
3179   application.Render();
3180
3181   tet_infoline("Testing texture is loaded and resource ready signal fired");
3182   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3183   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3184
3185   tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3186
3187   gResourceReadySignalFired        = false; // Reset signal check ready for testing next Control
3188   Visual::Base        imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3189   DummyControl        actor2       = DummyControl::New(true);
3190   Impl::DummyControl& dummyImpl2   = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3191   actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3192
3193   tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3194   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3195   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3196   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3197   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3198   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3199
3200   END_TEST;
3201 }
3202
3203 int UtcDaliImageVisualOrientationCorrection(void)
3204 {
3205   ToolkitTestApplication application;
3206   tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3207
3208   VisualFactory factory = VisualFactory::Get();
3209   tet_infoline("Create visual with Orientation correction set OFF");
3210   Property::Map propertyMap;
3211   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3212   propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3213   propertyMap.Insert("orientationCorrection", false);
3214   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3215
3216   tet_infoline("Create control for visual, need to loaded it");
3217   DummyControl        actor     = DummyControl::New(true);
3218   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3219   application.GetScene().Add(actor);
3220
3221   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3222   // Wait for image to load
3223   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3224
3225   Vector2 originalImageSize;
3226   tet_infoline("Get size of original visual to compare later with rotated image");
3227   imageVisual.GetNaturalSize(originalImageSize);
3228   DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3229   imageVisual.Reset();                                                                 // remove handle so can unregister it and remove from cache
3230   dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3231   application.SendNotification();
3232   application.Render();
3233
3234   tet_infoline("Create visual with Orientation correction set ON ");
3235   propertyMap.Clear();
3236   propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3237   propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3238   propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3239   imageVisual = factory.CreateVisual(propertyMap);
3240
3241   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3242   // Wait for image to load
3243   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3244
3245   Vector2 rotatedImageSize;
3246   imageVisual.GetNaturalSize(rotatedImageSize);
3247   tet_infoline("Confirm that visual has rotated");
3248   DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3249   DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3250
3251   Property::Map resultMap;
3252   imageVisual.CreatePropertyMap(resultMap);
3253
3254   // check the Property::ORIENTATION_CORRECTION value from the returned map
3255   Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3256   DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3257
3258   END_TEST;
3259 }
3260
3261 int UtcDaliImageVisualCustomShader(void)
3262 {
3263   ToolkitTestApplication application;
3264   tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3265
3266   VisualFactory     factory = VisualFactory::Get();
3267   Property::Map     properties;
3268   Property::Map     shader;
3269   const std::string vertexShader                    = "Foobar";
3270   const std::string fragmentShader                  = "Foobar";
3271   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3272   shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
3273
3274   properties[Visual::Property::TYPE]     = Visual::IMAGE;
3275   properties[Visual::Property::SHADER]   = shader;
3276   properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3277
3278   Visual::Base visual = factory.CreateVisual(properties);
3279
3280   // trigger creation through setting on stage
3281   DummyControl        dummy     = DummyControl::New(true);
3282   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3283   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3284
3285   dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3286   dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3287   application.GetScene().Add(dummy);
3288
3289   application.SendNotification();
3290   application.Render();
3291
3292   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3293
3294   Renderer        renderer = dummy.GetRendererAt(0);
3295   Shader          shader2  = renderer.GetShader();
3296   Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
3297   Property::Map*  map      = value.GetMap();
3298   DALI_TEST_CHECK(map);
3299
3300   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3301   DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3302
3303   Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3304   DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3305
3306   shader.Clear();
3307
3308   shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3309   properties[Visual::Property::SHADER]    = shader;
3310
3311   Visual::Base visual1 = factory.CreateVisual(properties);
3312
3313   // trigger creation through setting on stage
3314   DummyControl        dummy1     = DummyControl::New(true);
3315   Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3316   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3317   dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3318   dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3319   application.GetScene().Add(dummy1);
3320
3321   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3322   glAbstraction.EnableEnableDisableCallTrace(true);
3323
3324   application.SendNotification();
3325   application.Render();
3326
3327   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
3328   std::ostringstream blendStr;
3329   blendStr << std::hex << GL_BLEND;
3330   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3331
3332   END_TEST;
3333 }
3334
3335 void ResourceReadyLoadNext(Control control)
3336 {
3337   static int callNumber = 0;
3338
3339   gResourceReadySignalFired = true;
3340   gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3341
3342   if(callNumber == 0)
3343   {
3344     DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3345
3346     tet_infoline("Create visual with loaded image from within the signal handler");
3347     VisualFactory factory     = VisualFactory::Get();
3348     Visual::Base  imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3349
3350     Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3351     controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3352     callNumber = 1;
3353   }
3354   else
3355   {
3356     tet_infoline("3rd signal called");
3357     DALI_TEST_CHECK(true);
3358   }
3359 }
3360
3361 int UtcDaliImageVisualLoadReady01(void)
3362 {
3363   ToolkitTestApplication application;
3364   tet_infoline("UtcDaliImageVisualLoadReady01");
3365   tet_infoline("First part:  Load an image visual for one resource, then another image visual for a second resource.");
3366   tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3367   tet_infoline("Should get a ready signal for all three visuals");
3368
3369   ClearReadyIds();
3370
3371   tet_infoline("Create a control and connect to resource ready signal");
3372   DummyControl actor    = DummyControl::New(true);
3373   int          actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3374   actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3375   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3376   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3377   application.GetScene().Add(actor);
3378
3379   tet_infoline("Create visual with IMMEDIATE load policy");
3380   Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3381
3382   tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3383   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3384
3385   tet_infoline("Allow image time to load");
3386   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3387   application.SendNotification();
3388   application.Render();
3389
3390   tet_infoline("Testing texture is loaded and resource ready signal fired");
3391   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3392   DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3393
3394   tet_infoline("Original control correctly signalled, now testing failing image");
3395
3396   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3397   ClearReadyIds();
3398
3399   Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3400
3401   DummyControl        actor2     = DummyControl::New(true);
3402   int                 actor2Id   = actor2.GetProperty<int>(Actor::Property::ID);
3403   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3404   actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3405
3406   tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3407   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3408
3409   actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3410   application.GetScene().Add(actor2);
3411
3412   tet_infoline("Wait for loading thread to finish");
3413   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3414   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3415
3416   DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3417
3418   tet_infoline("Check for 3rd signal");
3419   application.SendNotification();
3420   DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3421   DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3422
3423   END_TEST;
3424 }
3425
3426 int UtcDaliImageVisualLoadImagePlanes01(void)
3427 {
3428   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3429   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3430
3431   ToolkitTestApplication application;
3432
3433   VisualFactory factory = VisualFactory::Get();
3434   DALI_TEST_CHECK(factory);
3435
3436   Property::Map propertyMap;
3437   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3438   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3439
3440   Visual::Base visual = factory.CreateVisual(propertyMap);
3441   DALI_TEST_CHECK(visual);
3442
3443   DummyControl      actor     = DummyControl::New();
3444   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3445   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3446   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3447   application.GetScene().Add(actor);
3448
3449   application.SendNotification();
3450   application.Render();
3451
3452   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3453
3454   TestGlAbstraction& gl           = application.GetGlAbstraction();
3455   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3456   textureTrace.Enable(true);
3457
3458   application.SendNotification();
3459   application.Render();
3460
3461   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3462   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3463   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3464
3465   Renderer renderer           = actor.GetRendererAt(0);
3466   auto     preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3467   DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3468
3469   END_TEST;
3470 }
3471
3472 int UtcDaliImageVisualLoadImagePlanes02(void)
3473 {
3474   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3475   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3476
3477   ToolkitTestApplication application;
3478
3479   VisualFactory factory = VisualFactory::Get();
3480   DALI_TEST_CHECK(factory);
3481
3482   // Alpha masking case - not support yuv planes
3483   Property::Map propertyMap;
3484   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3485   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3486   propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3487
3488   Visual::Base visual = factory.CreateVisual(propertyMap);
3489   DALI_TEST_CHECK(visual);
3490
3491   DummyControl      actor     = DummyControl::New();
3492   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3493   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3494   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3495   application.GetScene().Add(actor);
3496
3497   application.SendNotification();
3498   application.Render();
3499
3500   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3501
3502   TestGlAbstraction& gl           = application.GetGlAbstraction();
3503   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3504   textureTrace.Enable(true);
3505
3506   application.SendNotification();
3507   application.Render();
3508
3509   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3510   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3511   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3512
3513   END_TEST;
3514 }
3515
3516 int UtcDaliImageVisualLoadImagePlanes03(void)
3517 {
3518   EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3519   EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3520
3521   ToolkitTestApplication application;
3522
3523   VisualFactory factory = VisualFactory::Get();
3524   DALI_TEST_CHECK(factory);
3525
3526   TestGlAbstraction& gl           = application.GetGlAbstraction();
3527   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3528   textureTrace.Enable(true);
3529
3530   Property::Map propertyMap;
3531   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3532   propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3533   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3534
3535   Visual::Base visual = factory.CreateVisual(propertyMap);
3536   DALI_TEST_CHECK(visual);
3537
3538   DummyControl      actor     = DummyControl::New();
3539   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3540   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3541   actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3542   application.GetScene().Add(actor);
3543
3544   application.SendNotification();
3545   application.Render();
3546
3547   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3548   DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3549   DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3550
3551   END_TEST;
3552 }