4535413409da71f2cd36ccfc15979f4e4fffba19
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedImageVisual.cpp
1 /*
2  * Copyright (c) 2023 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 #include <dali/devel-api/adaptor-framework/window-devel.h>
32
33 #include "dummy-control.h"
34
35 using namespace Dali;
36 using namespace Dali::Toolkit;
37
38 void dali_animated_image_visual_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void dali_animated_image_visual_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48 namespace
49 {
50 const char* TEST_IMAGE_FILE_NAME      = TEST_RESOURCE_DIR "/application-icon-%02d.png";
51 const char* TEST_GIF_FILE_NAME        = TEST_RESOURCE_DIR "/anim.gif";
52 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
53 const char* TEST_WEBP_FILE_NAME       = TEST_RESOURCE_DIR "/dali-logo.webp";
54 } // namespace
55
56 void CopyUrlsIntoArray(Property::Array& urls, int startIndex = 0)
57 {
58   for(int i = 20 + startIndex; i <= 30; ++i)
59   {
60     char* url;
61     if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
62     {
63       Property::Value value(url);
64       urls.Add(value);
65       free(url);
66     }
67   }
68 }
69
70 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
71 {
72   ToolkitTestApplication application;
73   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap");
74
75   // request AnimatedImageVisual with a property map
76   VisualFactory factory             = VisualFactory::Get();
77   Visual::Base  animatedImageVisual = factory.CreateVisual(
78     Property::Map()
79       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
80       .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
81       .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
82       .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
83       .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
84       .Add(ImageVisual::Property::FITTING_MODE, FittingMode::FIT_WIDTH)
85       .Add(ImageVisual::Property::SAMPLING_MODE, SamplingMode::NEAREST)
86       .Add(ImageVisual::Property::DESIRED_WIDTH, 154)
87       .Add(ImageVisual::Property::DESIRED_HEIGHT, 79)
88       .Add(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME)
89       .Add(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f)
90       .Add(ImageVisual::Property::CROP_TO_MASK, true)
91       .Add(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING)
92       .Add(DevelVisual::Property::CORNER_RADIUS, 22.2f)
93       .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE)
94       .Add(DevelVisual::Property::BORDERLINE_WIDTH, 33.3f)
95       .Add(DevelVisual::Property::BORDERLINE_COLOR, Color::RED)
96       .Add(DevelVisual::Property::BORDERLINE_OFFSET, 0.3f));
97
98   Property::Map resultMap;
99   animatedImageVisual.CreatePropertyMap(resultMap);
100   // check the property values from the returned map from a visual
101   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
102   DALI_TEST_CHECK(value);
103   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
104
105   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
106   DALI_TEST_CHECK(value);
107   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
108
109   value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_U, Property::INTEGER);
110   DALI_TEST_CHECK(value);
111   DALI_TEST_CHECK(value->Get<int>() == WrapMode::REPEAT);
112
113   value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_V, Property::INTEGER);
114   DALI_TEST_CHECK(value);
115   DALI_TEST_CHECK(value->Get<int>() == WrapMode::DEFAULT);
116
117   value = resultMap.Find(Toolkit::ImageVisual::Property::FITTING_MODE, Property::INTEGER);
118   DALI_TEST_CHECK(value);
119   DALI_TEST_CHECK(value->Get<int>() == FittingMode::FIT_WIDTH);
120
121   value = resultMap.Find(Toolkit::ImageVisual::Property::SAMPLING_MODE, Property::INTEGER);
122   DALI_TEST_CHECK(value);
123   DALI_TEST_CHECK(value->Get<int>() == SamplingMode::NEAREST);
124
125   value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
126   DALI_TEST_CHECK(value);
127   DALI_TEST_CHECK(value->Get<int>() == 154);
128
129   value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
130   DALI_TEST_CHECK(value);
131   DALI_TEST_CHECK(value->Get<int>() == 79);
132
133   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
134   DALI_TEST_CHECK(value);
135   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(22.2f, 22.2f, 22.2f, 22.2f), TEST_LOCATION);
136
137   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER);
138   DALI_TEST_CHECK(value);
139   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
140
141   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
142   DALI_TEST_CHECK(value);
143   DALI_TEST_EQUALS(value->Get<float>(), 33.3f, TEST_LOCATION);
144
145   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
146   DALI_TEST_CHECK(value);
147   DALI_TEST_EQUALS(value->Get<Vector4>(), Color::RED, TEST_LOCATION);
148
149   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
150   DALI_TEST_CHECK(value);
151   DALI_TEST_EQUALS(value->Get<float>(), 0.3f, TEST_LOCATION);
152
153   // Check mask properties
154   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, Property::STRING);
155   DALI_TEST_CHECK(value);
156   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
157
158   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, Property::FLOAT);
159   DALI_TEST_CHECK(value);
160   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
161
162   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, Property::BOOLEAN);
163   DALI_TEST_CHECK(value);
164   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
165
166   value = resultMap.Find(DevelImageVisual::Property::MASKING_TYPE, Property::INTEGER);
167   DALI_TEST_CHECK(value);
168   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
169
170   // Natural size getted as desired size
171   Vector2 naturalSize;
172   animatedImageVisual.GetNaturalSize(naturalSize);
173   DALI_TEST_EQUALS(naturalSize, Vector2(154, 79), TEST_LOCATION);
174
175   // request AnimatedImageVisual with an URL
176   Visual::Base animatedImageVisual2 = factory.CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions());
177   resultMap.Clear();
178   animatedImageVisual2.CreatePropertyMap(resultMap);
179   // check the property values from the returned map from a visual
180   value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
181   DALI_TEST_CHECK(value);
182   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
183
184   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
185   DALI_TEST_CHECK(value);
186   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
187
188   // Natural size getted as image size
189   animatedImageVisual2.GetNaturalSize(naturalSize);
190   DALI_TEST_EQUALS(naturalSize, Vector2(50, 50), TEST_LOCATION);
191
192   END_TEST;
193 }
194
195 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
196 {
197   ToolkitTestApplication application;
198   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap for multi image with fixed cache");
199
200   // request AnimatedImageVisual with a property map
201   VisualFactory   factory = VisualFactory::Get();
202   Property::Array urls;
203   CopyUrlsIntoArray(urls);
204
205   Visual::Base animatedImageVisual = factory.CreateVisual(
206     Property::Map()
207       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
208       .Add("url", urls)
209       .Add("batchSize", 4)
210       .Add("cacheSize", 20)
211       .Add("loopCount", 10)
212       .Add("frameDelay", 200)
213       .Add("pixelArea", Vector4())
214       .Add("wrapModeU", WrapMode::REPEAT)
215       .Add("wrapModeV", WrapMode::DEFAULT)
216       .Add("fittingMode", FittingMode::FIT_WIDTH)
217       .Add("samplingMode", SamplingMode::NEAREST)
218       .Add("desiredWidth", 154)
219       .Add("desiredHeight", 79)
220       .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME)
221       .Add("maskContentScale", 1.6f)
222       .Add("cropToMask", true)
223       .Add(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING)
224       .Add("cornerRadius", Vector4(50.0f, 25.0f, 12.5f, 33.0f))
225       .Add("cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE)
226       .Add("borderlineWidth", 20.0f)
227       .Add("borderlineColor", Vector4())
228       .Add("borderlineOffset", -1.0f));
229
230   Property::Map resultMap;
231   animatedImageVisual.CreatePropertyMap(resultMap);
232   // check the property values from the returned map from a visual
233   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
234   DALI_TEST_CHECK(value);
235   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
236
237   value = resultMap.Find(ImageVisual::Property::URL, "url");
238   DALI_TEST_CHECK(value);
239   Property::Array* resultUrls = value->GetArray();
240   DALI_TEST_CHECK(resultUrls);
241   DALI_TEST_EQUALS(resultUrls->Count(), urls.Count(), TEST_LOCATION);
242
243   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
244   DALI_TEST_CHECK(value);
245   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
246
247   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
248   DALI_TEST_CHECK(value);
249   DALI_TEST_EQUALS(value->Get<int>(), 20, TEST_LOCATION);
250
251   value = resultMap.Find(Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount");
252   DALI_TEST_CHECK(value);
253   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
254
255   value = resultMap.Find(ImageVisual::Property::FRAME_DELAY, "frameDelay");
256   DALI_TEST_CHECK(value);
257   DALI_TEST_EQUALS(value->Get<int>(), 200, TEST_LOCATION);
258
259   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
260   DALI_TEST_CHECK(value);
261   DALI_TEST_EQUALS(value->Get<int>(), 11, TEST_LOCATION);
262
263   value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_U, "wrapModeU");
264   DALI_TEST_CHECK(value);
265   DALI_TEST_CHECK(value->Get<int>() == WrapMode::REPEAT);
266
267   value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_V, "wrapModeV");
268   DALI_TEST_CHECK(value);
269   DALI_TEST_CHECK(value->Get<int>() == WrapMode::DEFAULT);
270
271   value = resultMap.Find(Toolkit::ImageVisual::Property::FITTING_MODE, "fittingMode");
272   DALI_TEST_CHECK(value);
273   DALI_TEST_CHECK(value->Get<int>() == FittingMode::FIT_WIDTH);
274
275   value = resultMap.Find(Toolkit::ImageVisual::Property::SAMPLING_MODE, "samplingMode");
276   DALI_TEST_CHECK(value);
277   DALI_TEST_CHECK(value->Get<int>() == SamplingMode::NEAREST);
278
279   value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_WIDTH, "desiredWidth");
280   DALI_TEST_CHECK(value);
281   DALI_TEST_CHECK(value->Get<int>() == 154);
282
283   value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, "desiredHeight");
284   DALI_TEST_CHECK(value);
285   DALI_TEST_CHECK(value->Get<int>() == 79);
286
287   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius");
288   DALI_TEST_CHECK(value);
289   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(50.0f, 25.0f, 12.5f, 33.0f), TEST_LOCATION);
290
291   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
292   DALI_TEST_CHECK(value);
293   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
294
295   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
296   DALI_TEST_CHECK(value);
297   DALI_TEST_EQUALS(value->Get<float>(), 20.0f, TEST_LOCATION);
298
299   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
300   DALI_TEST_CHECK(value);
301   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4::ZERO, TEST_LOCATION);
302
303   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
304   DALI_TEST_CHECK(value);
305   DALI_TEST_EQUALS(value->Get<float>(), -1.0f, TEST_LOCATION);
306
307   // Check mask properties
308   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, "alphaMaskUrl");
309   DALI_TEST_CHECK(value);
310   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
311
312   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, "maskContentScale");
313   DALI_TEST_CHECK(value);
314   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
315
316   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, "cropToMask");
317   DALI_TEST_CHECK(value);
318   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
319
320   value = resultMap.Find(DevelImageVisual::Property::MASKING_TYPE, Property::INTEGER);
321   DALI_TEST_CHECK(value);
322   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
323
324   END_TEST;
325 }
326
327 int UtcDaliAnimatedImageVisualGetPropertyMap03(void)
328 {
329   ToolkitTestApplication application;
330   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap for multi image rolling cache");
331
332   // request AnimatedImageVisual with a property map
333   VisualFactory   factory = VisualFactory::Get();
334   Property::Array urls;
335   CopyUrlsIntoArray(urls);
336
337   Visual::Base animatedImageVisual = factory.CreateVisual(
338     Property::Map()
339       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
340       .Add("url", urls)
341       .Add("batchSize", 4)
342       .Add("cacheSize", 8)
343       .Add("loopCount", 10)
344       .Add("frameDelay", 200)
345       .Add("pixelArea", Vector4())
346       .Add("wrapModeU", WrapMode::REPEAT)
347       .Add("wrapModeV", WrapMode::DEFAULT)
348       .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME)
349       .Add("maskContentScale", 1.6f)
350       .Add("cropToMask", true)
351       .Add(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING)
352       .Add("cornerRadius", 50.5f));
353
354   Property::Map resultMap;
355   animatedImageVisual.CreatePropertyMap(resultMap);
356   // check the property values from the returned map from a visual
357   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
358   DALI_TEST_CHECK(value);
359   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
360
361   value = resultMap.Find(ImageVisual::Property::URL, "url");
362   DALI_TEST_CHECK(value);
363   Property::Array* resultUrls = value->GetArray();
364   DALI_TEST_CHECK(resultUrls);
365   DALI_TEST_EQUALS(resultUrls->Count(), urls.Count(), TEST_LOCATION);
366
367   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
368   DALI_TEST_CHECK(value);
369   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
370
371   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
372   DALI_TEST_CHECK(value);
373   DALI_TEST_EQUALS(value->Get<int>(), 8, TEST_LOCATION);
374
375   value = resultMap.Find(Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount");
376   DALI_TEST_CHECK(value);
377   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
378
379   value = resultMap.Find(ImageVisual::Property::FRAME_DELAY, "frameDelay");
380   DALI_TEST_CHECK(value);
381   DALI_TEST_EQUALS(value->Get<int>(), 200, TEST_LOCATION);
382
383   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
384   DALI_TEST_CHECK(value);
385   DALI_TEST_EQUALS(value->Get<int>(), 11, TEST_LOCATION);
386
387   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius");
388   DALI_TEST_CHECK(value);
389   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(50.5f, 50.5f, 50.5f, 50.5f), TEST_LOCATION);
390
391   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
392   DALI_TEST_CHECK(value);
393   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
394
395   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
396   DALI_TEST_CHECK(value);
397   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
398
399   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
400   DALI_TEST_CHECK(value);
401   DALI_TEST_EQUALS(value->Get<Vector4>(), Color::BLACK, TEST_LOCATION);
402
403   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
404   DALI_TEST_CHECK(value);
405   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
406
407   // Check mask properties
408   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, "alphaMaskUrl");
409   DALI_TEST_CHECK(value);
410   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
411
412   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, "maskContentScale");
413   DALI_TEST_CHECK(value);
414   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
415
416   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, "cropToMask");
417   DALI_TEST_CHECK(value);
418   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
419
420   value = resultMap.Find(DevelImageVisual::Property::MASKING_TYPE, Property::INTEGER);
421   DALI_TEST_CHECK(value);
422   DALI_TEST_CHECK(value->Get<bool>() == DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
423
424   // Natural size getted as masked image size
425   Vector2 naturalSize;
426   animatedImageVisual.GetNaturalSize(naturalSize);
427   DALI_TEST_EQUALS(naturalSize, Vector2(100, 100), TEST_LOCATION);
428
429   END_TEST;
430 }
431
432 int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
433 {
434   ToolkitTestApplication application;
435   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap");
436
437   // request AnimatedImageVisual with a property map
438   VisualFactory factory             = VisualFactory::Get();
439   Visual::Base  animatedImageVisual = factory.CreateVisual(
440     Property::Map()
441       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
442       .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
443       .Add(ImageVisual::Property::BATCH_SIZE, 1)
444       .Add(ImageVisual::Property::CACHE_SIZE, 1)
445       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true)
446       .Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED)
447       .Add(ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED)
448       .Add(DevelVisual::Property::BORDERLINE_WIDTH, 0.4f));
449
450   Property::Map resultMap;
451   animatedImageVisual.CreatePropertyMap(resultMap);
452
453   // check the property values from the returned map from a visual
454   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
455   DALI_TEST_CHECK(value);
456   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
457
458   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
459   DALI_TEST_CHECK(value);
460   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
461
462   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, Property::INTEGER);
463   DALI_TEST_CHECK(value);
464   DALI_TEST_CHECK(value->Get<int>() == 2);
465
466   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, Property::INTEGER);
467   DALI_TEST_CHECK(value);
468   DALI_TEST_CHECK(value->Get<int>() == 2);
469
470   value = resultMap.Find(ImageVisual::Property::SYNCHRONOUS_LOADING, Property::BOOLEAN);
471   DALI_TEST_CHECK(value);
472   DALI_TEST_CHECK(value->Get<bool>() == true);
473
474   value = resultMap.Find(ImageVisual::Property::RELEASE_POLICY, Property::INTEGER);
475   DALI_TEST_CHECK(value);
476   DALI_TEST_CHECK(value->Get<int>() == ImageVisual::ReleasePolicy::DETACHED);
477
478   value = resultMap.Find(ImageVisual::Property::LOAD_POLICY, Property::INTEGER);
479   DALI_TEST_CHECK(value);
480   DALI_TEST_CHECK(value->Get<int>() == ImageVisual::LoadPolicy::ATTACHED);
481
482   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
483   DALI_TEST_CHECK(value);
484   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
485
486   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
487   DALI_TEST_CHECK(value);
488   DALI_TEST_EQUALS(value->Get<float>(), 0.4f, TEST_LOCATION);
489
490   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
491   DALI_TEST_CHECK(value);
492   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
493
494   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
495   DALI_TEST_CHECK(value);
496   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
497
498   END_TEST;
499 }
500
501 int UtcDaliAnimatedImageVisualImageLoadingFail01(void)
502 {
503   ToolkitTestApplication application;
504   TestGlAbstraction&     gl = application.GetGlAbstraction();
505
506   {
507     Property::Map propertyMap;
508     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
509     propertyMap.Insert(ImageVisual::Property::URL, "dummy.gif");
510     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
511     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
512     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
513     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
514     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
515     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
516
517     VisualFactory factory = VisualFactory::Get();
518     Visual::Base  visual  = factory.CreateVisual(propertyMap);
519
520     DummyControl        dummyControl = DummyControl::New(true);
521     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
522     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
523
524     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
525     application.GetScene().Add(dummyControl);
526
527     TraceCallStack& textureTrace = gl.GetTextureTrace();
528     textureTrace.Enable(true);
529
530     application.SendNotification();
531     application.Render(20);
532
533     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
534
535     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
536
537     application.SendNotification();
538     application.Render(20);
539
540     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
541
542     dummyControl.Unparent();
543   }
544
545   END_TEST;
546 }
547
548 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
549 {
550   ToolkitTestApplication application;
551   TestGlAbstraction&     gl = application.GetGlAbstraction();
552
553   {
554     Property::Map propertyMap;
555     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
556     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
557     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
558     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
559     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
560     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
561     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
562     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
563
564     VisualFactory factory = VisualFactory::Get();
565     Visual::Base  visual  = factory.CreateVisual(propertyMap);
566
567     DummyControl        dummyControl = DummyControl::New(true);
568     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
569     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
570
571     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
572     application.GetScene().Add(dummyControl);
573
574     TraceCallStack& textureTrace = gl.GetTextureTrace();
575     textureTrace.Enable(true);
576
577     application.SendNotification();
578     application.Render(20);
579
580     // The first frame is loaded synchronously and load next batch.
581     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
582
583     application.SendNotification();
584     application.Render();
585
586     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
587     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
588
589     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3);
590
591     application.SendNotification();
592     application.Render(20);
593
594     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
595
596     application.SendNotification();
597     application.Render();
598
599     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
600
601     dummyControl.Unparent();
602   }
603   tet_infoline("Test that removing the visual from stage deletes all textures");
604   application.SendNotification();
605   application.Render(16);
606   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
607
608   END_TEST;
609 }
610
611 int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask01(void)
612 {
613   ToolkitTestApplication application;
614   tet_infoline("UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask01 for CPU Alpha Masking");
615   TestGlAbstraction& gl = application.GetGlAbstraction();
616
617   {
618     Property::Map propertyMap;
619     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
620     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
621     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
622     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
623     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
624     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
625     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
626     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
627     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
628
629     VisualFactory factory = VisualFactory::Get();
630     Visual::Base  visual  = factory.CreateVisual(propertyMap);
631
632     Property::Map testMap;
633     visual.CreatePropertyMap(testMap);
634     DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
635
636     DummyControl        dummyControl = DummyControl::New(true);
637     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
638     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
639
640     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
641     application.GetScene().Add(dummyControl);
642
643     TraceCallStack& textureTrace = gl.GetTextureTrace();
644     textureTrace.Enable(true);
645
646     application.SendNotification();
647     application.Render(20);
648
649     // The first frame is loaded synchronously and load next batch with masking
650     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
651
652     application.SendNotification();
653     application.Render();
654
655     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
656     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
657
658     dummyControl.Unparent();
659   }
660   tet_infoline("Test that removing the visual from stage deletes all textures");
661   application.SendNotification();
662   application.Render(16);
663   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
664
665   END_TEST;
666 }
667
668 int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask02(void)
669 {
670   ToolkitTestApplication application;
671   tet_infoline("UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask02 for GPU Alpha Masking");
672   TestGlAbstraction& gl = application.GetGlAbstraction();
673
674   {
675     Property::Map propertyMap;
676     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
677     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
678     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
679     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
680     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
681     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
682     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
683     propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
684     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
685     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
686
687     VisualFactory factory = VisualFactory::Get();
688     Visual::Base  visual  = factory.CreateVisual(propertyMap);
689
690     Property::Map testMap;
691     visual.CreatePropertyMap(testMap);
692     DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
693
694     DummyControl        dummyControl = DummyControl::New(true);
695     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
696     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
697
698     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
699     application.GetScene().Add(dummyControl);
700
701     TraceCallStack& textureTrace = gl.GetTextureTrace();
702     textureTrace.Enable(true);
703
704     application.SendNotification();
705     application.Render(20);
706
707     // The first frame is loaded synchronously and load next batch with masking
708     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
709
710     application.SendNotification();
711     application.Render();
712
713     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
714     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
715
716     dummyControl.Unparent();
717   }
718   tet_infoline("Test that removing the visual from stage deletes all textures");
719   application.SendNotification();
720   application.Render(16);
721   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
722
723   END_TEST;
724 }
725
726 int UtcDaliAnimatedImageVisualJumpToAction(void)
727 {
728   ToolkitTestApplication application;
729   TestGlAbstraction&     gl = application.GetGlAbstraction();
730
731   Property::Array urls;
732   CopyUrlsIntoArray(urls);
733
734   {
735     Property::Map propertyMap;
736     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
737     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
738     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
739     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 12);
740     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
741
742     VisualFactory factory = VisualFactory::Get();
743     Visual::Base  visual  = factory.CreateVisual(propertyMap);
744
745     DummyControl        dummyControl = DummyControl::New(true);
746     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
747     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
748
749     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
750     application.GetScene().Add(dummyControl);
751     application.SendNotification();
752     application.Render(20);
753
754     tet_infoline("Ready the visual after the visual is on stage");
755     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
756
757     tet_infoline("Test that a timer has been started");
758     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
759
760     TraceCallStack& textureTrace = gl.GetTextureTrace();
761     textureTrace.Enable(true);
762
763     application.SendNotification();
764     application.Render(20);
765
766     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
767
768     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
769
770     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
771
772     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20);
773
774     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
775
776     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
777
778     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
779     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
780
781     dummyControl.Unparent();
782   }
783   tet_infoline("Test that removing the visual from stage deletes all textures");
784   application.SendNotification();
785   application.Render(16);
786   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
787
788   END_TEST;
789 }
790
791 int UtcDaliAnimatedImageVisualStopBehavior(void)
792 {
793   ToolkitTestApplication application;
794   TestGlAbstraction&     gl = application.GetGlAbstraction();
795
796   Property::Array urls;
797   CopyUrlsIntoArray(urls);
798
799   {
800     Property::Map propertyMap;
801     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
802     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
803     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
804     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
805     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
806     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
807
808     VisualFactory factory = VisualFactory::Get();
809     Visual::Base  visual  = factory.CreateVisual(propertyMap);
810
811     // Expect that a batch of 4 textures has been requested. These will be serially loaded
812     // below.
813
814     DummyControl        dummyControl = DummyControl::New(true);
815     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
816     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
817
818     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
819     application.GetScene().Add(dummyControl);
820     application.SendNotification();
821     application.Render(20);
822
823     tet_infoline("Ready the visual after the visual is on stage");
824     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
825
826     tet_infoline("Test that a timer has been started");
827     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
828
829     TraceCallStack& textureTrace = gl.GetTextureTrace();
830     textureTrace.Enable(true);
831
832     application.SendNotification();
833     application.Render(20);
834
835     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
836
837     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
838
839     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
840
841     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1);
842
843     // Expect the second batch has been requested
844     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
845
846     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
847
848     dummyControl.Unparent();
849   }
850   tet_infoline("Test that removing the visual from stage deletes all textures");
851   application.SendNotification();
852   application.Render(16);
853   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
854
855   END_TEST;
856 }
857
858 int UtcDaliAnimatedImageVisualStopBehavior02(void)
859 {
860   ToolkitTestApplication application;
861   TestGlAbstraction&     gl = application.GetGlAbstraction();
862
863   Property::Array urls;
864   CopyUrlsIntoArray(urls);
865
866   {
867     Property::Map propertyMap;
868     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
869     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
870     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
871     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
872     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
873     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
874
875     VisualFactory factory = VisualFactory::Get();
876     Visual::Base  visual  = factory.CreateVisual(propertyMap);
877
878     // Expect that a batch of 4 textures has been requested. These will be serially loaded
879     // below.
880
881     DummyControl        dummyControl = DummyControl::New(true);
882     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
883     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
884
885     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
886     application.GetScene().Add(dummyControl);
887
888     tet_infoline("Ready the visual after the visual is on stage");
889     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
890
891     TraceCallStack& textureTrace = gl.GetTextureTrace();
892     textureTrace.Enable(true);
893
894     application.SendNotification();
895     application.Render(20);
896
897     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
898
899     Test::EmitGlobalTimerSignal();
900
901     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
902
903     application.SendNotification();
904     application.Render(20);
905
906     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
907
908     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
909
910     tet_infoline("Ready the visual after the visual is on stage");
911     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
912
913     application.SendNotification();
914     application.Render(20);
915
916     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
917
918     dummyControl.Unparent();
919   }
920   tet_infoline("Test that removing the visual from stage deletes all textures");
921   application.SendNotification();
922   application.Render(16);
923   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
924
925   END_TEST;
926 }
927
928 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
929 {
930   ToolkitTestApplication application;
931   TestGlAbstraction&     gl = application.GetGlAbstraction();
932
933   tet_infoline("Set cache size same as GIF frame, and try to load same image at another ImageView");
934   {
935     Property::Map propertyMap;
936     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
937     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
938     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
939     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
940     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
941
942     VisualFactory factory = VisualFactory::Get();
943     Visual::Base  visual  = factory.CreateVisual(propertyMap);
944
945     // Expect that a batch of 4 textures has been requested. These will be serially loaded
946     // below.
947
948     DummyControl        dummyControl = DummyControl::New(true);
949     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
950     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
951
952     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
953     application.GetScene().Add(dummyControl);
954
955     application.SendNotification();
956     application.Render();
957
958     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
959
960     // Batch 2 frames. Now frame 0, 1 cached.
961     application.SendNotification();
962     application.Render(20);
963
964     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
965
966     tet_infoline("Test that a timer has been started");
967
968     TraceCallStack& textureTrace = gl.GetTextureTrace();
969     textureTrace.Enable(true);
970
971     Test::EmitGlobalTimerSignal();
972
973     application.SendNotification();
974     application.Render();
975
976     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
977
978     // 0 frame removed. and after, batch 2 frames. Now frame 1, 2, 3 cached.
979     application.SendNotification();
980     application.Render(20);
981
982     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
983
984     Visual::Base        visual2       = factory.CreateVisual(propertyMap);
985     DummyControl        dummyControl2 = DummyControl::New(true);
986     Impl::DummyControl& dummyImpl2    = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
987     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
988     application.GetScene().Add(dummyControl2);
989
990     tet_infoline("Add new view with same url");
991
992     application.SendNotification();
993     application.Render();
994
995     // Note that we only re-load 0 frame.
996     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
997
998     tet_infoline("Test that we don't try to re-load new image cause it cached");
999     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
1000
1001     // Batch 2 frames. Now visual frame 1, 2, 3 cached and visual2 frame 0, 1 cached.
1002     application.SendNotification();
1003     application.Render(20);
1004
1005     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION);
1006
1007     textureTrace.Reset();
1008
1009     tet_infoline("Load some many frames");
1010
1011     const int repeatCount = 10;
1012     for(int repeat = 0; repeat < repeatCount; ++repeat)
1013     {
1014       Test::EmitGlobalTimerSignal();
1015       application.SendNotification();
1016       application.Render(2000);
1017     }
1018
1019     DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // A new texture should NOT be generated.
1020     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION);
1021
1022     textureTrace.Reset();
1023
1024     dummyControl.Unparent();
1025     dummyControl2.Unparent();
1026   }
1027   tet_infoline("Test that removing the visual from stage deletes all textures");
1028   application.SendNotification();
1029   application.Render(20);
1030   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1031
1032   END_TEST;
1033 }
1034
1035 int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01(void)
1036 {
1037   ToolkitTestApplication application;
1038   tet_infoline("UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01 for CPU Alpha Masking");
1039   TestGlAbstraction& gl = application.GetGlAbstraction();
1040
1041   {
1042     Property::Map propertyMap;
1043     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
1044     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
1045     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1046     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
1047     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
1048     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1049
1050     VisualFactory factory = VisualFactory::Get();
1051     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1052
1053     DummyControl        dummyControl = DummyControl::New(true);
1054     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1055     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1056
1057     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1058     application.GetScene().Add(dummyControl);
1059
1060     application.SendNotification();
1061     application.Render();
1062
1063     // load two frame(batch size), load mask image, and request two masking
1064     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
1065
1066     application.SendNotification();
1067     application.Render(20);
1068
1069     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
1070
1071     dummyControl.Unparent();
1072   }
1073   tet_infoline("Test that removing the visual from stage deletes all textures");
1074   application.SendNotification();
1075   application.Render(20);
1076   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1077
1078   END_TEST;
1079 }
1080
1081 int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask02(void)
1082 {
1083   ToolkitTestApplication application;
1084   tet_infoline("UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask02 for GPU Alpha Masking");
1085   TestGlAbstraction& gl = application.GetGlAbstraction();
1086
1087   {
1088     Property::Map propertyMap;
1089     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
1090     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
1091     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1092     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
1093     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
1094     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1095     propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1096
1097     VisualFactory factory = VisualFactory::Get();
1098     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1099
1100     DummyControl        dummyControl = DummyControl::New(true);
1101     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1102     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1103
1104     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1105     application.GetScene().Add(dummyControl);
1106
1107     Property::Map attributes;
1108     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes);
1109
1110     application.SendNotification();
1111     application.Render();
1112
1113     // load two frame(batch size), load mask image, and request two masking
1114     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1115
1116     application.SendNotification();
1117     application.Render(20);
1118
1119     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1120
1121     dummyControl.Unparent();
1122   }
1123   tet_infoline("Test that removing the visual from stage deletes all textures");
1124   application.SendNotification();
1125   application.Render(20);
1126   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1127
1128   END_TEST;
1129 }
1130
1131 int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask03(void)
1132 {
1133   ToolkitTestApplication application;
1134   tet_infoline("UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask03 for GPU Alpha Masking with broken mask texture");
1135   TestGlAbstraction& gl = application.GetGlAbstraction();
1136
1137   {
1138     Property::Map propertyMap;
1139     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
1140     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
1141     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1142     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
1143     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
1144     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "");
1145     propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1146
1147     VisualFactory factory = VisualFactory::Get();
1148     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1149
1150     DummyControl        dummyControl = DummyControl::New(true);
1151     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1152     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1153
1154     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1155     application.GetScene().Add(dummyControl);
1156
1157     application.SendNotification();
1158     application.Render();
1159
1160     // load two frame(batch size), load mask image, and request two masking
1161     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1162
1163     application.SendNotification();
1164     application.Render(20);
1165
1166     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 3, TEST_LOCATION);
1167
1168     dummyControl.Unparent();
1169   }
1170   tet_infoline("Test that removing the visual from stage deletes all textures");
1171   application.SendNotification();
1172   application.Render(20);
1173   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1174
1175   END_TEST;
1176 }
1177
1178 int UtcDaliAnimatedImageVisualMultiImage01(void)
1179 {
1180   ToolkitTestApplication application;
1181   TestGlAbstraction&     gl = application.GetGlAbstraction();
1182
1183   Property::Array urls;
1184   CopyUrlsIntoArray(urls);
1185
1186   {
1187     Property::Map propertyMap;
1188     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1189     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1190     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
1191     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
1192     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1193
1194     VisualFactory factory = VisualFactory::Get();
1195     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1196
1197     // Expect that a batch of 4 textures has been requested. These will be serially loaded
1198     // below.
1199
1200     DummyControl        dummyControl = DummyControl::New(true);
1201     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1202     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1203
1204     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1205     application.GetScene().Add(dummyControl);
1206     application.SendNotification();
1207     application.Render(16);
1208
1209     tet_infoline("Ready the visual after the visual is on stage");
1210     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1211
1212     tet_infoline("Test that a timer has been started");
1213     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1214
1215     TraceCallStack& textureTrace = gl.GetTextureTrace();
1216     textureTrace.Enable(true);
1217
1218     application.SendNotification();
1219     application.Render(16);
1220
1221     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
1222     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1223
1224     tet_infoline("Test that after 1 tick, and file loads completed, that we have 7 textures");
1225     Test::EmitGlobalTimerSignal();
1226
1227     // Expect the second batch has been requested
1228     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1229
1230     application.SendNotification();
1231     application.Render(16);
1232     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1233
1234     tet_infoline("Test that after 2 ticks that we have 6 textures");
1235
1236     Test::EmitGlobalTimerSignal();
1237     application.SendNotification();
1238     application.Render(16);
1239     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 6, TEST_LOCATION);
1240
1241     tet_infoline("And that at least 2 textures were requested");
1242     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1243     application.SendNotification();
1244     application.Render(16);
1245     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
1246
1247     tet_infoline("Test that after 3rd tick that we have 7 textures and 1 request");
1248     Test::EmitGlobalTimerSignal();
1249     application.SendNotification();
1250     application.Render(16);
1251     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1252
1253     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1254     application.SendNotification();
1255     application.Render(16);
1256     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
1257
1258     dummyControl.Unparent();
1259   }
1260   tet_infoline("Test that removing the visual from stage deletes all textures");
1261   application.SendNotification();
1262   application.Render(16);
1263   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1264
1265   END_TEST;
1266 }
1267
1268 int UtcDaliAnimatedImageVisualMultiImage02(void)
1269 {
1270   ToolkitTestApplication application;
1271   TestGlAbstraction&     gl = application.GetGlAbstraction();
1272
1273   tet_infoline("Test that the animated visual has different batch and cache size.");
1274
1275   {
1276     Property::Array urls;
1277     CopyUrlsIntoArray(urls);
1278
1279     Property::Map propertyMap;
1280     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1281     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1282     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 0);
1283     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 0);
1284     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1285
1286     VisualFactory factory = VisualFactory::Get();
1287     Visual::Base  visual  = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1288
1289     // Check the batch size and cache size need to have minimum 2.
1290     Property::Map resultMap;
1291     visual.CreatePropertyMap(resultMap);
1292     Property::Value* value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
1293     DALI_TEST_CHECK(value);
1294     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1295     value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
1296     DALI_TEST_CHECK(value);
1297     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1298     visual.Reset();
1299
1300     // Batch size is 2 and cache size is 3
1301     propertyMap.Clear();
1302     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1303     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1304     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1305     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1306     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1307
1308     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1309
1310     // Expect that each image is loaded each tick
1311     DummyControl        dummyControl = DummyControl::New(true);
1312     Impl::DummyControl& dummyImpl1   = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1313     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1314     visual.Reset();
1315
1316     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1317     application.GetScene().Add(dummyControl);
1318     application.SendNotification();
1319     application.Render(16);
1320
1321     tet_infoline("Ready the visual after the visual is on window");
1322     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1323     application.SendNotification();
1324     application.Render(16); //glGenTextures 1 and 2
1325     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
1326
1327     tet_infoline("Test that each tick, a new image is requested");
1328     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1329     application.SendNotification();
1330     application.Render(16);
1331     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1332     application.SendNotification();
1333     application.Render(16); //glGenTextures 3
1334     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1335
1336     tet_infoline("Test that each tick, a new image is requested");
1337     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1338     application.SendNotification();
1339     application.Render(16);
1340     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1341     application.SendNotification();
1342     application.Render(16); //glGenTextures 4
1343     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1344
1345     dummyImpl1.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1346     dummyControl.Unparent();
1347
1348     // Ensure to remove cached texture. (Since we support lazy cache removal)
1349     application.SendNotification();
1350     application.Render(16);
1351     application.SendNotification();
1352     application.Render(16);
1353
1354     // Batch size is 9 and cache size is 4
1355     propertyMap.Clear();
1356     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1357     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1358     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1359     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 7);
1360     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1361
1362     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1363
1364     // Expect that each image is loaded each tick
1365     dummyControl                   = DummyControl::New(true);
1366     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1367     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1368     visual.Reset();
1369
1370     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1371     application.GetScene().Add(dummyControl);
1372     application.SendNotification();
1373     application.Render(16);
1374
1375     tet_infoline("Ready the visual after the visual is on window");
1376     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1377     application.SendNotification();
1378     application.Render(16); //glGenTextures 1, 2, and 3
1379     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1380
1381     tet_infoline("Test that each tick, a new image is requested");
1382     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1383     application.SendNotification();
1384     application.Render(16);
1385     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1386     application.SendNotification();
1387     application.Render(16); //glGenTextures 4, 5, and 6
1388     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 5, TEST_LOCATION);
1389
1390     tet_infoline("Test that each tick, a new image is requested");
1391     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1392     application.SendNotification();
1393     application.Render(16);
1394     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1395     application.SendNotification();
1396     application.Render(16); //glGenTextures 7, 1, and 2
1397     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1398
1399     tet_infoline("Test that each tick, a new image is requested");
1400     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
1401     application.SendNotification();
1402     application.Render(16);
1403     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1404     application.SendNotification();
1405     application.Render(16); //glGenTextures 3
1406     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1407
1408     dummyControl.Unparent();
1409   }
1410   tet_infoline("Test that removing the visual from window deletes all textures");
1411   application.SendNotification();
1412   application.Render(16);
1413   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1414
1415   END_TEST;
1416 }
1417
1418 int UtcDaliAnimatedImageVisualMultiImage03(void)
1419 {
1420   ToolkitTestApplication application;
1421   TestGlAbstraction&     gl = application.GetGlAbstraction();
1422
1423   {
1424     Property::Array urls1, urls2;
1425     CopyUrlsIntoArray(urls1);
1426     CopyUrlsIntoArray(urls2);
1427
1428     Property::Map animatedImageMap1;
1429     animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE);
1430     animatedImageMap1.Insert(ImageVisual::Property::URL, Property::Value(urls1));
1431     animatedImageMap1.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1432     animatedImageMap1.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1433     animatedImageMap1.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1434
1435     Property::Map animatedImageMap2;
1436     animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE);
1437     animatedImageMap2.Insert(ImageVisual::Property::URL, Property::Value(urls2));
1438     animatedImageMap2.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1439     animatedImageMap2.Insert(ImageVisual::Property::CACHE_SIZE, 2);
1440     animatedImageMap2.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1441
1442     VisualFactory factory              = VisualFactory::Get();
1443     Visual::Base  animatedImageVisual1 = factory.CreateVisual(animatedImageMap1);
1444
1445     tet_infoline("Create two image views with the same URLs, offset by 1 frame.");
1446
1447     DummyControl        dummyControl1 = DummyControl::New(true);
1448     Impl::DummyControl& dummyImpl1    = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
1449     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual1);
1450     dummyControl1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1451     application.GetScene().Add(dummyControl1);
1452
1453     application.SendNotification();
1454     application.Render(16);
1455
1456     tet_infoline("Ready the requested image after the first visual is on stage");
1457     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1458     application.SendNotification();
1459     application.Render(16);
1460     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1461
1462     Visual::Base        animatedImageVisual2 = factory.CreateVisual(animatedImageMap2);
1463     DummyControl        dummyControl2        = DummyControl::New(true);
1464     Impl::DummyControl& dummyImpl2           = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
1465     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual2);
1466     dummyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1467     application.GetScene().Add(dummyControl2);
1468     application.SendNotification();
1469     application.Render(16);
1470
1471     tet_infoline("The texture cache should be holding the requested images; check that the renderer has a texture");
1472     TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
1473     Texture    t1 = ts.GetTexture(0);
1474     DALI_TEST_EQUALS(ts.GetTextureCount(), 1, TEST_LOCATION);
1475
1476     tet_infoline("Test that on the first tick, 1 new image is requested");
1477     Test::EmitGlobalTimerSignal(); // Both visuals should tick
1478
1479     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1480     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1481
1482     ts         = dummyControl2.GetRendererAt(0).GetTextures();
1483     Texture t2 = ts.GetTexture(0);
1484     DALI_TEST_CHECK(t1 != t2);
1485
1486     dummyControl1.Unparent();
1487     dummyControl2.Unparent();
1488   }
1489   tet_infoline("Test that removing the visual from stage deletes all textures");
1490   application.SendNotification();
1491   application.Render(16);
1492   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1493
1494   END_TEST;
1495 }
1496
1497 int UtcDaliAnimatedImageVisualMultiImage04(void)
1498 {
1499   ToolkitTestApplication application;
1500   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1501   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1502   textureTrace.Enable(true);
1503
1504   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");
1505
1506   Property::Array urls;
1507   CopyUrlsIntoArray(urls);
1508
1509   {
1510     Property::Map propertyMap;
1511     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1512     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1513     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 6);
1514     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1515     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1516
1517     VisualFactory factory = VisualFactory::Get();
1518     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1519
1520     tet_infoline("Expect that a batch of 7 textures has been requested.");
1521
1522     DummyControl        dummyControl = DummyControl::New(true);
1523     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1524     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1525
1526     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1527     application.GetScene().Add(dummyControl);
1528     application.SendNotification();
1529     application.Render(16);
1530
1531     tet_infoline("Wait for the first batch to complete");
1532     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
1533
1534     tet_infoline("Test that a timer has been started");
1535     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1536
1537     application.SendNotification();
1538     application.Render(16);
1539
1540     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 6, TEST_LOCATION);
1541     tet_infoline("Test that after 1 tick, and 5 file loads completed, that we have 11 textures");
1542     Test::EmitGlobalTimerSignal();
1543     application.SendNotification();
1544     application.Render(16);
1545
1546     // Expect the second batch has been requested
1547     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
1548
1549     application.SendNotification();
1550     application.Render(16);
1551     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1552
1553     tet_infoline("Test that after 2 ticks that we have 11 textures and no requests");
1554
1555     Test::EmitGlobalTimerSignal();
1556     application.SendNotification();
1557     application.Render(16);
1558     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1559     application.SendNotification();
1560     application.Render(16);
1561     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1562
1563     tet_infoline("Test that after 3rd tick that we have 11 textures and no requests");
1564     Test::EmitGlobalTimerSignal();
1565     application.SendNotification();
1566     application.Render(16);
1567
1568     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1569     application.SendNotification();
1570     application.Render(16);
1571     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1572
1573     dummyControl.Unparent();
1574   }
1575
1576   tet_infoline("Test that removing the visual from stage deletes all textures");
1577   application.SendNotification();
1578   application.Render(16);
1579   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1580
1581   END_TEST;
1582 }
1583
1584 int UtcDaliAnimatedImageVisualMultiImage05(void)
1585 {
1586   ToolkitTestApplication application;
1587   TestGlAbstraction&     gl = application.GetGlAbstraction();
1588
1589   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");
1590
1591   Property::Array urls;
1592   CopyUrlsIntoArray(urls);
1593
1594   {
1595     Property::Map propertyMap;
1596     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1597     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1598     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
1599     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1600     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1601
1602     VisualFactory factory = VisualFactory::Get();
1603     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1604
1605     tet_infoline("Expect that a batch of 4 textures has been requested.");
1606
1607     DummyControl        dummyControl = DummyControl::New(true);
1608     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1609     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1610
1611     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1612     application.GetScene().Add(dummyControl);
1613     application.SendNotification();
1614     application.Render(16);
1615
1616     tet_infoline("Wait for the first batch to complete");
1617     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1618
1619     tet_infoline("Test that a timer has been started");
1620     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1621
1622     application.SendNotification();
1623     application.Render(16);
1624
1625     tet_infoline("Test that a timer has been started");
1626     Test::EmitGlobalTimerSignal();
1627     application.SendNotification();
1628     application.Render(16);
1629
1630     dummyControl.Unparent();
1631   }
1632
1633   application.SendNotification();
1634   application.Render(16);
1635   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1636
1637   tet_infoline("Test that pending batch of image loads are cancelled instead of uploaded");
1638   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1639   application.SendNotification();
1640   application.Render(16);
1641   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1642
1643   END_TEST;
1644 }
1645
1646 void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyControl, uint16_t frameCount, uint16_t loopCount, const char* location)
1647 {
1648   TestGlAbstraction& gl           = application.GetGlAbstraction();
1649   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1650
1651   textureTrace.Enable(true);
1652   application.GetScene().Add(dummyControl);
1653
1654   application.SendNotification();
1655   application.Render(16);
1656
1657   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_INNER_LOCATION(location));
1658
1659   application.SendNotification();
1660   application.Render();
1661
1662   tet_infoline("Test that a timer has been created");
1663   DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_INNER_LOCATION(location));
1664
1665   for(uint16_t i = 0; i < loopCount; i++)
1666   {
1667     for(uint16_t j = 0; j < frameCount; j++)
1668     {
1669       if(i == 0 && j == 0)
1670       {
1671         continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1672       }
1673       tet_printf("Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u);
1674       Test::EmitGlobalTimerSignal();
1675       application.SendNotification();
1676       application.Render(16);
1677
1678       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_INNER_LOCATION(location));
1679
1680       application.SendNotification();
1681       application.Render();
1682       DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION(location));
1683       DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_INNER_LOCATION(location));
1684     }
1685     tet_printf("Test Loop %u \n\n", i + 1u);
1686   }
1687
1688   tet_printf("Test that after %u loops, and we have no frame. Timer should stop \n", loopCount);
1689   Test::EmitGlobalTimerSignal();
1690   application.SendNotification();
1691   application.Render(16);
1692   DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_INNER_LOCATION(location));
1693
1694   dummyControl.Unparent();
1695 }
1696
1697 int UtcDaliAnimatedImageVisualLoopCount(void)
1698 {
1699   ToolkitTestApplication application;
1700
1701   tet_infoline("UtcDaliAnimatedImageVisualLoopCount");
1702
1703   {
1704     // request AnimatedImageVisual with a property map
1705     // Test with no (0) loop count
1706     VisualFactory factory             = VisualFactory::Get();
1707     Visual::Base  animatedImageVisual = factory.CreateVisual(
1708       Property::Map()
1709         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1710         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1711         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1712         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1713         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1714         .Add(DevelImageVisual::Property::LOOP_COUNT, 0));
1715
1716     DummyControl        dummyControl = DummyControl::New(true);
1717     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1718     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1719     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1720
1721     TestLoopCount(application, dummyControl, 4, 0, TEST_LOCATION);
1722
1723     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1724     animatedImageVisual.Reset();
1725
1726     application.SendNotification();
1727     application.Render(16);
1728
1729     // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1730     animatedImageVisual = factory.CreateVisual(
1731       Property::Map()
1732         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1733         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1734         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1735         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1736         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1737         .Add(DevelImageVisual::Property::LOOP_COUNT, 1));
1738
1739     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1740
1741     TestLoopCount(application, dummyControl, 4, 1, TEST_LOCATION);
1742
1743     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1744     animatedImageVisual.Reset();
1745
1746     application.SendNotification();
1747     application.Render(16);
1748
1749     // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1750     animatedImageVisual = factory.CreateVisual(
1751       Property::Map()
1752         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1753         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1754         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1755         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1756         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1757         .Add(DevelImageVisual::Property::LOOP_COUNT, 100));
1758
1759     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1760
1761     TestLoopCount(application, dummyControl, 4, 100, TEST_LOCATION);
1762   }
1763   END_TEST;
1764 }
1765
1766 int UtcDaliAnimatedImageVisualPlayback(void)
1767 {
1768   ToolkitTestApplication application;
1769   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1770   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1771
1772   tet_infoline("UtcDaliAnimatedImageVisualPlayback");
1773
1774   {
1775     // request AnimatedImageVisual with a property map
1776     // Test with forever (-1) loop count
1777     VisualFactory factory             = VisualFactory::Get();
1778     Visual::Base  animatedImageVisual = factory.CreateVisual(
1779       Property::Map()
1780         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1781         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1782         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1783         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1784         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1785         .Add(DevelImageVisual::Property::LOOP_COUNT, -1));
1786
1787     DummyControl        dummyControl = DummyControl::New(true);
1788     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1789     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1790     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1791
1792     textureTrace.Enable(true);
1793     application.GetScene().Add(dummyControl);
1794     application.SendNotification();
1795     application.Render(16);
1796
1797     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1798
1799     application.SendNotification();
1800     application.Render();
1801
1802     tet_infoline("Test that a timer has been created");
1803     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1804
1805     Test::EmitGlobalTimerSignal();
1806     application.SendNotification();
1807     application.Render(16);
1808
1809     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1810
1811     application.SendNotification();
1812     application.Render();
1813     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1814
1815     Property::Map attributes;
1816     tet_infoline("Test Pause action. Timer should stop after Pause action");
1817     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes);
1818     Test::EmitGlobalTimerSignal();
1819     application.SendNotification();
1820     application.Render(16);
1821     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1822
1823     tet_infoline("Test Play action. Timer should Restart after Play action");
1824     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1825     Test::EmitGlobalTimerSignal();
1826     application.SendNotification();
1827     application.Render(16);
1828
1829     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1830
1831     application.SendNotification();
1832     application.Render();
1833     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1834
1835     tet_infoline("Test Stop action. Timer should stop after Stop action");
1836     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes);
1837     Test::EmitGlobalTimerSignal();
1838     application.SendNotification();
1839     application.Render(16);
1840     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1841
1842     tet_infoline("Test Play action. Timer should Restart after Play action");
1843     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1844     Test::EmitGlobalTimerSignal();
1845     application.SendNotification();
1846     application.Render(16);
1847
1848     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1849
1850     application.SendNotification();
1851     application.Render();
1852     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1853
1854     dummyControl.Unparent();
1855   }
1856
1857   END_TEST;
1858 }
1859
1860 int UtcDaliAnimatedImageVisualWrapMode(void)
1861 {
1862   ToolkitTestApplication application;
1863   tet_infoline("UtcDaliAnimatedImageVisualWrapMode");
1864
1865   VisualFactory factory = VisualFactory::Get();
1866   DALI_TEST_CHECK(factory);
1867
1868   // Test wrap mode in animated image visual.
1869   const int     width  = 950;
1870   const int     height = 1080;
1871   const Vector4 pixelArea(0.0f, 0.0f, 950 / 40, 1.0f);
1872
1873   Property::Map propertyMap;
1874   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1875   propertyMap.Insert(ImageVisual::Property::URL, TEST_WEBP_FILE_NAME);
1876   propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1877   propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT);
1878
1879   Visual::Base visual = factory.CreateVisual(propertyMap);
1880   DALI_TEST_CHECK(visual);
1881
1882   TestGlAbstraction& gl           = application.GetGlAbstraction();
1883   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1884   textureTrace.Enable(true);
1885   textureTrace.EnableLogging(true);
1886   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1887   texParameterTrace.Enable(true);
1888   texParameterTrace.EnableLogging(true);
1889
1890   DummyControl      actor     = DummyControl::New();
1891   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1892   dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1893   actor.SetProperty(Actor::Property::SIZE, Vector2(width, height));
1894   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1895
1896   DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1897   application.GetScene().Add(actor);
1898   application.SendNotification();
1899   application.Render();
1900
1901   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1902
1903   application.SendNotification();
1904   application.Render();
1905
1906   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1907
1908   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1909
1910   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1911   std::stringstream out;
1912   out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_REPEAT;
1913   DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1914
1915   // test the uniforms which used to handle the wrap mode
1916   Renderer renderer = actor.GetRendererAt(0u);
1917   DALI_TEST_CHECK(renderer);
1918
1919   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1920   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1921
1922   actor.Unparent();
1923   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1924
1925   END_TEST;
1926 }
1927
1928 int UtcDaliAnimatedImageVisualDesiredSize(void)
1929 {
1930   ToolkitTestApplication application;
1931   tet_infoline("UtcDaliAnimatedImageVisualDesiredSize");
1932
1933   TestGlAbstraction& gl           = application.GetGlAbstraction();
1934   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1935
1936   // Set desiredWidth < 37 and desiredHeight < 50, which is smaller than original image's size.
1937   int desiredWidth  = 15;
1938   int desiredHeight = 20;
1939
1940   Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
1941   DALI_TEST_CHECK(visual);
1942
1943   DummyControl      actor     = DummyControl::New(true);
1944   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1945   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1946
1947   application.GetScene().Add(actor);
1948
1949   application.SendNotification();
1950   application.Render();
1951
1952   // Trigger count is 2 - first frame and second frame.
1953   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1954
1955   textureTrace.Enable(true);
1956   textureTrace.EnableLogging(true);
1957
1958   application.SendNotification();
1959   application.Render();
1960
1961   {
1962     std::stringstream out;
1963     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
1964     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1965   }
1966
1967   // Unparent to make next trigger
1968   actor.Unparent();
1969
1970   application.SendNotification();
1971   application.Render();
1972
1973   // Set visual size
1974   actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
1975   application.GetScene().Add(actor);
1976
1977   application.SendNotification();
1978   application.Render();
1979
1980   // Trigger count is 2 - first frame and second frame.
1981   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1982
1983   textureTrace.Reset();
1984
1985   application.SendNotification();
1986   application.Render();
1987
1988   {
1989     std::stringstream out;
1990     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
1991     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed
1992   }
1993
1994   END_TEST;
1995 }
1996
1997
1998 int UtcDaliAnimatedImageVisualControlVisibilityChanged(void)
1999 {
2000   ToolkitTestApplication application;
2001   tet_infoline("UtcDaliAnimatedImageVisualControlVisibilityChanged");
2002
2003   Property::Map propertyMap;
2004   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE)
2005     .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
2006     .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME)
2007     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2008
2009   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2010   DALI_TEST_CHECK(visual);
2011
2012   DummyControl      actor     = DummyControl::New(true);
2013   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2014   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2015
2016   Vector2 controlSize(20.f, 30.f);
2017   actor.SetProperty(Actor::Property::SIZE, controlSize);
2018
2019   application.GetScene().Add(actor);
2020
2021   application.SendNotification();
2022   application.Render();
2023
2024   // Trigger count is 2 - load & render a frame
2025   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2026
2027   Property::Map attributes;
2028   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
2029
2030   application.SendNotification();
2031   application.Render();
2032
2033   // Check frame number
2034   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2035   Renderer renderer = actor.GetRendererAt(0u);
2036   DALI_TEST_CHECK(renderer);
2037
2038   Test::EmitGlobalTimerSignal();
2039   application.SendNotification();
2040   application.Render(16);
2041
2042   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2043
2044   application.SendNotification();
2045   application.Render();
2046
2047   Property::Map resultMap;
2048   visual.CreatePropertyMap(resultMap);
2049
2050   // check the property values from the returned map from a visual
2051   Property::Value* value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
2052   DALI_TEST_CHECK(value);
2053   DALI_TEST_NOT_EQUALS(value->Get<int>(), 0, Math::MACHINE_EPSILON_100, TEST_LOCATION);
2054
2055   actor.SetProperty(Actor::Property::VISIBLE, false);
2056
2057   Test::EmitGlobalTimerSignal();
2058   application.SendNotification();
2059   application.Render(16);
2060
2061   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2062
2063   application.SendNotification();
2064   application.Render();
2065
2066   visual.CreatePropertyMap(resultMap);
2067
2068   // check the property values from the returned map from a visual
2069   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
2070   DALI_TEST_CHECK(value);
2071   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION);
2072
2073   END_TEST;
2074 }
2075
2076 int UtcDaliAnimatedImageVisualWindowVisibilityChanged(void)
2077 {
2078   ToolkitTestApplication application;
2079   tet_infoline("UtcDaliAnimatedImageVisualWindowVisibilityChanged");
2080
2081   Property::Map propertyMap;
2082   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE)
2083     .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
2084     .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME)
2085     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2086
2087   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2088   DALI_TEST_CHECK(visual);
2089
2090   DummyControl      actor     = DummyControl::New(true);
2091   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2092   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2093
2094   Vector2 controlSize(20.f, 30.f);
2095   actor.SetProperty(Actor::Property::SIZE, controlSize);
2096
2097   application.GetScene().Add(actor);
2098
2099   application.SendNotification();
2100   application.Render();
2101
2102   // Trigger count is 2 - load & render a frame
2103   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2104
2105   Property::Map attributes;
2106   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
2107
2108   application.SendNotification();
2109   application.Render();
2110
2111   // Check frame number
2112   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2113   Renderer renderer = actor.GetRendererAt(0u);
2114   DALI_TEST_CHECK(renderer);
2115
2116   Test::EmitGlobalTimerSignal();
2117   application.SendNotification();
2118   application.Render(16);
2119
2120   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2121
2122   application.SendNotification();
2123   application.Render();
2124
2125   Property::Map resultMap;
2126   visual.CreatePropertyMap(resultMap);
2127
2128   // check the property values from the returned map from a visual
2129   Property::Value* value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
2130   DALI_TEST_CHECK(value);
2131   DALI_TEST_NOT_EQUALS(value->Get<int>(), 0, Math::MACHINE_EPSILON_100, TEST_LOCATION);
2132
2133   Window window = DevelWindow::Get(actor);
2134   window.Hide();
2135
2136   Test::EmitGlobalTimerSignal();
2137   application.SendNotification();
2138   application.Render(16);
2139
2140   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2141
2142   application.SendNotification();
2143   application.Render();
2144
2145   visual.CreatePropertyMap(resultMap);
2146
2147   // check the property values from the returned map from a visual
2148   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
2149   DALI_TEST_CHECK(value);
2150   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION);
2151
2152   END_TEST;
2153 }