2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
28 #include <dali-toolkit/dali-toolkit.h>
30 #include <dali-toolkit/devel-api/controls/control-devel.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
33 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
34 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
35 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
36 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
38 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
39 #include <dali/devel-api/adaptor-framework/window-devel.h>
40 #include <dali/devel-api/rendering/renderer-devel.h>
43 using namespace Dali::Toolkit;
45 void dali_animated_vector_image_visual_startup(void)
47 test_return_value = TET_UNDEF;
50 void dali_animated_vector_image_visual_cleanup(void)
52 test_return_value = TET_PASS;
57 const char* TEST_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
58 const char* TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP = "framedrop.json";
59 const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME = "invalid.json";
61 bool gAnimationFinishedSignalFired = false;
63 void VisualEventSignal(Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId)
65 if(visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED)
67 gAnimationFinishedSignalFired = true;
73 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
75 ToolkitTestApplication application;
76 tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual01: Request animated vector image visual with a json url");
78 VisualFactory factory = VisualFactory::Get();
79 Visual::Base visual = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
80 DALI_TEST_CHECK(visual);
82 DummyControl actor = DummyControl::New(true);
83 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
84 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
85 actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
86 application.GetScene().Add(actor);
88 application.SendNotification();
91 // Trigger count is 1 - render a frame
92 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
94 // renderer is added to actor
95 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
96 Renderer renderer = actor.GetRendererAt(0u);
97 DALI_TEST_CHECK(renderer);
99 // Test SetOffScene().
101 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
106 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual02(void)
108 ToolkitTestApplication application;
109 tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual02: Request animated vector image visual with a Property::Map");
111 Property::Map propertyMap;
112 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
113 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
114 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
116 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
117 DALI_TEST_CHECK(visual);
119 DummyControl actor = DummyControl::New(true);
120 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
121 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
122 actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
123 application.GetScene().Add(actor);
125 application.SendNotification();
126 application.Render();
128 // Trigger count is 2 - load & render a frame
129 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
131 // renderer is added to actor
132 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
133 Renderer renderer = actor.GetRendererAt(0u);
134 DALI_TEST_CHECK(renderer);
137 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
142 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void)
144 ToolkitTestApplication application;
145 tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual03: Request animated vector image visual with a Property::Map");
147 int startFrame = 1, endFrame = 3;
148 Property::Array playRange;
149 playRange.PushBack(startFrame);
150 playRange.PushBack(endFrame);
152 Property::Map propertyMap;
153 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
154 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
155 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
156 .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
157 .Add(DevelVisual::Property::CORNER_RADIUS, 50.0f)
158 .Add(DevelVisual::Property::BORDERLINE_WIDTH, 20.0f)
159 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
161 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
162 DALI_TEST_CHECK(visual);
164 DummyControl actor = DummyControl::New(true);
165 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
166 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
167 actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
168 application.GetScene().Add(actor);
170 application.SendNotification();
171 application.Render();
173 // Trigger count is 2 - load & render a frame
174 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
176 // renderer is added to actor
177 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
178 Renderer renderer = actor.GetRendererAt(0u);
179 DALI_TEST_CHECK(renderer);
182 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
187 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
189 ToolkitTestApplication application;
190 tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map");
192 int startFrame = 1, endFrame = 3;
193 int desiredWidth = 100, desiredHeight = 150;
194 float cornerRadius = 22.0f;
195 float borderlineWidth = 2.0f;
196 Vector4 borderlineColor = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
197 float borderlineOffset = 0.1f;
198 Property::Array playRange;
199 playRange.PushBack(startFrame);
200 playRange.PushBack(endFrame);
202 Property::Map propertyMap;
203 propertyMap.Add("visualType", DevelVisual::ANIMATED_VECTOR_IMAGE)
204 .Add("url", TEST_VECTOR_IMAGE_FILE_NAME)
206 .Add("playRange", playRange)
207 .Add("stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME)
208 .Add("loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE)
209 .Add("redrawInScalingDown", false)
210 .Add("cornerRadius", cornerRadius)
211 .Add("borderlineWidth", borderlineWidth)
212 .Add("borderlineColor", borderlineColor)
213 .Add("borderlineOffset", borderlineOffset)
214 .Add("desiredWidth", desiredWidth)
215 .Add("desiredHeight", desiredHeight);
217 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
218 DALI_TEST_CHECK(visual);
220 DummyControl actor = DummyControl::New(true);
221 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
222 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
223 actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
224 application.GetScene().Add(actor);
226 application.SendNotification();
227 application.Render();
229 // Trigger count is 1 - render a frame
230 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
232 // renderer is added to actor
233 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
235 Renderer renderer = actor.GetRendererAt(0u);
236 DALI_TEST_CHECK(renderer);
238 Property::Map resultMap;
239 visual.CreatePropertyMap(resultMap);
241 // check the property values from the returned map from a visual
242 Property::Value* value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
243 DALI_TEST_CHECK(value);
244 DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
246 value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
247 DALI_TEST_CHECK(value);
248 DALI_TEST_CHECK(value->Get<int>() == 3);
250 value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
251 DALI_TEST_CHECK(value);
253 Property::Array* result = value->GetArray();
254 DALI_TEST_CHECK(result);
256 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
257 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
259 value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
260 DALI_TEST_CHECK(value);
261 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::FIRST_FRAME);
263 value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
264 DALI_TEST_CHECK(value);
265 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::AUTO_REVERSE);
267 value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
268 DALI_TEST_CHECK(value);
269 DALI_TEST_CHECK(value->Get<bool>() == false);
271 value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
272 DALI_TEST_CHECK(value);
273 DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(cornerRadius, cornerRadius, cornerRadius, cornerRadius), TEST_LOCATION);
275 value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
276 DALI_TEST_CHECK(value);
277 DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
279 value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
280 DALI_TEST_CHECK(value);
281 DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
283 value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
284 DALI_TEST_CHECK(value);
285 DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
287 value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
288 DALI_TEST_CHECK(value);
289 DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
291 value = resultMap.Find(ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
292 DALI_TEST_CHECK(value);
293 DALI_TEST_EQUALS(value->Get<int>(), desiredWidth, TEST_LOCATION);
295 value = resultMap.Find(ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
296 DALI_TEST_CHECK(value);
297 DALI_TEST_EQUALS(value->Get<int>(), desiredHeight, TEST_LOCATION);
300 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
305 int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
307 ToolkitTestApplication application;
308 tet_infoline("UtcDaliAnimatedVectorImageVisualGetPropertyMap01");
310 int startFrame = 1, endFrame = 3;
311 int desiredWidth = 100, desiredHeight = 150;
312 Vector4 cornerRadius(50.0f, 22.0f, 0.0f, 3.0f);
313 float borderlineWidth = 2.3f;
314 Vector4 borderlineColor = Vector4(0.3f, 0.3f, 1.0f, 1.0f);
315 float borderlineOffset = 0.3f;
316 Property::Array playRange;
317 playRange.PushBack(startFrame);
318 playRange.PushBack(endFrame);
320 Property::Map propertyMap;
321 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
322 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
323 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
324 .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
325 .Add(DevelVisual::Property::CORNER_RADIUS, cornerRadius)
326 .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE)
327 .Add(DevelVisual::Property::BORDERLINE_WIDTH, borderlineWidth)
328 .Add(DevelVisual::Property::BORDERLINE_COLOR, borderlineColor)
329 .Add(DevelVisual::Property::BORDERLINE_OFFSET, borderlineOffset)
330 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false)
331 .Add(ImageVisual::Property::DESIRED_WIDTH, desiredWidth)
332 .Add(ImageVisual::Property::DESIRED_HEIGHT, desiredHeight);
334 // request AnimatedVectorImageVisual with a property map
335 VisualFactory factory = VisualFactory::Get();
336 Visual::Base visual = factory.CreateVisual(propertyMap);
338 DummyControl actor = DummyControl::New(true);
339 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
340 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
342 Vector2 controlSize(20.f, 30.f);
343 actor.SetProperty(Actor::Property::SIZE, controlSize);
345 application.GetScene().Add(actor);
347 application.SendNotification();
348 application.Render();
350 // Trigger count is 2 - load & render a frame
351 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
353 Property::Map resultMap;
354 resultMap = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
356 // check the property values from the returned map from a visual
357 Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
358 DALI_TEST_CHECK(value);
359 DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
361 value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
362 DALI_TEST_CHECK(value);
363 DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
365 value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
366 DALI_TEST_CHECK(value);
367 DALI_TEST_CHECK(value->Get<int>() == 3);
369 value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
370 DALI_TEST_CHECK(value);
372 Property::Array* result = value->GetArray();
373 DALI_TEST_CHECK(result);
375 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
376 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
378 value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
379 DALI_TEST_CHECK(value);
380 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::CURRENT_FRAME);
382 value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
383 DALI_TEST_CHECK(value);
384 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::RESTART);
386 value = resultMap.Find(DevelImageVisual::Property::CONTENT_INFO, Property::MAP);
387 DALI_TEST_CHECK(value);
389 value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
390 DALI_TEST_CHECK(value);
391 DALI_TEST_CHECK(value->Get<bool>() == true); // Check default value
393 value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
394 DALI_TEST_CHECK(value);
395 DALI_TEST_EQUALS(value->Get<Vector4>(), cornerRadius, TEST_LOCATION);
397 value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
398 DALI_TEST_CHECK(value);
399 DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
401 value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
402 DALI_TEST_CHECK(value);
403 DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
405 value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
406 DALI_TEST_CHECK(value);
407 DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
409 value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
410 DALI_TEST_CHECK(value);
411 DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
413 value = resultMap.Find(ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
414 DALI_TEST_CHECK(value);
415 DALI_TEST_EQUALS(value->Get<int>(), desiredWidth, TEST_LOCATION);
417 value = resultMap.Find(ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
418 DALI_TEST_CHECK(value);
419 DALI_TEST_EQUALS(value->Get<int>(), desiredHeight, TEST_LOCATION);
421 // request AnimatedVectorImageVisual with an URL
422 Visual::Base visual2 = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
425 visual2.CreatePropertyMap(resultMap);
427 // check the property values from the returned map from a visual
428 value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
429 DALI_TEST_CHECK(value);
430 DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
432 value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
433 DALI_TEST_CHECK(value);
434 DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
439 int UtcDaliAnimatedVectorImageVisualPlayback(void)
441 ToolkitTestApplication application;
443 tet_infoline("UtcDaliAnimatedVectorImageVisualPlayback");
446 // request AnimatedVectorImageVisual with a property map
447 VisualFactory factory = VisualFactory::Get();
448 Visual::Base visual = factory.CreateVisual(
450 .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
451 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
452 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
454 DummyControl dummyControl = DummyControl::New(true);
455 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
456 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
457 dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
459 Property::Map attributes;
460 tet_infoline("Test Play action");
461 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
463 application.GetScene().Add(dummyControl);
464 application.SendNotification();
465 application.Render(16);
467 Property::Map map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
468 Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
469 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
471 tet_infoline("Test Pause action");
472 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
474 application.SendNotification();
475 application.Render(16);
477 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
478 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
479 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PAUSED);
481 tet_infoline("Test Play action");
482 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
484 application.SendNotification();
485 application.Render(16);
487 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
488 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
489 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
491 tet_infoline("Test Stop action");
492 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
494 application.SendNotification();
495 application.Render(16);
497 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
498 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
499 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
501 tet_infoline("Test Stop action again");
502 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
504 application.SendNotification();
505 application.Render(16);
507 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
508 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
509 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
511 tet_infoline("Test Play action");
512 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
514 application.SendNotification();
515 application.Render(16);
517 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
518 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
519 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
521 tet_infoline("Off stage");
522 dummyControl.Unparent();
524 application.SendNotification();
525 application.Render(16);
527 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
528 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
529 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
531 tet_infoline("On stage again");
532 application.GetScene().Add(dummyControl);
534 application.SendNotification();
535 application.Render(16);
537 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
538 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
539 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
541 tet_infoline("Test Play action");
542 DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
544 application.SendNotification();
545 application.Render(16);
547 map = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
548 value = map.Find(DevelImageVisual::Property::PLAY_STATE);
549 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
552 Vector3 newSize(100.0f, 100.0f, 0.0f);
553 dummyControl.SetProperty(Actor::Property::SIZE, newSize);
555 application.SendNotification();
556 application.Render(16);
558 // Size should be changed
559 Vector3 naturalSize = dummyControl.GetNaturalSize();
560 DALI_TEST_CHECK(naturalSize == newSize);
562 dummyControl.Unparent();
568 int UtcDaliAnimatedVectorImageVisualCustomShader(void)
570 ToolkitTestApplication application;
571 tet_infoline("UtcDaliAnimatedVectorImageVisualCustomShader Test custom shader");
573 VisualFactory factory = VisualFactory::Get();
574 Property::Map properties;
575 Property::Map shader;
576 const std::string vertexShader = "Foobar";
577 const std::string fragmentShader = "Foobar sampler2D Foobar";
578 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
579 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
581 properties[Visual::Property::TYPE] = Visual::IMAGE;
582 properties[Visual::Property::SHADER] = shader;
583 properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME;
585 Visual::Base visual = factory.CreateVisual(properties);
587 // trigger creation through setting on stage
588 DummyControl dummy = DummyControl::New(true);
589 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
590 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
592 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
593 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
594 application.GetScene().Add(dummy);
596 application.SendNotification();
597 application.Render();
599 // Trigger count is 1 - render a frame
600 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
602 Renderer renderer = dummy.GetRendererAt(0);
603 Shader shader2 = renderer.GetShader();
604 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
605 Property::Map* map = value.GetMap();
606 DALI_TEST_CHECK(map);
608 std::string resultFragmentShader, resultVertexShader;
609 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
610 fragment->Get(resultFragmentShader);
611 DALI_TEST_CHECK(resultFragmentShader.find(fragmentShader) != std::string::npos);
613 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
614 vertex->Get(resultVertexShader);
615 DALI_TEST_CHECK(resultVertexShader.find(vertexShader) != std::string::npos);
620 int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
622 ToolkitTestApplication application;
623 tet_infoline("UtcDaliAnimatedVectorImageVisualNaturalSize");
625 VisualFactory factory = VisualFactory::Get();
626 Visual::Base visual = factory.CreateVisual(
628 .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
629 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
630 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
631 DALI_TEST_CHECK(visual);
633 DummyControl actor = DummyControl::New(true);
634 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
635 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
637 Vector2 controlSize(20.f, 30.f);
640 application.GetScene().Add(actor);
642 application.SendNotification();
643 application.Render();
645 // Trigger count is 1 - load
646 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
648 visual.GetNaturalSize(naturalSize);
650 DALI_TEST_EQUALS(naturalSize, Vector2(100.0f, 100.0f), TEST_LOCATION); // 100x100 is the content default size.
652 actor.SetProperty(Actor::Property::SIZE, controlSize);
654 application.SendNotification();
655 application.Render();
657 visual.GetNaturalSize(naturalSize);
659 DALI_TEST_EQUALS(naturalSize, controlSize, TEST_LOCATION);
664 int UtcDaliAnimatedVectorImageVisualLoopCount(void)
666 ToolkitTestApplication application;
667 tet_infoline("UtcDaliAnimatedVectorImageVisualLoopCount");
669 Property::Map propertyMap;
670 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
671 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
672 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
673 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
675 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
676 DALI_TEST_CHECK(visual);
678 DummyControl actor = DummyControl::New(true);
679 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
680 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
682 Vector2 controlSize(20.f, 30.f);
683 actor.SetProperty(Actor::Property::SIZE, controlSize);
685 application.GetScene().Add(actor);
687 Property::Map attributes;
688 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
690 application.SendNotification();
691 application.Render();
693 // Trigger count is 2 - load & render a frame
694 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
696 // renderer is added to actor
697 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
698 Renderer renderer = actor.GetRendererAt(0u);
699 DALI_TEST_CHECK(renderer);
704 int UtcDaliAnimatedVectorImageVisualPlayRange(void)
706 ToolkitTestApplication application;
707 tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRange");
709 int startFrame = 1, endFrame = 3;
710 Property::Array array;
711 array.PushBack(endFrame);
712 array.PushBack(startFrame);
714 Property::Map propertyMap;
715 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
716 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
717 .Add(DevelImageVisual::Property::PLAY_RANGE, array)
718 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
720 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
721 DALI_TEST_CHECK(visual);
723 DummyControl actor = DummyControl::New(true);
724 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
725 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
727 Vector2 controlSize(20.f, 30.f);
728 actor.SetProperty(Actor::Property::SIZE, controlSize);
730 application.GetScene().Add(actor);
732 Property::Map attributes;
733 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
735 application.SendNotification();
736 application.Render();
738 // Trigger count is 2 - load & render a frame
739 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
741 // renderer is added to actor
742 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
743 Renderer renderer = actor.GetRendererAt(0u);
744 DALI_TEST_CHECK(renderer);
746 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
747 Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
748 int totalFrameNumber = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER)->Get<int>();
750 int resultStartFrame, resultEndFrame;
751 Property::Array* result = value->GetArray();
752 result->GetElementAt(0).Get(resultStartFrame);
753 result->GetElementAt(1).Get(resultEndFrame);
755 DALI_TEST_EQUALS(startFrame, resultStartFrame, TEST_LOCATION);
756 DALI_TEST_EQUALS(endFrame, resultEndFrame, TEST_LOCATION);
758 // Set invalid play range
764 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
765 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
767 // To make event trigger
768 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
770 application.SendNotification();
771 application.Render();
773 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
775 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
776 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
778 result = value->GetArray();
779 result->GetElementAt(0).Get(resultStartFrame);
780 result->GetElementAt(1).Get(resultEndFrame);
782 DALI_TEST_EQUALS(resultStartFrame, 1, TEST_LOCATION);
783 DALI_TEST_EQUALS(resultEndFrame, totalFrameNumber - 1, TEST_LOCATION); // Should be clamped
785 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Map());
787 application.SendNotification();
788 application.Render();
790 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
792 // To make event trigger
793 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
795 application.SendNotification();
796 application.Render();
798 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
800 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
801 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
802 DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
809 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
810 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
812 // To make event trigger
813 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
815 application.SendNotification();
816 application.Render();
818 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
820 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
821 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
823 result = value->GetArray();
824 result->GetElementAt(0).Get(resultStartFrame);
825 result->GetElementAt(1).Get(resultEndFrame);
827 DALI_TEST_EQUALS(0, resultStartFrame, TEST_LOCATION);
828 DALI_TEST_EQUALS(2, resultEndFrame, TEST_LOCATION);
830 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
831 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION); // CURRENT_FRAME_NUMBER should be changed also.
836 int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
838 ToolkitTestApplication application;
839 tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRangeMarker");
841 Property::Array array;
842 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
844 Property::Map propertyMap;
845 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
846 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
847 .Add(DevelImageVisual::Property::PLAY_RANGE, array)
848 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
850 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
851 DALI_TEST_CHECK(visual);
853 DummyControl actor = DummyControl::New(true);
854 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
855 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
857 Vector2 controlSize(20.f, 30.f);
858 actor.SetProperty(Actor::Property::SIZE, controlSize);
860 application.GetScene().Add(actor);
862 Property::Map attributes;
863 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
865 application.SendNotification();
866 application.Render();
868 // Trigger count is 2 - load & render a frame
869 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
871 // renderer is added to actor
872 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
873 Renderer renderer = actor.GetRendererAt(0u);
874 DALI_TEST_CHECK(renderer);
876 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
877 Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
879 int resultStartFrame, resultEndFrame;
880 Property::Array* result = value->GetArray();
881 result->GetElementAt(0).Get(resultStartFrame);
882 result->GetElementAt(1).Get(resultEndFrame);
884 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
885 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
889 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
890 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_2);
893 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
894 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
896 // To make event trigger
897 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
899 application.SendNotification();
900 application.Render();
902 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
904 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
905 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
907 result = value->GetArray();
908 result->GetElementAt(0).Get(resultStartFrame);
909 result->GetElementAt(1).Get(resultEndFrame);
911 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
912 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
914 // Set invalid play range
917 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
920 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
921 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
923 // To make event trigger
924 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
926 application.SendNotification();
927 application.Render();
929 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
931 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
932 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
934 result = value->GetArray();
935 result->GetElementAt(0).Get(resultStartFrame);
936 result->GetElementAt(1).Get(resultEndFrame);
938 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION); // Should not be changed
939 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
944 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
946 ToolkitTestApplication application;
947 tet_infoline("UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal");
949 Property::Map propertyMap;
950 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
951 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
952 .Add(DevelImageVisual::Property::LOOP_COUNT, 3);
954 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
955 DALI_TEST_CHECK(visual);
957 DummyControl actor = DummyControl::New(true);
958 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
959 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
961 DevelControl::VisualEventSignal(actor).Connect(&VisualEventSignal);
963 Vector2 controlSize(20.f, 30.f);
964 actor.SetProperty(Actor::Property::SIZE, controlSize);
966 application.GetScene().Add(actor);
968 Property::Map attributes;
969 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
971 application.SendNotification();
972 application.Render();
974 // Wait for animation finish - render, finish
975 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
977 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
978 Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
979 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
981 DALI_TEST_EQUALS(gAnimationFinishedSignalFired, true, TEST_LOCATION);
986 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
988 ToolkitTestApplication application;
989 tet_infoline("UtcDaliAnimatedVectorImageVisualJumpTo");
991 Property::Map propertyMap;
992 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
993 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
994 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
995 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
997 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
998 DALI_TEST_CHECK(visual);
1000 tet_printf("1. Visual is created.\n");
1002 DummyControl actor = DummyControl::New(true);
1003 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1004 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1006 Vector2 controlSize(20.f, 30.f);
1007 actor.SetProperty(Actor::Property::SIZE, controlSize);
1009 application.GetScene().Add(actor);
1011 application.SendNotification();
1012 application.Render();
1014 // Trigger count is 2 - load & render a frame
1015 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1017 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2);
1019 // To make event trigger
1020 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1022 application.SendNotification();
1023 application.Render();
1025 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1027 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1028 Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1029 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1031 tet_printf("2. The current frame number is [%d].\n", value->Get<int>());
1033 Property::Array array;
1037 Property::Map attributes;
1038 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1039 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1041 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1043 // To make event trigger
1044 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1046 application.SendNotification();
1047 application.Render();
1049 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1051 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1052 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1053 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1055 tet_printf("3. The current frame number is [%d].\n", value->Get<int>());
1057 // Change play range
1064 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1065 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1068 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1070 application.SendNotification();
1071 application.Render();
1073 // Wait for animation finish
1074 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1077 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1079 // To make event trigger
1080 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1082 application.SendNotification();
1083 application.Render();
1085 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1087 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1088 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1089 DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1091 tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1093 // Jump to the same position
1094 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1096 // To make event trigger
1097 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1099 application.SendNotification();
1100 application.Render();
1102 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1104 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1105 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1106 DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1108 tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1113 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1115 ToolkitTestApplication application;
1116 tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1118 int startFrame = 1, endFrame = 3;
1119 Property::Array playRange;
1120 playRange.PushBack(startFrame);
1121 playRange.PushBack(endFrame);
1123 Property::Map propertyMap;
1124 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1125 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1126 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1127 .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
1128 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1130 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1131 DALI_TEST_CHECK(visual);
1133 DummyControl actor = DummyControl::New(true);
1134 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1135 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1137 Vector2 controlSize(20.f, 30.f);
1138 actor.SetProperty(Actor::Property::SIZE, controlSize);
1140 application.GetScene().Add(actor);
1142 application.SendNotification();
1143 application.Render();
1145 // Trigger count is 2 - load & render a frame
1146 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1148 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1149 Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1150 DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1152 value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1153 DALI_TEST_CHECK(value);
1155 Property::Array* result = value->GetArray();
1156 DALI_TEST_CHECK(result);
1158 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1159 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1162 playRange.PushBack(0);
1163 playRange.PushBack(2);
1165 Property::Map attributes;
1166 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1167 attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1169 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1171 // To make event trigger
1172 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1174 application.SendNotification();
1175 application.Render();
1177 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1179 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1180 value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1181 DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1183 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1184 result = value->GetArray();
1185 DALI_TEST_CHECK(result);
1187 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1188 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1193 playRange.PushBack(startFrame);
1194 playRange.PushBack(endFrame);
1196 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1198 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1200 // To make event trigger
1201 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1203 application.SendNotification();
1204 application.Render();
1206 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1208 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1209 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1211 result = value->GetArray();
1212 DALI_TEST_CHECK(result);
1214 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1215 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1217 // Play and update property
1219 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1221 application.SendNotification();
1222 application.Render();
1224 attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1226 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1228 application.SendNotification();
1229 application.Render();
1231 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1232 value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1233 DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1238 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1240 ToolkitTestApplication application;
1241 tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1243 Property::Map propertyMap;
1244 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1245 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1246 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1247 .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME)
1248 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1250 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1251 DALI_TEST_CHECK(visual);
1253 DummyControl actor = DummyControl::New(true);
1254 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1255 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1257 Vector2 controlSize(20.f, 30.f);
1258 actor.SetProperty(Actor::Property::SIZE, controlSize);
1260 application.GetScene().Add(actor);
1262 Property::Map attributes;
1263 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1265 application.SendNotification();
1266 application.Render();
1268 // Trigger count is 3 - load, render, animation finished
1269 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1271 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1272 Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1273 DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1275 // Change stop behavior
1276 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1278 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1283 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1285 application.SendNotification();
1286 application.Render();
1288 // Trigger count is 1 - animation finished
1289 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1291 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1293 Property::Value* value1 = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1294 int totalFrameNumber = value1->Get<int>();
1296 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1297 DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1299 // Change stop behavior
1300 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1301 attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1303 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1308 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1310 application.SendNotification();
1311 application.Render();
1314 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1316 // To make event trigger
1317 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1319 application.SendNotification();
1320 application.Render();
1322 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1324 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1325 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1326 int currentFrameNumber = value->Get<int>();
1329 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1331 // To make event trigger
1332 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1334 application.SendNotification();
1335 application.Render();
1337 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1339 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1340 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1341 DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1346 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1348 ToolkitTestApplication application;
1349 tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
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(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME)
1356 .Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE)
1357 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1359 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1360 DALI_TEST_CHECK(visual);
1362 DummyControl actor = DummyControl::New(true);
1363 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1364 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1366 Vector2 controlSize(20.f, 30.f);
1367 actor.SetProperty(Actor::Property::SIZE, controlSize);
1369 application.GetScene().Add(actor);
1371 Property::Map attributes;
1372 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1374 application.SendNotification();
1375 application.Render();
1377 // Trigger count is 3 - load, render, animation finished
1378 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1380 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1381 Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1382 DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1384 // Change stop behavior
1385 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1387 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1390 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1392 application.SendNotification();
1393 application.Render();
1395 // Trigger count is 1 - animation finished
1396 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1398 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1399 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1400 DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1402 // Change looping mode
1403 attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1405 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1408 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1410 application.SendNotification();
1411 application.Render();
1413 // Trigger count is 1 - animation finished
1414 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1416 Property::Value* value1 = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1417 int totalFrameNumber = value1->Get<int>();
1419 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1420 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1421 DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1426 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1428 ToolkitTestApplication application;
1429 tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1431 Property::Map propertyMap;
1432 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1433 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1435 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1436 DALI_TEST_CHECK(visual);
1438 DummyControl actor = DummyControl::New(true);
1439 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1440 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1441 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1443 application.GetScene().Add(actor);
1445 application.SendNotification();
1446 application.Render();
1448 // Trigger count is 1 - render a frame
1449 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1451 Renderer renderer = actor.GetRendererAt(0u);
1452 DALI_TEST_CHECK(renderer);
1454 Vector2 controlSize(20.f, 30.f);
1455 actor.SetProperty(Actor::Property::SIZE, controlSize);
1457 application.SendNotification();
1458 application.Render();
1460 application.SendNotification();
1461 application.Render();
1463 // Trigger count is 1 - render a frame
1464 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1466 auto textureSet = renderer.GetTextures();
1467 auto texture = textureSet.GetTexture(0);
1469 DALI_TEST_EQUALS(controlSize.width, texture.GetWidth(), TEST_LOCATION);
1470 DALI_TEST_EQUALS(controlSize.height, texture.GetHeight(), TEST_LOCATION);
1473 Vector3 controlScale(2.0f, 2.0f, 1.0f);
1474 actor.SetProperty(Actor::Property::SCALE, controlScale);
1476 application.SendNotification();
1477 application.Render();
1479 application.SendNotification();
1480 application.Render();
1482 // Trigger count is 1 - render a frame
1483 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1485 renderer = actor.GetRendererAt(0u);
1486 DALI_TEST_CHECK(renderer);
1488 textureSet = renderer.GetTextures();
1489 texture = textureSet.GetTexture(0);
1491 DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1492 DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1495 controlSize = Vector2(50.0f, 100.0f);
1496 Animation animation = Animation::New(1.0);
1497 animation.AnimateTo(Property(actor, Actor::Property::SIZE), Vector3(controlSize.x, controlSize.y, 0.0f));
1500 application.SendNotification();
1501 application.Render(1100); // After the animation
1503 application.SendNotification();
1504 application.Render();
1506 // Trigger count is 1 - render a frame
1507 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1509 renderer = actor.GetRendererAt(0u);
1510 DALI_TEST_CHECK(renderer);
1512 textureSet = renderer.GetTextures();
1513 texture = textureSet.GetTexture(0);
1515 DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1516 DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1521 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1523 ToolkitTestApplication application;
1524 tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1526 Property::Map propertyMap;
1527 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1528 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1529 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1531 Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1532 DALI_TEST_CHECK(visual1);
1534 DummyControl actor1 = DummyControl::New(true);
1535 DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1536 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1538 Vector2 controlSize(20.f, 30.f);
1539 actor1.SetProperty(Actor::Property::SIZE, controlSize);
1541 application.GetScene().Add(actor1);
1543 propertyMap.Clear();
1544 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1545 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1546 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1548 Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1549 DALI_TEST_CHECK(visual2);
1551 DummyControl actor2 = DummyControl::New(true);
1552 DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1553 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1555 actor2.SetProperty(Actor::Property::SIZE, controlSize);
1557 application.GetScene().Add(actor2);
1559 application.SendNotification();
1560 application.Render();
1562 // Trigger count is 4 - load & render a frame for each instance
1563 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1565 DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1567 // To make event trigger
1568 actor2.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1570 application.SendNotification();
1571 application.Render();
1573 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1575 Property::Map attributes;
1576 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1578 DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1579 DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1581 DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1583 // renderer is added to actor
1584 DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1585 Renderer renderer1 = actor1.GetRendererAt(0u);
1586 DALI_TEST_CHECK(renderer1);
1588 // renderer is added to actor
1589 DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1590 Renderer renderer2 = actor2.GetRendererAt(0u);
1591 DALI_TEST_CHECK(renderer2);
1596 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1598 ToolkitTestApplication application;
1599 tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1601 Property::Map propertyMap;
1602 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1603 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1604 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1606 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1607 DALI_TEST_CHECK(visual);
1609 DummyControl actor = DummyControl::New(true);
1610 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1611 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1613 Vector2 controlSize(20.f, 30.f);
1614 actor.SetProperty(Actor::Property::SIZE, controlSize);
1616 application.GetScene().Add(actor);
1618 application.SendNotification();
1619 application.Render();
1621 // Trigger count is 2 - load & render a frame
1622 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1624 Property::Map attributes;
1625 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1627 application.SendNotification();
1628 application.Render();
1630 // Check rendering behavior
1631 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1632 Renderer renderer = actor.GetRendererAt(0u);
1633 DALI_TEST_CHECK(renderer);
1634 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1636 actor.SetProperty(Actor::Property::VISIBLE, false);
1638 application.SendNotification();
1639 application.Render();
1641 // Check rendering behavior again
1642 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1647 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1649 ToolkitTestApplication application;
1650 tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
1652 Property::Map propertyMap;
1653 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1654 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1656 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1657 DALI_TEST_CHECK(visual);
1659 DummyControl actor = DummyControl::New(true);
1660 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1661 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1663 Vector2 controlSize(20.f, 30.f);
1664 actor.SetProperty(Actor::Property::SIZE, controlSize);
1666 application.GetScene().Add(actor);
1668 application.SendNotification();
1669 application.Render();
1671 // Trigger count is 1 - render a frame
1672 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1674 Property::Map attributes;
1675 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1677 application.SendNotification();
1678 application.Render();
1680 // Check rendering behavior
1681 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1682 Renderer renderer = actor.GetRendererAt(0u);
1683 DALI_TEST_CHECK(renderer);
1684 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1686 Window window = DevelWindow::Get(actor);
1689 application.SendNotification();
1690 application.Render();
1692 // Check rendering behavior again
1693 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1698 int UtcDaliAnimatedVectorImageVisualInvalidFile01(void)
1700 ToolkitTestApplication application;
1701 tet_infoline("Request loading with invalid file - should draw broken image");
1703 TestGlAbstraction& gl = application.GetGlAbstraction();
1704 TraceCallStack& textureTrace = gl.GetTextureTrace();
1705 textureTrace.Enable(true);
1707 Property::Map propertyMap;
1708 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1709 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1710 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1712 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1713 DALI_TEST_CHECK(visual);
1715 DummyControl actor = DummyControl::New(true);
1716 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1717 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1719 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1721 application.GetScene().Add(actor);
1723 application.SendNotification();
1724 application.Render();
1726 // Trigger count is 1 - load
1727 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1729 application.SendNotification();
1730 application.Render();
1732 // Check resource status
1733 Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1734 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1736 // The broken image should be shown.
1737 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1738 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1743 int UtcDaliAnimatedVectorImageVisualInvalidFile02(void)
1745 ToolkitTestApplication application;
1746 tet_infoline("Request loading with invalid file - should draw broken image");
1748 TestGlAbstraction& gl = application.GetGlAbstraction();
1749 TraceCallStack& textureTrace = gl.GetTextureTrace();
1750 textureTrace.Enable(true);
1752 Property::Map propertyMap;
1753 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1754 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
1756 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1757 DALI_TEST_CHECK(visual);
1759 DummyControl actor = DummyControl::New(true);
1760 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1761 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1763 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1765 application.SendNotification();
1766 application.Render();
1768 // Add to the Scene after loading
1769 application.GetScene().Add(actor);
1771 application.SendNotification();
1772 application.Render();
1774 // Check resource status
1775 Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1776 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1778 // The broken image should be shown.
1779 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1780 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1785 int UtcDaliAnimatedVectorImageVisualInvalidFile03(void)
1787 ToolkitTestApplication application;
1788 tet_infoline("Request loading with invalid file without size set - should draw broken image");
1790 TestGlAbstraction& gl = application.GetGlAbstraction();
1791 TraceCallStack& textureTrace = gl.GetTextureTrace();
1792 textureTrace.Enable(true);
1794 Property::Map propertyMap;
1795 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1796 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1797 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1799 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1800 DALI_TEST_CHECK(visual);
1802 DummyControl actor = DummyControl::New(true);
1803 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1804 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1806 application.GetScene().Add(actor);
1808 application.SendNotification();
1809 application.Render();
1811 // Trigger count is 1 - load
1812 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1814 application.SendNotification();
1815 application.Render();
1817 // Check resource status
1818 Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1819 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1821 // The broken image should be shown.
1822 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1823 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1828 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
1830 ToolkitTestApplication application;
1831 tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
1833 Property::Map propertyMap;
1834 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1835 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP)
1836 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1838 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1839 DALI_TEST_CHECK(visual);
1841 DummyControl actor = DummyControl::New(true);
1842 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1843 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1845 Vector2 controlSize(20.f, 30.f);
1846 actor.SetProperty(Actor::Property::SIZE, controlSize);
1848 application.GetScene().Add(actor);
1850 application.SendNotification();
1851 application.Render();
1853 // Trigger count is 2 - load, render the first frame
1854 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1856 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1857 Property::Value* value = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1858 int totalFrameNumber = value->Get<int>();
1860 Property::Map attributes;
1861 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1863 // Make delay to drop frames
1864 Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
1866 application.SendNotification();
1867 application.Render();
1869 // Trigger count is 1 - calculating frame drops
1870 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1872 // Check dropped frame
1873 uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
1874 DALI_TEST_CHECK(frames > 0);
1875 DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
1880 int UtcDaliAnimatedVectorImageVisualSize(void)
1882 ToolkitTestApplication application;
1883 tet_infoline("UtcDaliAnimatedVectorImageVisualSize");
1885 TestGlAbstraction& gl = application.GetGlAbstraction();
1886 TraceCallStack& textureTrace = gl.GetTextureTrace();
1888 VisualFactory factory = VisualFactory::Get();
1889 Visual::Base visual = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
1890 DALI_TEST_CHECK(visual);
1892 DummyControl actor = DummyControl::New(true);
1893 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1894 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1896 application.GetScene().Add(actor);
1898 application.SendNotification();
1899 application.Render();
1901 // Trigger count is 1 - resource ready
1902 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1904 textureTrace.Enable(true);
1906 application.SendNotification();
1907 application.Render();
1910 int width = 100, height = 100; // 100x100 is the content default size.
1911 std::stringstream out;
1912 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1913 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1916 actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
1918 application.SendNotification();
1919 application.Render();
1921 // Trigger count is 1 - resource ready
1922 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1924 textureTrace.Reset();
1926 application.SendNotification();
1927 application.Render();
1930 int width = 200, height = 200;
1931 std::stringstream out;
1932 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1933 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1941 bool gDynamicPropertyCallbackFired = false;
1943 Property::Value FillColorCallback(int32_t id, VectorAnimationRenderer::VectorProperty property, uint32_t frameNumber)
1945 gDynamicPropertyCallbackFired = true;
1949 return Vector3(0, 0, 1);
1953 return Vector3(1, 0, 0);
1958 int UtcDaliAnimatedVectorImageVisualDynamicProperty(void)
1960 ToolkitTestApplication application;
1961 tet_infoline("UtcDaliAnimatedVectorImageVisualDynamicProperty");
1963 VisualFactory factory = VisualFactory::Get();
1964 Visual::Base visual = factory.CreateVisual(
1966 .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1967 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1968 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
1969 DALI_TEST_CHECK(visual);
1971 DummyControl actor = DummyControl::New(true);
1972 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1973 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1975 application.GetScene().Add(actor);
1977 gDynamicPropertyCallbackFired = false;
1979 // Set dynamic property
1980 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info;
1982 info.keyPath = "Test.Path";
1983 info.property = static_cast<int>(VectorAnimationRenderer::VectorProperty::FILL_COLOR);
1984 info.callback = MakeCallback(FillColorCallback);
1986 DevelControl::DoActionExtension(actor, DummyControl::Property::TEST_VISUAL, DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY, Any(info));
1988 Property::Map attributes;
1989 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1991 application.SendNotification();
1992 application.Render();
1994 // Trigger count is 2 - load & render a frame
1995 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1997 // Test whether the property callback is called
1998 DALI_TEST_EQUALS(gDynamicPropertyCallbackFired, true, TEST_LOCATION);
2003 int UtcDaliAnimatedVectorImageVisualDesiredSize(void)
2005 ToolkitTestApplication application;
2006 tet_infoline("UtcDaliAnimatedVectorImageVisualDesiredSize");
2008 TestGlAbstraction& gl = application.GetGlAbstraction();
2009 TraceCallStack& textureTrace = gl.GetTextureTrace();
2010 int desiredWidth = 150, desiredHeight = 200;
2012 Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
2013 DALI_TEST_CHECK(visual);
2015 DummyControl actor = DummyControl::New(true);
2016 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2017 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2019 application.GetScene().Add(actor);
2021 application.SendNotification();
2022 application.Render();
2024 // Trigger count is 1 - resource ready
2025 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2027 textureTrace.Enable(true);
2029 application.SendNotification();
2030 application.Render();
2033 std::stringstream out;
2034 out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2035 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2038 // Unparent to make next trigger
2041 application.SendNotification();
2042 application.Render();
2045 actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
2046 application.GetScene().Add(actor);
2048 application.SendNotification();
2049 application.Render();
2051 // Trigger count is 1 - resource ready
2052 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2054 textureTrace.Reset();
2056 application.SendNotification();
2057 application.Render();
2060 std::stringstream out;
2061 out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2062 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed