2 * Copyright (c) 2020 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.
21 #include <dali/integration-api/scene.h>
22 #include <dali/integration-api/events/key-event-integ.h>
23 #include <dali/public-api/events/key-event.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/wheel-event-integ.h>
28 #include <dali-test-suite-utils.h>
29 #include <mesh-builder.h>
31 // Internal headers are allowed here
36 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
38 // Functor for EventProcessingFinished signal
39 struct EventProcessingFinishedFunctor
42 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
44 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
45 : mEventProcessingFinished( eventProcessingFinished )
50 mEventProcessingFinished = true;
53 bool& mEventProcessingFinished;
56 // Stores data that is populated in the key-event callback and will be read by the TET cases
57 struct KeyEventSignalData
60 : functorCalled(false)
65 functorCalled = false;
67 receivedKeyEvent.keyModifier = 0;
68 receivedKeyEvent.keyPressedName.clear();
69 receivedKeyEvent.keyPressed.clear();
73 KeyEvent receivedKeyEvent;
76 // Functor that sets the data when called
77 struct KeyEventReceivedFunctor
79 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
81 bool operator()( const KeyEvent& keyEvent )
83 signalData.functorCalled = true;
84 signalData.receivedKeyEvent = keyEvent;
89 KeyEventSignalData& signalData;
92 // Stores data that is populated in the touched signal callback and will be read by the TET cases
93 struct TouchedSignalData
96 : functorCalled(false),
97 createNewScene(false),
98 newSceneCreated(false)
103 functorCalled = false;
104 createNewScene = false;
105 newSceneCreated = false;
106 receivedTouchEvent.Reset();
111 bool newSceneCreated;
112 TouchEvent receivedTouchEvent;
115 // Functor that sets the data when touched signal is received
118 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
120 void operator()( const TouchEvent& touch )
122 signalData.functorCalled = true;
123 signalData.receivedTouchEvent = touch;
125 if ( signalData.createNewScene )
127 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
128 DALI_TEST_CHECK( scene );
130 signalData.newSceneCreated = true;
136 signalData.functorCalled = true;
139 TouchedSignalData& signalData;
142 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
143 struct WheelEventSignalData
145 WheelEventSignalData()
146 : functorCalled(false)
151 functorCalled = false;
155 WheelEvent receivedWheelEvent;
158 // Functor that sets the data when wheel-event signal is received
159 struct WheelEventReceivedFunctor
161 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
163 bool operator()( const WheelEvent& wheelEvent )
165 signalData.functorCalled = true;
166 signalData.receivedWheelEvent = wheelEvent;
171 WheelEventSignalData& signalData;
174 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
175 struct KeyEventGeneratedSignalData
177 KeyEventGeneratedSignalData()
178 : functorCalled(false)
183 functorCalled = false;
185 receivedKeyEvent.keyModifier = 0;
186 receivedKeyEvent.keyPressedName.clear();
187 receivedKeyEvent.keyPressed.clear();
191 KeyEvent receivedKeyEvent;
194 // Functor that sets the data when called
195 struct KeyEventGeneratedReceivedFunctor
197 KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
201 bool operator()( const KeyEvent& keyEvent )
203 signalData.functorCalled = true;
204 signalData.receivedKeyEvent = keyEvent;
211 signalData.functorCalled = true;
215 KeyEventGeneratedSignalData& signalData;
218 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
220 Integration::TouchEvent touchEvent;
221 Integration::Point point;
222 point.SetState( state );
223 point.SetScreenPosition( screenPosition );
224 touchEvent.points.push_back( point );
225 application.ProcessEvent( touchEvent );
228 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
233 void FrameCallback( int frameId )
237 } // unnamed namespace
239 int UtcDaliSceneAdd(void)
241 TestApplication application;
242 tet_infoline("Testing Dali::Integration::Scene::Add");
244 Dali::Integration::Scene scene = application.GetScene();
246 Actor actor = Actor::New();
247 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
250 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
255 int UtcDaliSceneRemove(void)
257 TestApplication application;
258 tet_infoline("Testing Dali::Integration::Scene::Remove");
260 Dali::Integration::Scene scene = application.GetScene();
262 Actor actor = Actor::New();
263 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
266 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
269 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
274 int UtcDaliSceneGetSize(void)
276 TestApplication application;
277 tet_infoline("Testing Dali::Integration::Scene::GetSize");
279 Dali::Integration::Scene scene = application.GetScene();
280 Size size = scene.GetSize();
281 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
282 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
287 int UtcDaliSceneGetDpi(void)
289 TestApplication application; // Initializes core DPI to default values
291 // Test that setting core DPI explicitly also sets up the scene's DPI.
292 Dali::Integration::Scene scene = application.GetScene();
293 scene.SetDpi( Vector2(200.0f, 180.0f) );
294 Vector2 dpi = scene.GetDpi();
295 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
296 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
300 int UtcDaliSceneGetRenderTaskList(void)
302 TestApplication application;
303 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
305 Dali::Integration::Scene scene = application.GetScene();
307 // Check we get a valid instance.
308 const RenderTaskList& tasks = scene.GetRenderTaskList();
310 // There should be 1 task by default.
311 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
313 // RenderTaskList has it's own UTC tests.
314 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
315 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
317 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
322 int UtcDaliSceneGetRootLayer(void)
324 TestApplication application;
325 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
327 Dali::Integration::Scene scene = application.GetScene();
328 Layer layer = scene.GetLayer( 0 );
329 DALI_TEST_CHECK( layer );
331 // Check that GetRootLayer() correctly retreived layer 0.
332 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
337 int UtcDaliSceneGetLayerCount(void)
339 TestApplication application;
340 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
342 Dali::Integration::Scene scene = application.GetScene();
343 // Initially we have a default layer
344 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
346 Layer layer = Layer::New();
349 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
353 int UtcDaliSceneGetLayer(void)
355 TestApplication application;
356 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
358 Dali::Integration::Scene scene = application.GetScene();
360 Layer rootLayer = scene.GetLayer( 0 );
361 DALI_TEST_CHECK( rootLayer );
363 Layer layer = Layer::New();
366 Layer sameLayer = scene.GetLayer( 1 );
367 DALI_TEST_CHECK( layer == sameLayer );
372 int UtcDaliSceneGet(void)
374 TestApplication application;
375 tet_infoline("Testing Dali::Integration::Scene::Get");
377 Dali::Integration::Scene scene = application.GetScene();
379 Actor actor = Actor::New();
380 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
384 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
389 int UtcDaliSceneDiscard(void)
391 TestApplication application;
392 tet_infoline("Testing Dali::Scene::Discard");
394 // Create a new Scene
395 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
396 DALI_TEST_CHECK( scene );
398 // One reference of scene kept here and the other one kept in the Core
399 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
401 // Render and notify.
402 application.SendNotification();
403 application.Render(0);
405 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
406 Layer rootLayer = scene.GetRootLayer();
407 DALI_TEST_CHECK( rootLayer );
408 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
410 // Request to discard the scene from the Core
412 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
414 // Reset the scene handle
417 // Render and notify.
418 application.SendNotification();
419 application.Render(0);
421 // At this point, the scene should have been automatically deleted
422 // To prove this, the ref count of the root layer handle should be decremented to 1
423 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
425 // Delete the root layer handle
428 // Render and notify.
429 application.SendNotification();
430 application.Render(0);
435 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
437 TestApplication application;
439 Dali::Integration::Scene scene = application.GetScene();
441 TouchedSignalData data;
442 data.createNewScene = true;
443 TouchFunctor functor( data );
444 scene.TouchSignal().Connect( &application, functor );
446 // Render and notify.
447 application.SendNotification();
448 application.Render();
450 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
452 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
453 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
454 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
460 int UtcDaliSceneRootLayerAndSceneAlignment(void)
462 TestApplication application;
465 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
466 DALI_TEST_CHECK( scene );
468 // One reference of scene kept here and the other one kept in the Core
469 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
471 // Add a renderable actor to the scene
472 auto actor = CreateRenderableActor();
475 // Render and notify.
476 application.SendNotification();
477 application.Render(0);
479 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
480 Layer rootLayer = scene.GetRootLayer();
481 DALI_TEST_CHECK( rootLayer );
482 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
484 // Request to discard the scene from the Core
486 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
488 // Reset the scene handle
491 // Render and notify.
492 application.SendNotification();
493 application.Render(0);
495 // At this point, the scene should have been automatically deleted
496 // To prove this, the ref count of the root layer handle should be decremented to 1
497 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
499 // Create a new Scene while the root layer of the deleted scene is still alive
500 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
501 DALI_TEST_CHECK( newScene );
503 // Render and notify.
504 application.SendNotification();
505 application.Render(0);
507 // At this point, we have only one scene but two root layers
508 // The root layer of the deleted scene is still alive
509 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
511 // Delete the root layer of the deleted scene
514 // Render and notify.
515 application.SendNotification();
516 application.Render(0);
521 int UtcDaliSceneEventProcessingFinishedP(void)
523 TestApplication application;
524 Dali::Integration::Scene scene = application.GetScene();
526 bool eventProcessingFinished = false;
527 EventProcessingFinishedFunctor functor( eventProcessingFinished );
528 scene.EventProcessingFinishedSignal().Connect( &application, functor );
530 Actor actor( Actor::New() );
533 application.SendNotification();
534 application.Render();
536 DALI_TEST_CHECK( eventProcessingFinished );
541 int UtcDaliSceneEventProcessingFinishedN(void)
543 TestApplication application;
544 Dali::Integration::Scene scene = application.GetScene();
546 bool eventProcessingFinished = false;
547 EventProcessingFinishedFunctor functor( eventProcessingFinished );
548 scene.EventProcessingFinishedSignal().Connect( &application, functor );
550 Actor actor( Actor::New() );
553 // Do not complete event processing and confirm the signal has not been emitted.
554 DALI_TEST_CHECK( !eventProcessingFinished );
559 int UtcDaliSceneSignalKeyEventP(void)
561 TestApplication application;
562 Dali::Integration::Scene scene = application.GetScene();
564 KeyEventSignalData data;
565 KeyEventReceivedFunctor functor( data );
566 scene.KeyEventSignal().Connect( &application, functor );
568 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
569 application.ProcessEvent( event );
571 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
572 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
573 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
574 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
575 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
579 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
580 application.ProcessEvent( event2 );
582 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
583 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
584 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
585 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
586 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
590 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
591 application.ProcessEvent( event3 );
593 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
594 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
595 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
596 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
597 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
601 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
602 application.ProcessEvent( event4 );
604 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
606 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
607 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
608 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
612 int UtcDaliSceneSignalKeyEventN(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 // Check that a non-pressed key events data is not modified.
622 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
627 int UtcDaliSceneTouchSignalP(void)
629 TestApplication application;
630 Dali::Integration::Scene scene = application.GetScene();
632 TouchedSignalData data;
633 TouchFunctor functor( data );
634 scene.TouchSignal().Connect( &application, functor );
636 // Render and notify.
637 application.SendNotification();
638 application.Render();
640 // Basic test: No actors, single touch (down then up).
642 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
644 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
645 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
646 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
649 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
651 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
652 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
653 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
657 // Add an actor to the scene.
658 Actor actor = Actor::New();
659 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
660 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
661 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
662 actor.TouchSignal().Connect( &DummyTouchCallback );
665 // Render and notify.
666 application.SendNotification();
667 application.Render();
669 // Actor on scene, single touch, down in actor, motion, then up outside actor.
671 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
673 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
674 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
675 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
678 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
680 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
683 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
685 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
686 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
687 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
691 // Multiple touch. Should only receive a touch on first down and last up.
693 Integration::TouchEvent touchEvent;
694 Integration::Point point;
697 point.SetState( PointState::DOWN );
698 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
699 touchEvent.points.push_back( point );
700 application.ProcessEvent( touchEvent );
701 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
702 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
706 touchEvent.points[0].SetState( PointState::STATIONARY );
707 point.SetDeviceId( 1 );
708 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
709 touchEvent.points.push_back( point );
710 application.ProcessEvent( touchEvent );
711 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
714 // Primary point is up
715 touchEvent.points[0].SetState( PointState::UP );
716 touchEvent.points[1].SetState( PointState::STATIONARY );
717 application.ProcessEvent( touchEvent );
718 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
721 // Remove 1st point now, 2nd point is now in motion
722 touchEvent.points.erase( touchEvent.points.begin() );
723 touchEvent.points[0].SetState( PointState::MOTION );
724 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
725 application.ProcessEvent( touchEvent );
726 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
730 touchEvent.points[0].SetState( PointState::UP );
731 application.ProcessEvent( touchEvent );
732 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
733 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
739 int UtcDaliSceneTouchSignalN(void)
741 TestApplication application;
742 Dali::Integration::Scene scene = application.GetScene();
744 TouchedSignalData data;
745 TouchFunctor functor( data );
746 scene.TouchSignal().Connect( &application, functor );
748 // Render and notify.
749 application.SendNotification();
750 application.Render();
752 // Confirm functor not called before there has been any touch event.
753 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
755 // No actors, single touch, down, motion then up.
757 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
759 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
760 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
761 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
765 // Confirm there is no signal when the touchpoint is only moved.
766 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
768 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
771 // Confirm a following up event generates a signal.
772 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
774 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
775 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
776 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
780 // Add an actor to the scene.
781 Actor actor = Actor::New();
782 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
783 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
784 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
785 actor.TouchSignal().Connect( &DummyTouchCallback );
788 // Render and notify.
789 application.SendNotification();
790 application.Render();
792 // Actor on scene. Interrupted before down and interrupted after down.
794 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
796 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
797 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
798 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
799 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
802 GenerateTouch( application, PointState::DOWN, Vector2( 10.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) == actor );
807 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::DOWN );
810 GenerateTouch( application, PointState::INTERRUPTED, 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) );
815 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
817 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
819 // Check that getting info about a non-existent point returns an empty handle
820 Actor actor = data.receivedTouchEvent.GetHitActor( 1 );
821 DALI_TEST_CHECK( !actor );
829 int UtcDaliSceneSignalWheelEventP(void)
831 TestApplication application;
832 Dali::Integration::Scene scene = application.GetScene();
834 WheelEventSignalData data;
835 WheelEventReceivedFunctor functor( data );
836 scene.WheelEventSignal().Connect( &application, functor );
838 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
839 application.ProcessEvent( event );
841 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
842 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.GetType() );
843 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.GetDirection() );
844 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.GetModifiers() );
845 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.GetPoint() );
846 DALI_TEST_CHECK( event.delta == data.receivedWheelEvent.GetDelta() );
847 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.GetTime() );
851 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
852 application.ProcessEvent( event2 );
854 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
855 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.GetType() );
856 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.GetDirection() );
857 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.GetModifiers() );
858 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.GetPoint() );
859 DALI_TEST_CHECK( event2.delta == data.receivedWheelEvent.GetDelta() );
860 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.GetTime() );
864 int UtcDaliSceneSurfaceResizedDefaultScene(void)
866 tet_infoline( "Ensure resizing of the surface is handled properly" );
868 TestApplication application;
870 auto defaultScene = application.GetScene();
871 DALI_TEST_CHECK( defaultScene );
873 // Ensure stage size matches the scene size
874 auto stage = Stage::GetCurrent();
875 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
878 Vector2 newSize( 1000.0f, 2000.0f );
879 DALI_TEST_CHECK( stage.GetSize() != newSize );
881 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
883 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
884 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
889 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
891 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
893 TestApplication application;
894 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
895 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
896 glAbstraction.EnableViewportCallTrace( true );
898 // Initial scene setup
899 Geometry geometry = CreateQuadGeometry();
900 Shader shader = CreateShader();
901 Renderer renderer = Renderer::New( geometry, shader );
903 Actor actor = Actor::New();
904 actor.AddRenderer(renderer);
905 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
906 application.GetScene().Add(actor);
908 // Render before resizing surface
909 application.SendNotification();
910 application.Render(0);
911 glAbstraction.ResetViewportCallStack();
913 auto defaultScene = application.GetScene();
914 DALI_TEST_CHECK( defaultScene );
916 // Ensure stage size matches the scene size
917 auto stage = Stage::GetCurrent();
918 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
921 Vector2 newSize( 1000.0f, 2000.0f );
922 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
923 DALI_TEST_CHECK( stage.GetSize() != newSize );
924 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
926 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
927 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
929 // Render after resizing surface
930 application.SendNotification();
931 application.Render(0);
933 // Check that the viewport is handled properly
934 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
939 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
941 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
943 TestApplication application;
944 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
945 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
946 glAbstraction.EnableViewportCallTrace( true );
948 // Initial scene setup
949 auto scene = application.GetScene();
951 Geometry geometry = CreateQuadGeometry();
952 Shader shader = CreateShader();
953 Renderer renderer = Renderer::New( geometry, shader );
955 Actor actor = Actor::New();
956 actor.AddRenderer(renderer);
958 int testHeight = 400;
959 actor.SetProperty( Actor::Property::SIZE, Vector2( testWidth, testHeight) );
962 CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
963 application.GetScene().Add( offscreenCameraActor );
965 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
967 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
968 newTask.SetCameraActor( offscreenCameraActor );
969 newTask.SetSourceActor( actor );
970 newTask.SetFrameBuffer( newFrameBuffer );
971 newTask.SetViewportPosition( Vector2(0, 0) );
972 newTask.SetViewportSize( Vector2(testWidth, testHeight) );
974 // Render before resizing surface
975 application.SendNotification();
976 application.Render(0);
977 glAbstraction.ResetViewportCallStack();
979 Rect<int32_t> initialViewport = newTask.GetViewport();
980 int initialWidth = initialViewport.width;
981 int initialHeight = initialViewport.height;
982 DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
983 DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
985 auto defaultScene = application.GetScene();
986 DALI_TEST_CHECK( defaultScene );
988 // Ensure stage size matches the scene size
989 auto stage = Stage::GetCurrent();
990 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
993 Vector2 newSize( 1000.0f, 2000.0f );
994 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
995 DALI_TEST_CHECK( stage.GetSize() != newSize );
996 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
998 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
999 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1001 // Render after resizing surface
1002 application.SendNotification();
1003 application.Render(0);
1005 // Check that the viewport is handled properly
1006 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1008 // Second render-task should not be affected
1009 Rect<int32_t> viewport = newTask.GetViewport();
1010 int width = viewport.width;
1011 int height = viewport.height;
1012 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1013 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1018 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1020 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1022 TestApplication application;
1023 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1025 auto scene = Integration::Scene::New( Size( originalSurfaceSize.width, originalSurfaceSize.height ) );
1027 // Ensure stage size does NOT match the surface size
1028 auto stage = Stage::GetCurrent();
1029 const auto stageSize = stage.GetSize();
1030 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1031 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1033 // Resize the surface and inform the scene accordingly
1034 Vector2 newSize( 1000.0f, 2000.0f );
1035 DALI_TEST_CHECK( stage.GetSize() != newSize );
1037 scene.SurfaceResized( newSize.width, newSize.height, 0, false );
1039 // Ensure the stage hasn't been resized
1040 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1041 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1046 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1048 TestApplication application;
1049 Dali::Integration::Scene scene = application.GetScene();
1051 KeyEventGeneratedSignalData data;
1052 KeyEventGeneratedReceivedFunctor functor( data );
1053 scene.KeyEventGeneratedSignal().Connect( &application, functor );
1055 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1056 application.ProcessEvent( event );
1058 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1059 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
1060 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
1061 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
1062 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1066 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1067 application.ProcessEvent( event2 );
1069 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1070 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
1071 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
1072 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
1073 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1077 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1078 application.ProcessEvent( event3 );
1080 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1081 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
1082 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
1083 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
1084 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1088 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1089 application.ProcessEvent( event4 );
1091 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1092 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
1093 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
1094 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
1095 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1099 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1101 tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1103 TestApplication application;
1105 // Create a new scene and set the background color of the main scene
1106 auto defaultScene = application.GetScene();
1107 defaultScene.SetBackgroundColor( Color::BLUE );
1109 // Need to create a renderable as we don't start rendering until we have at least one
1110 // We don't need to add this to any scene
1111 auto actor = CreateRenderableActor();
1113 auto& glAbstraction = application.GetGlAbstraction();
1114 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1116 application.SendNotification();
1117 application.Render();
1119 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1120 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1122 defaultScene.SurfaceReplaced();
1124 application.SendNotification();
1125 application.Render();
1127 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1128 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1130 // Check when the main render task viewport is set the clear color is clipped using scissors
1131 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1132 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1133 scissorTrace.Enable( true );
1134 enabledDisableTrace.Enable( true );
1136 defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1138 application.SendNotification();
1139 application.Render();
1141 // Check scissor test was enabled.
1142 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1144 // Check the scissor was set, and the coordinates are correct.
1145 DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1147 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1148 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1150 scissorTrace.Enable( false );
1151 scissorTrace.Reset();
1153 enabledDisableTrace.Enable( false );
1154 enabledDisableTrace.Reset();
1159 int UtcDaliSceneEmptySceneRendering(void)
1161 tet_infoline( "Ensure not rendering before a Renderer is added" );
1163 TestApplication application;
1164 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1166 // Render without any renderer
1167 application.SendNotification();
1168 application.Render();
1170 // Check the clear count and the render status
1171 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION );
1172 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), false, TEST_LOCATION );
1175 Geometry geometry = CreateQuadGeometry();
1176 Shader shader = CreateShader();
1177 Renderer renderer = Renderer::New( geometry, shader );
1179 Actor actor = Actor::New();
1180 actor.AddRenderer( renderer );
1182 actor.SetProperty( Actor::Property::SIZE, Vector2( 400, 400 ) );
1183 application.GetScene().Add( actor );
1186 application.SendNotification();
1187 application.Render();
1189 // Check the clear count and the render status
1190 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION );
1191 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1193 // Remove the Renderer
1194 application.GetScene().Remove( actor );
1199 application.SendNotification();
1200 application.Render();
1202 // Check the clear count and the render status
1203 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION ); // Should be cleared
1204 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1209 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1211 tet_infoline( "UtcDaliSceneFrameRenderedCallback" );
1213 TestApplication application;
1216 Geometry geometry = CreateQuadGeometry();
1217 Shader shader = CreateShader();
1218 Renderer renderer = Renderer::New( geometry, shader );
1220 Actor actor = Actor::New();
1221 actor.AddRenderer( renderer );
1222 application.GetScene().Add( actor );
1224 Dali::Integration::Scene scene = application.GetScene();
1227 scene.AddFrameRenderedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1228 scene.AddFramePresentedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1231 application.SendNotification();
1232 application.Render();
1234 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1235 scene.GetFrameRenderedCallback( callbackContainer );
1237 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1238 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );
1240 callbackContainer.clear();
1242 scene.GetFramePresentedCallback( callbackContainer );
1244 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1245 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );