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, true)
310 .Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED)
311 .Add(ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED)
312 .Add(DevelVisual::Property::BORDERLINE_WIDTH, 0.4f));
314 Property::Map resultMap;
315 animatedImageVisual.CreatePropertyMap(resultMap);
317 // check the property values from the returned map from a visual
318 Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
319 DALI_TEST_CHECK(value);
320 DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
322 value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
323 DALI_TEST_CHECK(value);
324 DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
326 value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, Property::INTEGER);
327 DALI_TEST_CHECK(value);
328 DALI_TEST_CHECK(value->Get<int>() == 2);
330 value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, Property::INTEGER);
331 DALI_TEST_CHECK(value);
332 DALI_TEST_CHECK(value->Get<int>() == 2);
334 value = resultMap.Find(ImageVisual::Property::SYNCHRONOUS_LOADING, Property::BOOLEAN);
335 DALI_TEST_CHECK(value);
336 DALI_TEST_CHECK(value->Get<bool>() == true);
338 value = resultMap.Find(ImageVisual::Property::RELEASE_POLICY, Property::INTEGER);
339 DALI_TEST_CHECK(value);
340 DALI_TEST_CHECK(value->Get<int>() == ImageVisual::ReleasePolicy::DETACHED);
342 value = resultMap.Find(ImageVisual::Property::LOAD_POLICY, Property::INTEGER);
343 DALI_TEST_CHECK(value);
344 DALI_TEST_CHECK(value->Get<int>() == ImageVisual::LoadPolicy::ATTACHED);
346 value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
347 DALI_TEST_CHECK(value);
348 DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
350 value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
351 DALI_TEST_CHECK(value);
352 DALI_TEST_EQUALS(value->Get<float>(), 0.4f, TEST_LOCATION);
354 value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
355 DALI_TEST_CHECK(value);
356 DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
358 value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
359 DALI_TEST_CHECK(value);
360 DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
365 int UtcDaliAnimatedImageVisualImageLoadingFail01(void)
367 ToolkitTestApplication application;
368 TestGlAbstraction& gl = application.GetGlAbstraction();
371 Property::Map propertyMap;
372 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
373 propertyMap.Insert(ImageVisual::Property::URL, "dummy.gif");
374 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
375 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
376 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
377 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
378 propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
379 propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
381 VisualFactory factory = VisualFactory::Get();
382 Visual::Base visual = factory.CreateVisual(propertyMap);
384 DummyControl dummyControl = DummyControl::New(true);
385 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
386 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
388 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
389 application.GetScene().Add(dummyControl);
391 TraceCallStack& textureTrace = gl.GetTextureTrace();
392 textureTrace.Enable(true);
394 application.SendNotification();
395 application.Render(20);
397 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
399 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
401 application.SendNotification();
402 application.Render(20);
404 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
406 dummyControl.Unparent();
412 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
414 ToolkitTestApplication application;
415 TestGlAbstraction& gl = application.GetGlAbstraction();
418 Property::Map propertyMap;
419 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
420 propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
421 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
422 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
423 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
424 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
425 propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
426 propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
428 VisualFactory factory = VisualFactory::Get();
429 Visual::Base visual = factory.CreateVisual(propertyMap);
431 DummyControl dummyControl = DummyControl::New(true);
432 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
433 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
435 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
436 application.GetScene().Add(dummyControl);
438 TraceCallStack& textureTrace = gl.GetTextureTrace();
439 textureTrace.Enable(true);
441 application.SendNotification();
442 application.Render(20);
444 // The first frame is loaded synchronously and load next batch.
445 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
447 application.SendNotification();
448 application.Render();
450 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
451 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
453 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3);
455 application.SendNotification();
456 application.Render(20);
458 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
460 application.SendNotification();
461 application.Render();
463 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
465 dummyControl.Unparent();
467 tet_infoline("Test that removing the visual from stage deletes all textures");
468 application.SendNotification();
469 application.Render(16);
470 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
475 int UtcDaliAnimatedImageVisualJumpToAction(void)
477 ToolkitTestApplication application;
478 TestGlAbstraction& gl = application.GetGlAbstraction();
480 Property::Array urls;
481 CopyUrlsIntoArray(urls);
484 Property::Map propertyMap;
485 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
486 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
487 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
488 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 12);
489 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
491 VisualFactory factory = VisualFactory::Get();
492 Visual::Base visual = factory.CreateVisual(propertyMap);
494 DummyControl dummyControl = DummyControl::New(true);
495 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
496 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
498 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
499 application.GetScene().Add(dummyControl);
500 application.SendNotification();
501 application.Render(20);
503 tet_infoline("Ready the visual after the visual is on stage");
504 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
506 tet_infoline("Test that a timer has been started");
507 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
509 TraceCallStack& textureTrace = gl.GetTextureTrace();
510 textureTrace.Enable(true);
512 application.SendNotification();
513 application.Render(20);
515 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
517 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
519 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
521 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20);
523 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
525 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
527 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
528 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
530 dummyControl.Unparent();
532 tet_infoline("Test that removing the visual from stage deletes all textures");
533 application.SendNotification();
534 application.Render(16);
535 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
540 int UtcDaliAnimatedImageVisualStopBehavior(void)
542 ToolkitTestApplication application;
543 TestGlAbstraction& gl = application.GetGlAbstraction();
545 Property::Array urls;
546 CopyUrlsIntoArray(urls);
549 Property::Map propertyMap;
550 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
551 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
552 propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
553 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
554 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
555 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
557 VisualFactory factory = VisualFactory::Get();
558 Visual::Base visual = factory.CreateVisual(propertyMap);
560 // Expect that a batch of 4 textures has been requested. These will be serially loaded
563 DummyControl dummyControl = DummyControl::New(true);
564 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
565 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
567 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
568 application.GetScene().Add(dummyControl);
569 application.SendNotification();
570 application.Render(20);
572 tet_infoline("Ready the visual after the visual is on stage");
573 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
575 tet_infoline("Test that a timer has been started");
576 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
578 TraceCallStack& textureTrace = gl.GetTextureTrace();
579 textureTrace.Enable(true);
581 application.SendNotification();
582 application.Render(20);
584 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
586 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
588 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
590 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1);
592 // Expect the second batch has been requested
593 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
595 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
597 dummyControl.Unparent();
599 tet_infoline("Test that removing the visual from stage deletes all textures");
600 application.SendNotification();
601 application.Render(16);
602 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
607 int UtcDaliAnimatedImageVisualStopBehavior02(void)
609 ToolkitTestApplication application;
610 TestGlAbstraction& gl = application.GetGlAbstraction();
612 Property::Array urls;
613 CopyUrlsIntoArray(urls);
616 Property::Map propertyMap;
617 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
618 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
619 propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
620 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
621 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
622 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
624 VisualFactory factory = VisualFactory::Get();
625 Visual::Base visual = factory.CreateVisual(propertyMap);
627 // Expect that a batch of 4 textures has been requested. These will be serially loaded
630 DummyControl dummyControl = DummyControl::New(true);
631 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
632 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
634 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
635 application.GetScene().Add(dummyControl);
637 tet_infoline("Ready the visual after the visual is on stage");
638 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
640 TraceCallStack& textureTrace = gl.GetTextureTrace();
641 textureTrace.Enable(true);
643 application.SendNotification();
644 application.Render(20);
646 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
648 Test::EmitGlobalTimerSignal();
650 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
652 application.SendNotification();
653 application.Render(20);
655 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
657 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
659 tet_infoline("Ready the visual after the visual is on stage");
660 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
662 application.SendNotification();
663 application.Render(20);
665 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
667 dummyControl.Unparent();
669 tet_infoline("Test that removing the visual from stage deletes all textures");
670 application.SendNotification();
671 application.Render(16);
672 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
677 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
679 ToolkitTestApplication application;
680 TestGlAbstraction& gl = application.GetGlAbstraction();
683 Property::Map propertyMap;
684 propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
685 propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
686 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
687 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
688 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
690 VisualFactory factory = VisualFactory::Get();
691 Visual::Base visual = factory.CreateVisual(propertyMap);
693 // Expect that a batch of 4 textures has been requested. These will be serially loaded
696 DummyControl dummyControl = DummyControl::New(true);
697 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
698 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
700 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
701 application.GetScene().Add(dummyControl);
703 application.SendNotification();
704 application.Render();
706 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
708 application.SendNotification();
709 application.Render(20);
711 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
713 tet_infoline("Test that a timer has been started");
715 TraceCallStack& textureTrace = gl.GetTextureTrace();
716 textureTrace.Enable(true);
718 Test::EmitGlobalTimerSignal();
720 application.SendNotification();
721 application.Render();
723 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
725 application.SendNotification();
726 application.Render(20);
728 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
730 dummyControl.Unparent();
732 tet_infoline("Test that removing the visual from stage deletes all textures");
733 application.SendNotification();
734 application.Render(20);
735 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
740 int UtcDaliAnimatedImageVisualMultiImage01(void)
742 ToolkitTestApplication application;
743 TestGlAbstraction& gl = application.GetGlAbstraction();
745 Property::Array urls;
746 CopyUrlsIntoArray(urls);
749 Property::Map propertyMap;
750 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
751 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
752 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
753 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
754 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
756 VisualFactory factory = VisualFactory::Get();
757 Visual::Base visual = factory.CreateVisual(propertyMap);
759 // Expect that a batch of 4 textures has been requested. These will be serially loaded
762 DummyControl dummyControl = DummyControl::New(true);
763 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
764 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
766 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
767 application.GetScene().Add(dummyControl);
768 application.SendNotification();
769 application.Render(16);
771 tet_infoline("Ready the visual after the visual is on stage");
772 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
774 tet_infoline("Test that a timer has been started");
775 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
777 TraceCallStack& textureTrace = gl.GetTextureTrace();
778 textureTrace.Enable(true);
780 application.SendNotification();
781 application.Render(16);
783 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
784 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
786 tet_infoline("Test that after 1 tick, and file loads completed, that we have 7 textures");
787 Test::EmitGlobalTimerSignal();
789 // Expect the second batch has been requested
790 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
792 application.SendNotification();
793 application.Render(16);
794 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
796 tet_infoline("Test that after 2 ticks that we have 6 textures");
798 Test::EmitGlobalTimerSignal();
799 application.SendNotification();
800 application.Render(16);
801 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 6, TEST_LOCATION);
803 tet_infoline("And that at least 2 textures were requested");
804 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
805 application.SendNotification();
806 application.Render(16);
807 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
809 tet_infoline("Test that after 3rd tick that we have 7 textures and 1 request");
810 Test::EmitGlobalTimerSignal();
811 application.SendNotification();
812 application.Render(16);
813 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
815 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
816 application.SendNotification();
817 application.Render(16);
818 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
820 dummyControl.Unparent();
822 tet_infoline("Test that removing the visual from stage deletes all textures");
823 application.SendNotification();
824 application.Render(16);
825 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
830 int UtcDaliAnimatedImageVisualMultiImage02(void)
832 ToolkitTestApplication application;
833 TestGlAbstraction& gl = application.GetGlAbstraction();
835 tet_infoline("Test that the animated visual has different batch and cache size.");
838 Property::Array urls;
839 CopyUrlsIntoArray(urls);
841 Property::Map propertyMap;
842 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
843 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
844 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 0);
845 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 0);
846 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
848 VisualFactory factory = VisualFactory::Get();
849 Visual::Base visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
851 // Check the batch size and cache size need to have minimum 2.
852 Property::Map resultMap;
853 visual.CreatePropertyMap(resultMap);
854 Property::Value* value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
855 DALI_TEST_CHECK(value);
856 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
857 value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
858 DALI_TEST_CHECK(value);
859 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
862 // Batch size is 2 and cache size is 3
864 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
865 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
866 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
867 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 3);
868 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
870 visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
872 // Expect that each image is loaded each tick
873 DummyControl dummyControl = DummyControl::New(true);
874 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
875 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
878 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
879 application.GetScene().Add(dummyControl);
880 application.SendNotification();
881 application.Render(16);
883 tet_infoline("Ready the visual after the visual is on window");
884 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
885 application.SendNotification();
886 application.Render(16); //glGenTextures 1 and 2
887 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
889 tet_infoline("Test that each tick, a new image is requested");
890 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
891 application.SendNotification();
892 application.Render(16);
893 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
894 application.SendNotification();
895 application.Render(16); //glGenTextures 3
896 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
898 tet_infoline("Test that each tick, a new image is requested");
899 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
900 application.SendNotification();
901 application.Render(16);
902 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
903 application.SendNotification();
904 application.Render(16); //glGenTextures 4
905 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
907 dummyImpl1.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
908 dummyControl.Unparent();
910 // Batch size is 9 and cache size is 4
912 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
913 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
914 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 3);
915 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 7);
916 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
918 visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
920 // Expect that each image is loaded each tick
921 dummyControl = DummyControl::New(true);
922 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
923 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
926 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
927 application.GetScene().Add(dummyControl);
928 application.SendNotification();
929 application.Render(16);
931 tet_infoline("Ready the visual after the visual is on window");
932 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
933 application.SendNotification();
934 application.Render(16); //glGenTextures 1, 2, and 3
935 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
937 tet_infoline("Test that each tick, a new image is requested");
938 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
939 application.SendNotification();
940 application.Render(16);
941 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
942 application.SendNotification();
943 application.Render(16); //glGenTextures 4, 5, and 6
944 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 5, TEST_LOCATION);
946 tet_infoline("Test that each tick, a new image is requested");
947 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
948 application.SendNotification();
949 application.Render(16);
950 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
951 application.SendNotification();
952 application.Render(16); //glGenTextures 7, 1, and 2
953 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
955 tet_infoline("Test that each tick, a new image is requested");
956 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
957 application.SendNotification();
958 application.Render(16);
959 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
960 application.SendNotification();
961 application.Render(16); //glGenTextures 3
962 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
964 dummyControl.Unparent();
966 tet_infoline("Test that removing the visual from window deletes all textures");
967 application.SendNotification();
968 application.Render(16);
969 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
974 int UtcDaliAnimatedImageVisualMultiImage03(void)
976 ToolkitTestApplication application;
977 TestGlAbstraction& gl = application.GetGlAbstraction();
980 Property::Array urls1, urls2;
981 CopyUrlsIntoArray(urls1);
982 CopyUrlsIntoArray(urls2);
984 Property::Map animatedImageMap1;
985 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE);
986 animatedImageMap1.Insert(ImageVisual::Property::URL, Property::Value(urls1));
987 animatedImageMap1.Insert(ImageVisual::Property::BATCH_SIZE, 3);
988 animatedImageMap1.Insert(ImageVisual::Property::CACHE_SIZE, 3);
989 animatedImageMap1.Insert(ImageVisual::Property::FRAME_DELAY, 100);
991 Property::Map animatedImageMap2;
992 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE);
993 animatedImageMap2.Insert(ImageVisual::Property::URL, Property::Value(urls2));
994 animatedImageMap2.Insert(ImageVisual::Property::BATCH_SIZE, 2);
995 animatedImageMap2.Insert(ImageVisual::Property::CACHE_SIZE, 2);
996 animatedImageMap2.Insert(ImageVisual::Property::FRAME_DELAY, 100);
998 VisualFactory factory = VisualFactory::Get();
999 Visual::Base animatedImageVisual1 = factory.CreateVisual(animatedImageMap1);
1001 tet_infoline("Create two image views with the same URLs, offset by 1 frame.");
1003 DummyControl dummyControl1 = DummyControl::New(true);
1004 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
1005 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual1);
1006 dummyControl1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1007 application.GetScene().Add(dummyControl1);
1009 application.SendNotification();
1010 application.Render(16);
1012 tet_infoline("Ready the requested image after the first visual is on stage");
1013 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1014 application.SendNotification();
1015 application.Render(16);
1016 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1018 Visual::Base animatedImageVisual2 = factory.CreateVisual(animatedImageMap2);
1019 DummyControl dummyControl2 = DummyControl::New(true);
1020 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
1021 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual2);
1022 dummyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1023 application.GetScene().Add(dummyControl2);
1024 application.SendNotification();
1025 application.Render(16);
1027 tet_infoline("The texture cache should be holding the requested images; check that the renderer has a texture");
1028 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
1029 Texture t1 = ts.GetTexture(0);
1030 DALI_TEST_EQUALS(ts.GetTextureCount(), 1, TEST_LOCATION);
1032 tet_infoline("Test that on the first tick, 1 new image is requested");
1033 Test::EmitGlobalTimerSignal(); // Both visuals should tick
1035 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1036 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1038 ts = dummyControl2.GetRendererAt(0).GetTextures();
1039 Texture t2 = ts.GetTexture(0);
1040 DALI_TEST_CHECK(t1 != t2);
1042 dummyControl1.Unparent();
1043 dummyControl2.Unparent();
1045 tet_infoline("Test that removing the visual from stage deletes all textures");
1046 application.SendNotification();
1047 application.Render(16);
1048 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1053 int UtcDaliAnimatedImageVisualMultiImage04(void)
1055 ToolkitTestApplication application;
1056 TestGlAbstraction& gl = application.GetGlAbstraction();
1057 TraceCallStack& textureTrace = gl.GetTextureTrace();
1058 textureTrace.Enable(true);
1060 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");
1062 Property::Array urls;
1063 CopyUrlsIntoArray(urls);
1066 Property::Map propertyMap;
1067 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1068 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1069 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 6);
1070 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1071 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1073 VisualFactory factory = VisualFactory::Get();
1074 Visual::Base visual = factory.CreateVisual(propertyMap);
1076 tet_infoline("Expect that a batch of 7 textures has been requested.");
1078 DummyControl dummyControl = DummyControl::New(true);
1079 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1080 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1082 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1083 application.GetScene().Add(dummyControl);
1084 application.SendNotification();
1085 application.Render(16);
1087 tet_infoline("Wait for the first batch to complete");
1088 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
1090 tet_infoline("Test that a timer has been started");
1091 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1093 application.SendNotification();
1094 application.Render(16);
1096 DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 6, TEST_LOCATION);
1097 tet_infoline("Test that after 1 tick, and 5 file loads completed, that we have 11 textures");
1098 Test::EmitGlobalTimerSignal();
1099 application.SendNotification();
1100 application.Render(16);
1102 // Expect the second batch has been requested
1103 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
1105 application.SendNotification();
1106 application.Render(16);
1107 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1109 tet_infoline("Test that after 2 ticks that we have 11 textures and no requests");
1111 Test::EmitGlobalTimerSignal();
1112 application.SendNotification();
1113 application.Render(16);
1114 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1115 application.SendNotification();
1116 application.Render(16);
1117 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1119 tet_infoline("Test that after 3rd tick that we have 11 textures and no requests");
1120 Test::EmitGlobalTimerSignal();
1121 application.SendNotification();
1122 application.Render(16);
1124 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1125 application.SendNotification();
1126 application.Render(16);
1127 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1129 dummyControl.Unparent();
1132 tet_infoline("Test that removing the visual from stage deletes all textures");
1133 application.SendNotification();
1134 application.Render(16);
1135 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1140 int UtcDaliAnimatedImageVisualMultiImage05(void)
1142 ToolkitTestApplication application;
1143 TestGlAbstraction& gl = application.GetGlAbstraction();
1145 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");
1147 Property::Array urls;
1148 CopyUrlsIntoArray(urls);
1151 Property::Map propertyMap;
1152 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1153 propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1154 propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
1155 propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1156 propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1158 VisualFactory factory = VisualFactory::Get();
1159 Visual::Base visual = factory.CreateVisual(propertyMap);
1161 tet_infoline("Expect that a batch of 4 textures has been requested.");
1163 DummyControl dummyControl = DummyControl::New(true);
1164 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1165 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1167 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1168 application.GetScene().Add(dummyControl);
1169 application.SendNotification();
1170 application.Render(16);
1172 tet_infoline("Wait for the first batch to complete");
1173 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1175 tet_infoline("Test that a timer has been started");
1176 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1178 application.SendNotification();
1179 application.Render(16);
1181 tet_infoline("Test that a timer has been started");
1182 Test::EmitGlobalTimerSignal();
1183 application.SendNotification();
1184 application.Render(16);
1186 dummyControl.Unparent();
1189 application.SendNotification();
1190 application.Render(16);
1191 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1193 tet_infoline("Test that pending batch of image loads are cancelled instead of uploaded");
1194 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1195 application.SendNotification();
1196 application.Render(16);
1197 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1202 void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyControl, uint16_t frameCount, uint16_t loopCount, const char* location)
1204 TestGlAbstraction& gl = application.GetGlAbstraction();
1205 TraceCallStack& textureTrace = gl.GetTextureTrace();
1207 textureTrace.Enable(true);
1208 application.GetScene().Add(dummyControl);
1210 application.SendNotification();
1211 application.Render(16);
1213 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_INNER_LOCATION(location));
1215 application.SendNotification();
1216 application.Render();
1218 tet_infoline("Test that a timer has been created");
1219 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_INNER_LOCATION(location));
1221 for(uint16_t i = 0; i < loopCount; i++)
1223 for(uint16_t j = 0; j < frameCount; j++)
1225 if(i == 0 && j == 0)
1227 continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1229 tet_printf("Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u);
1230 Test::EmitGlobalTimerSignal();
1231 application.SendNotification();
1232 application.Render(16);
1234 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_INNER_LOCATION(location));
1236 application.SendNotification();
1237 application.Render();
1238 DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION(location));
1239 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_INNER_LOCATION(location));
1241 tet_printf("Test Loop %u \n\n", i + 1u);
1244 tet_printf("Test that after %u loops, and we have no frame. Timer should stop \n", loopCount);
1245 Test::EmitGlobalTimerSignal();
1246 application.SendNotification();
1247 application.Render(16);
1248 DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_INNER_LOCATION(location));
1250 dummyControl.Unparent();
1253 int UtcDaliAnimatedImageVisualLoopCount(void)
1255 ToolkitTestApplication application;
1257 tet_infoline("UtcDaliAnimatedImageVisualLoopCount");
1260 // request AnimatedImageVisual with a property map
1261 // Test with no (0) loop count
1262 VisualFactory factory = VisualFactory::Get();
1263 Visual::Base animatedImageVisual = factory.CreateVisual(
1265 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1266 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1267 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1268 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1269 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1270 .Add(DevelImageVisual::Property::LOOP_COUNT, 0));
1272 DummyControl dummyControl = DummyControl::New(true);
1273 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1274 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1275 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1277 TestLoopCount(application, dummyControl, 4, 0, TEST_LOCATION);
1279 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1280 animatedImageVisual.Reset();
1282 application.SendNotification();
1283 application.Render(16);
1285 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1286 animatedImageVisual = factory.CreateVisual(
1288 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1289 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1290 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1291 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1292 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1293 .Add(DevelImageVisual::Property::LOOP_COUNT, 1));
1295 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1297 TestLoopCount(application, dummyControl, 4, 1, TEST_LOCATION);
1299 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1300 animatedImageVisual.Reset();
1302 application.SendNotification();
1303 application.Render(16);
1305 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1306 animatedImageVisual = factory.CreateVisual(
1308 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1309 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1310 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1311 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1312 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1313 .Add(DevelImageVisual::Property::LOOP_COUNT, 100));
1315 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1317 TestLoopCount(application, dummyControl, 4, 100, TEST_LOCATION);
1322 int UtcDaliAnimatedImageVisualPlayback(void)
1324 ToolkitTestApplication application;
1325 TestGlAbstraction& gl = application.GetGlAbstraction();
1326 TraceCallStack& textureTrace = gl.GetTextureTrace();
1328 tet_infoline("UtcDaliAnimatedImageVisualPlayback");
1331 // request AnimatedImageVisual with a property map
1332 // Test with forever (-1) loop count
1333 VisualFactory factory = VisualFactory::Get();
1334 Visual::Base animatedImageVisual = factory.CreateVisual(
1336 .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1337 .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1338 .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1339 .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1340 .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1341 .Add(DevelImageVisual::Property::LOOP_COUNT, -1));
1343 DummyControl dummyControl = DummyControl::New(true);
1344 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1345 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1346 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1348 textureTrace.Enable(true);
1349 application.GetScene().Add(dummyControl);
1350 application.SendNotification();
1351 application.Render(16);
1353 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1355 application.SendNotification();
1356 application.Render();
1358 tet_infoline("Test that a timer has been created");
1359 DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1361 Test::EmitGlobalTimerSignal();
1362 application.SendNotification();
1363 application.Render(16);
1365 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1367 application.SendNotification();
1368 application.Render();
1369 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1371 Property::Map attributes;
1372 tet_infoline("Test Pause action. Timer should stop after Pause action");
1373 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes);
1374 Test::EmitGlobalTimerSignal();
1375 application.SendNotification();
1376 application.Render(16);
1377 DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1379 tet_infoline("Test Play action. Timer should Restart after Play action");
1380 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1381 Test::EmitGlobalTimerSignal();
1382 application.SendNotification();
1383 application.Render(16);
1385 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1387 application.SendNotification();
1388 application.Render();
1389 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1391 tet_infoline("Test Stop action. Timer should stop after Stop action");
1392 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes);
1393 Test::EmitGlobalTimerSignal();
1394 application.SendNotification();
1395 application.Render(16);
1396 DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1398 tet_infoline("Test Play action. Timer should Restart after Play action");
1399 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1400 Test::EmitGlobalTimerSignal();
1401 application.SendNotification();
1402 application.Render(16);
1404 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1406 application.SendNotification();
1407 application.Render();
1408 DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1410 dummyControl.Unparent();