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 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
37 attribute mediump vec2 aPosition;\n
38 uniform mediump mat4 uModelView;\n
39 uniform mediump mat4 uProjection;\n
40 uniform mediump vec3 uSize;\n void main()\n {
42 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
44 vertexPosition.xyz *= uSize;
46 gl_Position = uProjection * uModelView * vertexPosition;
50 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
51 uniform lowp vec4 uColor;\n void main()\n {
53 gl_FragColor = uColor;
57 // Functor for EventProcessingFinished signal
58 struct EventProcessingFinishedFunctor
61 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
63 EventProcessingFinishedFunctor(bool& eventProcessingFinished)
64 : mEventProcessingFinished(eventProcessingFinished)
70 mEventProcessingFinished = true;
73 bool& mEventProcessingFinished;
76 // Stores data that is populated in the key-event callback and will be read by the TET cases
77 struct KeyEventSignalData
80 : functorCalled(false)
86 functorCalled = false;
88 receivedKeyEvent.Reset();
92 KeyEvent receivedKeyEvent;
95 // Functor that sets the data when called
96 struct KeyEventReceivedFunctor
98 KeyEventReceivedFunctor(KeyEventSignalData& data)
103 bool operator()(const KeyEvent& keyEvent)
105 signalData.functorCalled = true;
106 signalData.receivedKeyEvent = keyEvent;
111 KeyEventSignalData& signalData;
114 // Stores data that is populated in the touched signal callback and will be read by the TET cases
115 struct TouchedSignalData
118 : functorCalled(false),
119 createNewScene(false),
120 newSceneCreated(false)
126 functorCalled = false;
127 createNewScene = false;
128 newSceneCreated = false;
129 receivedTouchEvent.Reset();
134 bool newSceneCreated;
135 TouchEvent receivedTouchEvent;
138 // Functor that sets the data when touched signal is received
141 TouchFunctor(TouchedSignalData& data)
146 void operator()(const TouchEvent& touch)
148 signalData.functorCalled = true;
149 signalData.receivedTouchEvent = touch;
151 if(signalData.createNewScene)
153 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
154 DALI_TEST_CHECK(scene);
156 signalData.newSceneCreated = true;
162 signalData.functorCalled = true;
165 TouchedSignalData& signalData;
168 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
169 struct WheelEventSignalData
171 WheelEventSignalData()
172 : functorCalled(false)
178 functorCalled = false;
182 WheelEvent receivedWheelEvent;
185 // Functor that sets the data when wheel-event signal is received
186 struct WheelEventReceivedFunctor
188 WheelEventReceivedFunctor(WheelEventSignalData& data)
193 bool operator()(const WheelEvent& wheelEvent)
195 signalData.functorCalled = true;
196 signalData.receivedWheelEvent = wheelEvent;
201 WheelEventSignalData& signalData;
204 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
205 struct KeyEventGeneratedSignalData
207 KeyEventGeneratedSignalData()
208 : functorCalled(false)
214 functorCalled = false;
216 receivedKeyEvent.Reset();
220 KeyEvent receivedKeyEvent;
223 // Functor that sets the data when called
224 struct KeyEventGeneratedReceivedFunctor
226 KeyEventGeneratedReceivedFunctor(KeyEventGeneratedSignalData& data)
231 bool operator()(const KeyEvent& keyEvent)
233 signalData.functorCalled = true;
234 signalData.receivedKeyEvent = keyEvent;
241 signalData.functorCalled = true;
245 KeyEventGeneratedSignalData& signalData;
248 void GenerateTouch(TestApplication& application, PointState::Type state, const Vector2& screenPosition)
250 Integration::TouchEvent touchEvent;
251 Integration::Point point;
252 point.SetState(state);
253 point.SetScreenPosition(screenPosition);
254 touchEvent.points.push_back(point);
255 application.ProcessEvent(touchEvent);
258 bool DummyTouchCallback(Actor actor, const TouchEvent& touch)
263 void FrameCallback(int frameId)
267 } // unnamed namespace
269 int UtcDaliSceneAdd(void)
271 TestApplication application;
272 tet_infoline("Testing Dali::Integration::Scene::Add");
274 Dali::Integration::Scene scene = application.GetScene();
276 Actor actor = Actor::New();
277 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
280 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
285 int UtcDaliSceneRemove(void)
287 TestApplication application;
288 tet_infoline("Testing Dali::Integration::Scene::Remove");
290 Dali::Integration::Scene scene = application.GetScene();
292 Actor actor = Actor::New();
293 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
296 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
299 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
304 int UtcDaliSceneGetSize(void)
306 TestApplication application;
307 tet_infoline("Testing Dali::Integration::Scene::GetSize");
309 Dali::Integration::Scene scene = application.GetScene();
310 Size size = scene.GetSize();
311 DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION);
312 DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION);
317 int UtcDaliSceneGetDpi(void)
319 TestApplication application; // Initializes core DPI to default values
321 // Test that setting core DPI explicitly also sets up the scene's DPI.
322 Dali::Integration::Scene scene = application.GetScene();
323 scene.SetDpi(Vector2(200.0f, 180.0f));
324 Vector2 dpi = scene.GetDpi();
325 DALI_TEST_EQUALS(dpi.x, 200.0f, TEST_LOCATION);
326 DALI_TEST_EQUALS(dpi.y, 180.0f, TEST_LOCATION);
330 int UtcDaliSceneGetRenderTaskList(void)
332 TestApplication application;
333 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
335 Dali::Integration::Scene scene = application.GetScene();
337 // Check we get a valid instance.
338 const RenderTaskList& tasks = scene.GetRenderTaskList();
340 // There should be 1 task by default.
341 DALI_TEST_EQUALS(tasks.GetTaskCount(), 1u, TEST_LOCATION);
343 // RenderTaskList has it's own UTC tests.
344 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
345 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
347 DALI_TEST_EQUALS(scene.GetRenderTaskList().GetTask(1), newTask, TEST_LOCATION);
352 int UtcDaliSceneGetRootLayer(void)
354 TestApplication application;
355 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
357 Dali::Integration::Scene scene = application.GetScene();
358 Layer layer = scene.GetLayer(0);
359 DALI_TEST_CHECK(layer);
361 // Check that GetRootLayer() correctly retreived layer 0.
362 DALI_TEST_CHECK(scene.GetRootLayer() == layer);
367 int UtcDaliSceneGetLayerCount(void)
369 TestApplication application;
370 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
372 Dali::Integration::Scene scene = application.GetScene();
373 // Initially we have a default layer
374 DALI_TEST_EQUALS(scene.GetLayerCount(), 1u, TEST_LOCATION);
376 Layer layer = Layer::New();
379 DALI_TEST_EQUALS(scene.GetLayerCount(), 2u, TEST_LOCATION);
383 int UtcDaliSceneGetLayer(void)
385 TestApplication application;
386 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
388 Dali::Integration::Scene scene = application.GetScene();
390 Layer rootLayer = scene.GetLayer(0);
391 DALI_TEST_CHECK(rootLayer);
393 Layer layer = Layer::New();
396 Layer sameLayer = scene.GetLayer(1);
397 DALI_TEST_CHECK(layer == sameLayer);
402 int UtcDaliSceneGet(void)
404 TestApplication application;
405 tet_infoline("Testing Dali::Integration::Scene::Get");
407 Dali::Integration::Scene scene = application.GetScene();
409 Actor actor = Actor::New();
410 DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(actor));
414 DALI_TEST_CHECK(scene == Dali::Integration::Scene::Get(actor));
419 int UtcDaliSceneDiscard(void)
421 TestApplication application;
422 tet_infoline("Testing Dali::Scene::Discard");
424 // Create a new Scene
425 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
426 DALI_TEST_CHECK(scene);
428 // One reference of scene kept here and the other one kept in the Core
429 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
431 // Render and notify.
432 application.SendNotification();
433 application.Render(0);
435 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
436 Layer rootLayer = scene.GetRootLayer();
437 DALI_TEST_CHECK(rootLayer);
438 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
440 // Request to discard the scene from the Core
442 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
444 // Reset the scene handle
447 // Render and notify.
448 application.SendNotification();
449 application.Render(0);
451 // At this point, the scene should have been automatically deleted
452 // To prove this, the ref count of the root layer handle should be decremented to 1
453 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
455 // Delete the root layer handle
458 // Render and notify.
459 application.SendNotification();
460 application.Render(0);
465 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
467 TestApplication application;
469 Dali::Integration::Scene scene = application.GetScene();
471 TouchedSignalData data;
472 data.createNewScene = true;
473 TouchFunctor functor(data);
474 scene.TouchedSignal().Connect(&application, functor);
476 // Render and notify.
477 application.SendNotification();
478 application.Render();
480 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
482 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
483 DALI_TEST_EQUALS(true, data.createNewScene, TEST_LOCATION);
484 DALI_TEST_EQUALS(true, data.newSceneCreated, TEST_LOCATION);
490 int UtcDaliSceneRootLayerAndSceneAlignment(void)
492 TestApplication application;
495 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
496 DALI_TEST_CHECK(scene);
498 // One reference of scene kept here and the other one kept in the Core
499 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
501 // Add a renderable actor to the scene
502 auto actor = CreateRenderableActor();
505 // Render and notify.
506 application.SendNotification();
507 application.Render(0);
509 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
510 Layer rootLayer = scene.GetRootLayer();
511 DALI_TEST_CHECK(rootLayer);
512 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
514 // Request to discard the scene from the Core
516 DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
518 // Reset the scene handle
521 // Render and notify.
522 application.SendNotification();
523 application.Render(0);
525 // At this point, the scene should have been automatically deleted
526 // To prove this, the ref count of the root layer handle should be decremented to 1
527 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
529 // Create a new Scene while the root layer of the deleted scene is still alive
530 Dali::Integration::Scene newScene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
531 DALI_TEST_CHECK(newScene);
533 // Render and notify.
534 application.SendNotification();
535 application.Render(0);
537 // At this point, we have only one scene but two root layers
538 // The root layer of the deleted scene is still alive
539 DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
541 // Delete the root layer of the deleted scene
544 // Render and notify.
545 application.SendNotification();
546 application.Render(0);
551 int UtcDaliSceneEventProcessingFinishedP(void)
553 TestApplication application;
554 Dali::Integration::Scene scene = application.GetScene();
556 bool eventProcessingFinished = false;
557 EventProcessingFinishedFunctor functor(eventProcessingFinished);
558 scene.EventProcessingFinishedSignal().Connect(&application, functor);
560 Actor actor(Actor::New());
563 application.SendNotification();
564 application.Render();
566 DALI_TEST_CHECK(eventProcessingFinished);
571 int UtcDaliSceneEventProcessingFinishedN(void)
573 TestApplication application;
574 Dali::Integration::Scene scene = application.GetScene();
576 bool eventProcessingFinished = false;
577 EventProcessingFinishedFunctor functor(eventProcessingFinished);
578 scene.EventProcessingFinishedSignal().Connect(&application, functor);
580 Actor actor(Actor::New());
583 // Do not complete event processing and confirm the signal has not been emitted.
584 DALI_TEST_CHECK(!eventProcessingFinished);
589 int UtcDaliSceneSignalKeyEventP(void)
591 TestApplication application;
592 Dali::Integration::Scene scene = application.GetScene();
594 KeyEventSignalData data;
595 KeyEventReceivedFunctor functor(data);
596 scene.KeyEventSignal().Connect(&application, functor);
598 Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
599 application.ProcessEvent(event);
601 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
602 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
603 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
604 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
605 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
609 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
610 application.ProcessEvent(event2);
612 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
613 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
614 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
615 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
616 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
620 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
621 application.ProcessEvent(event3);
623 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
624 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
625 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
626 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
627 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
631 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
632 application.ProcessEvent(event4);
634 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
635 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
636 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
637 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
638 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
642 int UtcDaliSceneSignalKeyEventN(void)
644 TestApplication application;
645 Dali::Integration::Scene scene = application.GetScene();
647 KeyEventSignalData data;
648 KeyEventReceivedFunctor functor(data);
649 scene.KeyEventSignal().Connect(&application, functor);
651 // Check that a non-pressed key events data is not modified.
652 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
657 int UtcDaliSceneTouchedSignalP(void)
659 TestApplication application;
660 Dali::Integration::Scene scene = application.GetScene();
662 TouchedSignalData data;
663 TouchFunctor functor(data);
664 scene.TouchedSignal().Connect(&application, functor);
666 // Render and notify.
667 application.SendNotification();
668 application.Render();
670 // Basic test: No actors, single touch (down then up).
672 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
674 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
675 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
676 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
679 GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f));
681 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
682 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
683 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
687 // Add an actor to the scene.
688 Actor actor = Actor::New();
689 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
690 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
691 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
692 actor.TouchedSignal().Connect(&DummyTouchCallback);
695 // Render and notify.
696 application.SendNotification();
697 application.Render();
699 // Actor on scene, single touch, down in actor, motion, then up outside actor.
701 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
703 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
704 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
705 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
708 GenerateTouch(application, PointState::MOTION, Vector2(150.0f, 10.0f)); // Some motion
710 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
713 GenerateTouch(application, PointState::UP, Vector2(150.0f, 10.0f)); // Some motion
715 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
716 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
717 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
721 // Multiple touch. Should only receive a touch on first down and last up.
723 Integration::TouchEvent touchEvent;
724 Integration::Point point;
727 point.SetState(PointState::DOWN);
728 point.SetScreenPosition(Vector2(10.0f, 10.0f));
729 touchEvent.points.push_back(point);
730 application.ProcessEvent(touchEvent);
731 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
732 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
736 touchEvent.points[0].SetState(PointState::STATIONARY);
737 point.SetDeviceId(1);
738 point.SetScreenPosition(Vector2(50.0f, 50.0f));
739 touchEvent.points.push_back(point);
740 application.ProcessEvent(touchEvent);
741 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
744 // Primary point is up
745 touchEvent.points[0].SetState(PointState::UP);
746 touchEvent.points[1].SetState(PointState::STATIONARY);
747 application.ProcessEvent(touchEvent);
748 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
751 // Remove 1st point now, 2nd point is now in motion
752 touchEvent.points.erase(touchEvent.points.begin());
753 touchEvent.points[0].SetState(PointState::MOTION);
754 touchEvent.points[0].SetScreenPosition(Vector2(150.0f, 50.0f));
755 application.ProcessEvent(touchEvent);
756 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
760 touchEvent.points[0].SetState(PointState::UP);
761 application.ProcessEvent(touchEvent);
762 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
763 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
769 int UtcDaliSceneTouchedSignalN(void)
771 TestApplication application;
772 Dali::Integration::Scene scene = application.GetScene();
774 TouchedSignalData data;
775 TouchFunctor functor(data);
776 scene.TouchedSignal().Connect(&application, functor);
778 // Render and notify.
779 application.SendNotification();
780 application.Render();
782 // Confirm functor not called before there has been any touch event.
783 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
785 // No actors, single touch, down, motion then up.
787 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
789 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
790 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
791 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
795 // Confirm there is no signal when the touchpoint is only moved.
796 GenerateTouch(application, PointState::MOTION, Vector2(1200.0f, 10.0f)); // Some motion
798 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
801 // Confirm a following up event generates a signal.
802 GenerateTouch(application, PointState::UP, Vector2(1200.0f, 10.0f));
804 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
805 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
806 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
810 // Add an actor to the scene.
811 Actor actor = Actor::New();
812 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
813 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
814 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
815 actor.TouchedSignal().Connect(&DummyTouchCallback);
818 // Render and notify.
819 application.SendNotification();
820 application.Render();
822 // Actor on scene. Interrupted before down and interrupted after down.
824 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
827 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
828 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
829 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
832 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
834 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
835 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
836 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
837 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::DOWN);
840 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
842 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
843 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
844 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
845 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
847 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
849 // Check that getting info about a non-existent point returns an empty handle
850 Actor actor = data.receivedTouchEvent.GetHitActor(1);
851 DALI_TEST_CHECK(!actor);
859 int UtcDaliSceneSignalWheelEventP(void)
861 TestApplication application;
862 Dali::Integration::Scene scene = application.GetScene();
864 WheelEventSignalData data;
865 WheelEventReceivedFunctor functor(data);
866 scene.WheelEventSignal().Connect(&application, functor);
868 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
869 application.ProcessEvent(event);
871 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
872 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
873 DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
874 DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
875 DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
876 DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
877 DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
881 Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
882 application.ProcessEvent(event2);
884 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
885 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
886 DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
887 DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
888 DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
889 DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
890 DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
894 int UtcDaliSceneSurfaceResizedDefaultScene(void)
896 tet_infoline("Ensure resizing of the surface is handled properly");
898 TestApplication application;
900 auto defaultScene = application.GetScene();
901 DALI_TEST_CHECK(defaultScene);
903 // Ensure stage size matches the scene size
904 auto stage = Stage::GetCurrent();
905 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
908 Vector2 newSize(1000.0f, 2000.0f);
909 DALI_TEST_CHECK(stage.GetSize() != newSize);
910 defaultScene.SurfaceResized(newSize.width, newSize.height);
912 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
913 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
918 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
920 tet_infoline("Ensure resizing of the surface & viewport is handled properly");
922 TestApplication application;
923 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
924 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
925 glAbstraction.EnableViewportCallTrace(true);
927 // Initial scene setup
928 Geometry geometry = CreateQuadGeometry();
929 Shader shader = CreateShader();
930 Renderer renderer = Renderer::New(geometry, shader);
932 Actor actor = Actor::New();
933 actor.AddRenderer(renderer);
934 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
935 application.GetScene().Add(actor);
937 // Render before resizing surface
938 application.SendNotification();
939 application.Render(0);
940 glAbstraction.ResetViewportCallStack();
942 auto defaultScene = application.GetScene();
943 DALI_TEST_CHECK(defaultScene);
945 // consume the resize flag by first rendering
946 defaultScene.IsSurfaceRectChanged();
948 // Ensure stage size matches the scene size
949 auto stage = Stage::GetCurrent();
950 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
952 Rect<int32_t> surfaceRect = defaultScene.GetCurrentSurfaceRect();
955 // check resized flag before surface is resized.
956 surfaceResized = defaultScene.IsSurfaceRectChanged();
957 DALI_TEST_EQUALS(surfaceResized, false, TEST_LOCATION);
960 Vector2 newSize(1000.0f, 2000.0f);
961 std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
962 DALI_TEST_CHECK(stage.GetSize() != newSize);
963 defaultScene.SurfaceResized(newSize.width, newSize.height);
965 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
966 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
968 // Check current surface rect
969 Rect<int32_t> newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
971 // It should not be changed yet.
972 DALI_TEST_CHECK(surfaceRect == newSurfaceRect);
974 // Render after resizing surface
975 application.SendNotification();
976 application.Render(0);
978 surfaceResized = defaultScene.IsSurfaceRectChanged();
979 DALI_TEST_EQUALS(surfaceResized, true, TEST_LOCATION);
981 // Check that the viewport is handled properly
982 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
984 // Check current surface rect
985 newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
987 // It should be changed
988 DALI_TEST_EQUALS(newSurfaceRect.x, 0, TEST_LOCATION);
989 DALI_TEST_EQUALS(newSurfaceRect.y, 0, TEST_LOCATION);
990 DALI_TEST_EQUALS(newSurfaceRect.width, 1000, TEST_LOCATION);
991 DALI_TEST_EQUALS(newSurfaceRect.height, 2000, TEST_LOCATION);
996 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
998 tet_infoline("Ensure resizing of the surface & viewport is handled properly");
1000 TestApplication application;
1001 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1002 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
1003 glAbstraction.EnableViewportCallTrace(true);
1005 // Initial scene setup
1006 auto scene = application.GetScene();
1008 Geometry geometry = CreateQuadGeometry();
1009 Shader shader = CreateShader();
1010 Renderer renderer = Renderer::New(geometry, shader);
1012 Actor actor = Actor::New();
1013 actor.AddRenderer(renderer);
1014 int testWidth = 400;
1015 int testHeight = 400;
1016 actor.SetProperty(Actor::Property::SIZE, Vector2(testWidth, testHeight));
1019 CameraActor offscreenCameraActor = CameraActor::New(Size(testWidth, testHeight));
1020 application.GetScene().Add(offscreenCameraActor);
1022 FrameBuffer newFrameBuffer = FrameBuffer::New(testWidth, testHeight, FrameBuffer::Attachment::NONE);
1024 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
1025 newTask.SetCameraActor(offscreenCameraActor);
1026 newTask.SetSourceActor(actor);
1027 newTask.SetFrameBuffer(newFrameBuffer);
1028 newTask.SetViewportPosition(Vector2(0, 0));
1029 newTask.SetViewportSize(Vector2(testWidth, testHeight));
1031 // Render before resizing surface
1032 application.SendNotification();
1033 application.Render(0);
1034 glAbstraction.ResetViewportCallStack();
1036 Rect<int32_t> initialViewport = newTask.GetViewport();
1037 int initialWidth = initialViewport.width;
1038 int initialHeight = initialViewport.height;
1039 DALI_TEST_EQUALS(initialWidth, testWidth, TEST_LOCATION);
1040 DALI_TEST_EQUALS(initialHeight, testHeight, TEST_LOCATION);
1042 auto defaultScene = application.GetScene();
1043 DALI_TEST_CHECK(defaultScene);
1045 // Ensure stage size matches the scene size
1046 auto stage = Stage::GetCurrent();
1047 DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
1050 Vector2 newSize(1000.0f, 2000.0f);
1051 std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
1052 DALI_TEST_CHECK(stage.GetSize() != newSize);
1053 defaultScene.SurfaceResized(newSize.width, newSize.height);
1055 DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
1056 DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
1058 // Render after resizing surface
1059 application.SendNotification();
1060 application.Render(0);
1062 // Check that the viewport is handled properly
1063 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1065 // Second render-task should not be affected
1066 Rect<int32_t> viewport = newTask.GetViewport();
1067 int width = viewport.width;
1068 int height = viewport.height;
1069 DALI_TEST_EQUALS(width, testWidth, TEST_LOCATION);
1070 DALI_TEST_EQUALS(height, testHeight, TEST_LOCATION);
1075 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1077 tet_infoline("Ensure resizing of the surface is handled properly on additional scenes");
1079 TestApplication application;
1080 Vector2 originalSurfaceSize(500.0f, 1000.0f);
1082 auto scene = Integration::Scene::New(Size(originalSurfaceSize.width, originalSurfaceSize.height));
1084 // Ensure stage size does NOT match the surface size
1085 auto stage = Stage::GetCurrent();
1086 const auto stageSize = stage.GetSize();
1087 DALI_TEST_CHECK(stageSize != originalSurfaceSize);
1088 DALI_TEST_EQUALS(originalSurfaceSize, scene.GetSize(), TEST_LOCATION);
1090 // Resize the surface and inform the scene accordingly
1091 Vector2 newSize(1000.0f, 2000.0f);
1092 DALI_TEST_CHECK(stage.GetSize() != newSize);
1093 scene.SurfaceResized(newSize.width, newSize.height);
1095 // Ensure the stage hasn't been resized
1096 DALI_TEST_EQUALS(stage.GetSize(), stageSize, TEST_LOCATION);
1097 DALI_TEST_EQUALS(scene.GetSize(), newSize, TEST_LOCATION);
1102 #define CLIPPING_RECT_X (16)
1103 #define CLIPPING_RECT_Y (768)
1104 #define CLIPPING_RECT_WIDTH (32)
1105 #define CLIPPING_RECT_HEIGHT (32)
1107 int UtcDaliSceneSurfaceRotatedWithAngle0(void)
1109 tet_infoline("Ensure rotation of the surface is handled properly with Angle 0");
1111 TestApplication application(
1112 TestApplication::DEFAULT_SURFACE_WIDTH,
1113 TestApplication::DEFAULT_SURFACE_HEIGHT,
1114 TestApplication::DEFAULT_HORIZONTAL_DPI,
1115 TestApplication::DEFAULT_VERTICAL_DPI,
1119 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1121 std::vector<Rect<int>> damagedRects;
1122 Rect<int> clippingRect;
1123 application.SendNotification();
1124 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1126 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1128 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1129 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1131 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u);
1132 Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER);
1133 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1134 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1135 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1136 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1137 application.GetScene().Add(actor);
1139 application.SendNotification();
1140 application.Render(0);
1143 CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor();
1144 camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection);
1146 damagedRects.clear();
1147 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1148 TestApplication::DEFAULT_SURFACE_HEIGHT,
1151 // Check current surface orientation
1152 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1154 // It should not be changed yet.
1155 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1157 application.SendNotification();
1158 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1159 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1161 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1162 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1163 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1165 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1166 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1167 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1168 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1170 // Check current surface orientation
1171 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1173 // It should be changed.
1174 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1177 Quaternion rotationAngle(Dali::ANGLE_0, Vector3::ZAXIS);
1178 Matrix rotation, newProjection;
1179 rotation.SetIdentity();
1180 rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f));
1181 Matrix::Multiply(newProjection, projection, rotation);
1183 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1185 // Change actor size to trigger rendering
1186 actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f));
1189 application.SendNotification();
1190 application.Render(0);
1192 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1197 int UtcDaliSceneSurfaceRotatedWithAngle90(void)
1199 tet_infoline("Ensure rotation of the surface is handled properly with Angle 90");
1201 TestApplication application(
1202 TestApplication::DEFAULT_SURFACE_WIDTH,
1203 TestApplication::DEFAULT_SURFACE_HEIGHT,
1204 TestApplication::DEFAULT_HORIZONTAL_DPI,
1205 TestApplication::DEFAULT_VERTICAL_DPI,
1209 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1211 std::vector<Rect<int>> damagedRects;
1212 Rect<int> clippingRect;
1213 application.SendNotification();
1214 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1216 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1218 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1219 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1221 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u);
1222 Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER);
1223 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1224 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1225 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1226 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1227 application.GetScene().Add(actor);
1229 application.SendNotification();
1230 application.Render(0);
1233 CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor();
1234 camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection);
1236 damagedRects.clear();
1237 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1238 TestApplication::DEFAULT_SURFACE_HEIGHT,
1241 // Check current surface orientation
1242 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1244 // It should not be changed yet.
1245 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1247 application.SendNotification();
1248 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1249 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1251 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1252 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1253 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1255 // It is recalculation for glScissor.
1256 // Because surface is rotated and glScissor is called with recalcurated value.
1257 clippingRect.x = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1258 clippingRect.y = CLIPPING_RECT_X;
1259 clippingRect.width = CLIPPING_RECT_HEIGHT;
1260 clippingRect.height = CLIPPING_RECT_WIDTH;
1262 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1263 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1264 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1265 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1267 // Check current surface orientation
1268 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1270 // It should be changed.
1271 DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1274 Quaternion rotationAngle(Dali::ANGLE_90, Vector3::ZAXIS);
1275 Matrix rotation, newProjection;
1276 rotation.SetIdentity();
1277 rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f));
1278 Matrix::Multiply(newProjection, projection, rotation);
1280 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1282 // Change actor size to trigger rendering
1283 actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f));
1286 application.SendNotification();
1287 application.Render(0);
1289 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1294 int UtcDaliSceneSurfaceRotatedWithAngle180(void)
1296 tet_infoline("Ensure rotation of the surface is handled properly with Angle 180");
1298 TestApplication application(
1299 TestApplication::DEFAULT_SURFACE_WIDTH,
1300 TestApplication::DEFAULT_SURFACE_HEIGHT,
1301 TestApplication::DEFAULT_HORIZONTAL_DPI,
1302 TestApplication::DEFAULT_VERTICAL_DPI,
1306 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1308 std::vector<Rect<int>> damagedRects;
1309 Rect<int> clippingRect;
1310 application.SendNotification();
1311 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1313 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1315 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1316 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1318 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u);
1319 Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER);
1320 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1321 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1322 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1323 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1324 application.GetScene().Add(actor);
1326 application.SendNotification();
1327 application.Render(0);
1330 CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor();
1331 camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection);
1333 damagedRects.clear();
1334 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1335 TestApplication::DEFAULT_SURFACE_HEIGHT,
1338 // Check current surface orientation
1339 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1341 // It should not be changed yet.
1342 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1344 application.SendNotification();
1345 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1346 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1348 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1349 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1350 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1352 // It is recalculation for glScissor.
1353 // Because surface is rotated and glScissor is called with recalcurated value.
1354 clippingRect.x = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1355 clippingRect.y = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1356 clippingRect.width = CLIPPING_RECT_WIDTH;
1357 clippingRect.height = CLIPPING_RECT_HEIGHT;
1359 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1360 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1361 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1362 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1364 // Check current surface orientation
1365 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1367 // It should be changed.
1368 DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
1371 Quaternion rotationAngle(Dali::ANGLE_180, Vector3::ZAXIS);
1372 Matrix rotation, newProjection;
1373 rotation.SetIdentity();
1374 rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f));
1375 Matrix::Multiply(newProjection, projection, rotation);
1377 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1379 // Change actor size to trigger rendering
1380 actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f));
1383 application.SendNotification();
1384 application.Render(0);
1386 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1391 int UtcDaliSceneSurfaceRotatedWithAngle270(void)
1393 tet_infoline("Ensure rotation of the surface is handled properly with Angle 270");
1395 TestApplication application(
1396 TestApplication::DEFAULT_SURFACE_WIDTH,
1397 TestApplication::DEFAULT_SURFACE_HEIGHT,
1398 TestApplication::DEFAULT_HORIZONTAL_DPI,
1399 TestApplication::DEFAULT_VERTICAL_DPI,
1403 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1405 std::vector<Rect<int>> damagedRects;
1406 Rect<int> clippingRect;
1407 application.SendNotification();
1408 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1410 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1412 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1413 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1415 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u);
1416 Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER);
1417 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1418 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1419 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1420 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1421 application.GetScene().Add(actor);
1423 application.SendNotification();
1424 application.Render(0);
1427 CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor();
1428 camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection);
1430 damagedRects.clear();
1431 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1432 TestApplication::DEFAULT_SURFACE_HEIGHT,
1435 // Check current surface orientation
1436 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1438 // It should not be changed yet.
1439 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1441 application.SendNotification();
1442 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1443 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1445 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1446 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1447 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1449 // It is recalculation for glScissor.
1450 // Because surface is rotated and glScissor is called with recalcurated value.
1451 clippingRect.x = CLIPPING_RECT_Y;
1452 clippingRect.y = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1453 clippingRect.width = CLIPPING_RECT_HEIGHT;
1454 clippingRect.height = CLIPPING_RECT_WIDTH;
1456 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1457 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1458 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1459 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1461 // Check current surface orientation
1462 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1464 // It should be changed.
1465 DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
1468 Quaternion rotationAngle(Dali::ANGLE_270, Vector3::ZAXIS);
1469 Matrix rotation, newProjection;
1470 rotation.SetIdentity();
1471 rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f));
1472 Matrix::Multiply(newProjection, projection, rotation);
1474 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1476 // Change actor size to trigger rendering
1477 actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f));
1480 application.SendNotification();
1481 application.Render(0);
1483 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection));
1488 int UtcDaliSceneSetRotationCompletedAcknowledgementWithAngle90(void)
1490 tet_infoline("Ensure to acknowledge for completing surface 90 angle rotaiton");
1492 TestApplication application(
1493 TestApplication::DEFAULT_SURFACE_WIDTH,
1494 TestApplication::DEFAULT_SURFACE_HEIGHT,
1495 TestApplication::DEFAULT_HORIZONTAL_DPI,
1496 TestApplication::DEFAULT_VERTICAL_DPI,
1500 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1502 std::vector<Rect<int>> damagedRects;
1503 Rect<int> clippingRect;
1504 application.SendNotification();
1505 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1507 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1508 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1510 Actor actor = CreateRenderableActor();
1511 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1512 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1513 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1514 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1515 application.GetScene().Add(actor);
1517 application.SendNotification();
1519 damagedRects.clear();
1520 application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1521 TestApplication::DEFAULT_SURFACE_HEIGHT,
1524 // Check current surface orientation
1525 int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1527 // It should not be changed yet.
1528 DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1530 application.GetScene().SetRotationCompletedAcknowledgement();
1532 application.SendNotification();
1533 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1534 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1536 clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1537 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1538 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1540 // It is recalculation for glScissor.
1541 // Because surface is rotated and glScissor is called with recalcurated value.
1542 clippingRect.x = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1543 clippingRect.y = CLIPPING_RECT_X;
1544 clippingRect.width = CLIPPING_RECT_HEIGHT;
1545 clippingRect.height = CLIPPING_RECT_WIDTH;
1547 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1548 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1549 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1550 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1552 // Check current surface orientation
1553 orientation = application.GetScene().GetCurrentSurfaceOrientation();
1555 // It should be changed.
1556 DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1558 bool isSetRotationCompletedAcknowledgementSet = application.GetScene().IsRotationCompletedAcknowledgementSet();
1559 DALI_TEST_EQUALS(isSetRotationCompletedAcknowledgementSet, true, TEST_LOCATION);
1564 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1566 TestApplication application;
1567 Dali::Integration::Scene scene = application.GetScene();
1569 KeyEventGeneratedSignalData data;
1570 KeyEventGeneratedReceivedFunctor functor(data);
1571 scene.KeyEventGeneratedSignal().Connect(&application, functor);
1573 Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1574 application.ProcessEvent(event);
1576 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1577 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1578 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
1579 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
1580 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1584 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1585 application.ProcessEvent(event2);
1587 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1588 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1589 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
1590 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
1591 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1595 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1596 application.ProcessEvent(event3);
1598 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1599 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1600 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
1601 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
1602 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1606 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1607 application.ProcessEvent(event4);
1609 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1610 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1611 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
1612 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
1613 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1617 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1619 tet_infoline("Ensure we keep background color when the scene surface is replaced ");
1621 TestApplication application;
1623 // Create a new scene and set the background color of the main scene
1624 auto defaultScene = application.GetScene();
1625 defaultScene.SetBackgroundColor(Color::BLUE);
1627 // Need to create a renderable as we don't start rendering until we have at least one
1628 // We don't need to add this to any scene
1629 auto actor = CreateRenderableActor();
1631 auto& glAbstraction = application.GetGlAbstraction();
1632 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1634 application.SendNotification();
1635 application.Render();
1637 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION);
1638 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1640 defaultScene.SurfaceReplaced();
1642 application.SendNotification();
1643 application.Render();
1645 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION);
1646 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1648 // Check when the main render task viewport is set the clear color is clipped using scissors
1649 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1650 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1651 scissorTrace.Enable(true);
1652 enabledDisableTrace.Enable(true);
1654 defaultScene.GetRenderTaskList().GetTask(0).SetViewport(Viewport(0.0f, 0.0f, 100.0f, 100.0f));
1656 application.SendNotification();
1657 application.Render();
1659 // Check scissor test was enabled.
1660 std::ostringstream scissor;
1661 scissor << std::hex << GL_SCISSOR_TEST;
1662 DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
1664 // Check the scissor was set, and the coordinates are correct.
1665 DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", "0, 700, 100, 100"));
1667 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION);
1668 DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1670 scissorTrace.Enable(false);
1671 scissorTrace.Reset();
1673 enabledDisableTrace.Enable(false);
1674 enabledDisableTrace.Reset();
1679 int UtcDaliSceneEmptySceneRendering(void)
1681 tet_infoline("Ensure not rendering before a Renderer is added");
1683 TestApplication application;
1684 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1686 // Render without any renderer
1687 application.SendNotification();
1688 application.Render();
1690 // Check the clear count and the render status
1691 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1692 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1695 Geometry geometry = CreateQuadGeometry();
1696 Shader shader = CreateShader();
1697 Renderer renderer = Renderer::New(geometry, shader);
1699 // Render before adding renderer
1700 application.SendNotification();
1701 application.Render();
1703 // Check the clear count and the render status
1704 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1705 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1707 Actor actor = Actor::New();
1708 actor.AddRenderer(renderer);
1710 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
1711 application.GetScene().Add(actor);
1714 application.SendNotification();
1715 application.Render();
1717 // Check the clear count and the render status
1718 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION);
1719 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1721 // Remove the Renderer
1722 application.GetScene().Remove(actor);
1727 application.SendNotification();
1728 application.Render();
1730 // Check the clear count and the render status
1731 DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION); // Should be cleared
1732 DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1737 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1739 tet_infoline("UtcDaliSceneFrameRenderedCallback");
1741 TestApplication application;
1744 Geometry geometry = CreateQuadGeometry();
1745 Shader shader = CreateShader();
1746 Renderer renderer = Renderer::New(geometry, shader);
1748 Actor actor = Actor::New();
1749 actor.AddRenderer(renderer);
1750 application.GetScene().Add(actor);
1752 Dali::Integration::Scene scene = application.GetScene();
1755 scene.AddFrameRenderedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1756 scene.AddFramePresentedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1759 application.SendNotification();
1760 application.Render();
1762 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1763 scene.GetFrameRenderedCallback(callbackContainer);
1765 DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1766 DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1768 callbackContainer.clear();
1770 scene.GetFramePresentedCallback(callbackContainer);
1772 DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1773 DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);