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