Merge "Add methods to get current size and orientation to Scene" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Scene.cpp
1 /*
2  * Copyright (c) 2021 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 void GenerateTouch(TestApplication& application, PointState::Type state, const Vector2& screenPosition)
228 {
229   Integration::TouchEvent touchEvent;
230   Integration::Point      point;
231   point.SetState(state);
232   point.SetScreenPosition(screenPosition);
233   touchEvent.points.push_back(point);
234   application.ProcessEvent(touchEvent);
235 }
236
237 bool DummyTouchCallback(Actor actor, const TouchEvent& touch)
238 {
239   return true;
240 }
241
242 void FrameCallback(int frameId)
243 {
244 }
245
246 } // unnamed namespace
247
248 int UtcDaliSceneAdd(void)
249 {
250   TestApplication application;
251   tet_infoline("Testing Dali::Integration::Scene::Add");
252
253   Dali::Integration::Scene scene = application.GetScene();
254
255   Actor actor = Actor::New();
256   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
257
258   scene.Add(actor);
259   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
260
261   END_TEST;
262 }
263
264 int UtcDaliSceneRemove(void)
265 {
266   TestApplication application;
267   tet_infoline("Testing Dali::Integration::Scene::Remove");
268
269   Dali::Integration::Scene scene = application.GetScene();
270
271   Actor actor = Actor::New();
272   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
273
274   scene.Add(actor);
275   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
276
277   scene.Remove(actor);
278   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
279
280   END_TEST;
281 }
282
283 int UtcDaliSceneGetSize(void)
284 {
285   TestApplication application;
286   tet_infoline("Testing Dali::Integration::Scene::GetSize");
287
288   Dali::Integration::Scene scene = application.GetScene();
289   Size                     size  = scene.GetSize();
290   DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION);
291   DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION);
292
293   END_TEST;
294 }
295
296 int UtcDaliSceneGetDpi(void)
297 {
298   TestApplication application; // Initializes core DPI to default values
299
300   // Test that setting core DPI explicitly also sets up the scene's DPI.
301   Dali::Integration::Scene scene = application.GetScene();
302   scene.SetDpi(Vector2(200.0f, 180.0f));
303   Vector2 dpi = scene.GetDpi();
304   DALI_TEST_EQUALS(dpi.x, 200.0f, TEST_LOCATION);
305   DALI_TEST_EQUALS(dpi.y, 180.0f, TEST_LOCATION);
306   END_TEST;
307 }
308
309 int UtcDaliSceneGetRenderTaskList(void)
310 {
311   TestApplication application;
312   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
313
314   Dali::Integration::Scene scene = application.GetScene();
315
316   // Check we get a valid instance.
317   const RenderTaskList& tasks = scene.GetRenderTaskList();
318
319   // There should be 1 task by default.
320   DALI_TEST_EQUALS(tasks.GetTaskCount(), 1u, TEST_LOCATION);
321
322   // RenderTaskList has it's own UTC tests.
323   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
324   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
325
326   DALI_TEST_EQUALS(scene.GetRenderTaskList().GetTask(1), newTask, TEST_LOCATION);
327
328   END_TEST;
329 }
330
331 int UtcDaliSceneGetRootLayer(void)
332 {
333   TestApplication application;
334   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
335
336   Dali::Integration::Scene scene = application.GetScene();
337   Layer                    layer = scene.GetLayer(0);
338   DALI_TEST_CHECK(layer);
339
340   // Check that GetRootLayer() correctly retreived layer 0.
341   DALI_TEST_CHECK(scene.GetRootLayer() == layer);
342
343   END_TEST;
344 }
345
346 int UtcDaliSceneGetLayerCount(void)
347 {
348   TestApplication application;
349   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
350
351   Dali::Integration::Scene scene = application.GetScene();
352   // Initially we have a default layer
353   DALI_TEST_EQUALS(scene.GetLayerCount(), 1u, TEST_LOCATION);
354
355   Layer layer = Layer::New();
356   scene.Add(layer);
357
358   DALI_TEST_EQUALS(scene.GetLayerCount(), 2u, TEST_LOCATION);
359   END_TEST;
360 }
361
362 int UtcDaliSceneGetLayer(void)
363 {
364   TestApplication application;
365   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
366
367   Dali::Integration::Scene scene = application.GetScene();
368
369   Layer rootLayer = scene.GetLayer(0);
370   DALI_TEST_CHECK(rootLayer);
371
372   Layer layer = Layer::New();
373   scene.Add(layer);
374
375   Layer sameLayer = scene.GetLayer(1);
376   DALI_TEST_CHECK(layer == sameLayer);
377
378   END_TEST;
379 }
380
381 int UtcDaliSceneGet(void)
382 {
383   TestApplication application;
384   tet_infoline("Testing Dali::Integration::Scene::Get");
385
386   Dali::Integration::Scene scene = application.GetScene();
387
388   Actor actor = Actor::New();
389   DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(actor));
390
391   scene.Add(actor);
392
393   DALI_TEST_CHECK(scene == Dali::Integration::Scene::Get(actor));
394
395   END_TEST;
396 }
397
398 int UtcDaliSceneDiscard(void)
399 {
400   TestApplication application;
401   tet_infoline("Testing Dali::Scene::Discard");
402
403   // Create a new Scene
404   Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
405   DALI_TEST_CHECK(scene);
406
407   // One reference of scene kept here and the other one kept in the Core
408   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
409
410   // Render and notify.
411   application.SendNotification();
412   application.Render(0);
413
414   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
415   Layer rootLayer = scene.GetRootLayer();
416   DALI_TEST_CHECK(rootLayer);
417   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
418
419   // Request to discard the scene from the Core
420   scene.Discard();
421   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
422
423   // Reset the scene handle
424   scene.Reset();
425
426   // Render and notify.
427   application.SendNotification();
428   application.Render(0);
429
430   // At this point, the scene should have been automatically deleted
431   // To prove this, the ref count of the root layer handle should be decremented to 1
432   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
433
434   // Delete the root layer handle
435   rootLayer.Reset();
436
437   // Render and notify.
438   application.SendNotification();
439   application.Render(0);
440
441   END_TEST;
442 }
443
444 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
445 {
446   TestApplication application;
447
448   Dali::Integration::Scene scene = application.GetScene();
449
450   TouchedSignalData data;
451   data.createNewScene = true;
452   TouchFunctor functor(data);
453   scene.TouchedSignal().Connect(&application, functor);
454
455   // Render and notify.
456   application.SendNotification();
457   application.Render();
458
459   GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
460
461   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462   DALI_TEST_EQUALS(true, data.createNewScene, TEST_LOCATION);
463   DALI_TEST_EQUALS(true, data.newSceneCreated, TEST_LOCATION);
464   data.Reset();
465
466   END_TEST;
467 }
468
469 int UtcDaliSceneRootLayerAndSceneAlignment(void)
470 {
471   TestApplication application;
472
473   // Create a Scene
474   Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
475   DALI_TEST_CHECK(scene);
476
477   // One reference of scene kept here and the other one kept in the Core
478   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
479
480   // Add a renderable actor to the scene
481   auto actor = CreateRenderableActor();
482   scene.Add(actor);
483
484   // Render and notify.
485   application.SendNotification();
486   application.Render(0);
487
488   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
489   Layer rootLayer = scene.GetRootLayer();
490   DALI_TEST_CHECK(rootLayer);
491   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
492
493   // Request to discard the scene from the Core
494   scene.Discard();
495   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
496
497   // Reset the scene handle
498   scene.Reset();
499
500   // Render and notify.
501   application.SendNotification();
502   application.Render(0);
503
504   // At this point, the scene should have been automatically deleted
505   // To prove this, the ref count of the root layer handle should be decremented to 1
506   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
507
508   // Create a new Scene while the root layer of the deleted scene is still alive
509   Dali::Integration::Scene newScene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
510   DALI_TEST_CHECK(newScene);
511
512   // Render and notify.
513   application.SendNotification();
514   application.Render(0);
515
516   // At this point, we have only one scene but two root layers
517   // The root layer of the deleted scene is still alive
518   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
519
520   // Delete the root layer of the deleted scene
521   rootLayer.Reset();
522
523   // Render and notify.
524   application.SendNotification();
525   application.Render(0);
526
527   END_TEST;
528 }
529
530 int UtcDaliSceneEventProcessingFinishedP(void)
531 {
532   TestApplication          application;
533   Dali::Integration::Scene scene = application.GetScene();
534
535   bool                           eventProcessingFinished = false;
536   EventProcessingFinishedFunctor functor(eventProcessingFinished);
537   scene.EventProcessingFinishedSignal().Connect(&application, functor);
538
539   Actor actor(Actor::New());
540   scene.Add(actor);
541
542   application.SendNotification();
543   application.Render();
544
545   DALI_TEST_CHECK(eventProcessingFinished);
546
547   END_TEST;
548 }
549
550 int UtcDaliSceneEventProcessingFinishedN(void)
551 {
552   TestApplication          application;
553   Dali::Integration::Scene scene = application.GetScene();
554
555   bool                           eventProcessingFinished = false;
556   EventProcessingFinishedFunctor functor(eventProcessingFinished);
557   scene.EventProcessingFinishedSignal().Connect(&application, functor);
558
559   Actor actor(Actor::New());
560   scene.Add(actor);
561
562   // Do not complete event processing and confirm the signal has not been emitted.
563   DALI_TEST_CHECK(!eventProcessingFinished);
564
565   END_TEST;
566 }
567
568 int UtcDaliSceneSignalKeyEventP(void)
569 {
570   TestApplication          application;
571   Dali::Integration::Scene scene = application.GetScene();
572
573   KeyEventSignalData      data;
574   KeyEventReceivedFunctor functor(data);
575   scene.KeyEventSignal().Connect(&application, functor);
576
577   Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
578   application.ProcessEvent(event);
579
580   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
581   DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
582   DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
583   DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
584   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
585
586   data.Reset();
587
588   Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
589   application.ProcessEvent(event2);
590
591   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
592   DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
593   DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
594   DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
595   DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
596
597   data.Reset();
598
599   Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
600   application.ProcessEvent(event3);
601
602   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
603   DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
604   DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
605   DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
606   DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
607
608   data.Reset();
609
610   Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
611   application.ProcessEvent(event4);
612
613   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
614   DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
615   DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
616   DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
617   DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
618   END_TEST;
619 }
620
621 int UtcDaliSceneSignalKeyEventN(void)
622 {
623   TestApplication          application;
624   Dali::Integration::Scene scene = application.GetScene();
625
626   KeyEventSignalData      data;
627   KeyEventReceivedFunctor functor(data);
628   scene.KeyEventSignal().Connect(&application, functor);
629
630   // Check that a non-pressed key events data is not modified.
631   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
632
633   END_TEST;
634 }
635
636 int UtcDaliSceneTouchedSignalP(void)
637 {
638   TestApplication          application;
639   Dali::Integration::Scene scene = application.GetScene();
640
641   TouchedSignalData data;
642   TouchFunctor      functor(data);
643   scene.TouchedSignal().Connect(&application, functor);
644
645   // Render and notify.
646   application.SendNotification();
647   application.Render();
648
649   // Basic test: No actors, single touch (down then up).
650   {
651     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
652
653     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
654     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
655     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
656     data.Reset();
657
658     GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f));
659
660     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
661     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
662     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
663     data.Reset();
664   }
665
666   // Add an actor to the scene.
667   Actor actor = Actor::New();
668   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
669   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
670   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
671   actor.TouchedSignal().Connect(&DummyTouchCallback);
672   scene.Add(actor);
673
674   // Render and notify.
675   application.SendNotification();
676   application.Render();
677
678   // Actor on scene, single touch, down in actor, motion, then up outside actor.
679   {
680     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
681
682     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
683     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
684     DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
685     data.Reset();
686
687     GenerateTouch(application, PointState::MOTION, Vector2(150.0f, 10.0f)); // Some motion
688
689     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
690     data.Reset();
691
692     GenerateTouch(application, PointState::UP, Vector2(150.0f, 10.0f)); // Some motion
693
694     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
696     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
697     data.Reset();
698   }
699
700   // Multiple touch. Should only receive a touch on first down and last up.
701   {
702     Integration::TouchEvent touchEvent;
703     Integration::Point      point;
704
705     // 1st point
706     point.SetState(PointState::DOWN);
707     point.SetScreenPosition(Vector2(10.0f, 10.0f));
708     touchEvent.points.push_back(point);
709     application.ProcessEvent(touchEvent);
710     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
711     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
712     data.Reset();
713
714     // 2nd point
715     touchEvent.points[0].SetState(PointState::STATIONARY);
716     point.SetDeviceId(1);
717     point.SetScreenPosition(Vector2(50.0f, 50.0f));
718     touchEvent.points.push_back(point);
719     application.ProcessEvent(touchEvent);
720     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
721     data.Reset();
722
723     // Primary point is up
724     touchEvent.points[0].SetState(PointState::UP);
725     touchEvent.points[1].SetState(PointState::STATIONARY);
726     application.ProcessEvent(touchEvent);
727     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
728     data.Reset();
729
730     // Remove 1st point now, 2nd point is now in motion
731     touchEvent.points.erase(touchEvent.points.begin());
732     touchEvent.points[0].SetState(PointState::MOTION);
733     touchEvent.points[0].SetScreenPosition(Vector2(150.0f, 50.0f));
734     application.ProcessEvent(touchEvent);
735     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
736     data.Reset();
737
738     // Final point Up
739     touchEvent.points[0].SetState(PointState::UP);
740     application.ProcessEvent(touchEvent);
741     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
742     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
743     data.Reset();
744   }
745   END_TEST;
746 }
747
748 int UtcDaliSceneTouchedSignalN(void)
749 {
750   TestApplication          application;
751   Dali::Integration::Scene scene = application.GetScene();
752
753   TouchedSignalData data;
754   TouchFunctor      functor(data);
755   scene.TouchedSignal().Connect(&application, functor);
756
757   // Render and notify.
758   application.SendNotification();
759   application.Render();
760
761   // Confirm functor not called before there has been any touch event.
762   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
763
764   // No actors, single touch, down, motion then up.
765   {
766     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
767
768     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
769     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
770     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
771
772     data.Reset();
773
774     // Confirm there is no signal when the touchpoint is only moved.
775     GenerateTouch(application, PointState::MOTION, Vector2(1200.0f, 10.0f)); // Some motion
776
777     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
778     data.Reset();
779
780     // Confirm a following up event generates a signal.
781     GenerateTouch(application, PointState::UP, Vector2(1200.0f, 10.0f));
782
783     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
784     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
785     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
786     data.Reset();
787   }
788
789   // Add an actor to the scene.
790   Actor actor = Actor::New();
791   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
792   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
793   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
794   actor.TouchedSignal().Connect(&DummyTouchCallback);
795   scene.Add(actor);
796
797   // Render and notify.
798   application.SendNotification();
799   application.Render();
800
801   // Actor on scene. Interrupted before down and interrupted after down.
802   {
803     GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
804
805     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
806     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
807     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
808     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
809     data.Reset();
810
811     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
812
813     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
814     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
815     DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
816     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::DOWN);
817     data.Reset();
818
819     GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
820
821     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
822     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
823     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
824     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
825
826     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
827
828     // Check that getting info about a non-existent point returns an empty handle
829     Actor actor = data.receivedTouchEvent.GetHitActor(1);
830     DALI_TEST_CHECK(!actor);
831
832     data.Reset();
833   }
834
835   END_TEST;
836 }
837
838 int UtcDaliSceneSignalWheelEventP(void)
839 {
840   TestApplication          application;
841   Dali::Integration::Scene scene = application.GetScene();
842
843   WheelEventSignalData      data;
844   WheelEventReceivedFunctor functor(data);
845   scene.WheelEventSignal().Connect(&application, functor);
846
847   Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
848   application.ProcessEvent(event);
849
850   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
851   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
852   DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
853   DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
854   DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
855   DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
856   DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
857
858   data.Reset();
859
860   Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
861   application.ProcessEvent(event2);
862
863   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
864   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
865   DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
866   DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
867   DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
868   DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
869   DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
870   END_TEST;
871 }
872
873 int UtcDaliSceneSurfaceResizedDefaultScene(void)
874 {
875   tet_infoline("Ensure resizing of the surface is handled properly");
876
877   TestApplication application;
878
879   auto defaultScene = application.GetScene();
880   DALI_TEST_CHECK(defaultScene);
881
882   // Ensure stage size matches the scene size
883   auto stage = Stage::GetCurrent();
884   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
885
886   // Resize the scene
887   Vector2 newSize(1000.0f, 2000.0f);
888   DALI_TEST_CHECK(stage.GetSize() != newSize);
889   defaultScene.SurfaceResized(newSize.width, newSize.height);
890
891   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
892   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
893
894   END_TEST;
895 }
896
897 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
898 {
899   tet_infoline("Ensure resizing of the surface & viewport is handled properly");
900
901   TestApplication    application;
902   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
903   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
904   glAbstraction.EnableViewportCallTrace(true);
905
906   // Initial scene setup
907   Geometry geometry = CreateQuadGeometry();
908   Shader   shader   = CreateShader();
909   Renderer renderer = Renderer::New(geometry, shader);
910
911   Actor actor = Actor::New();
912   actor.AddRenderer(renderer);
913   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
914   application.GetScene().Add(actor);
915
916   // Render before resizing surface
917   application.SendNotification();
918   application.Render(0);
919   glAbstraction.ResetViewportCallStack();
920
921   auto defaultScene = application.GetScene();
922   DALI_TEST_CHECK(defaultScene);
923
924   // consume the resize flag by first rendering
925   defaultScene.IsSurfaceRectChanged();
926
927   // Ensure stage size matches the scene size
928   auto stage = Stage::GetCurrent();
929   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
930
931   Rect<int32_t> surfaceRect = defaultScene.GetCurrentSurfaceRect();
932
933   bool surfaceResized;
934   // check resized flag before surface is resized.
935   surfaceResized = defaultScene.IsSurfaceRectChanged();
936   DALI_TEST_EQUALS(surfaceResized, false, TEST_LOCATION);
937
938   // Resize the scene
939   Vector2     newSize(1000.0f, 2000.0f);
940   std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
941   DALI_TEST_CHECK(stage.GetSize() != newSize);
942   defaultScene.SurfaceResized(newSize.width, newSize.height);
943
944   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
945   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
946
947   // Check current surface rect
948   Rect<int32_t> newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
949
950   // It should not be changed yet.
951   DALI_TEST_CHECK(surfaceRect == newSurfaceRect);
952
953   // Render after resizing surface
954   application.SendNotification();
955   application.Render(0);
956
957   surfaceResized = defaultScene.IsSurfaceRectChanged();
958   DALI_TEST_EQUALS(surfaceResized, true, TEST_LOCATION);
959
960   // Check that the viewport is handled properly
961   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
962
963   // Check current surface rect
964   newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
965
966   // It should be changed
967   DALI_TEST_EQUALS(newSurfaceRect.x, 0, TEST_LOCATION);
968   DALI_TEST_EQUALS(newSurfaceRect.y, 0, TEST_LOCATION);
969   DALI_TEST_EQUALS(newSurfaceRect.width, 1000, TEST_LOCATION);
970   DALI_TEST_EQUALS(newSurfaceRect.height, 2000, TEST_LOCATION);
971
972   END_TEST;
973 }
974
975 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
976 {
977   tet_infoline("Ensure resizing of the surface & viewport is handled properly");
978
979   TestApplication    application;
980   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
981   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
982   glAbstraction.EnableViewportCallTrace(true);
983
984   // Initial scene setup
985   auto scene = application.GetScene();
986
987   Geometry geometry = CreateQuadGeometry();
988   Shader   shader   = CreateShader();
989   Renderer renderer = Renderer::New(geometry, shader);
990
991   Actor actor = Actor::New();
992   actor.AddRenderer(renderer);
993   int testWidth  = 400;
994   int testHeight = 400;
995   actor.SetProperty(Actor::Property::SIZE, Vector2(testWidth, testHeight));
996   scene.Add(actor);
997
998   CameraActor offscreenCameraActor = CameraActor::New(Size(testWidth, testHeight));
999   application.GetScene().Add(offscreenCameraActor);
1000
1001   FrameBuffer newFrameBuffer = FrameBuffer::New(testWidth, testHeight, FrameBuffer::Attachment::NONE);
1002
1003   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
1004   newTask.SetCameraActor(offscreenCameraActor);
1005   newTask.SetSourceActor(actor);
1006   newTask.SetFrameBuffer(newFrameBuffer);
1007   newTask.SetViewportPosition(Vector2(0, 0));
1008   newTask.SetViewportSize(Vector2(testWidth, testHeight));
1009
1010   // Render before resizing surface
1011   application.SendNotification();
1012   application.Render(0);
1013   glAbstraction.ResetViewportCallStack();
1014
1015   Rect<int32_t> initialViewport = newTask.GetViewport();
1016   int           initialWidth    = initialViewport.width;
1017   int           initialHeight   = initialViewport.height;
1018   DALI_TEST_EQUALS(initialWidth, testWidth, TEST_LOCATION);
1019   DALI_TEST_EQUALS(initialHeight, testHeight, TEST_LOCATION);
1020
1021   auto defaultScene = application.GetScene();
1022   DALI_TEST_CHECK(defaultScene);
1023
1024   // Ensure stage size matches the scene size
1025   auto stage = Stage::GetCurrent();
1026   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
1027
1028   // Resize the scene
1029   Vector2     newSize(1000.0f, 2000.0f);
1030   std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
1031   DALI_TEST_CHECK(stage.GetSize() != newSize);
1032   defaultScene.SurfaceResized(newSize.width, newSize.height);
1033
1034   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
1035   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
1036
1037   // Render after resizing surface
1038   application.SendNotification();
1039   application.Render(0);
1040
1041   // Check that the viewport is handled properly
1042   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1043
1044   // Second render-task should not be affected
1045   Rect<int32_t> viewport = newTask.GetViewport();
1046   int           width    = viewport.width;
1047   int           height   = viewport.height;
1048   DALI_TEST_EQUALS(width, testWidth, TEST_LOCATION);
1049   DALI_TEST_EQUALS(height, testHeight, TEST_LOCATION);
1050
1051   END_TEST;
1052 }
1053
1054 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1055 {
1056   tet_infoline("Ensure resizing of the surface is handled properly on additional scenes");
1057
1058   TestApplication application;
1059   Vector2         originalSurfaceSize(500.0f, 1000.0f);
1060
1061   auto scene = Integration::Scene::New(Size(originalSurfaceSize.width, originalSurfaceSize.height));
1062
1063   // Ensure stage size does NOT match the surface size
1064   auto       stage     = Stage::GetCurrent();
1065   const auto stageSize = stage.GetSize();
1066   DALI_TEST_CHECK(stageSize != originalSurfaceSize);
1067   DALI_TEST_EQUALS(originalSurfaceSize, scene.GetSize(), TEST_LOCATION);
1068
1069   // Resize the surface and inform the scene accordingly
1070   Vector2 newSize(1000.0f, 2000.0f);
1071   DALI_TEST_CHECK(stage.GetSize() != newSize);
1072   scene.SurfaceResized(newSize.width, newSize.height);
1073
1074   // Ensure the stage hasn't been resized
1075   DALI_TEST_EQUALS(stage.GetSize(), stageSize, TEST_LOCATION);
1076   DALI_TEST_EQUALS(scene.GetSize(), newSize, TEST_LOCATION);
1077
1078   END_TEST;
1079 }
1080
1081 #define CLIPPING_RECT_X (16)
1082 #define CLIPPING_RECT_Y (768)
1083 #define CLIPPING_RECT_WIDTH (32)
1084 #define CLIPPING_RECT_HEIGHT (32)
1085
1086 int UtcDaliSceneSurfaceRotatedWithAngle0(void)
1087 {
1088   tet_infoline("Ensure rotation of the surface is handled properly with Angle 0");
1089
1090   TestApplication application(
1091     TestApplication::DEFAULT_SURFACE_WIDTH,
1092     TestApplication::DEFAULT_SURFACE_HEIGHT,
1093     TestApplication::DEFAULT_HORIZONTAL_DPI,
1094     TestApplication::DEFAULT_VERTICAL_DPI,
1095     true,
1096     true);
1097
1098   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1099
1100   std::vector<Rect<int>> damagedRects;
1101   Rect<int>              clippingRect;
1102   application.SendNotification();
1103   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1104
1105   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1106   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1107
1108   Actor actor = CreateRenderableActor();
1109   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1110   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1111   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1112   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1113   application.GetScene().Add(actor);
1114
1115   application.SendNotification();
1116
1117   damagedRects.clear();
1118   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1119                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1120                                         0);
1121
1122   // Check current surface orientation
1123   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1124
1125   // It should not be changed yet.
1126   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1127
1128   application.SendNotification();
1129   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1130   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1131
1132   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1133   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1134   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1135
1136   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1137   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1138   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1139   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1140
1141   // Check current surface orientation
1142   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1143
1144   // It should be changed.
1145   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1146
1147   END_TEST;
1148 }
1149
1150 int UtcDaliSceneSurfaceRotatedWithAngle90(void)
1151 {
1152   tet_infoline("Ensure rotation of the surface is handled properly with Angle 90");
1153
1154   TestApplication application(
1155     TestApplication::DEFAULT_SURFACE_WIDTH,
1156     TestApplication::DEFAULT_SURFACE_HEIGHT,
1157     TestApplication::DEFAULT_HORIZONTAL_DPI,
1158     TestApplication::DEFAULT_VERTICAL_DPI,
1159     true,
1160     true);
1161
1162   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1163
1164   std::vector<Rect<int>> damagedRects;
1165   Rect<int>              clippingRect;
1166   application.SendNotification();
1167   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1168
1169   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1170   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1171
1172   Actor actor = CreateRenderableActor();
1173   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1174   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1175   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1176   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1177   application.GetScene().Add(actor);
1178
1179   application.SendNotification();
1180
1181   damagedRects.clear();
1182   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1183                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1184                                         90);
1185
1186   // Check current surface orientation
1187   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1188
1189   // It should not be changed yet.
1190   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1191
1192   application.SendNotification();
1193   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1194   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1195
1196   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1197   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1198   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1199
1200   // It is recalculation for glScissor.
1201   // Because surface is rotated and glScissor is called with recalcurated value.
1202   clippingRect.x      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1203   clippingRect.y      = CLIPPING_RECT_X;
1204   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1205   clippingRect.height = CLIPPING_RECT_WIDTH;
1206
1207   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1208   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1209   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1210   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1211
1212   // Check current surface orientation
1213   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1214
1215   // It should be changed.
1216   DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1217
1218   END_TEST;
1219 }
1220
1221 int UtcDaliSceneSurfaceRotatedWithAngle180(void)
1222 {
1223   tet_infoline("Ensure rotation of the surface is handled properly with Angle 180");
1224
1225   TestApplication application(
1226     TestApplication::DEFAULT_SURFACE_WIDTH,
1227     TestApplication::DEFAULT_SURFACE_HEIGHT,
1228     TestApplication::DEFAULT_HORIZONTAL_DPI,
1229     TestApplication::DEFAULT_VERTICAL_DPI,
1230     true,
1231     true);
1232
1233   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1234
1235   std::vector<Rect<int>> damagedRects;
1236   Rect<int>              clippingRect;
1237   application.SendNotification();
1238   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1239
1240   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1241   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1242
1243   Actor actor = CreateRenderableActor();
1244   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1245   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1246   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1247   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1248   application.GetScene().Add(actor);
1249
1250   application.SendNotification();
1251
1252   damagedRects.clear();
1253   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1254                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1255                                         180);
1256
1257   // Check current surface orientation
1258   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1259
1260   // It should not be changed yet.
1261   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1262
1263   application.SendNotification();
1264   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1265   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1266
1267   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1268   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1269   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1270
1271   // It is recalculation for glScissor.
1272   // Because surface is rotated and glScissor is called with recalcurated value.
1273   clippingRect.x      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1274   clippingRect.y      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1275   clippingRect.width  = CLIPPING_RECT_WIDTH;
1276   clippingRect.height = CLIPPING_RECT_HEIGHT;
1277
1278   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1279   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1280   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1281   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1282
1283   // Check current surface orientation
1284   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1285
1286   // It should be changed.
1287   DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
1288
1289   END_TEST;
1290 }
1291
1292 int UtcDaliSceneSurfaceRotatedWithAngle270(void)
1293 {
1294   tet_infoline("Ensure rotation of the surface is handled properly with Angle 270");
1295
1296   TestApplication application(
1297     TestApplication::DEFAULT_SURFACE_WIDTH,
1298     TestApplication::DEFAULT_SURFACE_HEIGHT,
1299     TestApplication::DEFAULT_HORIZONTAL_DPI,
1300     TestApplication::DEFAULT_VERTICAL_DPI,
1301     true,
1302     true);
1303
1304   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1305
1306   std::vector<Rect<int>> damagedRects;
1307   Rect<int>              clippingRect;
1308   application.SendNotification();
1309   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1310
1311   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1312   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1313
1314   Actor actor = CreateRenderableActor();
1315   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1316   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1317   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1318   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1319   application.GetScene().Add(actor);
1320
1321   application.SendNotification();
1322
1323   damagedRects.clear();
1324   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1325                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1326                                         270);
1327
1328   // Check current surface orientation
1329   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1330
1331   // It should not be changed yet.
1332   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1333
1334   application.SendNotification();
1335   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1336   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1337
1338   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1339   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1340   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1341
1342   // It is recalculation for glScissor.
1343   // Because surface is rotated and glScissor is called with recalcurated value.
1344   clippingRect.x      = CLIPPING_RECT_Y;
1345   clippingRect.y      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1346   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1347   clippingRect.height = CLIPPING_RECT_WIDTH;
1348
1349   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1350   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1351   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1352   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1353
1354   // Check current surface orientation
1355   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1356
1357   // It should be changed.
1358   DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
1359
1360   END_TEST;
1361 }
1362
1363 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1364 {
1365   TestApplication          application;
1366   Dali::Integration::Scene scene = application.GetScene();
1367
1368   KeyEventGeneratedSignalData      data;
1369   KeyEventGeneratedReceivedFunctor functor(data);
1370   scene.KeyEventGeneratedSignal().Connect(&application, functor);
1371
1372   Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1373   application.ProcessEvent(event);
1374
1375   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1376   DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1377   DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
1378   DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
1379   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1380
1381   data.Reset();
1382
1383   Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1384   application.ProcessEvent(event2);
1385
1386   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1387   DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1388   DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
1389   DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
1390   DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1391
1392   data.Reset();
1393
1394   Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1395   application.ProcessEvent(event3);
1396
1397   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1398   DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1399   DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
1400   DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
1401   DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1402
1403   data.Reset();
1404
1405   Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1406   application.ProcessEvent(event4);
1407
1408   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1409   DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
1410   DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
1411   DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
1412   DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
1413   END_TEST;
1414 }
1415
1416 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1417 {
1418   tet_infoline("Ensure we keep background color when the scene surface is replaced ");
1419
1420   TestApplication application;
1421
1422   // Create a new scene and set the background color of the main scene
1423   auto defaultScene = application.GetScene();
1424   defaultScene.SetBackgroundColor(Color::BLUE);
1425
1426   // Need to create a renderable as we don't start rendering until we have at least one
1427   // We don't need to add this to any scene
1428   auto actor = CreateRenderableActor();
1429
1430   auto& glAbstraction    = application.GetGlAbstraction();
1431   auto  clearCountBefore = glAbstraction.GetClearCountCalled();
1432
1433   application.SendNotification();
1434   application.Render();
1435
1436   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION);
1437   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1438
1439   defaultScene.SurfaceReplaced();
1440
1441   application.SendNotification();
1442   application.Render();
1443
1444   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION);
1445   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1446
1447   // Check when the main render task viewport is set the clear color is clipped using scissors
1448   TraceCallStack& scissorTrace        = glAbstraction.GetScissorTrace();
1449   TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1450   scissorTrace.Enable(true);
1451   enabledDisableTrace.Enable(true);
1452
1453   defaultScene.GetRenderTaskList().GetTask(0).SetViewport(Viewport(0.0f, 0.0f, 100.0f, 100.0f));
1454
1455   application.SendNotification();
1456   application.Render();
1457
1458   // Check scissor test was enabled.
1459   std::ostringstream scissor;
1460   scissor << std::hex << GL_SCISSOR_TEST;
1461   DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
1462
1463   // Check the scissor was set, and the coordinates are correct.
1464   DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", "0, 700, 100, 100"));
1465
1466   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION);
1467   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
1468
1469   scissorTrace.Enable(false);
1470   scissorTrace.Reset();
1471
1472   enabledDisableTrace.Enable(false);
1473   enabledDisableTrace.Reset();
1474
1475   END_TEST;
1476 }
1477
1478 int UtcDaliSceneEmptySceneRendering(void)
1479 {
1480   tet_infoline("Ensure not rendering before a Renderer is added");
1481
1482   TestApplication    application;
1483   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1484
1485   // Render without any renderer
1486   application.SendNotification();
1487   application.Render();
1488
1489   // Check the clear count and the render status
1490   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1491   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1492
1493   // Add a Renderer
1494   Geometry geometry = CreateQuadGeometry();
1495   Shader   shader   = CreateShader();
1496   Renderer renderer = Renderer::New(geometry, shader);
1497
1498   // Render before adding renderer
1499   application.SendNotification();
1500   application.Render();
1501
1502   // Check the clear count and the render status
1503   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
1504   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
1505
1506   Actor actor = Actor::New();
1507   actor.AddRenderer(renderer);
1508
1509   actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
1510   application.GetScene().Add(actor);
1511
1512   // Render
1513   application.SendNotification();
1514   application.Render();
1515
1516   // Check the clear count and the render status
1517   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION);
1518   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1519
1520   // Remove the Renderer
1521   application.GetScene().Remove(actor);
1522   actor.Reset();
1523   renderer.Reset();
1524
1525   // Render
1526   application.SendNotification();
1527   application.Render();
1528
1529   // Check the clear count and the render status
1530   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION); // Should be cleared
1531   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
1532
1533   END_TEST;
1534 }
1535
1536 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1537 {
1538   tet_infoline("UtcDaliSceneFrameRenderedCallback");
1539
1540   TestApplication application;
1541
1542   // Add a Renderer
1543   Geometry geometry = CreateQuadGeometry();
1544   Shader   shader   = CreateShader();
1545   Renderer renderer = Renderer::New(geometry, shader);
1546
1547   Actor actor = Actor::New();
1548   actor.AddRenderer(renderer);
1549   application.GetScene().Add(actor);
1550
1551   Dali::Integration::Scene scene = application.GetScene();
1552
1553   int frameId = 1;
1554   scene.AddFrameRenderedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1555   scene.AddFramePresentedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
1556
1557   // Render
1558   application.SendNotification();
1559   application.Render();
1560
1561   Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1562   scene.GetFrameRenderedCallback(callbackContainer);
1563
1564   DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1565   DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1566
1567   callbackContainer.clear();
1568
1569   scene.GetFramePresentedCallback(callbackContainer);
1570
1571   DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
1572   DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
1573
1574   END_TEST;
1575 }