[dali_1.9.15] Merge branch '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.GetId());
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 UtcDaliImageVisualImageHandle(void)
574 {
575   ToolkitTestApplication application;
576   tet_infoline( "Request image visual with an image handle" );
577
578   VisualFactory factory = VisualFactory::Get();
579   DALI_TEST_CHECK( factory );
580
581   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
582   Visual::Base visual = factory.CreateVisual( image );
583
584   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
585   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
586
587   const int width=512;
588   const int height=513;
589
590   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
591   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
592
593   TestGlAbstraction& gl = application.GetGlAbstraction();
594   TraceCallStack& textureTrace = gl.GetTextureTrace();
595   textureTrace.Enable(true);
596
597   DummyControl actor = DummyControl::New();
598   TestVisualRender( application, actor, visual, 1u,
599                     ImageDimensions(width, height),
600                     Integration::ResourcePointer(bitmap) );
601
602   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
603   END_TEST;
604 }
605
606 int UtcDaliImageVisualCustomWrapModePixelArea(void)
607 {
608   ToolkitTestApplication application;
609   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
610
611   VisualFactory factory = VisualFactory::Get();
612   DALI_TEST_CHECK( factory );
613
614   // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
615   const int width=34;
616   const int height=34;
617   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
618
619   Property::Map propertyMap;
620   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
621   propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
622   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
623   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
624   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
625   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
626   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
627   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
628   propertyMap.Insert( ImageVisual::Property::ATLASING, true );
629
630   Visual::Base visual = factory.CreateVisual( propertyMap );
631   DALI_TEST_CHECK( visual );
632
633   TestGlAbstraction& gl = application.GetGlAbstraction();
634   TraceCallStack& textureTrace = gl.GetTextureTrace();
635   textureTrace.Enable(true);
636   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
637   texParameterTrace.Enable( true );
638
639   DummyControl actor = DummyControl::New();
640   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
641   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
642   actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
643   actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
644   Stage::GetCurrent().Add( actor );
645
646   // loading started
647   application.SendNotification();
648   application.Render();
649
650   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
651
652   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
653
654   // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
655   std::stringstream out;
656   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
657   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
658   out.str("");
659   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
660   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
661
662   // test the uniforms which used to handle the wrap mode
663   Renderer renderer = actor.GetRendererAt( 0u );
664   DALI_TEST_CHECK( renderer );
665
666   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
667   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
668   Vector4 pixelAreaUniform;
669   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
670   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
671
672   Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
673   Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
674   DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
675   Vector2 wrapModeUniform;
676   DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
677   DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
678
679   actor.Unparent( );
680   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
681
682   END_TEST;
683 }
684
685 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
686 {
687   ToolkitTestApplication application;
688   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
689
690   VisualFactory factory = VisualFactory::Get();
691   DALI_TEST_CHECK( factory );
692
693   // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
694   const int width=600;
695   const int height=600;
696   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
697
698   Property::Map propertyMap;
699   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
700   propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
701   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
702   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
703   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
704   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
705   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
706   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
707
708   Visual::Base visual = factory.CreateVisual( propertyMap );
709   DALI_TEST_CHECK( visual );
710
711   TestGlAbstraction& gl = application.GetGlAbstraction();
712   TraceCallStack& textureTrace = gl.GetTextureTrace();
713   textureTrace.Enable(true);
714   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
715   texParameterTrace.Enable( true );
716
717   DummyControl actor = DummyControl::New();
718   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
719   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
720   actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
721   actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
722   Stage::GetCurrent().Add( actor );
723
724   // loading started
725   application.SendNotification();
726   application.Render();
727
728   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
729
730   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
731
732   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
733   std::stringstream out;
734   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
735   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
736   out.str("");
737   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
738   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
739
740   // test the uniforms which used to handle the wrap mode
741   Renderer renderer = actor.GetRendererAt( 0u );
742   DALI_TEST_CHECK( renderer );
743
744   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
745   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
746   Vector4 pixelAreaUniform;
747   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
748   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
749
750   Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
751   DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
752
753   actor.Unparent();
754   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
755
756   END_TEST;
757 }
758
759 int UtcDaliImageVisualAnimateMixColor(void)
760 {
761   ToolkitTestApplication application;
762   tet_infoline( "Animate mix color" );
763
764   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
765
766   VisualFactory factory = VisualFactory::Get();
767   Property::Map propertyMap;
768   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
769   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
770   propertyMap.Insert("mixColor", Color::BLUE);
771   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
772   Visual::Base visual = factory.CreateVisual( propertyMap );
773
774   DummyControl actor = DummyControl::New(true);
775   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
776   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
777
778   actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
779   actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
780   actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
781   Stage::GetCurrent().Add(actor);
782
783   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
784
785   Renderer renderer = actor.GetRendererAt(0);
786   Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
787   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
788   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
789
790   tet_infoline("Test that the renderer has the mixColor property");
791   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
792
793   const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
794
795   Property::Map map;
796   map["target"] = "testVisual";
797   map["property"] = "mixColor";
798   map["initialValue"] = Color::MAGENTA;
799   map["targetValue"] = TARGET_MIX_COLOR;
800   map["animator"] = Property::Map()
801     .Add("alphaFunction", "LINEAR")
802     .Add("timePeriod", Property::Map()
803          .Add("delay", 0.0f)
804          .Add("duration", 4.0f));
805
806   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
807
808   Animation animation = dummyImpl.CreateTransition( transition );
809
810   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
811   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
812
813   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
814   animation.Play();
815
816   application.SendNotification();
817   application.Render(0); // Ensure animation starts
818   application.Render(2000u); // Halfway point
819   Vector3 testColor( 1.0f, 0.0f, 0.5f );
820
821   // uColor.a should be actor's alpha * mixColor.a.
822   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
823   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
824
825   application.Render(2000u); // Halfway point between blue and white
826
827   DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::WHITE, TEST_LOCATION );
828   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
829   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
830
831   TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
832
833   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
834   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
835
836   END_TEST;
837 }
838
839 int UtcDaliImageVisualAnimateOpacity(void)
840 {
841   ToolkitTestApplication application;
842   tet_infoline( "Animate image visual opacity" );
843
844   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
845
846   VisualFactory factory = VisualFactory::Get();
847   Property::Map propertyMap;
848   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
849   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
850   propertyMap.Insert("opacity", 0.5f);
851   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
852   Visual::Base visual = factory.CreateVisual( propertyMap );
853
854   DummyControl actor = DummyControl::New(true);
855   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
856   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
857
858   actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
859   actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
860   actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
861   Stage::GetCurrent().Add(actor);
862
863   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
864
865   Renderer renderer = actor.GetRendererAt(0);
866   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
867   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
868
869   {
870     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." );
871
872     Property::Map map;
873     map["target"] = "testVisual";
874     map["property"] = "opacity";
875     map["targetValue"] = 1.0f;
876     map["animator"] = Property::Map()
877       .Add("alphaFunction", "LINEAR")
878       .Add("timePeriod", Property::Map()
879            .Add("delay", 0.0f)
880            .Add("duration", 4.0f));
881
882     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
883     Animation animation = dummyImpl.CreateTransition( transition );
884     animation.Play();
885
886     application.SendNotification();
887     application.Render(0);     // Ensure animation starts
888     application.Render(2000u); // Halfway point through animation
889     application.SendNotification(); // Handle any signals
890
891     Vector4 color;
892     DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
893     DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
894
895     application.Render(2001u); // end
896     application.SendNotification(); // ensure animation finished signal is sent
897
898     DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
899     DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
900
901     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
902     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
903   }
904
905
906   {
907     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." );
908
909     Property::Map map;
910     map["target"] = "testVisual";
911     map["property"] = Visual::Property::OPACITY;
912     map["targetValue"] = 0.1f;
913     map["animator"] = Property::Map()
914       .Add("alphaFunction", "LINEAR")
915       .Add("timePeriod", Property::Map()
916            .Add("delay", 0.0f)
917            .Add("duration", 4.0f));
918
919     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
920     Animation animation = dummyImpl.CreateTransition( transition );
921     animation.Play();
922
923     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
924     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
925
926     application.SendNotification();
927     application.Render(0);     // Ensure animation starts
928     application.Render(2000u); // Halfway point
929     application.SendNotification();
930
931     Vector4 color;
932     DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
933     DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
934
935     application.Render(2016u); // end
936     application.SendNotification();
937
938     DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
939     DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
940
941     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
942     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
943   }
944
945
946   END_TEST;
947 }
948
949
950
951 int UtcDaliImageVisualAnimateOpacity02(void)
952 {
953   ToolkitTestApplication application;
954   tet_infoline( "Animate image visual opacity" );
955
956   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
957
958   VisualFactory factory = VisualFactory::Get();
959   Property::Map propertyMap;
960   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
961   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
962   propertyMap.Insert("opacity", 0.5f);
963   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
964   Visual::Base visual = factory.CreateVisual( propertyMap );
965
966   DummyControl actor = DummyControl::New(true);
967   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
968   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
969
970   actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
971   actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
972   actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
973
974   tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
975
976   Property::Array array;
977
978   Property::Map map;
979   map["target"] = "testVisual";
980   map["property"] = "opacity";
981   map["initialValue"] = 0.0f;
982   map["targetValue"] = 1.0f;
983   map["animator"] = Property::Map()
984     .Add("alphaFunction", "LINEAR")
985     .Add("timePeriod", Property::Map()
986          .Add("delay", 0.0f)
987          .Add("duration", 4.0f));
988
989   Property::Map map2;
990   map2["target"] = "testVisual";
991   map2["property"] = "size";
992   map2["targetValue"] = Vector2(1.0f, 1.0f);
993
994   array.Add( map ).Add(map2);
995
996   Dali::Toolkit::TransitionData transition = TransitionData::New( array );
997   Animation animation = dummyImpl.CreateTransition( transition );
998
999   Stage::GetCurrent().Add(actor);
1000   application.SendNotification();
1001   application.Render(0);     // Ensure animation starts
1002
1003   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1004
1005   Renderer renderer = actor.GetRendererAt(0);
1006   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1007   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
1008
1009   animation = dummyImpl.CreateTransition( transition );
1010   animation.Play();
1011
1012   application.SendNotification();
1013   application.Render(0);     // Ensure animation starts
1014   application.Render(2000u); // Halfway point through animation
1015   application.SendNotification(); // Handle any signals
1016
1017   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1018   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
1019
1020   Vector4 color;
1021   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1022   DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
1023
1024   application.Render(2001u); // end
1025   application.SendNotification(); // ensure animation finished signal is sent
1026
1027   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1028   DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1029
1030   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1031   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
1032
1033   END_TEST;
1034 }
1035
1036
1037
1038 int UtcDaliImageVisualAnimatePixelArea(void)
1039 {
1040   ToolkitTestApplication application;
1041   tet_infoline( "ImageVisual animate pixel area" );
1042
1043   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1044
1045   VisualFactory factory = VisualFactory::Get();
1046   Property::Map propertyMap;
1047   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
1048   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1049   propertyMap.Insert("mixColor", Color::BLUE);
1050   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1051   Visual::Base visual = factory.CreateVisual( propertyMap );
1052
1053   DummyControl actor = DummyControl::New(true);
1054   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1055   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1056
1057   actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1058   actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1059   actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1060   Stage::GetCurrent().Add(actor);
1061
1062   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1063
1064   Renderer renderer = actor.GetRendererAt(0);
1065   Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
1066
1067   tet_infoline("Test that the renderer has the mixColor property");
1068   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1069
1070   // TransitionData only takes string keys
1071   Property::Map map;
1072   map["target"] = "testVisual";
1073   map["property"] = "pixelArea";
1074   map["initialValue"] = Vector4( 0,0,0,1 );
1075   map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1076   map["animator"] = Property::Map()
1077     .Add("alphaFunction", "LINEAR")
1078     .Add("timePeriod", Property::Map()
1079          .Add("delay", 0.0f)
1080          .Add("duration", 4.0f));
1081
1082   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1083
1084   Animation animation = dummyImpl.CreateTransition( transition );
1085   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1086   animation.Play();
1087
1088   application.SendNotification();
1089   application.Render(0);     // Ensure animation starts
1090   application.Render(2000u); // Halfway point
1091
1092   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1093
1094   application.Render(2000u); // End of animation
1095
1096   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1097
1098   END_TEST;
1099 }
1100
1101 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1102 {
1103   ToolkitTestApplication application;
1104   tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1105
1106   Property::Map propertyMap;
1107   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1108   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1109
1110   TestGlAbstraction& gl = application.GetGlAbstraction();
1111   TraceCallStack& textureTrace = gl.GetTextureTrace();
1112   textureTrace.Enable(true);
1113   TraceCallStack& drawTrace = gl.GetDrawTrace();
1114   drawTrace.Enable(true);
1115
1116   Actor actor = CreateActorWithImageVisual( propertyMap );
1117   Stage::GetCurrent().Add( actor );
1118   application.SendNotification();
1119
1120   Stage::GetCurrent().Remove( actor );
1121   application.SendNotification();
1122
1123   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1124   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1125   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1126   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1127
1128   END_TEST;
1129 }
1130
1131 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1132 {
1133   ToolkitTestApplication application;
1134   tet_infoline( "Load image asynchronosly, cancel loading, then load again" );
1135
1136   VisualFactory factory = VisualFactory::Get();
1137   DALI_TEST_CHECK( factory );
1138
1139   Property::Map propertyMap;
1140   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1141   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1142
1143   Visual::Base visual = factory.CreateVisual( propertyMap );
1144   DALI_TEST_CHECK( visual );
1145
1146   TestGlAbstraction& gl = application.GetGlAbstraction();
1147   TraceCallStack& textureTrace = gl.GetTextureTrace();
1148   textureTrace.Enable( true );
1149   TraceCallStack& drawTrace = gl.GetDrawTrace();
1150   drawTrace.Enable( true );
1151
1152   DummyControl actor = DummyControl::New();
1153   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1154   dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1155
1156   Stage::GetCurrent().Add( actor );
1157
1158   // Cancel loading
1159   Stage::GetCurrent().Remove( actor );
1160
1161   Stage::GetCurrent().Add( actor );
1162
1163   // Create another visual with the same image
1164   visual = factory.CreateVisual( propertyMap );
1165   DALI_TEST_CHECK( visual );
1166
1167   dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1168
1169   application.SendNotification();
1170   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1171
1172   application.SendNotification();
1173   application.Render();
1174
1175   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1176   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1177   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1178   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1179
1180   END_TEST;
1181 }
1182
1183 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1184 {
1185   ToolkitTestApplication application;
1186   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1187
1188   VisualFactory factory = VisualFactory::Get();
1189   DALI_TEST_CHECK( factory );
1190
1191   Property::Map propertyMap;
1192   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1193   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1194
1195   Visual::Base visual = factory.CreateVisual( propertyMap );
1196   DALI_TEST_CHECK( visual );
1197
1198   TestGlAbstraction& gl = application.GetGlAbstraction();
1199   TraceCallStack& textureTrace = gl.GetTextureTrace();
1200   textureTrace.Enable(true);
1201
1202   DummyControl actor = DummyControl::New();
1203   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1204   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1205
1206   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1207   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1208
1209   Stage::GetCurrent().Add( actor );
1210
1211   application.SendNotification();
1212   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1213
1214   application.SendNotification();
1215   application.Render();
1216
1217   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1218   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1219
1220   Stage::GetCurrent().Remove( actor );
1221   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1222
1223   END_TEST;
1224 }
1225
1226 int UtcDaliImageVisualSetInvalidSyncImage(void)
1227 {
1228   ToolkitTestApplication application;
1229   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1230
1231   VisualFactory factory = VisualFactory::Get();
1232   DALI_TEST_CHECK( factory );
1233
1234   Property::Map propertyMap;
1235   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1236   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1237   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1238
1239   Visual::Base visual = factory.CreateVisual( propertyMap );
1240   DALI_TEST_CHECK( visual );
1241
1242   TestGlAbstraction& gl = application.GetGlAbstraction();
1243   TraceCallStack& textureTrace = gl.GetTextureTrace();
1244   textureTrace.Enable(true);
1245
1246   DummyControl actor = DummyControl::New();
1247   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1248   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1249
1250   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1251   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1252
1253   Stage::GetCurrent().Add( actor );
1254
1255   application.SendNotification();
1256   application.Render();
1257
1258   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1259   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1260
1261   Stage::GetCurrent().Remove( actor );
1262   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1263
1264   END_TEST;
1265 }
1266
1267 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1268 {
1269   ToolkitTestApplication application;
1270   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1271
1272   VisualFactory factory = VisualFactory::Get();
1273   DALI_TEST_CHECK( factory );
1274
1275   // Local invalid file, asynchronous loading
1276   Property::Map propertyMap;
1277   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1278   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1279
1280   Visual::Base visual = factory.CreateVisual( propertyMap );
1281   DALI_TEST_CHECK( visual );
1282
1283   TestGlAbstraction& gl = application.GetGlAbstraction();
1284   TraceCallStack& textureTrace = gl.GetTextureTrace();
1285   textureTrace.Enable(true);
1286
1287   DummyControl actor = DummyControl::New();
1288   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1289   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1290
1291   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1292   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1293
1294   Stage::GetCurrent().Add( actor );
1295
1296   application.SendNotification();
1297   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1298
1299   application.SendNotification();
1300   application.Render();
1301
1302   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1303   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1304
1305   Stage::GetCurrent().Remove( actor );
1306   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1307
1308   END_TEST;
1309 }
1310
1311 int UtcDaliImageVisualAlphaMask(void)
1312 {
1313   ToolkitTestApplication application;
1314   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1315
1316   VisualFactory factory = VisualFactory::Get();
1317   DALI_TEST_CHECK( factory );
1318
1319   Property::Map propertyMap;
1320   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1321   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
1322   propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1323
1324   Visual::Base visual = factory.CreateVisual( propertyMap );
1325   DALI_TEST_CHECK( visual );
1326
1327   Property::Map testMap;
1328   visual.CreatePropertyMap(testMap);
1329   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1330
1331   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1332   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1333
1334   TestGlAbstraction& gl = application.GetGlAbstraction();
1335   TraceCallStack& textureTrace = gl.GetTextureTrace();
1336   textureTrace.Enable(true);
1337
1338   DummyControl actor = DummyControl::New();
1339   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1340   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1341
1342   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1343   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1344   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1345
1346   Stage::GetCurrent().Add( actor );
1347   application.SendNotification();
1348   application.Render();
1349
1350   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1351
1352   application.SendNotification();
1353   application.Render();
1354
1355   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1356   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1357   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1358
1359   dummyImpl.UnregisterVisual(  Control::CONTROL_PROPERTY_END_INDEX + 1 );
1360   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1361
1362   END_TEST;
1363 }
1364
1365 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1366 {
1367   ToolkitTestApplication application;
1368   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" );
1369
1370   VisualFactory factory = VisualFactory::Get();
1371   DALI_TEST_CHECK( factory );
1372
1373   Property::Map propertyMap;
1374   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1375   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
1376   propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1377   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1378
1379   Visual::Base visual = factory.CreateVisual( propertyMap );
1380   DALI_TEST_CHECK( visual );
1381
1382   Property::Map testMap;
1383   visual.CreatePropertyMap(testMap);
1384   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1385
1386   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1387   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1388
1389   TestGlAbstraction& gl = application.GetGlAbstraction();
1390   TraceCallStack& textureTrace = gl.GetTextureTrace();
1391   textureTrace.Enable(true);
1392
1393   DummyControl actor = DummyControl::New();
1394   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1395   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1396
1397   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1398   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1399   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1400
1401   Stage::GetCurrent().Add( actor );
1402
1403   // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1404
1405   application.SendNotification();
1406   application.Render();
1407
1408   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1409   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1410   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1411
1412   dummyImpl.UnregisterVisual(  Control::CONTROL_PROPERTY_END_INDEX + 1 );
1413   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1414
1415   END_TEST;
1416 }
1417
1418 int UtcDaliImageVisualRemoteAlphaMask(void)
1419 {
1420   ToolkitTestApplication application;
1421   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1422
1423   VisualFactory factory = VisualFactory::Get();
1424   DALI_TEST_CHECK( factory );
1425
1426   const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1427
1428   Property::Map propertyMap;
1429   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1430   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
1431   propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE );
1432
1433   Visual::Base visual = factory.CreateVisual( propertyMap );
1434   DALI_TEST_CHECK( visual );
1435
1436   Property::Map testMap;
1437   visual.CreatePropertyMap(testMap);
1438
1439   DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1440
1441   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1442   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1443
1444   TestGlAbstraction& gl = application.GetGlAbstraction();
1445   TraceCallStack& textureTrace = gl.GetTextureTrace();
1446   textureTrace.Enable(true);
1447
1448   DummyControl actor = DummyControl::New();
1449   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1450   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1451
1452   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1453
1454   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1455   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1456
1457   Stage::GetCurrent().Add( actor );
1458   application.SendNotification();
1459   application.Render();
1460
1461   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1462
1463   application.SendNotification();
1464   application.Render();
1465
1466   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1467   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1468   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1469
1470   END_TEST;
1471 }
1472
1473 int UtcDaliImageVisualAlphaMaskCrop(void)
1474 {
1475   ToolkitTestApplication application;
1476   tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1477
1478   VisualFactory factory = VisualFactory::Get();
1479   DALI_TEST_CHECK( factory );
1480
1481   Property::Map propertyMap;
1482   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
1483   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
1484   propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1485   propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1486   propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1487
1488   Visual::Base visual = factory.CreateVisual( propertyMap );
1489   DALI_TEST_CHECK( visual );
1490
1491   Property::Map testMap;
1492   visual.CreatePropertyMap(testMap);
1493   DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1494   DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1495   DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1496
1497   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1498   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1499
1500   TestGlAbstraction& gl = application.GetGlAbstraction();
1501   TraceCallStack& textureTrace = gl.GetTextureTrace();
1502   textureTrace.Enable(true);
1503
1504   DummyControl actor = DummyControl::New();
1505   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1506   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1507
1508   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1509   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1510   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1511
1512   Stage::GetCurrent().Add( actor );
1513   application.SendNotification();
1514   application.Render();
1515
1516   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1517
1518   application.SendNotification();
1519   application.Render();
1520
1521   Vector2 size;
1522   visual.GetNaturalSize(size);
1523
1524   DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1525   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1526   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1527   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1528
1529   END_TEST;
1530 }
1531
1532 int UtcDaliImageVisualReleasePolicy01(void)
1533 {
1534   ToolkitTestApplication application;
1535   tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1536
1537   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1538   DALI_TEST_CHECK( imageVisual );
1539
1540   // Set up debug trace
1541   TestGlAbstraction& gl = application.GetGlAbstraction();
1542   TraceCallStack& textureTrace = gl.GetTextureTrace();
1543   textureTrace.Enable(true);
1544
1545   tet_infoline( "Register visual with control and ensure it has the only handle" );
1546   DummyControl actor = DummyControl::New(true);
1547   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1548   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1549   imageVisual.Reset();
1550
1551   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1552
1553   application.SendNotification();
1554   application.Render(0);
1555   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1556   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1557
1558   Stage::GetCurrent().Add( actor );
1559
1560   // Wait for image to load
1561   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1562
1563   application.SendNotification();
1564   application.Render(0);
1565   // Test renderer and texture created
1566   tet_infoline( "Confirm texture created" );
1567   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1568   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1569
1570   tet_infoline( "Disable visual causing the texture to be deleted" );
1571   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1572
1573   application.SendNotification();
1574   application.Render(0);
1575   // Test renderer and textures removed.
1576   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1577   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1578
1579   END_TEST;
1580 }
1581
1582 int UtcDaliImageVisualReleasePolicy02(void)
1583 {
1584   ToolkitTestApplication application;
1585   tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1586
1587   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1588   DALI_TEST_CHECK( imageVisual );
1589
1590   // Setup debug trace
1591   TestGlAbstraction& gl = application.GetGlAbstraction();
1592   TraceCallStack& textureTrace = gl.GetTextureTrace();
1593   textureTrace.Enable(true);
1594
1595   tet_infoline( "Register visual with control and ensure it has the only handle" );
1596   DummyControl actor = DummyControl::New(true);
1597   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1598   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1599   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1600
1601   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1602
1603   application.SendNotification();
1604   application.Render(0);
1605   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1606   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1607
1608   Stage::GetCurrent().Add( actor );
1609
1610   // Wait for image to load
1611   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1612
1613   application.SendNotification();
1614   application.Render(0);
1615   // Test renderer and texture created
1616   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1617   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1618
1619
1620   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1621   tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1622   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1623   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1624   application.SendNotification();
1625   application.Render();
1626
1627   // Test texture removed after visual destroyed.
1628   tet_infoline( "Ensure texture is deleted after visual destroyed" );
1629   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1630
1631   END_TEST;
1632 }
1633
1634 int UtcDaliImageVisualReleasePolicy03(void)
1635 {
1636   ToolkitTestApplication application;
1637   tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1638
1639   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1640   DALI_TEST_CHECK( imageVisual );
1641
1642   TestGlAbstraction& gl = application.GetGlAbstraction();
1643   TraceCallStack& textureTrace = gl.GetTextureTrace();
1644   textureTrace.Enable(true);
1645
1646   tet_infoline( "Register visual with control and ensure it has the only handle" );
1647   DummyControl actor = DummyControl::New(true);
1648   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1649   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1650   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1651
1652   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1653
1654   application.SendNotification();
1655   application.Render(0);
1656   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1657   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1658
1659   Stage::GetCurrent().Add( actor );
1660
1661   // Wait for image to load
1662   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1663
1664   application.SendNotification();
1665   application.Render(0);
1666   // Test renderer and texture created
1667   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1668   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1669
1670   tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1671   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1672   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1673   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1674   application.SendNotification();
1675   application.Render();
1676
1677   tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1678   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1679
1680   END_TEST;
1681 }
1682
1683 int UtcDaliImageVisualReleasePolicy04(void)
1684 {
1685   ToolkitTestApplication application;
1686   tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1687
1688   tet_infoline( "Create first visual with Never release policy" );
1689   Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1690
1691   tet_infoline( "Create second visual with Destroyed release policy");
1692     Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1693
1694   // Set up trace debug
1695   TestGlAbstraction& gl = application.GetGlAbstraction();
1696   TraceCallStack& textureTrace = gl.GetTextureTrace();
1697   textureTrace.Enable(true);
1698
1699   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1700   DummyControl actor = DummyControl::New(true);
1701   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1702   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1703   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1704   imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1705   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1706
1707   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1708
1709   // Test initially zero renderers
1710   application.SendNotification();
1711   application.Render(0);
1712   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1713   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1714
1715   Stage::GetCurrent().Add( actor );
1716
1717   // Wait for image to load
1718   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1719
1720   application.SendNotification();
1721   application.Render(0);
1722   tet_infoline( "Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer" );
1723   DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1724   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1725
1726   // Test renderer removed when visual destroyed
1727   DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1728   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 );  // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1729   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1730   application.SendNotification();
1731   application.Render();
1732
1733   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1734   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1735
1736   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1737   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1738   application.SendNotification();
1739   application.Render();
1740
1741   tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1742   // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1743   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1744
1745   END_TEST;
1746 }
1747
1748 int UtcDaliImageVisualReleasePolicy05(void)
1749 {
1750   ToolkitTestApplication application;
1751   tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1752
1753   VisualFactory factory = VisualFactory::Get();
1754
1755   Property::Map propertyMapNeverReleasePolicy;
1756   propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1757   propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
1758   propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH,   20 );
1759   propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT,   30 );
1760   propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1761
1762   Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1763
1764   Property::Map resultMap;
1765   imageVisualNever.CreatePropertyMap( resultMap );
1766   DALI_TEST_CHECK( ! resultMap.Empty() );
1767
1768   DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1769
1770   END_TEST;
1771 }
1772
1773 int UtcDaliImageVisualReleasePolicy06(void)
1774 {
1775   ToolkitTestApplication application;
1776   tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1777
1778   Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1779   DALI_TEST_CHECK( imageVisual );
1780
1781   TestGlAbstraction& gl = application.GetGlAbstraction();
1782   TraceCallStack& textureTrace = gl.GetTextureTrace();
1783   textureTrace.Enable(true);
1784
1785   tet_infoline( "Register visual with control and ensure it has the only handle" );
1786   DummyControl actor = DummyControl::New(true);
1787   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1788   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1789   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1790
1791   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1792
1793   application.SendNotification();
1794   application.Render(0);
1795   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1796   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1797
1798   Stage::GetCurrent().Add( actor );
1799
1800   // Wait for image to load
1801   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1802
1803   application.SendNotification();
1804   application.Render(0);
1805   // Test renderer and texture created
1806   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1807   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1808   textureTrace.Reset();
1809
1810   tet_infoline( "Disable Visual and check texture not affected" );
1811   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1812   application.SendNotification();
1813   application.Render(0);
1814   tet_infoline( "Check renderer is destroyed when visual off stage" );
1815   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1816   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1817   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1818   textureTrace.Reset();
1819
1820   tet_infoline( "Re-enable Visual and check texture not affected" );
1821   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1822   application.SendNotification();
1823   application.Render(0);
1824   tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1825   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1826   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1827   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1828
1829   END_TEST;
1830 }
1831
1832 int UtcDaliImageVisualReleasePolicy07(void)
1833 {
1834   ToolkitTestApplication application;
1835   tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1836
1837   tet_infoline( "Create first visual with DESTROYED release policy" );
1838   Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1839
1840
1841   tet_infoline( "Create second visual with DETACHED release policy");
1842   Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1843
1844   // Set up trace debug
1845   TestGlAbstraction& gl = application.GetGlAbstraction();
1846   TraceCallStack& textureTrace = gl.GetTextureTrace();
1847   textureTrace.Enable(true);
1848
1849   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1850   DummyControl actor = DummyControl::New(true);
1851   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1852   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1853   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1854   imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1855   imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1856
1857   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1858
1859   // Test initially zero renderers
1860   application.SendNotification();
1861   application.Render(0);
1862   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1863   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1864
1865   Stage::GetCurrent().Add( actor );
1866
1867   // Wait for image to load
1868   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1869
1870   application.SendNotification();
1871   application.Render(0);
1872   tet_infoline( "Ensure a texture is created, shared amongst both visuals.  Each visual has its own renderer" );
1873   DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1874   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1875
1876   // Test renderer removed when visual destroyed
1877   DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1878   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false );  // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1879   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1880   application.SendNotification();
1881   application.Render();
1882
1883   // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1884   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1885
1886   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1887   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1888   application.SendNotification();
1889   application.Render();
1890
1891   tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1892   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1893
1894   END_TEST;
1895 }
1896
1897 int UtcDaliImageVisualLoadPolicy01(void)
1898 {
1899   ToolkitTestApplication application;
1900   tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1901
1902   // Set up trace debug
1903   TestGlAbstraction& gl = application.GetGlAbstraction();
1904   TraceCallStack& textureTrace = gl.GetTextureTrace();
1905   textureTrace.Enable(true);
1906
1907   tet_infoline( "Create visual with IMMEDIATE load policy" );
1908   VisualFactory factory = VisualFactory::Get();
1909
1910   Property::Map propertyMap;
1911   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1912   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
1913   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH,   20 );
1914   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT,   30 );
1915   propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
1916
1917   Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1918
1919   Property::Map resultMap;
1920   imageVisual.CreatePropertyMap( resultMap );
1921   DALI_TEST_CHECK( ! resultMap.Empty() );
1922   DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
1923
1924   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1925
1926   // Ensure texture has been uploaded
1927   application.SendNotification();
1928   application.Render();
1929
1930   tet_infoline( "Ensure texture loading starts after visual created" );
1931   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1932   textureTrace.Reset();
1933
1934   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1935   DummyControl actor = DummyControl::New(true);
1936   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1937   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1938   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1939
1940   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1941   Stage::GetCurrent().Add( actor );
1942   tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
1943   const unsigned int TIME_OUT_3_SECONDS = 3;
1944   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1945
1946   application.SendNotification();
1947   application.Render();
1948
1949   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1950   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1951
1952   // Ensure texture is deleted when no longer needed (ref count was correct )
1953   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1954
1955   application.SendNotification();
1956   application.Render();
1957
1958   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1959   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1960
1961   END_TEST;
1962 }
1963
1964 int UtcDaliImageVisualLoadPolicy02(void)
1965 {
1966   ToolkitTestApplication application;
1967   tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
1968
1969   // Set up trace debug
1970   TestGlAbstraction& gl = application.GetGlAbstraction();
1971   TraceCallStack& textureTrace = gl.GetTextureTrace();
1972   textureTrace.Enable(true);
1973
1974   tet_infoline( "Create visual with IMMEDIATE load policy" );
1975   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
1976
1977   const unsigned int TIME_OUT_3_SECONDS = 3;
1978   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1979
1980   // Act on meeage queue even although nothing expected to load
1981   application.SendNotification();
1982   application.Render();
1983
1984   tet_infoline( "Ensure texture is not generated yet" );
1985   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1986   textureTrace.Reset();
1987
1988   tet_infoline( "Register visuals with control and ensure it has the only handles" );
1989   DummyControl actor = DummyControl::New(true);
1990   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1991   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1992   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1993
1994   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1995   Stage::GetCurrent().Add( actor );
1996   tet_infoline( "Allow image time to load" );
1997   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1998
1999   application.SendNotification();
2000   application.Render();
2001
2002   tet_infoline( "Ensure texture generated and renderer created" );
2003   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2004   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2005
2006   // Ensure texture is delete when no longer needed
2007   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2008
2009   application.SendNotification();
2010   application.Render();
2011
2012   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2013   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2014
2015   END_TEST;
2016 }
2017
2018 int UtcDaliImageVisualLoadPolicy03(void)
2019 {
2020   ToolkitTestApplication application;
2021   tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2022
2023   const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2024
2025   // Set up trace debug
2026   TestGlAbstraction& gl = application.GetGlAbstraction();
2027   TraceCallStack& textureTrace = gl.GetTextureTrace();
2028   textureTrace.Enable(true);
2029
2030   tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2031   DummyControl actor = DummyControl::New(true);
2032   actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2033   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2034   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2035
2036   tet_infoline( "Create visual with IMMEDIATE load policy" );
2037   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2038
2039   tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2040   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2041   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2042
2043   tet_infoline( "Allow image time to load resource" );
2044   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2045   application.SendNotification();
2046   application.Render();
2047
2048   // Ensure texture has been uploaded
2049   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2050   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2051
2052   END_TEST;
2053 }
2054
2055 int UtcDaliImageVisualLoadPolicy04(void)
2056 {
2057   ToolkitTestApplication application;
2058   tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part  Load a visual image before attaching to stage");
2059   tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2060
2061   const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2062
2063   // Set up trace debug
2064   TestGlAbstraction& gl = application.GetGlAbstraction();
2065   TraceCallStack& textureTrace = gl.GetTextureTrace();
2066   textureTrace.Enable(true);
2067
2068   tet_infoline( "Create a control and connect to resource ready signal" );
2069   DummyControl actor = DummyControl::New(true);
2070   actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2071   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2072   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2073
2074   tet_infoline( "Create visual with IMMEDIATE load policy" );
2075   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2076
2077   tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2078   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2079   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2080
2081   tet_infoline( "Allow image time to load" );
2082   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2083   application.SendNotification();
2084   application.Render();
2085
2086   tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2087   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2088   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2089
2090   tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2091
2092   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2093   Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2094   DummyControl actor2 = DummyControl::New(true);
2095   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2096   actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2097
2098   tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2099   dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2100   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2101   actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2102   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2103   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2104
2105   END_TEST;
2106 }
2107
2108 int UtcDaliImageVisualLoadPolicy05(void)
2109 {
2110   ToolkitTestApplication application;
2111   tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part  Load a visual image before attaching to stage");
2112   tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2113   // Set up trace debug
2114   TestGlAbstraction& gl = application.GetGlAbstraction();
2115   TraceCallStack& textureTrace = gl.GetTextureTrace();
2116   textureTrace.Enable(true);
2117
2118   tet_infoline( "Create a control and connect to resource ready signal" );
2119   DummyControl actor = DummyControl::New(true);
2120   actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2121   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2122   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2123   Stage::GetCurrent().Add( actor );
2124
2125   tet_infoline( "Create visual with ATTACHED load policy" );
2126   Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2127
2128   tet_infoline( "Registering visual allows control to get a signal once loaded" );
2129   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2130   imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2131
2132   tet_infoline( "Allow image time to load" );
2133   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2134   application.SendNotification();
2135   application.Render();
2136
2137   tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2138   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2139   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2140
2141   tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2142
2143   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2144   Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2145   DummyControl actor2 = DummyControl::New(true);
2146   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2147   actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2148
2149   tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2150   dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2151   imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2152   actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2153   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2154   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2155
2156   END_TEST;
2157 }
2158
2159
2160 int UtcDaliImageVisualOrientationCorrection(void)
2161 {
2162   ToolkitTestApplication application;
2163   tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2164
2165   VisualFactory factory = VisualFactory::Get();
2166   tet_infoline( "Create visual with Orientation correction set OFF" );
2167   Property::Map propertyMap;
2168   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
2169   propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2170   propertyMap.Insert( "orientationCorrection", false );
2171   Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2172
2173   tet_infoline( "Create control for visual, need to loaded it" );
2174   DummyControl actor = DummyControl::New(true);
2175   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2176   Stage::GetCurrent().Add( actor );
2177
2178   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2179   // Wait for image to load
2180   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2181
2182   Vector2 originalImageSize;
2183   tet_infoline( "Get size of original visual to compare later with rotated image" );
2184   imageVisual.GetNaturalSize( originalImageSize );
2185   DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2186   imageVisual.Reset();  // remove handle so can unregister it and remove from cache
2187   dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2188   application.SendNotification();
2189   application.Render();
2190
2191   tet_infoline( "Create visual with Orientation correction set ON " );
2192   propertyMap.Clear();
2193   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
2194   propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2195   propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2196   imageVisual = factory.CreateVisual( propertyMap );
2197
2198   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2199   // Wait for image to load
2200   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2201
2202   Vector2 rotatedImageSize;
2203   imageVisual.GetNaturalSize( rotatedImageSize );
2204   tet_infoline( "Confirm that visual has rotated" );
2205   DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2206   DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2207
2208   Property::Map resultMap;
2209   imageVisual.CreatePropertyMap( resultMap );
2210
2211   // check the Property::ORIENTATION_CORRECTION value from the returned map
2212   Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION,  Property::BOOLEAN );
2213   DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2214
2215   END_TEST;
2216 }
2217
2218 int UtcDaliImageVisualCustomShader(void)
2219 {
2220   ToolkitTestApplication application;
2221   tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2222
2223   VisualFactory factory = VisualFactory::Get();
2224   Property::Map properties;
2225   Property::Map shader;
2226   const std::string vertexShader = "Foobar";
2227   const std::string fragmentShader = "Foobar";
2228   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2229   shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2230
2231   properties[Visual::Property::TYPE] = Visual::IMAGE;
2232   properties[Visual::Property::SHADER] = shader;
2233   properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2234
2235   Visual::Base visual = factory.CreateVisual( properties );
2236
2237   // trigger creation through setting on stage
2238   DummyControl dummy = DummyControl::New( true );
2239   Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2240   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2241
2242   dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2243   dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2244   Stage::GetCurrent().Add( dummy );
2245
2246   application.SendNotification();
2247   application.Render();
2248
2249   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2250
2251   Renderer renderer = dummy.GetRendererAt( 0 );
2252   Shader shader2 = renderer.GetShader();
2253   Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2254   Property::Map* map = value.GetMap();
2255   DALI_TEST_CHECK( map );
2256
2257   Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2258   DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2259
2260   Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2261   DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2262
2263   shader.Clear();
2264
2265   shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2266   properties[Visual::Property::SHADER] = shader;
2267
2268   Visual::Base visual1 = factory.CreateVisual( properties );
2269
2270   // trigger creation through setting on stage
2271   DummyControl dummy1 = DummyControl::New( true );
2272   Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2273   dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2274   dummy1.SetProperty( Actor::Property::SIZE, Vector2( 200, 200 ) );
2275   dummy1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2276   Stage::GetCurrent().Add( dummy1 );
2277
2278   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2279   glAbstraction.EnableEnableDisableCallTrace( true );
2280
2281   application.SendNotification();
2282   application.Render();
2283
2284   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2285   std::ostringstream blendStr;
2286   blendStr << GL_BLEND;
2287   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
2288
2289   END_TEST;
2290 }
2291
2292
2293 void ResourceReadyLoadNext( Control control )
2294 {
2295   static int callNumber = 0;
2296
2297   gResourceReadySignalFired = true;
2298   gReadyIds.push_back(control.GetId());
2299
2300   if( callNumber == 0 )
2301   {
2302     DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2303
2304     tet_infoline( "Create visual with loaded image from within the signal handler" );
2305     VisualFactory factory = VisualFactory::Get();
2306     Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2307
2308     Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2309     controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2310     callNumber = 1;
2311   }
2312   else
2313   {
2314     tet_infoline( "3rd signal called" );
2315     DALI_TEST_CHECK(true);
2316   }
2317 }
2318
2319 int UtcDaliImageVisualLoadReady01(void)
2320 {
2321   ToolkitTestApplication application;
2322   tet_infoline( "UtcDaliImageVisualLoadReady01");
2323   tet_infoline( "First part:  Load an image visual for one resource, then another image visual for a second resource.");
2324   tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2325   tet_infoline( "Should get a ready signal for all three visuals");
2326
2327   ClearReadyIds();
2328
2329   tet_infoline( "Create a control and connect to resource ready signal" );
2330   DummyControl actor = DummyControl::New(true);
2331   int actor1Id = actor.GetId();
2332   actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2333   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2334   actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2335   Stage::GetCurrent().Add(actor);
2336
2337   tet_infoline( "Create visual with IMMEDIATE load policy" );
2338   Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2339
2340   tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2341   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2342
2343
2344   tet_infoline( "Allow image time to load" );
2345   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2346   application.SendNotification();
2347   application.Render();
2348
2349   tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2350   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2351   DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2352
2353
2354   tet_infoline( "Original control correctly signalled, now testing failing image" );
2355
2356   gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2357   ClearReadyIds();
2358
2359   Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2360
2361   DummyControl actor2 = DummyControl::New(true);
2362   int actor2Id = actor2.GetId();
2363   Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2364   actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2365
2366   tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2367   dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2368
2369   actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2370   Stage::GetCurrent().Add(actor2);
2371
2372   tet_infoline( "Wait for loading thread to finish");
2373   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2374   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2375
2376   DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2377
2378   tet_infoline( "Check for 3rd signal");
2379   application.SendNotification();
2380   DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2381   DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);
2382
2383   END_TEST;
2384 }