2 * Copyright (c) 2019 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/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
27 #include <dali-test-suite-utils.h>
28 #include <mesh-builder.h>
30 // Internal headers are allowed here
35 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
37 // Functor for EventProcessingFinished signal
38 struct EventProcessingFinishedFunctor
41 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
43 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
44 : mEventProcessingFinished( eventProcessingFinished )
49 mEventProcessingFinished = true;
52 bool& mEventProcessingFinished;
55 // Stores data that is populated in the key-event callback and will be read by the TET cases
56 struct KeyEventSignalData
59 : functorCalled(false)
64 functorCalled = false;
66 receivedKeyEvent.keyModifier = 0;
67 receivedKeyEvent.keyPressedName.clear();
68 receivedKeyEvent.keyPressed.clear();
72 KeyEvent receivedKeyEvent;
75 // Functor that sets the data when called
76 struct KeyEventReceivedFunctor
78 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
80 bool operator()( const KeyEvent& keyEvent )
82 signalData.functorCalled = true;
83 signalData.receivedKeyEvent = keyEvent;
88 KeyEventSignalData& signalData;
91 // Stores data that is populated in the touched signal callback and will be read by the TET cases
92 struct TouchedSignalData
95 : functorCalled(false),
96 createNewScene(false),
97 newSceneCreated(false)
102 functorCalled = false;
103 createNewScene = false;
104 newSceneCreated = false;
106 receivedTouchEvent.points.clear();
107 receivedTouchEvent.time = 0;
109 receivedTouchData.Reset();
114 bool newSceneCreated;
115 TouchEvent receivedTouchEvent;
116 TouchData receivedTouchData;
119 // Functor that sets the data when touched signal is received
120 struct TouchedFunctor
122 TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
124 void operator()( const TouchEvent& touch )
126 signalData.functorCalled = true;
127 signalData.receivedTouchEvent = touch;
130 TouchedSignalData& signalData;
133 // Functor that sets the data when touched signal is received
136 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
138 void operator()( const TouchData& touch )
140 signalData.functorCalled = true;
141 signalData.receivedTouchData = touch;
143 if ( signalData.createNewScene )
145 TestRenderSurface* surface = new TestRenderSurface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); // This is a leak, but we need to keep the surface alive till the end
146 Dali::Integration::Scene scene = Dali::Integration::Scene::New( *surface );
147 DALI_TEST_CHECK( scene );
149 signalData.newSceneCreated = true;
155 signalData.functorCalled = true;
158 TouchedSignalData& signalData;
161 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
162 struct WheelEventSignalData
164 WheelEventSignalData()
165 : functorCalled(false)
170 functorCalled = false;
174 WheelEvent receivedWheelEvent;
177 // Functor that sets the data when wheel-event signal is received
178 struct WheelEventReceivedFunctor
180 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
182 bool operator()( const WheelEvent& wheelEvent )
184 signalData.functorCalled = true;
185 signalData.receivedWheelEvent = wheelEvent;
190 WheelEventSignalData& signalData;
193 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
195 Integration::TouchEvent touchEvent;
196 Integration::Point point;
197 point.SetState( state );
198 point.SetScreenPosition( screenPosition );
199 touchEvent.points.push_back( point );
200 application.ProcessEvent( touchEvent );
203 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
208 } // unnamed namespace
210 int UtcDaliSceneAdd(void)
212 TestApplication application;
213 tet_infoline("Testing Dali::Integration::Scene::Add");
215 Dali::Integration::Scene scene = application.GetScene();
217 Actor actor = Actor::New();
218 DALI_TEST_CHECK( !actor.OnStage() );
221 DALI_TEST_CHECK( actor.OnStage() );
226 int UtcDaliSceneRemove(void)
228 TestApplication application;
229 tet_infoline("Testing Dali::Integration::Scene::Remove");
231 Dali::Integration::Scene scene = application.GetScene();
233 Actor actor = Actor::New();
234 DALI_TEST_CHECK( !actor.OnStage() );
237 DALI_TEST_CHECK( actor.OnStage() );
240 DALI_TEST_CHECK( !actor.OnStage() );
245 int UtcDaliSceneGetSize(void)
247 TestApplication application;
248 tet_infoline("Testing Dali::Integration::Scene::GetSize");
250 Dali::Integration::Scene scene = application.GetScene();
251 Size size = scene.GetSize();
252 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
253 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
258 int UtcDaliSceneGetDpi(void)
260 TestApplication application; // Initializes core DPI to default values
262 // Test that setting core DPI explicitly also sets up the scene's DPI.
263 Dali::Integration::Scene scene = application.GetScene();
264 scene.SetDpi( Vector2(200.0f, 180.0f) );
265 Vector2 dpi = scene.GetDpi();
266 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
267 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
271 int UtcDaliSceneGetRenderTaskList(void)
273 TestApplication application;
274 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
276 Dali::Integration::Scene scene = application.GetScene();
278 // Check we get a valid instance.
279 const RenderTaskList& tasks = scene.GetRenderTaskList();
281 // There should be 1 task by default.
282 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
284 // RenderTaskList has it's own UTC tests.
285 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
286 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
288 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
293 int UtcDaliSceneGetRootLayer(void)
295 TestApplication application;
296 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
298 Dali::Integration::Scene scene = application.GetScene();
299 Layer layer = scene.GetLayer( 0 );
300 DALI_TEST_CHECK( layer );
302 // Check that GetRootLayer() correctly retreived layer 0.
303 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
308 int UtcDaliSceneGetLayerCount(void)
310 TestApplication application;
311 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
313 Dali::Integration::Scene scene = application.GetScene();
314 // Initially we have a default layer
315 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
317 Layer layer = Layer::New();
320 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
324 int UtcDaliSceneGetLayer(void)
326 TestApplication application;
327 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
329 Dali::Integration::Scene scene = application.GetScene();
331 Layer rootLayer = scene.GetLayer( 0 );
332 DALI_TEST_CHECK( rootLayer );
334 Layer layer = Layer::New();
337 Layer sameLayer = scene.GetLayer( 1 );
338 DALI_TEST_CHECK( layer == sameLayer );
343 int UtcDaliSceneGet(void)
345 TestApplication application;
346 tet_infoline("Testing Dali::Integration::Scene::Get");
348 Dali::Integration::Scene scene = application.GetScene();
350 Actor actor = Actor::New();
351 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
355 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
360 int UtcDaliSceneDiscard(void)
362 TestApplication application;
363 tet_infoline("Testing Dali::Scene::Discard");
365 // Create a new Scene
366 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
367 Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
368 DALI_TEST_CHECK( scene );
370 // One reference of scene kept here and the other one kept in the Core
371 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
373 // Render and notify.
374 application.SendNotification();
375 application.Render(0);
377 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
378 Layer rootLayer = scene.GetRootLayer();
379 DALI_TEST_CHECK( rootLayer );
380 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
382 // Request to discard the scene from the Core
384 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
386 // Reset the scene handle
389 // Render and notify.
390 application.SendNotification();
391 application.Render(0);
393 // At this point, the scene should have been automatically deleted
394 // To prove this, the ref count of the root layer handle should be decremented to 1
395 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
397 // Delete the root layer handle
400 // Render and notify.
401 application.SendNotification();
402 application.Render(0);
407 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
409 TestApplication application;
411 Dali::Integration::Scene scene = application.GetScene();
413 TouchedSignalData data;
414 data.createNewScene = true;
415 TouchFunctor functor( data );
416 scene.TouchSignal().Connect( &application, functor );
418 // Render and notify.
419 application.SendNotification();
420 application.Render();
422 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
424 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
425 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
426 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
432 int UtcDaliSceneRootLayerAndSceneAlignment(void)
434 TestApplication application;
437 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
438 Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
439 DALI_TEST_CHECK( scene );
441 // One reference of scene kept here and the other one kept in the Core
442 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
444 // Add a renderable actor to the scene
445 auto actor = CreateRenderableActor();
448 // Render and notify.
449 application.SendNotification();
450 application.Render(0);
452 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
453 Layer rootLayer = scene.GetRootLayer();
454 DALI_TEST_CHECK( rootLayer );
455 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
457 // Request to discard the scene from the Core
459 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
461 // Reset the scene handle
464 // Render and notify.
465 application.SendNotification();
466 application.Render(0);
468 // At this point, the scene should have been automatically deleted
469 // To prove this, the ref count of the root layer handle should be decremented to 1
470 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
472 // Create a new Scene while the root layer of the deleted scene is still alive
473 TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
474 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( surface2 );
475 DALI_TEST_CHECK( newScene );
477 // Render and notify.
478 application.SendNotification();
479 application.Render(0);
481 // At this point, we have only one scene but two root layers
482 // The root layer of the deleted scene is still alive
483 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
485 // Delete the root layer of the deleted scene
488 // Render and notify.
489 application.SendNotification();
490 application.Render(0);
495 int UtcDaliSceneDeleteSurface(void)
497 TestApplication application;
499 // Create the render surface for the scene
500 TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
503 Dali::Integration::Scene scene = Dali::Integration::Scene::New( *renderSurface );
504 DALI_TEST_CHECK( scene );
506 // Render and notify.
507 application.SendNotification();
508 application.Render(0);
510 // Add a renderable actor to the scene
511 auto actor = CreateRenderableActor();
514 // Render and notify.
515 application.SendNotification();
516 application.Render(0);
518 // Notify the Core that the render surface will be deleted.
519 application.GetCore().SurfaceDeleted( renderSurface );
521 // Delete the render surface
522 delete renderSurface;
523 renderSurface = nullptr;
525 // Render and notify.
526 application.SendNotification();
527 application.Render(0);
532 int UtcDaliSceneEventProcessingFinishedP(void)
534 TestApplication application;
535 Dali::Integration::Scene scene = application.GetScene();
537 bool eventProcessingFinished = false;
538 EventProcessingFinishedFunctor functor( eventProcessingFinished );
539 scene.EventProcessingFinishedSignal().Connect( &application, functor );
541 Actor actor( Actor::New() );
544 application.SendNotification();
545 application.Render();
547 DALI_TEST_CHECK( eventProcessingFinished );
552 int UtcDaliSceneEventProcessingFinishedN(void)
554 TestApplication application;
555 Dali::Integration::Scene scene = application.GetScene();
557 bool eventProcessingFinished = false;
558 EventProcessingFinishedFunctor functor( eventProcessingFinished );
559 scene.EventProcessingFinishedSignal().Connect( &application, functor );
561 Actor actor( Actor::New() );
564 // Do not complete event processing and confirm the signal has not been emitted.
565 DALI_TEST_CHECK( !eventProcessingFinished );
570 int UtcDaliSceneSignalKeyEventP(void)
572 TestApplication application;
573 Dali::Integration::Scene scene = application.GetScene();
575 KeyEventSignalData data;
576 KeyEventReceivedFunctor functor( data );
577 scene.KeyEventSignal().Connect( &application, functor );
579 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
580 application.ProcessEvent( event );
582 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
583 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
584 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
585 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
586 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
590 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
591 application.ProcessEvent( event2 );
593 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
594 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
595 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
596 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
597 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
601 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
602 application.ProcessEvent( event3 );
604 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
606 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
607 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
608 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
612 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
613 application.ProcessEvent( event4 );
615 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
616 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
617 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
618 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
619 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
623 int UtcDaliSceneSignalKeyEventN(void)
625 TestApplication application;
626 Dali::Integration::Scene scene = application.GetScene();
628 KeyEventSignalData data;
629 KeyEventReceivedFunctor functor( data );
630 scene.KeyEventSignal().Connect( &application, functor );
632 // Check that a non-pressed key events data is not modified.
633 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
638 int UtcDaliSceneTouchSignalP(void)
640 TestApplication application;
641 Dali::Integration::Scene scene = application.GetScene();
643 TouchedSignalData data;
644 TouchFunctor functor( data );
645 scene.TouchSignal().Connect( &application, functor );
647 // Render and notify.
648 application.SendNotification();
649 application.Render();
651 // Basic test: No actors, single touch (down then up).
653 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
655 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
656 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
657 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
660 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
662 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
663 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
664 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
668 // Add an actor to the scene.
669 Actor actor = Actor::New();
670 actor.SetSize( 100.0f, 100.0f );
671 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
672 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
673 actor.TouchedSignal().Connect( &DummyTouchCallback );
676 // Render and notify.
677 application.SendNotification();
678 application.Render();
680 // Actor on scene, single touch, down in actor, motion, then up outside actor.
682 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
684 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
685 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
686 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
689 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
691 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
694 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
696 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
697 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
698 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
702 // Multiple touch. Should only receive a touch on first down and last up.
704 Integration::TouchEvent touchEvent;
705 Integration::Point point;
708 point.SetState( PointState::DOWN );
709 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
710 touchEvent.points.push_back( point );
711 application.ProcessEvent( touchEvent );
712 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
713 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
717 touchEvent.points[0].SetState( PointState::STATIONARY );
718 point.SetDeviceId( 1 );
719 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
720 touchEvent.points.push_back( point );
721 application.ProcessEvent( touchEvent );
722 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
725 // Primary point is up
726 touchEvent.points[0].SetState( PointState::UP );
727 touchEvent.points[1].SetState( PointState::STATIONARY );
728 application.ProcessEvent( touchEvent );
729 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
732 // Remove 1st point now, 2nd point is now in motion
733 touchEvent.points.erase( touchEvent.points.begin() );
734 touchEvent.points[0].SetState( PointState::MOTION );
735 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
736 application.ProcessEvent( touchEvent );
737 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
741 touchEvent.points[0].SetState( PointState::UP );
742 application.ProcessEvent( touchEvent );
743 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
744 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
750 int UtcDaliSceneTouchSignalN(void)
752 TestApplication application;
753 Dali::Integration::Scene scene = application.GetScene();
755 TouchedSignalData data;
756 TouchFunctor functor( data );
757 scene.TouchSignal().Connect( &application, functor );
759 // Render and notify.
760 application.SendNotification();
761 application.Render();
763 // Confirm functor not called before there has been any touch event.
764 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
766 // No actors, single touch, down, motion then up.
768 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
770 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
771 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
772 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
776 // Confirm there is no signal when the touchpoint is only moved.
777 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
779 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
782 // Confirm a following up event generates a signal.
783 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
785 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
786 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
787 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
791 // Add an actor to the scene.
792 Actor actor = Actor::New();
793 actor.SetSize( 100.0f, 100.0f );
794 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
795 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
796 actor.TouchedSignal().Connect( &DummyTouchCallback );
799 // Render and notify.
800 application.SendNotification();
801 application.Render();
803 // Actor on scene. Interrupted before down and interrupted after down.
805 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
807 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
808 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
809 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
810 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
813 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
815 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
816 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
817 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
818 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
821 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
823 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
824 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
825 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
826 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
828 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
830 // Check that getting info about a non-existent point returns an empty handle
831 Actor actor = data.receivedTouchData.GetHitActor( 1 );
832 DALI_TEST_CHECK( !actor );
840 int UtcDaliSceneSignalWheelEventP(void)
842 TestApplication application;
843 Dali::Integration::Scene scene = application.GetScene();
845 WheelEventSignalData data;
846 WheelEventReceivedFunctor functor( data );
847 scene.WheelEventSignal().Connect( &application, functor );
849 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
850 application.ProcessEvent( event );
852 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
853 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
854 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
855 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
856 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
857 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
858 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
862 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
863 application.ProcessEvent( event2 );
865 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
866 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
867 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
868 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
869 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
870 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
871 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
875 int UtcDaliSceneEnsureEmptySceneCleared(void)
877 tet_infoline( "Ensure we clear the newly added window" );
879 TestApplication application;
881 // Create a new scene and set the background colors of both the new and the main scenes
882 auto defaultScene = application.GetScene();
883 defaultScene.SetBackgroundColor( Color::WHITE );
885 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
886 auto newScene = Integration::Scene::New( surface );
887 newScene.SetBackgroundColor( Color::RED );
889 // Need to create a renderable as we don't start rendering until we have at least one
890 // We don't need to add this to any scene
891 auto actor = CreateRenderableActor();
893 auto& glAbstraction = application.GetGlAbstraction();
894 auto clearCountBefore = glAbstraction.GetClearCountCalled();
896 application.SendNotification();
897 application.Render();
899 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
901 // Add the actor to the main scene
902 defaultScene.Add( actor );
904 application.SendNotification();
905 application.Render();
907 // Add another scene and set its background color, ensure we clear it to the appropriate color
909 TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
910 auto thirdScene = Integration::Scene::New( surface2 );
911 thirdScene.SetBackgroundColor( Color::BLUE );
913 clearCountBefore = glAbstraction.GetClearCountCalled();
915 application.SendNotification();
916 application.Render();
918 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
923 int UtcDaliSceneSurfaceResizedDefaultScene(void)
925 tet_infoline( "Ensure resizing of the surface is handled properly" );
927 TestApplication application;
929 auto defaultScene = application.GetScene();
930 Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
931 DALI_TEST_CHECK( defaultSurface );
933 // Ensure stage size matches the surface size
934 auto stage = Stage::GetCurrent();
935 DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
937 // Resize the surface and inform the scene accordingly
938 Vector2 newSize( 1000.0f, 2000.0f );
939 DALI_TEST_CHECK( stage.GetSize() != newSize );
940 defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
941 defaultScene.SurfaceResized( false );
943 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
944 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
949 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
951 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
953 TestApplication application;
954 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
955 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
956 glAbstraction.EnableViewportCallTrace( true );
958 // Initial scene setup
959 Geometry geometry = CreateQuadGeometry();
960 Shader shader = CreateShader();
961 Renderer renderer = Renderer::New( geometry, shader );
963 Actor actor = Actor::New();
964 actor.AddRenderer(renderer);
965 actor.SetSize(400, 400);
966 Stage::GetCurrent().Add(actor);
968 // Render before resizing surface
969 application.SendNotification();
970 application.Render(0);
971 glAbstraction.ResetViewportCallStack();
973 auto defaultScene = application.GetScene();
974 Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
975 DALI_TEST_CHECK( defaultSurface );
977 // Ensure stage size matches the surface size
978 auto stage = Stage::GetCurrent();
979 DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
981 // Resize the surface and inform the scene accordingly
982 Vector2 newSize( 1000.0f, 2000.0f );
983 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
984 DALI_TEST_CHECK( stage.GetSize() != newSize );
985 defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
986 defaultScene.SurfaceResized();
988 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
989 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
991 // Render after resizing surface
992 application.SendNotification();
993 application.Render(0);
995 // Check that the viewport is handled properly
996 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1001 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
1003 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
1005 TestApplication application;
1006 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1007 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
1008 glAbstraction.EnableViewportCallTrace( true );
1010 // Initial scene setup
1011 auto stage = Stage::GetCurrent();
1013 Geometry geometry = CreateQuadGeometry();
1014 Shader shader = CreateShader();
1015 Renderer renderer = Renderer::New( geometry, shader );
1017 Actor actor = Actor::New();
1018 actor.AddRenderer(renderer);
1019 int testWidth = 400;
1020 int testHeight = 400;
1021 actor.SetSize(testWidth, testHeight);
1024 CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
1025 Stage::GetCurrent().Add( offscreenCameraActor );
1027 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
1029 RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1030 newTask.SetCameraActor( offscreenCameraActor );
1031 newTask.SetSourceActor( actor );
1032 newTask.SetFrameBuffer( newFrameBuffer );
1033 newTask.SetViewportPosition( Vector2(0, 0) );
1034 newTask.SetViewportSize( Vector2(testWidth, testHeight) );
1036 // Render before resizing surface
1037 application.SendNotification();
1038 application.Render(0);
1039 glAbstraction.ResetViewportCallStack();
1041 Rect<int32_t> initialViewport = newTask.GetViewport();
1042 int initialWidth = initialViewport.width;
1043 int initialHeight = initialViewport.height;
1044 DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
1045 DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
1047 auto defaultScene = application.GetScene();
1048 Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
1049 DALI_TEST_CHECK( defaultSurface );
1051 // Ensure stage size matches the surface size
1052 DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
1054 // Resize the surface and inform the scene accordingly
1055 Vector2 newSize( 800.0f, 480.0f );
1056 std::string viewportParams( "0, 0, 800, 480" ); // to match newSize
1057 DALI_TEST_CHECK( stage.GetSize() != newSize );
1058 defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1059 defaultScene.SurfaceResized();
1061 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1062 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1064 // Render after resizing surface
1065 application.SendNotification();
1066 application.Render(0);
1068 // Check that the viewport is handled properly
1069 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1071 // Second render-task should not be affected
1072 Rect<int32_t> viewport = newTask.GetViewport();
1073 int width = viewport.width;
1074 int height = viewport.height;
1075 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1076 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1081 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1083 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1085 TestApplication application;
1086 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1088 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
1090 auto scene = Integration::Scene::New( surface );
1092 scene.SetSurface( surface, false );
1093 >>>>>>> e6df4fb... Support Client and Screen Rotation
1095 // Ensure stage size does NOT match the surface size
1096 auto stage = Stage::GetCurrent();
1097 const auto stageSize = stage.GetSize();
1098 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1099 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1101 // Resize the surface and inform the scene accordingly
1102 Vector2 newSize( 1000.0f, 2000.0f );
1103 DALI_TEST_CHECK( stage.GetSize() != newSize );
1104 surface.MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1105 scene.SurfaceResized( false );
1107 // Ensure the stage hasn't been resized
1108 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1109 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1114 int UtcDaliSceneSetSurface(void)
1116 tet_infoline( "Scene::SetSurface test" );
1118 TestApplication application;
1120 // Create a scene with a surface and ensure the size and surface is set correctly on the scene
1121 Vector2 surfaceSize( 480.0f, 800.0f );
1122 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, surfaceSize.width, surfaceSize.height ) );
1123 auto scene = Integration::Scene::New( surface );
1124 DALI_TEST_EQUALS( scene.GetSize(), surfaceSize, TEST_LOCATION );
1125 DALI_TEST_CHECK( scene.GetSurface() == &surface );
1127 // Create a new surface and set that on the scene
1128 Vector2 newSurfaceSize( 1000.0f, 1000.0f );
1129 TestRenderSurface newSurface( PositionSize( 0.0f, 0.0f, newSurfaceSize.width, newSurfaceSize.height ) );
1130 scene.SetSurface( newSurface );
1131 DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
1132 DALI_TEST_CHECK( scene.GetSurface() == &newSurface );
1134 // Ensure setting the same surface again doesn't have any side effects
1135 scene.SetSurface( newSurface );
1136 DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
1137 DALI_TEST_CHECK( scene.GetSurface() == &newSurface );