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 // Set 1 marker as array
842 Property::Array array;
843 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
845 Property::Map propertyMap;
846 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
847 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
848 .Add(DevelImageVisual::Property::PLAY_RANGE, array)
849 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
851 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
852 DALI_TEST_CHECK(visual);
854 DummyControl actor = DummyControl::New(true);
855 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
856 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
858 Vector2 controlSize(20.f, 30.f);
859 actor.SetProperty(Actor::Property::SIZE, controlSize);
861 application.GetScene().Add(actor);
863 Property::Map attributes;
864 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
866 application.SendNotification();
867 application.Render();
869 // Trigger count is 2 - load & render a frame
870 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
872 // renderer is added to actor
873 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
874 Renderer renderer = actor.GetRendererAt(0u);
875 DALI_TEST_CHECK(renderer);
877 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
878 Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
880 int resultStartFrame, resultEndFrame;
881 Property::Array* result = value->GetArray();
882 result->GetElementAt(0).Get(resultStartFrame);
883 result->GetElementAt(1).Get(resultEndFrame);
885 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
886 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
888 // Set 1 marker as string
892 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, VECTOR_ANIMATION_MARKER_NAME_1);
893 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
895 // To make event trigger
896 actor.SetProperty(Actor::Property::SIZE, Vector2(40.0f, 40.0f));
898 application.SendNotification();
899 application.Render();
901 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
903 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
904 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
906 result = value->GetArray();
907 result->GetElementAt(0).Get(resultStartFrame);
908 result->GetElementAt(1).Get(resultEndFrame);
910 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
911 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
915 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
916 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_2);
919 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
920 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
922 // To make event trigger
923 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
925 application.SendNotification();
926 application.Render();
928 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
930 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
931 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
933 result = value->GetArray();
934 result->GetElementAt(0).Get(resultStartFrame);
935 result->GetElementAt(1).Get(resultEndFrame);
937 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
938 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
940 // Set invalid play range
943 array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
946 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
947 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
949 // To make event trigger
950 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
952 application.SendNotification();
953 application.Render();
955 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
957 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
958 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
960 result = value->GetArray();
961 result->GetElementAt(0).Get(resultStartFrame);
962 result->GetElementAt(1).Get(resultEndFrame);
964 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION); // Should not be changed
965 DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
970 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
972 ToolkitTestApplication application;
973 tet_infoline("UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal");
975 Property::Map propertyMap;
976 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
977 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
978 .Add(DevelImageVisual::Property::LOOP_COUNT, 3);
980 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
981 DALI_TEST_CHECK(visual);
983 DummyControl actor = DummyControl::New(true);
984 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
985 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
987 DevelControl::VisualEventSignal(actor).Connect(&VisualEventSignal);
989 Vector2 controlSize(20.f, 30.f);
990 actor.SetProperty(Actor::Property::SIZE, controlSize);
992 application.GetScene().Add(actor);
994 Property::Map attributes;
995 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
997 application.SendNotification();
998 application.Render();
1000 // Wait for animation finish - render, finish
1001 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1003 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1004 Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
1005 DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
1007 DALI_TEST_EQUALS(gAnimationFinishedSignalFired, true, TEST_LOCATION);
1012 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
1014 ToolkitTestApplication application;
1015 tet_infoline("UtcDaliAnimatedVectorImageVisualJumpTo");
1017 Property::Map propertyMap;
1018 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1019 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1020 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1021 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1023 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1024 DALI_TEST_CHECK(visual);
1026 tet_printf("1. Visual is created.\n");
1028 DummyControl actor = DummyControl::New(true);
1029 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1030 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1032 Vector2 controlSize(20.f, 30.f);
1033 actor.SetProperty(Actor::Property::SIZE, controlSize);
1035 application.GetScene().Add(actor);
1037 application.SendNotification();
1038 application.Render();
1040 // Trigger count is 2 - load & render a frame
1041 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1043 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2);
1045 // To make event trigger
1046 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1048 application.SendNotification();
1049 application.Render();
1051 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1053 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1054 Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1055 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1057 tet_printf("2. The current frame number is [%d].\n", value->Get<int>());
1059 Property::Array array;
1063 Property::Map attributes;
1064 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1065 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1067 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1069 // To make event trigger
1070 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1072 application.SendNotification();
1073 application.Render();
1075 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1077 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1078 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1079 DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1081 tet_printf("3. The current frame number is [%d].\n", value->Get<int>());
1083 // Change play range
1090 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1091 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1094 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1096 application.SendNotification();
1097 application.Render();
1099 // Wait for animation finish
1100 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1103 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1105 // To make event trigger
1106 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1108 application.SendNotification();
1109 application.Render();
1111 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1113 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1114 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1115 DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1117 tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1119 // Jump to the same position
1120 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1122 // To make event trigger
1123 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1125 application.SendNotification();
1126 application.Render();
1128 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1130 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1131 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1132 DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1134 tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1139 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1141 ToolkitTestApplication application;
1142 tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1144 int startFrame = 1, endFrame = 3;
1145 Property::Array playRange;
1146 playRange.PushBack(startFrame);
1147 playRange.PushBack(endFrame);
1149 Property::Map propertyMap;
1150 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1151 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1152 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1153 .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
1154 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1156 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1157 DALI_TEST_CHECK(visual);
1159 DummyControl actor = DummyControl::New(true);
1160 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1161 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1163 Vector2 controlSize(20.f, 30.f);
1164 actor.SetProperty(Actor::Property::SIZE, controlSize);
1166 application.GetScene().Add(actor);
1168 application.SendNotification();
1169 application.Render();
1171 // Trigger count is 2 - load & render a frame
1172 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1174 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1175 Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1176 DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1178 value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1179 DALI_TEST_CHECK(value);
1181 Property::Array* result = value->GetArray();
1182 DALI_TEST_CHECK(result);
1184 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1185 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1188 playRange.PushBack(0);
1189 playRange.PushBack(2);
1191 Property::Map attributes;
1192 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1193 attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1195 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1197 // To make event trigger
1198 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1200 application.SendNotification();
1201 application.Render();
1203 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1205 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1206 value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1207 DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1209 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1210 result = value->GetArray();
1211 DALI_TEST_CHECK(result);
1213 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1214 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1219 playRange.PushBack(startFrame);
1220 playRange.PushBack(endFrame);
1222 attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1224 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1226 // To make event trigger
1227 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1229 application.SendNotification();
1230 application.Render();
1232 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1234 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1235 value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1237 result = value->GetArray();
1238 DALI_TEST_CHECK(result);
1240 DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1241 DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1243 // Play and update property
1245 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1247 application.SendNotification();
1248 application.Render();
1250 attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1252 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1254 application.SendNotification();
1255 application.Render();
1257 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1258 value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1259 DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1264 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1266 ToolkitTestApplication application;
1267 tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1269 Property::Map propertyMap;
1270 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1271 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1272 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1273 .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME)
1274 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1276 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1277 DALI_TEST_CHECK(visual);
1279 DummyControl actor = DummyControl::New(true);
1280 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1281 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1283 Vector2 controlSize(20.f, 30.f);
1284 actor.SetProperty(Actor::Property::SIZE, controlSize);
1286 application.GetScene().Add(actor);
1288 Property::Map attributes;
1289 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1291 application.SendNotification();
1292 application.Render();
1294 // Trigger count is 3 - load, render, animation finished
1295 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1297 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1298 Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1299 DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1301 // Change stop behavior
1302 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1304 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1309 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1311 application.SendNotification();
1312 application.Render();
1314 // Trigger count is 1 - animation finished
1315 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1317 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1319 Property::Value* value1 = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1320 int totalFrameNumber = value1->Get<int>();
1322 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1323 DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1325 // Change stop behavior
1326 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1327 attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1329 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1334 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1336 application.SendNotification();
1337 application.Render();
1340 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1342 // To make event trigger
1343 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1345 application.SendNotification();
1346 application.Render();
1348 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1350 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1351 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1352 int currentFrameNumber = value->Get<int>();
1355 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1357 // To make event trigger
1358 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1360 application.SendNotification();
1361 application.Render();
1363 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1365 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1366 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1367 DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1372 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1374 ToolkitTestApplication application;
1375 tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
1377 Property::Map propertyMap;
1378 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1379 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1380 .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1381 .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME)
1382 .Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE)
1383 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1385 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1386 DALI_TEST_CHECK(visual);
1388 DummyControl actor = DummyControl::New(true);
1389 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1390 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1392 Vector2 controlSize(20.f, 30.f);
1393 actor.SetProperty(Actor::Property::SIZE, controlSize);
1395 application.GetScene().Add(actor);
1397 Property::Map attributes;
1398 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1400 application.SendNotification();
1401 application.Render();
1403 // Trigger count is 3 - load, render, animation finished
1404 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1406 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1407 Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1408 DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1410 // Change stop behavior
1411 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1413 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1416 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1418 application.SendNotification();
1419 application.Render();
1421 // Trigger count is 1 - animation finished
1422 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1424 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1425 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1426 DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1428 // Change looping mode
1429 attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1431 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1434 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1436 application.SendNotification();
1437 application.Render();
1439 // Trigger count is 1 - animation finished
1440 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1442 Property::Value* value1 = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1443 int totalFrameNumber = value1->Get<int>();
1445 map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1446 value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1447 DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1452 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1454 ToolkitTestApplication application;
1455 tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1457 Property::Map propertyMap;
1458 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1459 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1461 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1462 DALI_TEST_CHECK(visual);
1464 DummyControl actor = DummyControl::New(true);
1465 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1466 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1467 actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1469 application.GetScene().Add(actor);
1471 application.SendNotification();
1472 application.Render();
1474 // Trigger count is 1 - render a frame
1475 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1477 Renderer renderer = actor.GetRendererAt(0u);
1478 DALI_TEST_CHECK(renderer);
1480 Vector2 controlSize(20.f, 30.f);
1481 actor.SetProperty(Actor::Property::SIZE, controlSize);
1483 application.SendNotification();
1484 application.Render();
1486 application.SendNotification();
1487 application.Render();
1489 // Trigger count is 1 - render a frame
1490 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1492 auto textureSet = renderer.GetTextures();
1493 auto texture = textureSet.GetTexture(0);
1495 DALI_TEST_EQUALS(controlSize.width, texture.GetWidth(), TEST_LOCATION);
1496 DALI_TEST_EQUALS(controlSize.height, texture.GetHeight(), TEST_LOCATION);
1499 Vector3 controlScale(2.0f, 2.0f, 1.0f);
1500 actor.SetProperty(Actor::Property::SCALE, controlScale);
1502 application.SendNotification();
1503 application.Render();
1505 application.SendNotification();
1506 application.Render();
1508 // Trigger count is 1 - render a frame
1509 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1511 renderer = actor.GetRendererAt(0u);
1512 DALI_TEST_CHECK(renderer);
1514 textureSet = renderer.GetTextures();
1515 texture = textureSet.GetTexture(0);
1517 DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1518 DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1521 controlSize = Vector2(50.0f, 100.0f);
1522 Animation animation = Animation::New(1.0);
1523 animation.AnimateTo(Property(actor, Actor::Property::SIZE), Vector3(controlSize.x, controlSize.y, 0.0f));
1526 application.SendNotification();
1527 application.Render(1100); // After the animation
1529 application.SendNotification();
1530 application.Render();
1532 // Trigger count is 1 - render a frame
1533 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1535 renderer = actor.GetRendererAt(0u);
1536 DALI_TEST_CHECK(renderer);
1538 textureSet = renderer.GetTextures();
1539 texture = textureSet.GetTexture(0);
1541 DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1542 DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1547 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1549 ToolkitTestApplication application;
1550 tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1552 Property::Map propertyMap;
1553 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1554 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1555 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1557 Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1558 DALI_TEST_CHECK(visual1);
1560 DummyControl actor1 = DummyControl::New(true);
1561 DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1562 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1564 Vector2 controlSize(20.f, 30.f);
1565 actor1.SetProperty(Actor::Property::SIZE, controlSize);
1567 application.GetScene().Add(actor1);
1569 propertyMap.Clear();
1570 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1571 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1572 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1574 Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1575 DALI_TEST_CHECK(visual2);
1577 DummyControl actor2 = DummyControl::New(true);
1578 DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1579 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1581 actor2.SetProperty(Actor::Property::SIZE, controlSize);
1583 application.GetScene().Add(actor2);
1585 application.SendNotification();
1586 application.Render();
1588 // Trigger count is 4 - load & render a frame for each instance
1589 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1591 DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1593 // To make event trigger
1594 actor2.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1596 application.SendNotification();
1597 application.Render();
1599 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1601 Property::Map attributes;
1602 attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1604 DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1605 DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1607 DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1609 // renderer is added to actor
1610 DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1611 Renderer renderer1 = actor1.GetRendererAt(0u);
1612 DALI_TEST_CHECK(renderer1);
1614 // renderer is added to actor
1615 DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1616 Renderer renderer2 = actor2.GetRendererAt(0u);
1617 DALI_TEST_CHECK(renderer2);
1622 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1624 ToolkitTestApplication application;
1625 tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1627 Property::Map propertyMap;
1628 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1629 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1630 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1632 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1633 DALI_TEST_CHECK(visual);
1635 DummyControl actor = DummyControl::New(true);
1636 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1637 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1639 Vector2 controlSize(20.f, 30.f);
1640 actor.SetProperty(Actor::Property::SIZE, controlSize);
1642 application.GetScene().Add(actor);
1644 application.SendNotification();
1645 application.Render();
1647 // Trigger count is 2 - load & render a frame
1648 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1650 Property::Map attributes;
1651 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1653 application.SendNotification();
1654 application.Render();
1656 // Check rendering behavior
1657 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1658 Renderer renderer = actor.GetRendererAt(0u);
1659 DALI_TEST_CHECK(renderer);
1660 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1662 actor.SetProperty(Actor::Property::VISIBLE, false);
1664 application.SendNotification();
1665 application.Render();
1667 // Check rendering behavior again
1668 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1673 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1675 ToolkitTestApplication application;
1676 tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
1678 Property::Map propertyMap;
1679 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1680 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1682 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1683 DALI_TEST_CHECK(visual);
1685 DummyControl actor = DummyControl::New(true);
1686 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1687 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1689 Vector2 controlSize(20.f, 30.f);
1690 actor.SetProperty(Actor::Property::SIZE, controlSize);
1692 application.GetScene().Add(actor);
1694 application.SendNotification();
1695 application.Render();
1697 // Trigger count is 1 - render a frame
1698 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1700 Property::Map attributes;
1701 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1703 application.SendNotification();
1704 application.Render();
1706 // Check rendering behavior
1707 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1708 Renderer renderer = actor.GetRendererAt(0u);
1709 DALI_TEST_CHECK(renderer);
1710 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1712 Window window = DevelWindow::Get(actor);
1715 application.SendNotification();
1716 application.Render();
1718 // Check rendering behavior again
1719 DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1724 int UtcDaliAnimatedVectorImageVisualInvalidFile01(void)
1726 ToolkitTestApplication application;
1727 tet_infoline("Request loading with invalid file - should draw broken image");
1729 TestGlAbstraction& gl = application.GetGlAbstraction();
1730 TraceCallStack& textureTrace = gl.GetTextureTrace();
1731 textureTrace.Enable(true);
1733 Property::Map propertyMap;
1734 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1735 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1736 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1738 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1739 DALI_TEST_CHECK(visual);
1741 DummyControl actor = DummyControl::New(true);
1742 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1743 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1745 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1747 application.GetScene().Add(actor);
1749 application.SendNotification();
1750 application.Render();
1752 // Trigger count is 1 - load
1753 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1755 application.SendNotification();
1756 application.Render();
1758 // Check resource status
1759 Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1760 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1762 // The broken image should be shown.
1763 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1764 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1769 int UtcDaliAnimatedVectorImageVisualInvalidFile02(void)
1771 ToolkitTestApplication application;
1772 tet_infoline("Request loading with invalid file - should draw broken image");
1774 TestGlAbstraction& gl = application.GetGlAbstraction();
1775 TraceCallStack& textureTrace = gl.GetTextureTrace();
1776 textureTrace.Enable(true);
1778 Property::Map propertyMap;
1779 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1780 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
1782 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1783 DALI_TEST_CHECK(visual);
1785 DummyControl actor = DummyControl::New(true);
1786 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1787 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1789 actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1791 application.SendNotification();
1792 application.Render();
1794 // Add to the Scene after loading
1795 application.GetScene().Add(actor);
1797 application.SendNotification();
1798 application.Render();
1800 // Check resource status
1801 Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1802 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1804 // The broken image should be shown.
1805 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1806 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1811 int UtcDaliAnimatedVectorImageVisualInvalidFile03(void)
1813 ToolkitTestApplication application;
1814 tet_infoline("Request loading with invalid file without size set - should draw broken image");
1816 TestGlAbstraction& gl = application.GetGlAbstraction();
1817 TraceCallStack& textureTrace = gl.GetTextureTrace();
1818 textureTrace.Enable(true);
1820 Property::Map propertyMap;
1821 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1822 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1823 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1825 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1826 DALI_TEST_CHECK(visual);
1828 DummyControl actor = DummyControl::New(true);
1829 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1830 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1832 application.GetScene().Add(actor);
1834 application.SendNotification();
1835 application.Render();
1837 // Trigger count is 1 - load
1838 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1840 application.SendNotification();
1841 application.Render();
1843 // Check resource status
1844 Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1845 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1847 // The broken image should be shown.
1848 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1849 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1854 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
1856 ToolkitTestApplication application;
1857 tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
1859 Property::Map propertyMap;
1860 propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1861 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP)
1862 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1864 Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1865 DALI_TEST_CHECK(visual);
1867 DummyControl actor = DummyControl::New(true);
1868 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1869 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1871 Vector2 controlSize(20.f, 30.f);
1872 actor.SetProperty(Actor::Property::SIZE, controlSize);
1874 application.GetScene().Add(actor);
1876 application.SendNotification();
1877 application.Render();
1879 // Trigger count is 2 - load, render the first frame
1880 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1882 Property::Map map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1883 Property::Value* value = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1884 int totalFrameNumber = value->Get<int>();
1886 Property::Map attributes;
1887 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1889 // Make delay to drop frames
1890 Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
1892 application.SendNotification();
1893 application.Render();
1895 // Trigger count is 1 - calculating frame drops
1896 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1898 // Check dropped frame
1899 uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
1900 DALI_TEST_CHECK(frames > 0);
1901 DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
1906 int UtcDaliAnimatedVectorImageVisualSize(void)
1908 ToolkitTestApplication application;
1909 tet_infoline("UtcDaliAnimatedVectorImageVisualSize");
1911 TestGlAbstraction& gl = application.GetGlAbstraction();
1912 TraceCallStack& textureTrace = gl.GetTextureTrace();
1914 VisualFactory factory = VisualFactory::Get();
1915 Visual::Base visual = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
1916 DALI_TEST_CHECK(visual);
1918 DummyControl actor = DummyControl::New(true);
1919 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1920 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1922 application.GetScene().Add(actor);
1924 application.SendNotification();
1925 application.Render();
1927 // Trigger count is 1 - resource ready
1928 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1930 textureTrace.Enable(true);
1932 application.SendNotification();
1933 application.Render();
1936 int width = 100, height = 100; // 100x100 is the content default size.
1937 std::stringstream out;
1938 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1939 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1942 actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
1944 application.SendNotification();
1945 application.Render();
1947 // Trigger count is 1 - resource ready
1948 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1950 textureTrace.Reset();
1952 application.SendNotification();
1953 application.Render();
1956 int width = 200, height = 200;
1957 std::stringstream out;
1958 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1959 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1967 bool gDynamicPropertyCallbackFired = false;
1969 Property::Value FillColorCallback(int32_t id, VectorAnimationRenderer::VectorProperty property, uint32_t frameNumber)
1971 gDynamicPropertyCallbackFired = true;
1975 return Vector3(0, 0, 1);
1979 return Vector3(1, 0, 0);
1984 int UtcDaliAnimatedVectorImageVisualDynamicProperty(void)
1986 ToolkitTestApplication application;
1987 tet_infoline("UtcDaliAnimatedVectorImageVisualDynamicProperty");
1989 VisualFactory factory = VisualFactory::Get();
1990 Visual::Base visual = factory.CreateVisual(
1992 .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1993 .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1994 .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
1995 DALI_TEST_CHECK(visual);
1997 DummyControl actor = DummyControl::New(true);
1998 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1999 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2001 Vector2 controlSize(20.f, 30.f);
2002 actor.SetProperty(Actor::Property::SIZE, controlSize);
2004 application.GetScene().Add(actor);
2006 gDynamicPropertyCallbackFired = false;
2008 // Set dynamic property
2009 DevelAnimatedVectorImageVisual::DynamicPropertyInfo info;
2011 info.keyPath = "Test.Path";
2012 info.property = static_cast<int>(VectorAnimationRenderer::VectorProperty::FILL_COLOR);
2013 info.callback = MakeCallback(FillColorCallback);
2015 DevelControl::DoActionExtension(actor, DummyControl::Property::TEST_VISUAL, DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY, Any(info));
2017 Property::Map attributes;
2018 DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2020 application.SendNotification();
2021 application.Render();
2023 // Trigger count is 2 - load & render a frame
2024 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2026 // Test whether the property callback is called
2027 DALI_TEST_EQUALS(gDynamicPropertyCallbackFired, true, TEST_LOCATION);
2032 int UtcDaliAnimatedVectorImageVisualDesiredSize(void)
2034 ToolkitTestApplication application;
2035 tet_infoline("UtcDaliAnimatedVectorImageVisualDesiredSize");
2037 TestGlAbstraction& gl = application.GetGlAbstraction();
2038 TraceCallStack& textureTrace = gl.GetTextureTrace();
2039 int desiredWidth = 150, desiredHeight = 200;
2041 Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
2042 DALI_TEST_CHECK(visual);
2044 DummyControl actor = DummyControl::New(true);
2045 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2046 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2048 application.GetScene().Add(actor);
2050 application.SendNotification();
2051 application.Render();
2053 // Trigger count is 1 - resource ready
2054 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2056 textureTrace.Enable(true);
2058 application.SendNotification();
2059 application.Render();
2062 std::stringstream out;
2063 out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2064 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2067 // Unparent to make next trigger
2070 application.SendNotification();
2071 application.Render();
2074 actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
2075 application.GetScene().Add(actor);
2077 application.SendNotification();
2078 application.Render();
2080 // Trigger count is 1 - resource ready
2081 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2083 textureTrace.Reset();
2085 application.SendNotification();
2086 application.Render();
2089 std::stringstream out;
2090 out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2091 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed