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 )
81 .Add( DevelVisual::Property::BORDERLINE_WIDTH, 33.3f )
82 .Add( DevelVisual::Property::BORDERLINE_COLOR, Color::RED )
83 .Add( DevelVisual::Property::BORDERLINE_OFFSET, 0.3f ));
85 Property::Map resultMap;
86 animatedImageVisual.CreatePropertyMap( resultMap );
87 // check the property values from the returned map from a visual
88 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
89 DALI_TEST_CHECK( value );
90 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
92 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
93 DALI_TEST_CHECK( value );
94 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
96 value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4 );
97 DALI_TEST_CHECK( value );
98 DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4(22.2f, 22.2f, 22.2f, 22.2f), TEST_LOCATION );
100 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER );
101 DALI_TEST_CHECK( value );
102 DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::ABSOLUTE );
104 value = resultMap.Find( DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT );
105 DALI_TEST_CHECK( value );
106 DALI_TEST_EQUALS( value->Get<float>(), 33.3f, TEST_LOCATION );
108 value = resultMap.Find( DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4 );
109 DALI_TEST_CHECK( value );
110 DALI_TEST_EQUALS( value->Get<Vector4>(), Color::RED, TEST_LOCATION );
112 value = resultMap.Find( DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT );
113 DALI_TEST_CHECK( value );
114 DALI_TEST_EQUALS( value->Get<float>(), 0.3f, TEST_LOCATION );
116 // request AnimatedImageVisual with an URL
117 Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
119 animatedImageVisual2.CreatePropertyMap( resultMap );
120 // check the property values from the returned map from a visual
121 value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
122 DALI_TEST_CHECK( value );
123 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
125 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
126 DALI_TEST_CHECK( value );
127 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
133 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
135 ToolkitTestApplication application;
136 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap for multi image with fixed cache" );
138 // request AnimatedImageVisual with a property map
139 VisualFactory factory = VisualFactory::Get();
140 Property::Array urls;
141 CopyUrlsIntoArray( urls );
143 Visual::Base animatedImageVisual = factory.CreateVisual(
145 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
147 .Add( "batchSize", 4 )
148 .Add( "cacheSize", 20 )
149 .Add( "loopCount", 10 )
150 .Add( "frameDelay", 200 )
151 .Add( "pixelArea", Vector4() )
152 .Add( "wrapModeU", WrapMode::REPEAT )
153 .Add( "wrapModeV", WrapMode::DEFAULT )
154 .Add( "cornerRadius", Vector4(50.0f, 25.0f, 12.5f, 33.0f) )
155 .Add( "cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE )
156 .Add( "borderlineWidth", 20.0f )
157 .Add( "borderlineColor", Vector4() )
158 .Add( "borderlineOffset", -1.0f));
160 Property::Map resultMap;
161 animatedImageVisual.CreatePropertyMap( resultMap );
162 // check the property values from the returned map from a visual
163 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
164 DALI_TEST_CHECK( value );
165 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
167 value = resultMap.Find( ImageVisual::Property::URL, "url" );
168 DALI_TEST_CHECK( value );
169 Property::Array* resultUrls = value->GetArray();
170 DALI_TEST_CHECK( resultUrls );
171 DALI_TEST_EQUALS( resultUrls->Count(), urls.Count(), TEST_LOCATION );
173 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
174 DALI_TEST_CHECK( value );
175 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
177 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
178 DALI_TEST_CHECK( value );
179 DALI_TEST_EQUALS( value->Get<int>(), 20, TEST_LOCATION );
181 value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
182 DALI_TEST_CHECK( value );
183 DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
185 value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
186 DALI_TEST_CHECK( value );
187 DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
189 value = resultMap.Find( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber" );
190 DALI_TEST_CHECK( value );
191 DALI_TEST_EQUALS( value->Get<int>(), 11, TEST_LOCATION );
193 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" );
194 DALI_TEST_CHECK( value );
195 DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4(50.0f, 25.0f, 12.5f, 33.0f), TEST_LOCATION );
197 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
198 DALI_TEST_CHECK( value );
199 DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::RELATIVE );
201 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth" );
202 DALI_TEST_CHECK( value );
203 DALI_TEST_EQUALS( value->Get<float>(), 20.0f, TEST_LOCATION );
205 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor" );
206 DALI_TEST_CHECK( value );
207 DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4::ZERO, TEST_LOCATION );
209 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset" );
210 DALI_TEST_CHECK( value );
211 DALI_TEST_EQUALS( value->Get<float>(), -1.0f, TEST_LOCATION );
217 int UtcDaliAnimatedImageVisualGetPropertyMap03(void)
219 ToolkitTestApplication application;
220 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap for multi image rolling cache" );
222 // request AnimatedImageVisual with a property map
223 VisualFactory factory = VisualFactory::Get();
224 Property::Array urls;
225 CopyUrlsIntoArray( urls );
227 Visual::Base animatedImageVisual = factory.CreateVisual(
229 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
231 .Add( "batchSize", 4 )
232 .Add( "cacheSize", 8 )
233 .Add( "loopCount", 10 )
234 .Add( "frameDelay", 200 )
235 .Add( "pixelArea", Vector4() )
236 .Add( "wrapModeU", WrapMode::REPEAT )
237 .Add( "wrapModeV", WrapMode::DEFAULT )
238 .Add( "cornerRadius", 50.5f ));
240 Property::Map resultMap;
241 animatedImageVisual.CreatePropertyMap( resultMap );
242 // check the property values from the returned map from a visual
243 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
244 DALI_TEST_CHECK( value );
245 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
247 value = resultMap.Find( ImageVisual::Property::URL, "url" );
248 DALI_TEST_CHECK( value );
249 Property::Array* resultUrls = value->GetArray();
250 DALI_TEST_CHECK( resultUrls );
251 DALI_TEST_EQUALS( resultUrls->Count(), urls.Count(), TEST_LOCATION );
253 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
254 DALI_TEST_CHECK( value );
255 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
257 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
258 DALI_TEST_CHECK( value );
259 DALI_TEST_EQUALS( value->Get<int>(), 8, TEST_LOCATION );
261 value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
262 DALI_TEST_CHECK( value );
263 DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
265 value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
266 DALI_TEST_CHECK( value );
267 DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
269 value = resultMap.Find( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber" );
270 DALI_TEST_CHECK( value );
271 DALI_TEST_EQUALS( value->Get<int>(), 11, TEST_LOCATION );
273 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" );
274 DALI_TEST_CHECK( value );
275 DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4(50.5f, 50.5f, 50.5f, 50.5f), TEST_LOCATION );
277 value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
278 DALI_TEST_CHECK( value );
279 DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::ABSOLUTE );
281 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth" );
282 DALI_TEST_CHECK( value );
283 DALI_TEST_EQUALS( value->Get<float>(), 0.0f, TEST_LOCATION );
285 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor" );
286 DALI_TEST_CHECK( value );
287 DALI_TEST_EQUALS( value->Get<Vector4>(), Color::BLACK, TEST_LOCATION );
289 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset" );
290 DALI_TEST_CHECK( value );
291 DALI_TEST_EQUALS( value->Get<float>(), 0.0f, TEST_LOCATION );
296 int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
298 ToolkitTestApplication application;
299 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
301 // request AnimatedImageVisual with a property map
302 VisualFactory factory = VisualFactory::Get();
303 Visual::Base animatedImageVisual = factory.CreateVisual(
305 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
306 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
307 .Add( ImageVisual::Property::BATCH_SIZE, 1 )
308 .Add( ImageVisual::Property::CACHE_SIZE, 1 )
309 .Add( ImageVisual::Property::SYNCHRONOUS_LOADING, false )
310 .Add( DevelVisual::Property::BORDERLINE_WIDTH, 0.4f ));
312 Property::Map resultMap;
313 animatedImageVisual.CreatePropertyMap( resultMap );
315 // check the property values from the returned map from a visual
316 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
317 DALI_TEST_CHECK( value );
318 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
320 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
321 DALI_TEST_CHECK( value );
322 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
324 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, Property::INTEGER );
325 DALI_TEST_CHECK( value );
326 DALI_TEST_CHECK( value->Get<int>() == 2 );
328 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, Property::INTEGER );
329 DALI_TEST_CHECK( value );
330 DALI_TEST_CHECK( value->Get<int>() == 2 );
332 value = resultMap.Find( Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber" );
333 DALI_TEST_CHECK( value );
334 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
336 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth" );
337 DALI_TEST_CHECK( value );
338 DALI_TEST_EQUALS( value->Get<float>(), 0.4f, TEST_LOCATION );
340 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor" );
341 DALI_TEST_CHECK( value );
342 DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION );
344 value = resultMap.Find( Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset" );
345 DALI_TEST_CHECK( value );
346 DALI_TEST_EQUALS( value->Get<float>(), 0.0f, TEST_LOCATION );
351 int UtcDaliAnimatedImageVisualImageLoadingFail01(void)
353 ToolkitTestApplication application;
354 TestGlAbstraction& gl = application.GetGlAbstraction();
357 Property::Map propertyMap;
358 propertyMap.Insert( Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
359 propertyMap.Insert( ImageVisual::Property::URL, "dummy.gif" );
360 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2 );
361 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2 );
362 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20 );
363 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
364 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS, 0.23f );
365 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE );
367 VisualFactory factory = VisualFactory::Get();
368 Visual::Base visual = factory.CreateVisual( propertyMap );
370 DummyControl dummyControl = DummyControl::New(true);
371 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
372 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
374 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
375 application.GetScene().Add( dummyControl );
377 TraceCallStack& textureTrace = gl.GetTextureTrace();
378 textureTrace.Enable(true);
380 application.SendNotification();
381 application.Render(20);
383 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
385 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
387 application.SendNotification();
388 application.Render(20);
390 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
392 dummyControl.Unparent();
398 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
400 ToolkitTestApplication application;
401 TestGlAbstraction& gl = application.GetGlAbstraction();
404 Property::Map propertyMap;
405 propertyMap.Insert( Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
406 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
407 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2 );
408 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2 );
409 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20 );
410 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
411 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS, 0.23f );
412 propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE );
414 VisualFactory factory = VisualFactory::Get();
415 Visual::Base visual = factory.CreateVisual( propertyMap );
417 DummyControl dummyControl = DummyControl::New(true);
418 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
419 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
421 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
422 application.GetScene().Add( dummyControl );
424 TraceCallStack& textureTrace = gl.GetTextureTrace();
425 textureTrace.Enable(true);
427 application.SendNotification();
428 application.Render(20);
430 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
432 application.SendNotification();
433 application.Render();
435 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
436 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
438 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3 );
440 application.SendNotification();
441 application.Render(20);
443 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
445 application.SendNotification();
446 application.Render();
448 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
450 dummyControl.Unparent();
452 tet_infoline("Test that removing the visual from stage deletes all textures");
453 application.SendNotification();
454 application.Render(16);
455 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
461 int UtcDaliAnimatedImageVisualJumpToAction(void)
463 ToolkitTestApplication application;
464 TestGlAbstraction& gl = application.GetGlAbstraction();
466 Property::Array urls;
467 CopyUrlsIntoArray( urls );
470 Property::Map propertyMap;
471 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
472 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
473 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
474 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 12);
475 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
477 VisualFactory factory = VisualFactory::Get();
478 Visual::Base visual = factory.CreateVisual( propertyMap );
480 DummyControl dummyControl = DummyControl::New(true);
481 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
482 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
484 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
485 application.GetScene().Add( dummyControl );
486 application.SendNotification();
487 application.Render(20);
489 tet_infoline( "Ready the visual after the visual is on stage" );
490 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
492 tet_infoline( "Test that a timer has been started" );
493 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
495 TraceCallStack& textureTrace = gl.GetTextureTrace();
496 textureTrace.Enable(true);
498 application.SendNotification();
499 application.Render(20);
501 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
503 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
505 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
507 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20 );
509 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
511 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
513 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
514 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
516 dummyControl.Unparent();
518 tet_infoline("Test that removing the visual from stage deletes all textures");
519 application.SendNotification();
520 application.Render(16);
521 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
527 int UtcDaliAnimatedImageVisualStopBehavior(void)
529 ToolkitTestApplication application;
530 TestGlAbstraction& gl = application.GetGlAbstraction();
532 Property::Array urls;
533 CopyUrlsIntoArray( urls );
536 Property::Map propertyMap;
537 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
538 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
539 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
540 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
541 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
542 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
544 VisualFactory factory = VisualFactory::Get();
545 Visual::Base visual = factory.CreateVisual( propertyMap );
547 // Expect that a batch of 4 textures has been requested. These will be serially loaded
550 DummyControl dummyControl = DummyControl::New(true);
551 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
552 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
554 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
555 application.GetScene().Add( dummyControl );
556 application.SendNotification();
557 application.Render(20);
559 tet_infoline( "Ready the visual after the visual is on stage" );
560 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
562 tet_infoline( "Test that a timer has been started" );
563 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
565 TraceCallStack& textureTrace = gl.GetTextureTrace();
566 textureTrace.Enable(true);
568 application.SendNotification();
569 application.Render(20);
571 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
573 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
575 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
577 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1 );
579 // Expect the second batch has been requested
580 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
582 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
584 dummyControl.Unparent();
586 tet_infoline("Test that removing the visual from stage deletes all textures");
587 application.SendNotification();
588 application.Render(16);
589 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
595 int UtcDaliAnimatedImageVisualStopBehavior02(void)
597 ToolkitTestApplication application;
598 TestGlAbstraction& gl = application.GetGlAbstraction();
600 Property::Array urls;
601 CopyUrlsIntoArray( urls );
604 Property::Map propertyMap;
605 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
606 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
607 propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
608 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
609 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2);
610 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
612 VisualFactory factory = VisualFactory::Get();
613 Visual::Base visual = factory.CreateVisual( propertyMap );
615 // Expect that a batch of 4 textures has been requested. These will be serially loaded
618 DummyControl dummyControl = DummyControl::New(true);
619 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
620 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
622 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
623 application.GetScene().Add( dummyControl );
625 tet_infoline( "Ready the visual after the visual is on stage" );
626 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
628 TraceCallStack& textureTrace = gl.GetTextureTrace();
629 textureTrace.Enable(true);
631 application.SendNotification();
632 application.Render(20);
634 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
636 Test::EmitGlobalTimerSignal();
638 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
640 application.SendNotification();
641 application.Render(20);
643 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
645 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
647 tet_infoline( "Ready the visual after the visual is on stage" );
648 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
650 application.SendNotification();
651 application.Render(20);
653 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
655 dummyControl.Unparent();
657 tet_infoline("Test that removing the visual from stage deletes all textures");
658 application.SendNotification();
659 application.Render(16);
660 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
666 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
668 ToolkitTestApplication application;
669 TestGlAbstraction& gl = application.GetGlAbstraction();
672 Property::Map propertyMap;
673 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
674 propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
675 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
676 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 4);
677 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
679 VisualFactory factory = VisualFactory::Get();
680 Visual::Base visual = factory.CreateVisual( propertyMap );
682 // Expect that a batch of 4 textures has been requested. These will be serially loaded
685 DummyControl dummyControl = DummyControl::New(true);
686 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
687 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
689 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
690 application.GetScene().Add( dummyControl );
692 application.SendNotification();
693 application.Render();
695 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
697 application.SendNotification();
698 application.Render(20);
700 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
702 tet_infoline( "Test that a timer has been started" );
704 TraceCallStack& textureTrace = gl.GetTextureTrace();
705 textureTrace.Enable(true);
707 Test::EmitGlobalTimerSignal();
709 application.SendNotification();
710 application.Render();
712 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
714 application.SendNotification();
715 application.Render(20);
717 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
719 dummyControl.Unparent();
721 tet_infoline("Test that removing the visual from stage deletes all textures");
722 application.SendNotification();
723 application.Render(20);
724 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
730 int UtcDaliAnimatedImageVisualMultiImage01(void)
732 ToolkitTestApplication application;
733 TestGlAbstraction& gl = application.GetGlAbstraction();
735 Property::Array urls;
736 CopyUrlsIntoArray( urls );
739 Property::Map propertyMap;
740 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
741 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
742 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
743 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
744 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
746 VisualFactory factory = VisualFactory::Get();
747 Visual::Base visual = factory.CreateVisual( propertyMap );
749 // Expect that a batch of 4 textures has been requested. These will be serially loaded
752 DummyControl dummyControl = DummyControl::New(true);
753 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
754 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
756 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
757 application.GetScene().Add( dummyControl );
758 application.SendNotification();
759 application.Render(16);
761 tet_infoline( "Ready the visual after the visual is on stage" );
762 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
764 tet_infoline( "Test that a timer has been started" );
765 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
767 TraceCallStack& textureTrace = gl.GetTextureTrace();
768 textureTrace.Enable(true);
770 application.SendNotification();
771 application.Render(16);
773 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
774 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
776 tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
777 Test::EmitGlobalTimerSignal();
779 // Expect the second batch has been requested
780 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
782 application.SendNotification();
783 application.Render(16);
784 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
787 tet_infoline( "Test that after 2 ticks that we have 6 textures" );
789 Test::EmitGlobalTimerSignal();
790 application.SendNotification();
791 application.Render(16);
792 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
794 tet_infoline("And that at least 2 textures were requested");
795 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
796 application.SendNotification();
797 application.Render(16);
798 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
801 tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
802 Test::EmitGlobalTimerSignal();
803 application.SendNotification();
804 application.Render(16);
805 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
807 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
808 application.SendNotification();
809 application.Render(16);
810 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
812 dummyControl.Unparent();
814 tet_infoline("Test that removing the visual from stage deletes all textures");
815 application.SendNotification();
816 application.Render(16);
817 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
822 int UtcDaliAnimatedImageVisualMultiImage02(void)
824 ToolkitTestApplication application;
825 TestGlAbstraction& gl = application.GetGlAbstraction();
827 tet_infoline( "Test that the animated visual has different batch and cache size." );
830 Property::Array urls;
831 CopyUrlsIntoArray( urls );
833 Property::Map propertyMap;
834 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
835 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
836 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
837 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
838 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
840 VisualFactory factory = VisualFactory::Get();
841 Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
843 // Check the batch size and cache size need to have minimum 2.
844 Property::Map resultMap;
845 visual.CreatePropertyMap( resultMap );
846 Property::Value* value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
847 DALI_TEST_CHECK( value );
848 DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
849 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
850 DALI_TEST_CHECK( value );
851 DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
854 // Batch size is 2 and cache size is 3
856 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
857 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
858 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
859 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 3);
860 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
862 visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
864 // Expect that each image is loaded each tick
865 DummyControl dummyControl = DummyControl::New(true);
866 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
867 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
870 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
871 application.GetScene().Add( dummyControl );
872 application.SendNotification();
873 application.Render(16);
875 tet_infoline( "Ready the visual after the visual is on window" );
876 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
877 application.SendNotification();
878 application.Render(16);//glGenTextures 1 and 2
879 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
881 tet_infoline( "Test that each tick, a new image is requested" );
882 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
883 application.SendNotification();
884 application.Render(16);
885 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
886 application.SendNotification();
887 application.Render(16);//glGenTextures 3
888 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
890 tet_infoline( "Test that each tick, a new image is requested" );
891 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
892 application.SendNotification();
893 application.Render(16);
894 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
895 application.SendNotification();
896 application.Render(16);//glGenTextures 4
897 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
899 dummyImpl1.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
900 dummyControl.Unparent();
903 // Batch size is 9 and cache size is 4
905 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
906 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
907 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 3);
908 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 7);
909 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
911 visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
913 // Expect that each image is loaded each tick
914 dummyControl = DummyControl::New(true);
915 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
916 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
919 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
920 application.GetScene().Add( dummyControl );
921 application.SendNotification();
922 application.Render(16);
924 tet_infoline( "Ready the visual after the visual is on window" );
925 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
926 application.SendNotification();
927 application.Render(16);//glGenTextures 1, 2, and 3
928 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
930 tet_infoline( "Test that each tick, a new image is requested" );
931 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
932 application.SendNotification();
933 application.Render(16);
934 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
935 application.SendNotification();
936 application.Render(16);//glGenTextures 4, 5, and 6
937 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 5, TEST_LOCATION );
939 tet_infoline( "Test that each tick, a new image is requested" );
940 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
941 application.SendNotification();
942 application.Render(16);
943 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
944 application.SendNotification();
945 application.Render(16);//glGenTextures 7, 1, and 2
946 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
948 tet_infoline( "Test that each tick, a new image is requested" );
949 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
950 application.SendNotification();
951 application.Render(16);
952 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
953 application.SendNotification();
954 application.Render(16);//glGenTextures 3
955 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
957 dummyControl.Unparent();
959 tet_infoline("Test that removing the visual from window deletes all textures");
960 application.SendNotification();
961 application.Render(16);
962 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
967 int UtcDaliAnimatedImageVisualMultiImage03(void)
969 ToolkitTestApplication application;
970 TestGlAbstraction& gl = application.GetGlAbstraction();
973 Property::Array urls1, urls2;
974 CopyUrlsIntoArray( urls1 );
975 CopyUrlsIntoArray( urls2 );
977 Property::Map animatedImageMap1;
978 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
979 animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
980 animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
981 animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
982 animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
984 Property::Map animatedImageMap2;
985 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
986 animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
987 animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
988 animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
989 animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
991 VisualFactory factory = VisualFactory::Get();
992 Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
994 tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
996 DummyControl dummyControl1 = DummyControl::New(true);
997 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
998 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
999 dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1000 application.GetScene().Add( dummyControl1 );
1002 application.SendNotification();
1003 application.Render(16);
1005 tet_infoline( "Ready the requested image after the first visual is on stage" );
1006 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1007 application.SendNotification();
1008 application.Render(16);
1009 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
1011 Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
1012 DummyControl dummyControl2 = DummyControl::New(true);
1013 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
1014 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
1015 dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1016 application.GetScene().Add( dummyControl2 );
1017 application.SendNotification();
1018 application.Render(16);
1020 tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
1021 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
1022 Texture t1 = ts.GetTexture( 0 );
1023 DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
1025 tet_infoline( "Test that on the first tick, 1 new image is requested" );
1026 Test::EmitGlobalTimerSignal(); // Both visuals should tick
1028 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1029 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
1031 ts = dummyControl2.GetRendererAt(0).GetTextures();
1032 Texture t2 = ts.GetTexture( 0 );
1033 DALI_TEST_CHECK( t1 != t2 );
1035 dummyControl1.Unparent();
1036 dummyControl2.Unparent();
1038 tet_infoline("Test that removing the visual from stage deletes all textures");
1039 application.SendNotification();
1040 application.Render(16);
1041 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1047 int UtcDaliAnimatedImageVisualMultiImage04(void)
1049 ToolkitTestApplication application;
1050 TestGlAbstraction& gl = application.GetGlAbstraction();
1051 TraceCallStack& textureTrace = gl.GetTextureTrace();
1052 textureTrace.Enable(true);
1054 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" );
1056 Property::Array urls;
1057 CopyUrlsIntoArray( urls );
1060 Property::Map propertyMap;
1061 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
1062 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
1063 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
1064 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
1065 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
1067 VisualFactory factory = VisualFactory::Get();
1068 Visual::Base visual = factory.CreateVisual( propertyMap );
1070 tet_infoline( "Expect that a batch of 7 textures has been requested." );
1072 DummyControl dummyControl = DummyControl::New(true);
1073 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1074 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1076 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1077 application.GetScene().Add( dummyControl );
1078 application.SendNotification();
1079 application.Render(16);
1081 tet_infoline( "Wait for the first batch to complete" );
1082 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
1084 tet_infoline( "Test that a timer has been started" );
1085 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1087 application.SendNotification();
1088 application.Render(16);
1090 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
1091 tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
1092 Test::EmitGlobalTimerSignal();
1093 application.SendNotification();
1094 application.Render(16);
1096 // Expect the second batch has been requested
1097 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
1099 application.SendNotification();
1100 application.Render(16);
1101 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1103 tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
1105 Test::EmitGlobalTimerSignal();
1106 application.SendNotification();
1107 application.Render(16);
1108 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
1109 application.SendNotification();
1110 application.Render(16);
1111 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1113 tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
1114 Test::EmitGlobalTimerSignal();
1115 application.SendNotification();
1116 application.Render(16);
1118 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
1119 application.SendNotification();
1120 application.Render(16);
1121 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
1123 dummyControl.Unparent();
1126 tet_infoline("Test that removing the visual from stage deletes all textures");
1127 application.SendNotification();
1128 application.Render(16);
1129 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1135 int UtcDaliAnimatedImageVisualMultiImage05(void)
1137 ToolkitTestApplication application;
1138 TestGlAbstraction& gl = application.GetGlAbstraction();
1140 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" );
1142 Property::Array urls;
1143 CopyUrlsIntoArray( urls );
1146 Property::Map propertyMap;
1147 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
1148 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
1149 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
1150 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
1151 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
1153 VisualFactory factory = VisualFactory::Get();
1154 Visual::Base visual = factory.CreateVisual( propertyMap );
1156 tet_infoline( "Expect that a batch of 4 textures has been requested." );
1158 DummyControl dummyControl = DummyControl::New(true);
1159 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1160 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1162 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1163 application.GetScene().Add( dummyControl );
1164 application.SendNotification();
1165 application.Render(16);
1167 tet_infoline( "Wait for the first batch to complete" );
1168 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
1170 tet_infoline( "Test that a timer has been started" );
1171 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1173 application.SendNotification();
1174 application.Render(16);
1176 tet_infoline( "Test that a timer has been started" );
1177 Test::EmitGlobalTimerSignal();
1178 application.SendNotification();
1179 application.Render(16);
1181 dummyControl.Unparent();
1184 application.SendNotification();
1185 application.Render(16);
1186 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1188 tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
1189 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
1190 application.SendNotification();
1191 application.Render(16);
1192 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
1197 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
1199 TestGlAbstraction& gl = application.GetGlAbstraction();
1200 TraceCallStack& textureTrace = gl.GetTextureTrace();
1202 textureTrace.Enable(true);
1203 application.GetScene().Add( dummyControl );
1205 application.SendNotification();
1206 application.Render(16);
1208 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_INNER_LOCATION( location ) );
1210 application.SendNotification();
1211 application.Render();
1213 tet_infoline( "Test that a timer has been created" );
1214 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
1216 for ( uint16_t i = 0; i < loopCount; i++ )
1218 for ( uint16_t j = 0; j < frameCount; j++ )
1220 if( i == 0 && j == 0 )
1222 continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1224 tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
1225 Test::EmitGlobalTimerSignal();
1226 application.SendNotification();
1227 application.Render(16);
1229 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_INNER_LOCATION( location ) );
1231 application.SendNotification();
1232 application.Render();
1233 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION( location ) );
1234 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
1236 tet_printf( "Test Loop %u \n\n", i + 1u );
1239 tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
1240 Test::EmitGlobalTimerSignal();
1241 application.SendNotification();
1242 application.Render(16);
1243 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
1245 dummyControl.Unparent();
1248 int UtcDaliAnimatedImageVisualLoopCount(void)
1250 ToolkitTestApplication application;
1252 tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
1255 // request AnimatedImageVisual with a property map
1256 // Test with no (0) loop count
1257 VisualFactory factory = VisualFactory::Get();
1258 Visual::Base animatedImageVisual = factory.CreateVisual(
1260 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1261 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1262 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1263 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1264 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1265 .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
1267 DummyControl dummyControl = DummyControl::New(true);
1268 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1269 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1270 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1272 TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
1274 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1275 animatedImageVisual.Reset();
1277 application.SendNotification();
1278 application.Render(16);
1280 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1281 animatedImageVisual = factory.CreateVisual(
1283 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1284 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1285 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1286 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1287 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1288 .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
1290 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1292 TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
1294 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1295 animatedImageVisual.Reset();
1297 application.SendNotification();
1298 application.Render(16);
1300 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1301 animatedImageVisual = factory.CreateVisual(
1303 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1304 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1305 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1306 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1307 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1308 .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
1310 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1312 TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
1317 int UtcDaliAnimatedImageVisualPlayback(void)
1319 ToolkitTestApplication application;
1320 TestGlAbstraction& gl = application.GetGlAbstraction();
1321 TraceCallStack& textureTrace = gl.GetTextureTrace();
1323 tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
1326 // request AnimatedImageVisual with a property map
1327 // Test with forever (-1) loop count
1328 VisualFactory factory = VisualFactory::Get();
1329 Visual::Base animatedImageVisual = factory.CreateVisual(
1331 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1332 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1333 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1334 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1335 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1336 .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
1338 DummyControl dummyControl = DummyControl::New(true);
1339 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1340 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1341 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1343 textureTrace.Enable(true);
1344 application.GetScene().Add( dummyControl );
1345 application.SendNotification();
1346 application.Render(16);
1348 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1350 application.SendNotification();
1351 application.Render();
1353 tet_infoline( "Test that a timer has been created" );
1354 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1356 Test::EmitGlobalTimerSignal();
1357 application.SendNotification();
1358 application.Render(16);
1360 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1362 application.SendNotification();
1363 application.Render();
1364 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1366 Property::Map attributes;
1367 tet_infoline( "Test Pause action. Timer should stop after Pause action" );
1368 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
1369 Test::EmitGlobalTimerSignal();
1370 application.SendNotification();
1371 application.Render(16);
1372 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1374 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1375 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1376 Test::EmitGlobalTimerSignal();
1377 application.SendNotification();
1378 application.Render(16);
1380 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1382 application.SendNotification();
1383 application.Render();
1384 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1386 tet_infoline( "Test Stop action. Timer should stop after Stop action" );
1387 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
1388 Test::EmitGlobalTimerSignal();
1389 application.SendNotification();
1390 application.Render(16);
1391 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1393 tet_infoline( "Test Play action. Timer should Restart after Play action" );
1394 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1395 Test::EmitGlobalTimerSignal();
1396 application.SendNotification();
1397 application.Render(16);
1399 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1401 application.SendNotification();
1402 application.Render();
1403 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1405 dummyControl.Unparent();