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.Reset();
71 KeyEvent receivedKeyEvent;
74 // Functor that sets the data when called
75 struct KeyEventReceivedFunctor
77 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
79 bool operator()( const KeyEvent& keyEvent )
81 signalData.functorCalled = true;
82 signalData.receivedKeyEvent = keyEvent;
87 KeyEventSignalData& signalData;
90 // Stores data that is populated in the touched signal callback and will be read by the TET cases
91 struct TouchedSignalData
94 : functorCalled(false),
95 createNewScene(false),
96 newSceneCreated(false)
101 functorCalled = false;
102 createNewScene = false;
103 newSceneCreated = false;
104 receivedTouchEvent.Reset();
109 bool newSceneCreated;
110 TouchEvent receivedTouchEvent;
113 // Functor that sets the data when touched signal is received
116 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
118 void operator()( const TouchEvent& touch )
120 signalData.functorCalled = true;
121 signalData.receivedTouchEvent = touch;
123 if ( signalData.createNewScene )
125 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
126 DALI_TEST_CHECK( scene );
128 signalData.newSceneCreated = true;
134 signalData.functorCalled = true;
137 TouchedSignalData& signalData;
140 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
141 struct WheelEventSignalData
143 WheelEventSignalData()
144 : functorCalled(false)
149 functorCalled = false;
153 WheelEvent receivedWheelEvent;
156 // Functor that sets the data when wheel-event signal is received
157 struct WheelEventReceivedFunctor
159 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
161 bool operator()( const WheelEvent& wheelEvent )
163 signalData.functorCalled = true;
164 signalData.receivedWheelEvent = wheelEvent;
169 WheelEventSignalData& signalData;
172 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
173 struct KeyEventGeneratedSignalData
175 KeyEventGeneratedSignalData()
176 : functorCalled(false)
181 functorCalled = false;
183 receivedKeyEvent.Reset();
187 KeyEvent receivedKeyEvent;
190 // Functor that sets the data when called
191 struct KeyEventGeneratedReceivedFunctor
193 KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
197 bool operator()( const KeyEvent& keyEvent )
199 signalData.functorCalled = true;
200 signalData.receivedKeyEvent = keyEvent;
207 signalData.functorCalled = true;
211 KeyEventGeneratedSignalData& signalData;
214 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
216 Integration::TouchEvent touchEvent;
217 Integration::Point point;
218 point.SetState( state );
219 point.SetScreenPosition( screenPosition );
220 touchEvent.points.push_back( point );
221 application.ProcessEvent( touchEvent );
224 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
229 void FrameCallback( int frameId )
233 } // unnamed namespace
235 int UtcDaliSceneAdd(void)
237 TestApplication application;
238 tet_infoline("Testing Dali::Integration::Scene::Add");
240 Dali::Integration::Scene scene = application.GetScene();
242 Actor actor = Actor::New();
243 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
246 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
251 int UtcDaliSceneRemove(void)
253 TestApplication application;
254 tet_infoline("Testing Dali::Integration::Scene::Remove");
256 Dali::Integration::Scene scene = application.GetScene();
258 Actor actor = Actor::New();
259 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
262 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
265 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
270 int UtcDaliSceneGetSize(void)
272 TestApplication application;
273 tet_infoline("Testing Dali::Integration::Scene::GetSize");
275 Dali::Integration::Scene scene = application.GetScene();
276 Size size = scene.GetSize();
277 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
278 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
283 int UtcDaliSceneGetDpi(void)
285 TestApplication application; // Initializes core DPI to default values
287 // Test that setting core DPI explicitly also sets up the scene's DPI.
288 Dali::Integration::Scene scene = application.GetScene();
289 scene.SetDpi( Vector2(200.0f, 180.0f) );
290 Vector2 dpi = scene.GetDpi();
291 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
292 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
296 int UtcDaliSceneGetRenderTaskList(void)
298 TestApplication application;
299 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
301 Dali::Integration::Scene scene = application.GetScene();
303 // Check we get a valid instance.
304 const RenderTaskList& tasks = scene.GetRenderTaskList();
306 // There should be 1 task by default.
307 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
309 // RenderTaskList has it's own UTC tests.
310 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
311 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
313 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
318 int UtcDaliSceneGetRootLayer(void)
320 TestApplication application;
321 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
323 Dali::Integration::Scene scene = application.GetScene();
324 Layer layer = scene.GetLayer( 0 );
325 DALI_TEST_CHECK( layer );
327 // Check that GetRootLayer() correctly retreived layer 0.
328 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
333 int UtcDaliSceneGetLayerCount(void)
335 TestApplication application;
336 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
338 Dali::Integration::Scene scene = application.GetScene();
339 // Initially we have a default layer
340 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
342 Layer layer = Layer::New();
345 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
349 int UtcDaliSceneGetLayer(void)
351 TestApplication application;
352 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
354 Dali::Integration::Scene scene = application.GetScene();
356 Layer rootLayer = scene.GetLayer( 0 );
357 DALI_TEST_CHECK( rootLayer );
359 Layer layer = Layer::New();
362 Layer sameLayer = scene.GetLayer( 1 );
363 DALI_TEST_CHECK( layer == sameLayer );
368 int UtcDaliSceneGet(void)
370 TestApplication application;
371 tet_infoline("Testing Dali::Integration::Scene::Get");
373 Dali::Integration::Scene scene = application.GetScene();
375 Actor actor = Actor::New();
376 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
380 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
385 int UtcDaliSceneDiscard(void)
387 TestApplication application;
388 tet_infoline("Testing Dali::Scene::Discard");
390 // Create a new Scene
391 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
392 DALI_TEST_CHECK( scene );
394 // One reference of scene kept here and the other one kept in the Core
395 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
397 // Render and notify.
398 application.SendNotification();
399 application.Render(0);
401 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
402 Layer rootLayer = scene.GetRootLayer();
403 DALI_TEST_CHECK( rootLayer );
404 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
406 // Request to discard the scene from the Core
408 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
410 // Reset the scene handle
413 // Render and notify.
414 application.SendNotification();
415 application.Render(0);
417 // At this point, the scene should have been automatically deleted
418 // To prove this, the ref count of the root layer handle should be decremented to 1
419 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
421 // Delete the root layer handle
424 // Render and notify.
425 application.SendNotification();
426 application.Render(0);
431 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
433 TestApplication application;
435 Dali::Integration::Scene scene = application.GetScene();
437 TouchedSignalData data;
438 data.createNewScene = true;
439 TouchFunctor functor( data );
440 scene.TouchSignal().Connect( &application, functor );
442 // Render and notify.
443 application.SendNotification();
444 application.Render();
446 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
448 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
449 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
450 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
456 int UtcDaliSceneRootLayerAndSceneAlignment(void)
458 TestApplication application;
461 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
462 DALI_TEST_CHECK( scene );
464 // One reference of scene kept here and the other one kept in the Core
465 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
467 // Add a renderable actor to the scene
468 auto actor = CreateRenderableActor();
471 // Render and notify.
472 application.SendNotification();
473 application.Render(0);
475 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
476 Layer rootLayer = scene.GetRootLayer();
477 DALI_TEST_CHECK( rootLayer );
478 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
480 // Request to discard the scene from the Core
482 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
484 // Reset the scene handle
487 // Render and notify.
488 application.SendNotification();
489 application.Render(0);
491 // At this point, the scene should have been automatically deleted
492 // To prove this, the ref count of the root layer handle should be decremented to 1
493 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
495 // Create a new Scene while the root layer of the deleted scene is still alive
496 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
497 DALI_TEST_CHECK( newScene );
499 // Render and notify.
500 application.SendNotification();
501 application.Render(0);
503 // At this point, we have only one scene but two root layers
504 // The root layer of the deleted scene is still alive
505 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
507 // Delete the root layer of the deleted scene
510 // Render and notify.
511 application.SendNotification();
512 application.Render(0);
517 int UtcDaliSceneEventProcessingFinishedP(void)
519 TestApplication application;
520 Dali::Integration::Scene scene = application.GetScene();
522 bool eventProcessingFinished = false;
523 EventProcessingFinishedFunctor functor( eventProcessingFinished );
524 scene.EventProcessingFinishedSignal().Connect( &application, functor );
526 Actor actor( Actor::New() );
529 application.SendNotification();
530 application.Render();
532 DALI_TEST_CHECK( eventProcessingFinished );
537 int UtcDaliSceneEventProcessingFinishedN(void)
539 TestApplication application;
540 Dali::Integration::Scene scene = application.GetScene();
542 bool eventProcessingFinished = false;
543 EventProcessingFinishedFunctor functor( eventProcessingFinished );
544 scene.EventProcessingFinishedSignal().Connect( &application, functor );
546 Actor actor( Actor::New() );
549 // Do not complete event processing and confirm the signal has not been emitted.
550 DALI_TEST_CHECK( !eventProcessingFinished );
555 int UtcDaliSceneSignalKeyEventP(void)
557 TestApplication application;
558 Dali::Integration::Scene scene = application.GetScene();
560 KeyEventSignalData data;
561 KeyEventReceivedFunctor functor( data );
562 scene.KeyEventSignal().Connect( &application, functor );
564 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
565 application.ProcessEvent( event );
567 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
568 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
569 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.GetKeyName() );
570 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.GetKeyString() );
571 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
575 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
576 application.ProcessEvent( event2 );
578 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
579 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
580 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.GetKeyName() );
581 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.GetKeyString() );
582 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
586 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
587 application.ProcessEvent( event3 );
589 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
590 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
591 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.GetKeyName() );
592 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.GetKeyString() );
593 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
597 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
598 application.ProcessEvent( event4 );
600 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
601 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
602 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.GetKeyName() );
603 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.GetKeyString() );
604 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
608 int UtcDaliSceneSignalKeyEventN(void)
610 TestApplication application;
611 Dali::Integration::Scene scene = application.GetScene();
613 KeyEventSignalData data;
614 KeyEventReceivedFunctor functor( data );
615 scene.KeyEventSignal().Connect( &application, functor );
617 // Check that a non-pressed key events data is not modified.
618 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
623 int UtcDaliSceneTouchSignalP(void)
625 TestApplication application;
626 Dali::Integration::Scene scene = application.GetScene();
628 TouchedSignalData data;
629 TouchFunctor functor( data );
630 scene.TouchSignal().Connect( &application, functor );
632 // Render and notify.
633 application.SendNotification();
634 application.Render();
636 // Basic test: No actors, single touch (down then up).
638 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
640 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
641 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
642 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
645 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
647 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
648 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
649 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
653 // Add an actor to the scene.
654 Actor actor = Actor::New();
655 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
656 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
657 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
658 actor.TouchSignal().Connect( &DummyTouchCallback );
661 // Render and notify.
662 application.SendNotification();
663 application.Render();
665 // Actor on scene, single touch, down in actor, motion, then up outside actor.
667 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
669 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
670 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
671 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
674 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
676 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
679 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
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 // Multiple touch. Should only receive a touch on first down and last up.
689 Integration::TouchEvent touchEvent;
690 Integration::Point point;
693 point.SetState( PointState::DOWN );
694 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
695 touchEvent.points.push_back( point );
696 application.ProcessEvent( touchEvent );
697 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
698 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
702 touchEvent.points[0].SetState( PointState::STATIONARY );
703 point.SetDeviceId( 1 );
704 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
705 touchEvent.points.push_back( point );
706 application.ProcessEvent( touchEvent );
707 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
710 // Primary point is up
711 touchEvent.points[0].SetState( PointState::UP );
712 touchEvent.points[1].SetState( PointState::STATIONARY );
713 application.ProcessEvent( touchEvent );
714 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
717 // Remove 1st point now, 2nd point is now in motion
718 touchEvent.points.erase( touchEvent.points.begin() );
719 touchEvent.points[0].SetState( PointState::MOTION );
720 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
721 application.ProcessEvent( touchEvent );
722 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
726 touchEvent.points[0].SetState( PointState::UP );
727 application.ProcessEvent( touchEvent );
728 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
729 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
735 int UtcDaliSceneTouchSignalN(void)
737 TestApplication application;
738 Dali::Integration::Scene scene = application.GetScene();
740 TouchedSignalData data;
741 TouchFunctor functor( data );
742 scene.TouchSignal().Connect( &application, functor );
744 // Render and notify.
745 application.SendNotification();
746 application.Render();
748 // Confirm functor not called before there has been any touch event.
749 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
751 // No actors, single touch, down, motion then up.
753 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
755 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
756 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
757 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
761 // Confirm there is no signal when the touchpoint is only moved.
762 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
764 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
767 // Confirm a following up event generates a signal.
768 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
770 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
771 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
772 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
776 // Add an actor to the scene.
777 Actor actor = Actor::New();
778 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
779 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
780 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
781 actor.TouchSignal().Connect( &DummyTouchCallback );
784 // Render and notify.
785 application.SendNotification();
786 application.Render();
788 // Actor on scene. Interrupted before down and interrupted after down.
790 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
792 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
793 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
794 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
795 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
798 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
800 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
801 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
802 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
803 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::DOWN );
806 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
808 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
809 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
810 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
811 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
813 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
815 // Check that getting info about a non-existent point returns an empty handle
816 Actor actor = data.receivedTouchEvent.GetHitActor( 1 );
817 DALI_TEST_CHECK( !actor );
825 int UtcDaliSceneSignalWheelEventP(void)
827 TestApplication application;
828 Dali::Integration::Scene scene = application.GetScene();
830 WheelEventSignalData data;
831 WheelEventReceivedFunctor functor( data );
832 scene.WheelEventSignal().Connect( &application, functor );
834 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
835 application.ProcessEvent( event );
837 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
838 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.GetType() );
839 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.GetDirection() );
840 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.GetModifiers() );
841 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.GetPoint() );
842 DALI_TEST_CHECK( event.delta == data.receivedWheelEvent.GetDelta() );
843 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.GetTime() );
847 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
848 application.ProcessEvent( event2 );
850 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
851 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.GetType() );
852 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.GetDirection() );
853 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.GetModifiers() );
854 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.GetPoint() );
855 DALI_TEST_CHECK( event2.delta == data.receivedWheelEvent.GetDelta() );
856 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.GetTime() );
860 int UtcDaliSceneSurfaceResizedDefaultScene(void)
862 tet_infoline( "Ensure resizing of the surface is handled properly" );
864 TestApplication application;
866 auto defaultScene = application.GetScene();
867 DALI_TEST_CHECK( defaultScene );
869 // Ensure stage size matches the scene size
870 auto stage = Stage::GetCurrent();
871 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
874 Vector2 newSize( 1000.0f, 2000.0f );
875 DALI_TEST_CHECK( stage.GetSize() != newSize );
877 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
879 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
880 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
885 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
887 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
889 TestApplication application;
890 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
891 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
892 glAbstraction.EnableViewportCallTrace( true );
894 // Initial scene setup
895 Geometry geometry = CreateQuadGeometry();
896 Shader shader = CreateShader();
897 Renderer renderer = Renderer::New( geometry, shader );
899 Actor actor = Actor::New();
900 actor.AddRenderer(renderer);
901 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
902 application.GetScene().Add(actor);
904 // Render before resizing surface
905 application.SendNotification();
906 application.Render(0);
907 glAbstraction.ResetViewportCallStack();
909 auto defaultScene = application.GetScene();
910 DALI_TEST_CHECK( defaultScene );
912 // Ensure stage size matches the scene size
913 auto stage = Stage::GetCurrent();
914 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
917 Vector2 newSize( 1000.0f, 2000.0f );
918 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
919 DALI_TEST_CHECK( stage.GetSize() != newSize );
920 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
922 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
923 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
925 // Render after resizing surface
926 application.SendNotification();
927 application.Render(0);
929 // Check that the viewport is handled properly
930 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
935 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
937 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
939 TestApplication application;
940 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
941 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
942 glAbstraction.EnableViewportCallTrace( true );
944 // Initial scene setup
945 auto scene = application.GetScene();
947 Geometry geometry = CreateQuadGeometry();
948 Shader shader = CreateShader();
949 Renderer renderer = Renderer::New( geometry, shader );
951 Actor actor = Actor::New();
952 actor.AddRenderer(renderer);
954 int testHeight = 400;
955 actor.SetProperty( Actor::Property::SIZE, Vector2( testWidth, testHeight) );
958 CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
959 application.GetScene().Add( offscreenCameraActor );
961 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
963 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
964 newTask.SetCameraActor( offscreenCameraActor );
965 newTask.SetSourceActor( actor );
966 newTask.SetFrameBuffer( newFrameBuffer );
967 newTask.SetViewportPosition( Vector2(0, 0) );
968 newTask.SetViewportSize( Vector2(testWidth, testHeight) );
970 // Render before resizing surface
971 application.SendNotification();
972 application.Render(0);
973 glAbstraction.ResetViewportCallStack();
975 Rect<int32_t> initialViewport = newTask.GetViewport();
976 int initialWidth = initialViewport.width;
977 int initialHeight = initialViewport.height;
978 DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
979 DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
981 auto defaultScene = application.GetScene();
982 DALI_TEST_CHECK( defaultScene );
984 // Ensure stage size matches the scene size
985 auto stage = Stage::GetCurrent();
986 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
989 Vector2 newSize( 1000.0f, 2000.0f );
990 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
991 DALI_TEST_CHECK( stage.GetSize() != newSize );
992 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
994 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
995 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
997 // Render after resizing surface
998 application.SendNotification();
999 application.Render(0);
1001 // Check that the viewport is handled properly
1002 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1004 // Second render-task should not be affected
1005 Rect<int32_t> viewport = newTask.GetViewport();
1006 int width = viewport.width;
1007 int height = viewport.height;
1008 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1009 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1014 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1016 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1018 TestApplication application;
1019 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1021 auto scene = Integration::Scene::New( Size( originalSurfaceSize.width, originalSurfaceSize.height ) );
1023 // Ensure stage size does NOT match the surface size
1024 auto stage = Stage::GetCurrent();
1025 const auto stageSize = stage.GetSize();
1026 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1027 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1029 // Resize the surface and inform the scene accordingly
1030 Vector2 newSize( 1000.0f, 2000.0f );
1031 DALI_TEST_CHECK( stage.GetSize() != newSize );
1033 scene.SurfaceResized( newSize.width, newSize.height, 0, false );
1035 // Ensure the stage hasn't been resized
1036 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1037 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1042 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1044 TestApplication application;
1045 Dali::Integration::Scene scene = application.GetScene();
1047 KeyEventGeneratedSignalData data;
1048 KeyEventGeneratedReceivedFunctor functor( data );
1049 scene.KeyEventGeneratedSignal().Connect( &application, functor );
1051 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1052 application.ProcessEvent( event );
1054 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1055 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
1056 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.GetKeyName() );
1057 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.GetKeyString() );
1058 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
1062 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1063 application.ProcessEvent( event2 );
1065 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1066 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
1067 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.GetKeyName() );
1068 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.GetKeyString() );
1069 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
1073 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1074 application.ProcessEvent( event3 );
1076 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1077 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
1078 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.GetKeyName() );
1079 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.GetKeyString() );
1080 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
1084 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1085 application.ProcessEvent( event4 );
1087 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1088 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
1089 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.GetKeyName() );
1090 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.GetKeyString() );
1091 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
1095 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1097 tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1099 TestApplication application;
1101 // Create a new scene and set the background color of the main scene
1102 auto defaultScene = application.GetScene();
1103 defaultScene.SetBackgroundColor( Color::BLUE );
1105 // Need to create a renderable as we don't start rendering until we have at least one
1106 // We don't need to add this to any scene
1107 auto actor = CreateRenderableActor();
1109 auto& glAbstraction = application.GetGlAbstraction();
1110 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1112 application.SendNotification();
1113 application.Render();
1115 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1116 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1118 defaultScene.SurfaceReplaced();
1120 application.SendNotification();
1121 application.Render();
1123 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1124 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1126 // Check when the main render task viewport is set the clear color is clipped using scissors
1127 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1128 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1129 scissorTrace.Enable( true );
1130 enabledDisableTrace.Enable( true );
1132 defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1134 application.SendNotification();
1135 application.Render();
1137 // Check scissor test was enabled.
1138 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1140 // Check the scissor was set, and the coordinates are correct.
1141 DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1143 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1144 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1146 scissorTrace.Enable( false );
1147 scissorTrace.Reset();
1149 enabledDisableTrace.Enable( false );
1150 enabledDisableTrace.Reset();
1155 int UtcDaliSceneEmptySceneRendering(void)
1157 tet_infoline( "Ensure not rendering before a Renderer is added" );
1159 TestApplication application;
1160 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1162 // Render without any renderer
1163 application.SendNotification();
1164 application.Render();
1166 // Check the clear count and the render status
1167 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION );
1168 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), false, TEST_LOCATION );
1171 Geometry geometry = CreateQuadGeometry();
1172 Shader shader = CreateShader();
1173 Renderer renderer = Renderer::New( geometry, shader );
1175 Actor actor = Actor::New();
1176 actor.AddRenderer( renderer );
1178 actor.SetProperty( Actor::Property::SIZE, Vector2( 400, 400 ) );
1179 application.GetScene().Add( actor );
1182 application.SendNotification();
1183 application.Render();
1185 // Check the clear count and the render status
1186 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION );
1187 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1189 // Remove the Renderer
1190 application.GetScene().Remove( actor );
1195 application.SendNotification();
1196 application.Render();
1198 // Check the clear count and the render status
1199 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION ); // Should be cleared
1200 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1205 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1207 tet_infoline( "UtcDaliSceneFrameRenderedCallback" );
1209 TestApplication application;
1212 Geometry geometry = CreateQuadGeometry();
1213 Shader shader = CreateShader();
1214 Renderer renderer = Renderer::New( geometry, shader );
1216 Actor actor = Actor::New();
1217 actor.AddRenderer( renderer );
1218 application.GetScene().Add( actor );
1220 Dali::Integration::Scene scene = application.GetScene();
1223 scene.AddFrameRenderedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1224 scene.AddFramePresentedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1227 application.SendNotification();
1228 application.Render();
1230 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1231 scene.GetFrameRenderedCallback( callbackContainer );
1233 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1234 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );
1236 callbackContainer.clear();
1238 scene.GetFramePresentedCallback( callbackContainer );
1240 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1241 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );