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