Apply premultiply in animated image visual
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedImageVisual.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdlib.h>
18 #include <iostream>
19
20 #include <dali-toolkit-test-suite-utils.h>
21
22 #include <toolkit-event-thread-callback.h>
23 #include <toolkit-timer.h>
24
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>
31
32 #include "dummy-control.h"
33
34 using namespace Dali;
35 using namespace Dali::Toolkit;
36
37 void dali_animated_image_visual_startup(void)
38 {
39   test_return_value = TET_UNDEF;
40 }
41
42 void dali_animated_image_visual_cleanup(void)
43 {
44   test_return_value = TET_PASS;
45 }
46
47 namespace
48 {
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";
51 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
52 } // namespace
53
54 void CopyUrlsIntoArray(Property::Array& urls, int startIndex = 0)
55 {
56   for(int i = 20 + startIndex; i <= 30; ++i)
57   {
58     char* url;
59     if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
60     {
61       Property::Value value(url);
62       urls.Add(value);
63       free(url);
64     }
65   }
66 }
67
68 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
69 {
70   ToolkitTestApplication application;
71   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap");
72
73   // request AnimatedImageVisual with a property map
74   VisualFactory factory             = VisualFactory::Get();
75   Visual::Base  animatedImageVisual = factory.CreateVisual(
76     Property::Map()
77       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
78       .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
79       .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
80       .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
81       .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
82       .Add(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME)
83       .Add(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f)
84       .Add(ImageVisual::Property::CROP_TO_MASK, true)
85       .Add(DevelVisual::Property::CORNER_RADIUS, 22.2f)
86       .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE)
87       .Add(DevelVisual::Property::BORDERLINE_WIDTH, 33.3f)
88       .Add(DevelVisual::Property::BORDERLINE_COLOR, Color::RED)
89       .Add(DevelVisual::Property::BORDERLINE_OFFSET, 0.3f));
90
91   Property::Map resultMap;
92   animatedImageVisual.CreatePropertyMap(resultMap);
93   // check the property values from the returned map from a visual
94   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
95   DALI_TEST_CHECK(value);
96   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
97
98   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
99   DALI_TEST_CHECK(value);
100   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
101
102   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
103   DALI_TEST_CHECK(value);
104   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(22.2f, 22.2f, 22.2f, 22.2f), TEST_LOCATION);
105
106   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER);
107   DALI_TEST_CHECK(value);
108   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
109
110   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
111   DALI_TEST_CHECK(value);
112   DALI_TEST_EQUALS(value->Get<float>(), 33.3f, TEST_LOCATION);
113
114   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
115   DALI_TEST_CHECK(value);
116   DALI_TEST_EQUALS(value->Get<Vector4>(), Color::RED, TEST_LOCATION);
117
118   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
119   DALI_TEST_CHECK(value);
120   DALI_TEST_EQUALS(value->Get<float>(), 0.3f, TEST_LOCATION);
121
122   // Check mask properties
123   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, Property::STRING);
124   DALI_TEST_CHECK(value);
125   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
126
127   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, Property::FLOAT);
128   DALI_TEST_CHECK(value);
129   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
130
131   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, Property::BOOLEAN);
132   DALI_TEST_CHECK(value);
133   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
134
135   Vector2 naturalSize;
136   animatedImageVisual.GetNaturalSize(naturalSize);
137   DALI_TEST_EQUALS(naturalSize, Vector2(100, 100), TEST_LOCATION);
138
139   // request AnimatedImageVisual with an URL
140   Visual::Base animatedImageVisual2 = factory.CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions());
141   resultMap.Clear();
142   animatedImageVisual2.CreatePropertyMap(resultMap);
143   // check the property values from the returned map from a visual
144   value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
145   DALI_TEST_CHECK(value);
146   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
147
148   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
149   DALI_TEST_CHECK(value);
150   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
151
152   END_TEST;
153 }
154
155 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
156 {
157   ToolkitTestApplication application;
158   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap for multi image with fixed cache");
159
160   // request AnimatedImageVisual with a property map
161   VisualFactory   factory = VisualFactory::Get();
162   Property::Array urls;
163   CopyUrlsIntoArray(urls);
164
165   Visual::Base animatedImageVisual = factory.CreateVisual(
166     Property::Map()
167       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
168       .Add("url", urls)
169       .Add("batchSize", 4)
170       .Add("cacheSize", 20)
171       .Add("loopCount", 10)
172       .Add("frameDelay", 200)
173       .Add("pixelArea", Vector4())
174       .Add("wrapModeU", WrapMode::REPEAT)
175       .Add("wrapModeV", WrapMode::DEFAULT)
176       .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME)
177       .Add("maskContentScale", 1.6f)
178       .Add("cropToMask", true)
179       .Add("cornerRadius", Vector4(50.0f, 25.0f, 12.5f, 33.0f))
180       .Add("cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE)
181       .Add("borderlineWidth", 20.0f)
182       .Add("borderlineColor", Vector4())
183       .Add("borderlineOffset", -1.0f));
184
185   Property::Map resultMap;
186   animatedImageVisual.CreatePropertyMap(resultMap);
187   // check the property values from the returned map from a visual
188   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
189   DALI_TEST_CHECK(value);
190   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
191
192   value = resultMap.Find(ImageVisual::Property::URL, "url");
193   DALI_TEST_CHECK(value);
194   Property::Array* resultUrls = value->GetArray();
195   DALI_TEST_CHECK(resultUrls);
196   DALI_TEST_EQUALS(resultUrls->Count(), urls.Count(), TEST_LOCATION);
197
198   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
199   DALI_TEST_CHECK(value);
200   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
201
202   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
203   DALI_TEST_CHECK(value);
204   DALI_TEST_EQUALS(value->Get<int>(), 20, TEST_LOCATION);
205
206   value = resultMap.Find(Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount");
207   DALI_TEST_CHECK(value);
208   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
209
210   value = resultMap.Find(ImageVisual::Property::FRAME_DELAY, "frameDelay");
211   DALI_TEST_CHECK(value);
212   DALI_TEST_EQUALS(value->Get<int>(), 200, TEST_LOCATION);
213
214   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
215   DALI_TEST_CHECK(value);
216   DALI_TEST_EQUALS(value->Get<int>(), 11, TEST_LOCATION);
217
218   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius");
219   DALI_TEST_CHECK(value);
220   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(50.0f, 25.0f, 12.5f, 33.0f), TEST_LOCATION);
221
222   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
223   DALI_TEST_CHECK(value);
224   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
225
226   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
227   DALI_TEST_CHECK(value);
228   DALI_TEST_EQUALS(value->Get<float>(), 20.0f, TEST_LOCATION);
229
230   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
231   DALI_TEST_CHECK(value);
232   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4::ZERO, TEST_LOCATION);
233
234   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
235   DALI_TEST_CHECK(value);
236   DALI_TEST_EQUALS(value->Get<float>(), -1.0f, TEST_LOCATION);
237
238   // Check mask properties
239   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, "alphaMaskUrl");
240   DALI_TEST_CHECK(value);
241   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
242
243   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, "maskContentScale");
244   DALI_TEST_CHECK(value);
245   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
246
247   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, "cropToMask");
248   DALI_TEST_CHECK(value);
249   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
250
251   END_TEST;
252 }
253
254 int UtcDaliAnimatedImageVisualGetPropertyMap03(void)
255 {
256   ToolkitTestApplication application;
257   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap for multi image rolling cache");
258
259   // request AnimatedImageVisual with a property map
260   VisualFactory   factory = VisualFactory::Get();
261   Property::Array urls;
262   CopyUrlsIntoArray(urls);
263
264   Visual::Base animatedImageVisual = factory.CreateVisual(
265     Property::Map()
266       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
267       .Add("url", urls)
268       .Add("batchSize", 4)
269       .Add("cacheSize", 8)
270       .Add("loopCount", 10)
271       .Add("frameDelay", 200)
272       .Add("pixelArea", Vector4())
273       .Add("wrapModeU", WrapMode::REPEAT)
274       .Add("wrapModeV", WrapMode::DEFAULT)
275       .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME)
276       .Add("maskContentScale", 1.6f)
277       .Add("cropToMask", true)
278       .Add("cornerRadius", 50.5f));
279
280   Property::Map resultMap;
281   animatedImageVisual.CreatePropertyMap(resultMap);
282   // check the property values from the returned map from a visual
283   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
284   DALI_TEST_CHECK(value);
285   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
286
287   value = resultMap.Find(ImageVisual::Property::URL, "url");
288   DALI_TEST_CHECK(value);
289   Property::Array* resultUrls = value->GetArray();
290   DALI_TEST_CHECK(resultUrls);
291   DALI_TEST_EQUALS(resultUrls->Count(), urls.Count(), TEST_LOCATION);
292
293   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
294   DALI_TEST_CHECK(value);
295   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
296
297   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
298   DALI_TEST_CHECK(value);
299   DALI_TEST_EQUALS(value->Get<int>(), 8, TEST_LOCATION);
300
301   value = resultMap.Find(Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount");
302   DALI_TEST_CHECK(value);
303   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
304
305   value = resultMap.Find(ImageVisual::Property::FRAME_DELAY, "frameDelay");
306   DALI_TEST_CHECK(value);
307   DALI_TEST_EQUALS(value->Get<int>(), 200, TEST_LOCATION);
308
309   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
310   DALI_TEST_CHECK(value);
311   DALI_TEST_EQUALS(value->Get<int>(), 11, TEST_LOCATION);
312
313   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius");
314   DALI_TEST_CHECK(value);
315   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(50.5f, 50.5f, 50.5f, 50.5f), TEST_LOCATION);
316
317   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
318   DALI_TEST_CHECK(value);
319   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
320
321   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
322   DALI_TEST_CHECK(value);
323   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
324
325   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
326   DALI_TEST_CHECK(value);
327   DALI_TEST_EQUALS(value->Get<Vector4>(), Color::BLACK, TEST_LOCATION);
328
329   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
330   DALI_TEST_CHECK(value);
331   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
332
333   // Check mask properties
334   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, "alphaMaskUrl");
335   DALI_TEST_CHECK(value);
336   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
337
338   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, "maskContentScale");
339   DALI_TEST_CHECK(value);
340   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
341
342   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, "cropToMask");
343   DALI_TEST_CHECK(value);
344   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
345
346   END_TEST;
347 }
348
349 int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
350 {
351   ToolkitTestApplication application;
352   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap");
353
354   // request AnimatedImageVisual with a property map
355   VisualFactory factory             = VisualFactory::Get();
356   Visual::Base  animatedImageVisual = factory.CreateVisual(
357     Property::Map()
358       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
359       .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
360       .Add(ImageVisual::Property::BATCH_SIZE, 1)
361       .Add(ImageVisual::Property::CACHE_SIZE, 1)
362       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true)
363       .Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED)
364       .Add(ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED)
365       .Add(DevelVisual::Property::BORDERLINE_WIDTH, 0.4f));
366
367   Property::Map resultMap;
368   animatedImageVisual.CreatePropertyMap(resultMap);
369
370   // check the property values from the returned map from a visual
371   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
372   DALI_TEST_CHECK(value);
373   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
374
375   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
376   DALI_TEST_CHECK(value);
377   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
378
379   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, Property::INTEGER);
380   DALI_TEST_CHECK(value);
381   DALI_TEST_CHECK(value->Get<int>() == 2);
382
383   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, Property::INTEGER);
384   DALI_TEST_CHECK(value);
385   DALI_TEST_CHECK(value->Get<int>() == 2);
386
387   value = resultMap.Find(ImageVisual::Property::SYNCHRONOUS_LOADING, Property::BOOLEAN);
388   DALI_TEST_CHECK(value);
389   DALI_TEST_CHECK(value->Get<bool>() == true);
390
391   value = resultMap.Find(ImageVisual::Property::RELEASE_POLICY, Property::INTEGER);
392   DALI_TEST_CHECK(value);
393   DALI_TEST_CHECK(value->Get<int>() == ImageVisual::ReleasePolicy::DETACHED);
394
395   value = resultMap.Find(ImageVisual::Property::LOAD_POLICY, Property::INTEGER);
396   DALI_TEST_CHECK(value);
397   DALI_TEST_CHECK(value->Get<int>() == ImageVisual::LoadPolicy::ATTACHED);
398
399   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
400   DALI_TEST_CHECK(value);
401   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
402
403   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
404   DALI_TEST_CHECK(value);
405   DALI_TEST_EQUALS(value->Get<float>(), 0.4f, TEST_LOCATION);
406
407   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
408   DALI_TEST_CHECK(value);
409   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
410
411   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
412   DALI_TEST_CHECK(value);
413   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
414
415   END_TEST;
416 }
417
418 int UtcDaliAnimatedImageVisualImageLoadingFail01(void)
419 {
420   ToolkitTestApplication application;
421   TestGlAbstraction&     gl = application.GetGlAbstraction();
422
423   {
424     Property::Map propertyMap;
425     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
426     propertyMap.Insert(ImageVisual::Property::URL, "dummy.gif");
427     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
428     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
429     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
430     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
431     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
432     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
433
434     VisualFactory factory = VisualFactory::Get();
435     Visual::Base  visual  = factory.CreateVisual(propertyMap);
436
437     DummyControl        dummyControl = DummyControl::New(true);
438     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
439     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
440
441     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
442     application.GetScene().Add(dummyControl);
443
444     TraceCallStack& textureTrace = gl.GetTextureTrace();
445     textureTrace.Enable(true);
446
447     application.SendNotification();
448     application.Render(20);
449
450     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
451
452     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
453
454     application.SendNotification();
455     application.Render(20);
456
457     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
458
459     dummyControl.Unparent();
460   }
461
462   END_TEST;
463 }
464
465 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
466 {
467   ToolkitTestApplication application;
468   TestGlAbstraction&     gl = application.GetGlAbstraction();
469
470   {
471     Property::Map propertyMap;
472     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
473     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
474     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
475     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
476     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
477     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
478     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
479     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
480
481     VisualFactory factory = VisualFactory::Get();
482     Visual::Base  visual  = factory.CreateVisual(propertyMap);
483
484     DummyControl        dummyControl = DummyControl::New(true);
485     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
486     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
487
488     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
489     application.GetScene().Add(dummyControl);
490
491     TraceCallStack& textureTrace = gl.GetTextureTrace();
492     textureTrace.Enable(true);
493
494     application.SendNotification();
495     application.Render(20);
496
497     // The first frame is loaded synchronously and load next batch.
498     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
499
500     application.SendNotification();
501     application.Render();
502
503     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
504     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
505
506     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3);
507
508     application.SendNotification();
509     application.Render(20);
510
511     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
512
513     application.SendNotification();
514     application.Render();
515
516     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
517
518     dummyControl.Unparent();
519   }
520   tet_infoline("Test that removing the visual from stage deletes all textures");
521   application.SendNotification();
522   application.Render(16);
523   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
524
525   END_TEST;
526 }
527
528 int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask(void)
529 {
530   ToolkitTestApplication application;
531   TestGlAbstraction&     gl = application.GetGlAbstraction();
532
533   {
534     Property::Map propertyMap;
535     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
536     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
537     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
538     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
539     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
540     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
541     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
542     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
543     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
544
545     VisualFactory factory = VisualFactory::Get();
546     Visual::Base  visual  = factory.CreateVisual(propertyMap);
547
548     Property::Map testMap;
549     visual.CreatePropertyMap(testMap);
550     DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
551
552     DummyControl        dummyControl = DummyControl::New(true);
553     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
554     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
555
556     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
557     application.GetScene().Add(dummyControl);
558
559     TraceCallStack& textureTrace = gl.GetTextureTrace();
560     textureTrace.Enable(true);
561
562     application.SendNotification();
563     application.Render(20);
564
565     // The first frame is loaded synchronously and load next batch with masking
566     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
567
568     application.SendNotification();
569     application.Render();
570
571     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
572     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
573
574     dummyControl.Unparent();
575   }
576   tet_infoline("Test that removing the visual from stage deletes all textures");
577   application.SendNotification();
578   application.Render(16);
579   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
580
581   END_TEST;
582 }
583
584 int UtcDaliAnimatedImageVisualJumpToAction(void)
585 {
586   ToolkitTestApplication application;
587   TestGlAbstraction&     gl = application.GetGlAbstraction();
588
589   Property::Array urls;
590   CopyUrlsIntoArray(urls);
591
592   {
593     Property::Map propertyMap;
594     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
595     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
596     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
597     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 12);
598     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
599
600     VisualFactory factory = VisualFactory::Get();
601     Visual::Base  visual  = factory.CreateVisual(propertyMap);
602
603     DummyControl        dummyControl = DummyControl::New(true);
604     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
605     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
606
607     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
608     application.GetScene().Add(dummyControl);
609     application.SendNotification();
610     application.Render(20);
611
612     tet_infoline("Ready the visual after the visual is on stage");
613     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
614
615     tet_infoline("Test that a timer has been started");
616     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
617
618     TraceCallStack& textureTrace = gl.GetTextureTrace();
619     textureTrace.Enable(true);
620
621     application.SendNotification();
622     application.Render(20);
623
624     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
625
626     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
627
628     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
629
630     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20);
631
632     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
633
634     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
635
636     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
637     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
638
639     dummyControl.Unparent();
640   }
641   tet_infoline("Test that removing the visual from stage deletes all textures");
642   application.SendNotification();
643   application.Render(16);
644   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
645
646   END_TEST;
647 }
648
649 int UtcDaliAnimatedImageVisualStopBehavior(void)
650 {
651   ToolkitTestApplication application;
652   TestGlAbstraction&     gl = application.GetGlAbstraction();
653
654   Property::Array urls;
655   CopyUrlsIntoArray(urls);
656
657   {
658     Property::Map propertyMap;
659     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
660     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
661     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
662     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
663     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
664     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
665
666     VisualFactory factory = VisualFactory::Get();
667     Visual::Base  visual  = factory.CreateVisual(propertyMap);
668
669     // Expect that a batch of 4 textures has been requested. These will be serially loaded
670     // below.
671
672     DummyControl        dummyControl = DummyControl::New(true);
673     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
674     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
675
676     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
677     application.GetScene().Add(dummyControl);
678     application.SendNotification();
679     application.Render(20);
680
681     tet_infoline("Ready the visual after the visual is on stage");
682     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
683
684     tet_infoline("Test that a timer has been started");
685     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
686
687     TraceCallStack& textureTrace = gl.GetTextureTrace();
688     textureTrace.Enable(true);
689
690     application.SendNotification();
691     application.Render(20);
692
693     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
694
695     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
696
697     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
698
699     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1);
700
701     // Expect the second batch has been requested
702     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
703
704     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
705
706     dummyControl.Unparent();
707   }
708   tet_infoline("Test that removing the visual from stage deletes all textures");
709   application.SendNotification();
710   application.Render(16);
711   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
712
713   END_TEST;
714 }
715
716 int UtcDaliAnimatedImageVisualStopBehavior02(void)
717 {
718   ToolkitTestApplication application;
719   TestGlAbstraction&     gl = application.GetGlAbstraction();
720
721   Property::Array urls;
722   CopyUrlsIntoArray(urls);
723
724   {
725     Property::Map propertyMap;
726     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
727     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
728     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
729     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
730     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
731     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
732
733     VisualFactory factory = VisualFactory::Get();
734     Visual::Base  visual  = factory.CreateVisual(propertyMap);
735
736     // Expect that a batch of 4 textures has been requested. These will be serially loaded
737     // below.
738
739     DummyControl        dummyControl = DummyControl::New(true);
740     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
741     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
742
743     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
744     application.GetScene().Add(dummyControl);
745
746     tet_infoline("Ready the visual after the visual is on stage");
747     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
748
749     TraceCallStack& textureTrace = gl.GetTextureTrace();
750     textureTrace.Enable(true);
751
752     application.SendNotification();
753     application.Render(20);
754
755     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
756
757     Test::EmitGlobalTimerSignal();
758
759     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
760
761     application.SendNotification();
762     application.Render(20);
763
764     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
765
766     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
767
768     tet_infoline("Ready the visual after the visual is on stage");
769     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
770
771     application.SendNotification();
772     application.Render(20);
773
774     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
775
776     dummyControl.Unparent();
777   }
778   tet_infoline("Test that removing the visual from stage deletes all textures");
779   application.SendNotification();
780   application.Render(16);
781   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
782
783   END_TEST;
784 }
785
786 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
787 {
788   ToolkitTestApplication application;
789   TestGlAbstraction&     gl = application.GetGlAbstraction();
790
791   tet_infoline("Set cache size same as GIF frame, and try to load same image at another ImageView");
792   {
793     Property::Map propertyMap;
794     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
795     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
796     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
797     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
798     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
799
800     VisualFactory factory = VisualFactory::Get();
801     Visual::Base  visual  = factory.CreateVisual(propertyMap);
802
803     // Expect that a batch of 4 textures has been requested. These will be serially loaded
804     // below.
805
806     DummyControl        dummyControl = DummyControl::New(true);
807     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
808     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
809
810     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
811     application.GetScene().Add(dummyControl);
812
813     application.SendNotification();
814     application.Render();
815
816     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
817
818     // Batch 2 frames. Now frame 0, 1 cached.
819     application.SendNotification();
820     application.Render(20);
821
822     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
823
824     tet_infoline("Test that a timer has been started");
825
826     TraceCallStack& textureTrace = gl.GetTextureTrace();
827     textureTrace.Enable(true);
828
829     Test::EmitGlobalTimerSignal();
830
831     application.SendNotification();
832     application.Render();
833
834     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
835
836     // 0 frame removed. and after, batch 2 frames. Now frame 1, 2, 3 cached.
837     application.SendNotification();
838     application.Render(20);
839
840     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
841
842     Visual::Base        visual2       = factory.CreateVisual(propertyMap);
843     DummyControl        dummyControl2 = DummyControl::New(true);
844     Impl::DummyControl& dummyImpl2    = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
845     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
846     application.GetScene().Add(dummyControl2);
847
848     tet_infoline("Add new view with same url");
849
850     application.SendNotification();
851     application.Render();
852
853     // Note that we only re-load 0 frame.
854     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
855
856     // To do: we need to fix caching bug in animated-visual
857     //tet_infoline("Test that we don't try to re-load new image cause it cached");
858     //DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
859
860     // Batch 2 frames. Now visual frame 1, 2, 3 cached and visual2 frame 0, 1 cached.
861     application.SendNotification();
862     application.Render(20);
863
864     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION);
865
866     textureTrace.Reset();
867
868     tet_infoline("Load some many frames");
869
870     const int repeatCount = 10;
871     for(int repeat = 0; repeat < repeatCount; ++repeat)
872     {
873       Test::EmitGlobalTimerSignal();
874       application.SendNotification();
875       application.Render(2000);
876     }
877
878     DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // A new texture should NOT be generated.
879     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION);
880
881     textureTrace.Reset();
882
883     dummyControl.Unparent();
884     dummyControl2.Unparent();
885   }
886   tet_infoline("Test that removing the visual from stage deletes all textures");
887   application.SendNotification();
888   application.Render(20);
889   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
890
891   END_TEST;
892 }
893
894 int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01(void)
895 {
896   ToolkitTestApplication application;
897   TestGlAbstraction&     gl = application.GetGlAbstraction();
898
899   {
900     Property::Map propertyMap;
901     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
902     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
903     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
904     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
905     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
906     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
907
908     VisualFactory factory = VisualFactory::Get();
909     Visual::Base  visual  = factory.CreateVisual(propertyMap);
910
911     DummyControl        dummyControl = DummyControl::New(true);
912     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
913     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
914
915     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
916     application.GetScene().Add(dummyControl);
917
918     application.SendNotification();
919     application.Render();
920
921     // load two frame(batch size), load mask image, and request two masking
922     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
923
924     application.SendNotification();
925     application.Render(20);
926
927     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
928
929     dummyControl.Unparent();
930   }
931   tet_infoline("Test that removing the visual from stage deletes all textures");
932   application.SendNotification();
933   application.Render(20);
934   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
935
936   END_TEST;
937 }
938
939 int UtcDaliAnimatedImageVisualMultiImage01(void)
940 {
941   ToolkitTestApplication application;
942   TestGlAbstraction&     gl = application.GetGlAbstraction();
943
944   Property::Array urls;
945   CopyUrlsIntoArray(urls);
946
947   {
948     Property::Map propertyMap;
949     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
950     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
951     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
952     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
953     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
954
955     VisualFactory factory = VisualFactory::Get();
956     Visual::Base  visual  = factory.CreateVisual(propertyMap);
957
958     // Expect that a batch of 4 textures has been requested. These will be serially loaded
959     // below.
960
961     DummyControl        dummyControl = DummyControl::New(true);
962     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
963     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
964
965     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
966     application.GetScene().Add(dummyControl);
967     application.SendNotification();
968     application.Render(16);
969
970     tet_infoline("Ready the visual after the visual is on stage");
971     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
972
973     tet_infoline("Test that a timer has been started");
974     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
975
976     TraceCallStack& textureTrace = gl.GetTextureTrace();
977     textureTrace.Enable(true);
978
979     application.SendNotification();
980     application.Render(16);
981
982     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
983     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
984
985     tet_infoline("Test that after 1 tick, and file loads completed, that we have 7 textures");
986     Test::EmitGlobalTimerSignal();
987
988     // Expect the second batch has been requested
989     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
990
991     application.SendNotification();
992     application.Render(16);
993     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
994
995     tet_infoline("Test that after 2 ticks that we have 6 textures");
996
997     Test::EmitGlobalTimerSignal();
998     application.SendNotification();
999     application.Render(16);
1000     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 6, TEST_LOCATION);
1001
1002     tet_infoline("And that at least 2 textures were requested");
1003     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1004     application.SendNotification();
1005     application.Render(16);
1006     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
1007
1008     tet_infoline("Test that after 3rd tick that we have 7 textures and 1 request");
1009     Test::EmitGlobalTimerSignal();
1010     application.SendNotification();
1011     application.Render(16);
1012     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1013
1014     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1015     application.SendNotification();
1016     application.Render(16);
1017     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
1018
1019     dummyControl.Unparent();
1020   }
1021   tet_infoline("Test that removing the visual from stage deletes all textures");
1022   application.SendNotification();
1023   application.Render(16);
1024   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1025
1026   END_TEST;
1027 }
1028
1029 int UtcDaliAnimatedImageVisualMultiImage02(void)
1030 {
1031   ToolkitTestApplication application;
1032   TestGlAbstraction&     gl = application.GetGlAbstraction();
1033
1034   tet_infoline("Test that the animated visual has different batch and cache size.");
1035
1036   {
1037     Property::Array urls;
1038     CopyUrlsIntoArray(urls);
1039
1040     Property::Map propertyMap;
1041     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1042     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1043     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 0);
1044     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 0);
1045     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1046
1047     VisualFactory factory = VisualFactory::Get();
1048     Visual::Base  visual  = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1049
1050     // Check the batch size and cache size need to have minimum 2.
1051     Property::Map resultMap;
1052     visual.CreatePropertyMap(resultMap);
1053     Property::Value* value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
1054     DALI_TEST_CHECK(value);
1055     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1056     value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
1057     DALI_TEST_CHECK(value);
1058     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1059     visual.Reset();
1060
1061     // Batch size is 2 and cache size is 3
1062     propertyMap.Clear();
1063     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1064     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1065     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1066     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1067     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1068
1069     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1070
1071     // Expect that each image is loaded each tick
1072     DummyControl        dummyControl = DummyControl::New(true);
1073     Impl::DummyControl& dummyImpl1   = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1074     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1075     visual.Reset();
1076
1077     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1078     application.GetScene().Add(dummyControl);
1079     application.SendNotification();
1080     application.Render(16);
1081
1082     tet_infoline("Ready the visual after the visual is on window");
1083     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1084     application.SendNotification();
1085     application.Render(16); //glGenTextures 1 and 2
1086     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
1087
1088     tet_infoline("Test that each tick, a new image is requested");
1089     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1090     application.SendNotification();
1091     application.Render(16);
1092     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1093     application.SendNotification();
1094     application.Render(16); //glGenTextures 3
1095     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1096
1097     tet_infoline("Test that each tick, a new image is requested");
1098     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1099     application.SendNotification();
1100     application.Render(16);
1101     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1102     application.SendNotification();
1103     application.Render(16); //glGenTextures 4
1104     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1105
1106     dummyImpl1.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1107     dummyControl.Unparent();
1108
1109     // Batch size is 9 and cache size is 4
1110     propertyMap.Clear();
1111     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1112     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1113     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1114     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 7);
1115     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1116
1117     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1118
1119     // Expect that each image is loaded each tick
1120     dummyControl                   = DummyControl::New(true);
1121     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1122     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1123     visual.Reset();
1124
1125     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1126     application.GetScene().Add(dummyControl);
1127     application.SendNotification();
1128     application.Render(16);
1129
1130     tet_infoline("Ready the visual after the visual is on window");
1131     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1132     application.SendNotification();
1133     application.Render(16); //glGenTextures 1, 2, and 3
1134     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1135
1136     tet_infoline("Test that each tick, a new image is requested");
1137     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1138     application.SendNotification();
1139     application.Render(16);
1140     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1141     application.SendNotification();
1142     application.Render(16); //glGenTextures 4, 5, and 6
1143     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 5, TEST_LOCATION);
1144
1145     tet_infoline("Test that each tick, a new image is requested");
1146     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1147     application.SendNotification();
1148     application.Render(16);
1149     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1150     application.SendNotification();
1151     application.Render(16); //glGenTextures 7, 1, and 2
1152     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1153
1154     tet_infoline("Test that each tick, a new image is requested");
1155     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
1156     application.SendNotification();
1157     application.Render(16);
1158     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1159     application.SendNotification();
1160     application.Render(16); //glGenTextures 3
1161     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1162
1163     dummyControl.Unparent();
1164   }
1165   tet_infoline("Test that removing the visual from window deletes all textures");
1166   application.SendNotification();
1167   application.Render(16);
1168   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1169
1170   END_TEST;
1171 }
1172
1173 int UtcDaliAnimatedImageVisualMultiImage03(void)
1174 {
1175   ToolkitTestApplication application;
1176   TestGlAbstraction&     gl = application.GetGlAbstraction();
1177
1178   {
1179     Property::Array urls1, urls2;
1180     CopyUrlsIntoArray(urls1);
1181     CopyUrlsIntoArray(urls2);
1182
1183     Property::Map animatedImageMap1;
1184     animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE);
1185     animatedImageMap1.Insert(ImageVisual::Property::URL, Property::Value(urls1));
1186     animatedImageMap1.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1187     animatedImageMap1.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1188     animatedImageMap1.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1189
1190     Property::Map animatedImageMap2;
1191     animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE);
1192     animatedImageMap2.Insert(ImageVisual::Property::URL, Property::Value(urls2));
1193     animatedImageMap2.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1194     animatedImageMap2.Insert(ImageVisual::Property::CACHE_SIZE, 2);
1195     animatedImageMap2.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1196
1197     VisualFactory factory              = VisualFactory::Get();
1198     Visual::Base  animatedImageVisual1 = factory.CreateVisual(animatedImageMap1);
1199
1200     tet_infoline("Create two image views with the same URLs, offset by 1 frame.");
1201
1202     DummyControl        dummyControl1 = DummyControl::New(true);
1203     Impl::DummyControl& dummyImpl1    = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
1204     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual1);
1205     dummyControl1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1206     application.GetScene().Add(dummyControl1);
1207
1208     application.SendNotification();
1209     application.Render(16);
1210
1211     tet_infoline("Ready the requested image after the first visual is on stage");
1212     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1213     application.SendNotification();
1214     application.Render(16);
1215     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1216
1217     Visual::Base        animatedImageVisual2 = factory.CreateVisual(animatedImageMap2);
1218     DummyControl        dummyControl2        = DummyControl::New(true);
1219     Impl::DummyControl& dummyImpl2           = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
1220     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual2);
1221     dummyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1222     application.GetScene().Add(dummyControl2);
1223     application.SendNotification();
1224     application.Render(16);
1225
1226     tet_infoline("The texture cache should be holding the requested images; check that the renderer has a texture");
1227     TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
1228     Texture    t1 = ts.GetTexture(0);
1229     DALI_TEST_EQUALS(ts.GetTextureCount(), 1, TEST_LOCATION);
1230
1231     tet_infoline("Test that on the first tick, 1 new image is requested");
1232     Test::EmitGlobalTimerSignal(); // Both visuals should tick
1233
1234     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1235     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1236
1237     ts         = dummyControl2.GetRendererAt(0).GetTextures();
1238     Texture t2 = ts.GetTexture(0);
1239     DALI_TEST_CHECK(t1 != t2);
1240
1241     dummyControl1.Unparent();
1242     dummyControl2.Unparent();
1243   }
1244   tet_infoline("Test that removing the visual from stage deletes all textures");
1245   application.SendNotification();
1246   application.Render(16);
1247   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1248
1249   END_TEST;
1250 }
1251
1252 int UtcDaliAnimatedImageVisualMultiImage04(void)
1253 {
1254   ToolkitTestApplication application;
1255   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1256   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1257   textureTrace.Enable(true);
1258
1259   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");
1260
1261   Property::Array urls;
1262   CopyUrlsIntoArray(urls);
1263
1264   {
1265     Property::Map propertyMap;
1266     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1267     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1268     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 6);
1269     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1270     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1271
1272     VisualFactory factory = VisualFactory::Get();
1273     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1274
1275     tet_infoline("Expect that a batch of 7 textures has been requested.");
1276
1277     DummyControl        dummyControl = DummyControl::New(true);
1278     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1279     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1280
1281     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1282     application.GetScene().Add(dummyControl);
1283     application.SendNotification();
1284     application.Render(16);
1285
1286     tet_infoline("Wait for the first batch to complete");
1287     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
1288
1289     tet_infoline("Test that a timer has been started");
1290     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1291
1292     application.SendNotification();
1293     application.Render(16);
1294
1295     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 6, TEST_LOCATION);
1296     tet_infoline("Test that after 1 tick, and 5 file loads completed, that we have 11 textures");
1297     Test::EmitGlobalTimerSignal();
1298     application.SendNotification();
1299     application.Render(16);
1300
1301     // Expect the second batch has been requested
1302     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
1303
1304     application.SendNotification();
1305     application.Render(16);
1306     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1307
1308     tet_infoline("Test that after 2 ticks that we have 11 textures and no requests");
1309
1310     Test::EmitGlobalTimerSignal();
1311     application.SendNotification();
1312     application.Render(16);
1313     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1314     application.SendNotification();
1315     application.Render(16);
1316     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1317
1318     tet_infoline("Test that after 3rd tick that we have 11 textures and no requests");
1319     Test::EmitGlobalTimerSignal();
1320     application.SendNotification();
1321     application.Render(16);
1322
1323     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1324     application.SendNotification();
1325     application.Render(16);
1326     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1327
1328     dummyControl.Unparent();
1329   }
1330
1331   tet_infoline("Test that removing the visual from stage deletes all textures");
1332   application.SendNotification();
1333   application.Render(16);
1334   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1335
1336   END_TEST;
1337 }
1338
1339 int UtcDaliAnimatedImageVisualMultiImage05(void)
1340 {
1341   ToolkitTestApplication application;
1342   TestGlAbstraction&     gl = application.GetGlAbstraction();
1343
1344   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");
1345
1346   Property::Array urls;
1347   CopyUrlsIntoArray(urls);
1348
1349   {
1350     Property::Map propertyMap;
1351     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1352     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1353     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
1354     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1355     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1356
1357     VisualFactory factory = VisualFactory::Get();
1358     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1359
1360     tet_infoline("Expect that a batch of 4 textures has been requested.");
1361
1362     DummyControl        dummyControl = DummyControl::New(true);
1363     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1364     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1365
1366     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1367     application.GetScene().Add(dummyControl);
1368     application.SendNotification();
1369     application.Render(16);
1370
1371     tet_infoline("Wait for the first batch to complete");
1372     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1373
1374     tet_infoline("Test that a timer has been started");
1375     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1376
1377     application.SendNotification();
1378     application.Render(16);
1379
1380     tet_infoline("Test that a timer has been started");
1381     Test::EmitGlobalTimerSignal();
1382     application.SendNotification();
1383     application.Render(16);
1384
1385     dummyControl.Unparent();
1386   }
1387
1388   application.SendNotification();
1389   application.Render(16);
1390   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1391
1392   tet_infoline("Test that pending batch of image loads are cancelled instead of uploaded");
1393   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1394   application.SendNotification();
1395   application.Render(16);
1396   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1397
1398   END_TEST;
1399 }
1400
1401 void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyControl, uint16_t frameCount, uint16_t loopCount, const char* location)
1402 {
1403   TestGlAbstraction& gl           = application.GetGlAbstraction();
1404   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1405
1406   textureTrace.Enable(true);
1407   application.GetScene().Add(dummyControl);
1408
1409   application.SendNotification();
1410   application.Render(16);
1411
1412   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_INNER_LOCATION(location));
1413
1414   application.SendNotification();
1415   application.Render();
1416
1417   tet_infoline("Test that a timer has been created");
1418   DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_INNER_LOCATION(location));
1419
1420   for(uint16_t i = 0; i < loopCount; i++)
1421   {
1422     for(uint16_t j = 0; j < frameCount; j++)
1423     {
1424       if(i == 0 && j == 0)
1425       {
1426         continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1427       }
1428       tet_printf("Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u);
1429       Test::EmitGlobalTimerSignal();
1430       application.SendNotification();
1431       application.Render(16);
1432
1433       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_INNER_LOCATION(location));
1434
1435       application.SendNotification();
1436       application.Render();
1437       DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION(location));
1438       DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_INNER_LOCATION(location));
1439     }
1440     tet_printf("Test Loop %u \n\n", i + 1u);
1441   }
1442
1443   tet_printf("Test that after %u loops, and we have no frame. Timer should stop \n", loopCount);
1444   Test::EmitGlobalTimerSignal();
1445   application.SendNotification();
1446   application.Render(16);
1447   DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_INNER_LOCATION(location));
1448
1449   dummyControl.Unparent();
1450 }
1451
1452 int UtcDaliAnimatedImageVisualLoopCount(void)
1453 {
1454   ToolkitTestApplication application;
1455
1456   tet_infoline("UtcDaliAnimatedImageVisualLoopCount");
1457
1458   {
1459     // request AnimatedImageVisual with a property map
1460     // Test with no (0) loop count
1461     VisualFactory factory             = VisualFactory::Get();
1462     Visual::Base  animatedImageVisual = factory.CreateVisual(
1463       Property::Map()
1464         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1465         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1466         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1467         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1468         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1469         .Add(DevelImageVisual::Property::LOOP_COUNT, 0));
1470
1471     DummyControl        dummyControl = DummyControl::New(true);
1472     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1473     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1474     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1475
1476     TestLoopCount(application, dummyControl, 4, 0, TEST_LOCATION);
1477
1478     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1479     animatedImageVisual.Reset();
1480
1481     application.SendNotification();
1482     application.Render(16);
1483
1484     // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1485     animatedImageVisual = factory.CreateVisual(
1486       Property::Map()
1487         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1488         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1489         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1490         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1491         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1492         .Add(DevelImageVisual::Property::LOOP_COUNT, 1));
1493
1494     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1495
1496     TestLoopCount(application, dummyControl, 4, 1, TEST_LOCATION);
1497
1498     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1499     animatedImageVisual.Reset();
1500
1501     application.SendNotification();
1502     application.Render(16);
1503
1504     // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1505     animatedImageVisual = factory.CreateVisual(
1506       Property::Map()
1507         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1508         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1509         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1510         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1511         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1512         .Add(DevelImageVisual::Property::LOOP_COUNT, 100));
1513
1514     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1515
1516     TestLoopCount(application, dummyControl, 4, 100, TEST_LOCATION);
1517   }
1518   END_TEST;
1519 }
1520
1521 int UtcDaliAnimatedImageVisualPlayback(void)
1522 {
1523   ToolkitTestApplication application;
1524   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1525   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1526
1527   tet_infoline("UtcDaliAnimatedImageVisualPlayback");
1528
1529   {
1530     // request AnimatedImageVisual with a property map
1531     // Test with forever (-1) loop count
1532     VisualFactory factory             = VisualFactory::Get();
1533     Visual::Base  animatedImageVisual = factory.CreateVisual(
1534       Property::Map()
1535         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1536         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1537         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1538         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1539         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1540         .Add(DevelImageVisual::Property::LOOP_COUNT, -1));
1541
1542     DummyControl        dummyControl = DummyControl::New(true);
1543     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1544     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1545     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1546
1547     textureTrace.Enable(true);
1548     application.GetScene().Add(dummyControl);
1549     application.SendNotification();
1550     application.Render(16);
1551
1552     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1553
1554     application.SendNotification();
1555     application.Render();
1556
1557     tet_infoline("Test that a timer has been created");
1558     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1559
1560     Test::EmitGlobalTimerSignal();
1561     application.SendNotification();
1562     application.Render(16);
1563
1564     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1565
1566     application.SendNotification();
1567     application.Render();
1568     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1569
1570     Property::Map attributes;
1571     tet_infoline("Test Pause action. Timer should stop after Pause action");
1572     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes);
1573     Test::EmitGlobalTimerSignal();
1574     application.SendNotification();
1575     application.Render(16);
1576     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1577
1578     tet_infoline("Test Play action. Timer should Restart after Play action");
1579     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1580     Test::EmitGlobalTimerSignal();
1581     application.SendNotification();
1582     application.Render(16);
1583
1584     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1585
1586     application.SendNotification();
1587     application.Render();
1588     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1589
1590     tet_infoline("Test Stop action. Timer should stop after Stop action");
1591     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes);
1592     Test::EmitGlobalTimerSignal();
1593     application.SendNotification();
1594     application.Render(16);
1595     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1596
1597     tet_infoline("Test Play action. Timer should Restart after Play action");
1598     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1599     Test::EmitGlobalTimerSignal();
1600     application.SendNotification();
1601     application.Render(16);
1602
1603     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1604
1605     application.SendNotification();
1606     application.Render();
1607     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1608
1609     dummyControl.Unparent();
1610   }
1611
1612   END_TEST;
1613 }