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