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.
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 // Stores data that is populated in the WheelEventGeneratedSignal callback and will be read by the TET cases
228 struct WheelEventGeneratedSignalData
230 WheelEventGeneratedSignalData()
231 : functorCalled(false)
237 functorCalled = false;
239 receivedWheelEvent.Reset();
243 WheelEvent receivedWheelEvent;
246 // Functor that sets the data when called
247 struct WheelEventGeneratedReceivedFunctor
249 WheelEventGeneratedReceivedFunctor(WheelEventGeneratedSignalData& data)
254 bool operator()(const WheelEvent& wheelEvent)
256 signalData.functorCalled = true;
257 signalData.receivedWheelEvent = wheelEvent;
264 signalData.functorCalled = true;
268 WheelEventGeneratedSignalData& signalData;
271 void GenerateTouch(TestApplication& application, PointState::Type state, const Vector2& screenPosition)
273 Integration::TouchEvent touchEvent;
274 Integration::Point point;
275 point.SetState(state);
276 point.SetScreenPosition(screenPosition);
277 touchEvent.points.push_back(point);
278 application.ProcessEvent(touchEvent);
281 bool DummyTouchCallback(Actor actor, const TouchEvent& touch)
286 void FrameCallback(int frameId)
290 } // unnamed namespace
292 int UtcDaliSceneAdd(void)
294 TestApplication application;
295 tet_infoline("Testing Dali::Integration::Scene::Add");
297 Dali::Integration::Scene scene = application.GetScene();
299 Actor actor = Actor::New();
300 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
303 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
308 int UtcDaliSceneRemove(void)
310 TestApplication application;
311 tet_infoline("Testing Dali::Integration::Scene::Remove");
313 Dali::Integration::Scene scene = application.GetScene();
315 Actor actor = Actor::New();
316 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
319 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
322 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
327 int UtcDaliSceneGetSize(void)
329 TestApplication application;
330 tet_infoline("Testing Dali::Integration::Scene::GetSize");
332 Dali::Integration::Scene scene = application.GetScene();
333 Size size = scene.GetSize();
334 DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION);
335 DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION);
340 int UtcDaliSceneGetDpi(void)
342 TestApplication application; // Initializes core DPI to default values
344 // Test that setting core DPI explicitly also sets up the scene's DPI.
345 Dali::Integration::Scene scene = application.GetScene();
346 scene.SetDpi(Vector2(200.0f, 180.0f));
347 Vector2 dpi = scene.GetDpi();
348 DALI_TEST_EQUALS(dpi.x, 200.0f, TEST_LOCATION);
349 DALI_TEST_EQUALS(dpi.y, 180.0f, TEST_LOCATION);
353 int UtcDaliSceneGetRenderTaskList(void)
355 TestApplication application;
356 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
358 Dali::Integration::Scene scene = application.GetScene();
360 // Check we get a valid instance.
361 const RenderTaskList& tasks = scene.GetRenderTaskList();
363 // There should be 1 task by default.
364 DALI_TEST_EQUALS(tasks.GetTaskCount(), 1u, TEST_LOCATION);
366 // RenderTaskList has it's own UTC tests.
367 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
368 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
370 DALI_TEST_EQUALS(scene.GetRenderTaskList().GetTask(1), newTask, TEST_LOCATION);
375 int UtcDaliSceneGetRootLayer(void)
377 TestApplication application;
378 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
380 Dali::Integration::Scene scene = application.GetScene();
381 Layer layer = scene.GetLayer(0);
382 DALI_TEST_CHECK(layer);
384 // Check that GetRootLayer() correctly retreived layer 0.
385 DALI_TEST_CHECK(scene.GetRootLayer() == layer);
390 int UtcDaliSceneGetLayerCount(void)
392 TestApplication application;
393 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
395 Dali::Integration::Scene scene = application.GetScene();
396 // Initially we have a default layer
397 DALI_TEST_EQUALS(scene.GetLayerCount(), 1u, TEST_LOCATION);
399 Layer layer = Layer::New();
402 DALI_TEST_EQUALS(scene.GetLayerCount(), 2u, TEST_LOCATION);
406 int UtcDaliSceneGetLayer(void)
408 TestApplication application;
409 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
411 Dali::Integration::Scene scene = application.GetScene();
413 Layer rootLayer = scene.GetLayer(0);
414 DALI_TEST_CHECK(rootLayer);
416 Layer layer = Layer::New();
419 Layer sameLayer = scene.GetLayer(1);
420 DALI_TEST_CHECK(layer == sameLayer);
425 int UtcDaliSceneGet(void)
427 TestApplication application;
428 tet_infoline("Testing Dali::Integration::Scene::Get");
430 Dali::Integration::Scene scene = application.GetScene();
432 Actor actor = Actor::New();
433 DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(actor));
437 DALI_TEST_CHECK(scene == Dali::Integration::Scene::Get(actor));
442 int UtcDaliSceneDiscard(void)
444 TestApplication application;
445 tet_infoline("Testing Dali::Scene::Discard");
447 // Create a new Scene
448 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
449 DALI_TEST_CHECK(scene);
451 // One reference of scene kept here and the other one kept in the Core
452 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
454 // Render and notify.
455 application.SendNotification();
456 application.Render(0);
458 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
459 Layer rootLayer = scene.GetRootLayer();
460 DALI_TEST_CHECK(rootLayer);
461 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
463 // Request to discard the scene from the Core
465 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
467 // Reset the scene handle
470 // Render and notify.
471 application.SendNotification();
472 application.Render(0);
474 // At this point, the scene should have been automatically deleted
475 // To prove this, the ref count of the root layer handle should be decremented to 1
476 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
478 // Delete the root layer handle
481 // Render and notify.
482 application.SendNotification();
483 application.Render(0);
488 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
490 TestApplication application;
492 Dali::Integration::Scene scene = application.GetScene();
494 TouchedSignalData data;
495 data.createNewScene = true;
496 TouchFunctor functor(data);
497 scene.TouchedSignal().Connect(&application, functor);
499 // Render and notify.
500 application.SendNotification();
501 application.Render();
503 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
505 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
506 DALI_TEST_EQUALS(true, data.createNewScene, TEST_LOCATION);
507 DALI_TEST_EQUALS(true, data.newSceneCreated, TEST_LOCATION);
513 int UtcDaliSceneRootLayerAndSceneAlignment(void)
515 TestApplication application;
518 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
519 DALI_TEST_CHECK(scene);
521 // One reference of scene kept here and the other one kept in the Core
522 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
524 // Add a renderable actor to the scene
525 auto actor = CreateRenderableActor();
528 // Render and notify.
529 application.SendNotification();
530 application.Render(0);
532 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
533 Layer rootLayer = scene.GetRootLayer();
534 DALI_TEST_CHECK(rootLayer);
535 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
537 // Request to discard the scene from the Core
539 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
541 // Reset the scene handle
544 // Render and notify.
545 application.SendNotification();
546 application.Render(0);
548 // At this point, the scene should have been automatically deleted
549 // To prove this, the ref count of the root layer handle should be decremented to 1
550 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
552 // Create a new Scene while the root layer of the deleted scene is still alive
553 Dali::Integration::Scene newScene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
554 DALI_TEST_CHECK(newScene);
556 // Render and notify.
557 application.SendNotification();
558 application.Render(0);
560 // At this point, we have only one scene but two root layers
561 // The root layer of the deleted scene is still alive
562 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
564 // Delete the root layer of the deleted scene
567 // Render and notify.
568 application.SendNotification();
569 application.Render(0);
574 int UtcDaliSceneEventProcessingFinishedP(void)
576 TestApplication application;
577 Dali::Integration::Scene scene = application.GetScene();
579 bool eventProcessingFinished = false;
580 EventProcessingFinishedFunctor functor(eventProcessingFinished);
581 scene.EventProcessingFinishedSignal().Connect(&application, functor);
583 Actor actor(Actor::New());
586 application.SendNotification();
587 application.Render();
589 DALI_TEST_CHECK(eventProcessingFinished);
594 int UtcDaliSceneEventProcessingFinishedN(void)
596 TestApplication application;
597 Dali::Integration::Scene scene = application.GetScene();
599 bool eventProcessingFinished = false;
600 EventProcessingFinishedFunctor functor(eventProcessingFinished);
601 scene.EventProcessingFinishedSignal().Connect(&application, functor);
603 Actor actor(Actor::New());
606 // Do not complete event processing and confirm the signal has not been emitted.
607 DALI_TEST_CHECK(!eventProcessingFinished);
612 int UtcDaliSceneSignalKeyEventP(void)
614 TestApplication application;
615 Dali::Integration::Scene scene = application.GetScene();
617 KeyEventSignalData data;
618 KeyEventReceivedFunctor functor(data);
619 scene.KeyEventSignal().Connect(&application, functor);
621 Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
622 application.ProcessEvent(event);
624 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
625 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
626 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
627 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
628 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
632 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
633 application.ProcessEvent(event2);
635 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
636 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
637 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
638 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
639 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
643 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
644 application.ProcessEvent(event3);
646 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
647 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
648 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
649 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
650 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
654 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
655 application.ProcessEvent(event4);
657 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
658 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
659 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
660 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
661 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
665 int UtcDaliSceneSignalKeyEventN(void)
667 TestApplication application;
668 Dali::Integration::Scene scene = application.GetScene();
670 KeyEventSignalData data;
671 KeyEventReceivedFunctor functor(data);
672 scene.KeyEventSignal().Connect(&application, functor);
674 // Check that a non-pressed key events data is not modified.
675 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
680 int UtcDaliSceneTouchedSignalP(void)
682 TestApplication application;
683 Dali::Integration::Scene scene = application.GetScene();
685 TouchedSignalData data;
686 TouchFunctor functor(data);
687 scene.TouchedSignal().Connect(&application, functor);
689 // Render and notify.
690 application.SendNotification();
691 application.Render();
693 // Basic test: No actors, single touch (down then up).
695 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
697 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
699 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
702 GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f));
704 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
705 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
706 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
710 // Add an actor to the scene.
711 Actor actor = Actor::New();
712 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
713 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
714 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
715 actor.TouchedSignal().Connect(&DummyTouchCallback);
718 // Render and notify.
719 application.SendNotification();
720 application.Render();
722 // Actor on scene, single touch, down in actor, motion, then up outside actor.
724 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
726 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
727 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
728 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
731 GenerateTouch(application, PointState::MOTION, Vector2(150.0f, 10.0f)); // Some motion
733 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
736 GenerateTouch(application, PointState::UP, Vector2(150.0f, 10.0f)); // Some motion
738 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
739 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
740 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
744 // Multiple touch. Should only receive a touch on first down and last up.
746 Integration::TouchEvent touchEvent;
747 Integration::Point point;
750 point.SetState(PointState::DOWN);
751 point.SetScreenPosition(Vector2(10.0f, 10.0f));
752 touchEvent.points.push_back(point);
753 application.ProcessEvent(touchEvent);
754 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
755 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
759 touchEvent.points[0].SetState(PointState::STATIONARY);
760 point.SetDeviceId(1);
761 point.SetScreenPosition(Vector2(50.0f, 50.0f));
762 touchEvent.points.push_back(point);
763 application.ProcessEvent(touchEvent);
764 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
767 // Primary point is up
768 touchEvent.points[0].SetState(PointState::UP);
769 touchEvent.points[1].SetState(PointState::STATIONARY);
770 application.ProcessEvent(touchEvent);
771 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
774 // Remove 1st point now, 2nd point is now in motion
775 touchEvent.points.erase(touchEvent.points.begin());
776 touchEvent.points[0].SetState(PointState::MOTION);
777 touchEvent.points[0].SetScreenPosition(Vector2(150.0f, 50.0f));
778 application.ProcessEvent(touchEvent);
779 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
783 touchEvent.points[0].SetState(PointState::UP);
784 application.ProcessEvent(touchEvent);
785 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
786 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
792 int UtcDaliSceneTouchedSignalN(void)
794 TestApplication application;
795 Dali::Integration::Scene scene = application.GetScene();
797 TouchedSignalData data;
798 TouchFunctor functor(data);
799 scene.TouchedSignal().Connect(&application, functor);
801 // Render and notify.
802 application.SendNotification();
803 application.Render();
805 // Confirm functor not called before there has been any touch event.
806 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
808 // No actors, single touch, down, motion then up.
810 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
812 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
813 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
814 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
818 // Confirm there is no signal when the touchpoint is only moved.
819 GenerateTouch(application, PointState::MOTION, Vector2(1200.0f, 10.0f)); // Some motion
821 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
824 // Confirm a following up event generates a signal.
825 GenerateTouch(application, PointState::UP, Vector2(1200.0f, 10.0f));
827 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
828 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
829 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
833 // Add an actor to the scene.
834 Actor actor = Actor::New();
835 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
836 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
837 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
838 actor.TouchedSignal().Connect(&DummyTouchCallback);
841 // Render and notify.
842 application.SendNotification();
843 application.Render();
845 // Actor on scene. Interrupted before down and interrupted after down.
847 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
849 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
850 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
851 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
852 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
855 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
857 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
858 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
859 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
860 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::DOWN);
863 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
865 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
866 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
867 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
868 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
870 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
872 // Check that getting info about a non-existent point returns an empty handle
873 Actor actor = data.receivedTouchEvent.GetHitActor(1);
874 DALI_TEST_CHECK(!actor);
882 int UtcDaliSceneSignalWheelEventP(void)
884 TestApplication application;
885 Dali::Integration::Scene scene = application.GetScene();
887 WheelEventSignalData data;
888 WheelEventReceivedFunctor functor(data);
889 scene.WheelEventSignal().Connect(&application, functor);
891 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
892 application.ProcessEvent(event);
894 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
895 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
896 DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
897 DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
898 DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
899 DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
900 DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
904 Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
905 application.ProcessEvent(event2);
907 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
908 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
909 DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
910 DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
911 DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
912 DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
913 DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
917 int UtcDaliSceneSurfaceResizedDefaultScene(void)
919 tet_infoline("Ensure resizing of the surface is handled properly");
921 TestApplication application;
923 auto defaultScene = application.GetScene();
924 DALI_TEST_CHECK(defaultScene);
926 // Ensure stage size matches the scene size
927 auto stage = Stage::GetCurrent();
928 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
931 Vector2 newSize(1000.0f, 2000.0f);
932 DALI_TEST_CHECK(stage.GetSize() != newSize);
933 defaultScene.SurfaceResized(newSize.width, newSize.height);
935 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
936 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
941 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
943 tet_infoline("Ensure resizing of the surface & viewport is handled properly");
945 TestApplication application;
946 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
947 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
948 glAbstraction.EnableViewportCallTrace(true);
950 // Initial scene setup
951 Geometry geometry = CreateQuadGeometry();
952 Shader shader = CreateShader();
953 Renderer renderer = Renderer::New(geometry, shader);
955 Actor actor = Actor::New();
956 actor.AddRenderer(renderer);
957 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
958 application.GetScene().Add(actor);
960 // Render before resizing surface
961 application.SendNotification();
962 application.Render(0);
963 glAbstraction.ResetViewportCallStack();
965 auto defaultScene = application.GetScene();
966 DALI_TEST_CHECK(defaultScene);
968 // consume the resize flag by first rendering
969 defaultScene.IsSurfaceRectChanged();
971 // Ensure stage size matches the scene size
972 auto stage = Stage::GetCurrent();
973 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
975 Rect<int32_t> surfaceRect = defaultScene.GetCurrentSurfaceRect();
978 // check resized flag before surface is resized.
979 surfaceResized = defaultScene.IsSurfaceRectChanged();
980 DALI_TEST_EQUALS(surfaceResized, false, TEST_LOCATION);
983 Vector2 newSize(1000.0f, 2000.0f);
984 std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
985 DALI_TEST_CHECK(stage.GetSize() != newSize);
986 defaultScene.SurfaceResized(newSize.width, newSize.height);
988 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
989 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
991 // Check current surface rect
992 Rect<int32_t> newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
994 // It should not be changed yet.
995 DALI_TEST_CHECK(surfaceRect == newSurfaceRect);
997 // Render after resizing surface
998 application.SendNotification();
999 application.Render(0);
1001 surfaceResized = defaultScene.IsSurfaceRectChanged();
1002 DALI_TEST_EQUALS(surfaceResized, true, TEST_LOCATION);
1004 // Check that the viewport is handled properly
1005 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1007 // Check current surface rect
1008 newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
1010 // It should be changed
1011 DALI_TEST_EQUALS(newSurfaceRect.x, 0, TEST_LOCATION);
1012 DALI_TEST_EQUALS(newSurfaceRect.y, 0, TEST_LOCATION);
1013 DALI_TEST_EQUALS(newSurfaceRect.width, 1000, TEST_LOCATION);
1014 DALI_TEST_EQUALS(newSurfaceRect.height, 2000, TEST_LOCATION);
1019 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
1021 tet_infoline("Ensure resizing of the surface & viewport is handled properly");
1023 TestApplication application;
1024 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1025 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
1026 glAbstraction.EnableViewportCallTrace(true);
1028 // Initial scene setup
1029 auto scene = application.GetScene();
1031 Geometry geometry = CreateQuadGeometry();
1032 Shader shader = CreateShader();
1033 Renderer renderer = Renderer::New(geometry, shader);
1035 Actor actor = Actor::New();
1036 actor.AddRenderer(renderer);
1037 int testWidth = 400;
1038 int testHeight = 400;
1039 actor.SetProperty(Actor::Property::SIZE, Vector2(testWidth, testHeight));
1042 CameraActor offscreenCameraActor = CameraActor::New(Size(testWidth, testHeight));
1043 application.GetScene().Add(offscreenCameraActor);
1045 FrameBuffer newFrameBuffer = FrameBuffer::New(testWidth, testHeight, FrameBuffer::Attachment::NONE);
1047 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
1048 newTask.SetCameraActor(offscreenCameraActor);
1049 newTask.SetSourceActor(actor);
1050 newTask.SetFrameBuffer(newFrameBuffer);
1051 newTask.SetViewportPosition(Vector2(0, 0));
1052 newTask.SetViewportSize(Vector2(testWidth, testHeight));
1054 // Render before resizing surface
1055 application.SendNotification();
1056 application.Render(0);
1057 glAbstraction.ResetViewportCallStack();
1059 Rect<int32_t> initialViewport = newTask.GetViewport();
1060 int initialWidth = initialViewport.width;
1061 int initialHeight = initialViewport.height;
1062 DALI_TEST_EQUALS(initialWidth, testWidth, TEST_LOCATION);
1063 DALI_TEST_EQUALS(initialHeight, testHeight, TEST_LOCATION);
1065 auto defaultScene = application.GetScene();
1066 DALI_TEST_CHECK(defaultScene);
1068 // Ensure stage size matches the scene size
1069 auto stage = Stage::GetCurrent();
1070 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
1073 Vector2 newSize(1000.0f, 2000.0f);
1074 std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
1075 DALI_TEST_CHECK(stage.GetSize() != newSize);
1076 defaultScene.SurfaceResized(newSize.width, newSize.height);
1078 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
1079 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
1081 // Render after resizing surface
1082 application.SendNotification();
1083 application.Render(0);
1085 // Check that the viewport is handled properly
1086 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1088 // Second render-task should not be affected
1089 Rect<int32_t> viewport = newTask.GetViewport();
1090 int width = viewport.width;
1091 int height = viewport.height;
1092 DALI_TEST_EQUALS(width, testWidth, TEST_LOCATION);
1093 DALI_TEST_EQUALS(height, testHeight, TEST_LOCATION);
1098 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1100 tet_infoline("Ensure resizing of the surface is handled properly on additional scenes");
1102 TestApplication application;
1103 Vector2 originalSurfaceSize(500.0f, 1000.0f);
1105 auto scene = Integration::Scene::New(Size(originalSurfaceSize.width, originalSurfaceSize.height));
1107 // Ensure stage size does NOT match the surface size
1108 auto stage = Stage::GetCurrent();
1109 const auto stageSize = stage.GetSize();
1110 DALI_TEST_CHECK(stageSize != originalSurfaceSize);
1111 DALI_TEST_EQUALS(originalSurfaceSize, scene.GetSize(), TEST_LOCATION);
1113 // Resize the surface and inform the scene accordingly
1114 Vector2 newSize(1000.0f, 2000.0f);
1115 DALI_TEST_CHECK(stage.GetSize() != newSize);
1116 scene.SurfaceResized(newSize.width, newSize.height);
1118 // Ensure the stage hasn't been resized
1119 DALI_TEST_EQUALS(stage.GetSize(), stageSize, TEST_LOCATION);
1120 DALI_TEST_EQUALS(scene.GetSize(), newSize, TEST_LOCATION);
1125 #define CLIPPING_RECT_X (16)
1126 #define CLIPPING_RECT_Y (768)
1127 #define CLIPPING_RECT_WIDTH (32)
1128 #define CLIPPING_RECT_HEIGHT (32)
1130 int UtcDaliSceneSurfaceRotatedWithAngle0(void)
1132 tet_infoline("Ensure rotation of the surface is handled properly with Angle 0");
1134 TestApplication application(
1135 TestApplication::DEFAULT_SURFACE_WIDTH,
1136 TestApplication::DEFAULT_SURFACE_HEIGHT,
1137 TestApplication::DEFAULT_HORIZONTAL_DPI,
1138 TestApplication::DEFAULT_VERTICAL_DPI,
1142 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1144 std::vector<Rect<int>> damagedRects;
1145 Rect<int> clippingRect;
1146 application.SendNotification();
1147 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1149 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1151 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1152 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1154 Actor actor = CreateRenderableActor();
1155 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1156 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1157 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1158 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1159 application.GetScene().Add(actor);
1161 application.SendNotification();
1163 damagedRects.clear();
1164 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1165 TestApplication::DEFAULT_SURFACE_HEIGHT,
1168 // Check current surface orientation
1169 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1171 // It should not be changed yet.
1172 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1174 application.SendNotification();
1175 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1176 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1178 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1179 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1180 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1182 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1183 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1184 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1185 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1187 // Check current surface orientation
1188 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1190 // It should be changed.
1191 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1196 int UtcDaliSceneSurfaceRotatedWithAngle90(void)
1198 tet_infoline("Ensure rotation of the surface is handled properly with Angle 90");
1200 TestApplication application(
1201 TestApplication::DEFAULT_SURFACE_WIDTH,
1202 TestApplication::DEFAULT_SURFACE_HEIGHT,
1203 TestApplication::DEFAULT_HORIZONTAL_DPI,
1204 TestApplication::DEFAULT_VERTICAL_DPI,
1208 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1210 std::vector<Rect<int>> damagedRects;
1211 Rect<int> clippingRect;
1212 application.SendNotification();
1213 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1215 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1217 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1218 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1220 Actor actor = CreateRenderableActor();
1221 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1222 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1223 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1224 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1225 application.GetScene().Add(actor);
1227 application.SendNotification();
1229 damagedRects.clear();
1230 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1231 TestApplication::DEFAULT_SURFACE_HEIGHT,
1234 // Check current surface orientation
1235 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1237 // It should not be changed yet.
1238 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1240 application.SendNotification();
1241 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1242 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1244 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1245 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1246 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1248 // It is recalculation for glScissor.
1249 // Because surface is rotated and glScissor is called with recalcurated value.
1250 clippingRect.x = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1251 clippingRect.y = CLIPPING_RECT_X;
1252 clippingRect.width = CLIPPING_RECT_HEIGHT;
1253 clippingRect.height = CLIPPING_RECT_WIDTH;
1255 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1256 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1257 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1258 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1260 // Check current surface orientation
1261 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1263 // It should be changed.
1264 DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1269 int UtcDaliSceneSurfaceRotatedWithAngle180(void)
1271 tet_infoline("Ensure rotation of the surface is handled properly with Angle 180");
1273 TestApplication application(
1274 TestApplication::DEFAULT_SURFACE_WIDTH,
1275 TestApplication::DEFAULT_SURFACE_HEIGHT,
1276 TestApplication::DEFAULT_HORIZONTAL_DPI,
1277 TestApplication::DEFAULT_VERTICAL_DPI,
1281 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1283 std::vector<Rect<int>> damagedRects;
1284 Rect<int> clippingRect;
1285 application.SendNotification();
1286 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1288 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1290 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1291 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1293 Actor actor = CreateRenderableActor();
1294 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1295 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1296 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1297 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1298 application.GetScene().Add(actor);
1300 application.SendNotification();
1302 damagedRects.clear();
1303 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1304 TestApplication::DEFAULT_SURFACE_HEIGHT,
1307 // Check current surface orientation
1308 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1310 // It should not be changed yet.
1311 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1313 application.SendNotification();
1314 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1315 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1317 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1318 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1319 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1321 // It is recalculation for glScissor.
1322 // Because surface is rotated and glScissor is called with recalcurated value.
1323 clippingRect.x = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1324 clippingRect.y = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1325 clippingRect.width = CLIPPING_RECT_WIDTH;
1326 clippingRect.height = CLIPPING_RECT_HEIGHT;
1328 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1329 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1330 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1331 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1333 // Check current surface orientation
1334 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1336 // It should be changed.
1337 DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
1342 int UtcDaliSceneSurfaceRotatedWithAngle270(void)
1344 tet_infoline("Ensure rotation of the surface is handled properly with Angle 270");
1346 TestApplication application(
1347 TestApplication::DEFAULT_SURFACE_WIDTH,
1348 TestApplication::DEFAULT_SURFACE_HEIGHT,
1349 TestApplication::DEFAULT_HORIZONTAL_DPI,
1350 TestApplication::DEFAULT_VERTICAL_DPI,
1354 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1356 std::vector<Rect<int>> damagedRects;
1357 Rect<int> clippingRect;
1358 application.SendNotification();
1359 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1361 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1363 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1364 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1366 Actor actor = CreateRenderableActor();
1367 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1368 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1369 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1370 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1371 application.GetScene().Add(actor);
1373 application.SendNotification();
1375 damagedRects.clear();
1376 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1377 TestApplication::DEFAULT_SURFACE_HEIGHT,
1380 // Check current surface orientation
1381 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1383 // It should not be changed yet.
1384 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1386 application.SendNotification();
1387 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1388 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1390 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1391 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1392 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1394 // It is recalculation for glScissor.
1395 // Because surface is rotated and glScissor is called with recalcurated value.
1396 clippingRect.x = CLIPPING_RECT_Y;
1397 clippingRect.y = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1398 clippingRect.width = CLIPPING_RECT_HEIGHT;
1399 clippingRect.height = CLIPPING_RECT_WIDTH;
1401 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1402 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1403 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1404 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1406 // Check current surface orientation
1407 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1409 // It should be changed.
1410 DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
1415 int UtcDaliSceneSetRotationCompletedAcknowledgementWithAngle90(void)
1417 tet_infoline("Ensure to acknowledge for completing surface 90 angle rotaiton");
1419 TestApplication application(
1420 TestApplication::DEFAULT_SURFACE_WIDTH,
1421 TestApplication::DEFAULT_SURFACE_HEIGHT,
1422 TestApplication::DEFAULT_HORIZONTAL_DPI,
1423 TestApplication::DEFAULT_VERTICAL_DPI,
1427 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1429 std::vector<Rect<int>> damagedRects;
1430 Rect<int> clippingRect;
1431 application.SendNotification();
1432 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1434 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1435 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1437 Actor actor = CreateRenderableActor();
1438 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1439 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1440 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1441 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1442 application.GetScene().Add(actor);
1444 application.SendNotification();
1446 damagedRects.clear();
1447 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1448 TestApplication::DEFAULT_SURFACE_HEIGHT,
1451 // Check current surface orientation
1452 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1454 // It should not be changed yet.
1455 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1457 application.GetScene().SetRotationCompletedAcknowledgement();
1459 application.SendNotification();
1460 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1461 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1463 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1464 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1465 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1467 // It is recalculation for glScissor.
1468 // Because surface is rotated and glScissor is called with recalcurated value.
1469 clippingRect.x = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1470 clippingRect.y = CLIPPING_RECT_X;
1471 clippingRect.width = CLIPPING_RECT_HEIGHT;
1472 clippingRect.height = CLIPPING_RECT_WIDTH;
1474 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1475 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1476 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1477 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1479 // Check current surface orientation
1480 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1482 // It should be changed.
1483 DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1485 bool isSetRotationCompletedAcknowledgementSet = application.GetScene().IsRotationCompletedAcknowledgementSet();
1486 DALI_TEST_EQUALS(isSetRotationCompletedAcknowledgementSet, true, TEST_LOCATION);
1491 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1493 TestApplication application;
1494 Dali::Integration::Scene scene = application.GetScene();
1496 KeyEventGeneratedSignalData data;
1497 KeyEventGeneratedReceivedFunctor functor(data);
1498 scene.KeyEventGeneratedSignal().Connect(&application, functor);
1500 Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1501 application.ProcessEvent(event);
1503 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1504 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1505 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
1506 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
1507 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1511 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1512 application.ProcessEvent(event2);
1514 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1515 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1516 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
1517 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
1518 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1522 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1523 application.ProcessEvent(event3);
1525 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1526 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1527 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
1528 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
1529 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1533 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1534 application.ProcessEvent(event4);
1536 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1537 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1538 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
1539 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
1540 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1544 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1546 tet_infoline("Ensure we keep background color when the scene surface is replaced ");
1548 TestApplication application;
1550 // Create a new scene and set the background color of the main scene
1551 auto defaultScene = application.GetScene();
1552 defaultScene.SetBackgroundColor(Color::BLUE);
1554 // Need to create a renderable as we don't start rendering until we have at least one
1555 // We don't need to add this to any scene
1556 auto actor = CreateRenderableActor();
1558 auto& glAbstraction = application.GetGlAbstraction();
1559 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1561 application.SendNotification();
1562 application.Render();
1564 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION);
1565 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1567 defaultScene.SurfaceReplaced();
1569 application.SendNotification();
1570 application.Render();
1572 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION);
1573 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1575 // Check when the main render task viewport is set the clear color is clipped using scissors
1576 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1577 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1578 scissorTrace.Enable(true);
1579 enabledDisableTrace.Enable(true);
1581 defaultScene.GetRenderTaskList().GetTask(0).SetViewport(Viewport(0.0f, 0.0f, 100.0f, 100.0f));
1583 application.SendNotification();
1584 application.Render();
1586 // Check scissor test was enabled.
1587 std::ostringstream scissor;
1588 scissor << std::hex << GL_SCISSOR_TEST;
1589 DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
1591 // Check the scissor was set, and the coordinates are correct.
1592 DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", "0, 700, 100, 100"));
1594 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION);
1595 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1597 scissorTrace.Enable(false);
1598 scissorTrace.Reset();
1600 enabledDisableTrace.Enable(false);
1601 enabledDisableTrace.Reset();
1606 int UtcDaliSceneEnsureRenderTargetRecreated(void)
1608 tet_infoline("Ensure render target is re-created when surface replaced ");
1610 TestApplication application;
1612 // Create a new scene and set the background color of the main scene
1613 auto defaultScene = application.GetScene();
1614 defaultScene.SetBackgroundColor(Color::BLUE);
1616 auto actor = CreateRenderableActor();
1617 defaultScene.Add(actor);
1619 auto& graphicsController = application.GetGraphicsController();
1621 application.SendNotification();
1622 application.Render();
1624 TraceCallStack& graphicsCallStack = graphicsController.mCallStack;
1625 TraceCallStack::NamedParams empty{};
1626 const TraceCallStack::NamedParams* matching = graphicsCallStack.FindLastMatch("PresentRenderTarget", empty);
1627 DALI_TEST_CHECK(matching != nullptr);
1629 graphicsCallStack.Reset();
1632 Graphics::RenderTargetCreateInfo createInfo{};
1633 createInfo.SetSurface(&fakeSurface1).SetExtent(Graphics::Extent2D{480u, 800u});
1634 defaultScene.SetSurfaceRenderTarget(createInfo);
1636 application.SendNotification();
1637 application.Render();
1639 TraceCallStack::NamedParams query1;
1640 query1["surface"] << std::hex << &fakeSurface1;
1641 const TraceCallStack::NamedParams* matching2 = graphicsCallStack.FindLastMatch("CreateRenderTarget", query1);
1642 DALI_TEST_CHECK(matching2 != nullptr);
1644 const TraceCallStack::NamedParams* matching3 = graphicsCallStack.FindLastMatch("PresentRenderTarget", empty);
1645 DALI_TEST_CHECK(matching3 != nullptr);
1646 DALI_TEST_EQUALS((*matching3)["surface"].str(), query1["surface"].str(), TEST_LOCATION);
1651 int UtcDaliSceneEmptySceneRendering(void)
1653 tet_infoline("Ensure not rendering before a Renderer is added");
1655 TestApplication application;
1656 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1658 // Render without any renderer
1659 application.SendNotification();
1660 application.Render();
1662 // Check the clear count and the render status
1663 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1664 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1667 Geometry geometry = CreateQuadGeometry();
1668 Shader shader = CreateShader();
1669 Renderer renderer = Renderer::New(geometry, shader);
1671 // Render before adding renderer
1672 application.SendNotification();
1673 application.Render();
1675 // Check the clear count and the render status
1676 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1677 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1679 Actor actor = Actor::New();
1680 actor.AddRenderer(renderer);
1682 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
1683 application.GetScene().Add(actor);
1686 application.SendNotification();
1687 application.Render();
1689 // Check the clear count and the render status
1690 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION);
1691 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1693 // Remove the Renderer
1694 application.GetScene().Remove(actor);
1699 application.SendNotification();
1700 application.Render();
1702 // Check the clear count and the render status
1703 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION); // Should be cleared
1704 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1709 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1711 tet_infoline("UtcDaliSceneFrameRenderedCallback");
1713 TestApplication application;
1716 Geometry geometry = CreateQuadGeometry();
1717 Shader shader = CreateShader();
1718 Renderer renderer = Renderer::New(geometry, shader);
1720 Actor actor = Actor::New();
1721 actor.AddRenderer(renderer);
1722 application.GetScene().Add(actor);
1724 Dali::Integration::Scene scene = application.GetScene();
1727 scene.AddFrameRenderedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1728 scene.AddFramePresentedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1731 application.SendNotification();
1732 application.Render();
1734 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1735 scene.GetFrameRenderedCallback(callbackContainer);
1737 DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1738 DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1740 callbackContainer.clear();
1742 scene.GetFramePresentedCallback(callbackContainer);
1744 DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1745 DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1750 int UtcDaliSceneWheelEventGeneratedSignalP(void)
1752 TestApplication application;
1753 Dali::Integration::Scene scene = application.GetScene();
1755 WheelEventGeneratedSignalData data;
1756 WheelEventGeneratedReceivedFunctor functor(data);
1757 scene.WheelEventGeneratedSignal().Connect(&application, functor);
1759 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
1760 application.ProcessEvent(event);
1762 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1763 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
1764 DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
1765 DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
1766 DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
1767 DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
1768 DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
1772 Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
1773 application.ProcessEvent(event2);
1775 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1776 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
1777 DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
1778 DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
1779 DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
1780 DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
1781 DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());