3 * Copyright (c) 2021 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::VECTOR4 );
94 DALI_TEST_CHECK( value );
95 DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4(22.2f, 22.2f, 22.2f, 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", Vector4(50.0f, 25.0f, 12.5f, 33.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<Vector4>(), Vector4(50.0f, 25.0f, 12.5f, 33.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<Vector4>(), Vector4(50.5f, 50.5f, 50.5f, 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 );
296 int UtcDaliAnimatedImageVisualImageLoadingFail01(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, "dummy.gif" );
305 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2 );
306 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2 );
307 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20 );
308 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
309 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS, 0.23f );
310 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE );
312 VisualFactory factory = VisualFactory::Get();
313 Visual::Base visual = factory.CreateVisual( propertyMap );
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 application.GetScene().Add( dummyControl );
322 TraceCallStack& textureTrace = gl.GetTextureTrace();
323 textureTrace.Enable(true);
325 application.SendNotification();
326 application.Render(20);
328 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
330 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
332 application.SendNotification();
333 application.Render(20);
335 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
337 dummyControl.Unparent();
343 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
345 ToolkitTestApplication application;
346 TestGlAbstraction& gl = application.GetGlAbstraction();
349 Property::Map propertyMap;
350 propertyMap.Insert( Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
351 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
352 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2 );
353 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2 );
354 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20 );
355 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
356 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS, 0.23f );
357 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE );
359 VisualFactory factory = VisualFactory::Get();
360 Visual::Base visual = factory.CreateVisual( propertyMap );
362 DummyControl dummyControl = DummyControl::New(true);
363 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
364 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
366 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
367 application.GetScene().Add( dummyControl );
369 TraceCallStack& textureTrace = gl.GetTextureTrace();
370 textureTrace.Enable(true);
372 application.SendNotification();
373 application.Render(20);
375 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
377 application.SendNotification();
378 application.Render();
380 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
381 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
383 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3 );
385 application.SendNotification();
386 application.Render(20);
388 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
390 application.SendNotification();
391 application.Render();
393 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
395 dummyControl.Unparent();
397 tet_infoline("Test that removing the visual from stage deletes all textures");
398 application.SendNotification();
399 application.Render(16);
400 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
406 int UtcDaliAnimatedImageVisualJumpToAction(void)
408 ToolkitTestApplication application;
409 TestGlAbstraction& gl = application.GetGlAbstraction();
411 Property::Array urls;
412 CopyUrlsIntoArray( urls );
415 Property::Map propertyMap;
416 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
417 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
418 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
419 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 12);
420 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
422 VisualFactory factory = VisualFactory::Get();
423 Visual::Base visual = factory.CreateVisual( propertyMap );
425 DummyControl dummyControl = DummyControl::New(true);
426 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
427 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
429 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
430 application.GetScene().Add( dummyControl );
431 application.SendNotification();
432 application.Render(20);
434 tet_infoline( "Ready the visual after the visual is on stage" );
435 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
437 tet_infoline( "Test that a timer has been started" );
438 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
440 TraceCallStack& textureTrace = gl.GetTextureTrace();
441 textureTrace.Enable(true);
443 application.SendNotification();
444 application.Render(20);
446 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
448 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
450 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
452 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20 );
454 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
456 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
458 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
459 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
461 dummyControl.Unparent();
463 tet_infoline("Test that removing the visual from stage deletes all textures");
464 application.SendNotification();
465 application.Render(16);
466 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
472 int UtcDaliAnimatedImageVisualStopBehavior(void)
474 ToolkitTestApplication application;
475 TestGlAbstraction& gl = application.GetGlAbstraction();
477 Property::Array urls;
478 CopyUrlsIntoArray( urls );
481 Property::Map propertyMap;
482 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
483 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
484 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
485 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
486 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
487 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
489 VisualFactory factory = VisualFactory::Get();
490 Visual::Base visual = factory.CreateVisual( propertyMap );
492 // Expect that a batch of 4 textures has been requested. These will be serially loaded
495 DummyControl dummyControl = DummyControl::New(true);
496 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
497 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
499 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
500 application.GetScene().Add( dummyControl );
501 application.SendNotification();
502 application.Render(20);
504 tet_infoline( "Ready the visual after the visual is on stage" );
505 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
507 tet_infoline( "Test that a timer has been started" );
508 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
510 TraceCallStack& textureTrace = gl.GetTextureTrace();
511 textureTrace.Enable(true);
513 application.SendNotification();
514 application.Render(20);
516 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
518 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
520 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
522 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1 );
524 // Expect the second batch has been requested
525 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
527 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
529 dummyControl.Unparent();
531 tet_infoline("Test that removing the visual from stage deletes all textures");
532 application.SendNotification();
533 application.Render(16);
534 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
540 int UtcDaliAnimatedImageVisualStopBehavior02(void)
542 ToolkitTestApplication application;
543 TestGlAbstraction& gl = application.GetGlAbstraction();
545 Property::Array urls;
546 CopyUrlsIntoArray( urls );
549 Property::Map propertyMap;
550 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
551 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
552 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
553 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
554 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2);
555 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
557 VisualFactory factory = VisualFactory::Get();
558 Visual::Base visual = factory.CreateVisual( propertyMap );
560 // Expect that a batch of 4 textures has been requested. These will be serially loaded
563 DummyControl dummyControl = DummyControl::New(true);
564 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
565 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
567 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
568 application.GetScene().Add( dummyControl );
570 tet_infoline( "Ready the visual after the visual is on stage" );
571 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
573 TraceCallStack& textureTrace = gl.GetTextureTrace();
574 textureTrace.Enable(true);
576 application.SendNotification();
577 application.Render(20);
579 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
581 Test::EmitGlobalTimerSignal();
583 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
585 application.SendNotification();
586 application.Render(20);
588 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
590 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
592 tet_infoline( "Ready the visual after the visual is on stage" );
593 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
595 application.SendNotification();
596 application.Render(20);
598 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
600 dummyControl.Unparent();
602 tet_infoline("Test that removing the visual from stage deletes all textures");
603 application.SendNotification();
604 application.Render(16);
605 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
611 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
613 ToolkitTestApplication application;
614 TestGlAbstraction& gl = application.GetGlAbstraction();
617 Property::Map propertyMap;
618 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
619 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
620 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
621 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 4);
622 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
624 VisualFactory factory = VisualFactory::Get();
625 Visual::Base visual = factory.CreateVisual( propertyMap );
627 // Expect that a batch of 4 textures has been requested. These will be serially loaded
630 DummyControl dummyControl = DummyControl::New(true);
631 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
632 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
634 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
635 application.GetScene().Add( dummyControl );
637 application.SendNotification();
638 application.Render();
640 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
642 application.SendNotification();
643 application.Render(20);
645 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
647 tet_infoline( "Test that a timer has been started" );
649 TraceCallStack& textureTrace = gl.GetTextureTrace();
650 textureTrace.Enable(true);
652 Test::EmitGlobalTimerSignal();
654 application.SendNotification();
655 application.Render();
657 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
659 application.SendNotification();
660 application.Render(20);
662 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
664 dummyControl.Unparent();
666 tet_infoline("Test that removing the visual from stage deletes all textures");
667 application.SendNotification();
668 application.Render(20);
669 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
675 int UtcDaliAnimatedImageVisualMultiImage01(void)
677 ToolkitTestApplication application;
678 TestGlAbstraction& gl = application.GetGlAbstraction();
680 Property::Array urls;
681 CopyUrlsIntoArray( urls );
684 Property::Map propertyMap;
685 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
686 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
687 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
688 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
689 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
691 VisualFactory factory = VisualFactory::Get();
692 Visual::Base visual = factory.CreateVisual( propertyMap );
694 // Expect that a batch of 4 textures has been requested. These will be serially loaded
697 DummyControl dummyControl = DummyControl::New(true);
698 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
699 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
701 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
702 application.GetScene().Add( dummyControl );
703 application.SendNotification();
704 application.Render(16);
706 tet_infoline( "Ready the visual after the visual is on stage" );
707 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
709 tet_infoline( "Test that a timer has been started" );
710 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
712 TraceCallStack& textureTrace = gl.GetTextureTrace();
713 textureTrace.Enable(true);
715 application.SendNotification();
716 application.Render(16);
718 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
719 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
721 tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
722 Test::EmitGlobalTimerSignal();
724 // Expect the second batch has been requested
725 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
727 application.SendNotification();
728 application.Render(16);
729 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
732 tet_infoline( "Test that after 2 ticks that we have 6 textures" );
734 Test::EmitGlobalTimerSignal();
735 application.SendNotification();
736 application.Render(16);
737 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
739 tet_infoline("And that at least 2 textures were requested");
740 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
741 application.SendNotification();
742 application.Render(16);
743 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
746 tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
747 Test::EmitGlobalTimerSignal();
748 application.SendNotification();
749 application.Render(16);
750 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
752 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
753 application.SendNotification();
754 application.Render(16);
755 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
757 dummyControl.Unparent();
759 tet_infoline("Test that removing the visual from stage deletes all textures");
760 application.SendNotification();
761 application.Render(16);
762 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
767 int UtcDaliAnimatedImageVisualMultiImage02(void)
769 ToolkitTestApplication application;
770 TestGlAbstraction& gl = application.GetGlAbstraction();
772 tet_infoline( "Test that the animated visual has different batch and cache size." );
775 Property::Array urls;
776 CopyUrlsIntoArray( urls );
778 Property::Map propertyMap;
779 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
780 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
781 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
782 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
783 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
785 VisualFactory factory = VisualFactory::Get();
786 Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
788 // Check the batch size and cache size need to have minimum 2.
789 Property::Map resultMap;
790 visual.CreatePropertyMap( resultMap );
791 Property::Value* value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
792 DALI_TEST_CHECK( value );
793 DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
794 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
795 DALI_TEST_CHECK( value );
796 DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
799 // Batch size is 2 and cache size is 3
801 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
802 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
803 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
804 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 3);
805 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
807 visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
809 // Expect that each image is loaded each tick
810 DummyControl dummyControl = DummyControl::New(true);
811 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
812 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
815 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
816 application.GetScene().Add( dummyControl );
817 application.SendNotification();
818 application.Render(16);
820 tet_infoline( "Ready the visual after the visual is on window" );
821 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
822 application.SendNotification();
823 application.Render(16);//glGenTextures 1 and 2
824 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
826 tet_infoline( "Test that each tick, a new image is requested" );
827 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
828 application.SendNotification();
829 application.Render(16);
830 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
831 application.SendNotification();
832 application.Render(16);//glGenTextures 3
833 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
835 tet_infoline( "Test that each tick, a new image is requested" );
836 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
837 application.SendNotification();
838 application.Render(16);
839 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
840 application.SendNotification();
841 application.Render(16);//glGenTextures 4
842 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
844 dummyImpl1.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
845 dummyControl.Unparent();
848 // Batch size is 9 and cache size is 4
850 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
851 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
852 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 3);
853 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 7);
854 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
856 visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
858 // Expect that each image is loaded each tick
859 dummyControl = DummyControl::New(true);
860 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
861 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
864 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
865 application.GetScene().Add( dummyControl );
866 application.SendNotification();
867 application.Render(16);
869 tet_infoline( "Ready the visual after the visual is on window" );
870 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
871 application.SendNotification();
872 application.Render(16);//glGenTextures 1, 2, and 3
873 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
875 tet_infoline( "Test that each tick, a new image is requested" );
876 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
877 application.SendNotification();
878 application.Render(16);
879 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
880 application.SendNotification();
881 application.Render(16);//glGenTextures 4, 5, and 6
882 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 5, TEST_LOCATION );
884 tet_infoline( "Test that each tick, a new image is requested" );
885 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
886 application.SendNotification();
887 application.Render(16);
888 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
889 application.SendNotification();
890 application.Render(16);//glGenTextures 7, 1, and 2
891 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
893 tet_infoline( "Test that each tick, a new image is requested" );
894 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
895 application.SendNotification();
896 application.Render(16);
897 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
898 application.SendNotification();
899 application.Render(16);//glGenTextures 3
900 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
902 dummyControl.Unparent();
904 tet_infoline("Test that removing the visual from window deletes all textures");
905 application.SendNotification();
906 application.Render(16);
907 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
912 int UtcDaliAnimatedImageVisualMultiImage03(void)
914 ToolkitTestApplication application;
915 TestGlAbstraction& gl = application.GetGlAbstraction();
918 Property::Array urls1, urls2;
919 CopyUrlsIntoArray( urls1 );
920 CopyUrlsIntoArray( urls2 );
922 Property::Map animatedImageMap1;
923 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
924 animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
925 animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
926 animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
927 animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
929 Property::Map animatedImageMap2;
930 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
931 animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
932 animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
933 animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
934 animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
936 VisualFactory factory = VisualFactory::Get();
937 Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
939 tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
941 DummyControl dummyControl1 = DummyControl::New(true);
942 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
943 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
944 dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
945 application.GetScene().Add( dummyControl1 );
947 application.SendNotification();
948 application.Render(16);
950 tet_infoline( "Ready the requested image after the first visual is on stage" );
951 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
952 application.SendNotification();
953 application.Render(16);
954 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
956 Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
957 DummyControl dummyControl2 = DummyControl::New(true);
958 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
959 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
960 dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
961 application.GetScene().Add( dummyControl2 );
962 application.SendNotification();
963 application.Render(16);
965 tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
966 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
967 Texture t1 = ts.GetTexture( 0 );
968 DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
970 tet_infoline( "Test that on the first tick, 1 new image is requested" );
971 Test::EmitGlobalTimerSignal(); // Both visuals should tick
973 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
974 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
976 ts = dummyControl2.GetRendererAt(0).GetTextures();
977 Texture t2 = ts.GetTexture( 0 );
978 DALI_TEST_CHECK( t1 != t2 );
980 dummyControl1.Unparent();
981 dummyControl2.Unparent();
983 tet_infoline("Test that removing the visual from stage deletes all textures");
984 application.SendNotification();
985 application.Render(16);
986 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
992 int UtcDaliAnimatedImageVisualMultiImage04(void)
994 ToolkitTestApplication application;
995 TestGlAbstraction& gl = application.GetGlAbstraction();
996 TraceCallStack& textureTrace = gl.GetTextureTrace();
997 textureTrace.Enable(true);
999 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" );
1001 Property::Array urls;
1002 CopyUrlsIntoArray( urls );
1005 Property::Map propertyMap;
1006 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
1007 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
1008 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
1009 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
1010 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
1012 VisualFactory factory = VisualFactory::Get();
1013 Visual::Base visual = factory.CreateVisual( propertyMap );
1015 tet_infoline( "Expect that a batch of 7 textures has been requested." );
1017 DummyControl dummyControl = DummyControl::New(true);
1018 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1019 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1021 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1022 application.GetScene().Add( dummyControl );
1023 application.SendNotification();
1024 application.Render(16);
1026 tet_infoline( "Wait for the first batch to complete" );
1027 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
1029 tet_infoline( "Test that a timer has been started" );
1030 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1032 application.SendNotification();
1033 application.Render(16);
1035 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
1036 tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
1037 Test::EmitGlobalTimerSignal();
1038 application.SendNotification();
1039 application.Render(16);
1041 // Expect the second batch has been requested
1042 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
1044 application.SendNotification();
1045 application.Render(16);
1046 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1048 tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
1050 Test::EmitGlobalTimerSignal();
1051 application.SendNotification();
1052 application.Render(16);
1053 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
1054 application.SendNotification();
1055 application.Render(16);
1056 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1058 tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
1059 Test::EmitGlobalTimerSignal();
1060 application.SendNotification();
1061 application.Render(16);
1063 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
1064 application.SendNotification();
1065 application.Render(16);
1066 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1068 dummyControl.Unparent();
1071 tet_infoline("Test that removing the visual from stage deletes all textures");
1072 application.SendNotification();
1073 application.Render(16);
1074 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1080 int UtcDaliAnimatedImageVisualMultiImage05(void)
1082 ToolkitTestApplication application;
1083 TestGlAbstraction& gl = application.GetGlAbstraction();
1085 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" );
1087 Property::Array urls;
1088 CopyUrlsIntoArray( urls );
1091 Property::Map propertyMap;
1092 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
1093 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
1094 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
1095 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
1096 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
1098 VisualFactory factory = VisualFactory::Get();
1099 Visual::Base visual = factory.CreateVisual( propertyMap );
1101 tet_infoline( "Expect that a batch of 4 textures has been requested." );
1103 DummyControl dummyControl = DummyControl::New(true);
1104 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1105 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1107 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1108 application.GetScene().Add( dummyControl );
1109 application.SendNotification();
1110 application.Render(16);
1112 tet_infoline( "Wait for the first batch to complete" );
1113 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
1115 tet_infoline( "Test that a timer has been started" );
1116 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1118 application.SendNotification();
1119 application.Render(16);
1121 tet_infoline( "Test that a timer has been started" );
1122 Test::EmitGlobalTimerSignal();
1123 application.SendNotification();
1124 application.Render(16);
1126 dummyControl.Unparent();
1129 application.SendNotification();
1130 application.Render(16);
1131 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1133 tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
1134 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
1135 application.SendNotification();
1136 application.Render(16);
1137 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1142 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
1144 TestGlAbstraction& gl = application.GetGlAbstraction();
1145 TraceCallStack& textureTrace = gl.GetTextureTrace();
1147 textureTrace.Enable(true);
1148 application.GetScene().Add( dummyControl );
1150 application.SendNotification();
1151 application.Render(16);
1153 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_INNER_LOCATION( location ) );
1155 application.SendNotification();
1156 application.Render();
1158 tet_infoline( "Test that a timer has been created" );
1159 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
1161 for ( uint16_t i = 0; i < loopCount; i++ )
1163 for ( uint16_t j = 0; j < frameCount; j++ )
1165 if( i == 0 && j == 0 )
1167 continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1169 tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
1170 Test::EmitGlobalTimerSignal();
1171 application.SendNotification();
1172 application.Render(16);
1174 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_INNER_LOCATION( location ) );
1176 application.SendNotification();
1177 application.Render();
1178 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION( location ) );
1179 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
1181 tet_printf( "Test Loop %u \n\n", i + 1u );
1184 tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
1185 Test::EmitGlobalTimerSignal();
1186 application.SendNotification();
1187 application.Render(16);
1188 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
1190 dummyControl.Unparent();
1193 int UtcDaliAnimatedImageVisualLoopCount(void)
1195 ToolkitTestApplication application;
1197 tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
1200 // request AnimatedImageVisual with a property map
1201 // Test with no (0) loop count
1202 VisualFactory factory = VisualFactory::Get();
1203 Visual::Base animatedImageVisual = factory.CreateVisual(
1205 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1206 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1207 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1208 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1209 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1210 .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
1212 DummyControl dummyControl = DummyControl::New(true);
1213 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1214 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1215 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1217 TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
1219 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1220 animatedImageVisual.Reset();
1222 application.SendNotification();
1223 application.Render(16);
1225 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1226 animatedImageVisual = factory.CreateVisual(
1228 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1229 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1230 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1231 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1232 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1233 .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
1235 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1237 TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
1239 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1240 animatedImageVisual.Reset();
1242 application.SendNotification();
1243 application.Render(16);
1245 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1246 animatedImageVisual = factory.CreateVisual(
1248 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1249 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1250 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1251 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1252 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1253 .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
1255 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1257 TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
1262 int UtcDaliAnimatedImageVisualPlayback(void)
1264 ToolkitTestApplication application;
1265 TestGlAbstraction& gl = application.GetGlAbstraction();
1266 TraceCallStack& textureTrace = gl.GetTextureTrace();
1268 tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
1271 // request AnimatedImageVisual with a property map
1272 // Test with forever (-1) loop count
1273 VisualFactory factory = VisualFactory::Get();
1274 Visual::Base animatedImageVisual = factory.CreateVisual(
1276 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1277 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1278 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1279 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1280 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1281 .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
1283 DummyControl dummyControl = DummyControl::New(true);
1284 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1285 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1286 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1288 textureTrace.Enable(true);
1289 application.GetScene().Add( dummyControl );
1290 application.SendNotification();
1291 application.Render(16);
1293 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1295 application.SendNotification();
1296 application.Render();
1298 tet_infoline( "Test that a timer has been created" );
1299 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1301 Test::EmitGlobalTimerSignal();
1302 application.SendNotification();
1303 application.Render(16);
1305 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1307 application.SendNotification();
1308 application.Render();
1309 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1311 Property::Map attributes;
1312 tet_infoline( "Test Pause action. Timer should stop after Pause action" );
1313 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
1314 Test::EmitGlobalTimerSignal();
1315 application.SendNotification();
1316 application.Render(16);
1317 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1319 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1320 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1321 Test::EmitGlobalTimerSignal();
1322 application.SendNotification();
1323 application.Render(16);
1325 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1327 application.SendNotification();
1328 application.Render();
1329 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1331 tet_infoline( "Test Stop action. Timer should stop after Stop action" );
1332 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
1333 Test::EmitGlobalTimerSignal();
1334 application.SendNotification();
1335 application.Render(16);
1336 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1338 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1339 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1340 Test::EmitGlobalTimerSignal();
1341 application.SendNotification();
1342 application.Render(16);
1344 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1346 application.SendNotification();
1347 application.Render();
1348 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1350 dummyControl.Unparent();