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 );
162 int UtcDaliAnimatedImageVisualJumpToAction(void)
164 ToolkitTestApplication application;
165 TestGlAbstraction& gl = application.GetGlAbstraction();
167 Property::Array urls;
168 CopyUrlsIntoArray( urls );
171 Property::Map propertyMap;
172 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
173 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
174 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
175 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 12);
176 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
178 VisualFactory factory = VisualFactory::Get();
179 Visual::Base visual = factory.CreateVisual( propertyMap );
181 DummyControl dummyControl = DummyControl::New(true);
182 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
183 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
185 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
186 Stage::GetCurrent().Add( dummyControl );
187 application.SendNotification();
188 application.Render(20);
190 tet_infoline( "Ready the visual after the visual is on stage" );
191 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
193 tet_infoline( "Test that a timer has been started" );
194 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
196 TraceCallStack& textureTrace = gl.GetTextureTrace();
197 textureTrace.Enable(true);
199 application.SendNotification();
200 application.Render(20);
202 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
204 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
206 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
208 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20 );
210 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
212 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
214 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
215 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
217 dummyControl.Unparent();
219 tet_infoline("Test that removing the visual from stage deletes all textures");
220 application.SendNotification();
221 application.Render(16);
222 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
228 int UtcDaliAnimatedImageVisualStopBehavior(void)
230 ToolkitTestApplication application;
231 TestGlAbstraction& gl = application.GetGlAbstraction();
233 Property::Array urls;
234 CopyUrlsIntoArray( urls );
237 Property::Map propertyMap;
238 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
239 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
240 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
241 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
242 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
243 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
245 VisualFactory factory = VisualFactory::Get();
246 Visual::Base visual = factory.CreateVisual( propertyMap );
248 // Expect that a batch of 4 textures has been requested. These will be serially loaded
251 DummyControl dummyControl = DummyControl::New(true);
252 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
253 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
255 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
256 Stage::GetCurrent().Add( dummyControl );
257 application.SendNotification();
258 application.Render(20);
260 tet_infoline( "Ready the visual after the visual is on stage" );
261 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
263 tet_infoline( "Test that a timer has been started" );
264 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
266 TraceCallStack& textureTrace = gl.GetTextureTrace();
267 textureTrace.Enable(true);
269 application.SendNotification();
270 application.Render(20);
272 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
274 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
276 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
278 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1 );
280 // Expect the second batch has been requested
281 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
283 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
285 dummyControl.Unparent();
287 tet_infoline("Test that removing the visual from stage deletes all textures");
288 application.SendNotification();
289 application.Render(16);
290 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
296 int UtcDaliAnimatedImageVisualGif01(void)
298 ToolkitTestApplication application;
299 TestGlAbstraction& gl = application.GetGlAbstraction();
302 Property::Map propertyMap;
303 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
304 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
305 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
306 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 4);
307 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
309 VisualFactory factory = VisualFactory::Get();
310 Visual::Base visual = factory.CreateVisual( propertyMap );
312 // Expect that a batch of 4 textures has been requested. These will be serially loaded
315 DummyControl dummyControl = DummyControl::New(true);
316 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
317 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
319 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
320 Stage::GetCurrent().Add( dummyControl );
321 application.SendNotification();
322 application.Render(20);
324 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
326 tet_infoline( "Test that a timer has been started" );
328 TraceCallStack& textureTrace = gl.GetTextureTrace();
329 textureTrace.Enable(true);
331 Test::EmitGlobalTimerSignal();
333 application.SendNotification();
334 application.Render(20);
336 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
338 dummyControl.Unparent();
340 tet_infoline("Test that removing the visual from stage deletes all textures");
341 application.SendNotification();
342 application.Render(20);
343 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
349 int UtcDaliAnimatedImageVisualMultiImage01(void)
351 ToolkitTestApplication application;
352 TestGlAbstraction& gl = application.GetGlAbstraction();
354 Property::Array urls;
355 CopyUrlsIntoArray( urls );
358 Property::Map propertyMap;
359 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
360 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
361 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
362 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
363 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
365 VisualFactory factory = VisualFactory::Get();
366 Visual::Base visual = factory.CreateVisual( propertyMap );
368 // Expect that a batch of 4 textures has been requested. These will be serially loaded
371 DummyControl dummyControl = DummyControl::New(true);
372 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
373 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
375 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
376 Stage::GetCurrent().Add( dummyControl );
377 application.SendNotification();
378 application.Render(16);
380 tet_infoline( "Ready the visual after the visual is on stage" );
381 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
383 tet_infoline( "Test that a timer has been started" );
384 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
386 TraceCallStack& textureTrace = gl.GetTextureTrace();
387 textureTrace.Enable(true);
389 application.SendNotification();
390 application.Render(16);
392 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
393 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
395 tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
396 Test::EmitGlobalTimerSignal();
398 // Expect the second batch has been requested
399 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
401 application.SendNotification();
402 application.Render(16);
403 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
406 tet_infoline( "Test that after 2 ticks that we have 6 textures" );
408 Test::EmitGlobalTimerSignal();
409 application.SendNotification();
410 application.Render(16);
411 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
413 tet_infoline("And that at least 2 textures were requested");
414 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
415 application.SendNotification();
416 application.Render(16);
417 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
420 tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
421 Test::EmitGlobalTimerSignal();
422 application.SendNotification();
423 application.Render(16);
424 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
426 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
427 application.SendNotification();
428 application.Render(16);
429 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
431 dummyControl.Unparent();
433 tet_infoline("Test that removing the visual from stage deletes all textures");
434 application.SendNotification();
435 application.Render(16);
436 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
441 int UtcDaliAnimatedImageVisualMultiImage02(void)
443 ToolkitTestApplication application;
444 TestGlAbstraction& gl = application.GetGlAbstraction();
446 tet_infoline( "Test that the animated visual still works with zero sized cache" );
449 Property::Array urls;
450 CopyUrlsIntoArray( urls );
452 Property::Map propertyMap;
453 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
454 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
455 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
456 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
457 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
459 VisualFactory factory = VisualFactory::Get();
460 Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
462 // Expect that each image is loaded each tick
464 DummyControl dummyControl = DummyControl::New(true);
465 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
466 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
468 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
469 Stage::GetCurrent().Add( dummyControl );
470 application.SendNotification();
471 application.Render(16);
473 tet_infoline( "Ready the visual after the visual is on stage" );
474 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
475 application.SendNotification();
476 application.Render(16);//glGenTextures 1
477 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
479 tet_infoline( "Test that each tick, a new image is requested" );
480 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
481 application.SendNotification();
482 application.Render(16);
483 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
484 application.SendNotification();
485 application.Render(16);//glGenTextures 2
486 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
488 tet_infoline( "Test that each tick, a new image is requested" );
489 Test::EmitGlobalTimerSignal(); // Internal::~TextureSet()
490 application.SendNotification();
491 application.Render(16);//glDeleteTextures 2
492 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
493 application.SendNotification();
494 application.Render(16);//glGenTextures 3
495 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
497 tet_infoline( "Test that each tick, a new image is requested" );
498 Test::EmitGlobalTimerSignal();
499 application.SendNotification();
500 application.Render(16);//glDeleteTextures 3
501 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
502 application.SendNotification();
503 application.Render(16);//Gen4
504 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
505 dummyControl.Unparent();
507 tet_infoline("Test that removing the visual from stage deletes all textures");
508 application.SendNotification();
509 application.Render(16);
510 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
515 int UtcDaliAnimatedImageVisualMultiImage03(void)
517 ToolkitTestApplication application;
518 TestGlAbstraction& gl = application.GetGlAbstraction();
521 Property::Array urls1, urls2;
522 CopyUrlsIntoArray( urls1 );
523 CopyUrlsIntoArray( urls2 );
525 Property::Map animatedImageMap1;
526 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
527 animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
528 animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
529 animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
530 animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
532 Property::Map animatedImageMap2;
533 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
534 animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
535 animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
536 animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
537 animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
539 VisualFactory factory = VisualFactory::Get();
540 Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
542 tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
544 DummyControl dummyControl1 = DummyControl::New(true);
545 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
546 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
547 dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
548 Stage::GetCurrent().Add( dummyControl1 );
550 application.SendNotification();
551 application.Render(16);
553 tet_infoline( "Ready the requested image after the first visual is on stage" );
554 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
555 application.SendNotification();
556 application.Render(16);
557 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
559 Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
560 DummyControl dummyControl2 = DummyControl::New(true);
561 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
562 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
563 dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
564 Stage::GetCurrent().Add( dummyControl2 );
565 application.SendNotification();
566 application.Render(16);
568 tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
569 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
570 Texture t1 = ts.GetTexture( 0 );
571 DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
573 tet_infoline( "Test that on the first tick, 1 new image is requested" );
574 Test::EmitGlobalTimerSignal(); // Both visuals should tick
576 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
577 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
579 ts = dummyControl2.GetRendererAt(0).GetTextures();
580 Texture t2 = ts.GetTexture( 0 );
581 DALI_TEST_CHECK( t1 != t2 );
583 dummyControl1.Unparent();
584 dummyControl2.Unparent();
586 tet_infoline("Test that removing the visual from stage deletes all textures");
587 application.SendNotification();
588 application.Render(16);
589 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
595 int UtcDaliAnimatedImageVisualMultiImage04(void)
597 ToolkitTestApplication application;
598 TestGlAbstraction& gl = application.GetGlAbstraction();
599 TraceCallStack& textureTrace = gl.GetTextureTrace();
600 textureTrace.Enable(true);
602 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" );
604 Property::Array urls;
605 CopyUrlsIntoArray( urls );
608 Property::Map propertyMap;
609 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
610 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
611 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
612 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
613 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
615 VisualFactory factory = VisualFactory::Get();
616 Visual::Base visual = factory.CreateVisual( propertyMap );
618 tet_infoline( "Expect that a batch of 7 textures has been requested." );
620 DummyControl dummyControl = DummyControl::New(true);
621 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
622 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
624 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
625 Stage::GetCurrent().Add( dummyControl );
626 application.SendNotification();
627 application.Render(16);
629 tet_infoline( "Wait for the first batch to complete" );
630 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
632 tet_infoline( "Test that a timer has been started" );
633 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
635 application.SendNotification();
636 application.Render(16);
638 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
639 tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
640 Test::EmitGlobalTimerSignal();
641 application.SendNotification();
642 application.Render(16);
644 // Expect the second batch has been requested
645 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
647 application.SendNotification();
648 application.Render(16);
649 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
651 tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
653 Test::EmitGlobalTimerSignal();
654 application.SendNotification();
655 application.Render(16);
656 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
657 application.SendNotification();
658 application.Render(16);
659 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
661 tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
662 Test::EmitGlobalTimerSignal();
663 application.SendNotification();
664 application.Render(16);
666 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
667 application.SendNotification();
668 application.Render(16);
669 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
671 dummyControl.Unparent();
674 tet_infoline("Test that removing the visual from stage deletes all textures");
675 application.SendNotification();
676 application.Render(16);
677 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
683 int UtcDaliAnimatedImageVisualMultiImage05(void)
685 ToolkitTestApplication application;
686 TestGlAbstraction& gl = application.GetGlAbstraction();
688 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" );
690 Property::Array urls;
691 CopyUrlsIntoArray( urls );
694 Property::Map propertyMap;
695 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
696 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
697 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
698 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
699 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
701 VisualFactory factory = VisualFactory::Get();
702 Visual::Base visual = factory.CreateVisual( propertyMap );
704 tet_infoline( "Expect that a batch of 4 textures has been requested." );
706 DummyControl dummyControl = DummyControl::New(true);
707 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
708 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
710 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
711 Stage::GetCurrent().Add( dummyControl );
712 application.SendNotification();
713 application.Render(16);
715 tet_infoline( "Wait for the first batch to complete" );
716 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
718 tet_infoline( "Test that a timer has been started" );
719 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
721 application.SendNotification();
722 application.Render(16);
724 tet_infoline( "Test that a timer has been started" );
725 Test::EmitGlobalTimerSignal();
726 application.SendNotification();
727 application.Render(16);
729 dummyControl.Unparent();
732 application.SendNotification();
733 application.Render(16);
734 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
736 tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
737 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
738 application.SendNotification();
739 application.Render(16);
740 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
745 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
747 TestGlAbstraction& gl = application.GetGlAbstraction();
748 TraceCallStack& textureTrace = gl.GetTextureTrace();
750 textureTrace.Enable(true);
751 Stage::GetCurrent().Add( dummyControl );
752 application.SendNotification();
753 application.Render(16);
755 tet_infoline( "Test that a timer has been created" );
756 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
758 for ( uint16_t i = 0; i < loopCount; i++ )
760 for ( uint16_t j = 0; j < frameCount; j++ )
762 if( i == 0 && j == 0 )
764 continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
766 tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
767 Test::EmitGlobalTimerSignal();
768 application.SendNotification();
769 application.Render(16);
770 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_INNER_LOCATION( location ) );
771 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
773 tet_printf( "\nTest Loop %u \n", i );
776 tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
777 Test::EmitGlobalTimerSignal();
778 application.SendNotification();
779 application.Render(16);
780 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
782 dummyControl.Unparent();
785 int UtcDaliAnimatedImageVisualLoopCount(void)
787 ToolkitTestApplication application;
789 tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
792 // request AnimatedImageVisual with a property map
793 // Test with no (0) loop count
794 VisualFactory factory = VisualFactory::Get();
795 Visual::Base animatedImageVisual = factory.CreateVisual(
797 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
798 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
799 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
800 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
801 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
802 .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
804 DummyControl dummyControl = DummyControl::New(true);
805 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
806 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
807 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
809 TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
811 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
812 animatedImageVisual = factory.CreateVisual(
814 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
815 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
816 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
817 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
818 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
819 .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
821 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
823 TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
825 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
826 animatedImageVisual = factory.CreateVisual(
828 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
829 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
830 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
831 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
832 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
833 .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
835 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
837 TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
843 int UtcDaliAnimatedImageVisualPlayback(void)
845 ToolkitTestApplication application;
846 TestGlAbstraction& gl = application.GetGlAbstraction();
847 TraceCallStack& textureTrace = gl.GetTextureTrace();
849 tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
852 // request AnimatedImageVisual with a property map
853 // Test with forever (-1) loop count
854 VisualFactory factory = VisualFactory::Get();
855 Visual::Base animatedImageVisual = factory.CreateVisual(
857 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
858 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
859 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
860 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
861 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
862 .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
864 DummyControl dummyControl = DummyControl::New(true);
865 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
866 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
867 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
869 textureTrace.Enable(true);
870 Stage::GetCurrent().Add( dummyControl );
871 application.SendNotification();
872 application.Render(16);
874 tet_infoline( "Test that a timer has been created" );
875 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
877 Test::EmitGlobalTimerSignal();
878 application.SendNotification();
879 application.Render(16);
880 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
882 Property::Map attributes;
883 tet_infoline( "Test Pause action. Timer should stop after Pause action" );
884 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
885 Test::EmitGlobalTimerSignal();
886 application.SendNotification();
887 application.Render(16);
888 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
890 tet_infoline( "Test Play action. Timer should Restart after Play action" );
891 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
892 Test::EmitGlobalTimerSignal();
893 application.SendNotification();
894 application.Render(16);
895 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
897 tet_infoline( "Test Stop action. Timer should stop after Stop action" );
898 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
899 Test::EmitGlobalTimerSignal();
900 application.SendNotification();
901 application.Render(16);
902 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
904 tet_infoline( "Test Play action. Timer should Restart after Play action" );
905 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
906 Test::EmitGlobalTimerSignal();
907 application.SendNotification();
908 application.Render(16);
909 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
911 dummyControl.Unparent();