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