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