Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RenderTask.cpp
1 /*
2  * Copyright (c) 2020 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/events/hit-test-algorithm.h>
20 #include <dali/integration-api/debug.h>
21 #include <dali/public-api/dali-core.h>
22 #include <mesh-builder.h>
23 #include <stdlib.h>
24 #include <test-native-image.h>
25
26 #include <iostream>
27
28 #define BOOLSTR(x) ((x) ? "T" : "F")
29
30 //& set: DaliRenderTask
31
32 using namespace Dali;
33
34 void utc_dali_render_task_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void utc_dali_render_task_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 /**
45  * APIs:
46  *
47  * Constructor, Destructor, DownCast, New, copy constructor, assignment operator
48  *
49  * SetSourceActor                      2+ve, 1-ve
50  * GetSourceActor                      1+ve, 1-ve
51  * SetExclusive                        2+ve, 0-ve
52  * IsExclusive                         2+ve, 0-ve
53  * SetInputEnabled                     1+ve, 0-ve
54  * GetInputEnabled                     1+ve, 0-ve
55  * SetCameraActor                      1+ve, 1-ve
56  * GetCameraActor                      1+ve, 1-ve
57  * SetTargetFrameBuffer                1+ve, 1-ve
58  * GetTargetFrameBuffer                1+ve, 1-ve
59  * SetScreenToFrameBufferFunction      1+ve, 1-ve
60  * GetScreenToFrameBufferFunction      1+ve, 1-ve
61  * SetScreenToFrameBufferMappingActor  1+ve, 1-ve
62  * GetScreenToFrameBufferMappingActor  1+ve, 1-ve
63  * SetViewportPosition                 1+ve
64  * GetCurrentViewportPosition          1+ve
65  * SetViewportSize                     1+ve
66  * GetCurrentViewportSize              1+ve
67  * SetViewport                         2+ve, 1-ve
68  * GetViewport                         2+ve, 1-ve
69  * SetClearColor                       1+ve, 1-ve
70  * GetClearColor                       1+ve, 1-ve
71  * SetClearEnabled                     1+ve, 1-ve
72  * GetClearEnabled                     1+ve, 1-ve
73  * SetCullMode
74  * GetCullMode
75  * SetRefreshRate                      Many
76  * GetRefreshRate                      1+ve
77  * FinishedSignal                      1+ve
78  */
79
80 namespace // unnamed namespace
81 {
82 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
83
84 /*
85  * Simulate time passed by.
86  *
87  * @note this will always process at least 1 frame (1/60 sec)
88  *
89  * @param application Test application instance
90  * @param duration Time to pass in milliseconds.
91  * @return The actual time passed in milliseconds
92  */
93 int Wait(TestApplication& application, int duration = 0)
94 {
95   int time = 0;
96
97   for(int i = 0; i <= (duration / RENDER_FRAME_INTERVAL); i++)
98   {
99     application.SendNotification();
100     application.Render(RENDER_FRAME_INTERVAL);
101     time += RENDER_FRAME_INTERVAL;
102   }
103
104   return time;
105 }
106
107 struct RenderTaskFinished
108 {
109   RenderTaskFinished(bool& finished)
110   : finished(finished)
111   {
112   }
113
114   void operator()(RenderTask& renderTask)
115   {
116     finished = true;
117   }
118
119   bool& finished;
120 };
121
122 struct RenderTaskFinishedRemoveSource
123 {
124   RenderTaskFinishedRemoveSource(bool& finished)
125   : finished(finished),
126     finishedOnce(false)
127   {
128   }
129
130   void operator()(RenderTask& renderTask)
131   {
132     DALI_TEST_CHECK(finishedOnce == false);
133     finished       = true;
134     finishedOnce   = true;
135     Actor srcActor = renderTask.GetSourceActor();
136     UnparentAndReset(srcActor);
137   }
138
139   bool& finished;
140   bool  finishedOnce;
141 };
142
143 struct RenderTaskFinishedRenderAgain
144 {
145   RenderTaskFinishedRenderAgain(bool& finished)
146   : finished(finished),
147     finishedOnce(false)
148   {
149   }
150
151   void operator()(RenderTask& renderTask)
152   {
153     DALI_TEST_CHECK(finishedOnce == false);
154     finished     = true;
155     finishedOnce = true;
156     renderTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
157   }
158
159   bool& finished;
160   bool  finishedOnce;
161 };
162
163 bool TestScreenToFrameBufferFunction(Vector2& coordinates)
164 {
165   coordinates = coordinates + Vector2(1, 2);
166
167   return true;
168 }
169
170 Actor CreateRenderableActorSuccess(TestApplication& application, std::string filename)
171 {
172   Actor actor = CreateRenderableActor();
173   actor.SetProperty(Actor::Property::SIZE, Vector2(80.0f, 80.0f));
174   return actor;
175 }
176
177 Texture CreateTexture()
178 {
179   return Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 80u, 80u);
180 }
181
182 RenderTask CreateRenderTask(TestApplication& application,
183                             CameraActor      offscreenCamera,
184                             Actor            rootActor,       // Reset default render task to point at this actor
185                             Actor            secondRootActor, // Source actor
186                             unsigned int     refreshRate,
187                             bool             glSync)
188 {
189   // Change main render task to use a different root
190   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
191   taskList.GetTask(0u).SetSourceActor(rootActor);
192
193   FrameBuffer frameBuffer = FrameBuffer::New(10, 10);
194   if(glSync)
195   {
196     NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
197     Texture                 texture            = Texture::New(*testNativeImagePtr);
198     frameBuffer.AttachColorTexture(texture);
199   }
200
201   // Don't draw output framebuffer // '
202
203   RenderTask newTask = taskList.CreateTask();
204   newTask.SetCameraActor(offscreenCamera);
205   newTask.SetSourceActor(secondRootActor);
206   newTask.SetInputEnabled(false);
207   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
208   newTask.SetClearEnabled(true);
209   newTask.SetExclusive(true);
210   newTask.SetRefreshRate(refreshRate);
211   newTask.SetFrameBuffer(frameBuffer);
212   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, glSync);
213   return newTask;
214 }
215
216 bool UpdateRender(TestApplication& application, TraceCallStack& callStack, bool testDrawn, bool& finishedSig, bool testFinished, bool testKeepUpdating, int lineNumber)
217 {
218   finishedSig = false;
219   callStack.Reset();
220
221   tet_printf("TestApplication::UpdateRender().\n");
222
223   application.Render(16);
224   application.SendNotification();
225
226   bool sigPassed = false;
227   if(testFinished)
228   {
229     sigPassed = finishedSig;
230   }
231   else
232   {
233     sigPassed = !finishedSig;
234   }
235
236   bool drawResult = callStack.FindMethod("DrawElements") || callStack.FindMethod("DrawArrays");
237
238   bool drawPassed = false;
239   if(testDrawn)
240   {
241     drawPassed = drawResult;
242   }
243   else
244   {
245     drawPassed = !drawResult;
246   }
247
248   bool keepUpdating       = (application.GetUpdateStatus() != 0);
249   bool keepUpdatingPassed = false;
250   if(testKeepUpdating)
251   {
252     keepUpdatingPassed = keepUpdating;
253   }
254   else
255   {
256     keepUpdatingPassed = !keepUpdating;
257   }
258
259   bool result = (sigPassed && drawPassed && keepUpdatingPassed);
260
261   tet_printf("UpdateRender: Expected: Draw:%s Signal:%s KeepUpdating: %s  Actual: Draw:%s  Signal:%s KeepUpdating: %s  %s, line %d\n",
262              BOOLSTR(testDrawn),
263              BOOLSTR(testFinished),
264              BOOLSTR(testKeepUpdating),
265              BOOLSTR(drawResult),
266              BOOLSTR(finishedSig),
267              BOOLSTR(keepUpdating),
268              result ? "Passed" : "Failed",
269              lineNumber);
270
271   return result;
272 }
273
274 } // unnamed namespace
275
276 /****************************************************************************************************/
277 /****************************************************************************************************/
278 /********************************   TEST CASES BELOW   **********************************************/
279 /****************************************************************************************************/
280 /****************************************************************************************************/
281
282 int UtcDaliRenderTaskDownCast01(void)
283 {
284   TestApplication application;
285
286   tet_infoline("Testing RenderTask::DownCast()");
287
288   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
289
290   BaseHandle base = taskList.GetTask(0u);
291   DALI_TEST_CHECK(base);
292
293   RenderTask task = RenderTask::DownCast(base);
294   DALI_TEST_CHECK(task);
295
296   // Try calling a method
297   DALI_TEST_CHECK(task.GetSourceActor());
298   END_TEST;
299 }
300
301 int UtcDaliRenderTaskDownCast02(void)
302 {
303   TestApplication application;
304
305   tet_infoline("Testing RenderTask::DownCast()");
306
307   Actor actor = Actor::New();
308
309   RenderTask task = RenderTask::DownCast(actor);
310   DALI_TEST_CHECK(!task);
311
312   END_TEST;
313 }
314
315 int UtcDaliRenderTaskSetSourceActorN(void)
316 {
317   TestApplication application;
318   tet_infoline("Testing RenderTask::SetSourceActor() Negative - try with empty actor handle");
319   Integration::Scene stage = application.GetScene();
320
321   Actor srcActor;
322
323   RenderTaskList taskList   = stage.GetRenderTaskList();
324   RenderTask     renderTask = taskList.CreateTask();
325   renderTask.SetSourceActor(srcActor);
326
327   application.SendNotification();
328   application.Render();
329
330   DALI_TEST_CHECK(!renderTask.GetSourceActor());
331   END_TEST;
332 }
333
334 int UtcDaliRenderTaskSetSourceActorP01(void)
335 {
336   TestApplication application;
337
338   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that setting a non-renderable actor stops existing source actor being rendered ");
339
340   Integration::Scene stage    = application.GetScene();
341   RenderTaskList     taskList = stage.GetRenderTaskList();
342   RenderTask         task     = taskList.GetTask(0u);
343
344   Actor actor = task.GetSourceActor();
345   DALI_TEST_CHECK(actor);
346
347   Texture img      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
348   Actor   newActor = CreateRenderableActor(img);
349   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
350   stage.Add(newActor);
351
352   Actor nonRenderableActor = Actor::New();
353   stage.Add(nonRenderableActor);
354
355   // Stop the newActor from being rendered by changing the source actor
356   DALI_TEST_CHECK(nonRenderableActor);
357   task.SetSourceActor(nonRenderableActor);
358   DALI_TEST_CHECK(task.GetSourceActor() != actor);
359   DALI_TEST_CHECK(task.GetSourceActor() == nonRenderableActor);
360
361   TestGlAbstraction& gl        = application.GetGlAbstraction();
362   TraceCallStack&    drawTrace = gl.GetDrawTrace();
363   drawTrace.Enable(true);
364
365   // Update & Render nothing!
366   application.GetGlAbstraction().ClearBoundTextures();
367   application.SendNotification();
368   application.Render();
369
370   // Check that nothing was rendered
371   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
372
373   END_TEST;
374 }
375
376 int UtcDaliRenderTaskSetSourceActorP02(void)
377 {
378   TestApplication application;
379
380   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that switching source from a non-renderable to a renderable actor causes the texture to be drawn");
381
382   Integration::Scene stage = application.GetScene();
383
384   RenderTaskList taskList = stage.GetRenderTaskList();
385
386   RenderTask task = taskList.GetTask(0u);
387
388   Actor actor = task.GetSourceActor();
389   DALI_TEST_CHECK(actor);
390
391   Texture img      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
392   Actor   newActor = CreateRenderableActor(img);
393   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
394   stage.Add(newActor);
395
396   Actor nonRenderableActor = Actor::New();
397   stage.Add(nonRenderableActor);
398
399   TestGlAbstraction& gl        = application.GetGlAbstraction();
400   TraceCallStack&    drawTrace = gl.GetDrawTrace();
401   drawTrace.Enable(true);
402
403   // Stop the newActor from being rendered by changing the source actor
404   DALI_TEST_CHECK(nonRenderableActor);
405   task.SetSourceActor(nonRenderableActor);
406   DALI_TEST_CHECK(task.GetSourceActor() != actor);
407   DALI_TEST_CHECK(task.GetSourceActor() == nonRenderableActor);
408
409   // Update & Render nothing!
410   application.GetGlAbstraction().ClearBoundTextures();
411   application.SendNotification();
412   application.Render();
413
414   // Check that nothing was rendered
415   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
416   drawTrace.Reset();
417
418   // Set newActor as the new source Actor
419   task.SetSourceActor(newActor);
420   DALI_TEST_CHECK(task.GetSourceActor() != actor);
421   DALI_TEST_CHECK(task.GetSourceActor() == newActor);
422
423   // Update & Render the newActor
424   application.GetGlAbstraction().ClearBoundTextures();
425   application.SendNotification();
426   application.Render();
427
428   // Check that the newActor was rendered
429   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
430   END_TEST;
431 }
432
433 int UtcDaliRenderTaskSetSourceActorOffScene(void)
434 {
435   TestApplication application;
436
437   tet_infoline("Testing RenderTask::SetSourceActor (on/off stage testing)");
438
439   Integration::Scene stage    = application.GetScene();
440   RenderTaskList     taskList = stage.GetRenderTaskList();
441   RenderTask         task     = taskList.GetTask(0u);
442
443   Actor actor = task.GetSourceActor();
444   DALI_TEST_CHECK(actor);
445
446   TestGlAbstraction& gl        = application.GetGlAbstraction();
447   TraceCallStack&    drawTrace = gl.GetDrawTrace();
448   drawTrace.Enable(true);
449
450   Texture img      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
451   Actor   newActor = CreateRenderableActor(img);
452   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
453   task.SetSourceActor(newActor);
454   // Don't add newActor to stage yet   //'
455
456   // Update & Render with the actor initially off-stage
457   application.SendNotification();
458   application.Render();
459
460   // Check that nothing was rendered
461   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
462
463   // Now add to stage
464   stage.Add(newActor);
465
466   // Update & Render with the actor on-stage
467   application.GetGlAbstraction().ClearBoundTextures();
468   application.SendNotification();
469   application.Render();
470
471   // Check that the newActor was rendered
472   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
473   drawTrace.Reset();
474
475   // Now remove from stage
476   stage.Remove(newActor);
477
478   // Update & Render with the actor off-stage
479   application.SendNotification();
480   application.Render();
481   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
482
483   END_TEST;
484 }
485
486 int UtcDaliRenderTaskSetSourceActorEmpty(void)
487 {
488   TestApplication application;
489
490   tet_infoline("Testing RenderTask::SetSourceActor (empty handle case)");
491
492   Integration::Scene stage    = application.GetScene();
493   RenderTaskList     taskList = stage.GetRenderTaskList();
494   RenderTask         task     = taskList.GetTask(0u);
495
496   Actor actor = task.GetSourceActor();
497   DALI_TEST_CHECK(actor);
498
499   Texture img      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
500   Actor   newActor = CreateRenderableActor(img);
501   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
502   stage.Add(newActor);
503
504   Actor nonRenderableActor = Actor::New();
505   stage.Add(nonRenderableActor);
506
507   // Set with empty handle
508   task.SetSourceActor(Actor());
509   DALI_TEST_CHECK(!task.GetSourceActor());
510
511   TestGlAbstraction& gl        = application.GetGlAbstraction();
512   TraceCallStack&    drawTrace = gl.GetDrawTrace();
513   drawTrace.Enable(true);
514
515   // Update & Render nothing!
516   application.SendNotification();
517   application.Render();
518
519   // Check that nothing was rendered
520   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
521
522   // Set with non-empty handle
523   task.SetSourceActor(newActor);
524   DALI_TEST_CHECK(task.GetSourceActor() == newActor);
525
526   // Update & Render the newActor
527   application.GetGlAbstraction().ClearBoundTextures();
528   application.SendNotification();
529   application.Render();
530
531   // Check that the newActor was rendered
532   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
533   END_TEST;
534 }
535
536 int UtcDaliRenderTaskSetSourceActorDestroyed(void)
537 {
538   TestApplication application;
539
540   tet_infoline("Testing RenderTask::SetSourceActor - Set a source actor and destroy the source actor");
541
542   Integration::Scene stage    = application.GetScene();
543   RenderTaskList     taskList = stage.GetRenderTaskList();
544   RenderTask         task     = taskList.GetTask(0u);
545
546   Actor actor = task.GetSourceActor();
547   DALI_TEST_CHECK(actor);
548
549   Texture img = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
550
551   Actor newActor = CreateRenderableActor(img);
552   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
553   stage.Add(newActor);
554
555   task.SetSourceActor(newActor);
556
557   DALI_TEST_CHECK(task.GetSourceActor() != actor);
558   DALI_TEST_CHECK(task.GetSourceActor() == newActor);
559
560   application.SendNotification();
561   application.Render();
562
563   // Destroy the source actor
564   stage.Remove(newActor);
565   newActor.Reset();
566
567   DALI_TEST_CHECK(!task.GetSourceActor()); // The source actor should be an empty handle.
568
569   END_TEST;
570 }
571
572 int UtcDaliRenderTaskGetSourceActorP01(void)
573 {
574   TestApplication application;
575
576   tet_infoline("Testing RenderTask::GetSourceActor() Check the default render task has a valid source actor");
577
578   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
579
580   RenderTask task = taskList.GetTask(0u);
581
582   Actor actor = task.GetSourceActor();
583   DALI_TEST_CHECK(actor);
584
585   // By default the entire scene should be rendered
586   Actor root = application.GetScene().GetLayer(0);
587   DALI_TEST_CHECK(root == actor);
588   END_TEST;
589 }
590
591 int UtcDaliRenderTaskGetSourceActorP02(void)
592 {
593   TestApplication application;
594
595   tet_infoline("Testing RenderTask::GetSourceActor() Create a new render task, Add a new actor to the stage and set it as the source of the new render task. Get its source actor and check that it is equivalent to what was set.");
596
597   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
598   RenderTask     task     = taskList.CreateTask();
599   Actor          actor    = Actor::New();
600   application.GetScene().Add(actor);
601   task.SetSourceActor(actor);
602
603   DALI_TEST_EQUALS(actor, task.GetSourceActor(), TEST_LOCATION);
604
605   END_TEST;
606 }
607
608 int UtcDaliRenderTaskGetSourceActorN(void)
609 {
610   TestApplication application;
611
612   tet_infoline("Testing RenderTask::GetSourceActor() Try with empty handle");
613
614   RenderTask task;
615   try
616   {
617     Actor actor = task.GetSourceActor();
618   }
619   catch(Dali::DaliException& e)
620   {
621     DALI_TEST_PRINT_ASSERT(e);
622     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
623   }
624
625   END_TEST;
626 }
627
628 int UtcDaliRenderTaskSetExclusive(void)
629 {
630   TestApplication application;
631
632   tet_infoline("Testing RenderTask::SetExclusive() Check that exclusion works");
633
634   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
635
636   // Manipulate the GenTextures behaviour, to identify different actors
637
638   std::vector<GLuint> ids;
639   ids.push_back(8);  // 8 = actor1
640   ids.push_back(9);  // 9 = actor2
641   ids.push_back(10); // 10 = actor3
642   application.GetGlAbstraction().SetNextTextureIds(ids);
643
644   Texture img1   = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
645   Actor   actor1 = CreateRenderableActor(img1);
646   actor1.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
647   application.GetScene().Add(actor1);
648
649   // Update & Render actor1
650   application.SendNotification();
651   application.Render();
652
653   // Check that the actor1 was rendered
654   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures(GL_TEXTURE0);
655   DALI_TEST_GREATER(boundTextures.size(), static_cast<std::vector<GLuint>::size_type>(0), TEST_LOCATION);
656
657   if(boundTextures.size())
658   {
659     int c = 0;
660     DALI_TEST_EQUALS(boundTextures[c++], 8u /*unique to actor1*/, TEST_LOCATION);
661     if(boundTextures.size() > 1)
662     {
663       DALI_TEST_EQUALS(boundTextures[c++], 8u /*unique to actor1*/, TEST_LOCATION);
664     }
665   }
666
667   Texture img2 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
668
669   Actor actor2 = CreateRenderableActor(img2);
670   actor2.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
671
672   // Force actor2 to be rendered before actor1
673   Layer layer = Layer::New();
674   application.GetScene().Add(layer);
675   layer.Add(actor2);
676   layer.LowerToBottom();
677
678   // Update & Render
679   application.GetGlAbstraction().ClearBoundTextures();
680   application.SendNotification();
681   application.Render();
682
683   // Check that the actors were rendered
684   DALI_TEST_GREATER(boundTextures.size(), static_cast<std::vector<GLuint>::size_type>(1), TEST_LOCATION);
685
686   if(boundTextures.size())
687   {
688     int c = 0;
689     DALI_TEST_EQUALS(boundTextures[c++], 9u /*unique to actor2*/, TEST_LOCATION);
690     if(boundTextures.size() > 2)
691     {
692       DALI_TEST_EQUALS(boundTextures[c++], 9u /*unique to actor1*/, TEST_LOCATION);
693     }
694     DALI_TEST_EQUALS(boundTextures[c++], 8u /*unique to actor1*/, TEST_LOCATION);
695   }
696
697   Texture img3   = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
698   Actor   actor3 = CreateRenderableActor(img3);
699   actor3.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
700
701   // Force actor3 to be rendered before actor2
702   layer = Layer::New();
703   application.GetScene().Add(layer);
704   layer.Add(actor3);
705   layer.LowerToBottom();
706
707   // Update & Render all actors
708   application.GetGlAbstraction().ClearBoundTextures();
709   application.SendNotification();
710   application.Render();
711
712   // Check that the actors were rendered
713   DALI_TEST_GREATER(boundTextures.size(), static_cast<std::vector<GLuint>::size_type>(2), TEST_LOCATION);
714
715   if(boundTextures.size())
716   {
717     int c = 0;
718     DALI_TEST_EQUALS(boundTextures[c++], 10u /*unique to actor3*/, TEST_LOCATION);
719     if(boundTextures.size() > 3)
720     {
721       DALI_TEST_EQUALS(boundTextures[c++], 10u /*unique to actor2*/, TEST_LOCATION);
722     }
723     DALI_TEST_EQUALS(boundTextures[c++], 9u /*unique to actor2*/, TEST_LOCATION);
724     DALI_TEST_EQUALS(boundTextures[c++], 8u /*unique to actor1*/, TEST_LOCATION);
725   }
726
727   // Both actors are now connected to the root node
728   // Setup 2 render-tasks - the first will render from the root-node, and the second from actor2
729
730   // Not exclusive is the default
731   RenderTask task1 = taskList.GetTask(0u);
732   DALI_TEST_CHECK(false == task1.IsExclusive());
733
734   RenderTask task2 = taskList.CreateTask();
735   DALI_TEST_CHECK(false == task2.IsExclusive());
736   task2.SetSourceActor(actor2);
737
738   // Task1 should render all actors, and task 2 should render only actor2
739
740   application.GetGlAbstraction().ClearBoundTextures();
741   application.SendNotification();
742   application.Render();
743
744   DALI_TEST_EQUALS(boundTextures.size(), 4u, TEST_LOCATION);
745
746   if(boundTextures.size() == 4)
747   {
748     // Test that task 1 renders actor3, then actor2 & then actor1
749     DALI_TEST_CHECK(boundTextures[0] == 10u);
750     DALI_TEST_CHECK(boundTextures[1] == 9u);
751     DALI_TEST_CHECK(boundTextures[2] == 8u);
752
753     // Test that task 2 renders actor2
754     DALI_TEST_EQUALS(boundTextures[3], 9u, TEST_LOCATION);
755   }
756
757   // Make actor2 exclusive to task2
758
759   task2.SetExclusive(true);
760   DALI_TEST_CHECK(true == task2.IsExclusive());
761
762   // Task1 should render only actor1, and task 2 should render only actor2
763
764   application.GetGlAbstraction().ClearBoundTextures();
765   application.SendNotification();
766   application.Render();
767
768   DALI_TEST_EQUALS(boundTextures.size(), 3u, TEST_LOCATION);
769   if(boundTextures.size() == 3)
770   {
771     // Test that task 1 renders actor3 & actor1
772     DALI_TEST_CHECK(boundTextures[0] == 10u);
773     DALI_TEST_CHECK(boundTextures[1] == 8u);
774
775     // Test that task 2 renders actor2
776     DALI_TEST_CHECK(boundTextures[2] == 9u);
777   }
778
779   // Create a renderable actor and replace the source actor in task2
780   auto actor4 = CreateRenderableActor();
781   task2.SetSourceActor(actor3);
782   DALI_TEST_EQUALS(actor3, task2.GetSourceActor(), TEST_LOCATION);
783
784   END_TEST;
785 }
786
787 int UtcDaliRenderTaskSetExclusive02(void)
788 {
789   TestApplication application;
790
791   tet_infoline("Testing RenderTask::SetExclusive() Check that changing from exclusive to not-exclusive works");
792
793   std::vector<GLuint> ids;
794   ids.push_back(8); // 8 = actor1
795   application.GetGlAbstraction().SetNextTextureIds(ids);
796
797   Texture img1   = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
798   Actor   actor1 = CreateRenderableActor(img1);
799   actor1.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
800   application.GetScene().Add(actor1);
801
802   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
803   RenderTask     task     = taskList.CreateTask();
804
805   task.SetSourceActor(actor1);
806   task.SetExclusive(true); // Actor should only render once
807
808   TestGlAbstraction& gl        = application.GetGlAbstraction();
809   TraceCallStack&    drawTrace = gl.GetDrawTrace();
810   drawTrace.Enable(true);
811
812   // Update & Render actor1
813   application.SendNotification();
814   application.Render();
815
816   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
817
818   // Set task to non-exclusive - actor1 should render twice:
819   drawTrace.Reset();
820   task.SetExclusive(false);
821   application.SendNotification();
822   application.Render();
823
824   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 2, TEST_LOCATION);
825
826   END_TEST;
827 }
828
829 int UtcDaliRenderTaskSetExclusiveN(void)
830 {
831   TestApplication application;
832
833   tet_infoline("Testing RenderTask::SetExclusive() on empty handle");
834
835   RenderTask task;
836   try
837   {
838     task.SetExclusive(true);
839   }
840   catch(Dali::DaliException& e)
841   {
842     DALI_TEST_PRINT_ASSERT(e);
843     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
844   }
845   END_TEST;
846 }
847
848 int UtcDaliRenderTaskIsExclusive01(void)
849 {
850   TestApplication application;
851
852   tet_infoline("Testing RenderTask::IsExclusive() Check default values are non-exclusive");
853
854   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
855
856   // Not exclusive is the default
857   RenderTask task = taskList.GetTask(0u);
858   DALI_TEST_CHECK(false == task.IsExclusive());
859
860   RenderTask newTask = taskList.CreateTask();
861   DALI_TEST_CHECK(false == newTask.IsExclusive());
862
863   END_TEST;
864 }
865
866 int UtcDaliRenderTaskIsExclusive02(void)
867 {
868   TestApplication application;
869
870   tet_infoline("Testing RenderTask::IsExclusive() Check the getter returns set values");
871
872   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
873
874   // Not exclusive is the default
875   RenderTask newTask = taskList.CreateTask();
876   DALI_TEST_EQUALS(newTask.IsExclusive(), false, TEST_LOCATION);
877
878   newTask.SetExclusive(true);
879   DALI_TEST_EQUALS(newTask.IsExclusive(), true, TEST_LOCATION);
880   END_TEST;
881 }
882
883 int UtcDaliRenderTaskIsExclusiveN(void)
884 {
885   TestApplication application;
886
887   tet_infoline("Testing RenderTask::IsExclusive() on empty handle");
888
889   RenderTask task;
890   try
891   {
892     bool x = task.IsExclusive();
893     (void)x;
894   }
895   catch(Dali::DaliException& e)
896   {
897     DALI_TEST_PRINT_ASSERT(e);
898     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
899   }
900   END_TEST;
901 }
902
903 int UtcDaliRenderTaskSetInputEnabled(void)
904 {
905   TestApplication application;
906
907   tet_infoline("Testing RenderTask::SetInputEnabled()");
908
909   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
910
911   // Input is enabled by default
912   RenderTask task = taskList.GetTask(0u);
913   DALI_TEST_CHECK(true == task.GetInputEnabled());
914
915   task.SetInputEnabled(false);
916   DALI_TEST_CHECK(false == task.GetInputEnabled());
917
918   task.SetInputEnabled(true);
919   DALI_TEST_CHECK(true == task.GetInputEnabled());
920   END_TEST;
921 }
922
923 int UtcDaliRenderTaskGetInputEnabled(void)
924 {
925   TestApplication application;
926
927   tet_infoline("Testing RenderTask::GetInputEnabled()");
928
929   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
930
931   // Input is enabled by default
932   RenderTask task = taskList.GetTask(0u);
933   DALI_TEST_EQUALS(true, task.GetInputEnabled(), TEST_LOCATION);
934
935   RenderTask newTask = taskList.CreateTask();
936   DALI_TEST_EQUALS(true, newTask.GetInputEnabled(), TEST_LOCATION);
937
938   newTask.SetInputEnabled(false);
939   DALI_TEST_EQUALS(false, newTask.GetInputEnabled(), TEST_LOCATION);
940
941   END_TEST;
942 }
943
944 int UtcDaliRenderTaskSetCameraActorP(void)
945 {
946   TestApplication application;
947
948   tet_infoline("Testing RenderTask::SetCameraActor()");
949
950   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
951
952   RenderTask task = taskList.GetTask(0u);
953
954   Actor defaultCameraActor = task.GetCameraActor();
955   DALI_TEST_CHECK(defaultCameraActor);
956
957   CameraActor newCameraActor = CameraActor::New();
958   DALI_TEST_CHECK(newCameraActor);
959
960   task.SetCameraActor(newCameraActor);
961   DALI_TEST_CHECK(task.GetCameraActor() != defaultCameraActor);
962   DALI_TEST_EQUALS(task.GetCameraActor(), newCameraActor, TEST_LOCATION);
963   END_TEST;
964 }
965
966 int UtcDaliRenderTaskSetCameraActorN(void)
967 {
968   TestApplication application;
969
970   tet_infoline("Testing RenderTask::SetCameraActor() with empty actor handle");
971
972   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
973
974   RenderTask task = taskList.GetTask(0u);
975
976   Actor actor = task.GetCameraActor();
977   DALI_TEST_CHECK(actor);
978
979   CameraActor cameraActor;
980
981   task.SetCameraActor(cameraActor);
982   DALI_TEST_EQUALS((bool)task.GetCameraActor(), false, TEST_LOCATION);
983   DALI_TEST_EQUALS(task.GetCameraActor(), cameraActor, TEST_LOCATION);
984   END_TEST;
985 }
986
987 int UtcDaliRenderTaskSetCameraActorDestroyed(void)
988 {
989   TestApplication application;
990
991   tet_infoline("Testing RenderTask::SetCameraActor - Set a camera actor and destroy the camera actor");
992
993   Integration::Scene stage    = application.GetScene();
994   RenderTaskList     taskList = stage.GetRenderTaskList();
995   RenderTask         task     = taskList.GetTask(0u);
996
997   CameraActor newCameraActor = CameraActor::New();
998   task.SetCameraActor(newCameraActor);
999
1000   DALI_TEST_EQUALS(task.GetCameraActor(), newCameraActor, TEST_LOCATION);
1001
1002   // Destroy the camera actor
1003   newCameraActor.Reset();
1004
1005   CameraActor camera = task.GetCameraActor();
1006   DALI_TEST_CHECK(!camera); // The camera actor should be an empty handle.
1007
1008   END_TEST;
1009 }
1010
1011 int UtcDaliRenderTaskGetCameraActorP(void)
1012 {
1013   TestApplication application;
1014
1015   tet_infoline("Testing RenderTask::GetCameraActor()");
1016
1017   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1018
1019   RenderTask task = taskList.GetTask(0u);
1020
1021   CameraActor actor = task.GetCameraActor();
1022   DALI_TEST_CHECK(actor);
1023   DALI_TEST_EQUALS(actor.GetProjectionMode(), Dali::Camera::PERSPECTIVE_PROJECTION, TEST_LOCATION);
1024   DALI_TEST_GREATER(actor.GetFieldOfView(), 0.0f, TEST_LOCATION);
1025   END_TEST;
1026 }
1027
1028 int UtcDaliRenderTaskGetCameraActorN(void)
1029 {
1030   TestApplication application;
1031
1032   tet_infoline("Testing RenderTask::GetCameraActor() with empty handle");
1033   RenderTask task;
1034
1035   try
1036   {
1037     Actor actor = task.GetCameraActor();
1038   }
1039   catch(Dali::DaliException& e)
1040   {
1041     DALI_TEST_PRINT_ASSERT(e);
1042     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1043   }
1044
1045   END_TEST;
1046 }
1047
1048 int UtcDaliRenderTaskSetFrameBufferP(void)
1049 {
1050   TestApplication application;
1051
1052   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1053
1054   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1055
1056   RenderTask task = taskList.GetTask(0u);
1057
1058   FrameBuffer newFrameBuffer = FrameBuffer::New(128u, 128u, FrameBuffer::Attachment::NONE);
1059   task.SetFrameBuffer(newFrameBuffer);
1060   DALI_TEST_CHECK(task.GetFrameBuffer() == newFrameBuffer);
1061   END_TEST;
1062 }
1063
1064 int UtcDaliRenderTaskSetFrameBufferN(void)
1065 {
1066   TestApplication application;
1067
1068   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1069
1070   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1071
1072   RenderTask  task = taskList.GetTask(0u);
1073   FrameBuffer newFrameBuffer; // Empty handle
1074   task.SetFrameBuffer(newFrameBuffer);
1075   DALI_TEST_EQUALS((bool)task.GetFrameBuffer(), false, TEST_LOCATION);
1076   END_TEST;
1077 }
1078
1079 int UtcDaliRenderTaskGetFrameBufferP(void)
1080 {
1081   TestApplication application;
1082
1083   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1084
1085   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1086
1087   RenderTask task = taskList.GetTask(0u);
1088
1089   FrameBuffer newFrameBuffer = FrameBuffer::New(1u, 1u, FrameBuffer::Attachment::NONE);
1090   task.SetFrameBuffer(newFrameBuffer);
1091   DALI_TEST_CHECK(task.GetFrameBuffer() == newFrameBuffer);
1092   END_TEST;
1093 }
1094
1095 int UtcDaliRenderTaskGetFrameBufferN(void)
1096 {
1097   TestApplication application;
1098
1099   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1100
1101   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1102
1103   RenderTask task = taskList.GetTask(0u);
1104
1105   // By default render-tasks do not render off-screen
1106   FrameBuffer frameBuffer = task.GetFrameBuffer();
1107   DALI_TEST_CHECK(!frameBuffer);
1108
1109   END_TEST;
1110 }
1111
1112 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionP(void)
1113 {
1114   TestApplication application;
1115
1116   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1117
1118   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1119
1120   RenderTask task = taskList.GetTask(0u);
1121
1122   task.SetScreenToFrameBufferFunction(TestScreenToFrameBufferFunction);
1123
1124   Vector2 coordinates(5, 10);
1125   Vector2 convertedCoordinates(6, 12); // + Vector(1, 2)
1126
1127   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1128   DALI_TEST_CHECK(func(coordinates));
1129   DALI_TEST_CHECK(coordinates == convertedCoordinates);
1130
1131   task.SetScreenToFrameBufferFunction(RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION);
1132   func = task.GetScreenToFrameBufferFunction();
1133   DALI_TEST_CHECK(func(coordinates));
1134
1135   task.SetScreenToFrameBufferFunction(RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION);
1136   func = task.GetScreenToFrameBufferFunction();
1137   DALI_TEST_CHECK(!func(coordinates));
1138   END_TEST;
1139 }
1140
1141 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionN(void)
1142 {
1143   TestApplication application;
1144
1145   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1146
1147   RenderTask task; // Empty handle
1148   try
1149   {
1150     task.SetScreenToFrameBufferFunction(TestScreenToFrameBufferFunction);
1151   }
1152   catch(Dali::DaliException& e)
1153   {
1154     DALI_TEST_PRINT_ASSERT(e);
1155     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1156   }
1157   END_TEST;
1158 }
1159
1160 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionP(void)
1161 {
1162   TestApplication application;
1163
1164   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction()");
1165
1166   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1167
1168   RenderTask task = taskList.GetTask(0u);
1169
1170   Vector2 originalCoordinates(5, 10);
1171   Vector2 coordinates(5, 10);
1172
1173   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1174   DALI_TEST_CHECK(!func(coordinates));                 // conversion should fail by default
1175   DALI_TEST_CHECK(coordinates == originalCoordinates); // coordinates should not be modified
1176   END_TEST;
1177 }
1178
1179 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionN(void)
1180 {
1181   TestApplication application;
1182
1183   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction() on empty handle");
1184
1185   RenderTask task;
1186   try
1187   {
1188     RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1189     (void)func;
1190   }
1191   catch(Dali::DaliException& e)
1192   {
1193     DALI_TEST_PRINT_ASSERT(e);
1194     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1195   }
1196   END_TEST;
1197 }
1198
1199 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorP(void)
1200 {
1201   TestApplication application;
1202   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor ");
1203
1204   RenderTaskList taskList     = application.GetScene().GetRenderTaskList();
1205   RenderTask     renderTask   = taskList.CreateTask();
1206   Actor          mappingActor = Actor::New();
1207   renderTask.SetScreenToFrameBufferMappingActor(mappingActor);
1208
1209   DALI_TEST_EQUALS(mappingActor, renderTask.GetScreenToFrameBufferMappingActor(), TEST_LOCATION);
1210   END_TEST;
1211 }
1212
1213 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorN(void)
1214 {
1215   TestApplication application;
1216   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1217
1218   RenderTask task;
1219   try
1220   {
1221     Actor mappingActor;
1222     task.SetScreenToFrameBufferMappingActor(mappingActor);
1223   }
1224   catch(Dali::DaliException& e)
1225   {
1226     DALI_TEST_PRINT_ASSERT(e);
1227     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1228   }
1229   END_TEST;
1230 }
1231
1232 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActor02N(void)
1233 {
1234   TestApplication application;
1235   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1236
1237   RenderTaskList taskList   = application.GetScene().GetRenderTaskList();
1238   RenderTask     renderTask = taskList.CreateTask();
1239   Actor          actor;
1240   renderTask.SetScreenToFrameBufferMappingActor(actor);
1241
1242   DALI_TEST_EQUALS((bool)renderTask.GetScreenToFrameBufferMappingActor(), false, TEST_LOCATION);
1243   END_TEST;
1244 }
1245
1246 int UtcDaliRenderTaskGetViewportP01(void)
1247 {
1248   TestApplication application;
1249
1250   tet_infoline("Testing RenderTask::GetViewport() on default task");
1251
1252   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1253   RenderTask     task     = taskList.GetTask(0u);
1254   Viewport       viewport = task.GetViewport();
1255
1256   // By default the viewport should match the stage width/height
1257   Vector2  stageSize = application.GetScene().GetSize();
1258   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1259   DALI_TEST_CHECK(viewport == expectedViewport);
1260   END_TEST;
1261 }
1262
1263 int UtcDaliRenderTaskGetViewportP02(void)
1264 {
1265   TestApplication application;
1266
1267   tet_infoline("Testing RenderTask::GetViewport() on new task");
1268
1269   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1270   RenderTask     task     = taskList.CreateTask();
1271   Viewport       viewport = task.GetViewport();
1272
1273   // By default the viewport should match the stage width/height
1274   Vector2  stageSize = application.GetScene().GetSize();
1275   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1276   DALI_TEST_CHECK(viewport == expectedViewport);
1277   END_TEST;
1278 }
1279
1280 int UtcDaliRenderTaskGetViewportN(void)
1281 {
1282   TestApplication application;
1283
1284   tet_infoline("Testing RenderTask::GetViewport() on empty handle");
1285
1286   RenderTask task;
1287   try
1288   {
1289     Viewport viewport = task.GetViewport();
1290     (void)viewport;
1291   }
1292   catch(Dali::DaliException& e)
1293   {
1294     DALI_TEST_PRINT_ASSERT(e);
1295     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1296   }
1297   END_TEST;
1298 }
1299
1300 int UtcDaliRenderTaskSetViewportP(void)
1301 {
1302   TestApplication application;
1303
1304   tet_infoline("Testing RenderTask::SetViewport()");
1305
1306   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1307
1308   RenderTask task      = taskList.GetTask(0u);
1309   Vector2    stageSize = application.GetScene().GetSize();
1310   Viewport   newViewport(0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f);
1311   task.SetViewport(newViewport);
1312
1313   // Update (viewport is a property)
1314   application.SendNotification();
1315   application.Render();
1316
1317   DALI_TEST_CHECK(task.GetViewport() == newViewport);
1318   END_TEST;
1319 }
1320
1321 int UtcDaliRenderTaskSetViewportN(void)
1322 {
1323   TestApplication application;
1324
1325   tet_infoline("Testing RenderTask::SetViewport()");
1326
1327   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1328
1329   RenderTask task;
1330   try
1331   {
1332     Vector2  stageSize = application.GetScene().GetSize();
1333     Viewport newViewport(0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f);
1334     task.SetViewport(newViewport);
1335   }
1336   catch(Dali::DaliException& e)
1337   {
1338     DALI_TEST_PRINT_ASSERT(e);
1339     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1340   }
1341
1342   END_TEST;
1343 }
1344
1345 int UtcDaliRenderTaskSetViewportPosition(void)
1346 {
1347   TestApplication application;
1348
1349   tet_infoline("Testing RenderTask::SetViewportPosition()");
1350
1351   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1352
1353   RenderTask task = taskList.GetTask(0u);
1354
1355   Viewport viewport = task.GetViewport();
1356
1357   // By default the viewport should match the stage width/height
1358
1359   Vector2  stageSize = application.GetScene().GetSize();
1360   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1361   DALI_TEST_CHECK(viewport == expectedViewport);
1362
1363   // 'Setter' test
1364   Vector2 newPosition(25.0f, 50.0f);
1365   task.SetViewportPosition(newPosition);
1366
1367   // Update (viewport is a property)
1368   application.SendNotification();
1369   application.Render();
1370
1371   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1372
1373   // Set by Property test
1374   Vector2 newPosition2(32.0f, 32.0f);
1375   task.SetProperty(RenderTask::Property::VIEWPORT_POSITION, newPosition2);
1376   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1377   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition, TEST_LOCATION); // still the old position
1378
1379   // Update
1380   application.SendNotification();
1381   application.Render();
1382
1383   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition2, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1384   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1385   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1386
1387   Vector2   newPosition3(64.0f, 0.0f);
1388   Animation animation = Animation::New(1.0f);
1389   animation.AnimateTo(Property(task, RenderTask::Property::VIEWPORT_POSITION), newPosition3, AlphaFunction::LINEAR);
1390   animation.Play();
1391
1392   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1393   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1394
1395   // Perform 1000ms worth of updates at which point animation should have completed.
1396   Wait(application, 1000);
1397   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1398   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1399   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1400
1401   // Create another animation which animates by a certain value
1402   const Vector2 newPosition4(75.0f, 45.0f);
1403   const Vector2 relativePosition(newPosition4 - newPosition3);
1404   animation = Animation::New(1.0f);
1405   animation.AnimateBy(Property(task, RenderTask::Property::VIEWPORT_POSITION), relativePosition);
1406   animation.Play();
1407
1408   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1409   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, TEST_LOCATION);
1410
1411   // Perform 1000ms worth of updates at which point animation should have completed.
1412   Wait(application, 1000);
1413   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1414   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1415   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1416
1417   END_TEST;
1418 }
1419
1420 int UtcDaliRenderTaskSetViewportSize(void)
1421 {
1422   TestApplication application;
1423
1424   tet_infoline("Testing RenderTask::SetViewportSize()");
1425
1426   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1427
1428   RenderTask task = taskList.GetTask(0u);
1429
1430   Viewport viewport = task.GetViewport();
1431
1432   // By default the viewport should match the stage width/height
1433
1434   Vector2  stageSize = application.GetScene().GetSize();
1435   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1436   DALI_TEST_CHECK(viewport == expectedViewport);
1437
1438   Vector2 newSize(128.0f, 64.0f);
1439   task.SetViewportSize(newSize);
1440
1441   // Update (viewport is a property)
1442   application.SendNotification();
1443   application.Render();
1444
1445   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1446
1447   // Set by Property test
1448   Vector2 newSize2(50.0f, 50.0f);
1449   task.SetProperty(RenderTask::Property::VIEWPORT_SIZE, newSize2);
1450   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1451   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize, TEST_LOCATION); // still the old position
1452
1453   // Update
1454   application.SendNotification();
1455   application.Render();
1456
1457   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize2, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1458   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1459   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1460
1461   Vector2   newSize3(10.0f, 10.0f);
1462   Animation animation = Animation::New(1.0f);
1463   animation.AnimateTo(Property(task, RenderTask::Property::VIEWPORT_SIZE), newSize3, AlphaFunction::LINEAR);
1464   animation.Play();
1465
1466   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1467   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1468
1469   // Perform 1000ms worth of updates at which point animation should have completed.
1470   Wait(application, 1000);
1471   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1472   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1473   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1474
1475   // Create another animation which animates by a certain value
1476   const Vector2 newSize4(75.0f, 45.0f);
1477   const Vector2 relativeSize(newSize4 - newSize3);
1478   animation = Animation::New(1.0f);
1479   animation.AnimateBy(Property(task, RenderTask::Property::VIEWPORT_SIZE), relativeSize);
1480   animation.Play();
1481
1482   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1483   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, TEST_LOCATION);
1484
1485   // Perform 1000ms worth of updates at which point animation should have completed.
1486   Wait(application, 1000);
1487   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1488   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1489   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1490
1491   END_TEST;
1492 }
1493
1494 int UtcDaliRenderTaskSetClearColorP(void)
1495 {
1496   TestApplication application;
1497
1498   tet_infoline("Testing RenderTask::SetClearColor()");
1499
1500   Vector4 testColor(1.0f, 2.0f, 3.0f, 4.0f);
1501   Vector4 testColor2(5.0f, 6.0f, 7.0f, 8.0f);
1502
1503   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1504
1505   RenderTask task = taskList.GetTask(0u);
1506   DALI_TEST_CHECK(task.GetClearColor() != testColor);
1507
1508   task.SetClearColor(testColor);
1509
1510   // Wait a frame.
1511   Wait(application);
1512
1513   DALI_TEST_EQUALS(task.GetClearColor(), testColor, TEST_LOCATION);
1514
1515   task.SetProperty(RenderTask::Property::CLEAR_COLOR, testColor2);
1516   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1517   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor, TEST_LOCATION); // still the old color
1518
1519   // Wait a frame.
1520   Wait(application);
1521
1522   DALI_TEST_EQUALS(task.GetClearColor(), testColor2, TEST_LOCATION);
1523   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1524   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1525
1526   Vector4   newColor3(10.0f, 10.0f, 20.0f, 30.0f);
1527   Animation animation = Animation::New(1.0f);
1528   animation.AnimateTo(Property(task, RenderTask::Property::CLEAR_COLOR), newColor3, AlphaFunction::LINEAR);
1529   animation.Play();
1530
1531   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1532   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1533
1534   // Perform 1000ms worth of updates at which point animation should have completed.
1535   Wait(application, 1000);
1536   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1537   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1538
1539   // Create another animation which animates by a certain value
1540   const Vector4 newColor4(0.45f, 0.35f, 0.25f, 0.1f);
1541   const Vector4 relativeColor(newColor4 - newColor3);
1542   animation = Animation::New(1.0f);
1543   animation.AnimateBy(Property(task, RenderTask::Property::CLEAR_COLOR), relativeColor);
1544   animation.Play();
1545
1546   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor4, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1547   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1548
1549   // Perform 1000ms worth of updates at which point animation should have completed.
1550   Wait(application, 1000);
1551   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor4, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1552   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor4, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1553
1554   END_TEST;
1555 }
1556
1557 int UtcDaliRenderTaskSetClearColorN(void)
1558 {
1559   TestApplication application;
1560
1561   tet_infoline("Testing RenderTask::SetClearColor() on empty handle");
1562
1563   RenderTask task;
1564   try
1565   {
1566     task.SetClearColor(Vector4::ZERO);
1567   }
1568   catch(Dali::DaliException& e)
1569   {
1570     DALI_TEST_PRINT_ASSERT(e);
1571     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1572   }
1573   END_TEST;
1574 }
1575
1576 int UtcDaliRenderTaskGetClearColorP(void)
1577 {
1578   TestApplication application;
1579
1580   tet_infoline("Testing RenderTask::GetClearColor()");
1581
1582   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1583   RenderTask     task     = taskList.GetTask(0u);
1584   DALI_TEST_EQUALS(task.GetClearColor(), RenderTask::DEFAULT_CLEAR_COLOR, TEST_LOCATION);
1585   END_TEST;
1586 }
1587
1588 int UtcDaliRenderTaskGetClearColorN(void)
1589 {
1590   TestApplication application;
1591
1592   tet_infoline("Testing RenderTask::GetClearColor()");
1593
1594   RenderTask task;
1595   try
1596   {
1597     Vector4 color = task.GetClearColor();
1598     (void)color;
1599   }
1600   catch(Dali::DaliException& e)
1601   {
1602     DALI_TEST_PRINT_ASSERT(e);
1603     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1604   }
1605   END_TEST;
1606 }
1607
1608 int UtcDaliRenderTaskSetClearEnabledP(void)
1609 {
1610   TestApplication application;
1611
1612   tet_infoline("Testing RenderTask::SetClearEnabled()");
1613
1614   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1615
1616   RenderTask task = taskList.GetTask(0u);
1617   DALI_TEST_CHECK(task.GetClearEnabled()); // defaults to true
1618
1619   task.SetClearEnabled(false);
1620   DALI_TEST_EQUALS(task.GetClearEnabled(), false, TEST_LOCATION);
1621
1622   task.SetClearEnabled(true);
1623   DALI_TEST_EQUALS(task.GetClearEnabled(), true, TEST_LOCATION);
1624   END_TEST;
1625 }
1626
1627 int UtcDaliRenderTaskSetClearEnabledN(void)
1628 {
1629   TestApplication application;
1630
1631   tet_infoline("Testing RenderTask::SetClearEnabled() with empty handle");
1632
1633   RenderTask task;
1634   try
1635   {
1636     task.SetClearEnabled(true);
1637   }
1638   catch(Dali::DaliException& e)
1639   {
1640     DALI_TEST_PRINT_ASSERT(e);
1641     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1642   }
1643   END_TEST;
1644 }
1645
1646 int UtcDaliRenderTaskGetClearEnabledP(void)
1647 {
1648   TestApplication application;
1649
1650   tet_infoline("Testing RenderTask::GetClearEnabled()");
1651
1652   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1653
1654   RenderTask task = taskList.GetTask(0u);
1655   DALI_TEST_CHECK(task.GetClearEnabled()); // defaults to true
1656   END_TEST;
1657 }
1658
1659 int UtcDaliRenderTaskGetClearEnabledN(void)
1660 {
1661   TestApplication application;
1662
1663   tet_infoline("Testing RenderTask::GetClearEnabled() with empty handle");
1664
1665   RenderTask task;
1666   try
1667   {
1668     bool x = task.GetClearEnabled();
1669     (void)x;
1670   }
1671   catch(Dali::DaliException& e)
1672   {
1673     DALI_TEST_PRINT_ASSERT(e);
1674     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1675   }
1676   END_TEST;
1677 }
1678
1679 int UtcDaliRenderTaskSetCullModeP(void)
1680 {
1681   TestApplication application;
1682
1683   tet_infoline("Testing RenderTask::SetCullMode()");
1684
1685   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1686   RenderTask     task     = taskList.GetTask(0u);
1687   DALI_TEST_EQUALS(task.GetCullMode(), true, TEST_LOCATION);
1688
1689   task.SetCullMode(false);
1690
1691   DALI_TEST_EQUALS(task.GetCullMode(), false, TEST_LOCATION);
1692
1693   END_TEST;
1694 }
1695
1696 int UtcDaliRenderTaskSetCullModeN(void)
1697 {
1698   TestApplication application;
1699
1700   tet_infoline("Testing RenderTask::SetCullMode() on empty handle");
1701
1702   RenderTask task;
1703   try
1704   {
1705     task.SetCullMode(false);
1706   }
1707   catch(Dali::DaliException& e)
1708   {
1709     DALI_TEST_PRINT_ASSERT(e);
1710     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1711   }
1712   END_TEST;
1713 }
1714
1715 int UtcDaliRenderTaskGetCullModeP(void)
1716 {
1717   TestApplication application;
1718
1719   tet_infoline("Testing RenderTask::GetCullMode()");
1720
1721   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1722   RenderTask     task     = taskList.GetTask(0u);
1723   DALI_TEST_EQUALS(task.GetCullMode(), true, TEST_LOCATION);
1724   END_TEST;
1725 }
1726
1727 int UtcDaliRenderTaskGetCullModeN(void)
1728 {
1729   TestApplication application;
1730
1731   tet_infoline("Testing RenderTask::GetCullMode() with empty handle");
1732
1733   RenderTask task;
1734   try
1735   {
1736     bool x = task.GetCullMode();
1737     (void)x;
1738   }
1739   catch(Dali::DaliException& e)
1740   {
1741     DALI_TEST_PRINT_ASSERT(e);
1742     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1743   }
1744   END_TEST;
1745 }
1746
1747 int UtcDaliRenderTaskSetRefreshRate(void)
1748 {
1749   TestApplication application;
1750
1751   tet_infoline("Testing RenderTask::SetRefreshRate()");
1752
1753   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1754
1755   // By default tasks will be processed every frame
1756   RenderTask task = taskList.GetTask(0u);
1757   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == task.GetRefreshRate());
1758
1759   task.SetRefreshRate(2u); // every-other frame
1760   DALI_TEST_CHECK(2u == task.GetRefreshRate());
1761
1762   task.SetRefreshRate(RenderTask::REFRESH_ALWAYS);
1763   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == task.GetRefreshRate());
1764   END_TEST;
1765 }
1766
1767 int UtcDaliRenderTaskGetRefreshRate(void)
1768 {
1769   TestApplication application;
1770
1771   tet_infoline("Testing RenderTask::GetRefreshRate()");
1772
1773   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1774
1775   // By default tasks will be processed every frame
1776   RenderTask task = taskList.GetTask(0u);
1777   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == task.GetRefreshRate());
1778
1779   RenderTask newTask = taskList.CreateTask();
1780   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == newTask.GetRefreshRate());
1781   END_TEST;
1782 }
1783
1784 int UtcDaliRenderTaskSignalFinished(void)
1785 {
1786   TestApplication application;
1787
1788   tet_infoline("Testing RenderTask::SignalFinished()");
1789
1790   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1791   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1792
1793   CameraActor offscreenCameraActor = CameraActor::New();
1794
1795   application.GetScene().Add(offscreenCameraActor);
1796
1797   Texture image     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 10, 10);
1798   Actor   rootActor = CreateRenderableActor(image);
1799   rootActor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1800   application.GetScene().Add(rootActor);
1801
1802   RenderTaskList          taskList           = application.GetScene().GetRenderTaskList();
1803   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
1804   Texture                 frameBufferTexture = Texture::New(*testNativeImagePtr);
1805   FrameBuffer             frameBuffer        = FrameBuffer::New(frameBufferTexture.GetWidth(), frameBufferTexture.GetHeight());
1806   frameBuffer.AttachColorTexture(frameBufferTexture);
1807
1808   RenderTask newTask = taskList.CreateTask();
1809   newTask.SetCameraActor(offscreenCameraActor);
1810   newTask.SetSourceActor(rootActor);
1811   newTask.SetInputEnabled(false);
1812   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
1813   newTask.SetClearEnabled(true);
1814   newTask.SetExclusive(true);
1815   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1816   newTask.SetFrameBuffer(frameBuffer);
1817   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, true);
1818
1819   bool               finished = false;
1820   RenderTaskFinished renderTaskFinished(finished);
1821   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
1822
1823   // Flush the queue and render.
1824   application.SendNotification();
1825
1826   // 1 render to process render task, then wait for sync before finished msg is sent
1827   // from update to the event thread.
1828
1829   application.Render();
1830   application.SendNotification();
1831   DALI_TEST_CHECK(!finished);
1832
1833   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1834   DALI_TEST_CHECK(lastSyncObj != NULL);
1835
1836   application.Render();
1837   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
1838   application.SendNotification();
1839   DALI_TEST_CHECK(!finished);
1840
1841   application.Render();
1842   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
1843   application.SendNotification();
1844   DALI_TEST_CHECK(!finished);
1845
1846   sync.SetObjectSynced(lastSyncObj, true);
1847
1848   application.Render();
1849   application.SendNotification();
1850   DALI_TEST_CHECK(!finished);
1851
1852   application.Render();
1853   application.SendNotification();
1854   DALI_TEST_CHECK(finished);
1855
1856   DALI_TEST_EQUALS(application.GetUpdateStatus(), 0, TEST_LOCATION);
1857   END_TEST;
1858 }
1859
1860 int UtcDaliRenderTaskContinuous01(void)
1861 {
1862   TestApplication application;
1863
1864   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not staged)\nPOST:continuous renders, no Finished signal");
1865
1866   // SETUP AN OFFSCREEN RENDER TASK
1867   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1868   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1869   drawTrace.Enable(true);
1870
1871   Actor rootActor = Actor::New();
1872   application.GetScene().Add(rootActor);
1873
1874   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
1875   application.GetScene().Add(offscreenCameraActor);
1876
1877   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1878
1879   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1880   bool               finished = false;
1881   RenderTaskFinished renderTaskFinished(finished);
1882   application.SendNotification();
1883
1884   // START PROCESS/RENDER                     Input,    Expected  Input, Expected, KeepUpdating
1885   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, false, __LINE__));
1886   application.GetPlatform().ClearReadyResources();
1887
1888   // ADD SOURCE ACTOR TO STAGE - expect continuous renders to start, no finished signal
1889   application.GetScene().Add(secondRootActor);
1890   application.SendNotification();
1891
1892   // CONTINUE PROCESS/RENDER                  Input,    Expected  Input,    Expected
1893   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
1894   END_TEST;
1895 }
1896
1897 int UtcDaliRenderTaskContinuous02(void)
1898 {
1899   TestApplication application;
1900
1901   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not visible)\nPOST:continuous renders, no Finished signal");
1902
1903   // SETUP AN OFFSCREEN RENDER TASK
1904   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1905   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1906   drawTrace.Enable(true);
1907
1908   Actor rootActor = Actor::New();
1909   application.GetScene().Add(rootActor);
1910
1911   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
1912   application.GetScene().Add(offscreenCameraActor);
1913
1914   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1915   application.GetScene().Add(secondRootActor);
1916   secondRootActor.SetProperty(Actor::Property::VISIBLE, false);
1917
1918   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1919   bool               finished = false;
1920   RenderTaskFinished renderTaskFinished(finished);
1921   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
1922   application.SendNotification();
1923
1924   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected, KeepUpdating
1925   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, false, __LINE__));
1926   application.GetPlatform().ClearReadyResources();
1927
1928   // MAKE SOURCE ACTOR VISIBLE - expect continuous renders to start, no finished signal
1929   secondRootActor.SetProperty(Actor::Property::VISIBLE, true);
1930   application.SendNotification();
1931
1932   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1933   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
1934   END_TEST;
1935 }
1936
1937 int UtcDaliRenderTaskContinuous03(void)
1938 {
1939   TestApplication application;
1940
1941   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (camera actor not staged)\nPOST:continuous renders, no Finished signal");
1942
1943   // SETUP AN OFFSCREEN RENDER TASK
1944   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1945   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1946   drawTrace.Enable(true);
1947
1948   Actor rootActor = Actor::New();
1949   application.GetScene().Add(rootActor);
1950
1951   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
1952   Actor       secondRootActor      = CreateRenderableActorSuccess(application, "aFile.jpg");
1953   application.GetScene().Add(secondRootActor);
1954
1955   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1956   bool               finished = false;
1957   RenderTaskFinished renderTaskFinished(finished);
1958   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
1959   application.SendNotification();
1960
1961   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1962   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, false, __LINE__));
1963   application.GetPlatform().ClearReadyResources();
1964
1965   // ADD CAMERA ACTOR TO STAGE - expect continuous renders to start, no finished signal
1966   application.GetScene().Add(offscreenCameraActor);
1967   application.SendNotification();
1968
1969   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1970   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
1971   END_TEST;
1972 }
1973
1974 int UtcDaliRenderTaskContinuous04(void)
1975 {
1976   TestApplication application;
1977
1978   tet_infoline("Testing RenderTask Render Continuous using loaded image");
1979
1980   // SETUP AN OFFSCREEN RENDER TASK
1981   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1982   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1983   drawTrace.Enable(true);
1984
1985   Actor rootActor = Actor::New();
1986   application.GetScene().Add(rootActor);
1987
1988   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
1989   application.GetScene().Add(offscreenCameraActor);
1990   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1991   application.GetScene().Add(secondRootActor);
1992
1993   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1994   bool               finished = false;
1995   RenderTaskFinished renderTaskFinished(finished);
1996   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
1997   application.SendNotification();
1998
1999   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2000   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2001   END_TEST;
2002 }
2003
2004 int UtcDaliRenderTaskOnce01(void)
2005 {
2006   TestApplication application;
2007
2008   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image");
2009
2010   // SETUP AN OFFSCREEN RENDER TASK
2011   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2012   TestGlSyncAbstraction& sync      = application.GetGlSyncAbstraction();
2013   TraceCallStack&        drawTrace = application.GetGlAbstraction().GetDrawTrace();
2014   drawTrace.Enable(true);
2015
2016   Actor rootActor = Actor::New();
2017   application.GetScene().Add(rootActor);
2018
2019   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2020   application.GetScene().Add(offscreenCameraActor);
2021   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2022
2023   application.GetScene().Add(secondRootActor);
2024
2025   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2026   bool               finished = false;
2027   RenderTaskFinished renderTaskFinished(finished);
2028   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2029   application.SendNotification();
2030
2031   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2032
2033   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2034   DALI_TEST_CHECK(lastSyncObj != NULL);
2035   sync.SetObjectSynced(lastSyncObj, true);
2036
2037   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2038   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2039   END_TEST;
2040 }
2041
2042 int UtcDaliRenderTaskOnce02(void)
2043 {
2044   TestApplication application;
2045
2046   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n");
2047
2048   // SETUP AN OFFSCREEN RENDER TASK
2049   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2050   TestGlSyncAbstraction& sync      = application.GetGlSyncAbstraction();
2051   TraceCallStack&        drawTrace = application.GetGlAbstraction().GetDrawTrace();
2052   drawTrace.Enable(true);
2053
2054   Actor rootActor = Actor::New();
2055   application.GetScene().Add(rootActor);
2056
2057   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2058   application.GetScene().Add(offscreenCameraActor);
2059
2060   Shader     shader     = CreateShader();
2061   Texture    image      = CreateTexture();
2062   TextureSet textureSet = CreateTextureSet(image);
2063
2064   Geometry geometry = CreateQuadGeometry();
2065   Renderer renderer = Renderer::New(geometry, shader);
2066   renderer.SetTextures(textureSet);
2067   Actor secondRootActor = Actor::New();
2068   secondRootActor.AddRenderer(renderer);
2069   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2070   application.GetScene().Add(secondRootActor);
2071
2072   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2073   bool               finished = false;
2074   RenderTaskFinished renderTaskFinished(finished);
2075   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2076   application.SendNotification();
2077
2078   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2079
2080   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2081   DALI_TEST_CHECK(lastSyncObj != NULL);
2082   sync.SetObjectSynced(lastSyncObj, true);
2083
2084   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2085   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2086
2087   END_TEST;
2088 }
2089
2090 int UtcDaliRenderTaskOnce03(void)
2091 {
2092   TestApplication application;
2093
2094   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image. Switch from render always after ready to render once\n");
2095
2096   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2097   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2098   TestGlSyncAbstraction& sync      = application.GetGlSyncAbstraction();
2099   TraceCallStack&        drawTrace = application.GetGlAbstraction().GetDrawTrace();
2100   drawTrace.Enable(true);
2101
2102   Actor rootActor = Actor::New();
2103   application.GetScene().Add(rootActor);
2104
2105   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2106   application.GetScene().Add(offscreenCameraActor);
2107   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2108   application.GetScene().Add(secondRootActor);
2109
2110   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2111   bool               finished = false;
2112   RenderTaskFinished renderTaskFinished(finished);
2113   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2114   application.SendNotification();
2115
2116   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2117
2118   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2119   application.SendNotification();
2120
2121   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2122
2123   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2124   DALI_TEST_CHECK(lastSyncObj != NULL);
2125   sync.SetObjectSynced(lastSyncObj, true);
2126
2127   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2128   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2129
2130   END_TEST;
2131 }
2132
2133 int UtcDaliRenderTaskOnce04(void)
2134 {
2135   TestApplication application;
2136   tet_infoline(
2137     "Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n"
2138     "Switch from render always after ready to render once\n");
2139
2140   // SETUP AN OFFSCREEN RENDER TASK
2141   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2142   TestGlSyncAbstraction& sync      = application.GetGlSyncAbstraction();
2143   TraceCallStack&        drawTrace = application.GetGlAbstraction().GetDrawTrace();
2144   drawTrace.Enable(true);
2145
2146   Actor rootActor = Actor::New();
2147   application.GetScene().Add(rootActor);
2148
2149   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2150   application.GetScene().Add(offscreenCameraActor);
2151
2152   Shader     shader     = CreateShader();
2153   Texture    image      = CreateTexture();
2154   TextureSet textureSet = CreateTextureSet(image);
2155
2156   Geometry geometry = CreateQuadGeometry();
2157   Renderer renderer = Renderer::New(geometry, shader);
2158   renderer.SetTextures(textureSet);
2159   Actor secondRootActor = Actor::New();
2160   secondRootActor.AddRenderer(renderer);
2161   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2162   application.GetScene().Add(secondRootActor);
2163
2164   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2165   bool               finished = false;
2166   RenderTaskFinished renderTaskFinished(finished);
2167   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2168   application.SendNotification();
2169
2170   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2171
2172   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2173   application.SendNotification();
2174
2175   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2176
2177   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2178   DALI_TEST_CHECK(lastSyncObj != NULL);
2179   sync.SetObjectSynced(lastSyncObj, true);
2180
2181   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2182   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2183
2184   END_TEST;
2185 }
2186
2187 int UtcDaliRenderTaskOnceNoSync01(void)
2188 {
2189   TestApplication application;
2190
2191   tet_infoline("Testing RenderTask Render Once, \nPRE: Resources ready\nPOST: Finished signal sent once only");
2192
2193   // SETUP AN OFFSCREEN RENDER TASK
2194   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2195   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2196   drawTrace.Enable(true);
2197
2198   Actor rootActor = Actor::New();
2199   application.GetScene().Add(rootActor);
2200
2201   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2202   application.GetScene().Add(offscreenCameraActor);
2203   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2204   application.GetScene().Add(secondRootActor);
2205
2206   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2207   bool               finished = false;
2208   RenderTaskFinished renderTaskFinished(finished);
2209   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2210   application.SendNotification();
2211
2212   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2213   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2214   END_TEST;
2215 }
2216
2217 int UtcDaliRenderTaskOnceNoSync02(void)
2218 {
2219   TestApplication application;
2220
2221   tet_infoline(
2222     "Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loaded image.\n"
2223     "PRE: Resources ready\nPOST: Finished signal sent once only");
2224   // SETUP AN OFFSCREEN RENDER TASK
2225   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2226   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2227   drawTrace.Enable(true);
2228
2229   Actor rootActor = Actor::New();
2230   application.GetScene().Add(rootActor);
2231
2232   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2233   application.GetScene().Add(offscreenCameraActor);
2234
2235   Shader     shader     = CreateShader();
2236   Texture    image      = CreateTexture();
2237   TextureSet textureSet = CreateTextureSet(image);
2238
2239   Geometry geometry = CreateQuadGeometry();
2240   Renderer renderer = Renderer::New(geometry, shader);
2241   renderer.SetTextures(textureSet);
2242   Actor secondRootActor = Actor::New();
2243   secondRootActor.AddRenderer(renderer);
2244   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2245   application.GetScene().Add(secondRootActor);
2246
2247   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2248   bool               finished = false;
2249   RenderTaskFinished renderTaskFinished(finished);
2250   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2251   application.SendNotification();
2252
2253   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2254   application.GetPlatform().ClearReadyResources();
2255   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2256
2257   END_TEST;
2258 }
2259
2260 int UtcDaliRenderTaskOnceNoSync03(void)
2261 {
2262   TestApplication application;
2263
2264   tet_infoline(
2265     "Testing RenderTask Render Once, using loaded image. Switch from render always after ready to render once\n"
2266     "PRE: Render task ready, Image loaded\n"
2267     "POST: Finished signal sent only once");
2268
2269   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2270   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2271   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2272   drawTrace.Enable(true);
2273
2274   Actor rootActor = Actor::New();
2275   application.GetScene().Add(rootActor);
2276
2277   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2278   application.GetScene().Add(offscreenCameraActor);
2279   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2280   application.GetScene().Add(secondRootActor);
2281
2282   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2283   bool               finished = false;
2284   RenderTaskFinished renderTaskFinished(finished);
2285   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2286   application.SendNotification();
2287
2288   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2289
2290   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2291   application.SendNotification(); //         Input,    Expected  Input,    Expected
2292   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2293   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2294   END_TEST;
2295 }
2296
2297 int UtcDaliRenderTaskOnceNoSync04(void)
2298 {
2299   TestApplication application;
2300
2301   tet_infoline(
2302     "Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2303     "Switch from render always after ready to render once\n"
2304     "PRE: Render task ready, Image not loaded\n"
2305     "POST: Finished signal sent only once");
2306
2307   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2308   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2309   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2310   drawTrace.Enable(true);
2311
2312   Actor rootActor = Actor::New();
2313   application.GetScene().Add(rootActor);
2314
2315   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2316   application.GetScene().Add(offscreenCameraActor);
2317
2318   Shader     shader     = CreateShader();
2319   Texture    image      = CreateTexture();
2320   TextureSet textureSet = CreateTextureSet(image);
2321
2322   Geometry geometry = CreateQuadGeometry();
2323   Renderer renderer = Renderer::New(geometry, shader);
2324   renderer.SetTextures(textureSet);
2325   Actor secondRootActor = Actor::New();
2326   secondRootActor.AddRenderer(renderer);
2327   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2328   application.GetScene().Add(secondRootActor);
2329
2330   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2331   bool               finished = false;
2332   RenderTaskFinished renderTaskFinished(finished);
2333   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2334   application.SendNotification();
2335
2336   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2337   TestGlSyncAbstraction&                      sync        = application.GetGlSyncAbstraction();
2338   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2339   DALI_TEST_CHECK(lastSyncObj == NULL);
2340
2341   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2342   application.SendNotification(); //         Input,    Expected  Input,    Expected
2343   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2344   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2345
2346   lastSyncObj = sync.GetLastSyncObject();
2347   DALI_TEST_CHECK(lastSyncObj == NULL);
2348
2349   END_TEST;
2350 }
2351
2352 int UtcDaliRenderTaskOnceNoSync05(void)
2353 {
2354   TestApplication application;
2355
2356   tet_infoline(
2357     "Testing RenderTask Render Once\n"
2358     "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
2359     "PRE: resources failed to load\n"
2360     "POST: No finished signal sent.");
2361
2362   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2363   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2364   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2365   drawTrace.Enable(true);
2366
2367   Actor rootActor = Actor::New();
2368   application.GetScene().Add(rootActor);
2369
2370   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2371   application.GetScene().Add(offscreenCameraActor);
2372   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2373   application.GetScene().Add(secondRootActor);
2374
2375   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2376   bool               finished = false;
2377   RenderTaskFinished renderTaskFinished(finished);
2378   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2379   application.SendNotification();
2380
2381   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
2382   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2383
2384   // CHANGE TO RENDER ONCE,
2385   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2386   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2387
2388   END_TEST;
2389 }
2390
2391 int UtcDaliRenderTaskOnceChain01(void)
2392 {
2393   TestApplication application;
2394
2395   tet_infoline(
2396     "Testing RenderTask Render Once Chained render tasks\n"
2397     "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
2398     "PRE: resources ready\n"
2399     "POST: 2 finished signals sent.");
2400
2401   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2402   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2403   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2404   drawTrace.Enable(true);
2405
2406   Actor defaultRootActor = Actor::New(); // Root for default RT
2407   application.GetScene().Add(defaultRootActor);
2408
2409   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2410   application.GetScene().Add(offscreenCameraActor);
2411   Actor firstRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2412   application.GetScene().Add(firstRootActor);
2413
2414   // first render task
2415   RenderTask         firstTask     = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
2416   bool               firstFinished = false;
2417   RenderTaskFinished renderTask1Finished(firstFinished);
2418   firstTask.FinishedSignal().Connect(&application, renderTask1Finished);
2419
2420   // Second render task
2421   FrameBuffer fbo             = firstTask.GetFrameBuffer();
2422   Actor       secondRootActor = CreateRenderableActor(fbo.GetColorTexture());
2423   application.GetScene().Add(secondRootActor);
2424   RenderTask         secondTask     = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2425   bool               secondFinished = false;
2426   RenderTaskFinished renderTask2Finished(secondFinished);
2427   secondTask.FinishedSignal().Connect(&application, renderTask2Finished);
2428
2429   application.SendNotification();
2430
2431   //Both render tasks are executed.
2432   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, firstFinished, false, true, __LINE__));
2433   DALI_TEST_CHECK(firstFinished == false);
2434   DALI_TEST_CHECK(secondFinished == false);
2435
2436   //Nothing else to render and both render task should have finished now
2437   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, firstFinished, true, false, __LINE__));
2438   DALI_TEST_CHECK(firstFinished == true);
2439   DALI_TEST_CHECK(secondFinished == true);
2440
2441   END_TEST;
2442 }
2443
2444 int UtcDaliRenderTaskProperties(void)
2445 {
2446   TestApplication application;
2447
2448   RenderTask task = application.GetScene().GetRenderTaskList().CreateTask();
2449
2450   Property::IndexContainer indices;
2451   task.GetPropertyIndices(indices);
2452   DALI_TEST_CHECK(indices.Size());
2453   DALI_TEST_EQUALS(indices.Size(), task.GetPropertyCount(), TEST_LOCATION);
2454   END_TEST;
2455 }
2456
2457 int UtcDaliRenderTaskFinishInvisibleSourceActor(void)
2458 {
2459   TestApplication application;
2460
2461   tet_infoline("Testing RenderTask::FinishInvisibleSourceActor()");
2462
2463   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2464   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2465
2466   CameraActor offscreenCameraActor = CameraActor::New();
2467
2468   application.GetScene().Add(offscreenCameraActor);
2469
2470   Texture image     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 10, 10);
2471   Actor   rootActor = CreateRenderableActor(image);
2472   rootActor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
2473   rootActor.SetProperty(Actor::Property::VISIBLE, false);
2474   application.GetScene().Add(rootActor);
2475
2476   RenderTaskList          taskList           = application.GetScene().GetRenderTaskList();
2477   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
2478   Texture                 frameBufferTexture = Texture::New(*testNativeImagePtr);
2479   FrameBuffer             frameBuffer        = FrameBuffer::New(frameBufferTexture.GetWidth(), frameBufferTexture.GetHeight());
2480   frameBuffer.AttachColorTexture(frameBufferTexture);
2481
2482   // Flush all outstanding messages
2483   application.SendNotification();
2484   application.Render();
2485
2486   RenderTask newTask = taskList.CreateTask();
2487   newTask.SetCameraActor(offscreenCameraActor);
2488   newTask.SetSourceActor(rootActor);
2489   newTask.SetInputEnabled(false);
2490   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
2491   newTask.SetClearEnabled(true);
2492   newTask.SetExclusive(true);
2493   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2494   newTask.SetFrameBuffer(frameBuffer);
2495   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, true);
2496
2497   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
2498
2499   bool               finished = false;
2500   RenderTaskFinished renderTaskFinished(finished);
2501   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2502
2503   // Flush the queue and render.
2504   application.SendNotification();
2505
2506   // 1 render to process render task, then wait for sync before finished msg is sent
2507   // from update to the event thread.
2508
2509   application.Render();
2510   application.SendNotification();
2511   DALI_TEST_CHECK(!finished);
2512
2513   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2514   DALI_TEST_CHECK(lastSyncObj != NULL);
2515
2516   application.Render();
2517   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
2518   application.SendNotification();
2519   DALI_TEST_CHECK(!finished);
2520
2521   application.Render();
2522   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
2523   application.SendNotification();
2524   DALI_TEST_CHECK(!finished);
2525
2526   sync.SetObjectSynced(lastSyncObj, true);
2527
2528   application.Render();
2529   application.SendNotification();
2530   DALI_TEST_CHECK(!finished);
2531
2532   application.Render();
2533   application.SendNotification();
2534   DALI_TEST_CHECK(finished);
2535   finished = false;
2536
2537   application.Render(); // Double check no more finished signal
2538   application.SendNotification();
2539   DALI_TEST_CHECK(!finished);
2540
2541   END_TEST;
2542 }
2543
2544 int UtcDaliRenderTaskFinishMissingImage(void)
2545 {
2546   TestApplication application;
2547
2548   // Previously we had bugs where not having a resource ID would cause render-tasks to wait forever
2549   tet_infoline("Testing RenderTask::SignalFinished() when an Actor has no Image set");
2550
2551   Integration::Scene stage = application.GetScene();
2552
2553   Texture image     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 10, 10);
2554   Actor   rootActor = CreateRenderableActor(image);
2555   rootActor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
2556   stage.Add(rootActor);
2557
2558   Actor actorWithMissingImage = CreateRenderableActor(Texture());
2559   actorWithMissingImage.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
2560   stage.Add(actorWithMissingImage);
2561
2562   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2563   RenderTask     newTask  = taskList.CreateTask();
2564   newTask.SetInputEnabled(false);
2565   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
2566   newTask.SetClearEnabled(true);
2567   newTask.SetExclusive(true);
2568   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2569
2570   bool               finished = false;
2571   RenderTaskFinished renderTaskFinished(finished);
2572   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2573
2574   // 1 render to process render task, then 1 before finished msg is sent from update to the event thread.
2575   application.SendNotification();
2576   application.Render();
2577   application.Render();
2578
2579   application.SendNotification();
2580   DALI_TEST_CHECK(finished);
2581
2582   END_TEST;
2583 }
2584
2585 int UtcDaliRenderTaskWorldToViewport(void)
2586 {
2587   TestApplication application(400u, 400u); // square surface
2588
2589   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2590
2591   Actor actor = Actor::New();
2592   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2593   actor.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 0.0));
2594
2595   actor.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5, 0.5, 0.5));
2596   actor.SetProperty(Actor::Property::ANCHOR_POINT, Vector3(0.5, 0.5, 0.5));
2597
2598   application.GetScene().Add(actor);
2599
2600   application.SendNotification();
2601   application.Render();
2602   application.SendNotification();
2603
2604   RenderTask task = taskList.GetTask(0u);
2605
2606   CameraActor camera = task.GetCameraActor();
2607
2608   Vector2 screenSize = task.GetCurrentViewportSize();
2609
2610   float screenX = 0.0;
2611   float screenY = 0.0;
2612
2613   bool ok = task.WorldToViewport(actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION), screenX, screenY);
2614   DALI_TEST_CHECK(ok == true);
2615
2616   DALI_TEST_EQUALS(screenX, screenSize.x / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2617   DALI_TEST_EQUALS(screenY, screenSize.y / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2618
2619   Actor actor2     = Actor::New();
2620   float actor2Size = 100.f;
2621   actor2.SetProperty(Actor::Property::SIZE, Vector2(actor2Size, actor2Size));
2622   actor2.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 0.0));
2623   actor2.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5, 0.5, 0.0));
2624   actor2.SetProperty(Actor::Property::ANCHOR_POINT, Vector3(0.5, 0.5, 0.0));
2625   application.GetScene().Add(actor2);
2626   actor2.Add(actor);
2627   actor.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0, 0, 0));
2628
2629   application.SendNotification();
2630   application.Render();
2631   application.SendNotification();
2632
2633   ok = task.WorldToViewport(actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION), screenX, screenY);
2634   DALI_TEST_CHECK(ok == true);
2635
2636   DALI_TEST_EQUALS(screenX, screenSize.x / 2 - actor2Size / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2637   DALI_TEST_EQUALS(screenY, screenSize.y / 2 - actor2Size / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2638
2639   END_TEST;
2640 }
2641
2642 int UtcDaliRenderTaskViewportToLocal(void)
2643 {
2644   TestApplication application;
2645   Actor           actor = Actor::New();
2646   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2647   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2648   actor.SetProperty(Actor::Property::POSITION, Vector2(10.0f, 10.0f));
2649   application.GetScene().Add(actor);
2650
2651   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2652   RenderTask     task     = taskList.GetTask(0u);
2653
2654   // flush the queue and render once
2655   application.SendNotification();
2656   application.Render();
2657   application.SendNotification();
2658   application.Render();
2659
2660   float localX;
2661   float localY;
2662
2663   float rtLocalX;
2664   float rtLocalY;
2665
2666   float screenX = 50.0f;
2667   float screenY = 50.0f;
2668
2669   DALI_TEST_CHECK(actor.ScreenToLocal(localX, localY, screenX, screenY));
2670
2671   DALI_TEST_CHECK(task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY));
2672
2673   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
2674   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
2675
2676   END_TEST;
2677 }
2678
2679 int UtcDaliRenderTaskOffscreenViewportToLocal(void)
2680 {
2681   TestApplication application;
2682   Actor           actor = Actor::New();
2683   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2684   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2685   actor.SetProperty(Actor::Property::POSITION, Vector2(10.0f, 10.0f));
2686   application.GetScene().Add(actor);
2687
2688   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2689   RenderTask     task     = taskList.CreateTask();
2690
2691   FrameBuffer newFrameBuffer = FrameBuffer::New(10, 10);
2692   task.SetFrameBuffer(newFrameBuffer);
2693   task.SetSourceActor(actor);
2694   task.SetScreenToFrameBufferMappingActor(actor);
2695
2696   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2697   application.GetScene().Add(offscreenCameraActor);
2698   task.SetCameraActor(offscreenCameraActor);
2699
2700   // flush the queue and render once
2701   application.SendNotification();
2702   application.Render();
2703   application.SendNotification();
2704   application.Render();
2705
2706   float localX;
2707   float localY;
2708
2709   float rtLocalX;
2710   float rtLocalY;
2711
2712   float screenX = 50.0f;
2713   float screenY = 50.0f;
2714
2715   DALI_TEST_CHECK(actor.ScreenToLocal(localX, localY, screenX, screenY));
2716
2717   DALI_TEST_CHECK(task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY));
2718
2719   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
2720   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
2721
2722   END_TEST;
2723 }
2724
2725 int UtcDaliRenderTaskRequiresSync(void)
2726 {
2727   TestApplication application;
2728   RenderTaskList  taskList = application.GetScene().GetRenderTaskList();
2729
2730   RenderTask newTask = taskList.CreateTask();
2731   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, false);
2732
2733   DALI_TEST_EQUALS(newTask.GetProperty<bool>(RenderTask::Property::REQUIRES_SYNC), false, TEST_LOCATION);
2734   DALI_TEST_EQUALS(newTask.GetCurrentProperty<bool>(RenderTask::Property::REQUIRES_SYNC), false, TEST_LOCATION);
2735
2736   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, true);
2737
2738   DALI_TEST_EQUALS(newTask.GetProperty<bool>(RenderTask::Property::REQUIRES_SYNC), true, TEST_LOCATION);
2739   DALI_TEST_EQUALS(newTask.GetCurrentProperty<bool>(RenderTask::Property::REQUIRES_SYNC), true, TEST_LOCATION);
2740
2741   END_TEST;
2742 }
2743
2744 int UtcDaliRenderTaskSetClearEnabled(void)
2745 {
2746   TestApplication application;
2747
2748   tet_infoline("UtcDaliRenderTaskSetClearEnabled");
2749
2750   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2751   TestGlAbstraction& gl = application.GetGlAbstraction();
2752
2753   Actor renderableActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2754   application.GetScene().Add(renderableActor);
2755
2756   Actor rootActor = Actor::New();
2757   application.GetScene().Add(rootActor);
2758
2759   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2760   application.GetScene().Add(offscreenCameraActor);
2761
2762   Actor sourceActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2763   application.GetScene().Add(sourceActor);
2764
2765   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, sourceActor, RenderTask::REFRESH_ALWAYS, false);
2766
2767   DALI_TEST_EQUALS(gl.GetClearCountCalled(), 0, TEST_LOCATION);
2768
2769   application.SendNotification();
2770   application.Render();
2771
2772   // glClear should be called twice - default task and the new task.
2773   DALI_TEST_EQUALS(gl.GetClearCountCalled(), 2, TEST_LOCATION);
2774
2775   newTask.SetClearEnabled(false);
2776
2777   application.SendNotification();
2778   application.Render();
2779
2780   // The count should increase by 1 - default task only.
2781   DALI_TEST_EQUALS(gl.GetClearCountCalled(), 3, TEST_LOCATION);
2782
2783   END_TEST;
2784 }
2785
2786 int UtcDaliRenderTaskMoveConstrctor(void)
2787 {
2788   TestApplication application;
2789
2790   Vector4 testColor(1.0f, 2.0f, 3.0f, 4.0f);
2791
2792   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2793   RenderTask     task     = taskList.GetTask(0u);
2794   DALI_TEST_CHECK(task);
2795   DALI_TEST_EQUALS(2, task.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2796   DALI_TEST_CHECK(task.GetClearColor() != testColor);
2797
2798   task.SetClearColor(testColor);
2799
2800   // Wait a frame.
2801   Wait(application);
2802
2803   DALI_TEST_EQUALS(task.GetClearColor(), testColor, TEST_LOCATION);
2804
2805   RenderTask move = std::move(task);
2806   DALI_TEST_CHECK(move);
2807   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2808   DALI_TEST_EQUALS(move.GetClearColor(), testColor, TEST_LOCATION);
2809   DALI_TEST_CHECK(!task);
2810
2811   END_TEST;
2812 }
2813
2814 int UtcDaliRenderTaskMoveAssignment(void)
2815 {
2816   TestApplication application;
2817
2818   Vector4 testColor(1.0f, 2.0f, 3.0f, 4.0f);
2819
2820   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2821   RenderTask     task     = taskList.GetTask(0u);
2822   DALI_TEST_CHECK(task);
2823   DALI_TEST_EQUALS(2, task.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2824   DALI_TEST_CHECK(task.GetClearColor() != testColor);
2825
2826   task.SetClearColor(testColor);
2827
2828   // Wait a frame.
2829   Wait(application);
2830
2831   DALI_TEST_EQUALS(task.GetClearColor(), testColor, TEST_LOCATION);
2832
2833   RenderTask move;
2834   move = std::move(task);
2835   DALI_TEST_CHECK(move);
2836   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2837   DALI_TEST_EQUALS(move.GetClearColor(), testColor, TEST_LOCATION);
2838   DALI_TEST_CHECK(!task);
2839
2840   END_TEST;
2841 }
2842
2843 int UtcDaliRenderTaskSetCullModeNegative(void)
2844 {
2845   TestApplication  application;
2846   Dali::RenderTask instance;
2847   try
2848   {
2849     bool arg1(false);
2850     instance.SetCullMode(arg1);
2851     DALI_TEST_CHECK(false); // Should not get here
2852   }
2853   catch(...)
2854   {
2855     DALI_TEST_CHECK(true); // We expect an assert
2856   }
2857   END_TEST;
2858 }
2859
2860 int UtcDaliRenderTaskSetViewportNegative(void)
2861 {
2862   TestApplication  application;
2863   Dali::RenderTask instance;
2864   try
2865   {
2866     Dali::Rect<int> arg1;
2867     instance.SetViewport(arg1);
2868     DALI_TEST_CHECK(false); // Should not get here
2869   }
2870   catch(...)
2871   {
2872     DALI_TEST_CHECK(true); // We expect an assert
2873   }
2874   END_TEST;
2875 }
2876
2877 int UtcDaliRenderTaskSetExclusiveNegative(void)
2878 {
2879   TestApplication  application;
2880   Dali::RenderTask instance;
2881   try
2882   {
2883     bool arg1(false);
2884     instance.SetExclusive(arg1);
2885     DALI_TEST_CHECK(false); // Should not get here
2886   }
2887   catch(...)
2888   {
2889     DALI_TEST_CHECK(true); // We expect an assert
2890   }
2891   END_TEST;
2892 }
2893
2894 int UtcDaliRenderTaskSetClearColorNegative(void)
2895 {
2896   TestApplication  application;
2897   Dali::RenderTask instance;
2898   try
2899   {
2900     Dali::Vector4 arg1;
2901     instance.SetClearColor(arg1);
2902     DALI_TEST_CHECK(false); // Should not get here
2903   }
2904   catch(...)
2905   {
2906     DALI_TEST_CHECK(true); // We expect an assert
2907   }
2908   END_TEST;
2909 }
2910
2911 int UtcDaliRenderTaskFinishedSignalNegative(void)
2912 {
2913   TestApplication  application;
2914   Dali::RenderTask instance;
2915   try
2916   {
2917     instance.FinishedSignal();
2918     DALI_TEST_CHECK(false); // Should not get here
2919   }
2920   catch(...)
2921   {
2922     DALI_TEST_CHECK(true); // We expect an assert
2923   }
2924   END_TEST;
2925 }
2926
2927 int UtcDaliRenderTaskSetCameraActorNegative(void)
2928 {
2929   TestApplication  application;
2930   Dali::RenderTask instance;
2931   try
2932   {
2933     Dali::CameraActor arg1;
2934     instance.SetCameraActor(arg1);
2935     DALI_TEST_CHECK(false); // Should not get here
2936   }
2937   catch(...)
2938   {
2939     DALI_TEST_CHECK(true); // We expect an assert
2940   }
2941   END_TEST;
2942 }
2943
2944 int UtcDaliRenderTaskSetFrameBufferNegative(void)
2945 {
2946   TestApplication  application;
2947   Dali::RenderTask instance;
2948   try
2949   {
2950     Dali::FrameBuffer arg1;
2951     instance.SetFrameBuffer(arg1);
2952     DALI_TEST_CHECK(false); // Should not get here
2953   }
2954   catch(...)
2955   {
2956     DALI_TEST_CHECK(true); // We expect an assert
2957   }
2958   END_TEST;
2959 }
2960
2961 int UtcDaliRenderTaskSetRefreshRateNegative(void)
2962 {
2963   TestApplication  application;
2964   Dali::RenderTask instance;
2965   try
2966   {
2967     unsigned int arg1(0u);
2968     instance.SetRefreshRate(arg1);
2969     DALI_TEST_CHECK(false); // Should not get here
2970   }
2971   catch(...)
2972   {
2973     DALI_TEST_CHECK(true); // We expect an assert
2974   }
2975   END_TEST;
2976 }
2977
2978 int UtcDaliRenderTaskSetSourceActorNegative(void)
2979 {
2980   TestApplication  application;
2981   Dali::RenderTask instance;
2982   try
2983   {
2984     Dali::Actor arg1;
2985     instance.SetSourceActor(arg1);
2986     DALI_TEST_CHECK(false); // Should not get here
2987   }
2988   catch(...)
2989   {
2990     DALI_TEST_CHECK(true); // We expect an assert
2991   }
2992   END_TEST;
2993 }
2994
2995 int UtcDaliRenderTaskSetClearEnabledNegative(void)
2996 {
2997   TestApplication  application;
2998   Dali::RenderTask instance;
2999   try
3000   {
3001     bool arg1(false);
3002     instance.SetClearEnabled(arg1);
3003     DALI_TEST_CHECK(false); // Should not get here
3004   }
3005   catch(...)
3006   {
3007     DALI_TEST_CHECK(true); // We expect an assert
3008   }
3009   END_TEST;
3010 }
3011
3012 int UtcDaliRenderTaskSetInputEnabledNegative(void)
3013 {
3014   TestApplication  application;
3015   Dali::RenderTask instance;
3016   try
3017   {
3018     bool arg1(false);
3019     instance.SetInputEnabled(arg1);
3020     DALI_TEST_CHECK(false); // Should not get here
3021   }
3022   catch(...)
3023   {
3024     DALI_TEST_CHECK(true); // We expect an assert
3025   }
3026   END_TEST;
3027 }
3028
3029 int UtcDaliRenderTaskSetViewportSizeNegative(void)
3030 {
3031   TestApplication  application;
3032   Dali::RenderTask instance;
3033   try
3034   {
3035     Dali::Vector2 arg1;
3036     instance.SetViewportSize(arg1);
3037     DALI_TEST_CHECK(false); // Should not get here
3038   }
3039   catch(...)
3040   {
3041     DALI_TEST_CHECK(true); // We expect an assert
3042   }
3043   END_TEST;
3044 }
3045
3046 int UtcDaliRenderTaskSetViewportPositionNegative(void)
3047 {
3048   TestApplication  application;
3049   Dali::RenderTask instance;
3050   try
3051   {
3052     Dali::Vector2 arg1;
3053     instance.SetViewportPosition(arg1);
3054     DALI_TEST_CHECK(false); // Should not get here
3055   }
3056   catch(...)
3057   {
3058     DALI_TEST_CHECK(true); // We expect an assert
3059   }
3060   END_TEST;
3061 }
3062
3063 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionNegative(void)
3064 {
3065   TestApplication  application;
3066   Dali::RenderTask instance;
3067   try
3068   {
3069     RenderTask::ScreenToFrameBufferFunction arg1(nullptr);
3070     instance.SetScreenToFrameBufferFunction(arg1);
3071     DALI_TEST_CHECK(false); // Should not get here
3072   }
3073   catch(...)
3074   {
3075     DALI_TEST_CHECK(true); // We expect an assert
3076   }
3077   END_TEST;
3078 }
3079
3080 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActorNegative(void)
3081 {
3082   TestApplication  application;
3083   Dali::RenderTask instance;
3084   try
3085   {
3086     Dali::Actor arg1;
3087     instance.SetScreenToFrameBufferMappingActor(arg1);
3088     DALI_TEST_CHECK(false); // Should not get here
3089   }
3090   catch(...)
3091   {
3092     DALI_TEST_CHECK(true); // We expect an assert
3093   }
3094   END_TEST;
3095 }
3096
3097 int UtcDaliRenderTaskGetCullModeNegative(void)
3098 {
3099   TestApplication  application;
3100   Dali::RenderTask instance;
3101   try
3102   {
3103     instance.GetCullMode();
3104     DALI_TEST_CHECK(false); // Should not get here
3105   }
3106   catch(...)
3107   {
3108     DALI_TEST_CHECK(true); // We expect an assert
3109   }
3110   END_TEST;
3111 }
3112
3113 int UtcDaliRenderTaskGetViewportNegative(void)
3114 {
3115   TestApplication  application;
3116   Dali::RenderTask instance;
3117   try
3118   {
3119     instance.GetViewport();
3120     DALI_TEST_CHECK(false); // Should not get here
3121   }
3122   catch(...)
3123   {
3124     DALI_TEST_CHECK(true); // We expect an assert
3125   }
3126   END_TEST;
3127 }
3128
3129 int UtcDaliRenderTaskIsExclusiveNegative(void)
3130 {
3131   TestApplication  application;
3132   Dali::RenderTask instance;
3133   try
3134   {
3135     instance.IsExclusive();
3136     DALI_TEST_CHECK(false); // Should not get here
3137   }
3138   catch(...)
3139   {
3140     DALI_TEST_CHECK(true); // We expect an assert
3141   }
3142   END_TEST;
3143 }
3144
3145 int UtcDaliRenderTaskGetClearColorNegative(void)
3146 {
3147   TestApplication  application;
3148   Dali::RenderTask instance;
3149   try
3150   {
3151     instance.GetClearColor();
3152     DALI_TEST_CHECK(false); // Should not get here
3153   }
3154   catch(...)
3155   {
3156     DALI_TEST_CHECK(true); // We expect an assert
3157   }
3158   END_TEST;
3159 }
3160
3161 int UtcDaliRenderTaskGetCameraActorNegative(void)
3162 {
3163   TestApplication  application;
3164   Dali::RenderTask instance;
3165   try
3166   {
3167     instance.GetCameraActor();
3168     DALI_TEST_CHECK(false); // Should not get here
3169   }
3170   catch(...)
3171   {
3172     DALI_TEST_CHECK(true); // We expect an assert
3173   }
3174   END_TEST;
3175 }
3176
3177 int UtcDaliRenderTaskGetFrameBufferNegative(void)
3178 {
3179   TestApplication  application;
3180   Dali::RenderTask instance;
3181   try
3182   {
3183     instance.GetFrameBuffer();
3184     DALI_TEST_CHECK(false); // Should not get here
3185   }
3186   catch(...)
3187   {
3188     DALI_TEST_CHECK(true); // We expect an assert
3189   }
3190   END_TEST;
3191 }
3192
3193 int UtcDaliRenderTaskGetRefreshRateNegative(void)
3194 {
3195   TestApplication  application;
3196   Dali::RenderTask instance;
3197   try
3198   {
3199     instance.GetRefreshRate();
3200     DALI_TEST_CHECK(false); // Should not get here
3201   }
3202   catch(...)
3203   {
3204     DALI_TEST_CHECK(true); // We expect an assert
3205   }
3206   END_TEST;
3207 }
3208
3209 int UtcDaliRenderTaskGetSourceActorNegative(void)
3210 {
3211   TestApplication  application;
3212   Dali::RenderTask instance;
3213   try
3214   {
3215     instance.GetSourceActor();
3216     DALI_TEST_CHECK(false); // Should not get here
3217   }
3218   catch(...)
3219   {
3220     DALI_TEST_CHECK(true); // We expect an assert
3221   }
3222   END_TEST;
3223 }
3224
3225 int UtcDaliRenderTaskGetClearEnabledNegative(void)
3226 {
3227   TestApplication  application;
3228   Dali::RenderTask instance;
3229   try
3230   {
3231     instance.GetClearEnabled();
3232     DALI_TEST_CHECK(false); // Should not get here
3233   }
3234   catch(...)
3235   {
3236     DALI_TEST_CHECK(true); // We expect an assert
3237   }
3238   END_TEST;
3239 }
3240
3241 int UtcDaliRenderTaskGetInputEnabledNegative(void)
3242 {
3243   TestApplication  application;
3244   Dali::RenderTask instance;
3245   try
3246   {
3247     instance.GetInputEnabled();
3248     DALI_TEST_CHECK(false); // Should not get here
3249   }
3250   catch(...)
3251   {
3252     DALI_TEST_CHECK(true); // We expect an assert
3253   }
3254   END_TEST;
3255 }
3256
3257 int UtcDaliRenderTaskViewportToLocalNegative(void)
3258 {
3259   TestApplication  application;
3260   Dali::RenderTask instance;
3261   try
3262   {
3263     Dali::Actor arg1(Actor::New());
3264     float       arg2(0.0f);
3265     float       arg3(0.0f);
3266     float       arg4(0.0f);
3267     float       arg5(0.0f);
3268     instance.ViewportToLocal(arg1, arg2, arg3, arg4, arg5);
3269     DALI_TEST_CHECK(false); // Should not get here
3270   }
3271   catch(...)
3272   {
3273     DALI_TEST_CHECK(true); // We expect an assert
3274   }
3275   END_TEST;
3276 }
3277
3278 int UtcDaliRenderTaskWorldToViewportNegative(void)
3279 {
3280   TestApplication  application;
3281   Dali::RenderTask instance;
3282   try
3283   {
3284     Dali::Vector3 arg1;
3285     float         arg2(0.0f);
3286     float         arg3(0.0f);
3287     instance.WorldToViewport(arg1, arg2, arg3);
3288     DALI_TEST_CHECK(false); // Should not get here
3289   }
3290   catch(...)
3291   {
3292     DALI_TEST_CHECK(true); // We expect an assert
3293   }
3294   END_TEST;
3295 }
3296
3297 int UtcDaliRenderTaskGetCurrentViewportSizeNegative(void)
3298 {
3299   TestApplication  application;
3300   Dali::RenderTask instance;
3301   try
3302   {
3303     instance.GetCurrentViewportSize();
3304     DALI_TEST_CHECK(false); // Should not get here
3305   }
3306   catch(...)
3307   {
3308     DALI_TEST_CHECK(true); // We expect an assert
3309   }
3310   END_TEST;
3311 }
3312
3313 int UtcDaliRenderTaskGetCurrentViewportPositionNegative(void)
3314 {
3315   TestApplication  application;
3316   Dali::RenderTask instance;
3317   try
3318   {
3319     instance.GetCurrentViewportPosition();
3320     DALI_TEST_CHECK(false); // Should not get here
3321   }
3322   catch(...)
3323   {
3324     DALI_TEST_CHECK(true); // We expect an assert
3325   }
3326   END_TEST;
3327 }
3328
3329 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionNegative(void)
3330 {
3331   TestApplication  application;
3332   Dali::RenderTask instance;
3333   try
3334   {
3335     instance.GetScreenToFrameBufferFunction();
3336     DALI_TEST_CHECK(false); // Should not get here
3337   }
3338   catch(...)
3339   {
3340     DALI_TEST_CHECK(true); // We expect an assert
3341   }
3342   END_TEST;
3343 }
3344
3345 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorNegative(void)
3346 {
3347   TestApplication  application;
3348   Dali::RenderTask instance;
3349   try
3350   {
3351     instance.GetScreenToFrameBufferMappingActor();
3352     DALI_TEST_CHECK(false); // Should not get here
3353   }
3354   catch(...)
3355   {
3356     DALI_TEST_CHECK(true); // We expect an assert
3357   }
3358   END_TEST;
3359 }