3 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-timer.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.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/devel-api/visuals/animated-image-visual-actions-devel.h>
28 #include "dummy-control.h"
31 using namespace Dali::Toolkit;
33 void dali_animated_image_visual_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_animated_image_visual_cleanup(void)
40 test_return_value = TET_PASS;
45 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-%02d.png";
46 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
50 void CopyUrlsIntoArray( Property::Array& urls, int startIndex=0 )
52 for( int i=20+startIndex;i<=30;++i)
55 if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
57 Property::Value value(url);
64 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
66 ToolkitTestApplication application;
67 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
69 // request AnimatedImageVisual with a property map
70 VisualFactory factory = VisualFactory::Get();
71 Visual::Base animatedImageVisual = factory.CreateVisual(
73 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
74 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
75 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
76 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
77 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT ));
79 Property::Map resultMap;
80 animatedImageVisual.CreatePropertyMap( resultMap );
81 // check the property values from the returned map from a visual
82 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
83 DALI_TEST_CHECK( value );
84 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
86 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
87 DALI_TEST_CHECK( value );
88 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
90 // request AnimatedImageVisual with an URL
91 Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
93 animatedImageVisual2.CreatePropertyMap( resultMap );
94 // check the property values from the returned map from a visual
95 value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
96 DALI_TEST_CHECK( value );
97 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
99 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
100 DALI_TEST_CHECK( value );
101 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
107 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
109 ToolkitTestApplication application;
110 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap for multi image" );
112 // request AnimatedImageVisual with a property map
113 VisualFactory factory = VisualFactory::Get();
114 Property::Array urls;
115 CopyUrlsIntoArray( urls );
117 Visual::Base animatedImageVisual = factory.CreateVisual(
119 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
121 .Add( "batchSize", 4 )
122 .Add( "cacheSize", 8 )
123 .Add( "loopCount", 10 )
124 .Add( "frameDelay", 200 )
125 .Add( "pixelArea", Vector4() )
126 .Add( "wrapModeU", WrapMode::REPEAT )
127 .Add( "wrapModeV", WrapMode::DEFAULT ));
129 Property::Map resultMap;
130 animatedImageVisual.CreatePropertyMap( resultMap );
131 // check the property values from the returned map from a visual
132 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
133 DALI_TEST_CHECK( value );
134 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
136 value = resultMap.Find( ImageVisual::Property::URL, "url" );
137 DALI_TEST_CHECK( value );
138 Property::Array* resultUrls = value->GetArray();
139 DALI_TEST_CHECK( resultUrls );
140 DALI_TEST_EQUALS( resultUrls->Count(), urls.Count(), TEST_LOCATION );
142 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
143 DALI_TEST_CHECK( value );
144 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
146 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
147 DALI_TEST_CHECK( value );
148 DALI_TEST_EQUALS( value->Get<int>(), 8, TEST_LOCATION );
150 value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
151 DALI_TEST_CHECK( value );
152 DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
154 value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
155 DALI_TEST_CHECK( value );
156 DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
161 int UtcDaliAnimatedImageVisualGetPropertyMap03(void)
163 ToolkitTestApplication application;
164 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
166 // request AnimatedImageVisual with a property map
167 VisualFactory factory = VisualFactory::Get();
168 Visual::Base animatedImageVisual = factory.CreateVisual(
170 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
171 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
172 .Add( ImageVisual::Property::BATCH_SIZE, 1 )
173 .Add( ImageVisual::Property::CACHE_SIZE, 1 )
174 .Add( ImageVisual::Property::SYNCHRONOUS_LOADING, false ));
176 Property::Map resultMap;
177 animatedImageVisual.CreatePropertyMap( resultMap );
179 // check the property values from the returned map from a visual
180 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
181 DALI_TEST_CHECK( value );
182 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
184 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
185 DALI_TEST_CHECK( value );
186 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
188 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, Property::INTEGER );
189 DALI_TEST_CHECK( value );
190 DALI_TEST_CHECK( value->Get<int>() == 2 );
192 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, Property::INTEGER );
193 DALI_TEST_CHECK( value );
194 DALI_TEST_CHECK( value->Get<int>() == 2 );
200 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
202 ToolkitTestApplication application;
203 TestGlAbstraction& gl = application.GetGlAbstraction();
206 Property::Map propertyMap;
207 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
208 propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
209 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
210 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2);
211 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
212 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true);
214 VisualFactory factory = VisualFactory::Get();
215 Visual::Base visual = factory.CreateVisual( propertyMap );
217 DummyControl dummyControl = DummyControl::New(true);
218 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
219 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
221 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
222 Stage::GetCurrent().Add( dummyControl );
224 TraceCallStack& textureTrace = gl.GetTextureTrace();
225 textureTrace.Enable(true);
227 application.SendNotification();
228 application.Render(20);
230 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
232 application.SendNotification();
233 application.Render();
235 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
236 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
238 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3 );
240 application.SendNotification();
241 application.Render(20);
243 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
245 application.SendNotification();
246 application.Render();
248 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
250 dummyControl.Unparent();
252 tet_infoline("Test that removing the visual from stage deletes all textures");
253 application.SendNotification();
254 application.Render(16);
255 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
261 int UtcDaliAnimatedImageVisualJumpToAction(void)
263 ToolkitTestApplication application;
264 TestGlAbstraction& gl = application.GetGlAbstraction();
266 Property::Array urls;
267 CopyUrlsIntoArray( urls );
270 Property::Map propertyMap;
271 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
272 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
273 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
274 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 12);
275 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
277 VisualFactory factory = VisualFactory::Get();
278 Visual::Base visual = factory.CreateVisual( propertyMap );
280 DummyControl dummyControl = DummyControl::New(true);
281 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
282 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
284 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
285 Stage::GetCurrent().Add( dummyControl );
286 application.SendNotification();
287 application.Render(20);
289 tet_infoline( "Ready the visual after the visual is on stage" );
290 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
292 tet_infoline( "Test that a timer has been started" );
293 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
295 TraceCallStack& textureTrace = gl.GetTextureTrace();
296 textureTrace.Enable(true);
298 application.SendNotification();
299 application.Render(20);
301 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
303 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
305 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
307 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20 );
309 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
311 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
313 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
314 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
316 dummyControl.Unparent();
318 tet_infoline("Test that removing the visual from stage deletes all textures");
319 application.SendNotification();
320 application.Render(16);
321 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
327 int UtcDaliAnimatedImageVisualStopBehavior(void)
329 ToolkitTestApplication application;
330 TestGlAbstraction& gl = application.GetGlAbstraction();
332 Property::Array urls;
333 CopyUrlsIntoArray( urls );
336 Property::Map propertyMap;
337 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
338 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
339 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
340 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
341 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
342 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
344 VisualFactory factory = VisualFactory::Get();
345 Visual::Base visual = factory.CreateVisual( propertyMap );
347 // Expect that a batch of 4 textures has been requested. These will be serially loaded
350 DummyControl dummyControl = DummyControl::New(true);
351 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
352 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
354 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
355 Stage::GetCurrent().Add( dummyControl );
356 application.SendNotification();
357 application.Render(20);
359 tet_infoline( "Ready the visual after the visual is on stage" );
360 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
362 tet_infoline( "Test that a timer has been started" );
363 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
365 TraceCallStack& textureTrace = gl.GetTextureTrace();
366 textureTrace.Enable(true);
368 application.SendNotification();
369 application.Render(20);
371 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
373 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
375 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
377 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1 );
379 // Expect the second batch has been requested
380 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
382 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
384 dummyControl.Unparent();
386 tet_infoline("Test that removing the visual from stage deletes all textures");
387 application.SendNotification();
388 application.Render(16);
389 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
395 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
397 ToolkitTestApplication application;
398 TestGlAbstraction& gl = application.GetGlAbstraction();
401 Property::Map propertyMap;
402 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
403 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
404 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
405 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 4);
406 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
408 VisualFactory factory = VisualFactory::Get();
409 Visual::Base visual = factory.CreateVisual( propertyMap );
411 // Expect that a batch of 4 textures has been requested. These will be serially loaded
414 DummyControl dummyControl = DummyControl::New(true);
415 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
416 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
418 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
419 Stage::GetCurrent().Add( dummyControl );
421 application.SendNotification();
422 application.Render();
424 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
426 application.SendNotification();
427 application.Render(20);
429 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
431 tet_infoline( "Test that a timer has been started" );
433 TraceCallStack& textureTrace = gl.GetTextureTrace();
434 textureTrace.Enable(true);
436 Test::EmitGlobalTimerSignal();
438 application.SendNotification();
439 application.Render();
441 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
443 application.SendNotification();
444 application.Render(20);
446 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
448 dummyControl.Unparent();
450 tet_infoline("Test that removing the visual from stage deletes all textures");
451 application.SendNotification();
452 application.Render(20);
453 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
459 int UtcDaliAnimatedImageVisualMultiImage01(void)
461 ToolkitTestApplication application;
462 TestGlAbstraction& gl = application.GetGlAbstraction();
464 Property::Array urls;
465 CopyUrlsIntoArray( urls );
468 Property::Map propertyMap;
469 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
470 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
471 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
472 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
473 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
475 VisualFactory factory = VisualFactory::Get();
476 Visual::Base visual = factory.CreateVisual( propertyMap );
478 // Expect that a batch of 4 textures has been requested. These will be serially loaded
481 DummyControl dummyControl = DummyControl::New(true);
482 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
483 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
485 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
486 Stage::GetCurrent().Add( dummyControl );
487 application.SendNotification();
488 application.Render(16);
490 tet_infoline( "Ready the visual after the visual is on stage" );
491 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
493 tet_infoline( "Test that a timer has been started" );
494 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
496 TraceCallStack& textureTrace = gl.GetTextureTrace();
497 textureTrace.Enable(true);
499 application.SendNotification();
500 application.Render(16);
502 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
503 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
505 tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
506 Test::EmitGlobalTimerSignal();
508 // Expect the second batch has been requested
509 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
511 application.SendNotification();
512 application.Render(16);
513 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
516 tet_infoline( "Test that after 2 ticks that we have 6 textures" );
518 Test::EmitGlobalTimerSignal();
519 application.SendNotification();
520 application.Render(16);
521 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
523 tet_infoline("And that at least 2 textures were requested");
524 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
525 application.SendNotification();
526 application.Render(16);
527 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
530 tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
531 Test::EmitGlobalTimerSignal();
532 application.SendNotification();
533 application.Render(16);
534 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
536 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
537 application.SendNotification();
538 application.Render(16);
539 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
541 dummyControl.Unparent();
543 tet_infoline("Test that removing the visual from stage deletes all textures");
544 application.SendNotification();
545 application.Render(16);
546 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
551 int UtcDaliAnimatedImageVisualMultiImage02(void)
553 ToolkitTestApplication application;
554 TestGlAbstraction& gl = application.GetGlAbstraction();
556 tet_infoline( "Test that the animated visual still works with zero sized cache" );
559 Property::Array urls;
560 CopyUrlsIntoArray( urls );
562 Property::Map propertyMap;
563 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
564 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
565 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
566 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2);
567 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
569 VisualFactory factory = VisualFactory::Get();
570 Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
572 // Expect that each image is loaded each tick
574 DummyControl dummyControl = DummyControl::New(true);
575 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
576 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
578 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
579 Stage::GetCurrent().Add( dummyControl );
580 application.SendNotification();
581 application.Render(16);
583 tet_infoline( "Ready the visual after the visual is on stage" );
584 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
585 application.SendNotification();
586 application.Render(16);//glGenTextures 1
587 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
589 tet_infoline( "Test that each tick, a new image is requested" );
590 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
591 application.SendNotification();
592 application.Render(16);
593 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
594 application.SendNotification();
595 application.Render(16);//glGenTextures 2
596 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
598 tet_infoline( "Test that each tick, a new image is requested" );
599 Test::EmitGlobalTimerSignal(); // Internal::~TextureSet()
600 application.SendNotification();
601 application.Render(16);//glDeleteTextures 2
602 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
603 application.SendNotification();
604 application.Render(16);//glGenTextures 3
605 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
607 tet_infoline( "Test that each tick, a new image is requested" );
608 Test::EmitGlobalTimerSignal();
609 application.SendNotification();
610 application.Render(16);//glDeleteTextures 3
611 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
612 application.SendNotification();
613 application.Render(16);//Gen4
614 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
615 dummyControl.Unparent();
617 tet_infoline("Test that removing the visual from stage deletes all textures");
618 application.SendNotification();
619 application.Render(16);
620 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
625 int UtcDaliAnimatedImageVisualMultiImage03(void)
627 ToolkitTestApplication application;
628 TestGlAbstraction& gl = application.GetGlAbstraction();
631 Property::Array urls1, urls2;
632 CopyUrlsIntoArray( urls1 );
633 CopyUrlsIntoArray( urls2 );
635 Property::Map animatedImageMap1;
636 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
637 animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
638 animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
639 animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
640 animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
642 Property::Map animatedImageMap2;
643 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
644 animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
645 animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
646 animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
647 animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
649 VisualFactory factory = VisualFactory::Get();
650 Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
652 tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
654 DummyControl dummyControl1 = DummyControl::New(true);
655 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
656 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
657 dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
658 Stage::GetCurrent().Add( dummyControl1 );
660 application.SendNotification();
661 application.Render(16);
663 tet_infoline( "Ready the requested image after the first visual is on stage" );
664 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
665 application.SendNotification();
666 application.Render(16);
667 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
669 Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
670 DummyControl dummyControl2 = DummyControl::New(true);
671 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
672 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
673 dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
674 Stage::GetCurrent().Add( dummyControl2 );
675 application.SendNotification();
676 application.Render(16);
678 tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
679 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
680 Texture t1 = ts.GetTexture( 0 );
681 DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
683 tet_infoline( "Test that on the first tick, 1 new image is requested" );
684 Test::EmitGlobalTimerSignal(); // Both visuals should tick
686 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
687 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
689 ts = dummyControl2.GetRendererAt(0).GetTextures();
690 Texture t2 = ts.GetTexture( 0 );
691 DALI_TEST_CHECK( t1 != t2 );
693 dummyControl1.Unparent();
694 dummyControl2.Unparent();
696 tet_infoline("Test that removing the visual from stage deletes all textures");
697 application.SendNotification();
698 application.Render(16);
699 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
705 int UtcDaliAnimatedImageVisualMultiImage04(void)
707 ToolkitTestApplication application;
708 TestGlAbstraction& gl = application.GetGlAbstraction();
709 TraceCallStack& textureTrace = gl.GetTextureTrace();
710 textureTrace.Enable(true);
712 tet_infoline( "Test that if the cache size is the same as the number of urls, that once the cache is full, no new images are loaded" );
714 Property::Array urls;
715 CopyUrlsIntoArray( urls );
718 Property::Map propertyMap;
719 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
720 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
721 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
722 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
723 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
725 VisualFactory factory = VisualFactory::Get();
726 Visual::Base visual = factory.CreateVisual( propertyMap );
728 tet_infoline( "Expect that a batch of 7 textures has been requested." );
730 DummyControl dummyControl = DummyControl::New(true);
731 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
732 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
734 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
735 Stage::GetCurrent().Add( dummyControl );
736 application.SendNotification();
737 application.Render(16);
739 tet_infoline( "Wait for the first batch to complete" );
740 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
742 tet_infoline( "Test that a timer has been started" );
743 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
745 application.SendNotification();
746 application.Render(16);
748 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
749 tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
750 Test::EmitGlobalTimerSignal();
751 application.SendNotification();
752 application.Render(16);
754 // Expect the second batch has been requested
755 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
757 application.SendNotification();
758 application.Render(16);
759 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
761 tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
763 Test::EmitGlobalTimerSignal();
764 application.SendNotification();
765 application.Render(16);
766 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
767 application.SendNotification();
768 application.Render(16);
769 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
771 tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
772 Test::EmitGlobalTimerSignal();
773 application.SendNotification();
774 application.Render(16);
776 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
777 application.SendNotification();
778 application.Render(16);
779 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
781 dummyControl.Unparent();
784 tet_infoline("Test that removing the visual from stage deletes all textures");
785 application.SendNotification();
786 application.Render(16);
787 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
793 int UtcDaliAnimatedImageVisualMultiImage05(void)
795 ToolkitTestApplication application;
796 TestGlAbstraction& gl = application.GetGlAbstraction();
798 tet_infoline( "Test that if the cache size is the same as the number of urls, that removing a partially loaded visual removes all textures" );
800 Property::Array urls;
801 CopyUrlsIntoArray( urls );
804 Property::Map propertyMap;
805 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
806 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
807 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
808 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
809 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
811 VisualFactory factory = VisualFactory::Get();
812 Visual::Base visual = factory.CreateVisual( propertyMap );
814 tet_infoline( "Expect that a batch of 4 textures has been requested." );
816 DummyControl dummyControl = DummyControl::New(true);
817 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
818 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
820 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
821 Stage::GetCurrent().Add( dummyControl );
822 application.SendNotification();
823 application.Render(16);
825 tet_infoline( "Wait for the first batch to complete" );
826 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
828 tet_infoline( "Test that a timer has been started" );
829 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
831 application.SendNotification();
832 application.Render(16);
834 tet_infoline( "Test that a timer has been started" );
835 Test::EmitGlobalTimerSignal();
836 application.SendNotification();
837 application.Render(16);
839 dummyControl.Unparent();
842 application.SendNotification();
843 application.Render(16);
844 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
846 tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
847 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
848 application.SendNotification();
849 application.Render(16);
850 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
855 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
857 TestGlAbstraction& gl = application.GetGlAbstraction();
858 TraceCallStack& textureTrace = gl.GetTextureTrace();
860 textureTrace.Enable(true);
861 Stage::GetCurrent().Add( dummyControl );
863 application.SendNotification();
864 application.Render(16);
866 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_INNER_LOCATION( location ) );
868 application.SendNotification();
869 application.Render();
871 tet_infoline( "Test that a timer has been created" );
872 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
874 for ( uint16_t i = 0; i < loopCount; i++ )
876 for ( uint16_t j = 0; j < frameCount; j++ )
878 if( i == 0 && j == 0 )
880 continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
882 tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
883 Test::EmitGlobalTimerSignal();
884 application.SendNotification();
885 application.Render(16);
887 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_INNER_LOCATION( location ) );
889 application.SendNotification();
890 application.Render();
891 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION( location ) );
892 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
894 tet_printf( "Test Loop %u \n\n", i + 1u );
897 tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
898 Test::EmitGlobalTimerSignal();
899 application.SendNotification();
900 application.Render(16);
901 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
903 dummyControl.Unparent();
906 int UtcDaliAnimatedImageVisualLoopCount(void)
908 ToolkitTestApplication application;
910 tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
913 // request AnimatedImageVisual with a property map
914 // Test with no (0) loop count
915 VisualFactory factory = VisualFactory::Get();
916 Visual::Base animatedImageVisual = factory.CreateVisual(
918 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
919 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
920 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
921 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
922 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
923 .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
925 DummyControl dummyControl = DummyControl::New(true);
926 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
927 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
928 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
930 TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
932 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
933 animatedImageVisual.Reset();
935 application.SendNotification();
936 application.Render(16);
938 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
939 animatedImageVisual = factory.CreateVisual(
941 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
942 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
943 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
944 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
945 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
946 .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
948 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
950 TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
952 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
953 animatedImageVisual.Reset();
955 application.SendNotification();
956 application.Render(16);
958 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
959 animatedImageVisual = factory.CreateVisual(
961 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
962 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
963 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
964 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
965 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
966 .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
968 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
970 TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
975 int UtcDaliAnimatedImageVisualPlayback(void)
977 ToolkitTestApplication application;
978 TestGlAbstraction& gl = application.GetGlAbstraction();
979 TraceCallStack& textureTrace = gl.GetTextureTrace();
981 tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
984 // request AnimatedImageVisual with a property map
985 // Test with forever (-1) loop count
986 VisualFactory factory = VisualFactory::Get();
987 Visual::Base animatedImageVisual = factory.CreateVisual(
989 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
990 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
991 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
992 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
993 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
994 .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
996 DummyControl dummyControl = DummyControl::New(true);
997 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
998 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
999 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1001 textureTrace.Enable(true);
1002 Stage::GetCurrent().Add( dummyControl );
1003 application.SendNotification();
1004 application.Render(16);
1006 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1008 application.SendNotification();
1009 application.Render();
1011 tet_infoline( "Test that a timer has been created" );
1012 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1014 Test::EmitGlobalTimerSignal();
1015 application.SendNotification();
1016 application.Render(16);
1018 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1020 application.SendNotification();
1021 application.Render();
1022 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1024 Property::Map attributes;
1025 tet_infoline( "Test Pause action. Timer should stop after Pause action" );
1026 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
1027 Test::EmitGlobalTimerSignal();
1028 application.SendNotification();
1029 application.Render(16);
1030 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1032 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1033 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1034 Test::EmitGlobalTimerSignal();
1035 application.SendNotification();
1036 application.Render(16);
1038 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1040 application.SendNotification();
1041 application.Render();
1042 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1044 tet_infoline( "Test Stop action. Timer should stop after Stop action" );
1045 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
1046 Test::EmitGlobalTimerSignal();
1047 application.SendNotification();
1048 application.Render(16);
1049 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1051 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1052 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1053 Test::EmitGlobalTimerSignal();
1054 application.SendNotification();
1055 application.Render(16);
1057 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1059 application.SendNotification();
1060 application.Render();
1061 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1063 dummyControl.Unparent();