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/visual-properties-devel.h>
27 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
28 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
29 #include "dummy-control.h"
32 using namespace Dali::Toolkit;
34 void dali_animated_image_visual_startup(void)
36 test_return_value = TET_UNDEF;
39 void dali_animated_image_visual_cleanup(void)
41 test_return_value = TET_PASS;
46 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-%02d.png";
47 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
51 void CopyUrlsIntoArray( Property::Array& urls, int startIndex=0 )
53 for( int i=20+startIndex;i<=30;++i)
56 if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
58 Property::Value value(url);
65 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
67 ToolkitTestApplication application;
68 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
70 // request AnimatedImageVisual with a property map
71 VisualFactory factory = VisualFactory::Get();
72 Visual::Base animatedImageVisual = factory.CreateVisual(
74 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
75 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
76 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
77 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
78 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
79 .Add( DevelVisual::Property::CORNER_RADIUS, 22.2f )
80 .Add( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE ));
82 Property::Map resultMap;
83 animatedImageVisual.CreatePropertyMap( resultMap );
84 // check the property values from the returned map from a visual
85 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
86 DALI_TEST_CHECK( value );
87 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
89 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
90 DALI_TEST_CHECK( value );
91 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
93 value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT );
94 DALI_TEST_CHECK( value );
95 DALI_TEST_EQUALS( value->Get<float>(), 22.2f, TEST_LOCATION );
97 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER );
98 DALI_TEST_CHECK( value );
99 DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::ABSOLUTE );
101 // request AnimatedImageVisual with an URL
102 Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
104 animatedImageVisual2.CreatePropertyMap( resultMap );
105 // check the property values from the returned map from a visual
106 value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
107 DALI_TEST_CHECK( value );
108 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
110 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
111 DALI_TEST_CHECK( value );
112 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
118 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
120 ToolkitTestApplication application;
121 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap for multi image with fixed cache" );
123 // request AnimatedImageVisual with a property map
124 VisualFactory factory = VisualFactory::Get();
125 Property::Array urls;
126 CopyUrlsIntoArray( urls );
128 Visual::Base animatedImageVisual = factory.CreateVisual(
130 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
132 .Add( "batchSize", 4 )
133 .Add( "cacheSize", 20 )
134 .Add( "loopCount", 10 )
135 .Add( "frameDelay", 200 )
136 .Add( "pixelArea", Vector4() )
137 .Add( "wrapModeU", WrapMode::REPEAT )
138 .Add( "wrapModeV", WrapMode::DEFAULT )
139 .Add( "cornerRadius", 50.0f )
140 .Add( "cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE ));
142 Property::Map resultMap;
143 animatedImageVisual.CreatePropertyMap( resultMap );
144 // check the property values from the returned map from a visual
145 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
146 DALI_TEST_CHECK( value );
147 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
149 value = resultMap.Find( ImageVisual::Property::URL, "url" );
150 DALI_TEST_CHECK( value );
151 Property::Array* resultUrls = value->GetArray();
152 DALI_TEST_CHECK( resultUrls );
153 DALI_TEST_EQUALS( resultUrls->Count(), urls.Count(), TEST_LOCATION );
155 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
156 DALI_TEST_CHECK( value );
157 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
159 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
160 DALI_TEST_CHECK( value );
161 DALI_TEST_EQUALS( value->Get<int>(), 20, TEST_LOCATION );
163 value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
164 DALI_TEST_CHECK( value );
165 DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
167 value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
168 DALI_TEST_CHECK( value );
169 DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
171 value = resultMap.Find( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber" );
172 DALI_TEST_CHECK( value );
173 DALI_TEST_EQUALS( value->Get<int>(), 11, TEST_LOCATION );
175 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" );
176 DALI_TEST_CHECK( value );
177 DALI_TEST_EQUALS( value->Get<float>(), 50.0f, TEST_LOCATION );
179 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
180 DALI_TEST_CHECK( value );
181 DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::RELATIVE );
187 int UtcDaliAnimatedImageVisualGetPropertyMap03(void)
189 ToolkitTestApplication application;
190 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap for multi image rolling cache" );
192 // request AnimatedImageVisual with a property map
193 VisualFactory factory = VisualFactory::Get();
194 Property::Array urls;
195 CopyUrlsIntoArray( urls );
197 Visual::Base animatedImageVisual = factory.CreateVisual(
199 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
201 .Add( "batchSize", 4 )
202 .Add( "cacheSize", 8 )
203 .Add( "loopCount", 10 )
204 .Add( "frameDelay", 200 )
205 .Add( "pixelArea", Vector4() )
206 .Add( "wrapModeU", WrapMode::REPEAT )
207 .Add( "wrapModeV", WrapMode::DEFAULT )
208 .Add( "cornerRadius", 50.5f ));
210 Property::Map resultMap;
211 animatedImageVisual.CreatePropertyMap( resultMap );
212 // check the property values from the returned map from a visual
213 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
214 DALI_TEST_CHECK( value );
215 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
217 value = resultMap.Find( ImageVisual::Property::URL, "url" );
218 DALI_TEST_CHECK( value );
219 Property::Array* resultUrls = value->GetArray();
220 DALI_TEST_CHECK( resultUrls );
221 DALI_TEST_EQUALS( resultUrls->Count(), urls.Count(), TEST_LOCATION );
223 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
224 DALI_TEST_CHECK( value );
225 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
227 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
228 DALI_TEST_CHECK( value );
229 DALI_TEST_EQUALS( value->Get<int>(), 8, TEST_LOCATION );
231 value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
232 DALI_TEST_CHECK( value );
233 DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
235 value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
236 DALI_TEST_CHECK( value );
237 DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
239 value = resultMap.Find( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber" );
240 DALI_TEST_CHECK( value );
241 DALI_TEST_EQUALS( value->Get<int>(), 11, TEST_LOCATION );
243 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" );
244 DALI_TEST_CHECK( value );
245 DALI_TEST_EQUALS( value->Get<float>(), 50.5f, TEST_LOCATION );
247 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
248 DALI_TEST_CHECK( value );
249 DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::ABSOLUTE );
254 int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
256 ToolkitTestApplication application;
257 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
259 // request AnimatedImageVisual with a property map
260 VisualFactory factory = VisualFactory::Get();
261 Visual::Base animatedImageVisual = factory.CreateVisual(
263 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
264 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
265 .Add( ImageVisual::Property::BATCH_SIZE, 1 )
266 .Add( ImageVisual::Property::CACHE_SIZE, 1 )
267 .Add( ImageVisual::Property::SYNCHRONOUS_LOADING, false ));
269 Property::Map resultMap;
270 animatedImageVisual.CreatePropertyMap( resultMap );
272 // check the property values from the returned map from a visual
273 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
274 DALI_TEST_CHECK( value );
275 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
277 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
278 DALI_TEST_CHECK( value );
279 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
281 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, Property::INTEGER );
282 DALI_TEST_CHECK( value );
283 DALI_TEST_CHECK( value->Get<int>() == 2 );
285 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, Property::INTEGER );
286 DALI_TEST_CHECK( value );
287 DALI_TEST_CHECK( value->Get<int>() == 2 );
289 value = resultMap.Find( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber" );
290 DALI_TEST_CHECK( value );
291 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
297 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
299 ToolkitTestApplication application;
300 TestGlAbstraction& gl = application.GetGlAbstraction();
303 Property::Map propertyMap;
304 propertyMap.Insert( Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
305 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
306 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2 );
307 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2 );
308 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20 );
309 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
310 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS, 0.23f );
311 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE );
313 VisualFactory factory = VisualFactory::Get();
314 Visual::Base visual = factory.CreateVisual( propertyMap );
316 DummyControl dummyControl = DummyControl::New(true);
317 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
318 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
320 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
321 application.GetScene().Add( dummyControl );
323 TraceCallStack& textureTrace = gl.GetTextureTrace();
324 textureTrace.Enable(true);
326 application.SendNotification();
327 application.Render(20);
329 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
331 application.SendNotification();
332 application.Render();
334 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
335 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
337 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3 );
339 application.SendNotification();
340 application.Render(20);
342 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
344 application.SendNotification();
345 application.Render();
347 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
349 dummyControl.Unparent();
351 tet_infoline("Test that removing the visual from stage deletes all textures");
352 application.SendNotification();
353 application.Render(16);
354 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
360 int UtcDaliAnimatedImageVisualJumpToAction(void)
362 ToolkitTestApplication application;
363 TestGlAbstraction& gl = application.GetGlAbstraction();
365 Property::Array urls;
366 CopyUrlsIntoArray( urls );
369 Property::Map propertyMap;
370 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
371 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
372 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
373 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 12);
374 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
376 VisualFactory factory = VisualFactory::Get();
377 Visual::Base visual = factory.CreateVisual( propertyMap );
379 DummyControl dummyControl = DummyControl::New(true);
380 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
381 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
383 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
384 application.GetScene().Add( dummyControl );
385 application.SendNotification();
386 application.Render(20);
388 tet_infoline( "Ready the visual after the visual is on stage" );
389 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
391 tet_infoline( "Test that a timer has been started" );
392 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
394 TraceCallStack& textureTrace = gl.GetTextureTrace();
395 textureTrace.Enable(true);
397 application.SendNotification();
398 application.Render(20);
400 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
402 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
404 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
406 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20 );
408 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
410 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
412 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
413 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
415 dummyControl.Unparent();
417 tet_infoline("Test that removing the visual from stage deletes all textures");
418 application.SendNotification();
419 application.Render(16);
420 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
426 int UtcDaliAnimatedImageVisualStopBehavior(void)
428 ToolkitTestApplication application;
429 TestGlAbstraction& gl = application.GetGlAbstraction();
431 Property::Array urls;
432 CopyUrlsIntoArray( urls );
435 Property::Map propertyMap;
436 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
437 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
438 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
439 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
440 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
441 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
443 VisualFactory factory = VisualFactory::Get();
444 Visual::Base visual = factory.CreateVisual( propertyMap );
446 // Expect that a batch of 4 textures has been requested. These will be serially loaded
449 DummyControl dummyControl = DummyControl::New(true);
450 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
451 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
453 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
454 application.GetScene().Add( dummyControl );
455 application.SendNotification();
456 application.Render(20);
458 tet_infoline( "Ready the visual after the visual is on stage" );
459 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
461 tet_infoline( "Test that a timer has been started" );
462 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
464 TraceCallStack& textureTrace = gl.GetTextureTrace();
465 textureTrace.Enable(true);
467 application.SendNotification();
468 application.Render(20);
470 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
472 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
474 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
476 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1 );
478 // Expect the second batch has been requested
479 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
481 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
483 dummyControl.Unparent();
485 tet_infoline("Test that removing the visual from stage deletes all textures");
486 application.SendNotification();
487 application.Render(16);
488 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
494 int UtcDaliAnimatedImageVisualStopBehavior02(void)
496 ToolkitTestApplication application;
497 TestGlAbstraction& gl = application.GetGlAbstraction();
499 Property::Array urls;
500 CopyUrlsIntoArray( urls );
503 Property::Map propertyMap;
504 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
505 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
506 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
507 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
508 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2);
509 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
511 VisualFactory factory = VisualFactory::Get();
512 Visual::Base visual = factory.CreateVisual( propertyMap );
514 // Expect that a batch of 4 textures has been requested. These will be serially loaded
517 DummyControl dummyControl = DummyControl::New(true);
518 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
519 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
521 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
522 application.GetScene().Add( dummyControl );
524 tet_infoline( "Ready the visual after the visual is on stage" );
525 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
527 TraceCallStack& textureTrace = gl.GetTextureTrace();
528 textureTrace.Enable(true);
530 application.SendNotification();
531 application.Render(20);
533 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
535 Test::EmitGlobalTimerSignal();
537 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
539 application.SendNotification();
540 application.Render(20);
542 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
544 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
546 tet_infoline( "Ready the visual after the visual is on stage" );
547 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
549 application.SendNotification();
550 application.Render(20);
552 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
554 dummyControl.Unparent();
556 tet_infoline("Test that removing the visual from stage deletes all textures");
557 application.SendNotification();
558 application.Render(16);
559 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
565 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
567 ToolkitTestApplication application;
568 TestGlAbstraction& gl = application.GetGlAbstraction();
571 Property::Map propertyMap;
572 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
573 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
574 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
575 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 4);
576 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
578 VisualFactory factory = VisualFactory::Get();
579 Visual::Base visual = factory.CreateVisual( propertyMap );
581 // Expect that a batch of 4 textures has been requested. These will be serially loaded
584 DummyControl dummyControl = DummyControl::New(true);
585 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
586 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
588 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
589 application.GetScene().Add( dummyControl );
591 application.SendNotification();
592 application.Render();
594 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
596 application.SendNotification();
597 application.Render(20);
599 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
601 tet_infoline( "Test that a timer has been started" );
603 TraceCallStack& textureTrace = gl.GetTextureTrace();
604 textureTrace.Enable(true);
606 Test::EmitGlobalTimerSignal();
608 application.SendNotification();
609 application.Render();
611 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
613 application.SendNotification();
614 application.Render(20);
616 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
618 dummyControl.Unparent();
620 tet_infoline("Test that removing the visual from stage deletes all textures");
621 application.SendNotification();
622 application.Render(20);
623 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
629 int UtcDaliAnimatedImageVisualMultiImage01(void)
631 ToolkitTestApplication application;
632 TestGlAbstraction& gl = application.GetGlAbstraction();
634 Property::Array urls;
635 CopyUrlsIntoArray( urls );
638 Property::Map propertyMap;
639 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
640 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
641 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
642 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
643 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
645 VisualFactory factory = VisualFactory::Get();
646 Visual::Base visual = factory.CreateVisual( propertyMap );
648 // Expect that a batch of 4 textures has been requested. These will be serially loaded
651 DummyControl dummyControl = DummyControl::New(true);
652 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
653 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
655 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
656 application.GetScene().Add( dummyControl );
657 application.SendNotification();
658 application.Render(16);
660 tet_infoline( "Ready the visual after the visual is on stage" );
661 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
663 tet_infoline( "Test that a timer has been started" );
664 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
666 TraceCallStack& textureTrace = gl.GetTextureTrace();
667 textureTrace.Enable(true);
669 application.SendNotification();
670 application.Render(16);
672 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
673 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
675 tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
676 Test::EmitGlobalTimerSignal();
678 // Expect the second batch has been requested
679 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
681 application.SendNotification();
682 application.Render(16);
683 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
686 tet_infoline( "Test that after 2 ticks that we have 6 textures" );
688 Test::EmitGlobalTimerSignal();
689 application.SendNotification();
690 application.Render(16);
691 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
693 tet_infoline("And that at least 2 textures were requested");
694 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
695 application.SendNotification();
696 application.Render(16);
697 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
700 tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
701 Test::EmitGlobalTimerSignal();
702 application.SendNotification();
703 application.Render(16);
704 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
706 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
707 application.SendNotification();
708 application.Render(16);
709 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
711 dummyControl.Unparent();
713 tet_infoline("Test that removing the visual from stage deletes all textures");
714 application.SendNotification();
715 application.Render(16);
716 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
721 int UtcDaliAnimatedImageVisualMultiImage02(void)
723 ToolkitTestApplication application;
724 TestGlAbstraction& gl = application.GetGlAbstraction();
726 tet_infoline( "Test that the animated visual has different batch and cache size." );
729 Property::Array urls;
730 CopyUrlsIntoArray( urls );
732 Property::Map propertyMap;
733 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
734 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
735 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
736 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
737 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
739 VisualFactory factory = VisualFactory::Get();
740 Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
742 // Check the batch size and cache size need to have minimum 2.
743 Property::Map resultMap;
744 visual.CreatePropertyMap( resultMap );
745 Property::Value* value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
746 DALI_TEST_CHECK( value );
747 DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
748 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
749 DALI_TEST_CHECK( value );
750 DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
753 // Batch size is 2 and cache size is 3
755 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
756 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
757 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
758 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 3);
759 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
761 visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
763 // Expect that each image is loaded each tick
764 DummyControl dummyControl = DummyControl::New(true);
765 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
766 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
769 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
770 application.GetScene().Add( dummyControl );
771 application.SendNotification();
772 application.Render(16);
774 tet_infoline( "Ready the visual after the visual is on window" );
775 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
776 application.SendNotification();
777 application.Render(16);//glGenTextures 1 and 2
778 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
780 tet_infoline( "Test that each tick, a new image is requested" );
781 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
782 application.SendNotification();
783 application.Render(16);
784 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
785 application.SendNotification();
786 application.Render(16);//glGenTextures 3
787 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
789 tet_infoline( "Test that each tick, a new image is requested" );
790 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
791 application.SendNotification();
792 application.Render(16);
793 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
794 application.SendNotification();
795 application.Render(16);//glGenTextures 4
796 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
798 dummyImpl1.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
799 dummyControl.Unparent();
802 // Batch size is 9 and cache size is 4
804 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
805 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
806 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 3);
807 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 7);
808 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
810 visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
812 // Expect that each image is loaded each tick
813 dummyControl = DummyControl::New(true);
814 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
815 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
818 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
819 application.GetScene().Add( dummyControl );
820 application.SendNotification();
821 application.Render(16);
823 tet_infoline( "Ready the visual after the visual is on window" );
824 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
825 application.SendNotification();
826 application.Render(16);//glGenTextures 1, 2, and 3
827 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
829 tet_infoline( "Test that each tick, a new image is requested" );
830 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
831 application.SendNotification();
832 application.Render(16);
833 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
834 application.SendNotification();
835 application.Render(16);//glGenTextures 4, 5, and 6
836 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 5, TEST_LOCATION );
838 tet_infoline( "Test that each tick, a new image is requested" );
839 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
840 application.SendNotification();
841 application.Render(16);
842 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
843 application.SendNotification();
844 application.Render(16);//glGenTextures 7, 1, and 2
845 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
847 tet_infoline( "Test that each tick, a new image is requested" );
848 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
849 application.SendNotification();
850 application.Render(16);
851 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
852 application.SendNotification();
853 application.Render(16);//glGenTextures 3
854 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
856 dummyControl.Unparent();
858 tet_infoline("Test that removing the visual from window deletes all textures");
859 application.SendNotification();
860 application.Render(16);
861 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
866 int UtcDaliAnimatedImageVisualMultiImage03(void)
868 ToolkitTestApplication application;
869 TestGlAbstraction& gl = application.GetGlAbstraction();
872 Property::Array urls1, urls2;
873 CopyUrlsIntoArray( urls1 );
874 CopyUrlsIntoArray( urls2 );
876 Property::Map animatedImageMap1;
877 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
878 animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
879 animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
880 animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
881 animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
883 Property::Map animatedImageMap2;
884 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
885 animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
886 animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
887 animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
888 animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
890 VisualFactory factory = VisualFactory::Get();
891 Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
893 tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
895 DummyControl dummyControl1 = DummyControl::New(true);
896 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
897 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
898 dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
899 application.GetScene().Add( dummyControl1 );
901 application.SendNotification();
902 application.Render(16);
904 tet_infoline( "Ready the requested image after the first visual is on stage" );
905 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
906 application.SendNotification();
907 application.Render(16);
908 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
910 Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
911 DummyControl dummyControl2 = DummyControl::New(true);
912 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
913 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
914 dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
915 application.GetScene().Add( dummyControl2 );
916 application.SendNotification();
917 application.Render(16);
919 tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
920 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
921 Texture t1 = ts.GetTexture( 0 );
922 DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
924 tet_infoline( "Test that on the first tick, 1 new image is requested" );
925 Test::EmitGlobalTimerSignal(); // Both visuals should tick
927 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
928 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
930 ts = dummyControl2.GetRendererAt(0).GetTextures();
931 Texture t2 = ts.GetTexture( 0 );
932 DALI_TEST_CHECK( t1 != t2 );
934 dummyControl1.Unparent();
935 dummyControl2.Unparent();
937 tet_infoline("Test that removing the visual from stage deletes all textures");
938 application.SendNotification();
939 application.Render(16);
940 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
946 int UtcDaliAnimatedImageVisualMultiImage04(void)
948 ToolkitTestApplication application;
949 TestGlAbstraction& gl = application.GetGlAbstraction();
950 TraceCallStack& textureTrace = gl.GetTextureTrace();
951 textureTrace.Enable(true);
953 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" );
955 Property::Array urls;
956 CopyUrlsIntoArray( urls );
959 Property::Map propertyMap;
960 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
961 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
962 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
963 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
964 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
966 VisualFactory factory = VisualFactory::Get();
967 Visual::Base visual = factory.CreateVisual( propertyMap );
969 tet_infoline( "Expect that a batch of 7 textures has been requested." );
971 DummyControl dummyControl = DummyControl::New(true);
972 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
973 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
975 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
976 application.GetScene().Add( dummyControl );
977 application.SendNotification();
978 application.Render(16);
980 tet_infoline( "Wait for the first batch to complete" );
981 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
983 tet_infoline( "Test that a timer has been started" );
984 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
986 application.SendNotification();
987 application.Render(16);
989 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
990 tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
991 Test::EmitGlobalTimerSignal();
992 application.SendNotification();
993 application.Render(16);
995 // Expect the second batch has been requested
996 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
998 application.SendNotification();
999 application.Render(16);
1000 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1002 tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
1004 Test::EmitGlobalTimerSignal();
1005 application.SendNotification();
1006 application.Render(16);
1007 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
1008 application.SendNotification();
1009 application.Render(16);
1010 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1012 tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
1013 Test::EmitGlobalTimerSignal();
1014 application.SendNotification();
1015 application.Render(16);
1017 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
1018 application.SendNotification();
1019 application.Render(16);
1020 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1022 dummyControl.Unparent();
1025 tet_infoline("Test that removing the visual from stage deletes all textures");
1026 application.SendNotification();
1027 application.Render(16);
1028 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1034 int UtcDaliAnimatedImageVisualMultiImage05(void)
1036 ToolkitTestApplication application;
1037 TestGlAbstraction& gl = application.GetGlAbstraction();
1039 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" );
1041 Property::Array urls;
1042 CopyUrlsIntoArray( urls );
1045 Property::Map propertyMap;
1046 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
1047 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
1048 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
1049 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
1050 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
1052 VisualFactory factory = VisualFactory::Get();
1053 Visual::Base visual = factory.CreateVisual( propertyMap );
1055 tet_infoline( "Expect that a batch of 4 textures has been requested." );
1057 DummyControl dummyControl = DummyControl::New(true);
1058 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1059 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1061 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1062 application.GetScene().Add( dummyControl );
1063 application.SendNotification();
1064 application.Render(16);
1066 tet_infoline( "Wait for the first batch to complete" );
1067 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
1069 tet_infoline( "Test that a timer has been started" );
1070 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1072 application.SendNotification();
1073 application.Render(16);
1075 tet_infoline( "Test that a timer has been started" );
1076 Test::EmitGlobalTimerSignal();
1077 application.SendNotification();
1078 application.Render(16);
1080 dummyControl.Unparent();
1083 application.SendNotification();
1084 application.Render(16);
1085 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1087 tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
1088 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
1089 application.SendNotification();
1090 application.Render(16);
1091 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1096 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
1098 TestGlAbstraction& gl = application.GetGlAbstraction();
1099 TraceCallStack& textureTrace = gl.GetTextureTrace();
1101 textureTrace.Enable(true);
1102 application.GetScene().Add( dummyControl );
1104 application.SendNotification();
1105 application.Render(16);
1107 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_INNER_LOCATION( location ) );
1109 application.SendNotification();
1110 application.Render();
1112 tet_infoline( "Test that a timer has been created" );
1113 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
1115 for ( uint16_t i = 0; i < loopCount; i++ )
1117 for ( uint16_t j = 0; j < frameCount; j++ )
1119 if( i == 0 && j == 0 )
1121 continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1123 tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
1124 Test::EmitGlobalTimerSignal();
1125 application.SendNotification();
1126 application.Render(16);
1128 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_INNER_LOCATION( location ) );
1130 application.SendNotification();
1131 application.Render();
1132 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION( location ) );
1133 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
1135 tet_printf( "Test Loop %u \n\n", i + 1u );
1138 tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
1139 Test::EmitGlobalTimerSignal();
1140 application.SendNotification();
1141 application.Render(16);
1142 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
1144 dummyControl.Unparent();
1147 int UtcDaliAnimatedImageVisualLoopCount(void)
1149 ToolkitTestApplication application;
1151 tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
1154 // request AnimatedImageVisual with a property map
1155 // Test with no (0) loop count
1156 VisualFactory factory = VisualFactory::Get();
1157 Visual::Base animatedImageVisual = factory.CreateVisual(
1159 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1160 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1161 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1162 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1163 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1164 .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
1166 DummyControl dummyControl = DummyControl::New(true);
1167 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1168 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1169 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1171 TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
1173 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1174 animatedImageVisual.Reset();
1176 application.SendNotification();
1177 application.Render(16);
1179 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1180 animatedImageVisual = factory.CreateVisual(
1182 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1183 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1184 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1185 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1186 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1187 .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
1189 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1191 TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
1193 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1194 animatedImageVisual.Reset();
1196 application.SendNotification();
1197 application.Render(16);
1199 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1200 animatedImageVisual = factory.CreateVisual(
1202 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1203 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1204 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1205 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1206 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1207 .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
1209 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1211 TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
1216 int UtcDaliAnimatedImageVisualPlayback(void)
1218 ToolkitTestApplication application;
1219 TestGlAbstraction& gl = application.GetGlAbstraction();
1220 TraceCallStack& textureTrace = gl.GetTextureTrace();
1222 tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
1225 // request AnimatedImageVisual with a property map
1226 // Test with forever (-1) loop count
1227 VisualFactory factory = VisualFactory::Get();
1228 Visual::Base animatedImageVisual = factory.CreateVisual(
1230 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1231 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1232 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1233 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1234 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1235 .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
1237 DummyControl dummyControl = DummyControl::New(true);
1238 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1239 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1240 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1242 textureTrace.Enable(true);
1243 application.GetScene().Add( dummyControl );
1244 application.SendNotification();
1245 application.Render(16);
1247 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1249 application.SendNotification();
1250 application.Render();
1252 tet_infoline( "Test that a timer has been created" );
1253 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1255 Test::EmitGlobalTimerSignal();
1256 application.SendNotification();
1257 application.Render(16);
1259 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1261 application.SendNotification();
1262 application.Render();
1263 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1265 Property::Map attributes;
1266 tet_infoline( "Test Pause action. Timer should stop after Pause action" );
1267 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
1268 Test::EmitGlobalTimerSignal();
1269 application.SendNotification();
1270 application.Render(16);
1271 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1273 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1274 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1275 Test::EmitGlobalTimerSignal();
1276 application.SendNotification();
1277 application.Render(16);
1279 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1281 application.SendNotification();
1282 application.Render();
1283 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1285 tet_infoline( "Test Stop action. Timer should stop after Stop action" );
1286 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
1287 Test::EmitGlobalTimerSignal();
1288 application.SendNotification();
1289 application.Render(16);
1290 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1292 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1293 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1294 Test::EmitGlobalTimerSignal();
1295 application.SendNotification();
1296 application.Render(16);
1298 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1300 application.SendNotification();
1301 application.Render();
1302 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1304 dummyControl.Unparent();