2 * Copyright (c) 2021 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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/common/stage.h>
20 #include <dali/integration-api/events/key-event-integ.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/wheel-event-integ.h>
23 #include <dali/integration-api/scene.h>
24 #include <dali/public-api/events/key-event.h>
25 #include <mesh-builder.h>
30 // Internal headers are allowed here
34 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
36 // Functor for EventProcessingFinished signal
37 struct EventProcessingFinishedFunctor
40 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
42 EventProcessingFinishedFunctor(bool& eventProcessingFinished)
43 : mEventProcessingFinished(eventProcessingFinished)
49 mEventProcessingFinished = true;
52 bool& mEventProcessingFinished;
55 // Stores data that is populated in the key-event callback and will be read by the TET cases
56 struct KeyEventSignalData
59 : functorCalled(false)
65 functorCalled = false;
67 receivedKeyEvent.Reset();
71 KeyEvent receivedKeyEvent;
74 // Functor that sets the data when called
75 struct KeyEventReceivedFunctor
77 KeyEventReceivedFunctor(KeyEventSignalData& data)
82 bool operator()(const KeyEvent& keyEvent)
84 signalData.functorCalled = true;
85 signalData.receivedKeyEvent = keyEvent;
90 KeyEventSignalData& signalData;
93 // Stores data that is populated in the touched signal callback and will be read by the TET cases
94 struct TouchedSignalData
97 : functorCalled(false),
98 createNewScene(false),
99 newSceneCreated(false)
105 functorCalled = false;
106 createNewScene = false;
107 newSceneCreated = false;
108 receivedTouchEvent.Reset();
113 bool newSceneCreated;
114 TouchEvent receivedTouchEvent;
117 // Functor that sets the data when touched signal is received
120 TouchFunctor(TouchedSignalData& data)
125 void operator()(const TouchEvent& touch)
127 signalData.functorCalled = true;
128 signalData.receivedTouchEvent = touch;
130 if(signalData.createNewScene)
132 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
133 DALI_TEST_CHECK(scene);
135 signalData.newSceneCreated = true;
141 signalData.functorCalled = true;
144 TouchedSignalData& signalData;
147 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
148 struct WheelEventSignalData
150 WheelEventSignalData()
151 : functorCalled(false)
157 functorCalled = false;
161 WheelEvent receivedWheelEvent;
164 // Functor that sets the data when wheel-event signal is received
165 struct WheelEventReceivedFunctor
167 WheelEventReceivedFunctor(WheelEventSignalData& data)
172 bool operator()(const WheelEvent& wheelEvent)
174 signalData.functorCalled = true;
175 signalData.receivedWheelEvent = wheelEvent;
180 WheelEventSignalData& signalData;
183 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
184 struct KeyEventGeneratedSignalData
186 KeyEventGeneratedSignalData()
187 : functorCalled(false)
193 functorCalled = false;
195 receivedKeyEvent.Reset();
199 KeyEvent receivedKeyEvent;
202 // Functor that sets the data when called
203 struct KeyEventGeneratedReceivedFunctor
205 KeyEventGeneratedReceivedFunctor(KeyEventGeneratedSignalData& data)
210 bool operator()(const KeyEvent& keyEvent)
212 signalData.functorCalled = true;
213 signalData.receivedKeyEvent = keyEvent;
220 signalData.functorCalled = true;
224 KeyEventGeneratedSignalData& signalData;
227 void GenerateTouch(TestApplication& application, PointState::Type state, const Vector2& screenPosition)
229 Integration::TouchEvent touchEvent;
230 Integration::Point point;
231 point.SetState(state);
232 point.SetScreenPosition(screenPosition);
233 touchEvent.points.push_back(point);
234 application.ProcessEvent(touchEvent);
237 bool DummyTouchCallback(Actor actor, const TouchEvent& touch)
242 void FrameCallback(int frameId)
246 } // unnamed namespace
248 int UtcDaliSceneAdd(void)
250 TestApplication application;
251 tet_infoline("Testing Dali::Integration::Scene::Add");
253 Dali::Integration::Scene scene = application.GetScene();
255 Actor actor = Actor::New();
256 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
259 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
264 int UtcDaliSceneRemove(void)
266 TestApplication application;
267 tet_infoline("Testing Dali::Integration::Scene::Remove");
269 Dali::Integration::Scene scene = application.GetScene();
271 Actor actor = Actor::New();
272 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
275 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
278 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
283 int UtcDaliSceneGetSize(void)
285 TestApplication application;
286 tet_infoline("Testing Dali::Integration::Scene::GetSize");
288 Dali::Integration::Scene scene = application.GetScene();
289 Size size = scene.GetSize();
290 DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION);
291 DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION);
296 int UtcDaliSceneGetDpi(void)
298 TestApplication application; // Initializes core DPI to default values
300 // Test that setting core DPI explicitly also sets up the scene's DPI.
301 Dali::Integration::Scene scene = application.GetScene();
302 scene.SetDpi(Vector2(200.0f, 180.0f));
303 Vector2 dpi = scene.GetDpi();
304 DALI_TEST_EQUALS(dpi.x, 200.0f, TEST_LOCATION);
305 DALI_TEST_EQUALS(dpi.y, 180.0f, TEST_LOCATION);
309 int UtcDaliSceneGetRenderTaskList(void)
311 TestApplication application;
312 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
314 Dali::Integration::Scene scene = application.GetScene();
316 // Check we get a valid instance.
317 const RenderTaskList& tasks = scene.GetRenderTaskList();
319 // There should be 1 task by default.
320 DALI_TEST_EQUALS(tasks.GetTaskCount(), 1u, TEST_LOCATION);
322 // RenderTaskList has it's own UTC tests.
323 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
324 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
326 DALI_TEST_EQUALS(scene.GetRenderTaskList().GetTask(1), newTask, TEST_LOCATION);
331 int UtcDaliSceneGetRootLayer(void)
333 TestApplication application;
334 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
336 Dali::Integration::Scene scene = application.GetScene();
337 Layer layer = scene.GetLayer(0);
338 DALI_TEST_CHECK(layer);
340 // Check that GetRootLayer() correctly retreived layer 0.
341 DALI_TEST_CHECK(scene.GetRootLayer() == layer);
346 int UtcDaliSceneGetLayerCount(void)
348 TestApplication application;
349 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
351 Dali::Integration::Scene scene = application.GetScene();
352 // Initially we have a default layer
353 DALI_TEST_EQUALS(scene.GetLayerCount(), 1u, TEST_LOCATION);
355 Layer layer = Layer::New();
358 DALI_TEST_EQUALS(scene.GetLayerCount(), 2u, TEST_LOCATION);
362 int UtcDaliSceneGetLayer(void)
364 TestApplication application;
365 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
367 Dali::Integration::Scene scene = application.GetScene();
369 Layer rootLayer = scene.GetLayer(0);
370 DALI_TEST_CHECK(rootLayer);
372 Layer layer = Layer::New();
375 Layer sameLayer = scene.GetLayer(1);
376 DALI_TEST_CHECK(layer == sameLayer);
381 int UtcDaliSceneGet(void)
383 TestApplication application;
384 tet_infoline("Testing Dali::Integration::Scene::Get");
386 Dali::Integration::Scene scene = application.GetScene();
388 Actor actor = Actor::New();
389 DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(actor));
393 DALI_TEST_CHECK(scene == Dali::Integration::Scene::Get(actor));
398 int UtcDaliSceneDiscard(void)
400 TestApplication application;
401 tet_infoline("Testing Dali::Scene::Discard");
403 // Create a new Scene
404 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
405 DALI_TEST_CHECK(scene);
407 // One reference of scene kept here and the other one kept in the Core
408 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
410 // Render and notify.
411 application.SendNotification();
412 application.Render(0);
414 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
415 Layer rootLayer = scene.GetRootLayer();
416 DALI_TEST_CHECK(rootLayer);
417 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
419 // Request to discard the scene from the Core
421 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
423 // Reset the scene handle
426 // Render and notify.
427 application.SendNotification();
428 application.Render(0);
430 // At this point, the scene should have been automatically deleted
431 // To prove this, the ref count of the root layer handle should be decremented to 1
432 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
434 // Delete the root layer handle
437 // Render and notify.
438 application.SendNotification();
439 application.Render(0);
444 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
446 TestApplication application;
448 Dali::Integration::Scene scene = application.GetScene();
450 TouchedSignalData data;
451 data.createNewScene = true;
452 TouchFunctor functor(data);
453 scene.TouchedSignal().Connect(&application, functor);
455 // Render and notify.
456 application.SendNotification();
457 application.Render();
459 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
461 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462 DALI_TEST_EQUALS(true, data.createNewScene, TEST_LOCATION);
463 DALI_TEST_EQUALS(true, data.newSceneCreated, TEST_LOCATION);
469 int UtcDaliSceneRootLayerAndSceneAlignment(void)
471 TestApplication application;
474 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
475 DALI_TEST_CHECK(scene);
477 // One reference of scene kept here and the other one kept in the Core
478 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
480 // Add a renderable actor to the scene
481 auto actor = CreateRenderableActor();
484 // Render and notify.
485 application.SendNotification();
486 application.Render(0);
488 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
489 Layer rootLayer = scene.GetRootLayer();
490 DALI_TEST_CHECK(rootLayer);
491 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
493 // Request to discard the scene from the Core
495 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
497 // Reset the scene handle
500 // Render and notify.
501 application.SendNotification();
502 application.Render(0);
504 // At this point, the scene should have been automatically deleted
505 // To prove this, the ref count of the root layer handle should be decremented to 1
506 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
508 // Create a new Scene while the root layer of the deleted scene is still alive
509 Dali::Integration::Scene newScene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
510 DALI_TEST_CHECK(newScene);
512 // Render and notify.
513 application.SendNotification();
514 application.Render(0);
516 // At this point, we have only one scene but two root layers
517 // The root layer of the deleted scene is still alive
518 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
520 // Delete the root layer of the deleted scene
523 // Render and notify.
524 application.SendNotification();
525 application.Render(0);
530 int UtcDaliSceneEventProcessingFinishedP(void)
532 TestApplication application;
533 Dali::Integration::Scene scene = application.GetScene();
535 bool eventProcessingFinished = false;
536 EventProcessingFinishedFunctor functor(eventProcessingFinished);
537 scene.EventProcessingFinishedSignal().Connect(&application, functor);
539 Actor actor(Actor::New());
542 application.SendNotification();
543 application.Render();
545 DALI_TEST_CHECK(eventProcessingFinished);
550 int UtcDaliSceneEventProcessingFinishedN(void)
552 TestApplication application;
553 Dali::Integration::Scene scene = application.GetScene();
555 bool eventProcessingFinished = false;
556 EventProcessingFinishedFunctor functor(eventProcessingFinished);
557 scene.EventProcessingFinishedSignal().Connect(&application, functor);
559 Actor actor(Actor::New());
562 // Do not complete event processing and confirm the signal has not been emitted.
563 DALI_TEST_CHECK(!eventProcessingFinished);
568 int UtcDaliSceneSignalKeyEventP(void)
570 TestApplication application;
571 Dali::Integration::Scene scene = application.GetScene();
573 KeyEventSignalData data;
574 KeyEventReceivedFunctor functor(data);
575 scene.KeyEventSignal().Connect(&application, functor);
577 Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
578 application.ProcessEvent(event);
580 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
581 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
582 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
583 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
584 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
588 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
589 application.ProcessEvent(event2);
591 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
592 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
593 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
594 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
595 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
599 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
600 application.ProcessEvent(event3);
602 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
603 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
604 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
605 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
606 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
610 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
611 application.ProcessEvent(event4);
613 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
614 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
615 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
616 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
617 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
621 int UtcDaliSceneSignalKeyEventN(void)
623 TestApplication application;
624 Dali::Integration::Scene scene = application.GetScene();
626 KeyEventSignalData data;
627 KeyEventReceivedFunctor functor(data);
628 scene.KeyEventSignal().Connect(&application, functor);
630 // Check that a non-pressed key events data is not modified.
631 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
636 int UtcDaliSceneTouchedSignalP(void)
638 TestApplication application;
639 Dali::Integration::Scene scene = application.GetScene();
641 TouchedSignalData data;
642 TouchFunctor functor(data);
643 scene.TouchedSignal().Connect(&application, functor);
645 // Render and notify.
646 application.SendNotification();
647 application.Render();
649 // Basic test: No actors, single touch (down then up).
651 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
653 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
654 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
655 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
658 GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f));
660 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
661 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
662 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
666 // Add an actor to the scene.
667 Actor actor = Actor::New();
668 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
669 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
670 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
671 actor.TouchedSignal().Connect(&DummyTouchCallback);
674 // Render and notify.
675 application.SendNotification();
676 application.Render();
678 // Actor on scene, single touch, down in actor, motion, then up outside actor.
680 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
682 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
683 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
684 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
687 GenerateTouch(application, PointState::MOTION, Vector2(150.0f, 10.0f)); // Some motion
689 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
692 GenerateTouch(application, PointState::UP, Vector2(150.0f, 10.0f)); // Some motion
694 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
696 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
700 // Multiple touch. Should only receive a touch on first down and last up.
702 Integration::TouchEvent touchEvent;
703 Integration::Point point;
706 point.SetState(PointState::DOWN);
707 point.SetScreenPosition(Vector2(10.0f, 10.0f));
708 touchEvent.points.push_back(point);
709 application.ProcessEvent(touchEvent);
710 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
711 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
715 touchEvent.points[0].SetState(PointState::STATIONARY);
716 point.SetDeviceId(1);
717 point.SetScreenPosition(Vector2(50.0f, 50.0f));
718 touchEvent.points.push_back(point);
719 application.ProcessEvent(touchEvent);
720 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
723 // Primary point is up
724 touchEvent.points[0].SetState(PointState::UP);
725 touchEvent.points[1].SetState(PointState::STATIONARY);
726 application.ProcessEvent(touchEvent);
727 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
730 // Remove 1st point now, 2nd point is now in motion
731 touchEvent.points.erase(touchEvent.points.begin());
732 touchEvent.points[0].SetState(PointState::MOTION);
733 touchEvent.points[0].SetScreenPosition(Vector2(150.0f, 50.0f));
734 application.ProcessEvent(touchEvent);
735 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
739 touchEvent.points[0].SetState(PointState::UP);
740 application.ProcessEvent(touchEvent);
741 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
742 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
748 int UtcDaliSceneTouchedSignalN(void)
750 TestApplication application;
751 Dali::Integration::Scene scene = application.GetScene();
753 TouchedSignalData data;
754 TouchFunctor functor(data);
755 scene.TouchedSignal().Connect(&application, functor);
757 // Render and notify.
758 application.SendNotification();
759 application.Render();
761 // Confirm functor not called before there has been any touch event.
762 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
764 // No actors, single touch, down, motion then up.
766 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
768 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
769 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
770 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
774 // Confirm there is no signal when the touchpoint is only moved.
775 GenerateTouch(application, PointState::MOTION, Vector2(1200.0f, 10.0f)); // Some motion
777 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
780 // Confirm a following up event generates a signal.
781 GenerateTouch(application, PointState::UP, Vector2(1200.0f, 10.0f));
783 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
784 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
785 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
789 // Add an actor to the scene.
790 Actor actor = Actor::New();
791 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
792 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
793 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
794 actor.TouchedSignal().Connect(&DummyTouchCallback);
797 // Render and notify.
798 application.SendNotification();
799 application.Render();
801 // Actor on scene. Interrupted before down and interrupted after down.
803 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
805 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
806 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
807 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
808 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
811 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
813 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
814 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
815 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
816 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::DOWN);
819 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
821 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
822 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
823 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
824 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
826 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
828 // Check that getting info about a non-existent point returns an empty handle
829 Actor actor = data.receivedTouchEvent.GetHitActor(1);
830 DALI_TEST_CHECK(!actor);
838 int UtcDaliSceneSignalWheelEventP(void)
840 TestApplication application;
841 Dali::Integration::Scene scene = application.GetScene();
843 WheelEventSignalData data;
844 WheelEventReceivedFunctor functor(data);
845 scene.WheelEventSignal().Connect(&application, functor);
847 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
848 application.ProcessEvent(event);
850 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
851 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
852 DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
853 DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
854 DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
855 DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
856 DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
860 Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
861 application.ProcessEvent(event2);
863 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
864 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
865 DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
866 DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
867 DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
868 DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
869 DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
873 int UtcDaliSceneSurfaceResizedDefaultScene(void)
875 tet_infoline("Ensure resizing of the surface is handled properly");
877 TestApplication application;
879 auto defaultScene = application.GetScene();
880 DALI_TEST_CHECK(defaultScene);
882 // Ensure stage size matches the scene size
883 auto stage = Stage::GetCurrent();
884 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
887 Vector2 newSize(1000.0f, 2000.0f);
888 DALI_TEST_CHECK(stage.GetSize() != newSize);
889 defaultScene.SurfaceResized(newSize.width, newSize.height);
891 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
892 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
897 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
899 tet_infoline("Ensure resizing of the surface & viewport is handled properly");
901 TestApplication application;
902 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
903 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
904 glAbstraction.EnableViewportCallTrace(true);
906 // Initial scene setup
907 Geometry geometry = CreateQuadGeometry();
908 Shader shader = CreateShader();
909 Renderer renderer = Renderer::New(geometry, shader);
911 Actor actor = Actor::New();
912 actor.AddRenderer(renderer);
913 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
914 application.GetScene().Add(actor);
916 // Render before resizing surface
917 application.SendNotification();
918 application.Render(0);
919 glAbstraction.ResetViewportCallStack();
921 auto defaultScene = application.GetScene();
922 DALI_TEST_CHECK(defaultScene);
924 // consume the resize flag by first rendering
925 defaultScene.IsSurfaceRectChanged();
927 // Ensure stage size matches the scene size
928 auto stage = Stage::GetCurrent();
929 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
931 Rect<int32_t> surfaceRect = defaultScene.GetCurrentSurfaceRect();
934 // check resized flag before surface is resized.
935 surfaceResized = defaultScene.IsSurfaceRectChanged();
936 DALI_TEST_EQUALS(surfaceResized, false, TEST_LOCATION);
939 Vector2 newSize(1000.0f, 2000.0f);
940 std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
941 DALI_TEST_CHECK(stage.GetSize() != newSize);
942 defaultScene.SurfaceResized(newSize.width, newSize.height);
944 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
945 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
947 // Check current surface rect
948 Rect<int32_t> newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
950 // It should not be changed yet.
951 DALI_TEST_CHECK(surfaceRect == newSurfaceRect);
953 // Render after resizing surface
954 application.SendNotification();
955 application.Render(0);
957 surfaceResized = defaultScene.IsSurfaceRectChanged();
958 DALI_TEST_EQUALS(surfaceResized, true, TEST_LOCATION);
960 // Check that the viewport is handled properly
961 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
963 // Check current surface rect
964 newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
966 // It should be changed
967 DALI_TEST_EQUALS(newSurfaceRect.x, 0, TEST_LOCATION);
968 DALI_TEST_EQUALS(newSurfaceRect.y, 0, TEST_LOCATION);
969 DALI_TEST_EQUALS(newSurfaceRect.width, 1000, TEST_LOCATION);
970 DALI_TEST_EQUALS(newSurfaceRect.height, 2000, TEST_LOCATION);
975 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
977 tet_infoline("Ensure resizing of the surface & viewport is handled properly");
979 TestApplication application;
980 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
981 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
982 glAbstraction.EnableViewportCallTrace(true);
984 // Initial scene setup
985 auto scene = application.GetScene();
987 Geometry geometry = CreateQuadGeometry();
988 Shader shader = CreateShader();
989 Renderer renderer = Renderer::New(geometry, shader);
991 Actor actor = Actor::New();
992 actor.AddRenderer(renderer);
994 int testHeight = 400;
995 actor.SetProperty(Actor::Property::SIZE, Vector2(testWidth, testHeight));
998 CameraActor offscreenCameraActor = CameraActor::New(Size(testWidth, testHeight));
999 application.GetScene().Add(offscreenCameraActor);
1001 FrameBuffer newFrameBuffer = FrameBuffer::New(testWidth, testHeight, FrameBuffer::Attachment::NONE);
1003 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
1004 newTask.SetCameraActor(offscreenCameraActor);
1005 newTask.SetSourceActor(actor);
1006 newTask.SetFrameBuffer(newFrameBuffer);
1007 newTask.SetViewportPosition(Vector2(0, 0));
1008 newTask.SetViewportSize(Vector2(testWidth, testHeight));
1010 // Render before resizing surface
1011 application.SendNotification();
1012 application.Render(0);
1013 glAbstraction.ResetViewportCallStack();
1015 Rect<int32_t> initialViewport = newTask.GetViewport();
1016 int initialWidth = initialViewport.width;
1017 int initialHeight = initialViewport.height;
1018 DALI_TEST_EQUALS(initialWidth, testWidth, TEST_LOCATION);
1019 DALI_TEST_EQUALS(initialHeight, testHeight, TEST_LOCATION);
1021 auto defaultScene = application.GetScene();
1022 DALI_TEST_CHECK(defaultScene);
1024 // Ensure stage size matches the scene size
1025 auto stage = Stage::GetCurrent();
1026 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
1029 Vector2 newSize(1000.0f, 2000.0f);
1030 std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
1031 DALI_TEST_CHECK(stage.GetSize() != newSize);
1032 defaultScene.SurfaceResized(newSize.width, newSize.height);
1034 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
1035 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
1037 // Render after resizing surface
1038 application.SendNotification();
1039 application.Render(0);
1041 // Check that the viewport is handled properly
1042 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1044 // Second render-task should not be affected
1045 Rect<int32_t> viewport = newTask.GetViewport();
1046 int width = viewport.width;
1047 int height = viewport.height;
1048 DALI_TEST_EQUALS(width, testWidth, TEST_LOCATION);
1049 DALI_TEST_EQUALS(height, testHeight, TEST_LOCATION);
1054 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1056 tet_infoline("Ensure resizing of the surface is handled properly on additional scenes");
1058 TestApplication application;
1059 Vector2 originalSurfaceSize(500.0f, 1000.0f);
1061 auto scene = Integration::Scene::New(Size(originalSurfaceSize.width, originalSurfaceSize.height));
1063 // Ensure stage size does NOT match the surface size
1064 auto stage = Stage::GetCurrent();
1065 const auto stageSize = stage.GetSize();
1066 DALI_TEST_CHECK(stageSize != originalSurfaceSize);
1067 DALI_TEST_EQUALS(originalSurfaceSize, scene.GetSize(), TEST_LOCATION);
1069 // Resize the surface and inform the scene accordingly
1070 Vector2 newSize(1000.0f, 2000.0f);
1071 DALI_TEST_CHECK(stage.GetSize() != newSize);
1072 scene.SurfaceResized(newSize.width, newSize.height);
1074 // Ensure the stage hasn't been resized
1075 DALI_TEST_EQUALS(stage.GetSize(), stageSize, TEST_LOCATION);
1076 DALI_TEST_EQUALS(scene.GetSize(), newSize, TEST_LOCATION);
1081 #define CLIPPING_RECT_X (16)
1082 #define CLIPPING_RECT_Y (768)
1083 #define CLIPPING_RECT_WIDTH (32)
1084 #define CLIPPING_RECT_HEIGHT (32)
1086 int UtcDaliSceneSurfaceRotatedWithAngle0(void)
1088 tet_infoline("Ensure rotation of the surface is handled properly with Angle 0");
1090 TestApplication application(
1091 TestApplication::DEFAULT_SURFACE_WIDTH,
1092 TestApplication::DEFAULT_SURFACE_HEIGHT,
1093 TestApplication::DEFAULT_HORIZONTAL_DPI,
1094 TestApplication::DEFAULT_VERTICAL_DPI,
1098 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1100 std::vector<Rect<int>> damagedRects;
1101 Rect<int> clippingRect;
1102 application.SendNotification();
1103 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1105 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1107 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1108 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1110 Actor actor = CreateRenderableActor();
1111 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1112 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1113 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1114 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1115 application.GetScene().Add(actor);
1117 application.SendNotification();
1119 damagedRects.clear();
1120 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1121 TestApplication::DEFAULT_SURFACE_HEIGHT,
1124 // Check current surface orientation
1125 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1127 // It should not be changed yet.
1128 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1130 application.SendNotification();
1131 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1132 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1134 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1135 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1136 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1138 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1139 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1140 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1141 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1143 // Check current surface orientation
1144 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1146 // It should be changed.
1147 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1152 int UtcDaliSceneSurfaceRotatedWithAngle90(void)
1154 tet_infoline("Ensure rotation of the surface is handled properly with Angle 90");
1156 TestApplication application(
1157 TestApplication::DEFAULT_SURFACE_WIDTH,
1158 TestApplication::DEFAULT_SURFACE_HEIGHT,
1159 TestApplication::DEFAULT_HORIZONTAL_DPI,
1160 TestApplication::DEFAULT_VERTICAL_DPI,
1164 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1166 std::vector<Rect<int>> damagedRects;
1167 Rect<int> clippingRect;
1168 application.SendNotification();
1169 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1171 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1173 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1174 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1176 Actor actor = CreateRenderableActor();
1177 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1178 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1179 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1180 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1181 application.GetScene().Add(actor);
1183 application.SendNotification();
1185 damagedRects.clear();
1186 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1187 TestApplication::DEFAULT_SURFACE_HEIGHT,
1190 // Check current surface orientation
1191 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1193 // It should not be changed yet.
1194 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1196 application.SendNotification();
1197 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1198 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1200 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1201 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1202 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1204 // It is recalculation for glScissor.
1205 // Because surface is rotated and glScissor is called with recalcurated value.
1206 clippingRect.x = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1207 clippingRect.y = CLIPPING_RECT_X;
1208 clippingRect.width = CLIPPING_RECT_HEIGHT;
1209 clippingRect.height = CLIPPING_RECT_WIDTH;
1211 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1212 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1213 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1214 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1216 // Check current surface orientation
1217 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1219 // It should be changed.
1220 DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1225 int UtcDaliSceneSurfaceRotatedWithAngle180(void)
1227 tet_infoline("Ensure rotation of the surface is handled properly with Angle 180");
1229 TestApplication application(
1230 TestApplication::DEFAULT_SURFACE_WIDTH,
1231 TestApplication::DEFAULT_SURFACE_HEIGHT,
1232 TestApplication::DEFAULT_HORIZONTAL_DPI,
1233 TestApplication::DEFAULT_VERTICAL_DPI,
1237 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1239 std::vector<Rect<int>> damagedRects;
1240 Rect<int> clippingRect;
1241 application.SendNotification();
1242 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1244 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1246 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1247 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1249 Actor actor = CreateRenderableActor();
1250 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1251 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1252 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1253 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1254 application.GetScene().Add(actor);
1256 application.SendNotification();
1258 damagedRects.clear();
1259 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1260 TestApplication::DEFAULT_SURFACE_HEIGHT,
1263 // Check current surface orientation
1264 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1266 // It should not be changed yet.
1267 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1269 application.SendNotification();
1270 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1271 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1273 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1274 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1275 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1277 // It is recalculation for glScissor.
1278 // Because surface is rotated and glScissor is called with recalcurated value.
1279 clippingRect.x = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1280 clippingRect.y = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1281 clippingRect.width = CLIPPING_RECT_WIDTH;
1282 clippingRect.height = CLIPPING_RECT_HEIGHT;
1284 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1285 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1286 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1287 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1289 // Check current surface orientation
1290 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1292 // It should be changed.
1293 DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
1298 int UtcDaliSceneSurfaceRotatedWithAngle270(void)
1300 tet_infoline("Ensure rotation of the surface is handled properly with Angle 270");
1302 TestApplication application(
1303 TestApplication::DEFAULT_SURFACE_WIDTH,
1304 TestApplication::DEFAULT_SURFACE_HEIGHT,
1305 TestApplication::DEFAULT_HORIZONTAL_DPI,
1306 TestApplication::DEFAULT_VERTICAL_DPI,
1310 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1312 std::vector<Rect<int>> damagedRects;
1313 Rect<int> clippingRect;
1314 application.SendNotification();
1315 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1317 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1319 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1320 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1322 Actor actor = CreateRenderableActor();
1323 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1324 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1325 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1326 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1327 application.GetScene().Add(actor);
1329 application.SendNotification();
1331 damagedRects.clear();
1332 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1333 TestApplication::DEFAULT_SURFACE_HEIGHT,
1336 // Check current surface orientation
1337 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1339 // It should not be changed yet.
1340 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1342 application.SendNotification();
1343 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1344 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1346 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1347 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1348 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1350 // It is recalculation for glScissor.
1351 // Because surface is rotated and glScissor is called with recalcurated value.
1352 clippingRect.x = CLIPPING_RECT_Y;
1353 clippingRect.y = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1354 clippingRect.width = CLIPPING_RECT_HEIGHT;
1355 clippingRect.height = CLIPPING_RECT_WIDTH;
1357 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1358 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1359 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1360 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1362 // Check current surface orientation
1363 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1365 // It should be changed.
1366 DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
1371 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1373 TestApplication application;
1374 Dali::Integration::Scene scene = application.GetScene();
1376 KeyEventGeneratedSignalData data;
1377 KeyEventGeneratedReceivedFunctor functor(data);
1378 scene.KeyEventGeneratedSignal().Connect(&application, functor);
1380 Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1381 application.ProcessEvent(event);
1383 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1384 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1385 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
1386 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
1387 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1391 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1392 application.ProcessEvent(event2);
1394 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1395 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1396 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
1397 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
1398 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1402 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1403 application.ProcessEvent(event3);
1405 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1406 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1407 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
1408 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
1409 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1413 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1414 application.ProcessEvent(event4);
1416 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1417 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1418 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
1419 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
1420 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1424 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1426 tet_infoline("Ensure we keep background color when the scene surface is replaced ");
1428 TestApplication application;
1430 // Create a new scene and set the background color of the main scene
1431 auto defaultScene = application.GetScene();
1432 defaultScene.SetBackgroundColor(Color::BLUE);
1434 // Need to create a renderable as we don't start rendering until we have at least one
1435 // We don't need to add this to any scene
1436 auto actor = CreateRenderableActor();
1438 auto& glAbstraction = application.GetGlAbstraction();
1439 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1441 application.SendNotification();
1442 application.Render();
1444 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION);
1445 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1447 defaultScene.SurfaceReplaced();
1449 application.SendNotification();
1450 application.Render();
1452 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION);
1453 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1455 // Check when the main render task viewport is set the clear color is clipped using scissors
1456 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1457 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1458 scissorTrace.Enable(true);
1459 enabledDisableTrace.Enable(true);
1461 defaultScene.GetRenderTaskList().GetTask(0).SetViewport(Viewport(0.0f, 0.0f, 100.0f, 100.0f));
1463 application.SendNotification();
1464 application.Render();
1466 // Check scissor test was enabled.
1467 std::ostringstream scissor;
1468 scissor << std::hex << GL_SCISSOR_TEST;
1469 DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
1471 // Check the scissor was set, and the coordinates are correct.
1472 DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", "0, 700, 100, 100"));
1474 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION);
1475 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1477 scissorTrace.Enable(false);
1478 scissorTrace.Reset();
1480 enabledDisableTrace.Enable(false);
1481 enabledDisableTrace.Reset();
1486 int UtcDaliSceneEmptySceneRendering(void)
1488 tet_infoline("Ensure not rendering before a Renderer is added");
1490 TestApplication application;
1491 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1493 // Render without any renderer
1494 application.SendNotification();
1495 application.Render();
1497 // Check the clear count and the render status
1498 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1499 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1502 Geometry geometry = CreateQuadGeometry();
1503 Shader shader = CreateShader();
1504 Renderer renderer = Renderer::New(geometry, shader);
1506 // Render before adding renderer
1507 application.SendNotification();
1508 application.Render();
1510 // Check the clear count and the render status
1511 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1512 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1514 Actor actor = Actor::New();
1515 actor.AddRenderer(renderer);
1517 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
1518 application.GetScene().Add(actor);
1521 application.SendNotification();
1522 application.Render();
1524 // Check the clear count and the render status
1525 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION);
1526 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1528 // Remove the Renderer
1529 application.GetScene().Remove(actor);
1534 application.SendNotification();
1535 application.Render();
1537 // Check the clear count and the render status
1538 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION); // Should be cleared
1539 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1544 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1546 tet_infoline("UtcDaliSceneFrameRenderedCallback");
1548 TestApplication application;
1551 Geometry geometry = CreateQuadGeometry();
1552 Shader shader = CreateShader();
1553 Renderer renderer = Renderer::New(geometry, shader);
1555 Actor actor = Actor::New();
1556 actor.AddRenderer(renderer);
1557 application.GetScene().Add(actor);
1559 Dali::Integration::Scene scene = application.GetScene();
1562 scene.AddFrameRenderedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1563 scene.AddFramePresentedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1566 application.SendNotification();
1567 application.Render();
1569 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1570 scene.GetFrameRenderedCallback(callbackContainer);
1572 DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1573 DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1575 callbackContainer.clear();
1577 scene.GetFramePresentedCallback(callbackContainer);
1579 DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1580 DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);