Merge "(Vector) Add NOTIFY_AFTER_RASTERIZATION property for low fps file + Use Update...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedVectorImageVisual.cpp
1 /*
2  * Copyright (c) 2024 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 <chrono>
19 #include <iostream>
20 #include <thread>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-event-thread-callback.h>
24 #include <toolkit-timer.h>
25 #include <toolkit-vector-animation-renderer.h>
26 #include "dummy-control.h"
27 #include "test-native-image-source.h"
28
29 #include <dali-toolkit/dali-toolkit.h>
30
31 #include <dali-toolkit/devel-api/controls/control-devel.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
33 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
34 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
35 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
36 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
37 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
38
39 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
40 #include <dali/devel-api/adaptor-framework/window-devel.h>
41 #include <dali/devel-api/rendering/renderer-devel.h>
42
43 using namespace Dali;
44 using namespace Dali::Toolkit;
45
46 void dali_animated_vector_image_visual_startup(void)
47 {
48   test_return_value = TET_UNDEF;
49 }
50
51 void dali_animated_vector_image_visual_cleanup(void)
52 {
53   test_return_value = TET_PASS;
54 }
55
56 namespace
57 {
58 const char* TEST_VECTOR_IMAGE_FILE_NAME            = TEST_RESOURCE_DIR "/insta_camera.json";
59 const char* TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP = "framedrop.json";
60 const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME    = "invalid.json";
61
62 bool gAnimationFinishedSignalFired = false;
63
64 void VisualEventSignal(Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId)
65 {
66   if(visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED)
67   {
68     gAnimationFinishedSignalFired = true;
69   }
70 }
71
72 } // namespace
73
74 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
75 {
76   ToolkitTestApplication application;
77   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual01: Request animated vector image visual with a json url");
78
79   VisualFactory factory = VisualFactory::Get();
80   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
81   DALI_TEST_CHECK(visual);
82
83   DummyControl      actor     = DummyControl::New(true);
84   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
85   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
86   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
87   application.GetScene().Add(actor);
88
89   application.SendNotification();
90   application.Render();
91
92   // Trigger count is 1 - render a frame
93   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
94
95   // renderer is added to actor
96   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
97   Renderer renderer = actor.GetRendererAt(0u);
98   DALI_TEST_CHECK(renderer);
99
100   // Test SetOffScene().
101   actor.Unparent();
102   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
103
104   END_TEST;
105 }
106
107 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual02(void)
108 {
109   ToolkitTestApplication application;
110   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual02: Request animated vector image visual with a Property::Map");
111
112   Property::Map propertyMap;
113   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
114     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
115     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
116
117   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
118   DALI_TEST_CHECK(visual);
119
120   DummyControl      actor     = DummyControl::New(true);
121   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
122   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
123   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
124   application.GetScene().Add(actor);
125
126   application.SendNotification();
127   application.Render();
128
129   // Trigger count is 2 - load & render a frame
130   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
131
132   // renderer is added to actor
133   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
134   Renderer renderer = actor.GetRendererAt(0u);
135   DALI_TEST_CHECK(renderer);
136
137   actor.Unparent();
138   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
139
140   END_TEST;
141 }
142
143 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void)
144 {
145   ToolkitTestApplication application;
146   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual03: Request animated vector image visual with a Property::Map");
147
148   int             startFrame = 1, endFrame = 3;
149   Property::Array playRange;
150   playRange.PushBack(startFrame);
151   playRange.PushBack(endFrame);
152
153   Property::Map propertyMap;
154   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
155     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
156     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
157     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
158     .Add(DevelVisual::Property::CORNER_RADIUS, 50.0f)
159     .Add(DevelVisual::Property::BORDERLINE_WIDTH, 20.0f)
160     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
161
162   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
163   DALI_TEST_CHECK(visual);
164
165   DummyControl      actor     = DummyControl::New(true);
166   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
167   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
168   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
169   application.GetScene().Add(actor);
170
171   application.SendNotification();
172   application.Render();
173
174   // Trigger count is 2 - load & render a frame
175   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
176
177   // renderer is added to actor
178   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
179   Renderer renderer = actor.GetRendererAt(0u);
180   DALI_TEST_CHECK(renderer);
181
182   actor.Unparent();
183   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
184
185   END_TEST;
186 }
187
188 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
189 {
190   ToolkitTestApplication application;
191   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map");
192
193   int             startFrame = 1, endFrame = 3;
194   int             desiredWidth = 100, desiredHeight = 150;
195   float           cornerRadius     = 22.0f;
196   float           borderlineWidth  = 2.0f;
197   Vector4         borderlineColor  = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
198   float           borderlineOffset = 0.1f;
199   Property::Array playRange;
200   playRange.PushBack(startFrame);
201   playRange.PushBack(endFrame);
202
203   Property::Map propertyMap;
204   propertyMap.Add("visualType", DevelVisual::ANIMATED_VECTOR_IMAGE)
205     .Add("url", TEST_VECTOR_IMAGE_FILE_NAME)
206     .Add("loopCount", 3)
207     .Add("playRange", playRange)
208     .Add("stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME)
209     .Add("loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE)
210     .Add("redrawInScalingDown", false)
211     .Add("enableFrameCache", false)
212     .Add("notifyAfterRasterization", false)
213     .Add("cornerRadius", cornerRadius)
214     .Add("borderlineWidth", borderlineWidth)
215     .Add("borderlineColor", borderlineColor)
216     .Add("borderlineOffset", borderlineOffset)
217     .Add("desiredWidth", desiredWidth)
218     .Add("desiredHeight", desiredHeight);
219
220   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
221   DALI_TEST_CHECK(visual);
222
223   DummyControl      actor     = DummyControl::New(true);
224   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
225   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
226   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
227   application.GetScene().Add(actor);
228
229   application.SendNotification();
230   application.Render();
231
232   // Trigger count is 1 - render a frame
233   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
234
235   // renderer is added to actor
236   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
237
238   Renderer renderer = actor.GetRendererAt(0u);
239   DALI_TEST_CHECK(renderer);
240
241   Property::Map resultMap;
242   visual.CreatePropertyMap(resultMap);
243
244   // check the property values from the returned map from a visual
245   Property::Value* value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
246   DALI_TEST_CHECK(value);
247   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
248
249   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
250   DALI_TEST_CHECK(value);
251   DALI_TEST_CHECK(value->Get<int>() == 3);
252
253   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
254   DALI_TEST_CHECK(value);
255
256   Property::Array* result = value->GetArray();
257   DALI_TEST_CHECK(result);
258
259   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
260   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
261
262   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
263   DALI_TEST_CHECK(value);
264   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::FIRST_FRAME);
265
266   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
267   DALI_TEST_CHECK(value);
268   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::AUTO_REVERSE);
269
270   value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
271   DALI_TEST_CHECK(value);
272   DALI_TEST_CHECK(value->Get<bool>() == false);
273
274   value = resultMap.Find(DevelImageVisual::Property::ENABLE_FRAME_CACHE, Property::BOOLEAN);
275   DALI_TEST_CHECK(value);
276   DALI_TEST_CHECK(value->Get<bool>() == false);
277
278   value = resultMap.Find(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION, Property::BOOLEAN);
279   DALI_TEST_CHECK(value);
280   DALI_TEST_CHECK(value->Get<bool>() == false);
281
282   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
283   DALI_TEST_CHECK(value);
284   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(cornerRadius, cornerRadius, cornerRadius, cornerRadius), TEST_LOCATION);
285
286   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
287   DALI_TEST_CHECK(value);
288   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
289
290   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
291   DALI_TEST_CHECK(value);
292   DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
293
294   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
295   DALI_TEST_CHECK(value);
296   DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
297
298   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
299   DALI_TEST_CHECK(value);
300   DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
301
302   value = resultMap.Find(ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
303   DALI_TEST_CHECK(value);
304   DALI_TEST_EQUALS(value->Get<int>(), desiredWidth, TEST_LOCATION);
305
306   value = resultMap.Find(ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
307   DALI_TEST_CHECK(value);
308   DALI_TEST_EQUALS(value->Get<int>(), desiredHeight, TEST_LOCATION);
309
310   actor.Unparent();
311   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
312
313   END_TEST;
314 }
315
316 int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
317 {
318   ToolkitTestApplication application;
319   tet_infoline("UtcDaliAnimatedVectorImageVisualGetPropertyMap01");
320
321   int             startFrame = 1, endFrame = 3;
322   int             desiredWidth = 100, desiredHeight = 150;
323   Vector4         cornerRadius(50.0f, 22.0f, 0.0f, 3.0f);
324   float           borderlineWidth  = 2.3f;
325   Vector4         borderlineColor  = Vector4(0.3f, 0.3f, 1.0f, 1.0f);
326   float           borderlineOffset = 0.3f;
327   Property::Array playRange;
328   playRange.PushBack(startFrame);
329   playRange.PushBack(endFrame);
330
331   Property::Map propertyMap;
332   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
333     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
334     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
335     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
336     .Add(DevelVisual::Property::CORNER_RADIUS, cornerRadius)
337     .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE)
338     .Add(DevelVisual::Property::BORDERLINE_WIDTH, borderlineWidth)
339     .Add(DevelVisual::Property::BORDERLINE_COLOR, borderlineColor)
340     .Add(DevelVisual::Property::BORDERLINE_OFFSET, borderlineOffset)
341     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false)
342     .Add(ImageVisual::Property::DESIRED_WIDTH, desiredWidth)
343     .Add(ImageVisual::Property::DESIRED_HEIGHT, desiredHeight);
344
345   // request AnimatedVectorImageVisual with a property map
346   VisualFactory factory = VisualFactory::Get();
347   Visual::Base  visual  = factory.CreateVisual(propertyMap);
348
349   DummyControl      actor     = DummyControl::New(true);
350   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
351   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
352
353   Vector2 controlSize(20.f, 30.f);
354   actor.SetProperty(Actor::Property::SIZE, controlSize);
355
356   application.GetScene().Add(actor);
357
358   application.SendNotification();
359   application.Render();
360
361   // Trigger count is 2 - load & render a frame
362   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
363
364   Property::Map resultMap;
365   resultMap = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
366
367   // check the property values from the returned map from a visual
368   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
369   DALI_TEST_CHECK(value);
370   DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
371
372   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
373   DALI_TEST_CHECK(value);
374   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
375
376   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
377   DALI_TEST_CHECK(value);
378   DALI_TEST_CHECK(value->Get<int>() == 3);
379
380   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
381   DALI_TEST_CHECK(value);
382
383   Property::Array* result = value->GetArray();
384   DALI_TEST_CHECK(result);
385
386   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
387   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
388
389   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
390   DALI_TEST_CHECK(value);
391   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::CURRENT_FRAME);
392
393   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
394   DALI_TEST_CHECK(value);
395   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::RESTART);
396
397   value = resultMap.Find(DevelImageVisual::Property::CONTENT_INFO, Property::MAP);
398   DALI_TEST_CHECK(value);
399
400   value = resultMap.Find(DevelImageVisual::Property::MARKER_INFO, Property::MAP);
401   DALI_TEST_CHECK(value);
402
403   value = resultMap.Find(DevelImageVisual::Property::ENABLE_FRAME_CACHE, Property::BOOLEAN);
404   DALI_TEST_CHECK(value);
405   DALI_TEST_CHECK(value->Get<bool>() == false); // Check default value
406
407   value = resultMap.Find(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION, Property::BOOLEAN);
408   DALI_TEST_CHECK(value);
409   DALI_TEST_CHECK(value->Get<bool>() == false); // Check default value
410
411   value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
412   DALI_TEST_CHECK(value);
413   DALI_TEST_CHECK(value->Get<bool>() == true); // Check default value
414
415   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
416   DALI_TEST_CHECK(value);
417   DALI_TEST_EQUALS(value->Get<Vector4>(), cornerRadius, TEST_LOCATION);
418
419   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
420   DALI_TEST_CHECK(value);
421   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
422
423   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
424   DALI_TEST_CHECK(value);
425   DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
426
427   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
428   DALI_TEST_CHECK(value);
429   DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
430
431   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
432   DALI_TEST_CHECK(value);
433   DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
434
435   value = resultMap.Find(ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
436   DALI_TEST_CHECK(value);
437   DALI_TEST_EQUALS(value->Get<int>(), desiredWidth, TEST_LOCATION);
438
439   value = resultMap.Find(ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
440   DALI_TEST_CHECK(value);
441   DALI_TEST_EQUALS(value->Get<int>(), desiredHeight, TEST_LOCATION);
442
443   // request AnimatedVectorImageVisual with an URL
444   Visual::Base visual2 = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
445
446   resultMap.Clear();
447   visual2.CreatePropertyMap(resultMap);
448
449   // check the property values from the returned map from a visual
450   value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
451   DALI_TEST_CHECK(value);
452   DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
453
454   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
455   DALI_TEST_CHECK(value);
456   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
457
458   END_TEST;
459 }
460
461 int UtcDaliAnimatedVectorImageVisualPlayback(void)
462 {
463   ToolkitTestApplication application;
464
465   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayback");
466
467   {
468     // request AnimatedVectorImageVisual with a property map
469     VisualFactory factory = VisualFactory::Get();
470     Visual::Base  visual  = factory.CreateVisual(
471       Property::Map()
472         .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
473         .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
474         .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
475
476     DummyControl        dummyControl = DummyControl::New(true);
477     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
478     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
479     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
480
481     Property::Map attributes;
482     tet_infoline("Test Play action");
483     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
484
485     application.GetScene().Add(dummyControl);
486     application.SendNotification();
487     application.Render(16);
488
489     Property::Map    map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
490     Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
491     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
492
493     tet_infoline("Test Pause action");
494     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
495
496     application.SendNotification();
497     application.Render(16);
498
499     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
500     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
501     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PAUSED);
502
503     tet_infoline("Test Play action");
504     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
505
506     application.SendNotification();
507     application.Render(16);
508
509     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
510     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
511     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
512
513     tet_infoline("Test Stop action");
514     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
515
516     application.SendNotification();
517     application.Render(16);
518
519     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
520     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
521     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
522
523     tet_infoline("Test Stop action again");
524     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
525
526     application.SendNotification();
527     application.Render(16);
528
529     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
530     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
531     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
532
533     tet_infoline("Test Play action");
534     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
535
536     application.SendNotification();
537     application.Render(16);
538
539     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
540     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
541     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
542
543     tet_infoline("Off stage");
544     dummyControl.Unparent();
545
546     application.SendNotification();
547     application.Render(16);
548
549     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
550     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
551     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
552
553     tet_infoline("On stage again");
554     application.GetScene().Add(dummyControl);
555
556     application.SendNotification();
557     application.Render(16);
558
559     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
560     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
561     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
562
563     tet_infoline("Test Play action");
564     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
565
566     application.SendNotification();
567     application.Render(16);
568
569     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
570     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
571     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
572
573     // Change Size
574     Vector3 newSize(100.0f, 100.0f, 0.0f);
575     dummyControl.SetProperty(Actor::Property::SIZE, newSize);
576
577     application.SendNotification();
578     application.Render(16);
579
580     // Size should be changed
581     Vector3 naturalSize = dummyControl.GetNaturalSize();
582     DALI_TEST_CHECK(naturalSize == newSize);
583
584     dummyControl.Unparent();
585   }
586
587   END_TEST;
588 }
589
590 int UtcDaliAnimatedVectorImageVisualCustomShader(void)
591 {
592   ToolkitTestApplication application;
593   tet_infoline("UtcDaliAnimatedVectorImageVisualCustomShader Test custom shader");
594
595   VisualFactory     factory = VisualFactory::Get();
596   Property::Map     properties;
597   Property::Map     shader;
598   const std::string vertexShader                    = "Foobar";
599   const std::string fragmentShader                  = "Foobar sampler2D Foobar";
600   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
601   shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
602
603   properties[Visual::Property::TYPE]     = Visual::IMAGE;
604   properties[Visual::Property::SHADER]   = shader;
605   properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME;
606
607   Visual::Base visual = factory.CreateVisual(properties);
608
609   // trigger creation through setting on stage
610   DummyControl        dummy     = DummyControl::New(true);
611   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
612   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
613
614   dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
615   dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
616   application.GetScene().Add(dummy);
617
618   application.SendNotification();
619   application.Render();
620
621   // Trigger count is 1 - render a frame
622   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
623
624   Renderer        renderer = dummy.GetRendererAt(0);
625   Shader          shader2  = renderer.GetShader();
626   Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
627   Property::Map*  map      = value.GetMap();
628   DALI_TEST_CHECK(map);
629
630   std::string      resultFragmentShader, resultVertexShader;
631   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
632   fragment->Get(resultFragmentShader);
633   DALI_TEST_CHECK(resultFragmentShader.find(fragmentShader) != std::string::npos);
634
635   Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
636   vertex->Get(resultVertexShader);
637   DALI_TEST_CHECK(resultVertexShader.find(vertexShader) != std::string::npos);
638
639   END_TEST;
640 }
641
642 int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
643 {
644   ToolkitTestApplication application;
645   tet_infoline("UtcDaliAnimatedVectorImageVisualNaturalSize");
646
647   VisualFactory factory = VisualFactory::Get();
648   Visual::Base  visual  = factory.CreateVisual(
649     Property::Map()
650       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
651       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
652       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
653   DALI_TEST_CHECK(visual);
654
655   DummyControl      actor     = DummyControl::New(true);
656   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
657   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
658
659   Vector2 controlSize(20.f, 30.f);
660   Vector2 naturalSize;
661
662   application.GetScene().Add(actor);
663
664   application.SendNotification();
665   application.Render();
666
667   // Trigger count is 1 - load
668   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
669
670   visual.GetNaturalSize(naturalSize);
671
672   DALI_TEST_EQUALS(naturalSize, Vector2(100.0f, 100.0f), TEST_LOCATION); // 100x100 is the content default size.
673
674   actor.SetProperty(Actor::Property::SIZE, controlSize);
675
676   application.SendNotification();
677   application.Render();
678
679   visual.GetNaturalSize(naturalSize);
680
681   DALI_TEST_EQUALS(naturalSize, controlSize, TEST_LOCATION);
682
683   END_TEST;
684 }
685
686 int UtcDaliAnimatedVectorImageVisualLoopCount(void)
687 {
688   ToolkitTestApplication application;
689   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopCount");
690
691   Property::Map propertyMap;
692   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
693     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
694     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
695     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
696
697   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
698   DALI_TEST_CHECK(visual);
699
700   DummyControl      actor     = DummyControl::New(true);
701   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
702   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
703
704   Vector2 controlSize(20.f, 30.f);
705   actor.SetProperty(Actor::Property::SIZE, controlSize);
706
707   application.GetScene().Add(actor);
708
709   Property::Map attributes;
710   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
711
712   application.SendNotification();
713   application.Render();
714
715   // Trigger count is 2 - load & render a frame
716   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
717
718   // renderer is added to actor
719   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
720   Renderer renderer = actor.GetRendererAt(0u);
721   DALI_TEST_CHECK(renderer);
722
723   END_TEST;
724 }
725
726 int UtcDaliAnimatedVectorImageVisualPlayRange(void)
727 {
728   ToolkitTestApplication application;
729   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRange");
730
731   int             startFrame = 1, endFrame = 3;
732   Property::Array array;
733   array.PushBack(endFrame);
734   array.PushBack(startFrame);
735
736   Property::Map propertyMap;
737   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
738     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
739     .Add(DevelImageVisual::Property::PLAY_RANGE, array)
740     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
741
742   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
743   DALI_TEST_CHECK(visual);
744
745   DummyControl      actor     = DummyControl::New(true);
746   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
747   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
748
749   Vector2 controlSize(20.f, 30.f);
750   actor.SetProperty(Actor::Property::SIZE, controlSize);
751
752   application.GetScene().Add(actor);
753
754   Property::Map attributes;
755   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
756
757   application.SendNotification();
758   application.Render();
759
760   // Trigger count is 2 - load & render a frame
761   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
762
763   // renderer is added to actor
764   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
765   Renderer renderer = actor.GetRendererAt(0u);
766   DALI_TEST_CHECK(renderer);
767
768   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
769   Property::Value* value            = map.Find(DevelImageVisual::Property::PLAY_RANGE);
770   int              totalFrameNumber = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER)->Get<int>();
771
772   int              resultStartFrame, resultEndFrame;
773   Property::Array* result = value->GetArray();
774   result->GetElementAt(0).Get(resultStartFrame);
775   result->GetElementAt(1).Get(resultEndFrame);
776
777   DALI_TEST_EQUALS(startFrame, resultStartFrame, TEST_LOCATION);
778   DALI_TEST_EQUALS(endFrame, resultEndFrame, TEST_LOCATION);
779
780   // Set invalid play range
781   array.Clear();
782   array.PushBack(1);
783   array.PushBack(100);
784
785   attributes.Clear();
786   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
787   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
788
789   // To make event trigger
790   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
791
792   application.SendNotification();
793   application.Render();
794
795   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
796
797   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
798   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
799
800   result = value->GetArray();
801   result->GetElementAt(0).Get(resultStartFrame);
802   result->GetElementAt(1).Get(resultEndFrame);
803
804   DALI_TEST_EQUALS(resultStartFrame, 1, TEST_LOCATION);
805   DALI_TEST_EQUALS(resultEndFrame, totalFrameNumber - 1, TEST_LOCATION); // Should be clamped
806
807   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Map());
808
809   application.SendNotification();
810   application.Render();
811
812   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
813
814   // To make event trigger
815   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
816
817   application.SendNotification();
818   application.Render();
819
820   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
821
822   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
823   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
824   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
825
826   array.Clear();
827   array.PushBack(0);
828   array.PushBack(2);
829
830   attributes.Clear();
831   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
832   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
833
834   // To make event trigger
835   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
836
837   application.SendNotification();
838   application.Render();
839
840   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
841
842   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
843   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
844
845   result = value->GetArray();
846   result->GetElementAt(0).Get(resultStartFrame);
847   result->GetElementAt(1).Get(resultEndFrame);
848
849   DALI_TEST_EQUALS(0, resultStartFrame, TEST_LOCATION);
850   DALI_TEST_EQUALS(2, resultEndFrame, TEST_LOCATION);
851
852   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
853   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION); // CURRENT_FRAME_NUMBER should be changed also.
854
855   END_TEST;
856 }
857
858 int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
859 {
860   ToolkitTestApplication application;
861   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRangeMarker");
862
863   // Set 1 marker as array
864   Property::Array array;
865   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
866
867   Property::Map propertyMap;
868   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
869     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
870     .Add(DevelImageVisual::Property::PLAY_RANGE, array)
871     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
872
873   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
874   DALI_TEST_CHECK(visual);
875
876   DummyControl      actor     = DummyControl::New(true);
877   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
878   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
879
880   Vector2 controlSize(20.f, 30.f);
881   actor.SetProperty(Actor::Property::SIZE, controlSize);
882
883   application.GetScene().Add(actor);
884
885   Property::Map attributes;
886   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
887
888   application.SendNotification();
889   application.Render();
890
891   // Trigger count is 2 - load & render a frame
892   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
893
894   // renderer is added to actor
895   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
896   Renderer renderer = actor.GetRendererAt(0u);
897   DALI_TEST_CHECK(renderer);
898
899   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
900   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
901
902   int              resultStartFrame, resultEndFrame;
903   Property::Array* result = value->GetArray();
904   result->GetElementAt(0).Get(resultStartFrame);
905   result->GetElementAt(1).Get(resultEndFrame);
906
907   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
908   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
909
910   // Set 1 marker as string
911   array.Clear();
912
913   attributes.Clear();
914   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, VECTOR_ANIMATION_MARKER_NAME_1);
915   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
916
917   // To make event trigger
918   actor.SetProperty(Actor::Property::SIZE, Vector2(40.0f, 40.0f));
919
920   application.SendNotification();
921   application.Render();
922
923   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
924
925   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
926   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
927
928   result = value->GetArray();
929   result->GetElementAt(0).Get(resultStartFrame);
930   result->GetElementAt(1).Get(resultEndFrame);
931
932   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
933   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
934
935   // Set 2 markers
936   array.Clear();
937   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
938   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_2);
939
940   attributes.Clear();
941   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
942   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
943
944   // To make event trigger
945   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
946
947   application.SendNotification();
948   application.Render();
949
950   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
951
952   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
953   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
954
955   result = value->GetArray();
956   result->GetElementAt(0).Get(resultStartFrame);
957   result->GetElementAt(1).Get(resultEndFrame);
958
959   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
960   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
961
962   // Set invalid play range
963   array.Clear();
964   array.PushBack(1);
965   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
966
967   attributes.Clear();
968   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
969   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
970
971   // To make event trigger
972   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
973
974   application.SendNotification();
975   application.Render();
976
977   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
978
979   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
980   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
981
982   result = value->GetArray();
983   result->GetElementAt(0).Get(resultStartFrame);
984   result->GetElementAt(1).Get(resultEndFrame);
985
986   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION); // Should not be changed
987   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
988
989   END_TEST;
990 }
991
992 int UtcDaliAnimatedVectorImageVisualMarkerInfo(void)
993 {
994   ToolkitTestApplication application;
995   tet_infoline("UtcDaliAnimatedVectorImageVisualMarkerInfo");
996
997   Property::Map propertyMap;
998   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
999     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1000     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1001
1002   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1003   DALI_TEST_CHECK(visual);
1004
1005   DummyControl      actor     = DummyControl::New(true);
1006   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1007   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1008
1009   Vector2 controlSize(20.f, 30.f);
1010   actor.SetProperty(Actor::Property::SIZE, controlSize);
1011
1012   application.GetScene().Add(actor);
1013
1014   Property::Map attributes;
1015   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1016
1017   application.SendNotification();
1018   application.Render();
1019
1020   // Trigger count is 2 - load & render a frame
1021   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1022
1023   // renderer is added to actor
1024   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1025   Renderer renderer = actor.GetRendererAt(0u);
1026   DALI_TEST_CHECK(renderer);
1027
1028   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1029   Property::Value* value = map.Find(DevelImageVisual::Property::MARKER_INFO);
1030
1031   DALI_TEST_CHECK(value);
1032
1033   Property::Map* result = value->GetMap();
1034   DALI_TEST_CHECK(result);
1035
1036   std::string resultMarkerName;
1037   int         resultStartFrame, resultEndFrame;
1038   DALI_TEST_EQUALS(2u, result->Count(), TEST_LOCATION);
1039
1040   for(uint32_t i = 0u; i < result->Count(); ++i)
1041   {
1042     if(result->GetKeyAt(i).stringKey == VECTOR_ANIMATION_MARKER_NAME_1)
1043     {
1044       Property::Array* frameArray = result->GetValue(i).GetArray();
1045       DALI_TEST_CHECK(frameArray);
1046       frameArray->GetElementAt(0).Get(resultStartFrame);
1047       frameArray->GetElementAt(1).Get(resultEndFrame);
1048
1049       DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
1050       DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
1051     }
1052     else if(result->GetKeyAt(i).stringKey == VECTOR_ANIMATION_MARKER_NAME_2)
1053     {
1054       Property::Array* frameArray = result->GetValue(i).GetArray();
1055       DALI_TEST_CHECK(frameArray);
1056       frameArray->GetElementAt(0).Get(resultStartFrame);
1057       frameArray->GetElementAt(1).Get(resultEndFrame);
1058
1059       DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_2, resultStartFrame, TEST_LOCATION);
1060       DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
1061     }
1062     else
1063     {
1064       DALI_TEST_CHECK(false);
1065     }
1066   }
1067
1068   END_TEST;
1069 }
1070
1071 int UtcDaliAnimatedVectorImageVisualMarkerInfoFromInvalid(void)
1072 {
1073   ToolkitTestApplication application;
1074   tet_infoline("UtcDaliAnimatedVectorImageVisualMarkerInfoFromInvalid");
1075
1076   Property::Map propertyMap;
1077   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1078     .Add(ImageVisual::Property::URL, "invalid.json")
1079     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1080
1081   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1082   DALI_TEST_CHECK(visual);
1083
1084   DummyControl      actor     = DummyControl::New(true);
1085   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1086   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1087
1088   Vector2 controlSize(20.f, 30.f);
1089   actor.SetProperty(Actor::Property::SIZE, controlSize);
1090
1091   application.GetScene().Add(actor);
1092
1093   Property::Map attributes;
1094   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1095
1096   application.SendNotification();
1097   application.Render();
1098
1099   // Trigger count is 1 - load, and failed.
1100   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1101
1102   // renderer is added to actor
1103   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1104   Renderer renderer = actor.GetRendererAt(0u);
1105   DALI_TEST_CHECK(renderer);
1106
1107   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1108   Property::Value* value = map.Find(DevelImageVisual::Property::MARKER_INFO);
1109
1110   // The values when load failed case is invalid.
1111   DALI_TEST_CHECK(value == nullptr || (value->GetMap() == nullptr) || (value->GetMap()->Empty()));
1112
1113   END_TEST;
1114 }
1115
1116 int UtcDaliAnimatedVectorImageVisualUsedFixedCache(void)
1117 {
1118   ToolkitTestApplication application;
1119   tet_infoline("UtcDaliAnimatedVectorImageVisualUsedFixedCache");
1120
1121   Property::Map propertyMap;
1122   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1123     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1124     .Add(DevelImageVisual::Property::ENABLE_FRAME_CACHE, true)
1125     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1126
1127   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1128   DALI_TEST_CHECK(visual);
1129
1130   DummyControl      actor     = DummyControl::New(true);
1131   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1132   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1133   //actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1134   application.GetScene().Add(actor);
1135
1136   application.SendNotification();
1137   application.Render();
1138
1139   // Trigger count is 1 - load
1140   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1141
1142   Vector2 controlSize(200.f, 200.f);
1143   actor.SetProperty(Actor::Property::SIZE, controlSize);
1144
1145   application.SendNotification();
1146   application.Render();
1147
1148   // Trigger count is 1 - render a frame
1149   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1150
1151   // renderer is added to actor
1152   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1153   Renderer renderer = actor.GetRendererAt(0u);
1154   DALI_TEST_CHECK(renderer);
1155
1156   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1157   Property::Value* value = map.Find(DevelImageVisual::Property::ENABLE_FRAME_CACHE);
1158   DALI_TEST_CHECK(value->Get<bool>() == true);
1159
1160   END_TEST;
1161 }
1162
1163 int UtcDaliAnimatedVectorImageVisualUsedFixedCacheFailed(void)
1164 {
1165   ToolkitTestApplication application;
1166   tet_infoline("UtcDaliAnimatedVectorImageVisualUsedFixedCacheFailed");
1167
1168   Property::Map propertyMap;
1169   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1170     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1171     .Add(DevelImageVisual::Property::ENABLE_FRAME_CACHE, true)
1172     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1173
1174   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1175   DALI_TEST_CHECK(visual);
1176
1177   DummyControl      actor     = DummyControl::New(true);
1178   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1179   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1180
1181   Vector2 controlSize(200.f, 200.f);
1182   actor.SetProperty(Actor::Property::SIZE, controlSize);
1183
1184   application.GetScene().Add(actor);
1185   application.SendNotification();
1186   application.Render();
1187
1188   // Trigger count is 1 - load, and failed.
1189   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1190
1191   // renderer is added to actor
1192   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1193   Renderer renderer = actor.GetRendererAt(0u);
1194   DALI_TEST_CHECK(renderer);
1195
1196   propertyMap.Clear();
1197   propertyMap.Add(DevelImageVisual::Property::ENABLE_FRAME_CACHE, true)
1198     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1199     .Add(ImageVisual::Property::DESIRED_WIDTH, 100)
1200     .Add(ImageVisual::Property::DESIRED_HEIGHT, 100);
1201   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1202
1203   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1204   Property::Value* value = map.Find(DevelImageVisual::Property::ENABLE_FRAME_CACHE);
1205   DALI_TEST_CHECK(value->Get<bool>() == true);
1206
1207   END_TEST;
1208 }
1209
1210 int UtcDaliAnimatedVectorImageVisualNotifyAfterRasterization(void)
1211 {
1212   ToolkitTestApplication application;
1213   tet_infoline("UtcDaliAnimatedVectorImageVisualNotifyAfterRasterization");
1214
1215   Property::Map propertyMap;
1216   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1217     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1218     .Add(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION, true)
1219     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1220
1221   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1222   DALI_TEST_CHECK(visual);
1223
1224   DummyControl      actor     = DummyControl::New(true);
1225   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1226   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1227
1228   application.GetScene().Add(actor);
1229
1230   application.SendNotification();
1231   application.Render();
1232
1233   // Trigger count is 1 - load
1234   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1235
1236   Vector2 controlSize(200.f, 200.f);
1237   actor.SetProperty(Actor::Property::SIZE, controlSize);
1238
1239   application.SendNotification();
1240   application.Render();
1241
1242   // Trigger count is 1 - render a frame
1243   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1244
1245   // Play animation
1246   Property::Map attributes;
1247   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1248
1249   application.SendNotification();
1250   application.Render();
1251
1252   // renderer is added to actor
1253   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1254   Renderer renderer = actor.GetRendererAt(0u);
1255   DALI_TEST_CHECK(renderer);
1256
1257   // Check renderer behavior
1258   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1259
1260   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1261   Property::Value* value = map.Find(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION);
1262   DALI_TEST_CHECK(value->Get<bool>() == true);
1263
1264   propertyMap.Clear();
1265   propertyMap.Add(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION, false);
1266   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1267
1268   application.SendNotification();
1269   application.Render();
1270
1271   // Check renderer behavior again
1272   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1273
1274   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1275   value = map.Find(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION);
1276   DALI_TEST_CHECK(value->Get<bool>() == false);
1277
1278   propertyMap.Clear();
1279   propertyMap.Add(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION, true);
1280   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1281
1282   application.SendNotification();
1283   application.Render();
1284
1285   // Check renderer behavior again
1286   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1287
1288   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1289   value = map.Find(DevelImageVisual::Property::NOTIFY_AFTER_RASTERIZATION);
1290   DALI_TEST_CHECK(value->Get<bool>() == true);
1291
1292   END_TEST;
1293 }
1294
1295 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
1296 {
1297   ToolkitTestApplication application;
1298   tet_infoline("UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal");
1299
1300   Property::Map propertyMap;
1301   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1302     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1303
1304   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1305   DALI_TEST_CHECK(visual);
1306
1307   DummyControl      actor     = DummyControl::New(true);
1308   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1309   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1310
1311   DevelControl::VisualEventSignal(actor).Connect(&VisualEventSignal);
1312
1313   Vector2 controlSize(20.f, 30.f);
1314   actor.SetProperty(Actor::Property::SIZE, controlSize);
1315
1316   application.GetScene().Add(actor);
1317
1318   application.SendNotification();
1319   application.Render();
1320
1321   // Trigger count is 1 - render a frame
1322   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1323
1324   propertyMap.Clear();
1325   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1326   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1327
1328   Property::Map attributes;
1329   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1330
1331   application.SendNotification();
1332   application.Render();
1333
1334   // Wait for animation finish
1335   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1336
1337   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1338   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
1339   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
1340
1341   DALI_TEST_EQUALS(gAnimationFinishedSignalFired, true, TEST_LOCATION);
1342
1343   END_TEST;
1344 }
1345
1346 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
1347 {
1348   ToolkitTestApplication application;
1349   tet_infoline("UtcDaliAnimatedVectorImageVisualJumpTo");
1350
1351   Property::Map propertyMap;
1352   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1353     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1354     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1355     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1356
1357   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1358   DALI_TEST_CHECK(visual);
1359
1360   tet_printf("1. Visual is created.\n");
1361
1362   DummyControl      actor     = DummyControl::New(true);
1363   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1364   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1365
1366   Vector2 controlSize(20.f, 30.f);
1367   actor.SetProperty(Actor::Property::SIZE, controlSize);
1368
1369   application.GetScene().Add(actor);
1370
1371   application.SendNotification();
1372   application.Render();
1373
1374   // Trigger count is 2 - load & render a frame
1375   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1376
1377   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2);
1378
1379   // To make event trigger
1380   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1381
1382   application.SendNotification();
1383   application.Render();
1384
1385   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1386
1387   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1388   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1389   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1390
1391   tet_printf("2. The current frame number is [%d].\n", value->Get<int>());
1392
1393   Property::Array array;
1394   array.PushBack(0);
1395   array.PushBack(2);
1396
1397   Property::Map attributes;
1398   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1399   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1400
1401   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1402
1403   // To make event trigger
1404   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1405
1406   application.SendNotification();
1407   application.Render();
1408
1409   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1410
1411   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1412   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1413   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1414
1415   tet_printf("3. The current frame number is [%d].\n", value->Get<int>());
1416
1417   // Change play range
1418   attributes.Clear();
1419   array.Clear();
1420
1421   array.PushBack(0);
1422   array.PushBack(4);
1423
1424   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1425   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1426
1427   attributes.Clear();
1428   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1429
1430   application.SendNotification();
1431   application.Render();
1432
1433   // Wait for animation finish
1434   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1435   // EventThread will be triggered after animation finished (For render forcibly).
1436   // TODO : Is this logic will works well on server-side?
1437   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1438
1439   // Jump to 3
1440   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1441
1442   // To make event trigger
1443   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1444
1445   application.SendNotification();
1446   application.Render();
1447
1448   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1449
1450   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1451   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1452   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1453
1454   tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1455
1456   // Jump to the same position
1457   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1458
1459   // To make event trigger
1460   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1461
1462   application.SendNotification();
1463   application.Render();
1464
1465   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1466
1467   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1468   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1469   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1470
1471   tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1472
1473   END_TEST;
1474 }
1475
1476 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1477 {
1478   ToolkitTestApplication application;
1479   tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1480
1481   int             startFrame = 1, endFrame = 3;
1482   Property::Array playRange;
1483   playRange.PushBack(startFrame);
1484   playRange.PushBack(endFrame);
1485
1486   Property::Map propertyMap;
1487   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1488     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1489     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1490     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
1491     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1492
1493   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1494   DALI_TEST_CHECK(visual);
1495
1496   DummyControl      actor     = DummyControl::New(true);
1497   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1498   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1499
1500   Vector2 controlSize(20.f, 30.f);
1501   actor.SetProperty(Actor::Property::SIZE, controlSize);
1502
1503   application.GetScene().Add(actor);
1504
1505   application.SendNotification();
1506   application.Render();
1507
1508   // Trigger count is 2 - load & render a frame
1509   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1510
1511   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1512   Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1513   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1514
1515   value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1516   DALI_TEST_CHECK(value);
1517
1518   Property::Array* result = value->GetArray();
1519   DALI_TEST_CHECK(result);
1520
1521   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1522   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1523
1524   playRange.Clear();
1525   playRange.PushBack(0);
1526   playRange.PushBack(2);
1527
1528   Property::Map attributes;
1529   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1530   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1531
1532   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1533
1534   // To make event trigger
1535   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1536
1537   application.SendNotification();
1538   application.Render();
1539
1540   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1541
1542   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1543   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1544   DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1545
1546   value  = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1547   result = value->GetArray();
1548   DALI_TEST_CHECK(result);
1549
1550   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1551   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1552
1553   attributes.Clear();
1554
1555   playRange.Clear();
1556   playRange.PushBack(startFrame);
1557   playRange.PushBack(endFrame);
1558
1559   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1560
1561   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1562
1563   // To make event trigger
1564   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1565
1566   application.SendNotification();
1567   application.Render();
1568
1569   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1570
1571   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1572   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1573
1574   result = value->GetArray();
1575   DALI_TEST_CHECK(result);
1576
1577   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1578   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1579
1580   // Play and update property
1581   attributes.Clear();
1582   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1583
1584   application.SendNotification();
1585   application.Render();
1586
1587   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1588
1589   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1590
1591   application.SendNotification();
1592   application.Render();
1593
1594   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1595   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1596   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1597
1598   END_TEST;
1599 }
1600
1601 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1602 {
1603   ToolkitTestApplication application;
1604   tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1605
1606   Property::Map propertyMap;
1607   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1608     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1609     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1610
1611   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1612   DALI_TEST_CHECK(visual);
1613
1614   DummyControl      actor     = DummyControl::New(true);
1615   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1616   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1617
1618   Vector2 controlSize(20.f, 30.f);
1619   actor.SetProperty(Actor::Property::SIZE, controlSize);
1620
1621   application.GetScene().Add(actor);
1622
1623   application.SendNotification();
1624   application.Render();
1625
1626   // Trigger count is 2 - load & render a frame
1627   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1628
1629   propertyMap.Clear();
1630   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1631   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
1632   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1633
1634   Property::Map attributes;
1635   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1636
1637   application.SendNotification();
1638   application.Render();
1639
1640   // Trigger count is 1 - animation finished
1641   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1642
1643   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1644   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1645   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1646
1647   // Change stop behavior
1648   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1649
1650   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1651
1652   attributes.Clear();
1653
1654   // Play again
1655   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1656
1657   application.SendNotification();
1658   application.Render();
1659
1660   // Trigger count is 1 - animation finished
1661   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1662
1663   map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1664
1665   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1666   int              totalFrameNumber = value1->Get<int>();
1667
1668   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1669   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1670
1671   // Change stop behavior
1672   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1673   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1674
1675   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1676
1677   attributes.Clear();
1678
1679   // Play again
1680   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1681
1682   application.SendNotification();
1683   application.Render();
1684
1685   // Pause
1686   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1687
1688   // To make event trigger
1689   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1690
1691   application.SendNotification();
1692   application.Render();
1693
1694   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1695
1696   map                    = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1697   value                  = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1698   int currentFrameNumber = value->Get<int>();
1699
1700   // Stop
1701   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1702
1703   // To make event trigger
1704   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1705
1706   application.SendNotification();
1707   application.Render();
1708
1709   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1710
1711   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1712   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1713   DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1714
1715   END_TEST;
1716 }
1717
1718 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1719 {
1720   ToolkitTestApplication application;
1721   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
1722
1723   Property::Map propertyMap;
1724   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1725     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1726     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1727
1728   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1729   DALI_TEST_CHECK(visual);
1730
1731   DummyControl      actor     = DummyControl::New(true);
1732   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1733   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1734
1735   Vector2 controlSize(20.f, 30.f);
1736   actor.SetProperty(Actor::Property::SIZE, controlSize);
1737
1738   application.GetScene().Add(actor);
1739
1740   application.SendNotification();
1741   application.Render();
1742
1743   // Trigger count is 2 - load, render
1744   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1745
1746   propertyMap.Clear();
1747   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1748   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1749   propertyMap.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE);
1750   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1751
1752   Property::Map attributes;
1753   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1754
1755   application.SendNotification();
1756   application.Render();
1757
1758   // Trigger count is 1 - animation finished
1759   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1760
1761   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1762   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1763   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1764
1765   // Change stop behavior
1766   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1767
1768   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1769
1770   // Play again
1771   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1772
1773   application.SendNotification();
1774   application.Render();
1775
1776   // Trigger count is 1 - animation finished
1777   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1778
1779   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1780   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1781   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1782
1783   // Change looping mode
1784   attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1785
1786   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1787
1788   // Play again
1789   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1790
1791   application.SendNotification();
1792   application.Render();
1793
1794   // Trigger count is 1 - animation finished
1795   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1796
1797   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1798   int              totalFrameNumber = value1->Get<int>();
1799
1800   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1801   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1802   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1803
1804   END_TEST;
1805 }
1806
1807 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1808 {
1809   ToolkitTestApplication application;
1810   tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1811
1812   Property::Map propertyMap;
1813   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1814     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1815
1816   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1817   DALI_TEST_CHECK(visual);
1818
1819   DummyControl      actor     = DummyControl::New(true);
1820   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1821   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1822   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1823
1824   application.GetScene().Add(actor);
1825
1826   application.SendNotification();
1827   application.Render();
1828
1829   // Trigger count is 1 - render a frame
1830   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1831
1832   Renderer renderer = actor.GetRendererAt(0u);
1833   DALI_TEST_CHECK(renderer);
1834
1835   Vector2 controlSize(20.f, 30.f);
1836   actor.SetProperty(Actor::Property::SIZE, controlSize);
1837
1838   application.SendNotification();
1839   application.Render();
1840
1841   application.SendNotification();
1842   application.Render();
1843
1844   // Trigger count is 1 - render a frame
1845   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1846
1847   auto textureSet = renderer.GetTextures();
1848   auto texture    = textureSet.GetTexture(0);
1849
1850   DALI_TEST_EQUALS(controlSize.width, texture.GetWidth(), TEST_LOCATION);
1851   DALI_TEST_EQUALS(controlSize.height, texture.GetHeight(), TEST_LOCATION);
1852
1853   // Change scale
1854   Vector3 controlScale(2.0f, 2.0f, 1.0f);
1855   actor.SetProperty(Actor::Property::SCALE, controlScale);
1856
1857   application.SendNotification();
1858   application.Render();
1859
1860   application.SendNotification();
1861   application.Render();
1862
1863   // Trigger count is 1 - render a frame
1864   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1865
1866   renderer = actor.GetRendererAt(0u);
1867   DALI_TEST_CHECK(renderer);
1868
1869   textureSet = renderer.GetTextures();
1870   texture    = textureSet.GetTexture(0);
1871
1872   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1873   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1874
1875   // Size animation
1876   controlSize         = Vector2(50.0f, 100.0f);
1877   Animation animation = Animation::New(1.0);
1878   animation.AnimateTo(Property(actor, Actor::Property::SIZE), Vector3(controlSize.x, controlSize.y, 0.0f));
1879   animation.Play();
1880
1881   application.SendNotification();
1882   application.Render(1100); // After the animation
1883
1884   application.SendNotification();
1885   application.Render();
1886
1887   // Trigger count is 1 - render a frame
1888   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1889
1890   renderer = actor.GetRendererAt(0u);
1891   DALI_TEST_CHECK(renderer);
1892
1893   textureSet = renderer.GetTextures();
1894   texture    = textureSet.GetTexture(0);
1895
1896   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1897   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1898
1899   END_TEST;
1900 }
1901
1902 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1903 {
1904   ToolkitTestApplication application;
1905   tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1906
1907   Property::Map propertyMap;
1908   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1909     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1910     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1911
1912   Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1913   DALI_TEST_CHECK(visual1);
1914
1915   DummyControl      actor1     = DummyControl::New(true);
1916   DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1917   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1918
1919   Vector2 controlSize(20.f, 30.f);
1920   actor1.SetProperty(Actor::Property::SIZE, controlSize);
1921
1922   application.GetScene().Add(actor1);
1923
1924   application.SendNotification();
1925   application.Render();
1926
1927   // Trigger count is 2 - load & render a frame
1928   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1929
1930   propertyMap.Clear();
1931   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1932     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1933     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1934
1935   Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1936   DALI_TEST_CHECK(visual2);
1937
1938   DummyControl      actor2     = DummyControl::New(true);
1939   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1940   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1941
1942   actor2.SetProperty(Actor::Property::SIZE, controlSize);
1943
1944   application.GetScene().Add(actor2);
1945
1946   application.SendNotification();
1947   application.Render();
1948
1949   // Trigger count is 2 - load & render a frame
1950   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1951
1952   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1953
1954   // To make event trigger
1955   actor2.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1956
1957   application.SendNotification();
1958   application.Render();
1959
1960   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1961
1962   Property::Map attributes;
1963   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1964
1965   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1966   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1967
1968   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1969
1970   // renderer is added to actor
1971   DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1972   Renderer renderer1 = actor1.GetRendererAt(0u);
1973   DALI_TEST_CHECK(renderer1);
1974
1975   // renderer is added to actor
1976   DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1977   Renderer renderer2 = actor2.GetRendererAt(0u);
1978   DALI_TEST_CHECK(renderer2);
1979
1980   END_TEST;
1981 }
1982
1983 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1984 {
1985   ToolkitTestApplication application;
1986   tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1987
1988   Property::Map propertyMap;
1989   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1990     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1991     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1992
1993   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1994   DALI_TEST_CHECK(visual);
1995
1996   DummyControl      actor     = DummyControl::New(true);
1997   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1998   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1999
2000   Vector2 controlSize(20.f, 30.f);
2001   actor.SetProperty(Actor::Property::SIZE, controlSize);
2002
2003   application.GetScene().Add(actor);
2004
2005   application.SendNotification();
2006   application.Render();
2007
2008   // Trigger count is 2 - load & render a frame
2009   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2010
2011   Property::Map attributes;
2012   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2013
2014   application.SendNotification();
2015   application.Render();
2016
2017   // Check rendering behavior
2018   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2019   Renderer renderer = actor.GetRendererAt(0u);
2020   DALI_TEST_CHECK(renderer);
2021   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
2022
2023   actor.SetProperty(Actor::Property::VISIBLE, false);
2024
2025   application.SendNotification();
2026   application.Render();
2027
2028   // Check rendering behavior again
2029   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
2030
2031   END_TEST;
2032 }
2033
2034 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
2035 {
2036   ToolkitTestApplication application;
2037   tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
2038
2039   Property::Map propertyMap;
2040   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2041     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
2042
2043   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2044   DALI_TEST_CHECK(visual);
2045
2046   DummyControl      actor     = DummyControl::New(true);
2047   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2048   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2049
2050   Vector2 controlSize(20.f, 30.f);
2051   actor.SetProperty(Actor::Property::SIZE, controlSize);
2052
2053   application.GetScene().Add(actor);
2054
2055   application.SendNotification();
2056   application.Render();
2057
2058   // Trigger count is 1 - render a frame
2059   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2060
2061   Property::Map attributes;
2062   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2063
2064   application.SendNotification();
2065   application.Render();
2066
2067   // Check rendering behavior
2068   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2069   Renderer renderer = actor.GetRendererAt(0u);
2070   DALI_TEST_CHECK(renderer);
2071   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
2072
2073   Window window = DevelWindow::Get(actor);
2074   window.Hide();
2075
2076   application.SendNotification();
2077   application.Render();
2078
2079   // Check rendering behavior again
2080   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
2081
2082   END_TEST;
2083 }
2084
2085 int UtcDaliAnimatedVectorImageVisualInvalidFile01(void)
2086 {
2087   ToolkitTestApplication application;
2088   tet_infoline("Request loading with invalid file - should draw broken image");
2089
2090   TestGlAbstraction& gl           = application.GetGlAbstraction();
2091   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2092   textureTrace.Enable(true);
2093
2094   Property::Map propertyMap;
2095   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2096     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
2097     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2098
2099   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2100   DALI_TEST_CHECK(visual);
2101
2102   DummyControl      actor     = DummyControl::New(true);
2103   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2104   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2105
2106   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
2107
2108   application.GetScene().Add(actor);
2109
2110   application.SendNotification();
2111   application.Render();
2112
2113   // Trigger count is 1 - load
2114   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2115
2116   application.SendNotification();
2117   application.Render();
2118
2119   // Check resource status
2120   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
2121   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2122
2123   // The broken image should be shown.
2124   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2125   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2126
2127   END_TEST;
2128 }
2129
2130 int UtcDaliAnimatedVectorImageVisualInvalidFile02(void)
2131 {
2132   ToolkitTestApplication application;
2133   tet_infoline("Request loading with invalid file - should draw broken image");
2134
2135   TestGlAbstraction& gl           = application.GetGlAbstraction();
2136   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2137   textureTrace.Enable(true);
2138
2139   Property::Map propertyMap;
2140   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2141     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
2142
2143   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2144   DALI_TEST_CHECK(visual);
2145
2146   DummyControl      actor     = DummyControl::New(true);
2147   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2148   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2149
2150   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
2151
2152   application.SendNotification();
2153   application.Render();
2154
2155   // Add to the Scene after loading
2156   application.GetScene().Add(actor);
2157
2158   application.SendNotification();
2159   application.Render();
2160
2161   // Check resource status
2162   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
2163   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2164
2165   // The broken image should be shown.
2166   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2167   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2168
2169   END_TEST;
2170 }
2171
2172 int UtcDaliAnimatedVectorImageVisualInvalidFile03(void)
2173 {
2174   ToolkitTestApplication application;
2175   tet_infoline("Request loading with invalid file without size set - should draw broken image");
2176
2177   TestGlAbstraction& gl           = application.GetGlAbstraction();
2178   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2179   textureTrace.Enable(true);
2180
2181   Property::Map propertyMap;
2182   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2183     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
2184     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2185
2186   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2187   DALI_TEST_CHECK(visual);
2188
2189   DummyControl      actor     = DummyControl::New(true);
2190   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2191   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2192
2193   application.GetScene().Add(actor);
2194
2195   application.SendNotification();
2196   application.Render();
2197
2198   // Trigger count is 1 - load
2199   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2200
2201   application.SendNotification();
2202   application.Render();
2203
2204   // Check resource status
2205   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
2206   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2207
2208   // The broken image should be shown.
2209   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2210   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2211
2212   END_TEST;
2213 }
2214
2215 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
2216 {
2217   ToolkitTestApplication application;
2218   tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
2219
2220   Property::Map propertyMap;
2221   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2222     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP)
2223     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2224
2225   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2226   DALI_TEST_CHECK(visual);
2227
2228   DummyControl      actor     = DummyControl::New(true);
2229   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2230   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2231
2232   Vector2 controlSize(20.f, 30.f);
2233   actor.SetProperty(Actor::Property::SIZE, controlSize);
2234
2235   application.GetScene().Add(actor);
2236
2237   application.SendNotification();
2238   application.Render();
2239
2240   // Trigger count is 2 - load, render the first frame
2241   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2242
2243   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2244   Property::Value* value            = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
2245   int              totalFrameNumber = value->Get<int>();
2246
2247   Property::Map attributes;
2248   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2249
2250   // Make delay to drop frames
2251   Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
2252
2253   application.SendNotification();
2254   application.Render();
2255
2256   // Trigger count is 1 - calculating frame drops
2257   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2258
2259   // Check dropped frame
2260   uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
2261   DALI_TEST_CHECK(frames > 0);
2262   DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
2263
2264   END_TEST;
2265 }
2266
2267 int UtcDaliAnimatedVectorImageVisualSize(void)
2268 {
2269   ToolkitTestApplication application;
2270   tet_infoline("UtcDaliAnimatedVectorImageVisualSize");
2271
2272   TestGlAbstraction& gl           = application.GetGlAbstraction();
2273   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2274
2275   VisualFactory factory = VisualFactory::Get();
2276   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
2277   DALI_TEST_CHECK(visual);
2278
2279   DummyControl      actor     = DummyControl::New(true);
2280   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2281   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2282
2283   application.GetScene().Add(actor);
2284
2285   application.SendNotification();
2286   application.Render();
2287
2288   // Trigger count is 1 - resource ready
2289   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2290
2291   textureTrace.Enable(true);
2292
2293   application.SendNotification();
2294   application.Render();
2295
2296   {
2297     int               width = 100, height = 100; // 100x100 is the content default size.
2298     std::stringstream out;
2299     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
2300     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2301   }
2302
2303   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
2304
2305   application.SendNotification();
2306   application.Render();
2307
2308   // Trigger count is 1 - resource ready
2309   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2310
2311   textureTrace.Reset();
2312
2313   application.SendNotification();
2314   application.Render();
2315
2316   {
2317     int               width = 200, height = 200;
2318     std::stringstream out;
2319     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
2320     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2321   }
2322
2323   END_TEST;
2324 }
2325
2326 namespace
2327 {
2328 bool gDynamicPropertyCallbackFired = false;
2329
2330 Property::Value FillColorCallback(int32_t id, VectorAnimationRenderer::VectorProperty property, uint32_t frameNumber)
2331 {
2332   gDynamicPropertyCallbackFired = true;
2333
2334   if(frameNumber < 3)
2335   {
2336     return Vector3(0, 0, 1);
2337   }
2338   else
2339   {
2340     return Vector3(1, 0, 0);
2341   }
2342 }
2343 } // namespace
2344
2345 int UtcDaliAnimatedVectorImageVisualDynamicProperty(void)
2346 {
2347   ToolkitTestApplication application;
2348   tet_infoline("UtcDaliAnimatedVectorImageVisualDynamicProperty");
2349
2350   VisualFactory factory = VisualFactory::Get();
2351   Visual::Base  visual  = factory.CreateVisual(
2352     Property::Map()
2353       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2354       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2355       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
2356   DALI_TEST_CHECK(visual);
2357
2358   DummyControl      actor     = DummyControl::New(true);
2359   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2360   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2361
2362   Vector2 controlSize(20.f, 30.f);
2363   actor.SetProperty(Actor::Property::SIZE, controlSize);
2364
2365   application.GetScene().Add(actor);
2366
2367   gDynamicPropertyCallbackFired = false;
2368
2369   // Set dynamic property
2370   DevelAnimatedVectorImageVisual::DynamicPropertyInfo info;
2371   info.id       = 1;
2372   info.keyPath  = "Test.Path";
2373   info.property = static_cast<int>(VectorAnimationRenderer::VectorProperty::FILL_COLOR);
2374   info.callback = MakeCallback(FillColorCallback);
2375
2376   DevelControl::DoActionExtension(actor, DummyControl::Property::TEST_VISUAL, DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY, Any(info));
2377
2378   Property::Map attributes;
2379   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2380
2381   application.SendNotification();
2382   application.Render();
2383
2384   // Trigger count is 2 - load & render a frame
2385   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2386
2387   // Test whether the property callback is called
2388   DALI_TEST_EQUALS(gDynamicPropertyCallbackFired, true, TEST_LOCATION);
2389
2390   END_TEST;
2391 }
2392
2393 int UtcDaliAnimatedVectorImageVisualDesiredSize(void)
2394 {
2395   ToolkitTestApplication application;
2396   tet_infoline("UtcDaliAnimatedVectorImageVisualDesiredSize");
2397
2398   TestGlAbstraction& gl           = application.GetGlAbstraction();
2399   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2400   int                desiredWidth = 150, desiredHeight = 200;
2401
2402   Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
2403   DALI_TEST_CHECK(visual);
2404
2405   DummyControl      actor     = DummyControl::New(true);
2406   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2407   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2408
2409   application.GetScene().Add(actor);
2410
2411   application.SendNotification();
2412   application.Render();
2413
2414   // Trigger count is 1 - resource ready
2415   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2416
2417   textureTrace.Enable(true);
2418
2419   application.SendNotification();
2420   application.Render();
2421
2422   {
2423     std::stringstream out;
2424     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2425     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2426   }
2427
2428   // Unparent to make next trigger
2429   actor.Unparent();
2430
2431   application.SendNotification();
2432   application.Render();
2433
2434   // Set visual size
2435   actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
2436   application.GetScene().Add(actor);
2437
2438   application.SendNotification();
2439   application.Render();
2440
2441   // Trigger count is 1 - resource ready
2442   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2443
2444   textureTrace.Reset();
2445
2446   application.SendNotification();
2447   application.Render();
2448
2449   {
2450     std::stringstream out;
2451     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2452     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed
2453   }
2454
2455   END_TEST;
2456 }
2457
2458 int UtcDaliAnimatedVectorImageVisualFlushAction(void)
2459 {
2460   ToolkitTestApplication application;
2461
2462   tet_infoline("UtcDaliAnimatedVectorImageVisualFlushAction");
2463
2464   int startFrame = 1;
2465   int endFrame   = 2;
2466
2467   int totalFrameCount = 0;
2468
2469   Property::Array playRange;
2470   playRange.PushBack(startFrame);
2471   playRange.PushBack(endFrame);
2472
2473   Property::Map    resultMap;
2474   Property::Value* value = nullptr;
2475
2476   // request AnimatedVectorImageVisual with a property map
2477   VisualFactory factory = VisualFactory::Get();
2478   Visual::Base  visual  = factory.CreateVisual(
2479     Property::Map()
2480       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2481       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2482       .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
2483       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true));
2484
2485   DummyControl        dummyControl = DummyControl::New(true);
2486   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
2487   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2488   dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
2489
2490   application.GetScene().Add(dummyControl);
2491
2492   // Retry function to get playrange until expect values comes.
2493   auto CheckAndRetryPlayRange = [&](int expectStartFrame, int expectEndFrame, std::vector<std::pair<int, int>> retrialFrames) {
2494     int tryCount    = 0;
2495     int tryCountMax = 30;
2496     while(++tryCount <= tryCountMax)
2497     {
2498       Property::Map resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2499
2500       Property::Value* value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
2501       DALI_TEST_CHECK(value);
2502
2503       Property::Array* result = value->GetArray();
2504       DALI_TEST_CHECK(result);
2505       DALI_TEST_EQUALS(result->Count(), 2, TEST_LOCATION);
2506
2507       bool tryAgain = false;
2508       for(auto& framePair : retrialFrames)
2509       {
2510         if(result->GetElementAt(0).Get<int>() == framePair.first && result->GetElementAt(1).Get<int>() == framePair.second)
2511         {
2512           tryAgain = true;
2513           break;
2514         }
2515       }
2516       if(tryAgain)
2517       {
2518         tet_printf("Retry to get value again! [%d]\n", tryCount);
2519         // Dummy sleep 1 second.
2520         Test::WaitForEventThreadTrigger(1, 1);
2521         continue;
2522       }
2523
2524       DALI_TEST_EQUALS(result->GetElementAt(0).Get<int>(), expectStartFrame, TEST_LOCATION);
2525       DALI_TEST_EQUALS(result->GetElementAt(1).Get<int>(), expectEndFrame, TEST_LOCATION);
2526       break;
2527     }
2528     DALI_TEST_CHECK(tryCount <= tryCountMax);
2529   };
2530
2531   tet_printf("Pause lottie first.\n");
2532
2533   Property::Map attributes;
2534   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
2535
2536   application.SendNotification();
2537   application.Render(16);
2538
2539   do
2540   {
2541     resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2542
2543     value = resultMap.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER, Property::INTEGER);
2544     DALI_TEST_CHECK(value);
2545     totalFrameCount = value->Get<int>();
2546   } while(totalFrameCount == 0);
2547
2548   // Ensure that vector data sended well.
2549   CheckAndRetryPlayRange(startFrame, endFrame, {{0, 0}, {0, totalFrameCount - 1}});
2550
2551   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2552
2553   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2554   DALI_TEST_CHECK(value);
2555   DALI_TEST_EQUALS(value->Get<int>(), startFrame, TEST_LOCATION);
2556
2557   tet_printf("Now logically, range : [%d~%d], current : %d\n", startFrame, endFrame, startFrame);
2558
2559   int changedStartFrame1 = startFrame + 2;
2560   int changedEndFrame1   = endFrame + 2;
2561
2562   playRange.Clear();
2563   playRange.Add(changedStartFrame1);
2564   playRange.Add(changedEndFrame1);
2565
2566   tet_printf("Change play range\n");
2567   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2568   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2569
2570   tet_printf("Jump to changedEndFrame!\n");
2571   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, changedEndFrame1);
2572
2573   attributes.Clear();
2574   tet_infoline("Flush Action!");
2575   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame1, changedEndFrame1, changedEndFrame1);
2576   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::FLUSH, attributes);
2577
2578   int changedStartFrame2 = startFrame + 1;
2579   int changedEndFrame2   = endFrame + 1;
2580
2581   playRange.Clear();
2582   playRange.Add(changedStartFrame2);
2583   playRange.Add(changedEndFrame2);
2584
2585   tet_printf("Change play range again\n");
2586   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame2, changedEndFrame2, changedEndFrame2);
2587   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2588   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2589
2590   application.SendNotification();
2591   application.Render(16);
2592
2593   // Ensure that vector data sended well.
2594   CheckAndRetryPlayRange(changedStartFrame2, changedEndFrame2, {{changedStartFrame1, changedEndFrame1}, {startFrame, endFrame}});
2595
2596   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2597
2598   tet_printf("Test whether current frame number changed well. If Flush not works, current frame become startFrame.");
2599   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2600   DALI_TEST_CHECK(value);
2601   DALI_TEST_EQUALS(value->Get<int>(), changedEndFrame2, TEST_LOCATION);
2602
2603   dummyControl.Unparent();
2604
2605   END_TEST;
2606 }
2607
2608 int UtcDaliAnimatedVectorImageNativeTextureChangeShader(void)
2609 {
2610   ToolkitTestApplication application;
2611   tet_infoline("UtcDaliAnimatedVectorImageNativeTextureChangeShader");
2612
2613   VisualFactory factory = VisualFactory::Get();
2614   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
2615   DALI_TEST_CHECK(visual);
2616
2617   DummyControl      actor     = DummyControl::New(true);
2618   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2619   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2620
2621   // Make we use native texture now.
2622   Test::VectorAnimationRenderer::UseNativeImageTexture(true);
2623
2624   application.GetScene().Add(actor);
2625
2626   application.SendNotification();
2627   application.Render();
2628
2629   // Trigger count is 1 - resource ready
2630   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2631
2632   application.SendNotification();
2633   application.Render();
2634
2635   Renderer        renderer = actor.GetRendererAt(0);
2636   Shader          shader   = renderer.GetShader();
2637   Property::Value value    = shader.GetProperty(Shader::Property::PROGRAM);
2638   Property::Map*  map      = value.GetMap();
2639   DALI_TEST_CHECK(map);
2640
2641   std::string      resultFragmentShader, resultVertexShader;
2642   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2643   fragment->Get(resultFragmentShader);
2644   DALI_TEST_CHECK(resultFragmentShader.find(NativeImageSourceTest::GetCustomFragmentPrefix()) != std::string::npos);
2645
2646   // Reset to make we use normal texture again.
2647   Test::VectorAnimationRenderer::UseNativeImageTexture(false);
2648
2649   END_TEST;
2650 }