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