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