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