2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <toolkit-timer.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
28 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include "dummy-control.h"
35 using namespace Dali::Toolkit;
37 void dali_animated_image_visual_startup(void)
39 test_return_value = TET_UNDEF;
42 void dali_animated_image_visual_cleanup(void)
44 test_return_value = TET_PASS;
49 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-%02d.png";
50 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
53 void CopyUrlsIntoArray(Property::Array& urls, int startIndex = 0)
55 for(int i = 20 + startIndex; i <= 30; ++i)
58 if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
60 Property::Value value(url);
67 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
69 ToolkitTestApplication application;
70 tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap");
72 // request AnimatedImageVisual with a property map
73 VisualFactory factory = VisualFactory::Get();
74 Visual::Base animatedImageVisual = factory.CreateVisual(
76 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
77 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
78 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
79 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
80 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
81 .Add(DevelVisual::Property::CORNER_RADIUS, 22.2f)
82 .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE)
83 .Add(DevelVisual::Property::BORDERLINE_WIDTH, 33.3f)
84 .Add(DevelVisual::Property::BORDERLINE_COLOR, Color::RED)
85 .Add(DevelVisual::Property::BORDERLINE_OFFSET, 0.3f));
87 Property::Map resultMap;
88 animatedImageVisual.CreatePropertyMap(resultMap);
89 // check the property values from the returned map from a visual
90 Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
91 DALI_TEST_CHECK(value);
92 DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
94 value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
95 DALI_TEST_CHECK(value);
96 DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
98 value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
99 DALI_TEST_CHECK(value);
100 DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(22.2f, 22.2f, 22.2f, 22.2f), TEST_LOCATION);
102 value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER);
103 DALI_TEST_CHECK(value);
104 DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
106 value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
107 DALI_TEST_CHECK(value);
108 DALI_TEST_EQUALS(value->Get<float>(), 33.3f, TEST_LOCATION);
110 value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
111 DALI_TEST_CHECK(value);
112 DALI_TEST_EQUALS(value->Get<Vector4>(), Color::RED, TEST_LOCATION);
114 value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
115 DALI_TEST_CHECK(value);
116 DALI_TEST_EQUALS(value->Get<float>(), 0.3f, TEST_LOCATION);
118 // request AnimatedImageVisual with an URL
119 Visual::Base animatedImageVisual2 = factory.CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions());
121 animatedImageVisual2.CreatePropertyMap(resultMap);
122 // check the property values from the returned map from a visual
123 value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
124 DALI_TEST_CHECK(value);
125 DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
127 value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
128 DALI_TEST_CHECK(value);
129 DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
134 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
136 ToolkitTestApplication application;
137 tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap for multi image with fixed cache");
139 // request AnimatedImageVisual with a property map
140 VisualFactory factory = VisualFactory::Get();
141 Property::Array urls;
142 CopyUrlsIntoArray(urls);
144 Visual::Base animatedImageVisual = factory.CreateVisual(
146 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
149 .Add("cacheSize", 20)
150 .Add("loopCount", 10)
151 .Add("frameDelay", 200)
152 .Add("pixelArea", Vector4())
153 .Add("wrapModeU", WrapMode::REPEAT)
154 .Add("wrapModeV", WrapMode::DEFAULT)
155 .Add("cornerRadius", Vector4(50.0f, 25.0f, 12.5f, 33.0f))
156 .Add("cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE)
157 .Add("borderlineWidth", 20.0f)
158 .Add("borderlineColor", Vector4())
159 .Add("borderlineOffset", -1.0f));
161 Property::Map resultMap;
162 animatedImageVisual.CreatePropertyMap(resultMap);
163 // check the property values from the returned map from a visual
164 Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
165 DALI_TEST_CHECK(value);
166 DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
168 value = resultMap.Find(ImageVisual::Property::URL, "url");
169 DALI_TEST_CHECK(value);
170 Property::Array* resultUrls = value->GetArray();
171 DALI_TEST_CHECK(resultUrls);
172 DALI_TEST_EQUALS(resultUrls->Count(), urls.Count(), TEST_LOCATION);
174 value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
175 DALI_TEST_CHECK(value);
176 DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
178 value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
179 DALI_TEST_CHECK(value);
180 DALI_TEST_EQUALS(value->Get<int>(), 20, TEST_LOCATION);
182 value = resultMap.Find(Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount");
183 DALI_TEST_CHECK(value);
184 DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
186 value = resultMap.Find(ImageVisual::Property::FRAME_DELAY, "frameDelay");
187 DALI_TEST_CHECK(value);
188 DALI_TEST_EQUALS(value->Get<int>(), 200, TEST_LOCATION);
190 value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
191 DALI_TEST_CHECK(value);
192 DALI_TEST_EQUALS(value->Get<int>(), 11, TEST_LOCATION);
194 value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius");
195 DALI_TEST_CHECK(value);
196 DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(50.0f, 25.0f, 12.5f, 33.0f), TEST_LOCATION);
198 value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
199 DALI_TEST_CHECK(value);
200 DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
202 value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
203 DALI_TEST_CHECK(value);
204 DALI_TEST_EQUALS(value->Get<float>(), 20.0f, TEST_LOCATION);
206 value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
207 DALI_TEST_CHECK(value);
208 DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4::ZERO, TEST_LOCATION);
210 value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
211 DALI_TEST_CHECK(value);
212 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)
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);
460 int UtcDaliAnimatedImageVisualJumpToAction(void)
462 ToolkitTestApplication application;
463 TestGlAbstraction& gl = application.GetGlAbstraction();
465 Property::Array urls;
466 CopyUrlsIntoArray(urls);
469 Property::Map propertyMap;
470 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
471 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
472 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
473 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 12);
474 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
476 VisualFactory factory = VisualFactory::Get();
477 Visual::Base visual = factory.CreateVisual(propertyMap);
479 DummyControl dummyControl = DummyControl::New(true);
480 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
481 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
483 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
484 application.GetScene().Add(dummyControl);
485 application.SendNotification();
486 application.Render(20);
488 tet_infoline("Ready the visual after the visual is on stage");
489 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
491 tet_infoline("Test that a timer has been started");
492 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
494 TraceCallStack& textureTrace = gl.GetTextureTrace();
495 textureTrace.Enable(true);
497 application.SendNotification();
498 application.Render(20);
500 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
502 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
504 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
506 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20);
508 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
510 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
512 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
513 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
515 dummyControl.Unparent();
517 tet_infoline("Test that removing the visual from stage deletes all textures");
518 application.SendNotification();
519 application.Render(16);
520 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
525 int UtcDaliAnimatedImageVisualStopBehavior(void)
527 ToolkitTestApplication application;
528 TestGlAbstraction& gl = application.GetGlAbstraction();
530 Property::Array urls;
531 CopyUrlsIntoArray(urls);
534 Property::Map propertyMap;
535 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
536 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
537 propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
538 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
539 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
540 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
542 VisualFactory factory = VisualFactory::Get();
543 Visual::Base visual = factory.CreateVisual(propertyMap);
545 // Expect that a batch of 4 textures has been requested. These will be serially loaded
548 DummyControl dummyControl = DummyControl::New(true);
549 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
550 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
552 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
553 application.GetScene().Add(dummyControl);
554 application.SendNotification();
555 application.Render(20);
557 tet_infoline("Ready the visual after the visual is on stage");
558 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
560 tet_infoline("Test that a timer has been started");
561 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
563 TraceCallStack& textureTrace = gl.GetTextureTrace();
564 textureTrace.Enable(true);
566 application.SendNotification();
567 application.Render(20);
569 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
571 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
573 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
575 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1);
577 // Expect the second batch has been requested
578 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
580 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
582 dummyControl.Unparent();
584 tet_infoline("Test that removing the visual from stage deletes all textures");
585 application.SendNotification();
586 application.Render(16);
587 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
592 int UtcDaliAnimatedImageVisualStopBehavior02(void)
594 ToolkitTestApplication application;
595 TestGlAbstraction& gl = application.GetGlAbstraction();
597 Property::Array urls;
598 CopyUrlsIntoArray(urls);
601 Property::Map propertyMap;
602 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
603 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
604 propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
605 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
606 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
607 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
609 VisualFactory factory = VisualFactory::Get();
610 Visual::Base visual = factory.CreateVisual(propertyMap);
612 // Expect that a batch of 4 textures has been requested. These will be serially loaded
615 DummyControl dummyControl = DummyControl::New(true);
616 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
617 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
619 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
620 application.GetScene().Add(dummyControl);
622 tet_infoline("Ready the visual after the visual is on stage");
623 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
625 TraceCallStack& textureTrace = gl.GetTextureTrace();
626 textureTrace.Enable(true);
628 application.SendNotification();
629 application.Render(20);
631 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
633 Test::EmitGlobalTimerSignal();
635 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
637 application.SendNotification();
638 application.Render(20);
640 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
642 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
644 tet_infoline("Ready the visual after the visual is on stage");
645 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
647 application.SendNotification();
648 application.Render(20);
650 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
652 dummyControl.Unparent();
654 tet_infoline("Test that removing the visual from stage deletes all textures");
655 application.SendNotification();
656 application.Render(16);
657 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
662 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
664 ToolkitTestApplication application;
665 TestGlAbstraction& gl = application.GetGlAbstraction();
668 Property::Map propertyMap;
669 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
670 propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
671 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
672 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
673 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
675 VisualFactory factory = VisualFactory::Get();
676 Visual::Base visual = factory.CreateVisual(propertyMap);
678 // Expect that a batch of 4 textures has been requested. These will be serially loaded
681 DummyControl dummyControl = DummyControl::New(true);
682 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
683 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
685 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
686 application.GetScene().Add(dummyControl);
688 application.SendNotification();
689 application.Render();
691 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
693 application.SendNotification();
694 application.Render(20);
696 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
698 tet_infoline("Test that a timer has been started");
700 TraceCallStack& textureTrace = gl.GetTextureTrace();
701 textureTrace.Enable(true);
703 Test::EmitGlobalTimerSignal();
705 application.SendNotification();
706 application.Render();
708 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
710 application.SendNotification();
711 application.Render(20);
713 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
715 dummyControl.Unparent();
717 tet_infoline("Test that removing the visual from stage deletes all textures");
718 application.SendNotification();
719 application.Render(20);
720 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
725 int UtcDaliAnimatedImageVisualMultiImage01(void)
727 ToolkitTestApplication application;
728 TestGlAbstraction& gl = application.GetGlAbstraction();
730 Property::Array urls;
731 CopyUrlsIntoArray(urls);
734 Property::Map propertyMap;
735 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
736 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
737 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
738 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
739 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
741 VisualFactory factory = VisualFactory::Get();
742 Visual::Base visual = factory.CreateVisual(propertyMap);
744 // Expect that a batch of 4 textures has been requested. These will be serially loaded
747 DummyControl dummyControl = DummyControl::New(true);
748 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
749 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
751 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
752 application.GetScene().Add(dummyControl);
753 application.SendNotification();
754 application.Render(16);
756 tet_infoline("Ready the visual after the visual is on stage");
757 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
759 tet_infoline("Test that a timer has been started");
760 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
762 TraceCallStack& textureTrace = gl.GetTextureTrace();
763 textureTrace.Enable(true);
765 application.SendNotification();
766 application.Render(16);
768 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
769 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
771 tet_infoline("Test that after 1 tick, and file loads completed, that we have 7 textures");
772 Test::EmitGlobalTimerSignal();
774 // Expect the second batch has been requested
775 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
777 application.SendNotification();
778 application.Render(16);
779 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
781 tet_infoline("Test that after 2 ticks that we have 6 textures");
783 Test::EmitGlobalTimerSignal();
784 application.SendNotification();
785 application.Render(16);
786 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 6, TEST_LOCATION);
788 tet_infoline("And that at least 2 textures were requested");
789 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
790 application.SendNotification();
791 application.Render(16);
792 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
794 tet_infoline("Test that after 3rd tick that we have 7 textures and 1 request");
795 Test::EmitGlobalTimerSignal();
796 application.SendNotification();
797 application.Render(16);
798 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
800 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
801 application.SendNotification();
802 application.Render(16);
803 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
805 dummyControl.Unparent();
807 tet_infoline("Test that removing the visual from stage deletes all textures");
808 application.SendNotification();
809 application.Render(16);
810 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
815 int UtcDaliAnimatedImageVisualMultiImage02(void)
817 ToolkitTestApplication application;
818 TestGlAbstraction& gl = application.GetGlAbstraction();
820 tet_infoline("Test that the animated visual has different batch and cache size.");
823 Property::Array urls;
824 CopyUrlsIntoArray(urls);
826 Property::Map propertyMap;
827 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
828 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
829 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 0);
830 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 0);
831 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
833 VisualFactory factory = VisualFactory::Get();
834 Visual::Base visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
836 // Check the batch size and cache size need to have minimum 2.
837 Property::Map resultMap;
838 visual.CreatePropertyMap(resultMap);
839 Property::Value* value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
840 DALI_TEST_CHECK(value);
841 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
842 value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
843 DALI_TEST_CHECK(value);
844 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
847 // Batch size is 2 and cache size is 3
849 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
850 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
851 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
852 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 3);
853 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
855 visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
857 // Expect that each image is loaded each tick
858 DummyControl dummyControl = DummyControl::New(true);
859 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
860 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
863 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
864 application.GetScene().Add(dummyControl);
865 application.SendNotification();
866 application.Render(16);
868 tet_infoline("Ready the visual after the visual is on window");
869 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
870 application.SendNotification();
871 application.Render(16); //glGenTextures 1 and 2
872 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
874 tet_infoline("Test that each tick, a new image is requested");
875 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
876 application.SendNotification();
877 application.Render(16);
878 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
879 application.SendNotification();
880 application.Render(16); //glGenTextures 3
881 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
883 tet_infoline("Test that each tick, a new image is requested");
884 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
885 application.SendNotification();
886 application.Render(16);
887 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
888 application.SendNotification();
889 application.Render(16); //glGenTextures 4
890 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
892 dummyImpl1.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
893 dummyControl.Unparent();
895 // Batch size is 9 and cache size is 4
897 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
898 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
899 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 3);
900 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 7);
901 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
903 visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
905 // Expect that each image is loaded each tick
906 dummyControl = DummyControl::New(true);
907 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
908 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
911 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
912 application.GetScene().Add(dummyControl);
913 application.SendNotification();
914 application.Render(16);
916 tet_infoline("Ready the visual after the visual is on window");
917 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
918 application.SendNotification();
919 application.Render(16); //glGenTextures 1, 2, and 3
920 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
922 tet_infoline("Test that each tick, a new image is requested");
923 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
924 application.SendNotification();
925 application.Render(16);
926 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
927 application.SendNotification();
928 application.Render(16); //glGenTextures 4, 5, and 6
929 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 5, TEST_LOCATION);
931 tet_infoline("Test that each tick, a new image is requested");
932 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
933 application.SendNotification();
934 application.Render(16);
935 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
936 application.SendNotification();
937 application.Render(16); //glGenTextures 7, 1, and 2
938 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
940 tet_infoline("Test that each tick, a new image is requested");
941 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
942 application.SendNotification();
943 application.Render(16);
944 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
945 application.SendNotification();
946 application.Render(16); //glGenTextures 3
947 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
949 dummyControl.Unparent();
951 tet_infoline("Test that removing the visual from window deletes all textures");
952 application.SendNotification();
953 application.Render(16);
954 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
959 int UtcDaliAnimatedImageVisualMultiImage03(void)
961 ToolkitTestApplication application;
962 TestGlAbstraction& gl = application.GetGlAbstraction();
965 Property::Array urls1, urls2;
966 CopyUrlsIntoArray(urls1);
967 CopyUrlsIntoArray(urls2);
969 Property::Map animatedImageMap1;
970 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE);
971 animatedImageMap1.Insert(ImageVisual::Property::URL, Property::Value(urls1));
972 animatedImageMap1.Insert(ImageVisual::Property::BATCH_SIZE, 3);
973 animatedImageMap1.Insert(ImageVisual::Property::CACHE_SIZE, 3);
974 animatedImageMap1.Insert(ImageVisual::Property::FRAME_DELAY, 100);
976 Property::Map animatedImageMap2;
977 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE);
978 animatedImageMap2.Insert(ImageVisual::Property::URL, Property::Value(urls2));
979 animatedImageMap2.Insert(ImageVisual::Property::BATCH_SIZE, 2);
980 animatedImageMap2.Insert(ImageVisual::Property::CACHE_SIZE, 2);
981 animatedImageMap2.Insert(ImageVisual::Property::FRAME_DELAY, 100);
983 VisualFactory factory = VisualFactory::Get();
984 Visual::Base animatedImageVisual1 = factory.CreateVisual(animatedImageMap1);
986 tet_infoline("Create two image views with the same URLs, offset by 1 frame.");
988 DummyControl dummyControl1 = DummyControl::New(true);
989 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
990 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual1);
991 dummyControl1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
992 application.GetScene().Add(dummyControl1);
994 application.SendNotification();
995 application.Render(16);
997 tet_infoline("Ready the requested image after the first visual is on stage");
998 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
999 application.SendNotification();
1000 application.Render(16);
1001 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1003 Visual::Base animatedImageVisual2 = factory.CreateVisual(animatedImageMap2);
1004 DummyControl dummyControl2 = DummyControl::New(true);
1005 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
1006 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual2);
1007 dummyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1008 application.GetScene().Add(dummyControl2);
1009 application.SendNotification();
1010 application.Render(16);
1012 tet_infoline("The texture cache should be holding the requested images; check that the renderer has a texture");
1013 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
1014 Texture t1 = ts.GetTexture(0);
1015 DALI_TEST_EQUALS(ts.GetTextureCount(), 1, TEST_LOCATION);
1017 tet_infoline("Test that on the first tick, 1 new image is requested");
1018 Test::EmitGlobalTimerSignal(); // Both visuals should tick
1020 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1021 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1023 ts = dummyControl2.GetRendererAt(0).GetTextures();
1024 Texture t2 = ts.GetTexture(0);
1025 DALI_TEST_CHECK(t1 != t2);
1027 dummyControl1.Unparent();
1028 dummyControl2.Unparent();
1030 tet_infoline("Test that removing the visual from stage deletes all textures");
1031 application.SendNotification();
1032 application.Render(16);
1033 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1038 int UtcDaliAnimatedImageVisualMultiImage04(void)
1040 ToolkitTestApplication application;
1041 TestGlAbstraction& gl = application.GetGlAbstraction();
1042 TraceCallStack& textureTrace = gl.GetTextureTrace();
1043 textureTrace.Enable(true);
1045 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");
1047 Property::Array urls;
1048 CopyUrlsIntoArray(urls);
1051 Property::Map propertyMap;
1052 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1053 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1054 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 6);
1055 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1056 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1058 VisualFactory factory = VisualFactory::Get();
1059 Visual::Base visual = factory.CreateVisual(propertyMap);
1061 tet_infoline("Expect that a batch of 7 textures has been requested.");
1063 DummyControl dummyControl = DummyControl::New(true);
1064 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1065 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1067 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1068 application.GetScene().Add(dummyControl);
1069 application.SendNotification();
1070 application.Render(16);
1072 tet_infoline("Wait for the first batch to complete");
1073 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
1075 tet_infoline("Test that a timer has been started");
1076 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1078 application.SendNotification();
1079 application.Render(16);
1081 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 6, TEST_LOCATION);
1082 tet_infoline("Test that after 1 tick, and 5 file loads completed, that we have 11 textures");
1083 Test::EmitGlobalTimerSignal();
1084 application.SendNotification();
1085 application.Render(16);
1087 // Expect the second batch has been requested
1088 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
1090 application.SendNotification();
1091 application.Render(16);
1092 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1094 tet_infoline("Test that after 2 ticks that we have 11 textures and no requests");
1096 Test::EmitGlobalTimerSignal();
1097 application.SendNotification();
1098 application.Render(16);
1099 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1100 application.SendNotification();
1101 application.Render(16);
1102 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1104 tet_infoline("Test that after 3rd tick that we have 11 textures and no requests");
1105 Test::EmitGlobalTimerSignal();
1106 application.SendNotification();
1107 application.Render(16);
1109 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1110 application.SendNotification();
1111 application.Render(16);
1112 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1114 dummyControl.Unparent();
1117 tet_infoline("Test that removing the visual from stage deletes all textures");
1118 application.SendNotification();
1119 application.Render(16);
1120 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1125 int UtcDaliAnimatedImageVisualMultiImage05(void)
1127 ToolkitTestApplication application;
1128 TestGlAbstraction& gl = application.GetGlAbstraction();
1130 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");
1132 Property::Array urls;
1133 CopyUrlsIntoArray(urls);
1136 Property::Map propertyMap;
1137 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1138 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1139 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
1140 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1141 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1143 VisualFactory factory = VisualFactory::Get();
1144 Visual::Base visual = factory.CreateVisual(propertyMap);
1146 tet_infoline("Expect that a batch of 4 textures has been requested.");
1148 DummyControl dummyControl = DummyControl::New(true);
1149 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1150 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1152 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1153 application.GetScene().Add(dummyControl);
1154 application.SendNotification();
1155 application.Render(16);
1157 tet_infoline("Wait for the first batch to complete");
1158 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1160 tet_infoline("Test that a timer has been started");
1161 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1163 application.SendNotification();
1164 application.Render(16);
1166 tet_infoline("Test that a timer has been started");
1167 Test::EmitGlobalTimerSignal();
1168 application.SendNotification();
1169 application.Render(16);
1171 dummyControl.Unparent();
1174 application.SendNotification();
1175 application.Render(16);
1176 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1178 tet_infoline("Test that pending batch of image loads are cancelled instead of uploaded");
1179 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1180 application.SendNotification();
1181 application.Render(16);
1182 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1187 void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyControl, uint16_t frameCount, uint16_t loopCount, const char* location)
1189 TestGlAbstraction& gl = application.GetGlAbstraction();
1190 TraceCallStack& textureTrace = gl.GetTextureTrace();
1192 textureTrace.Enable(true);
1193 application.GetScene().Add(dummyControl);
1195 application.SendNotification();
1196 application.Render(16);
1198 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_INNER_LOCATION(location));
1200 application.SendNotification();
1201 application.Render();
1203 tet_infoline("Test that a timer has been created");
1204 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_INNER_LOCATION(location));
1206 for(uint16_t i = 0; i < loopCount; i++)
1208 for(uint16_t j = 0; j < frameCount; j++)
1210 if(i == 0 && j == 0)
1212 continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1214 tet_printf("Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u);
1215 Test::EmitGlobalTimerSignal();
1216 application.SendNotification();
1217 application.Render(16);
1219 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_INNER_LOCATION(location));
1221 application.SendNotification();
1222 application.Render();
1223 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION(location));
1224 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_INNER_LOCATION(location));
1226 tet_printf("Test Loop %u \n\n", i + 1u);
1229 tet_printf("Test that after %u loops, and we have no frame. Timer should stop \n", loopCount);
1230 Test::EmitGlobalTimerSignal();
1231 application.SendNotification();
1232 application.Render(16);
1233 DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_INNER_LOCATION(location));
1235 dummyControl.Unparent();
1238 int UtcDaliAnimatedImageVisualLoopCount(void)
1240 ToolkitTestApplication application;
1242 tet_infoline("UtcDaliAnimatedImageVisualLoopCount");
1245 // request AnimatedImageVisual with a property map
1246 // Test with no (0) loop count
1247 VisualFactory factory = VisualFactory::Get();
1248 Visual::Base animatedImageVisual = factory.CreateVisual(
1250 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1251 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1252 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1253 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1254 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1255 .Add(DevelImageVisual::Property::LOOP_COUNT, 0));
1257 DummyControl dummyControl = DummyControl::New(true);
1258 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1259 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1260 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1262 TestLoopCount(application, dummyControl, 4, 0, TEST_LOCATION);
1264 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1265 animatedImageVisual.Reset();
1267 application.SendNotification();
1268 application.Render(16);
1270 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1271 animatedImageVisual = factory.CreateVisual(
1273 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1274 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1275 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1276 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1277 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1278 .Add(DevelImageVisual::Property::LOOP_COUNT, 1));
1280 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1282 TestLoopCount(application, dummyControl, 4, 1, TEST_LOCATION);
1284 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1285 animatedImageVisual.Reset();
1287 application.SendNotification();
1288 application.Render(16);
1290 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1291 animatedImageVisual = factory.CreateVisual(
1293 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1294 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1295 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1296 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1297 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1298 .Add(DevelImageVisual::Property::LOOP_COUNT, 100));
1300 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1302 TestLoopCount(application, dummyControl, 4, 100, TEST_LOCATION);
1307 int UtcDaliAnimatedImageVisualPlayback(void)
1309 ToolkitTestApplication application;
1310 TestGlAbstraction& gl = application.GetGlAbstraction();
1311 TraceCallStack& textureTrace = gl.GetTextureTrace();
1313 tet_infoline("UtcDaliAnimatedImageVisualPlayback");
1316 // request AnimatedImageVisual with a property map
1317 // Test with forever (-1) loop count
1318 VisualFactory factory = VisualFactory::Get();
1319 Visual::Base animatedImageVisual = factory.CreateVisual(
1321 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1322 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1323 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1324 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1325 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1326 .Add(DevelImageVisual::Property::LOOP_COUNT, -1));
1328 DummyControl dummyControl = DummyControl::New(true);
1329 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1330 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1331 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1333 textureTrace.Enable(true);
1334 application.GetScene().Add(dummyControl);
1335 application.SendNotification();
1336 application.Render(16);
1338 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1340 application.SendNotification();
1341 application.Render();
1343 tet_infoline("Test that a timer has been created");
1344 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1346 Test::EmitGlobalTimerSignal();
1347 application.SendNotification();
1348 application.Render(16);
1350 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1352 application.SendNotification();
1353 application.Render();
1354 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1356 Property::Map attributes;
1357 tet_infoline("Test Pause action. Timer should stop after Pause action");
1358 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes);
1359 Test::EmitGlobalTimerSignal();
1360 application.SendNotification();
1361 application.Render(16);
1362 DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1364 tet_infoline("Test Play action. Timer should Restart after Play action");
1365 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1366 Test::EmitGlobalTimerSignal();
1367 application.SendNotification();
1368 application.Render(16);
1370 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1372 application.SendNotification();
1373 application.Render();
1374 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1376 tet_infoline("Test Stop action. Timer should stop after Stop action");
1377 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes);
1378 Test::EmitGlobalTimerSignal();
1379 application.SendNotification();
1380 application.Render(16);
1381 DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1383 tet_infoline("Test Play action. Timer should Restart after Play action");
1384 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1385 Test::EmitGlobalTimerSignal();
1386 application.SendNotification();
1387 application.Render(16);
1389 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1391 application.SendNotification();
1392 application.Render();
1393 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1395 dummyControl.Unparent();