Merge "(Partial Update) Set the updated flag when the Renderer is added/removed"...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Scene.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/common/stage.h>
20 #include <dali/integration-api/events/key-event-integ.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/wheel-event-integ.h>
23 #include <dali/integration-api/scene.h>
24 #include <dali/public-api/events/key-event.h>
25 #include <mesh-builder.h>
26 #include <stdlib.h>
27
28 #include <iostream>
29
30 // Internal headers are allowed here
31
32 namespace
33 {
34 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
35
36 // Functor for EventProcessingFinished signal
37 struct EventProcessingFinishedFunctor
38 {
39   /**
40    * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
41    */
42   EventProcessingFinishedFunctor(bool& eventProcessingFinished)
43   : mEventProcessingFinished(eventProcessingFinished)
44   {
45   }
46
47   void operator()()
48   {
49     mEventProcessingFinished = true;
50   }
51
52   bool& mEventProcessingFinished;
53 };
54
55 // Stores data that is populated in the key-event callback and will be read by the TET cases
56 struct KeyEventSignalData
57 {
58   KeyEventSignalData()
59   : functorCalled(false)
60   {
61   }
62
63   void Reset()
64   {
65     functorCalled = false;
66
67     receivedKeyEvent.Reset();
68   }
69
70   bool     functorCalled;
71   KeyEvent receivedKeyEvent;
72 };
73
74 // Functor that sets the data when called
75 struct KeyEventReceivedFunctor
76 {
77   KeyEventReceivedFunctor(KeyEventSignalData& data)
78   : signalData(data)
79   {
80   }
81
82   bool operator()(const KeyEvent& keyEvent)
83   {
84     signalData.functorCalled    = true;
85     signalData.receivedKeyEvent = keyEvent;
86
87     return true;
88   }
89
90   KeyEventSignalData& signalData;
91 };
92
93 // Stores data that is populated in the touched signal callback and will be read by the TET cases
94 struct TouchedSignalData
95 {
96   TouchedSignalData()
97   : functorCalled(false),
98     createNewScene(false),
99     newSceneCreated(false)
100   {
101   }
102
103   void Reset()
104   {
105     functorCalled   = false;
106     createNewScene  = false;
107     newSceneCreated = false;
108     receivedTouchEvent.Reset();
109   }
110
111   bool       functorCalled;
112   bool       createNewScene;
113   bool       newSceneCreated;
114   TouchEvent receivedTouchEvent;
115 };
116
117 // Functor that sets the data when touched signal is received
118 struct TouchFunctor
119 {
120   TouchFunctor(TouchedSignalData& data)
121   : signalData(data)
122   {
123   }
124
125   void operator()(const TouchEvent& touch)
126   {
127     signalData.functorCalled      = true;
128     signalData.receivedTouchEvent = touch;
129
130     if(signalData.createNewScene)
131     {
132       Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
133       DALI_TEST_CHECK(scene);
134
135       signalData.newSceneCreated = true;
136     }
137   }
138
139   void operator()()
140   {
141     signalData.functorCalled = true;
142   }
143
144   TouchedSignalData& signalData;
145 };
146
147 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
148 struct WheelEventSignalData
149 {
150   WheelEventSignalData()
151   : functorCalled(false)
152   {
153   }
154
155   void Reset()
156   {
157     functorCalled = false;
158   }
159
160   bool       functorCalled;
161   WheelEvent receivedWheelEvent;
162 };
163
164 // Functor that sets the data when wheel-event signal is received
165 struct WheelEventReceivedFunctor
166 {
167   WheelEventReceivedFunctor(WheelEventSignalData& data)
168   : signalData(data)
169   {
170   }
171
172   bool operator()(const WheelEvent& wheelEvent)
173   {
174     signalData.functorCalled      = true;
175     signalData.receivedWheelEvent = wheelEvent;
176
177     return true;
178   }
179
180   WheelEventSignalData& signalData;
181 };
182
183 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
184 struct KeyEventGeneratedSignalData
185 {
186   KeyEventGeneratedSignalData()
187   : functorCalled(false)
188   {
189   }
190
191   void Reset()
192   {
193     functorCalled = false;
194
195     receivedKeyEvent.Reset();
196   }
197
198   bool     functorCalled;
199   KeyEvent receivedKeyEvent;
200 };
201
202 // Functor that sets the data when called
203 struct KeyEventGeneratedReceivedFunctor
204 {
205   KeyEventGeneratedReceivedFunctor(KeyEventGeneratedSignalData& data)
206   : signalData(data)
207   {
208   }
209
210   bool operator()(const KeyEvent& keyEvent)
211   {
212     signalData.functorCalled    = true;
213     signalData.receivedKeyEvent = keyEvent;
214
215     return true;
216   }
217
218   bool operator()()
219   {
220     signalData.functorCalled = true;
221     return true;
222   }
223
224   KeyEventGeneratedSignalData& signalData;
225 };
226
227 // Stores data that is populated in the WheelEventGeneratedSignal callback and will be read by the TET cases
228 struct WheelEventGeneratedSignalData
229 {
230   WheelEventGeneratedSignalData()
231   : functorCalled(false)
232   {
233   }
234
235   void Reset()
236   {
237     functorCalled = false;
238
239     receivedWheelEvent.Reset();
240   }
241
242   bool       functorCalled;
243   WheelEvent receivedWheelEvent;
244 };
245
246 // Functor that sets the data when called
247 struct WheelEventGeneratedReceivedFunctor
248 {
249   WheelEventGeneratedReceivedFunctor(WheelEventGeneratedSignalData& data)
250   : signalData(data)
251   {
252   }
253
254   bool operator()(const WheelEvent& wheelEvent)
255   {
256     signalData.functorCalled      = true;
257     signalData.receivedWheelEvent = wheelEvent;
258
259     return true;
260   }
261
262   bool operator()()
263   {
264     signalData.functorCalled = true;
265     return true;
266   }
267
268   WheelEventGeneratedSignalData& signalData;
269 };
270
271 void GenerateTouch(TestApplication& application, PointState::Type state, const Vector2& screenPosition)
272 {
273   Integration::TouchEvent touchEvent;
274   Integration::Point      point;
275   point.SetState(state);
276   point.SetScreenPosition(screenPosition);
277   touchEvent.points.push_back(point);
278   application.ProcessEvent(touchEvent);
279 }
280
281 bool DummyTouchCallback(Actor actor, const TouchEvent& touch)
282 {
283   return true;
284 }
285
286 void FrameCallback(int frameId)
287 {
288 }
289
290 } // unnamed namespace
291
292 int UtcDaliSceneAdd(void)
293 {
294   TestApplication application;
295   tet_infoline("Testing Dali::Integration::Scene::Add");
296
297   Dali::Integration::Scene scene = application.GetScene();
298
299   Actor actor = Actor::New();
300   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
301
302   scene.Add(actor);
303   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
304
305   END_TEST;
306 }
307
308 int UtcDaliSceneRemove(void)
309 {
310   TestApplication application;
311   tet_infoline("Testing Dali::Integration::Scene::Remove");
312
313   Dali::Integration::Scene scene = application.GetScene();
314
315   Actor actor = Actor::New();
316   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
317
318   scene.Add(actor);
319   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
320
321   scene.Remove(actor);
322   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
323
324   END_TEST;
325 }
326
327 int UtcDaliSceneGetSize(void)
328 {
329   TestApplication application;
330   tet_infoline("Testing Dali::Integration::Scene::GetSize");
331
332   Dali::Integration::Scene scene = application.GetScene();
333   Size                     size  = scene.GetSize();
334   DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION);
335   DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION);
336
337   END_TEST;
338 }
339
340 int UtcDaliSceneGetDpi(void)
341 {
342   TestApplication application; // Initializes core DPI to default values
343
344   // Test that setting core DPI explicitly also sets up the scene's DPI.
345   Dali::Integration::Scene scene = application.GetScene();
346   scene.SetDpi(Vector2(200.0f, 180.0f));
347   Vector2 dpi = scene.GetDpi();
348   DALI_TEST_EQUALS(dpi.x, 200.0f, TEST_LOCATION);
349   DALI_TEST_EQUALS(dpi.y, 180.0f, TEST_LOCATION);
350   END_TEST;
351 }
352
353 int UtcDaliSceneGetRenderTaskList(void)
354 {
355   TestApplication application;
356   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
357
358   Dali::Integration::Scene scene = application.GetScene();
359
360   // Check we get a valid instance.
361   const RenderTaskList& tasks = scene.GetRenderTaskList();
362
363   // There should be 1 task by default.
364   DALI_TEST_EQUALS(tasks.GetTaskCount(), 1u, TEST_LOCATION);
365
366   // RenderTaskList has it's own UTC tests.
367   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
368   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
369
370   DALI_TEST_EQUALS(scene.GetRenderTaskList().GetTask(1), newTask, TEST_LOCATION);
371
372   END_TEST;
373 }
374
375 int UtcDaliSceneGetRootLayer(void)
376 {
377   TestApplication application;
378   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
379
380   Dali::Integration::Scene scene = application.GetScene();
381   Layer                    layer = scene.GetLayer(0);
382   DALI_TEST_CHECK(layer);
383
384   // Check that GetRootLayer() correctly retreived layer 0.
385   DALI_TEST_CHECK(scene.GetRootLayer() == layer);
386
387   END_TEST;
388 }
389
390 int UtcDaliSceneGetLayerCount(void)
391 {
392   TestApplication application;
393   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
394
395   Dali::Integration::Scene scene = application.GetScene();
396   // Initially we have a default layer
397   DALI_TEST_EQUALS(scene.GetLayerCount(), 1u, TEST_LOCATION);
398
399   Layer layer = Layer::New();
400   scene.Add(layer);
401
402   DALI_TEST_EQUALS(scene.GetLayerCount(), 2u, TEST_LOCATION);
403   END_TEST;
404 }
405
406 int UtcDaliSceneGetLayer(void)
407 {
408   TestApplication application;
409   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
410
411   Dali::Integration::Scene scene = application.GetScene();
412
413   Layer rootLayer = scene.GetLayer(0);
414   DALI_TEST_CHECK(rootLayer);
415
416   Layer layer = Layer::New();
417   scene.Add(layer);
418
419   Layer sameLayer = scene.GetLayer(1);
420   DALI_TEST_CHECK(layer == sameLayer);
421
422   END_TEST;
423 }
424
425 int UtcDaliSceneGet(void)
426 {
427   TestApplication application;
428   tet_infoline("Testing Dali::Integration::Scene::Get");
429
430   Dali::Integration::Scene scene = application.GetScene();
431
432   Actor actor = Actor::New();
433   DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(actor));
434
435   scene.Add(actor);
436
437   DALI_TEST_CHECK(scene == Dali::Integration::Scene::Get(actor));
438
439   END_TEST;
440 }
441
442 int UtcDaliSceneDiscard(void)
443 {
444   TestApplication application;
445   tet_infoline("Testing Dali::Scene::Discard");
446
447   // Create a new Scene
448   Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
449   DALI_TEST_CHECK(scene);
450
451   // One reference of scene kept here and the other one kept in the Core
452   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
453
454   // Render and notify.
455   application.SendNotification();
456   application.Render(0);
457
458   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
459   Layer rootLayer = scene.GetRootLayer();
460   DALI_TEST_CHECK(rootLayer);
461   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
462
463   // Request to discard the scene from the Core
464   scene.Discard();
465   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
466
467   // Reset the scene handle
468   scene.Reset();
469
470   // Render and notify.
471   application.SendNotification();
472   application.Render(0);
473
474   // At this point, the scene should have been automatically deleted
475   // To prove this, the ref count of the root layer handle should be decremented to 1
476   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
477
478   // Delete the root layer handle
479   rootLayer.Reset();
480
481   // Render and notify.
482   application.SendNotification();
483   application.Render(0);
484
485   END_TEST;
486 }
487
488 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
489 {
490   TestApplication application;
491
492   Dali::Integration::Scene scene = application.GetScene();
493
494   TouchedSignalData data;
495   data.createNewScene = true;
496   TouchFunctor functor(data);
497   scene.TouchedSignal().Connect(&application, functor);
498
499   // Render and notify.
500   application.SendNotification();
501   application.Render();
502
503   GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
504
505   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
506   DALI_TEST_EQUALS(true, data.createNewScene, TEST_LOCATION);
507   DALI_TEST_EQUALS(true, data.newSceneCreated, TEST_LOCATION);
508   data.Reset();
509
510   END_TEST;
511 }
512
513 int UtcDaliSceneRootLayerAndSceneAlignment(void)
514 {
515   TestApplication application;
516
517   // Create a Scene
518   Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
519   DALI_TEST_CHECK(scene);
520
521   // One reference of scene kept here and the other one kept in the Core
522   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
523
524   // Add a renderable actor to the scene
525   auto actor = CreateRenderableActor();
526   scene.Add(actor);
527
528   // Render and notify.
529   application.SendNotification();
530   application.Render(0);
531
532   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
533   Layer rootLayer = scene.GetRootLayer();
534   DALI_TEST_CHECK(rootLayer);
535   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
536
537   // Request to discard the scene from the Core
538   scene.Discard();
539   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
540
541   // Reset the scene handle
542   scene.Reset();
543
544   // Render and notify.
545   application.SendNotification();
546   application.Render(0);
547
548   // At this point, the scene should have been automatically deleted
549   // To prove this, the ref count of the root layer handle should be decremented to 1
550   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
551
552   // Create a new Scene while the root layer of the deleted scene is still alive
553   Dali::Integration::Scene newScene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
554   DALI_TEST_CHECK(newScene);
555
556   // Render and notify.
557   application.SendNotification();
558   application.Render(0);
559
560   // At this point, we have only one scene but two root layers
561   // The root layer of the deleted scene is still alive
562   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
563
564   // Delete the root layer of the deleted scene
565   rootLayer.Reset();
566
567   // Render and notify.
568   application.SendNotification();
569   application.Render(0);
570
571   END_TEST;
572 }
573
574 int UtcDaliSceneEventProcessingFinishedP(void)
575 {
576   TestApplication          application;
577   Dali::Integration::Scene scene = application.GetScene();
578
579   bool                           eventProcessingFinished = false;
580   EventProcessingFinishedFunctor functor(eventProcessingFinished);
581   scene.EventProcessingFinishedSignal().Connect(&application, functor);
582
583   Actor actor(Actor::New());
584   scene.Add(actor);
585
586   application.SendNotification();
587   application.Render();
588
589   DALI_TEST_CHECK(eventProcessingFinished);
590
591   END_TEST;
592 }
593
594 int UtcDaliSceneEventProcessingFinishedN(void)
595 {
596   TestApplication          application;
597   Dali::Integration::Scene scene = application.GetScene();
598
599   bool                           eventProcessingFinished = false;
600   EventProcessingFinishedFunctor functor(eventProcessingFinished);
601   scene.EventProcessingFinishedSignal().Connect(&application, functor);
602
603   Actor actor(Actor::New());
604   scene.Add(actor);
605
606   // Do not complete event processing and confirm the signal has not been emitted.
607   DALI_TEST_CHECK(!eventProcessingFinished);
608
609   END_TEST;
610 }
611
612 int UtcDaliSceneSignalKeyEventP(void)
613 {
614   TestApplication          application;
615   Dali::Integration::Scene scene = application.GetScene();
616
617   KeyEventSignalData      data;
618   KeyEventReceivedFunctor functor(data);
619   scene.KeyEventSignal().Connect(&application, functor);
620
621   Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
622   application.ProcessEvent(event);
623
624   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
625   DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
626   DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
627   DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
628   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
629
630   data.Reset();
631
632   Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
633   application.ProcessEvent(event2);
634
635   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
636   DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
637   DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
638   DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
639   DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
640
641   data.Reset();
642
643   Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
644   application.ProcessEvent(event3);
645
646   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
647   DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
648   DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
649   DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
650   DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
651
652   data.Reset();
653
654   Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
655   application.ProcessEvent(event4);
656
657   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
658   DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
659   DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
660   DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
661   DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
662   END_TEST;
663 }
664
665 int UtcDaliSceneSignalKeyEventN(void)
666 {
667   TestApplication          application;
668   Dali::Integration::Scene scene = application.GetScene();
669
670   KeyEventSignalData      data;
671   KeyEventReceivedFunctor functor(data);
672   scene.KeyEventSignal().Connect(&application, functor);
673
674   // Check that a non-pressed key events data is not modified.
675   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
676
677   END_TEST;
678 }
679
680 int UtcDaliSceneTouchedSignalP(void)
681 {
682   TestApplication          application;
683   Dali::Integration::Scene scene = application.GetScene();
684
685   TouchedSignalData data;
686   TouchFunctor      functor(data);
687   scene.TouchedSignal().Connect(&application, functor);
688
689   // Render and notify.
690   application.SendNotification();
691   application.Render();
692
693   // Basic test: No actors, single touch (down then up).
694   {
695     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
696
697     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
699     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
700     data.Reset();
701
702     GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f));
703
704     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
705     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
706     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
707     data.Reset();
708   }
709
710   // Add an actor to the scene.
711   Actor actor = Actor::New();
712   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
713   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
714   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
715   actor.TouchedSignal().Connect(&DummyTouchCallback);
716   scene.Add(actor);
717
718   // Render and notify.
719   application.SendNotification();
720   application.Render();
721
722   // Actor on scene, single touch, down in actor, motion, then up outside actor.
723   {
724     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
725
726     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
727     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
728     DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
729     data.Reset();
730
731     GenerateTouch(application, PointState::MOTION, Vector2(150.0f, 10.0f)); // Some motion
732
733     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
734     data.Reset();
735
736     GenerateTouch(application, PointState::UP, Vector2(150.0f, 10.0f)); // Some motion
737
738     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
739     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
740     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
741     data.Reset();
742   }
743
744   // Multiple touch. Should only receive a touch on first down and last up.
745   {
746     Integration::TouchEvent touchEvent;
747     Integration::Point      point;
748
749     // 1st point
750     point.SetState(PointState::DOWN);
751     point.SetScreenPosition(Vector2(10.0f, 10.0f));
752     touchEvent.points.push_back(point);
753     application.ProcessEvent(touchEvent);
754     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
755     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
756     data.Reset();
757
758     // 2nd point
759     touchEvent.points[0].SetState(PointState::STATIONARY);
760     point.SetDeviceId(1);
761     point.SetScreenPosition(Vector2(50.0f, 50.0f));
762     touchEvent.points.push_back(point);
763     application.ProcessEvent(touchEvent);
764     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
765     data.Reset();
766
767     // Primary point is up
768     touchEvent.points[0].SetState(PointState::UP);
769     touchEvent.points[1].SetState(PointState::STATIONARY);
770     application.ProcessEvent(touchEvent);
771     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
772     data.Reset();
773
774     // Remove 1st point now, 2nd point is now in motion
775     touchEvent.points.erase(touchEvent.points.begin());
776     touchEvent.points[0].SetState(PointState::MOTION);
777     touchEvent.points[0].SetScreenPosition(Vector2(150.0f, 50.0f));
778     application.ProcessEvent(touchEvent);
779     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
780     data.Reset();
781
782     // Final point Up
783     touchEvent.points[0].SetState(PointState::UP);
784     application.ProcessEvent(touchEvent);
785     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
786     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
787     data.Reset();
788   }
789   END_TEST;
790 }
791
792 int UtcDaliSceneTouchedSignalN(void)
793 {
794   TestApplication          application;
795   Dali::Integration::Scene scene = application.GetScene();
796
797   TouchedSignalData data;
798   TouchFunctor      functor(data);
799   scene.TouchedSignal().Connect(&application, functor);
800
801   // Render and notify.
802   application.SendNotification();
803   application.Render();
804
805   // Confirm functor not called before there has been any touch event.
806   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
807
808   // No actors, single touch, down, motion then up.
809   {
810     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
811
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
816     data.Reset();
817
818     // Confirm there is no signal when the touchpoint is only moved.
819     GenerateTouch(application, PointState::MOTION, Vector2(1200.0f, 10.0f)); // Some motion
820
821     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
822     data.Reset();
823
824     // Confirm a following up event generates a signal.
825     GenerateTouch(application, PointState::UP, Vector2(1200.0f, 10.0f));
826
827     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
828     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
829     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
830     data.Reset();
831   }
832
833   // Add an actor to the scene.
834   Actor actor = Actor::New();
835   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
836   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
837   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
838   actor.TouchedSignal().Connect(&DummyTouchCallback);
839   scene.Add(actor);
840
841   // Render and notify.
842   application.SendNotification();
843   application.Render();
844
845   // Actor on scene. Interrupted before down and interrupted after down.
846   {
847     GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
848
849     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
850     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
851     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
852     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
853     data.Reset();
854
855     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
856
857     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
858     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
859     DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
860     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::DOWN);
861     data.Reset();
862
863     GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
864
865     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
866     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
867     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
868     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
869
870     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
871
872     // Check that getting info about a non-existent point returns an empty handle
873     Actor actor = data.receivedTouchEvent.GetHitActor(1);
874     DALI_TEST_CHECK(!actor);
875
876     data.Reset();
877   }
878
879   END_TEST;
880 }
881
882 int UtcDaliSceneSignalWheelEventP(void)
883 {
884   TestApplication          application;
885   Dali::Integration::Scene scene = application.GetScene();
886
887   WheelEventSignalData      data;
888   WheelEventReceivedFunctor functor(data);
889   scene.WheelEventSignal().Connect(&application, functor);
890
891   Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
892   application.ProcessEvent(event);
893
894   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
895   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
896   DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
897   DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
898   DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
899   DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
900   DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
901
902   data.Reset();
903
904   Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
905   application.ProcessEvent(event2);
906
907   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
908   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
909   DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
910   DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
911   DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
912   DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
913   DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
914   END_TEST;
915 }
916
917 int UtcDaliSceneSurfaceResizedDefaultScene(void)
918 {
919   tet_infoline("Ensure resizing of the surface is handled properly");
920
921   TestApplication application;
922
923   auto defaultScene = application.GetScene();
924   DALI_TEST_CHECK(defaultScene);
925
926   // Ensure stage size matches the scene size
927   auto stage = Stage::GetCurrent();
928   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
929
930   // Resize the scene
931   Vector2 newSize(1000.0f, 2000.0f);
932   DALI_TEST_CHECK(stage.GetSize() != newSize);
933   defaultScene.SurfaceResized(newSize.width, newSize.height);
934
935   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
936   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
937
938   END_TEST;
939 }
940
941 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
942 {
943   tet_infoline("Ensure resizing of the surface & viewport is handled properly");
944
945   TestApplication    application;
946   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
947   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
948   glAbstraction.EnableViewportCallTrace(true);
949
950   // Initial scene setup
951   Geometry geometry = CreateQuadGeometry();
952   Shader   shader   = CreateShader();
953   Renderer renderer = Renderer::New(geometry, shader);
954
955   Actor actor = Actor::New();
956   actor.AddRenderer(renderer);
957   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
958   application.GetScene().Add(actor);
959
960   // Render before resizing surface
961   application.SendNotification();
962   application.Render(0);
963   glAbstraction.ResetViewportCallStack();
964
965   auto defaultScene = application.GetScene();
966   DALI_TEST_CHECK(defaultScene);
967
968   // consume the resize flag by first rendering
969   defaultScene.IsSurfaceRectChanged();
970
971   // Ensure stage size matches the scene size
972   auto stage = Stage::GetCurrent();
973   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
974
975   Rect<int32_t> surfaceRect = defaultScene.GetCurrentSurfaceRect();
976
977   bool surfaceResized;
978   // check resized flag before surface is resized.
979   surfaceResized = defaultScene.IsSurfaceRectChanged();
980   DALI_TEST_EQUALS(surfaceResized, false, TEST_LOCATION);
981
982   // Resize the scene
983   Vector2     newSize(1000.0f, 2000.0f);
984   std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
985   DALI_TEST_CHECK(stage.GetSize() != newSize);
986   defaultScene.SurfaceResized(newSize.width, newSize.height);
987
988   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
989   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
990
991   // Check current surface rect
992   Rect<int32_t> newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
993
994   // It should not be changed yet.
995   DALI_TEST_CHECK(surfaceRect == newSurfaceRect);
996
997   // Render after resizing surface
998   application.SendNotification();
999   application.Render(0);
1000
1001   surfaceResized = defaultScene.IsSurfaceRectChanged();
1002   DALI_TEST_EQUALS(surfaceResized, true, TEST_LOCATION);
1003
1004   // Check that the viewport is handled properly
1005   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1006
1007   // Check current surface rect
1008   newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
1009
1010   // It should be changed
1011   DALI_TEST_EQUALS(newSurfaceRect.x, 0, TEST_LOCATION);
1012   DALI_TEST_EQUALS(newSurfaceRect.y, 0, TEST_LOCATION);
1013   DALI_TEST_EQUALS(newSurfaceRect.width, 1000, TEST_LOCATION);
1014   DALI_TEST_EQUALS(newSurfaceRect.height, 2000, TEST_LOCATION);
1015
1016   END_TEST;
1017 }
1018
1019 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
1020 {
1021   tet_infoline("Ensure resizing of the surface & viewport is handled properly");
1022
1023   TestApplication    application;
1024   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1025   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
1026   glAbstraction.EnableViewportCallTrace(true);
1027
1028   // Initial scene setup
1029   auto scene = application.GetScene();
1030
1031   Geometry geometry = CreateQuadGeometry();
1032   Shader   shader   = CreateShader();
1033   Renderer renderer = Renderer::New(geometry, shader);
1034
1035   Actor actor = Actor::New();
1036   actor.AddRenderer(renderer);
1037   int testWidth  = 400;
1038   int testHeight = 400;
1039   actor.SetProperty(Actor::Property::SIZE, Vector2(testWidth, testHeight));
1040   scene.Add(actor);
1041
1042   CameraActor offscreenCameraActor = CameraActor::New(Size(testWidth, testHeight));
1043   application.GetScene().Add(offscreenCameraActor);
1044
1045   FrameBuffer newFrameBuffer = FrameBuffer::New(testWidth, testHeight, FrameBuffer::Attachment::NONE);
1046
1047   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
1048   newTask.SetCameraActor(offscreenCameraActor);
1049   newTask.SetSourceActor(actor);
1050   newTask.SetFrameBuffer(newFrameBuffer);
1051   newTask.SetViewportPosition(Vector2(0, 0));
1052   newTask.SetViewportSize(Vector2(testWidth, testHeight));
1053
1054   // Render before resizing surface
1055   application.SendNotification();
1056   application.Render(0);
1057   glAbstraction.ResetViewportCallStack();
1058
1059   Rect<int32_t> initialViewport = newTask.GetViewport();
1060   int           initialWidth    = initialViewport.width;
1061   int           initialHeight   = initialViewport.height;
1062   DALI_TEST_EQUALS(initialWidth, testWidth, TEST_LOCATION);
1063   DALI_TEST_EQUALS(initialHeight, testHeight, TEST_LOCATION);
1064
1065   auto defaultScene = application.GetScene();
1066   DALI_TEST_CHECK(defaultScene);
1067
1068   // Ensure stage size matches the scene size
1069   auto stage = Stage::GetCurrent();
1070   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
1071
1072   // Resize the scene
1073   Vector2     newSize(1000.0f, 2000.0f);
1074   std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
1075   DALI_TEST_CHECK(stage.GetSize() != newSize);
1076   defaultScene.SurfaceResized(newSize.width, newSize.height);
1077
1078   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
1079   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
1080
1081   // Render after resizing surface
1082   application.SendNotification();
1083   application.Render(0);
1084
1085   // Check that the viewport is handled properly
1086   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1087
1088   // Second render-task should not be affected
1089   Rect<int32_t> viewport = newTask.GetViewport();
1090   int           width    = viewport.width;
1091   int           height   = viewport.height;
1092   DALI_TEST_EQUALS(width, testWidth, TEST_LOCATION);
1093   DALI_TEST_EQUALS(height, testHeight, TEST_LOCATION);
1094
1095   END_TEST;
1096 }
1097
1098 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1099 {
1100   tet_infoline("Ensure resizing of the surface is handled properly on additional scenes");
1101
1102   TestApplication application;
1103   Vector2         originalSurfaceSize(500.0f, 1000.0f);
1104
1105   auto scene = Integration::Scene::New(Size(originalSurfaceSize.width, originalSurfaceSize.height));
1106
1107   // Ensure stage size does NOT match the surface size
1108   auto       stage     = Stage::GetCurrent();
1109   const auto stageSize = stage.GetSize();
1110   DALI_TEST_CHECK(stageSize != originalSurfaceSize);
1111   DALI_TEST_EQUALS(originalSurfaceSize, scene.GetSize(), TEST_LOCATION);
1112
1113   // Resize the surface and inform the scene accordingly
1114   Vector2 newSize(1000.0f, 2000.0f);
1115   DALI_TEST_CHECK(stage.GetSize() != newSize);
1116   scene.SurfaceResized(newSize.width, newSize.height);
1117
1118   // Ensure the stage hasn't been resized
1119   DALI_TEST_EQUALS(stage.GetSize(), stageSize, TEST_LOCATION);
1120   DALI_TEST_EQUALS(scene.GetSize(), newSize, TEST_LOCATION);
1121
1122   END_TEST;
1123 }
1124
1125 #define CLIPPING_RECT_X (16)
1126 #define CLIPPING_RECT_Y (768)
1127 #define CLIPPING_RECT_WIDTH (32)
1128 #define CLIPPING_RECT_HEIGHT (32)
1129
1130 int UtcDaliSceneSurfaceRotatedWithAngle0(void)
1131 {
1132   tet_infoline("Ensure rotation of the surface is handled properly with Angle 0");
1133
1134   TestApplication application(
1135     TestApplication::DEFAULT_SURFACE_WIDTH,
1136     TestApplication::DEFAULT_SURFACE_HEIGHT,
1137     TestApplication::DEFAULT_HORIZONTAL_DPI,
1138     TestApplication::DEFAULT_VERTICAL_DPI,
1139     true,
1140     true);
1141
1142   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1143
1144   std::vector<Rect<int>> damagedRects;
1145   Rect<int>              clippingRect;
1146   application.SendNotification();
1147   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1148
1149   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1150
1151   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1152   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1153
1154   Actor actor = CreateRenderableActor();
1155   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1156   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1157   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1158   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1159   application.GetScene().Add(actor);
1160
1161   application.SendNotification();
1162
1163   damagedRects.clear();
1164   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1165                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1166                                         0);
1167
1168   // Check current surface orientation
1169   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1170
1171   // It should not be changed yet.
1172   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1173
1174   application.SendNotification();
1175   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1176   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1177
1178   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1179   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1180   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1181
1182   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1183   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1184   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1185   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1186
1187   // Check current surface orientation
1188   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1189
1190   // It should be changed.
1191   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1192
1193   END_TEST;
1194 }
1195
1196 int UtcDaliSceneSurfaceRotatedWithAngle90(void)
1197 {
1198   tet_infoline("Ensure rotation of the surface is handled properly with Angle 90");
1199
1200   TestApplication application(
1201     TestApplication::DEFAULT_SURFACE_WIDTH,
1202     TestApplication::DEFAULT_SURFACE_HEIGHT,
1203     TestApplication::DEFAULT_HORIZONTAL_DPI,
1204     TestApplication::DEFAULT_VERTICAL_DPI,
1205     true,
1206     true);
1207
1208   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1209
1210   std::vector<Rect<int>> damagedRects;
1211   Rect<int>              clippingRect;
1212   application.SendNotification();
1213   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1214
1215   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1216
1217   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1218   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1219
1220   Actor actor = CreateRenderableActor();
1221   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1222   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1223   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1224   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1225   application.GetScene().Add(actor);
1226
1227   application.SendNotification();
1228
1229   damagedRects.clear();
1230   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1231                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1232                                         90);
1233
1234   // Check current surface orientation
1235   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1236
1237   // It should not be changed yet.
1238   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1239
1240   application.SendNotification();
1241   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1242   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1243
1244   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1245   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1246   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1247
1248   // It is recalculation for glScissor.
1249   // Because surface is rotated and glScissor is called with recalcurated value.
1250   clippingRect.x      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1251   clippingRect.y      = CLIPPING_RECT_X;
1252   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1253   clippingRect.height = CLIPPING_RECT_WIDTH;
1254
1255   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1256   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1257   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1258   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1259
1260   // Check current surface orientation
1261   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1262
1263   // It should be changed.
1264   DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1265
1266   END_TEST;
1267 }
1268
1269 int UtcDaliSceneSurfaceRotatedWithAngle180(void)
1270 {
1271   tet_infoline("Ensure rotation of the surface is handled properly with Angle 180");
1272
1273   TestApplication application(
1274     TestApplication::DEFAULT_SURFACE_WIDTH,
1275     TestApplication::DEFAULT_SURFACE_HEIGHT,
1276     TestApplication::DEFAULT_HORIZONTAL_DPI,
1277     TestApplication::DEFAULT_VERTICAL_DPI,
1278     true,
1279     true);
1280
1281   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1282
1283   std::vector<Rect<int>> damagedRects;
1284   Rect<int>              clippingRect;
1285   application.SendNotification();
1286   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1287
1288   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1289
1290   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1291   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1292
1293   Actor actor = CreateRenderableActor();
1294   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1295   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1296   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1297   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1298   application.GetScene().Add(actor);
1299
1300   application.SendNotification();
1301
1302   damagedRects.clear();
1303   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1304                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1305                                         180);
1306
1307   // Check current surface orientation
1308   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1309
1310   // It should not be changed yet.
1311   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1312
1313   application.SendNotification();
1314   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1315   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1316
1317   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1318   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1319   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1320
1321   // It is recalculation for glScissor.
1322   // Because surface is rotated and glScissor is called with recalcurated value.
1323   clippingRect.x      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1324   clippingRect.y      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1325   clippingRect.width  = CLIPPING_RECT_WIDTH;
1326   clippingRect.height = CLIPPING_RECT_HEIGHT;
1327
1328   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1329   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1330   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1331   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1332
1333   // Check current surface orientation
1334   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1335
1336   // It should be changed.
1337   DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
1338
1339   END_TEST;
1340 }
1341
1342 int UtcDaliSceneSurfaceRotatedWithAngle270(void)
1343 {
1344   tet_infoline("Ensure rotation of the surface is handled properly with Angle 270");
1345
1346   TestApplication application(
1347     TestApplication::DEFAULT_SURFACE_WIDTH,
1348     TestApplication::DEFAULT_SURFACE_HEIGHT,
1349     TestApplication::DEFAULT_HORIZONTAL_DPI,
1350     TestApplication::DEFAULT_VERTICAL_DPI,
1351     true,
1352     true);
1353
1354   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1355
1356   std::vector<Rect<int>> damagedRects;
1357   Rect<int>              clippingRect;
1358   application.SendNotification();
1359   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1360
1361   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1362
1363   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1364   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1365
1366   Actor actor = CreateRenderableActor();
1367   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1368   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1369   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1370   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1371   application.GetScene().Add(actor);
1372
1373   application.SendNotification();
1374
1375   damagedRects.clear();
1376   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1377                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1378                                         270);
1379
1380   // Check current surface orientation
1381   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1382
1383   // It should not be changed yet.
1384   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1385
1386   application.SendNotification();
1387   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1388   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1389
1390   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1391   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1392   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1393
1394   // It is recalculation for glScissor.
1395   // Because surface is rotated and glScissor is called with recalcurated value.
1396   clippingRect.x      = CLIPPING_RECT_Y;
1397   clippingRect.y      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1398   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1399   clippingRect.height = CLIPPING_RECT_WIDTH;
1400
1401   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1402   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1403   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1404   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1405
1406   // Check current surface orientation
1407   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1408
1409   // It should be changed.
1410   DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
1411
1412   END_TEST;
1413 }
1414
1415 int UtcDaliSceneSetRotationCompletedAcknowledgementWithAngle90(void)
1416 {
1417   tet_infoline("Ensure to acknowledge for completing surface 90 angle rotaiton");
1418
1419   TestApplication application(
1420     TestApplication::DEFAULT_SURFACE_WIDTH,
1421     TestApplication::DEFAULT_SURFACE_HEIGHT,
1422     TestApplication::DEFAULT_HORIZONTAL_DPI,
1423     TestApplication::DEFAULT_VERTICAL_DPI,
1424     true,
1425     true);
1426
1427   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1428
1429   std::vector<Rect<int>> damagedRects;
1430   Rect<int>              clippingRect;
1431   application.SendNotification();
1432   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1433
1434   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1435   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1436
1437   Actor actor = CreateRenderableActor();
1438   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1439   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1440   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1441   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1442   application.GetScene().Add(actor);
1443
1444   application.SendNotification();
1445
1446   damagedRects.clear();
1447   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1448                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1449                                         90);
1450
1451   // Check current surface orientation
1452   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1453
1454   // It should not be changed yet.
1455   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1456
1457   application.GetScene().SetRotationCompletedAcknowledgement();
1458
1459   application.SendNotification();
1460   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1461   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1462
1463   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1464   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1465   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1466
1467   // It is recalculation for glScissor.
1468   // Because surface is rotated and glScissor is called with recalcurated value.
1469   clippingRect.x      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1470   clippingRect.y      = CLIPPING_RECT_X;
1471   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1472   clippingRect.height = CLIPPING_RECT_WIDTH;
1473
1474   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1475   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1476   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1477   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1478
1479   // Check current surface orientation
1480   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1481
1482   // It should be changed.
1483   DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1484
1485   bool isSetRotationCompletedAcknowledgementSet = application.GetScene().IsRotationCompletedAcknowledgementSet();
1486   DALI_TEST_EQUALS(isSetRotationCompletedAcknowledgementSet, true, TEST_LOCATION);
1487
1488   END_TEST;
1489 }
1490
1491 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1492 {
1493   TestApplication          application;
1494   Dali::Integration::Scene scene = application.GetScene();
1495
1496   KeyEventGeneratedSignalData      data;
1497   KeyEventGeneratedReceivedFunctor functor(data);
1498   scene.KeyEventGeneratedSignal().Connect(&application, functor);
1499
1500   Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1501   application.ProcessEvent(event);
1502
1503   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1504   DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1505   DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
1506   DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
1507   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1508
1509   data.Reset();
1510
1511   Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1512   application.ProcessEvent(event2);
1513
1514   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1515   DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1516   DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
1517   DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
1518   DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1519
1520   data.Reset();
1521
1522   Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1523   application.ProcessEvent(event3);
1524
1525   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1526   DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1527   DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
1528   DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
1529   DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1530
1531   data.Reset();
1532
1533   Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1534   application.ProcessEvent(event4);
1535
1536   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1537   DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1538   DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
1539   DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
1540   DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1541   END_TEST;
1542 }
1543
1544 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1545 {
1546   tet_infoline("Ensure we keep background color when the scene surface is replaced ");
1547
1548   TestApplication application;
1549
1550   // Create a new scene and set the background color of the main scene
1551   auto defaultScene = application.GetScene();
1552   defaultScene.SetBackgroundColor(Color::BLUE);
1553
1554   // Need to create a renderable as we don't start rendering until we have at least one
1555   // We don't need to add this to any scene
1556   auto actor = CreateRenderableActor();
1557
1558   auto& glAbstraction    = application.GetGlAbstraction();
1559   auto  clearCountBefore = glAbstraction.GetClearCountCalled();
1560
1561   application.SendNotification();
1562   application.Render();
1563
1564   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION);
1565   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1566
1567   defaultScene.SurfaceReplaced();
1568
1569   application.SendNotification();
1570   application.Render();
1571
1572   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION);
1573   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1574
1575   // Check when the main render task viewport is set the clear color is clipped using scissors
1576   TraceCallStack& scissorTrace        = glAbstraction.GetScissorTrace();
1577   TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1578   scissorTrace.Enable(true);
1579   enabledDisableTrace.Enable(true);
1580
1581   defaultScene.GetRenderTaskList().GetTask(0).SetViewport(Viewport(0.0f, 0.0f, 100.0f, 100.0f));
1582
1583   application.SendNotification();
1584   application.Render();
1585
1586   // Check scissor test was enabled.
1587   std::ostringstream scissor;
1588   scissor << std::hex << GL_SCISSOR_TEST;
1589   DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
1590
1591   // Check the scissor was set, and the coordinates are correct.
1592   DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", "0, 700, 100, 100"));
1593
1594   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION);
1595   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1596
1597   scissorTrace.Enable(false);
1598   scissorTrace.Reset();
1599
1600   enabledDisableTrace.Enable(false);
1601   enabledDisableTrace.Reset();
1602
1603   END_TEST;
1604 }
1605
1606 int UtcDaliSceneEnsureRenderTargetRecreated(void)
1607 {
1608   tet_infoline("Ensure render target is re-created when surface replaced ");
1609
1610   TestApplication application;
1611
1612   // Create a new scene and set the background color of the main scene
1613   auto defaultScene = application.GetScene();
1614   defaultScene.SetBackgroundColor(Color::BLUE);
1615
1616   auto actor = CreateRenderableActor();
1617   defaultScene.Add(actor);
1618
1619   auto& graphicsController = application.GetGraphicsController();
1620
1621   application.SendNotification();
1622   application.Render();
1623
1624   TraceCallStack&                    graphicsCallStack = graphicsController.mCallStack;
1625   TraceCallStack::NamedParams        empty{};
1626   const TraceCallStack::NamedParams* matching = graphicsCallStack.FindLastMatch("PresentRenderTarget", empty);
1627   DALI_TEST_CHECK(matching != nullptr);
1628
1629   graphicsCallStack.Reset();
1630
1631   int                              fakeSurface1;
1632   Graphics::RenderTargetCreateInfo createInfo{};
1633   createInfo.SetSurface(&fakeSurface1).SetExtent(Graphics::Extent2D{480u, 800u});
1634   defaultScene.SetSurfaceRenderTarget(createInfo);
1635
1636   application.SendNotification();
1637   application.Render();
1638
1639   TraceCallStack::NamedParams query1;
1640   query1["surface"] << std::hex << &fakeSurface1;
1641   const TraceCallStack::NamedParams* matching2 = graphicsCallStack.FindLastMatch("CreateRenderTarget", query1);
1642   DALI_TEST_CHECK(matching2 != nullptr);
1643
1644   const TraceCallStack::NamedParams* matching3 = graphicsCallStack.FindLastMatch("PresentRenderTarget", empty);
1645   DALI_TEST_CHECK(matching3 != nullptr);
1646   DALI_TEST_EQUALS((*matching3)["surface"].str(), query1["surface"].str(), TEST_LOCATION);
1647
1648   END_TEST;
1649 }
1650
1651 int UtcDaliSceneEmptySceneRendering(void)
1652 {
1653   tet_infoline("Ensure not rendering before a Renderer is added");
1654
1655   TestApplication    application;
1656   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1657
1658   // Render without any renderer
1659   application.SendNotification();
1660   application.Render();
1661
1662   // Check the clear count and the render status
1663   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1664   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1665
1666   // Add a Renderer
1667   Geometry geometry = CreateQuadGeometry();
1668   Shader   shader   = CreateShader();
1669   Renderer renderer = Renderer::New(geometry, shader);
1670
1671   // Render before adding renderer
1672   application.SendNotification();
1673   application.Render();
1674
1675   // Check the clear count and the render status
1676   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1677   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1678
1679   Actor actor = Actor::New();
1680   actor.AddRenderer(renderer);
1681
1682   actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
1683   application.GetScene().Add(actor);
1684
1685   // Render
1686   application.SendNotification();
1687   application.Render();
1688
1689   // Check the clear count and the render status
1690   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION);
1691   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1692
1693   // Remove the Renderer
1694   application.GetScene().Remove(actor);
1695   actor.Reset();
1696   renderer.Reset();
1697
1698   // Render
1699   application.SendNotification();
1700   application.Render();
1701
1702   // Check the clear count and the render status
1703   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION); // Should be cleared
1704   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1705
1706   END_TEST;
1707 }
1708
1709 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1710 {
1711   tet_infoline("UtcDaliSceneFrameRenderedCallback");
1712
1713   TestApplication application;
1714
1715   // Add a Renderer
1716   Geometry geometry = CreateQuadGeometry();
1717   Shader   shader   = CreateShader();
1718   Renderer renderer = Renderer::New(geometry, shader);
1719
1720   Actor actor = Actor::New();
1721   actor.AddRenderer(renderer);
1722   application.GetScene().Add(actor);
1723
1724   Dali::Integration::Scene scene = application.GetScene();
1725
1726   int frameId = 1;
1727   scene.AddFrameRenderedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1728   scene.AddFramePresentedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1729
1730   // Render
1731   application.SendNotification();
1732   application.Render();
1733
1734   Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1735   scene.GetFrameRenderedCallback(callbackContainer);
1736
1737   DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1738   DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1739
1740   callbackContainer.clear();
1741
1742   scene.GetFramePresentedCallback(callbackContainer);
1743
1744   DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1745   DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1746
1747   END_TEST;
1748 }
1749
1750 int UtcDaliSceneWheelEventGeneratedSignalP(void)
1751 {
1752   TestApplication          application;
1753   Dali::Integration::Scene scene = application.GetScene();
1754
1755   WheelEventGeneratedSignalData      data;
1756   WheelEventGeneratedReceivedFunctor functor(data);
1757   scene.WheelEventGeneratedSignal().Connect(&application, functor);
1758
1759   Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
1760   application.ProcessEvent(event);
1761
1762   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1763   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
1764   DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
1765   DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
1766   DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
1767   DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
1768   DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
1769
1770   data.Reset();
1771
1772   Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
1773   application.ProcessEvent(event2);
1774
1775   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1776   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
1777   DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
1778   DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
1779   DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
1780   DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
1781   DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
1782   END_TEST;
1783 }