Merge "Revert "Move Some Devel Properties & APIs to the Public API"" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageVisual.cpp
1 /*
2  * Copyright (c) 2017 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 <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <toolkit-timer.h>
21 #include <toolkit-event-thread-callback.h>
22 #include <dali/devel-api/object/handle-devel.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include "dummy-control.h"
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 void dali_image_visual_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void dali_image_visual_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 namespace
44 {
45 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR  "/gallery-small-1.jpg";
46 const char* TEST_LARGE_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/tbcol.png";
47 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
48 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
49 const char* TEST_INVALID_FILE_NAME =  TEST_RESOURCE_DIR  "/invalid.jpg";
50 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
51 const char* TEST_MASK_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/mask.png";
52 const char* TEST_ROTATED_IMAGE =  TEST_RESOURCE_DIR  "/keyboard-Landscape.jpg";
53
54
55 bool gResourceReadySignalFired = false;
56
57 void ResourceReadySignal( Control control )
58 {
59   gResourceReadySignalFired = true;
60 }
61
62 Actor CreateActorWithImageVisual(const Property::Map& map)
63 {
64   VisualFactory factory = VisualFactory::Get();
65   DummyControl actor = DummyControl::New();
66   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
67   Visual::Base visual = factory.CreateVisual( map );
68   DALI_TEST_CHECK( visual );
69   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
70   actor.SetSize( 200.f, 200.f );
71   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
72   return actor;
73 }
74
75
76 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
77 {
78   VisualFactory factory = VisualFactory::Get();
79
80   Property::Map propertyMap;
81   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
82   propertyMap.Insert( ImageVisual::Property::URL,  url );
83   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH,   20 );
84   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT,   30 );
85   propertyMap.Insert( key , value );
86
87   return factory.CreateVisual( propertyMap );
88 }
89
90 } // namespace
91
92 void TestVisualRender( ToolkitTestApplication& application,
93                        DummyControl& actor,
94                        Visual::Base& visual,
95                        std::size_t expectedSamplers = 0,
96                        ImageDimensions imageDimensions = ImageDimensions(),
97                        Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
98 {
99   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
100   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
101
102   if( resourcePtr )
103   {
104     // set the image size, for test case, this needs to be set before loading started
105     application.GetPlatform().SetClosestImageSize(  Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
106   }
107
108   actor.SetSize( 200.f, 200.f );
109   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
110
111   Stage::GetCurrent().Add( actor );
112
113   application.SendNotification(); // Send messages to update
114   application.Render();           // process update and render
115   application.SendNotification(); // process any signals to event
116
117   if( resourcePtr )
118   {
119     DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
120   }
121
122   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
123 }
124
125 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
126 {
127   Property::Map map;
128   visual.CreatePropertyMap(map);
129   Property::Value* value = map.Find( mixColorIndex );
130   DALI_TEST_CHECK( value );
131   Vector3 mixColor1;
132   DALI_TEST_CHECK( value->Get( mixColor1 ) );
133   DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
134
135   value = map.Find( Visual::Property::MIX_COLOR );
136   DALI_TEST_CHECK( value );
137   Vector4 mixColor2;
138   DALI_TEST_CHECK( value->Get( mixColor2 ) );
139   DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
140
141   value = map.Find( Visual::Property::OPACITY );
142   DALI_TEST_CHECK( value );
143   float opacity;
144   DALI_TEST_CHECK( value->Get( opacity ) );
145   DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
146 }
147
148
149
150 int UtcDaliImageVisualPropertyMap(void)
151 {
152   ToolkitTestApplication application;
153   tet_infoline( "Request image visual with a Property::Map" );
154
155   VisualFactory factory = VisualFactory::Get();
156   DALI_TEST_CHECK( factory );
157
158   Property::Map propertyMap;
159   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
160   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
161
162   Visual::Base visual = factory.CreateVisual( propertyMap );
163   DALI_TEST_CHECK( visual );
164
165   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
166   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
167
168   TestGlAbstraction& gl = application.GetGlAbstraction();
169   TraceCallStack& textureTrace = gl.GetTextureTrace();
170   textureTrace.Enable(true);
171
172   DummyControl actor = DummyControl::New();
173   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
174   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
175
176   actor.SetSize( 200.f, 200.f );
177   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
178
179   Stage::GetCurrent().Add( actor );
180   application.SendNotification();
181   application.Render();
182
183   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
184
185   application.SendNotification();
186   application.Render();
187
188   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
189
190   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
191
192   Stage::GetCurrent().Remove( actor );
193   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
194
195   END_TEST;
196 }
197
198
199 int UtcDaliImageVisualRemoteImageLoad(void)
200 {
201   ToolkitTestApplication application;
202   tet_infoline( "Request remote image visual with a Property::Map" );
203
204   VisualFactory factory = VisualFactory::Get();
205   DALI_TEST_CHECK( factory );
206
207   Property::Map propertyMap;
208   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
209   propertyMap.Insert( ImageVisual::Property::URL,  TEST_REMOTE_IMAGE_FILE_NAME );
210
211   Visual::Base visual = factory.CreateVisual( propertyMap );
212   DALI_TEST_CHECK( visual );
213
214   TestGlAbstraction& gl = application.GetGlAbstraction();
215   TraceCallStack& textureTrace = gl.GetTextureTrace();
216   textureTrace.Enable(true);
217
218   DummyControl actor = DummyControl::New();
219   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
220   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
221
222   actor.SetSize( 200.f, 200.f );
223   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
224
225   Stage::GetCurrent().Add( actor );
226   application.SendNotification();
227
228   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
229
230   application.SendNotification();
231   application.Render();
232
233   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
234   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
235
236   Stage::GetCurrent().Remove( actor );
237   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
238
239   END_TEST;
240 }
241
242 int UtcDaliImageVisualTextureReuse1(void)
243 {
244   ToolkitTestApplication application;
245   tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
246
247   Property::Map propertyMap;
248   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
249   propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
250   propertyMap.Insert( DevelImageVisual::Property::RELEASE_POLICY,  DevelImageVisual::ReleasePolicy::DETACHED );
251
252   TestGlAbstraction& gl = application.GetGlAbstraction();
253   TraceCallStack& textureTrace = gl.GetTextureTrace();
254   textureTrace.Enable(true);
255   TraceCallStack& drawTrace = gl.GetDrawTrace();
256   drawTrace.Enable(true);
257
258   Actor actor = CreateActorWithImageVisual( propertyMap );
259   Stage::GetCurrent().Add( actor );
260   application.SendNotification();
261
262   // Wait for image to load
263   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
264
265   application.SendNotification();
266   application.Render();
267
268   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
269   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
270   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
271   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
272   textureTrace.Reset();
273   drawTrace.Reset();
274
275   Actor actor2 = CreateActorWithImageVisual( propertyMap );
276   Stage::GetCurrent().Add(actor2);
277
278   application.SendNotification(); // Send messages to update
279   application.Render();           // process update and render
280   application.SendNotification(); // process any signals to event
281
282   DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
283
284   tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
285                "draw calls use the same texture as the previous draw call\n" );
286
287   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
288   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
289   DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
290
291   tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
292
293   Stage::GetCurrent().Remove( actor );
294   application.SendNotification();
295   application.Render();
296
297   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
298   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
299
300   tet_infoline("Test that removing last actor does delete the texture\n");
301
302   Stage::GetCurrent().Remove( actor2 ); // Detaches remaining ImageVisual
303   application.SendNotification();
304   application.Render();
305
306   DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
307   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
308
309   END_TEST;
310 }
311
312
313 int UtcDaliImageVisualTextureReuse2(void)
314 {
315   ToolkitTestApplication application;
316   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" );
317
318   Property::Map propertyMap;
319   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
320   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
321
322   TestGlAbstraction& gl = application.GetGlAbstraction();
323   TraceCallStack& textureTrace = gl.GetTextureTrace();
324   textureTrace.Enable(true);
325   TraceCallStack& drawTrace = gl.GetDrawTrace();
326   drawTrace.Enable(true);
327
328   Actor actor = CreateActorWithImageVisual( propertyMap );
329   Stage::GetCurrent().Add( actor );
330   application.SendNotification();
331
332   // Wait for image to load
333   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
334
335   application.SendNotification();
336   application.Render();
337
338   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
339   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
340   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
341   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
342   textureTrace.Reset();
343   drawTrace.Reset();
344
345   propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
346   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
347   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
348   Actor actor2 = CreateActorWithImageVisual( propertyMap );
349   Stage::GetCurrent().Add(actor2);
350
351   application.SendNotification();
352
353   // Wait for image to load
354   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
355
356   application.SendNotification();
357   application.Render();
358
359   DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
360
361   tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
362                "renderers are using different textures\n" );
363
364   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
365   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
366   TraceCallStack::NamedParams tex1;
367   tex1["texture"] = "1";
368   TraceCallStack::NamedParams tex2;
369   tex1["texture"] = "2";
370   DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
371   DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
372
373   tet_infoline("Test that removing 1 actor deletes it's texture\n");
374
375   Stage::GetCurrent().Remove( actor );
376   application.SendNotification();
377   application.Render();
378
379   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
380   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
381
382   tet_infoline("Test that removing last actor deletes it's texture\n");
383
384   Stage::GetCurrent().Remove( actor2 );
385   application.SendNotification();
386   application.Render();
387
388   DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
389   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
390
391   END_TEST;
392 }
393
394
395 int UtcDaliImageVisualImageHandle(void)
396 {
397   ToolkitTestApplication application;
398   tet_infoline( "Request image visual with an image handle" );
399
400   VisualFactory factory = VisualFactory::Get();
401   DALI_TEST_CHECK( factory );
402
403   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
404   Visual::Base visual = factory.CreateVisual( image );
405
406   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
407   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
408
409   const int width=512;
410   const int height=513;
411
412   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
413   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
414
415   TestGlAbstraction& gl = application.GetGlAbstraction();
416   TraceCallStack& textureTrace = gl.GetTextureTrace();
417   textureTrace.Enable(true);
418
419   DummyControl actor = DummyControl::New();
420   TestVisualRender( application, actor, visual, 1u,
421                     ImageDimensions(width, height),
422                     Integration::ResourcePointer(bitmap) );
423
424   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
425   END_TEST;
426 }
427
428 int UtcDaliImageVisualCustomWrapModePixelArea(void)
429 {
430   ToolkitTestApplication application;
431   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
432
433   VisualFactory factory = VisualFactory::Get();
434   DALI_TEST_CHECK( factory );
435
436   // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
437   const int width=34;
438   const int height=34;
439   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
440
441   Property::Map propertyMap;
442   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
443   propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
444   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
445   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
446   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
447   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
448   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
449   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
450   propertyMap.Insert( ImageVisual::Property::ATLASING, true );
451
452   Visual::Base visual = factory.CreateVisual( propertyMap );
453   DALI_TEST_CHECK( visual );
454
455   TestGlAbstraction& gl = application.GetGlAbstraction();
456   TraceCallStack& textureTrace = gl.GetTextureTrace();
457   textureTrace.Enable(true);
458   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
459   texParameterTrace.Enable( true );
460
461   DummyControl actor = DummyControl::New();
462   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
463   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
464   actor.SetSize(2000, 2000);
465   actor.SetParentOrigin(ParentOrigin::CENTER);
466   Stage::GetCurrent().Add( actor );
467
468   // loading started
469   application.SendNotification();
470   application.Render();
471
472   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
473
474   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
475
476   // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
477   std::stringstream out;
478   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
479   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
480   out.str("");
481   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
482   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
483
484   // test the uniforms which used to handle the wrap mode
485   Renderer renderer = actor.GetRendererAt( 0u );
486   DALI_TEST_CHECK( renderer );
487
488   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
489   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
490   Vector4 pixelAreaUniform;
491   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
492   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
493
494   Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
495   Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
496   DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
497   Vector2 wrapModeUniform;
498   DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
499   DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
500
501   actor.Unparent( );
502   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
503
504   END_TEST;
505 }
506
507 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
508 {
509   ToolkitTestApplication application;
510   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
511
512   VisualFactory factory = VisualFactory::Get();
513   DALI_TEST_CHECK( factory );
514
515   // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
516   const int width=600;
517   const int height=600;
518   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
519
520   Property::Map propertyMap;
521   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
522   propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
523   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
524   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
525   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
526   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
527   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
528   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
529
530   Visual::Base visual = factory.CreateVisual( propertyMap );
531   DALI_TEST_CHECK( visual );
532
533   TestGlAbstraction& gl = application.GetGlAbstraction();
534   TraceCallStack& textureTrace = gl.GetTextureTrace();
535   textureTrace.Enable(true);
536   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
537   texParameterTrace.Enable( true );
538
539   DummyControl actor = DummyControl::New();
540   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
541   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
542   actor.SetSize(2000, 2000);
543   actor.SetParentOrigin(ParentOrigin::CENTER);
544   Stage::GetCurrent().Add( actor );
545
546   // loading started
547   application.SendNotification();
548   application.Render();
549
550   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
551
552   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
553
554   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
555   std::stringstream out;
556   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
557   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
558   out.str("");
559   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
560   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
561
562   // test the uniforms which used to handle the wrap mode
563   Renderer renderer = actor.GetRendererAt( 0u );
564   DALI_TEST_CHECK( renderer );
565
566   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
567   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
568   Vector4 pixelAreaUniform;
569   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
570   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
571
572   Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
573   DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
574
575   actor.Unparent();
576   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
577
578   END_TEST;
579 }
580
581 int UtcDaliImageVisualAnimateMixColor(void)
582 {
583   ToolkitTestApplication application;
584   tet_infoline( "Animate mix color" );
585
586   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
587
588   VisualFactory factory = VisualFactory::Get();
589   Property::Map propertyMap;
590   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
591   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
592   propertyMap.Insert("mixColor", Color::BLUE);
593   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
594   Visual::Base visual = factory.CreateVisual( propertyMap );
595
596   DummyControl actor = DummyControl::New(true);
597   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
598   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
599
600   actor.SetSize(2000, 2000);
601   actor.SetParentOrigin(ParentOrigin::CENTER);
602   actor.SetColor(Color::BLACK);
603   Stage::GetCurrent().Add(actor);
604
605   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
606
607   Renderer renderer = actor.GetRendererAt(0);
608   Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
609   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
610   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
611
612   tet_infoline("Test that the renderer has the mixColor property");
613   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
614
615   const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
616
617   Property::Map map;
618   map["target"] = "testVisual";
619   map["property"] = "mixColor";
620   map["initialValue"] = Color::MAGENTA;
621   map["targetValue"] = TARGET_MIX_COLOR;
622   map["animator"] = Property::Map()
623     .Add("alphaFunction", "LINEAR")
624     .Add("timePeriod", Property::Map()
625          .Add("delay", 0.0f)
626          .Add("duration", 4.0f));
627
628   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
629
630   Animation animation = dummyImpl.CreateTransition( transition );
631
632   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
633   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
634
635   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
636   animation.Play();
637
638   application.SendNotification();
639   application.Render(0); // Ensure animation starts
640   application.Render(2000u); // Halfway point
641   Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f );
642
643   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
644   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(testColor)), true, TEST_LOCATION );
645   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", testColor.a), true, TEST_LOCATION );
646
647   application.Render(2000u); // Halfway point between blue and white
648
649   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
650   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
651   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION );
652   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", TARGET_MIX_COLOR.a), true, TEST_LOCATION );
653
654   TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
655
656   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
657   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
658
659   END_TEST;
660 }
661
662 int UtcDaliImageVisualAnimateOpacity(void)
663 {
664   ToolkitTestApplication application;
665   tet_infoline( "Animate image visual opacity" );
666
667   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
668
669   VisualFactory factory = VisualFactory::Get();
670   Property::Map propertyMap;
671   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
672   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
673   propertyMap.Insert("opacity", 0.5f);
674   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
675   Visual::Base visual = factory.CreateVisual( propertyMap );
676
677   DummyControl actor = DummyControl::New(true);
678   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
679   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
680
681   actor.SetSize(2000, 2000);
682   actor.SetParentOrigin(ParentOrigin::CENTER);
683   actor.SetColor(Color::BLACK);
684   Stage::GetCurrent().Add(actor);
685
686   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
687
688   Renderer renderer = actor.GetRendererAt(0);
689   tet_infoline("Test that the renderer has the opacity property");
690   Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
691   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
692
693
694   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
695   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
696
697   {
698     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." );
699
700     Property::Map map;
701     map["target"] = "testVisual";
702     map["property"] = "opacity";
703     map["targetValue"] = 1.0f;
704     map["animator"] = Property::Map()
705       .Add("alphaFunction", "LINEAR")
706       .Add("timePeriod", Property::Map()
707            .Add("delay", 0.0f)
708            .Add("duration", 4.0f));
709
710     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
711     Animation animation = dummyImpl.CreateTransition( transition );
712     animation.Play();
713
714     application.SendNotification();
715     application.Render(0);     // Ensure animation starts
716     application.Render(2000u); // Halfway point through animation
717     application.SendNotification(); // Handle any signals
718
719     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.75f), true, TEST_LOCATION );
720
721     application.Render(2001u); // end
722     application.SendNotification(); // ensure animation finished signal is sent
723
724     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 1.0f), true, TEST_LOCATION );
725
726     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
727     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
728   }
729
730
731   {
732     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." );
733
734     Property::Map map;
735     map["target"] = "testVisual";
736     map["property"] = Visual::Property::OPACITY;
737     map["targetValue"] = 0.1f;
738     map["animator"] = Property::Map()
739       .Add("alphaFunction", "LINEAR")
740       .Add("timePeriod", Property::Map()
741            .Add("delay", 0.0f)
742            .Add("duration", 4.0f));
743
744     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
745     Animation animation = dummyImpl.CreateTransition( transition );
746     animation.Play();
747
748     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
749     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
750
751     application.SendNotification();
752     application.Render(0);     // Ensure animation starts
753     application.Render(2000u); // Halfway point
754     application.SendNotification();
755
756     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.55f), true, TEST_LOCATION );
757
758     application.Render(2016u); // end
759     application.SendNotification();
760
761     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.1f), true, TEST_LOCATION );
762
763     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
764     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
765   }
766
767
768   END_TEST;
769 }
770
771 int UtcDaliImageVisualAnimatePixelArea(void)
772 {
773   ToolkitTestApplication application;
774   tet_infoline( "ImageVisual animate pixel area" );
775
776   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
777
778   VisualFactory factory = VisualFactory::Get();
779   Property::Map propertyMap;
780   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
781   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
782   propertyMap.Insert("mixColor", Color::BLUE);
783   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
784   Visual::Base visual = factory.CreateVisual( propertyMap );
785
786   DummyControl actor = DummyControl::New(true);
787   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
788   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
789
790   actor.SetSize(2000, 2000);
791   actor.SetParentOrigin(ParentOrigin::CENTER);
792   actor.SetColor(Color::BLACK);
793   Stage::GetCurrent().Add(actor);
794
795   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
796
797   Renderer renderer = actor.GetRendererAt(0);
798   Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
799
800   tet_infoline("Test that the renderer has the mixColor property");
801   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
802
803   // TransitionData only takes string keys
804   Property::Map map;
805   map["target"] = "testVisual";
806   map["property"] = "pixelArea";
807   map["initialValue"] = Vector4( 0,0,0,1 );
808   map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
809   map["animator"] = Property::Map()
810     .Add("alphaFunction", "LINEAR")
811     .Add("timePeriod", Property::Map()
812          .Add("delay", 0.0f)
813          .Add("duration", 4.0f));
814
815   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
816
817   Animation animation = dummyImpl.CreateTransition( transition );
818   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
819   animation.Play();
820
821   application.SendNotification();
822   application.Render(0);     // Ensure animation starts
823   application.Render(2000u); // Halfway point
824
825   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
826
827   application.Render(2000u); // End of animation
828
829   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
830
831   END_TEST;
832 }
833
834 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
835 {
836   ToolkitTestApplication application;
837   tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
838
839   Property::Map propertyMap;
840   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
841   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
842
843   TestGlAbstraction& gl = application.GetGlAbstraction();
844   TraceCallStack& textureTrace = gl.GetTextureTrace();
845   textureTrace.Enable(true);
846   TraceCallStack& drawTrace = gl.GetDrawTrace();
847   drawTrace.Enable(true);
848
849   Actor actor = CreateActorWithImageVisual( propertyMap );
850   Stage::GetCurrent().Add( actor );
851   application.SendNotification();
852
853   Stage::GetCurrent().Remove( actor );
854   application.SendNotification();
855
856   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
857   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
858   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
859   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
860
861   END_TEST;
862 }
863
864 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
865 {
866   ToolkitTestApplication application;
867   tet_infoline( "Load image asynchronosly, cancel loading, then load again" );
868
869   VisualFactory factory = VisualFactory::Get();
870   DALI_TEST_CHECK( factory );
871
872   Property::Map propertyMap;
873   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
874   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
875
876   Visual::Base visual = factory.CreateVisual( propertyMap );
877   DALI_TEST_CHECK( visual );
878
879   TestGlAbstraction& gl = application.GetGlAbstraction();
880   TraceCallStack& textureTrace = gl.GetTextureTrace();
881   textureTrace.Enable( true );
882   TraceCallStack& drawTrace = gl.GetDrawTrace();
883   drawTrace.Enable( true );
884
885   DummyControl actor = DummyControl::New();
886   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
887   dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
888
889   Stage::GetCurrent().Add( actor );
890
891   // Cancel loading
892   Stage::GetCurrent().Remove( actor );
893
894   Stage::GetCurrent().Add( actor );
895
896   // Create another visual with the same image
897   visual = factory.CreateVisual( propertyMap );
898   DALI_TEST_CHECK( visual );
899
900   dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
901
902   application.SendNotification();
903   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
904
905   application.SendNotification();
906   application.Render();
907
908   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
909   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
910   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
911   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
912
913   END_TEST;
914 }
915
916 int UtcDaliImageVisualSetInvalidAsyncImage(void)
917 {
918   ToolkitTestApplication application;
919   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
920
921   VisualFactory factory = VisualFactory::Get();
922   DALI_TEST_CHECK( factory );
923
924   Property::Map propertyMap;
925   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
926   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
927
928   Visual::Base visual = factory.CreateVisual( propertyMap );
929   DALI_TEST_CHECK( visual );
930
931   TestGlAbstraction& gl = application.GetGlAbstraction();
932   TraceCallStack& textureTrace = gl.GetTextureTrace();
933   textureTrace.Enable(true);
934
935   DummyControl actor = DummyControl::New();
936   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
937   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
938
939   actor.SetSize( 200.f, 200.f );
940   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
941
942   Stage::GetCurrent().Add( actor );
943
944   application.SendNotification();
945   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
946
947   application.SendNotification();
948   application.Render();
949
950   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
951   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
952
953   Stage::GetCurrent().Remove( actor );
954   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
955
956   END_TEST;
957 }
958
959 int UtcDaliImageVisualSetInvalidSyncImage(void)
960 {
961   ToolkitTestApplication application;
962   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
963
964   VisualFactory factory = VisualFactory::Get();
965   DALI_TEST_CHECK( factory );
966
967   Property::Map propertyMap;
968   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
969   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
970   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
971
972   Visual::Base visual = factory.CreateVisual( propertyMap );
973   DALI_TEST_CHECK( visual );
974
975   TestGlAbstraction& gl = application.GetGlAbstraction();
976   TraceCallStack& textureTrace = gl.GetTextureTrace();
977   textureTrace.Enable(true);
978
979   DummyControl actor = DummyControl::New();
980   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
981   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
982
983   actor.SetSize( 200.f, 200.f );
984   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
985
986   Stage::GetCurrent().Add( actor );
987
988   application.SendNotification();
989   application.Render();
990
991   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
992   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
993
994   Stage::GetCurrent().Remove( actor );
995   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
996
997   END_TEST;
998 }
999
1000 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1001 {
1002   ToolkitTestApplication application;
1003   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1004
1005   VisualFactory factory = VisualFactory::Get();
1006   DALI_TEST_CHECK( factory );
1007
1008   // Local invalid file, asynchronous loading
1009   Property::Map propertyMap;
1010   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1011   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1012
1013   Visual::Base visual = factory.CreateVisual( propertyMap );
1014   DALI_TEST_CHECK( visual );
1015
1016   TestGlAbstraction& gl = application.GetGlAbstraction();
1017   TraceCallStack& textureTrace = gl.GetTextureTrace();
1018   textureTrace.Enable(true);
1019
1020   DummyControl actor = DummyControl::New();
1021   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1022   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1023
1024   actor.SetSize( 200.f, 200.f );
1025   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1026
1027   Stage::GetCurrent().Add( actor );
1028
1029   application.SendNotification();
1030   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1031
1032   application.SendNotification();
1033   application.Render();
1034
1035   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1036   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1037
1038   Stage::GetCurrent().Remove( actor );
1039   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1040
1041   END_TEST;
1042 }
1043
1044 int UtcDaliImageVisualAlphaMask(void)
1045 {
1046   ToolkitTestApplication application;
1047   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1048
1049   VisualFactory factory = VisualFactory::Get();
1050   DALI_TEST_CHECK( factory );
1051
1052   Property::Map propertyMap;
1053   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1054   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
1055   propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1056
1057   Visual::Base visual = factory.CreateVisual( propertyMap );
1058   DALI_TEST_CHECK( visual );
1059
1060   Property::Map testMap;
1061   visual.CreatePropertyMap(testMap);
1062   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1063
1064   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1065   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1066
1067   TestGlAbstraction& gl = application.GetGlAbstraction();
1068   TraceCallStack& textureTrace = gl.GetTextureTrace();
1069   textureTrace.Enable(true);
1070
1071   DummyControl actor = DummyControl::New();
1072   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1073   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1074
1075   actor.SetSize( 200.f, 200.f );
1076   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1077   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1078
1079   Stage::GetCurrent().Add( actor );
1080   application.SendNotification();
1081   application.Render();
1082
1083   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1084
1085   application.SendNotification();
1086   application.Render();
1087
1088   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1089   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1090   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1091
1092   dummyImpl.UnregisterVisual(  Control::CONTROL_PROPERTY_END_INDEX + 1 );
1093   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1094
1095   END_TEST;
1096 }
1097
1098 int UtcDaliImageVisualRemoteAlphaMask(void)
1099 {
1100   ToolkitTestApplication application;
1101   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1102
1103   VisualFactory factory = VisualFactory::Get();
1104   DALI_TEST_CHECK( factory );
1105
1106   const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1107
1108   Property::Map propertyMap;
1109   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1110   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
1111   propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1112
1113   Visual::Base visual = factory.CreateVisual( propertyMap );
1114   DALI_TEST_CHECK( visual );
1115
1116   Property::Map testMap;
1117   visual.CreatePropertyMap(testMap);
1118   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1119
1120   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1121   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1122
1123   TestGlAbstraction& gl = application.GetGlAbstraction();
1124   TraceCallStack& textureTrace = gl.GetTextureTrace();
1125   textureTrace.Enable(true);
1126
1127   DummyControl actor = DummyControl::New();
1128   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1129   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1130   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1131
1132   actor.SetSize( 200.f, 200.f );
1133   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1134
1135   Stage::GetCurrent().Add( actor );
1136   application.SendNotification();
1137   application.Render();
1138
1139   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1140
1141   application.SendNotification();
1142   application.Render();
1143
1144   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1145   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1146   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1147
1148   END_TEST;
1149 }
1150
1151
1152 int UtcDaliImageVisualAlphaMaskCrop(void)
1153 {
1154   ToolkitTestApplication application;
1155   tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1156
1157   VisualFactory factory = VisualFactory::Get();
1158   DALI_TEST_CHECK( factory );
1159
1160   Property::Map propertyMap;
1161   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1162   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
1163   propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1164   propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1165   propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1166
1167   Visual::Base visual = factory.CreateVisual( propertyMap );
1168   DALI_TEST_CHECK( visual );
1169
1170   Property::Map testMap;
1171   visual.CreatePropertyMap(testMap);
1172   DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1173   DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1174   DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1175
1176   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1177   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1178
1179   TestGlAbstraction& gl = application.GetGlAbstraction();
1180   TraceCallStack& textureTrace = gl.GetTextureTrace();
1181   textureTrace.Enable(true);
1182
1183   DummyControl actor = DummyControl::New();
1184   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1185   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1186
1187   actor.SetSize( 200.f, 200.f );
1188   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1189   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1190
1191   Stage::GetCurrent().Add( actor );
1192   application.SendNotification();
1193   application.Render();
1194
1195   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1196
1197   application.SendNotification();
1198   application.Render();
1199
1200   Vector2 size;
1201   visual.GetNaturalSize(size);
1202
1203   DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1204   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1205   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1206   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1207
1208   END_TEST;
1209 }
1210
1211 int UtcDaliImageVisualReleasePolicy01(void)
1212 {
1213   ToolkitTestApplication application;
1214   tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1215
1216   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
1217   DALI_TEST_CHECK( imageVisual );
1218
1219   // Set up debug trace
1220   TestGlAbstraction& gl = application.GetGlAbstraction();
1221   TraceCallStack& textureTrace = gl.GetTextureTrace();
1222   textureTrace.Enable(true);
1223
1224   tet_infoline( "Register visual with control and ensure it has the only handle" );
1225   DummyControl actor = DummyControl::New(true);
1226   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1227   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1228   imageVisual.Reset();
1229
1230   actor.SetSize(200.f, 200.f);
1231
1232   application.SendNotification();
1233   application.Render(0);
1234   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1235   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1236
1237   Stage::GetCurrent().Add( actor );
1238
1239   // Wait for image to load
1240   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1241
1242   application.SendNotification();
1243   application.Render(0);
1244   // Test renderer and texture created
1245   tet_infoline( "Confirm texture created" );
1246   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1247   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1248
1249   tet_infoline( "Disable visual causing the texture to be deleted" );
1250   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1251
1252   application.SendNotification();
1253   application.Render(0);
1254   // Test renderer and textures removed.
1255   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1256   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1257
1258   END_TEST;
1259 }
1260
1261 int UtcDaliImageVisualReleasePolicy02(void)
1262 {
1263   ToolkitTestApplication application;
1264   tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1265
1266   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1267   DALI_TEST_CHECK( imageVisual );
1268
1269   // Setup debug trace
1270   TestGlAbstraction& gl = application.GetGlAbstraction();
1271   TraceCallStack& textureTrace = gl.GetTextureTrace();
1272   textureTrace.Enable(true);
1273
1274   tet_infoline( "Register visual with control and ensure it has the only handle" );
1275   DummyControl actor = DummyControl::New(true);
1276   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1277   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1278   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1279
1280   actor.SetSize(200.f, 200.f);
1281
1282   application.SendNotification();
1283   application.Render(0);
1284   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1285   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1286
1287   Stage::GetCurrent().Add( actor );
1288
1289   // Wait for image to load
1290   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1291
1292   application.SendNotification();
1293   application.Render(0);
1294   // Test renderer and texture created
1295   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1296   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1297
1298
1299   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1300   tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1301   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1302   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1303   application.SendNotification();
1304   application.Render();
1305
1306   // Test texture removed after visual destroyed.
1307   tet_infoline( "Ensure texture is deleted after visual destroyed" );
1308   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1309
1310   END_TEST;
1311 }
1312
1313 int UtcDaliImageVisualReleasePolicy03(void)
1314 {
1315   ToolkitTestApplication application;
1316   tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1317
1318   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1319   DALI_TEST_CHECK( imageVisual );
1320
1321   TestGlAbstraction& gl = application.GetGlAbstraction();
1322   TraceCallStack& textureTrace = gl.GetTextureTrace();
1323   textureTrace.Enable(true);
1324
1325   tet_infoline( "Register visual with control and ensure it has the only handle" );
1326   DummyControl actor = DummyControl::New(true);
1327   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1328   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1329   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1330
1331   actor.SetSize(200.f, 200.f);
1332
1333   application.SendNotification();
1334   application.Render(0);
1335   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1336   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1337
1338   Stage::GetCurrent().Add( actor );
1339
1340   // Wait for image to load
1341   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1342
1343   application.SendNotification();
1344   application.Render(0);
1345   // Test renderer and texture created
1346   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1347   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1348
1349   tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1350   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1351   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1352   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1353   application.SendNotification();
1354   application.Render();
1355
1356   tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1357   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1358
1359   END_TEST;
1360 }
1361
1362 int UtcDaliImageVisualReleasePolicy04(void)
1363 {
1364   ToolkitTestApplication application;
1365   tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1366
1367   tet_infoline( "Create first visual with Never release policy" );
1368   Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1369
1370   tet_infoline( "Create second visual with Destroyed release policy");
1371     Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1372
1373   // Set up trace debug
1374   TestGlAbstraction& gl = application.GetGlAbstraction();
1375   TraceCallStack& textureTrace = gl.GetTextureTrace();
1376   textureTrace.Enable(true);
1377
1378   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1379   DummyControl actor = DummyControl::New(true);
1380   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1381   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1382   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1383   imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1384   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1385
1386   actor.SetSize(200.f, 200.f);
1387
1388   // Test initially zero renderers
1389   application.SendNotification();
1390   application.Render(0);
1391   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1392   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1393
1394   Stage::GetCurrent().Add( actor );
1395
1396   // Wait for image to load
1397   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1398
1399   application.SendNotification();
1400   application.Render(0);
1401   tet_infoline( "Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer" );
1402   DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1403   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1404
1405   // Test renderer removed when visual destroyed
1406   DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1407   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 );  // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1408   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1409   application.SendNotification();
1410   application.Render();
1411
1412   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1413   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1414
1415   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1416   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1417   application.SendNotification();
1418   application.Render();
1419
1420   tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1421   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1422   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1423
1424   END_TEST;
1425 }
1426
1427 int UtcDaliImageVisualReleasePolicy05(void)
1428 {
1429   ToolkitTestApplication application;
1430   tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1431
1432   VisualFactory factory = VisualFactory::Get();
1433
1434   Property::Map propertyMapNeverReleasePolicy;
1435   propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1436   propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
1437   propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH,   20 );
1438   propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT,   30 );
1439   propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1440
1441   Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1442
1443   Property::Map resultMap;
1444   imageVisualNever.CreatePropertyMap( resultMap );
1445   DALI_TEST_CHECK( ! resultMap.Empty() );
1446
1447   DALI_TEST_EQUALS( ( resultMap.Find( DevelImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)DevelImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1448
1449   END_TEST;
1450 }
1451
1452 int UtcDaliImageVisualReleasePolicy06(void)
1453 {
1454   ToolkitTestApplication application;
1455   tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1456
1457   Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1458   DALI_TEST_CHECK( imageVisual );
1459
1460   TestGlAbstraction& gl = application.GetGlAbstraction();
1461   TraceCallStack& textureTrace = gl.GetTextureTrace();
1462   textureTrace.Enable(true);
1463
1464   tet_infoline( "Register visual with control and ensure it has the only handle" );
1465   DummyControl actor = DummyControl::New(true);
1466   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1467   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1468   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1469
1470   actor.SetSize(200.f, 200.f);
1471
1472   application.SendNotification();
1473   application.Render(0);
1474   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1475   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1476
1477   Stage::GetCurrent().Add( actor );
1478
1479   // Wait for image to load
1480   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1481
1482   application.SendNotification();
1483   application.Render(0);
1484   // Test renderer and texture created
1485   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1486   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1487   textureTrace.Reset();
1488
1489   tet_infoline( "Disable Visual and check texture not affected" );
1490   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1491   application.SendNotification();
1492   application.Render(0);
1493   tet_infoline( "Check renderer is destroyed when visual off stage" );
1494   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1495   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1496   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1497   textureTrace.Reset();
1498
1499   tet_infoline( "Re-enable Visual and check texture not affected" );
1500   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1501   application.SendNotification();
1502   application.Render(0);
1503   tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1504   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1505   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1506   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1507
1508   END_TEST;
1509 }
1510
1511 int UtcDaliImageVisualReleasePolicy07(void)
1512 {
1513   ToolkitTestApplication application;
1514   tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1515
1516   tet_infoline( "Create first visual with DESTROYED release policy" );
1517   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1518
1519
1520   tet_infoline( "Create second visual with DETACHED release policy");
1521   Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
1522
1523   // Set up trace debug
1524   TestGlAbstraction& gl = application.GetGlAbstraction();
1525   TraceCallStack& textureTrace = gl.GetTextureTrace();
1526   textureTrace.Enable(true);
1527
1528   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1529   DummyControl actor = DummyControl::New(true);
1530   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1531   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1532   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1533   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1534   imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1535
1536   actor.SetSize(200.f, 200.f);
1537
1538   // Test initially zero renderers
1539   application.SendNotification();
1540   application.Render(0);
1541   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1542   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1543
1544   Stage::GetCurrent().Add( actor );
1545
1546   // Wait for image to load
1547   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1548
1549   application.SendNotification();
1550   application.Render(0);
1551   tet_infoline( "Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer" );
1552   DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1553   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1554
1555   // Test renderer removed when visual destroyed
1556   DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1557   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false );  // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1558   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1559   application.SendNotification();
1560   application.Render();
1561
1562   // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1563   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1564
1565   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1566   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1567   application.SendNotification();
1568   application.Render();
1569
1570   tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1571   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1572
1573   END_TEST;
1574 }
1575
1576 int UtcDaliImageVisualLoadPolicy01(void)
1577 {
1578   ToolkitTestApplication application;
1579   tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1580
1581   // Set up trace debug
1582   TestGlAbstraction& gl = application.GetGlAbstraction();
1583   TraceCallStack& textureTrace = gl.GetTextureTrace();
1584   textureTrace.Enable(true);
1585
1586   tet_infoline( "Create visual with IMMEDIATE load policy" );
1587   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1588
1589   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1590
1591   // Ensure texture has been uploaded
1592   application.SendNotification();
1593   application.Render();
1594
1595   tet_infoline( "Ensure texture loading starts after visual created" );
1596   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1597   textureTrace.Reset();
1598
1599   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1600   DummyControl actor = DummyControl::New(true);
1601   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1602   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1603   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1604
1605   actor.SetSize(200.f, 200.f);
1606   Stage::GetCurrent().Add( actor );
1607   tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
1608   const unsigned int TIME_OUT_3_SECONDS = 3;
1609   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1610
1611   application.SendNotification();
1612   application.Render();
1613
1614   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1615   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1616
1617   // Ensure texture is deleted when no longer needed (ref count was correct )
1618   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1619
1620   application.SendNotification();
1621   application.Render();
1622
1623   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1624   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1625
1626   END_TEST;
1627 }
1628
1629 int UtcDaliImageVisualLoadPolicy02(void)
1630 {
1631   ToolkitTestApplication application;
1632   tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
1633
1634   // Set up trace debug
1635   TestGlAbstraction& gl = application.GetGlAbstraction();
1636   TraceCallStack& textureTrace = gl.GetTextureTrace();
1637   textureTrace.Enable(true);
1638
1639   tet_infoline( "Create visual with IMMEDIATE load policy" );
1640   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
1641
1642   const unsigned int TIME_OUT_3_SECONDS = 3;
1643   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1644
1645   // Act on meeage queue even although nothing expected to load
1646   application.SendNotification();
1647   application.Render();
1648
1649   tet_infoline( "Ensure texture is not generated yet" );
1650   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1651   textureTrace.Reset();
1652
1653   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1654   DummyControl actor = DummyControl::New(true);
1655   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1656   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1657   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1658
1659   actor.SetSize(200.f, 200.f);
1660   Stage::GetCurrent().Add( actor );
1661   tet_infoline( "Allow image time to load" );
1662   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1663
1664   application.SendNotification();
1665   application.Render();
1666
1667   tet_infoline( "Ensure texture generated and renderer created" );
1668   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1669   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1670
1671   // Ensure texture is delete when no longer needed
1672   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1673
1674   application.SendNotification();
1675   application.Render();
1676
1677   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1678   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1679
1680   END_TEST;
1681 }
1682
1683 int UtcDaliImageVisualLoadPolicy03(void)
1684 {
1685   ToolkitTestApplication application;
1686   tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
1687
1688   const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
1689
1690   // Set up trace debug
1691   TestGlAbstraction& gl = application.GetGlAbstraction();
1692   TraceCallStack& textureTrace = gl.GetTextureTrace();
1693   textureTrace.Enable(true);
1694
1695   tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
1696   DummyControl actor = DummyControl::New(true);
1697   actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1698   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1699   actor.SetSize(200.f, 200.f);
1700
1701   tet_infoline( "Create visual with IMMEDIATE load policy" );
1702   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1703
1704   tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
1705   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1706   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1707
1708   tet_infoline( "Allow image time to load resource" );
1709   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1710   application.SendNotification();
1711   application.Render();
1712
1713   // Ensure texture has been uploaded
1714   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1715   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1716
1717   END_TEST;
1718 }
1719
1720 int UtcDaliImageVisualLoadPolicy04(void)
1721 {
1722   ToolkitTestApplication application;
1723   tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part  Load a visual image before attaching to stage");
1724   tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
1725
1726   const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
1727
1728   // Set up trace debug
1729   TestGlAbstraction& gl = application.GetGlAbstraction();
1730   TraceCallStack& textureTrace = gl.GetTextureTrace();
1731   textureTrace.Enable(true);
1732
1733   tet_infoline( "Create a control and connect to resource ready signal" );
1734   DummyControl actor = DummyControl::New(true);
1735   actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1736   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1737   actor.SetSize(200.f, 200.f);
1738
1739   tet_infoline( "Create visual with IMMEDIATE load policy" );
1740   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1741
1742   tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
1743   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1744   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1745
1746   tet_infoline( "Allow image time to load" );
1747   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1748   application.SendNotification();
1749   application.Render();
1750
1751   tet_infoline( "Testing texture is loaded and resource ready signal fired" );
1752   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1753   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1754
1755   tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
1756
1757   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
1758   Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1759   DummyControl actor2 = DummyControl::New(true);
1760   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1761   actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
1762
1763   tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
1764   dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
1765   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
1766   actor2.SetSize(200.f, 200.f);
1767   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
1768   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1769
1770   END_TEST;
1771 }
1772
1773 int UtcDaliImageVisualLoadPolicy05(void)
1774 {
1775   ToolkitTestApplication application;
1776   tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part  Load a visual image before attaching to stage");
1777   tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
1778   // Set up trace debug
1779   TestGlAbstraction& gl = application.GetGlAbstraction();
1780   TraceCallStack& textureTrace = gl.GetTextureTrace();
1781   textureTrace.Enable(true);
1782
1783   tet_infoline( "Create a control and connect to resource ready signal" );
1784   DummyControl actor = DummyControl::New(true);
1785   actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1786   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1787   actor.SetSize(200.f, 200.f);
1788   Stage::GetCurrent().Add( actor );
1789
1790   tet_infoline( "Create visual with ATTACHED load policy" );
1791   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
1792
1793   tet_infoline( "Registering visual allows control to get a signal once loaded" );
1794   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1795   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1796
1797   tet_infoline( "Allow image time to load" );
1798   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1799   application.SendNotification();
1800   application.Render();
1801
1802   tet_infoline( "Testing texture is loaded and resource ready signal fired" );
1803   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1804   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1805
1806   tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
1807
1808   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
1809   Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
1810   DummyControl actor2 = DummyControl::New(true);
1811   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1812   actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
1813
1814   tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
1815   dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
1816   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
1817   actor2.SetSize(200.f, 200.f);
1818   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
1819   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1820
1821   END_TEST;
1822 }
1823
1824
1825 int UtcDaliImageVisualOrientationCorrection(void)
1826 {
1827   ToolkitTestApplication application;
1828   tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
1829
1830   VisualFactory factory = VisualFactory::Get();
1831   tet_infoline( "Create visual with Orientation correction set OFF" );
1832   Property::Map propertyMap;
1833   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1834   propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
1835   propertyMap.Insert( DevelImageVisual::Property::ORIENTATION_CORRECTION, false );
1836   Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1837
1838   tet_infoline( "Create control for visual, need to loaded it" );
1839   DummyControl actor = DummyControl::New(true);
1840   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1841   Stage::GetCurrent().Add( actor );
1842
1843   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1844   // Wait for image to load
1845   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1846
1847   Vector2 originalImageSize;
1848   tet_infoline( "Get size of original visual to compare later with rotated image" );
1849   imageVisual.GetNaturalSize( originalImageSize );
1850   DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
1851   imageVisual.Reset();  // remove handle so can unregister it and remove from cache
1852   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1853   application.SendNotification();
1854   application.Render();
1855
1856   tet_infoline( "Create visual with Orientation correction set ON " );
1857   propertyMap.Clear();
1858   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1859   propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
1860   propertyMap.Insert( DevelImageVisual::Property::ORIENTATION_CORRECTION, true );
1861   imageVisual = factory.CreateVisual( propertyMap );
1862
1863   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1864   // Wait for image to load
1865   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1866
1867   Vector2 rotatedImageSize;
1868   imageVisual.GetNaturalSize( rotatedImageSize );
1869   tet_infoline( "Confirm that visual has rotated" );
1870   DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
1871   DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
1872
1873   Property::Map resultMap;
1874   imageVisual.CreatePropertyMap( resultMap );
1875
1876   // check the Property::ORIENTATION_CORRECTION value from the returned map
1877   Property::Value* typeValue = resultMap.Find( DevelImageVisual::Property::ORIENTATION_CORRECTION,  Property::BOOLEAN );
1878   DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
1879
1880   END_TEST;
1881 }