[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RenderTask.cpp
1 /*
2  * Copyright (c) 2023 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-actor-utils.h>
25 #include <test-native-image.h>
26
27 #include <iostream>
28
29 #define BOOLSTR(x) ((x) ? "T" : "F")
30
31 //& set: DaliRenderTask
32
33 using namespace Dali;
34
35 void utc_dali_render_task_startup(void)
36 {
37   test_return_value = TET_UNDEF;
38 }
39
40 void utc_dali_render_task_cleanup(void)
41 {
42   test_return_value = TET_PASS;
43 }
44
45 /**
46  * APIs:
47  *
48  * Constructor, Destructor, DownCast, New, copy constructor, assignment operator
49  *
50  * SetSourceActor                      2+ve, 1-ve
51  * GetSourceActor                      1+ve, 1-ve
52  * SetExclusive                        2+ve, 0-ve
53  * IsExclusive                         2+ve, 0-ve
54  * SetInputEnabled                     1+ve, 0-ve
55  * GetInputEnabled                     1+ve, 0-ve
56  * SetCameraActor                      1+ve, 1-ve
57  * GetCameraActor                      1+ve, 1-ve
58  * SetTargetFrameBuffer                1+ve, 1-ve
59  * GetTargetFrameBuffer                1+ve, 1-ve
60  * SetScreenToFrameBufferFunction      1+ve, 1-ve
61  * GetScreenToFrameBufferFunction      1+ve, 1-ve
62  * SetScreenToFrameBufferMappingActor  1+ve, 1-ve
63  * GetScreenToFrameBufferMappingActor  1+ve, 1-ve
64  * SetViewportPosition                 1+ve
65  * GetCurrentViewportPosition          1+ve
66  * SetViewportSize                     1+ve
67  * GetCurrentViewportSize              1+ve
68  * SetViewport                         2+ve, 1-ve
69  * GetViewport                         2+ve, 1-ve
70  * SetClearColor                       1+ve, 1-ve
71  * GetClearColor                       1+ve, 1-ve
72  * SetClearEnabled                     1+ve, 1-ve
73  * GetClearEnabled                     1+ve, 1-ve
74  * SetCullMode
75  * GetCullMode
76  * SetRefreshRate                      Many
77  * GetRefreshRate                      1+ve
78  * FinishedSignal                      1+ve
79  */
80
81 namespace // unnamed namespace
82 {
83 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
84
85 // Test shader codes
86 const std::string_view SHADER_COLOR_TEST_SHADER_VERT1{
87   R"(INPUT mediump vec2 aPosition;
88 uniform highp mat4 uMvpMatrix;
89 uniform highp vec3 uSize;
90
91 //Visual size and offset
92 uniform mediump vec2 offset;
93 uniform highp vec2 size;
94 uniform mediump vec4 offsetSizeMode;
95 uniform mediump vec2 origin;
96 uniform mediump vec2 anchorPoint;
97 uniform mediump vec2 extraSize;
98
99 vec4 ComputeVertexPosition()
100 {
101   vec2 visualSize = mix(size * uSize.xy, size, offsetSizeMode.zw ) + extraSize;
102   vec2 visualOffset = mix(offset * uSize.xy, offset, offsetSizeMode.xy);
103   mediump vec2 vPosition = aPosition * visualSize;
104   return vec4(vPosition + anchorPoint * visualSize + visualOffset + origin * uSize.xy, 0.0, 1.0);
105 }
106
107 void main()
108 {
109   gl_Position = uMvpMatrix * ComputeVertexPosition();
110 }
111 )"};
112
113 // Test shader codes
114 const std::string_view SHADER_COLOR_TEST_SHADER_VERT2{
115   R"(INPUT mediump vec2 aPosition;
116 uniform highp mat4 uMvpMatrix;
117 uniform highp vec3 uSize;
118
119 //Visual size and offset
120 uniform mediump vec2 offset;
121 uniform highp vec2 size;
122 uniform mediump vec4 offsetSizeMode;
123 uniform mediump vec2 origin;
124 uniform mediump vec2 anchorPoint;
125 uniform mediump vec2 extraSize;
126
127 vec4 ComputeVertexPosition2()
128 {
129   vec2 visualSize = mix(size * uSize.xy, size, offsetSizeMode.zw ) + extraSize;
130   vec2 visualOffset = mix(offset * uSize.xy, offset, offsetSizeMode.xy);
131   mediump vec2 vPosition = aPosition * visualSize;
132   return vec4(vPosition + anchorPoint * visualSize + visualOffset + origin * uSize.xy, 0.0, 1.0);
133 }
134
135 void main()
136 {
137   gl_Position = uMvpMatrix * ComputeVertexPosition2();
138 }
139 )"};
140
141 const std::string_view SHADER_COLOR_TEST_SHADER_FRAG{
142   R"(
143 void main()
144 {
145   OUT_COLOR = vec4(0.0, 0.0, 1.0, 1.0);
146 }
147 )"};
148
149 /*
150  * Simulate time passed by.
151  *
152  * @note this will always process at least 1 frame (1/60 sec)
153  *
154  * @param application Test application instance
155  * @param duration Time to pass in milliseconds.
156  * @return The actual time passed in milliseconds
157  */
158 int Wait(TestApplication& application, int duration = 0)
159 {
160   int time = 0;
161
162   for(int i = 0; i <= (duration / RENDER_FRAME_INTERVAL); i++)
163   {
164     application.SendNotification();
165     application.Render(RENDER_FRAME_INTERVAL);
166     time += RENDER_FRAME_INTERVAL;
167   }
168
169   return time;
170 }
171
172 struct RenderTaskFinished
173 {
174   RenderTaskFinished(bool& finished)
175   : finished(finished)
176   {
177   }
178
179   void operator()(RenderTask& renderTask)
180   {
181     finished = true;
182   }
183
184   bool& finished;
185 };
186
187 struct RenderTaskFinishedRemoveSource
188 {
189   RenderTaskFinishedRemoveSource(bool& finished)
190   : finished(finished),
191     finishedOnce(false)
192   {
193   }
194
195   void operator()(RenderTask& renderTask)
196   {
197     DALI_TEST_CHECK(finishedOnce == false);
198     finished       = true;
199     finishedOnce   = true;
200     Actor srcActor = renderTask.GetSourceActor();
201     UnparentAndReset(srcActor);
202   }
203
204   bool& finished;
205   bool  finishedOnce;
206 };
207
208 struct RenderTaskFinishedRenderAgain
209 {
210   RenderTaskFinishedRenderAgain(bool& finished)
211   : finished(finished),
212     finishedOnce(false)
213   {
214   }
215
216   void operator()(RenderTask& renderTask)
217   {
218     DALI_TEST_CHECK(finishedOnce == false);
219     finished     = true;
220     finishedOnce = true;
221     renderTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
222   }
223
224   bool& finished;
225   bool  finishedOnce;
226 };
227
228 bool TestScreenToFrameBufferFunction(Vector2& coordinates)
229 {
230   coordinates = coordinates + Vector2(1, 2);
231
232   return true;
233 }
234
235 Actor CreateRenderableActorSuccess(TestApplication& application, std::string filename)
236 {
237   Actor actor = CreateRenderableActor();
238   actor.SetProperty(Actor::Property::SIZE, Vector2(80.0f, 80.0f));
239   return actor;
240 }
241
242 Texture CreateTexture(void)
243 {
244   return Dali::CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 80, 80);
245 }
246
247 RenderTask CreateRenderTask(TestApplication& application,
248                             CameraActor      offscreenCamera,
249                             Actor            rootActor,       // Reset default render task to point at this actor
250                             Actor            secondRootActor, // Source actor
251                             unsigned int     refreshRate,
252                             bool             glSync,
253                             uint32_t         frameBufferWidth  = 10,
254                             uint32_t         frameBufferHeight = 10)
255 {
256   // Change main render task to use a different root
257   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
258   taskList.GetTask(0u).SetSourceActor(rootActor);
259
260   FrameBuffer frameBuffer = FrameBuffer::New(frameBufferWidth, frameBufferHeight);
261   if(glSync)
262   {
263     NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(frameBufferWidth, frameBufferHeight);
264     Texture                 texture            = Texture::New(*testNativeImagePtr);
265     frameBuffer.AttachColorTexture(texture);
266   }
267
268   // Don't draw output framebuffer // '
269
270   RenderTask newTask = taskList.CreateTask();
271   newTask.SetCameraActor(offscreenCamera);
272   newTask.SetSourceActor(secondRootActor);
273   newTask.SetInputEnabled(false);
274   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
275   newTask.SetClearEnabled(true);
276   newTask.SetExclusive(true);
277   newTask.SetRefreshRate(refreshRate);
278   newTask.SetFrameBuffer(frameBuffer);
279   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, glSync);
280   return newTask;
281 }
282
283 bool UpdateRender(TestApplication& application, TraceCallStack& callStack, bool testDrawn, bool& finishedSig, bool testFinished, bool testKeepUpdating, int lineNumber)
284 {
285   finishedSig = false;
286   callStack.Reset();
287
288   tet_printf("TestApplication::UpdateRender().\n");
289
290   application.Render(16);
291   application.SendNotification();
292
293   bool sigPassed = false;
294   if(testFinished)
295   {
296     sigPassed = finishedSig;
297   }
298   else
299   {
300     sigPassed = !finishedSig;
301   }
302
303   bool drawResult = callStack.FindMethod("DrawElements") || callStack.FindMethod("DrawArrays");
304
305   bool drawPassed = false;
306   if(testDrawn)
307   {
308     drawPassed = drawResult;
309   }
310   else
311   {
312     drawPassed = !drawResult;
313   }
314
315   bool keepUpdating       = (application.GetUpdateStatus() != 0);
316   bool keepUpdatingPassed = false;
317   if(testKeepUpdating)
318   {
319     keepUpdatingPassed = keepUpdating;
320   }
321   else
322   {
323     keepUpdatingPassed = !keepUpdating;
324   }
325
326   bool result = (sigPassed && drawPassed && keepUpdatingPassed);
327
328   tet_printf("UpdateRender: Expected: Draw:%s Signal:%s KeepUpdating: %s  Actual: Draw:%s  Signal:%s KeepUpdating: %s  %s, line %d\n",
329              BOOLSTR(testDrawn),
330              BOOLSTR(testFinished),
331              BOOLSTR(testKeepUpdating),
332              BOOLSTR(drawResult),
333              BOOLSTR(finishedSig),
334              BOOLSTR(keepUpdating),
335              result ? "Passed" : "Failed",
336              lineNumber);
337
338   return result;
339 }
340
341 } // unnamed namespace
342
343 /****************************************************************************************************/
344 /****************************************************************************************************/
345 /********************************   TEST CASES BELOW   **********************************************/
346 /****************************************************************************************************/
347 /****************************************************************************************************/
348
349 int UtcDaliRenderTaskDownCast01(void)
350 {
351   TestApplication application;
352
353   tet_infoline("Testing RenderTask::DownCast()");
354
355   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
356
357   BaseHandle base = taskList.GetTask(0u);
358   DALI_TEST_CHECK(base);
359
360   RenderTask task = RenderTask::DownCast(base);
361   DALI_TEST_CHECK(task);
362
363   // Try calling a method
364   DALI_TEST_CHECK(task.GetSourceActor());
365   END_TEST;
366 }
367
368 int UtcDaliRenderTaskDownCast02(void)
369 {
370   TestApplication application;
371
372   tet_infoline("Testing RenderTask::DownCast()");
373
374   Actor actor = Actor::New();
375
376   RenderTask task = RenderTask::DownCast(actor);
377   DALI_TEST_CHECK(!task);
378
379   END_TEST;
380 }
381
382 int UtcDaliRenderTaskSetSourceActorN(void)
383 {
384   TestApplication application;
385   tet_infoline("Testing RenderTask::SetSourceActor() Negative - try with empty actor handle");
386   Integration::Scene stage = application.GetScene();
387
388   Actor srcActor;
389
390   RenderTaskList taskList   = stage.GetRenderTaskList();
391   RenderTask     renderTask = taskList.CreateTask();
392   renderTask.SetSourceActor(srcActor);
393
394   application.SendNotification();
395   application.Render();
396
397   DALI_TEST_CHECK(!renderTask.GetSourceActor());
398   END_TEST;
399 }
400
401 int UtcDaliRenderTaskSetSourceActorP01(void)
402 {
403   TestApplication application;
404
405   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that setting a non-renderable actor stops existing source actor being rendered ");
406
407   Integration::Scene stage    = application.GetScene();
408   RenderTaskList     taskList = stage.GetRenderTaskList();
409   RenderTask         task     = taskList.GetTask(0u);
410
411   Actor actor = task.GetSourceActor();
412   DALI_TEST_CHECK(actor);
413
414   Texture img      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
415   Actor   newActor = CreateRenderableActor(img);
416   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
417   stage.Add(newActor);
418
419   Actor nonRenderableActor = Actor::New();
420   stage.Add(nonRenderableActor);
421
422   // Stop the newActor from being rendered by changing the source actor
423   DALI_TEST_CHECK(nonRenderableActor);
424   task.SetSourceActor(nonRenderableActor);
425   DALI_TEST_CHECK(task.GetSourceActor() != actor);
426   DALI_TEST_CHECK(task.GetSourceActor() == nonRenderableActor);
427
428   TestGlAbstraction& gl        = application.GetGlAbstraction();
429   TraceCallStack&    drawTrace = gl.GetDrawTrace();
430   drawTrace.Enable(true);
431
432   // Update & Render nothing!
433   application.GetGlAbstraction().ClearBoundTextures();
434   application.SendNotification();
435   application.Render();
436
437   // Check that nothing was rendered
438   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
439
440   END_TEST;
441 }
442
443 int UtcDaliRenderTaskSetSourceActorP02(void)
444 {
445   TestApplication application;
446
447   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that switching source from a non-renderable to a renderable actor causes the texture to be drawn");
448
449   Integration::Scene stage = application.GetScene();
450
451   RenderTaskList taskList = stage.GetRenderTaskList();
452
453   RenderTask task = taskList.GetTask(0u);
454
455   Actor actor = task.GetSourceActor();
456   DALI_TEST_CHECK(actor);
457
458   Texture img      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
459   Actor   newActor = CreateRenderableActor(img);
460   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
461   stage.Add(newActor);
462
463   Actor nonRenderableActor = Actor::New();
464   stage.Add(nonRenderableActor);
465
466   TestGlAbstraction& gl        = application.GetGlAbstraction();
467   TraceCallStack&    drawTrace = gl.GetDrawTrace();
468   drawTrace.Enable(true);
469
470   // Stop the newActor from being rendered by changing the source actor
471   DALI_TEST_CHECK(nonRenderableActor);
472   task.SetSourceActor(nonRenderableActor);
473   DALI_TEST_CHECK(task.GetSourceActor() != actor);
474   DALI_TEST_CHECK(task.GetSourceActor() == nonRenderableActor);
475
476   // Update & Render nothing!
477   application.GetGlAbstraction().ClearBoundTextures();
478   application.SendNotification();
479   application.Render();
480
481   // Check that nothing was rendered
482   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
483   drawTrace.Reset();
484
485   // Set newActor as the new source Actor
486   task.SetSourceActor(newActor);
487   DALI_TEST_CHECK(task.GetSourceActor() != actor);
488   DALI_TEST_CHECK(task.GetSourceActor() == newActor);
489
490   // Update & Render the newActor
491   application.GetGlAbstraction().ClearBoundTextures();
492   application.SendNotification();
493   application.Render();
494
495   // Check that the newActor was rendered
496   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
497   END_TEST;
498 }
499
500 int UtcDaliRenderTaskSetSourceActorOffScene(void)
501 {
502   TestApplication application;
503
504   tet_infoline("Testing RenderTask::SetSourceActor (on/off stage testing)");
505
506   Integration::Scene stage    = application.GetScene();
507   RenderTaskList     taskList = stage.GetRenderTaskList();
508   RenderTask         task     = taskList.GetTask(0u);
509
510   Actor actor = task.GetSourceActor();
511   DALI_TEST_CHECK(actor);
512
513   TestGlAbstraction& gl        = application.GetGlAbstraction();
514   TraceCallStack&    drawTrace = gl.GetDrawTrace();
515   drawTrace.Enable(true);
516
517   Texture img      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
518   Actor   newActor = CreateRenderableActor(img);
519   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
520   task.SetSourceActor(newActor);
521   // Don't add newActor to stage yet   //'
522
523   // Update & Render with the actor initially off-stage
524   application.SendNotification();
525   application.Render();
526
527   // Check that nothing was rendered
528   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
529
530   // Now add to stage
531   stage.Add(newActor);
532
533   // Update & Render with the actor on-stage
534   application.GetGlAbstraction().ClearBoundTextures();
535   application.SendNotification();
536   application.Render();
537
538   // Check that the newActor was rendered
539   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
540   drawTrace.Reset();
541
542   // Now remove from stage
543   stage.Remove(newActor);
544
545   // Update & Render with the actor off-stage
546   application.SendNotification();
547   application.Render();
548   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
549
550   END_TEST;
551 }
552
553 int UtcDaliRenderTaskSetSourceActorEmpty(void)
554 {
555   TestApplication application;
556
557   tet_infoline("Testing RenderTask::SetSourceActor (empty handle case)");
558
559   Integration::Scene stage    = application.GetScene();
560   RenderTaskList     taskList = stage.GetRenderTaskList();
561   RenderTask         task     = taskList.GetTask(0u);
562
563   Actor actor = task.GetSourceActor();
564   DALI_TEST_CHECK(actor);
565
566   Texture img      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
567   Actor   newActor = CreateRenderableActor(img);
568   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
569   stage.Add(newActor);
570
571   Actor nonRenderableActor = Actor::New();
572   stage.Add(nonRenderableActor);
573
574   // Set with empty handle
575   task.SetSourceActor(Actor());
576   DALI_TEST_CHECK(!task.GetSourceActor());
577
578   TestGlAbstraction& gl        = application.GetGlAbstraction();
579   TraceCallStack&    drawTrace = gl.GetDrawTrace();
580   drawTrace.Enable(true);
581
582   // Update & Render nothing!
583   application.SendNotification();
584   application.Render();
585
586   // Check that nothing was rendered
587   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
588
589   // Set with non-empty handle
590   task.SetSourceActor(newActor);
591   DALI_TEST_CHECK(task.GetSourceActor() == newActor);
592
593   // Update & Render the newActor
594   application.GetGlAbstraction().ClearBoundTextures();
595   application.SendNotification();
596   application.Render();
597
598   // Check that the newActor was rendered
599   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
600   END_TEST;
601 }
602
603 int UtcDaliRenderTaskSetSourceActorDestroyed(void)
604 {
605   TestApplication application;
606
607   tet_infoline("Testing RenderTask::SetSourceActor - Set a source actor and destroy the source actor");
608
609   Integration::Scene stage    = application.GetScene();
610   RenderTaskList     taskList = stage.GetRenderTaskList();
611   RenderTask         task     = taskList.GetTask(0u);
612
613   Actor actor = task.GetSourceActor();
614   DALI_TEST_CHECK(actor);
615
616   Texture img = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
617
618   Actor newActor = CreateRenderableActor(img);
619   newActor.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
620   stage.Add(newActor);
621
622   task.SetSourceActor(newActor);
623
624   DALI_TEST_CHECK(task.GetSourceActor() != actor);
625   DALI_TEST_CHECK(task.GetSourceActor() == newActor);
626
627   application.SendNotification();
628   application.Render();
629
630   // Destroy the source actor
631   stage.Remove(newActor);
632   newActor.Reset();
633
634   DALI_TEST_CHECK(!task.GetSourceActor()); // The source actor should be an empty handle.
635
636   END_TEST;
637 }
638
639 int UtcDaliRenderTaskGetSourceActorP01(void)
640 {
641   TestApplication application;
642
643   tet_infoline("Testing RenderTask::GetSourceActor() Check the default render task has a valid source actor");
644
645   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
646
647   RenderTask task = taskList.GetTask(0u);
648
649   Actor actor = task.GetSourceActor();
650   DALI_TEST_CHECK(actor);
651
652   // By default the entire scene should be rendered
653   Actor root = application.GetScene().GetLayer(0);
654   DALI_TEST_CHECK(root == actor);
655   END_TEST;
656 }
657
658 int UtcDaliRenderTaskGetSourceActorP02(void)
659 {
660   TestApplication application;
661
662   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.");
663
664   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
665   RenderTask     task     = taskList.CreateTask();
666   Actor          actor    = Actor::New();
667   application.GetScene().Add(actor);
668   task.SetSourceActor(actor);
669
670   DALI_TEST_EQUALS(actor, task.GetSourceActor(), TEST_LOCATION);
671
672   END_TEST;
673 }
674
675 int UtcDaliRenderTaskGetSourceActorN(void)
676 {
677   TestApplication application;
678
679   tet_infoline("Testing RenderTask::GetSourceActor() Try with empty handle");
680
681   RenderTask task;
682   try
683   {
684     Actor actor = task.GetSourceActor();
685   }
686   catch(Dali::DaliException& e)
687   {
688     DALI_TEST_PRINT_ASSERT(e);
689     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
690   }
691
692   END_TEST;
693 }
694
695 int UtcDaliRenderTaskSetExclusive(void)
696 {
697   TestApplication application;
698
699   tet_infoline("Testing RenderTask::SetExclusive() Check that exclusion works");
700
701   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
702
703   // Creates:
704   //           Root
705   //  Actor1   Layer    Layer
706   //           Actor2  Actor3
707
708   // Task 1 is the default render task, should render from Root, incl Actor2
709   // Task 2 uses Actor2 as a source actor (texture id 9)
710
711   // Manipulate the GenTextures behaviour, to identify different actors
712
713   std::vector<GLuint> ids;
714   ids.push_back(8);  // 8 = actor1
715   ids.push_back(9);  // 9 = actor2
716   ids.push_back(10); // 10 = actor3
717   application.GetGlAbstraction().SetNextTextureIds(ids);
718
719   Texture img1   = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
720   Actor   actor1 = CreateRenderableActor(img1);
721   actor1.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
722   application.GetScene().Add(actor1);
723
724   // Update & Render actor1
725   application.SendNotification();
726   application.Render();
727
728   // Check that the actor1 was rendered
729   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures(GL_TEXTURE0);
730   DALI_TEST_GREATER(boundTextures.size(), static_cast<std::vector<GLuint>::size_type>(0), TEST_LOCATION);
731
732   if(boundTextures.size())
733   {
734     int a = boundTextures.size() - 1;
735     DALI_TEST_EQUALS(boundTextures[a], 8u /*unique to actor1*/, TEST_LOCATION);
736   }
737
738   Texture img2 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
739
740   Actor actor2 = CreateRenderableActor(img2);
741   actor2.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
742
743   // Force actor2 to be rendered before actor1
744   Layer layer = Layer::New();
745   application.GetScene().Add(layer);
746   layer.Add(actor2);
747   layer.LowerToBottom();
748
749   // Update & Render
750   application.GetGlAbstraction().ClearBoundTextures();
751   application.SendNotification();
752   application.Render();
753
754   // Check that the actors were rendered
755   DALI_TEST_GREATER(boundTextures.size(), static_cast<std::vector<GLuint>::size_type>(1), TEST_LOCATION);
756
757   if(boundTextures.size() >= 2)
758   {
759     int a = boundTextures.size() - 2;
760     int b = boundTextures.size() - 1;
761     DALI_TEST_EQUALS(boundTextures[a], 9u /*unique to actor2*/, TEST_LOCATION);
762     DALI_TEST_EQUALS(boundTextures[b], 8u /*unique to actor1*/, TEST_LOCATION);
763   }
764
765   Texture img3   = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
766   Actor   actor3 = CreateRenderableActor(img3);
767   actor3.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
768
769   // Force actor3 to be rendered before actor2
770   layer = Layer::New();
771   application.GetScene().Add(layer);
772   layer.Add(actor3);
773   layer.LowerToBottom();
774
775   // Update & Render all actors
776   application.GetGlAbstraction().ClearBoundTextures();
777   application.SendNotification();
778   application.Render();
779
780   // Check that the actors were rendered
781   DALI_TEST_GREATER(boundTextures.size(), static_cast<std::vector<GLuint>::size_type>(2), TEST_LOCATION);
782
783   if(boundTextures.size() >= 3)
784   {
785     int a = boundTextures.size() - 3;
786     int b = boundTextures.size() - 2;
787     int c = boundTextures.size() - 1;
788     DALI_TEST_EQUALS(boundTextures[a], 10u /*unique to actor3*/, TEST_LOCATION);
789     DALI_TEST_EQUALS(boundTextures[b], 9u /*unique to actor2*/, TEST_LOCATION);
790     DALI_TEST_EQUALS(boundTextures[c], 8u /*unique to actor1*/, TEST_LOCATION);
791   }
792
793   // Both actors are now connected to the root node
794   // Setup 2 render-tasks - the first will render from the root-node, and the second from actor2
795
796   // Not exclusive is the default
797   RenderTask task1 = taskList.GetTask(0u);
798   DALI_TEST_CHECK(false == task1.IsExclusive());
799
800   RenderTask task2 = taskList.CreateTask();
801   DALI_TEST_CHECK(false == task2.IsExclusive());
802   task2.SetSourceActor(actor2);
803
804   // Task1 should render all actors, and task 2 should render only actor2
805
806   application.GetGlAbstraction().ClearBoundTextures();
807   application.SendNotification();
808   application.Render();
809
810   if(boundTextures.size() >= 4)
811   {
812     // Test that task 1 renders actor3, then actor2 & then actor1
813     int a = boundTextures.size() - 4;
814     int b = boundTextures.size() - 3;
815     int c = boundTextures.size() - 2;
816     int d = boundTextures.size() - 1;
817     DALI_TEST_EQUALS(boundTextures[a], 10u /*unique to actor3*/, TEST_LOCATION);
818     DALI_TEST_EQUALS(boundTextures[b], 9u /*unique to actor2*/, TEST_LOCATION);
819     DALI_TEST_EQUALS(boundTextures[c], 8u /*unique to actor1*/, TEST_LOCATION);
820
821     // Test that task 2 renders actor2
822     DALI_TEST_EQUALS(boundTextures[d], 9u, TEST_LOCATION);
823   }
824
825   // Make actor2 exclusive to task2
826
827   task2.SetExclusive(true);
828   DALI_TEST_CHECK(true == task2.IsExclusive());
829
830   // Task1 should render only actor1, and task 2 should render only actor2
831
832   application.GetGlAbstraction().ClearBoundTextures();
833   application.SendNotification();
834   application.Render();
835
836   DALI_TEST_EQUALS(boundTextures.size(), 3u, TEST_LOCATION);
837   if(boundTextures.size() == 3)
838   {
839     // Test that task 1 renders actor3 & actor1
840     DALI_TEST_CHECK(boundTextures[0] == 10u);
841     DALI_TEST_CHECK(boundTextures[1] == 8u);
842
843     // Test that task 2 renders actor2
844     DALI_TEST_CHECK(boundTextures[2] == 9u);
845   }
846
847   // Create a renderable actor and replace the source actor in task2
848   auto actor4 = CreateRenderableActor();
849   task2.SetSourceActor(actor3);
850   DALI_TEST_EQUALS(actor3, task2.GetSourceActor(), TEST_LOCATION);
851
852   END_TEST;
853 }
854
855 int UtcDaliRenderTaskSetExclusive02(void)
856 {
857   TestApplication application;
858
859   tet_infoline("Testing RenderTask::SetExclusive() Check that changing from exclusive to not-exclusive works");
860
861   std::vector<GLuint> ids;
862   ids.push_back(8); // 8 = actor1
863   application.GetGlAbstraction().SetNextTextureIds(ids);
864
865   Texture img1   = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
866   Actor   actor1 = CreateRenderableActor(img1);
867   actor1.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
868   application.GetScene().Add(actor1);
869
870   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
871   RenderTask     task     = taskList.CreateTask();
872
873   task.SetSourceActor(actor1);
874   task.SetExclusive(true); // Actor should only render once
875
876   TestGlAbstraction& gl        = application.GetGlAbstraction();
877   TraceCallStack&    drawTrace = gl.GetDrawTrace();
878   drawTrace.Enable(true);
879
880   // Update & Render actor1
881   application.SendNotification();
882   application.Render();
883
884   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
885
886   // Set task to non-exclusive - actor1 should render twice:
887   drawTrace.Reset();
888   task.SetExclusive(false);
889   application.SendNotification();
890   application.Render();
891
892   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 2, TEST_LOCATION);
893
894   END_TEST;
895 }
896
897 int UtcDaliRenderTaskSetExclusive03(void)
898 {
899   TestApplication application;
900
901   tet_infoline("Testing RenderTask::SetExclusive() Check that changing from exclusive to not-exclusive works");
902
903   std::vector<GLuint> ids;
904   ids.push_back(8); // 8 = actor1
905   application.GetGlAbstraction().SetNextTextureIds(ids);
906
907   Texture img1   = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
908   Actor   actor1 = CreateRenderableActor(img1);
909   actor1.SetProperty(Actor::Property::SIZE, Vector2(1.0f, 1.0f));
910   application.GetScene().Add(actor1);
911
912   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
913   RenderTask     task     = taskList.CreateTask();
914
915   task.SetSourceActor(actor1);
916   task.SetExclusive(true); // Actor should only render once
917
918   TestGlAbstraction& gl        = application.GetGlAbstraction();
919   TraceCallStack&    drawTrace = gl.GetDrawTrace();
920   drawTrace.Enable(true);
921
922   // Update & Render actor1
923   application.SendNotification();
924   application.Render();
925
926   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
927
928   // Set task to non-exclusive - actor1 should render twice:
929   drawTrace.Reset();
930
931   RenderTask task2 = taskList.CreateTask();
932   task2.SetSourceActor(actor1);
933   task2.SetExclusive(true); // Actor should only render once
934
935   application.SendNotification();
936   application.Render();
937
938   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 2, TEST_LOCATION);
939
940   // Set task to non-exclusive - actor1 should render twice:
941   drawTrace.Reset();
942   task.SetExclusive(false);
943   application.SendNotification();
944   application.Render();
945
946   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
947
948   // Set task to non-exclusive - actor1 should render twice:
949   drawTrace.Reset();
950   task2.SetExclusive(false);
951   application.SendNotification();
952   application.Render();
953
954   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
955
956   END_TEST;
957 }
958
959 int UtcDaliRenderTaskSetExclusiveN(void)
960 {
961   TestApplication application;
962
963   tet_infoline("Testing RenderTask::SetExclusive() on empty handle");
964
965   RenderTask task;
966   try
967   {
968     task.SetExclusive(true);
969   }
970   catch(Dali::DaliException& e)
971   {
972     DALI_TEST_PRINT_ASSERT(e);
973     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
974   }
975   END_TEST;
976 }
977
978 int UtcDaliRenderTaskIsExclusive01(void)
979 {
980   TestApplication application;
981
982   tet_infoline("Testing RenderTask::IsExclusive() Check default values are non-exclusive");
983
984   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
985
986   // Not exclusive is the default
987   RenderTask task = taskList.GetTask(0u);
988   DALI_TEST_CHECK(false == task.IsExclusive());
989
990   RenderTask newTask = taskList.CreateTask();
991   DALI_TEST_CHECK(false == newTask.IsExclusive());
992
993   END_TEST;
994 }
995
996 int UtcDaliRenderTaskIsExclusive02(void)
997 {
998   TestApplication application;
999
1000   tet_infoline("Testing RenderTask::IsExclusive() Check the getter returns set values");
1001
1002   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1003
1004   // Not exclusive is the default
1005   RenderTask newTask = taskList.CreateTask();
1006   DALI_TEST_EQUALS(newTask.IsExclusive(), false, TEST_LOCATION);
1007
1008   newTask.SetExclusive(true);
1009   DALI_TEST_EQUALS(newTask.IsExclusive(), true, TEST_LOCATION);
1010   END_TEST;
1011 }
1012
1013 int UtcDaliRenderTaskIsExclusiveN(void)
1014 {
1015   TestApplication application;
1016
1017   tet_infoline("Testing RenderTask::IsExclusive() on empty handle");
1018
1019   RenderTask task;
1020   try
1021   {
1022     bool x = task.IsExclusive();
1023     (void)x;
1024   }
1025   catch(Dali::DaliException& e)
1026   {
1027     DALI_TEST_PRINT_ASSERT(e);
1028     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1029   }
1030   END_TEST;
1031 }
1032
1033 int UtcDaliRenderTaskSetInputEnabled(void)
1034 {
1035   TestApplication application;
1036
1037   tet_infoline("Testing RenderTask::SetInputEnabled()");
1038
1039   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1040
1041   // Input is enabled by default
1042   RenderTask task = taskList.GetTask(0u);
1043   DALI_TEST_CHECK(true == task.GetInputEnabled());
1044
1045   task.SetInputEnabled(false);
1046   DALI_TEST_CHECK(false == task.GetInputEnabled());
1047
1048   task.SetInputEnabled(true);
1049   DALI_TEST_CHECK(true == task.GetInputEnabled());
1050   END_TEST;
1051 }
1052
1053 int UtcDaliRenderTaskGetInputEnabled(void)
1054 {
1055   TestApplication application;
1056
1057   tet_infoline("Testing RenderTask::GetInputEnabled()");
1058
1059   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1060
1061   // Input is enabled by default
1062   RenderTask task = taskList.GetTask(0u);
1063   DALI_TEST_EQUALS(true, task.GetInputEnabled(), TEST_LOCATION);
1064
1065   RenderTask newTask = taskList.CreateTask();
1066   DALI_TEST_EQUALS(true, newTask.GetInputEnabled(), TEST_LOCATION);
1067
1068   newTask.SetInputEnabled(false);
1069   DALI_TEST_EQUALS(false, newTask.GetInputEnabled(), TEST_LOCATION);
1070
1071   END_TEST;
1072 }
1073
1074 int UtcDaliRenderTaskSetCameraActorP(void)
1075 {
1076   TestApplication application;
1077
1078   tet_infoline("Testing RenderTask::SetCameraActor()");
1079
1080   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1081
1082   RenderTask task = taskList.GetTask(0u);
1083
1084   Actor defaultCameraActor = task.GetCameraActor();
1085   DALI_TEST_CHECK(defaultCameraActor);
1086
1087   CameraActor newCameraActor = CameraActor::New();
1088   DALI_TEST_CHECK(newCameraActor);
1089
1090   task.SetCameraActor(newCameraActor);
1091   DALI_TEST_CHECK(task.GetCameraActor() != defaultCameraActor);
1092   DALI_TEST_EQUALS(task.GetCameraActor(), newCameraActor, TEST_LOCATION);
1093   END_TEST;
1094 }
1095
1096 int UtcDaliRenderTaskSetCameraActorN(void)
1097 {
1098   TestApplication application;
1099
1100   tet_infoline("Testing RenderTask::SetCameraActor() with empty actor handle");
1101
1102   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1103
1104   RenderTask task = taskList.GetTask(0u);
1105
1106   Actor actor = task.GetCameraActor();
1107   DALI_TEST_CHECK(actor);
1108
1109   CameraActor cameraActor;
1110
1111   task.SetCameraActor(cameraActor);
1112   DALI_TEST_EQUALS((bool)task.GetCameraActor(), false, TEST_LOCATION);
1113   DALI_TEST_EQUALS(task.GetCameraActor(), cameraActor, TEST_LOCATION);
1114   END_TEST;
1115 }
1116
1117 int UtcDaliRenderTaskSetCameraActorDestroyed(void)
1118 {
1119   TestApplication application;
1120
1121   tet_infoline("Testing RenderTask::SetCameraActor - Set a camera actor and destroy the camera actor");
1122
1123   Integration::Scene stage    = application.GetScene();
1124   RenderTaskList     taskList = stage.GetRenderTaskList();
1125   RenderTask         task     = taskList.GetTask(0u);
1126
1127   CameraActor newCameraActor = CameraActor::New();
1128   task.SetCameraActor(newCameraActor);
1129
1130   DALI_TEST_EQUALS(task.GetCameraActor(), newCameraActor, TEST_LOCATION);
1131
1132   // Destroy the camera actor
1133   newCameraActor.Reset();
1134
1135   CameraActor camera = task.GetCameraActor();
1136   DALI_TEST_CHECK(!camera); // The camera actor should be an empty handle.
1137
1138   END_TEST;
1139 }
1140
1141 int UtcDaliRenderTaskGetCameraActorP(void)
1142 {
1143   TestApplication application;
1144
1145   tet_infoline("Testing RenderTask::GetCameraActor()");
1146
1147   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1148
1149   RenderTask task = taskList.GetTask(0u);
1150
1151   CameraActor actor = task.GetCameraActor();
1152   DALI_TEST_CHECK(actor);
1153   DALI_TEST_EQUALS(actor.GetProjectionMode(), Dali::Camera::PERSPECTIVE_PROJECTION, TEST_LOCATION);
1154   DALI_TEST_GREATER(actor.GetFieldOfView(), 0.0f, TEST_LOCATION);
1155   END_TEST;
1156 }
1157
1158 int UtcDaliRenderTaskGetCameraActorN(void)
1159 {
1160   TestApplication application;
1161
1162   tet_infoline("Testing RenderTask::GetCameraActor() with empty handle");
1163   RenderTask task;
1164
1165   try
1166   {
1167     Actor actor = task.GetCameraActor();
1168   }
1169   catch(Dali::DaliException& e)
1170   {
1171     DALI_TEST_PRINT_ASSERT(e);
1172     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1173   }
1174
1175   END_TEST;
1176 }
1177
1178 int UtcDaliRenderTaskSetFrameBufferP(void)
1179 {
1180   TestApplication application;
1181
1182   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1183
1184   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1185
1186   RenderTask task = taskList.GetTask(0u);
1187
1188   FrameBuffer newFrameBuffer = FrameBuffer::New(128u, 128u, FrameBuffer::Attachment::NONE);
1189   task.SetFrameBuffer(newFrameBuffer);
1190   DALI_TEST_CHECK(task.GetFrameBuffer() == newFrameBuffer);
1191   END_TEST;
1192 }
1193
1194 int UtcDaliRenderTaskSetFrameBufferN(void)
1195 {
1196   TestApplication application;
1197
1198   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1199
1200   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1201
1202   RenderTask  task = taskList.GetTask(0u);
1203   FrameBuffer newFrameBuffer; // Empty handle
1204   task.SetFrameBuffer(newFrameBuffer);
1205   DALI_TEST_EQUALS((bool)task.GetFrameBuffer(), false, TEST_LOCATION);
1206   END_TEST;
1207 }
1208
1209 int UtcDaliRenderTaskGetFrameBufferP(void)
1210 {
1211   TestApplication application;
1212
1213   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1214
1215   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1216
1217   RenderTask task = taskList.GetTask(0u);
1218
1219   FrameBuffer newFrameBuffer = FrameBuffer::New(1u, 1u, FrameBuffer::Attachment::NONE);
1220   task.SetFrameBuffer(newFrameBuffer);
1221   DALI_TEST_CHECK(task.GetFrameBuffer() == newFrameBuffer);
1222   END_TEST;
1223 }
1224
1225 int UtcDaliRenderTaskGetFrameBufferN(void)
1226 {
1227   TestApplication application;
1228
1229   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1230
1231   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1232
1233   RenderTask task = taskList.GetTask(0u);
1234
1235   // By default render-tasks do not render off-screen
1236   FrameBuffer frameBuffer = task.GetFrameBuffer();
1237   DALI_TEST_CHECK(!frameBuffer);
1238
1239   END_TEST;
1240 }
1241
1242 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionP(void)
1243 {
1244   TestApplication application;
1245
1246   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1247
1248   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1249
1250   RenderTask task = taskList.GetTask(0u);
1251
1252   task.SetScreenToFrameBufferFunction(TestScreenToFrameBufferFunction);
1253
1254   Vector2 coordinates(5, 10);
1255   Vector2 convertedCoordinates(6, 12); // + Vector(1, 2)
1256
1257   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1258   DALI_TEST_CHECK(func(coordinates));
1259   DALI_TEST_CHECK(coordinates == convertedCoordinates);
1260
1261   task.SetScreenToFrameBufferFunction(RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION);
1262   func = task.GetScreenToFrameBufferFunction();
1263   DALI_TEST_CHECK(func(coordinates));
1264
1265   task.SetScreenToFrameBufferFunction(RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION);
1266   func = task.GetScreenToFrameBufferFunction();
1267   DALI_TEST_CHECK(!func(coordinates));
1268   END_TEST;
1269 }
1270
1271 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionN(void)
1272 {
1273   TestApplication application;
1274
1275   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1276
1277   RenderTask task; // Empty handle
1278   try
1279   {
1280     task.SetScreenToFrameBufferFunction(TestScreenToFrameBufferFunction);
1281   }
1282   catch(Dali::DaliException& e)
1283   {
1284     DALI_TEST_PRINT_ASSERT(e);
1285     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1286   }
1287   END_TEST;
1288 }
1289
1290 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionP(void)
1291 {
1292   TestApplication application;
1293
1294   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction()");
1295
1296   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1297
1298   RenderTask task = taskList.GetTask(0u);
1299
1300   Vector2 originalCoordinates(5, 10);
1301   Vector2 coordinates(5, 10);
1302
1303   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1304   DALI_TEST_CHECK(!func(coordinates));                 // conversion should fail by default
1305   DALI_TEST_CHECK(coordinates == originalCoordinates); // coordinates should not be modified
1306   END_TEST;
1307 }
1308
1309 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionN(void)
1310 {
1311   TestApplication application;
1312
1313   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction() on empty handle");
1314
1315   RenderTask task;
1316   try
1317   {
1318     RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1319     (void)func;
1320   }
1321   catch(Dali::DaliException& e)
1322   {
1323     DALI_TEST_PRINT_ASSERT(e);
1324     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1325   }
1326   END_TEST;
1327 }
1328
1329 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorP(void)
1330 {
1331   TestApplication application;
1332   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor ");
1333
1334   RenderTaskList taskList     = application.GetScene().GetRenderTaskList();
1335   RenderTask     renderTask   = taskList.CreateTask();
1336   Actor          mappingActor = Actor::New();
1337   renderTask.SetScreenToFrameBufferMappingActor(mappingActor);
1338
1339   DALI_TEST_EQUALS(mappingActor, renderTask.GetScreenToFrameBufferMappingActor(), TEST_LOCATION);
1340   END_TEST;
1341 }
1342
1343 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorN(void)
1344 {
1345   TestApplication application;
1346   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1347
1348   RenderTask task;
1349   try
1350   {
1351     Actor mappingActor;
1352     task.SetScreenToFrameBufferMappingActor(mappingActor);
1353   }
1354   catch(Dali::DaliException& e)
1355   {
1356     DALI_TEST_PRINT_ASSERT(e);
1357     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1358   }
1359   END_TEST;
1360 }
1361
1362 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActor02N(void)
1363 {
1364   TestApplication application;
1365   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1366
1367   RenderTaskList taskList   = application.GetScene().GetRenderTaskList();
1368   RenderTask     renderTask = taskList.CreateTask();
1369   Actor          actor;
1370   renderTask.SetScreenToFrameBufferMappingActor(actor);
1371
1372   DALI_TEST_EQUALS((bool)renderTask.GetScreenToFrameBufferMappingActor(), false, TEST_LOCATION);
1373   END_TEST;
1374 }
1375
1376 int UtcDaliRenderTaskGetViewportP01(void)
1377 {
1378   TestApplication application;
1379
1380   tet_infoline("Testing RenderTask::GetViewport() on default task");
1381
1382   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1383   RenderTask     task     = taskList.GetTask(0u);
1384   Viewport       viewport = task.GetViewport();
1385
1386   // By default the viewport should match the stage width/height
1387   Vector2  stageSize = application.GetScene().GetSize();
1388   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1389   DALI_TEST_CHECK(viewport == expectedViewport);
1390   END_TEST;
1391 }
1392
1393 int UtcDaliRenderTaskGetViewportP02(void)
1394 {
1395   TestApplication application;
1396
1397   tet_infoline("Testing RenderTask::GetViewport() on new task");
1398
1399   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1400   RenderTask     task     = taskList.CreateTask();
1401   Viewport       viewport = task.GetViewport();
1402
1403   // By default the viewport should match the stage width/height
1404   Vector2  stageSize = application.GetScene().GetSize();
1405   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1406   DALI_TEST_CHECK(viewport == expectedViewport);
1407   END_TEST;
1408 }
1409
1410 int UtcDaliRenderTaskGetViewportN(void)
1411 {
1412   TestApplication application;
1413
1414   tet_infoline("Testing RenderTask::GetViewport() on empty handle");
1415
1416   RenderTask task;
1417   try
1418   {
1419     Viewport viewport = task.GetViewport();
1420     (void)viewport;
1421   }
1422   catch(Dali::DaliException& e)
1423   {
1424     DALI_TEST_PRINT_ASSERT(e);
1425     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1426   }
1427   END_TEST;
1428 }
1429
1430 int UtcDaliRenderTaskSetViewportP(void)
1431 {
1432   TestApplication application;
1433
1434   tet_infoline("Testing RenderTask::SetViewport()");
1435
1436   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1437
1438   RenderTask task      = taskList.GetTask(0u);
1439   Vector2    stageSize = application.GetScene().GetSize();
1440   Viewport   newViewport(0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f);
1441   task.SetViewport(newViewport);
1442
1443   // Update (viewport is a property)
1444   application.SendNotification();
1445   application.Render();
1446
1447   DALI_TEST_CHECK(task.GetViewport() == newViewport);
1448   END_TEST;
1449 }
1450
1451 int UtcDaliRenderTaskSetViewportN(void)
1452 {
1453   TestApplication application;
1454
1455   tet_infoline("Testing RenderTask::SetViewport()");
1456
1457   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1458
1459   RenderTask task;
1460   try
1461   {
1462     Vector2  stageSize = application.GetScene().GetSize();
1463     Viewport newViewport(0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f);
1464     task.SetViewport(newViewport);
1465   }
1466   catch(Dali::DaliException& e)
1467   {
1468     DALI_TEST_PRINT_ASSERT(e);
1469     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1470   }
1471
1472   END_TEST;
1473 }
1474
1475 int UtcDaliRenderTaskSetViewportPosition(void)
1476 {
1477   TestApplication application;
1478
1479   tet_infoline("Testing RenderTask::SetViewportPosition()");
1480
1481   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1482
1483   RenderTask task = taskList.GetTask(0u);
1484
1485   Viewport viewport = task.GetViewport();
1486
1487   // By default the viewport should match the stage width/height
1488
1489   Vector2  stageSize = application.GetScene().GetSize();
1490   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1491   DALI_TEST_CHECK(viewport == expectedViewport);
1492
1493   // 'Setter' test
1494   Vector2 newPosition(25.0f, 50.0f);
1495   task.SetViewportPosition(newPosition);
1496
1497   // Update (viewport is a property)
1498   application.SendNotification();
1499   application.Render();
1500
1501   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1502
1503   // Set by Property test
1504   Vector2 newPosition2(32.0f, 32.0f);
1505   task.SetProperty(RenderTask::Property::VIEWPORT_POSITION, newPosition2);
1506   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1507   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition, TEST_LOCATION); // still the old position
1508
1509   // Update
1510   application.SendNotification();
1511   application.Render();
1512
1513   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition2, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1514   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1515   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1516
1517   Vector2   newPosition3(64.0f, 0.0f);
1518   Animation animation = Animation::New(1.0f);
1519   animation.AnimateTo(Property(task, RenderTask::Property::VIEWPORT_POSITION), newPosition3, AlphaFunction::LINEAR);
1520   animation.Play();
1521
1522   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1523   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition2, TEST_LOCATION);
1524
1525   // Perform 1000ms worth of updates at which point animation should have completed.
1526   Wait(application, 1000);
1527   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1528   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1529   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1530
1531   // Create another animation which animates by a certain value
1532   const Vector2 newPosition4(75.0f, 45.0f);
1533   const Vector2 relativePosition(newPosition4 - newPosition3);
1534   animation = Animation::New(1.0f);
1535   animation.AnimateBy(Property(task, RenderTask::Property::VIEWPORT_POSITION), relativePosition);
1536   animation.Play();
1537
1538   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1539   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition3, TEST_LOCATION);
1540
1541   // Perform 1000ms worth of updates at which point animation should have completed.
1542   Wait(application, 1000);
1543   DALI_TEST_EQUALS(task.GetCurrentViewportPosition(), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1544   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1545   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_POSITION), newPosition4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1546
1547   END_TEST;
1548 }
1549
1550 int UtcDaliRenderTaskSetViewportSize(void)
1551 {
1552   TestApplication application;
1553
1554   tet_infoline("Testing RenderTask::SetViewportSize()");
1555
1556   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1557
1558   RenderTask task = taskList.GetTask(0u);
1559
1560   Viewport viewport = task.GetViewport();
1561
1562   // By default the viewport should match the stage width/height
1563
1564   Vector2  stageSize = application.GetScene().GetSize();
1565   Viewport expectedViewport(0, 0, stageSize.width, stageSize.height);
1566   DALI_TEST_CHECK(viewport == expectedViewport);
1567
1568   Vector2 newSize(128.0f, 64.0f);
1569   task.SetViewportSize(newSize);
1570
1571   // Update (viewport is a property)
1572   application.SendNotification();
1573   application.Render();
1574
1575   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1576
1577   // Set by Property test
1578   Vector2 newSize2(50.0f, 50.0f);
1579   task.SetProperty(RenderTask::Property::VIEWPORT_SIZE, newSize2);
1580   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1581   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize, TEST_LOCATION); // still the old position
1582
1583   // Update
1584   application.SendNotification();
1585   application.Render();
1586
1587   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize2, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1588   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1589   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1590
1591   Vector2   newSize3(10.0f, 10.0f);
1592   Animation animation = Animation::New(1.0f);
1593   animation.AnimateTo(Property(task, RenderTask::Property::VIEWPORT_SIZE), newSize3, AlphaFunction::LINEAR);
1594   animation.Play();
1595
1596   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1597   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize2, TEST_LOCATION);
1598
1599   // Perform 1000ms worth of updates at which point animation should have completed.
1600   Wait(application, 1000);
1601   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1602   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1603   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1604
1605   // Create another animation which animates by a certain value
1606   const Vector2 newSize4(75.0f, 45.0f);
1607   const Vector2 relativeSize(newSize4 - newSize3);
1608   animation = Animation::New(1.0f);
1609   animation.AnimateBy(Property(task, RenderTask::Property::VIEWPORT_SIZE), relativeSize);
1610   animation.Play();
1611
1612   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1613   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize3, TEST_LOCATION);
1614
1615   // Perform 1000ms worth of updates at which point animation should have completed.
1616   Wait(application, 1000);
1617   DALI_TEST_EQUALS(task.GetCurrentViewportSize(), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1618   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1619   DALI_TEST_EQUALS(task.GetProperty<Vector2>(RenderTask::Property::VIEWPORT_SIZE), newSize4, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1620
1621   END_TEST;
1622 }
1623
1624 int UtcDaliRenderTaskSetClearColorP(void)
1625 {
1626   TestApplication application;
1627
1628   tet_infoline("Testing RenderTask::SetClearColor()");
1629
1630   Vector4 testColor(1.0f, 2.0f, 3.0f, 4.0f);
1631   Vector4 testColor2(5.0f, 6.0f, 7.0f, 8.0f);
1632
1633   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1634
1635   RenderTask task = taskList.GetTask(0u);
1636   DALI_TEST_CHECK(task.GetClearColor() != testColor);
1637
1638   task.SetClearColor(testColor);
1639
1640   // Wait a frame.
1641   Wait(application);
1642
1643   DALI_TEST_EQUALS(task.GetClearColor(), testColor, TEST_LOCATION);
1644
1645   task.SetProperty(RenderTask::Property::CLEAR_COLOR, testColor2);
1646   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1647   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor, TEST_LOCATION); // still the old color
1648
1649   // Wait a frame.
1650   Wait(application);
1651
1652   DALI_TEST_EQUALS(task.GetClearColor(), testColor2, TEST_LOCATION);
1653   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1654   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1655
1656   Vector4   newColor3(10.0f, 10.0f, 20.0f, 30.0f);
1657   Animation animation = Animation::New(1.0f);
1658   animation.AnimateTo(Property(task, RenderTask::Property::CLEAR_COLOR), newColor3, AlphaFunction::LINEAR);
1659   animation.Play();
1660
1661   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1662   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), testColor2, TEST_LOCATION);
1663
1664   // Perform 1000ms worth of updates at which point animation should have completed.
1665   Wait(application, 1000);
1666   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1667   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION);
1668
1669   // Create another animation which animates by a certain value
1670   const Vector4 newColor4(0.45f, 0.35f, 0.25f, 0.1f);
1671   const Vector4 relativeColor(newColor4 - newColor3);
1672   animation = Animation::New(1.0f);
1673   animation.AnimateBy(Property(task, RenderTask::Property::CLEAR_COLOR), relativeColor);
1674   animation.Play();
1675
1676   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor4, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1677   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor3, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1678
1679   // Perform 1000ms worth of updates at which point animation should have completed.
1680   Wait(application, 1000);
1681   DALI_TEST_EQUALS(task.GetCurrentProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor4, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1682   DALI_TEST_EQUALS(task.GetProperty<Vector4>(RenderTask::Property::CLEAR_COLOR), newColor4, Math::MACHINE_EPSILON_10, TEST_LOCATION);
1683
1684   END_TEST;
1685 }
1686
1687 int UtcDaliRenderTaskSetClearColorN(void)
1688 {
1689   TestApplication application;
1690
1691   tet_infoline("Testing RenderTask::SetClearColor() on empty handle");
1692
1693   RenderTask task;
1694   try
1695   {
1696     task.SetClearColor(Vector4::ZERO);
1697   }
1698   catch(Dali::DaliException& e)
1699   {
1700     DALI_TEST_PRINT_ASSERT(e);
1701     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1702   }
1703   END_TEST;
1704 }
1705
1706 int UtcDaliRenderTaskGetClearColorP(void)
1707 {
1708   TestApplication application;
1709
1710   tet_infoline("Testing RenderTask::GetClearColor()");
1711
1712   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1713   RenderTask     task     = taskList.GetTask(0u);
1714   DALI_TEST_EQUALS(task.GetClearColor(), RenderTask::DEFAULT_CLEAR_COLOR, TEST_LOCATION);
1715   END_TEST;
1716 }
1717
1718 int UtcDaliRenderTaskGetClearColorN(void)
1719 {
1720   TestApplication application;
1721
1722   tet_infoline("Testing RenderTask::GetClearColor()");
1723
1724   RenderTask task;
1725   try
1726   {
1727     Vector4 color = task.GetClearColor();
1728     (void)color;
1729   }
1730   catch(Dali::DaliException& e)
1731   {
1732     DALI_TEST_PRINT_ASSERT(e);
1733     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1734   }
1735   END_TEST;
1736 }
1737
1738 int UtcDaliRenderTaskSetClearEnabledP(void)
1739 {
1740   TestApplication application;
1741
1742   tet_infoline("Testing RenderTask::SetClearEnabled()");
1743
1744   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1745
1746   RenderTask task = taskList.GetTask(0u);
1747   DALI_TEST_CHECK(task.GetClearEnabled()); // defaults to true
1748
1749   task.SetClearEnabled(false);
1750   DALI_TEST_EQUALS(task.GetClearEnabled(), false, TEST_LOCATION);
1751
1752   task.SetClearEnabled(true);
1753   DALI_TEST_EQUALS(task.GetClearEnabled(), true, TEST_LOCATION);
1754   END_TEST;
1755 }
1756
1757 int UtcDaliRenderTaskSetClearEnabledN(void)
1758 {
1759   TestApplication application;
1760
1761   tet_infoline("Testing RenderTask::SetClearEnabled() with empty handle");
1762
1763   RenderTask task;
1764   try
1765   {
1766     task.SetClearEnabled(true);
1767   }
1768   catch(Dali::DaliException& e)
1769   {
1770     DALI_TEST_PRINT_ASSERT(e);
1771     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1772   }
1773   END_TEST;
1774 }
1775
1776 int UtcDaliRenderTaskGetClearEnabledP(void)
1777 {
1778   TestApplication application;
1779
1780   tet_infoline("Testing RenderTask::GetClearEnabled()");
1781
1782   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1783
1784   RenderTask task = taskList.GetTask(0u);
1785   DALI_TEST_CHECK(task.GetClearEnabled()); // defaults to true
1786   END_TEST;
1787 }
1788
1789 int UtcDaliRenderTaskGetClearEnabledN(void)
1790 {
1791   TestApplication application;
1792
1793   tet_infoline("Testing RenderTask::GetClearEnabled() with empty handle");
1794
1795   RenderTask task;
1796   try
1797   {
1798     bool x = task.GetClearEnabled();
1799     (void)x;
1800   }
1801   catch(Dali::DaliException& e)
1802   {
1803     DALI_TEST_PRINT_ASSERT(e);
1804     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1805   }
1806   END_TEST;
1807 }
1808
1809 int UtcDaliRenderTaskSetCullModeP(void)
1810 {
1811   TestApplication application;
1812
1813   tet_infoline("Testing RenderTask::SetCullMode()");
1814
1815   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1816   RenderTask     task     = taskList.GetTask(0u);
1817   DALI_TEST_EQUALS(task.GetCullMode(), true, TEST_LOCATION);
1818
1819   task.SetCullMode(false);
1820
1821   DALI_TEST_EQUALS(task.GetCullMode(), false, TEST_LOCATION);
1822
1823   END_TEST;
1824 }
1825
1826 int UtcDaliRenderTaskSetCullModeN(void)
1827 {
1828   TestApplication application;
1829
1830   tet_infoline("Testing RenderTask::SetCullMode() on empty handle");
1831
1832   RenderTask task;
1833   try
1834   {
1835     task.SetCullMode(false);
1836   }
1837   catch(Dali::DaliException& e)
1838   {
1839     DALI_TEST_PRINT_ASSERT(e);
1840     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1841   }
1842   END_TEST;
1843 }
1844
1845 int UtcDaliRenderTaskGetCullModeP(void)
1846 {
1847   TestApplication application;
1848
1849   tet_infoline("Testing RenderTask::GetCullMode()");
1850
1851   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1852   RenderTask     task     = taskList.GetTask(0u);
1853   DALI_TEST_EQUALS(task.GetCullMode(), true, TEST_LOCATION);
1854   END_TEST;
1855 }
1856
1857 int UtcDaliRenderTaskGetCullModeN(void)
1858 {
1859   TestApplication application;
1860
1861   tet_infoline("Testing RenderTask::GetCullMode() with empty handle");
1862
1863   RenderTask task;
1864   try
1865   {
1866     bool x = task.GetCullMode();
1867     (void)x;
1868   }
1869   catch(Dali::DaliException& e)
1870   {
1871     DALI_TEST_PRINT_ASSERT(e);
1872     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1873   }
1874   END_TEST;
1875 }
1876
1877 int UtcDaliRenderTaskSetRefreshRate(void)
1878 {
1879   TestApplication application;
1880
1881   tet_infoline("Testing RenderTask::SetRefreshRate()");
1882
1883   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1884
1885   // By default tasks will be processed every frame
1886   RenderTask task = taskList.GetTask(0u);
1887   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == task.GetRefreshRate());
1888
1889   task.SetRefreshRate(2u); // every-other frame
1890   DALI_TEST_CHECK(2u == task.GetRefreshRate());
1891
1892   task.SetRefreshRate(RenderTask::REFRESH_ALWAYS);
1893   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == task.GetRefreshRate());
1894   END_TEST;
1895 }
1896
1897 int UtcDaliRenderTaskGetRefreshRate(void)
1898 {
1899   TestApplication application;
1900
1901   tet_infoline("Testing RenderTask::GetRefreshRate()");
1902
1903   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1904
1905   // By default tasks will be processed every frame
1906   RenderTask task = taskList.GetTask(0u);
1907   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == task.GetRefreshRate());
1908
1909   RenderTask newTask = taskList.CreateTask();
1910   DALI_TEST_CHECK(RenderTask::REFRESH_ALWAYS == newTask.GetRefreshRate());
1911   END_TEST;
1912 }
1913
1914 int UtcDaliRenderTaskSignalFinished(void)
1915 {
1916   TestApplication application;
1917
1918   tet_infoline("Testing RenderTask::SignalFinished()");
1919
1920   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1921   auto& sync = application.GetGraphicsSyncImpl();
1922
1923   CameraActor offscreenCameraActor = CameraActor::New();
1924
1925   application.GetScene().Add(offscreenCameraActor);
1926
1927   Texture image     = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 10, 10);
1928   Actor   rootActor = CreateRenderableActor(image);
1929   rootActor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1930   application.GetScene().Add(rootActor);
1931
1932   RenderTaskList          taskList           = application.GetScene().GetRenderTaskList();
1933   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
1934   Texture                 frameBufferTexture = Texture::New(*testNativeImagePtr);
1935   FrameBuffer             frameBuffer        = FrameBuffer::New(frameBufferTexture.GetWidth(), frameBufferTexture.GetHeight());
1936   frameBuffer.AttachColorTexture(frameBufferTexture);
1937
1938   RenderTask newTask = taskList.CreateTask();
1939   newTask.SetCameraActor(offscreenCameraActor);
1940   newTask.SetSourceActor(rootActor);
1941   newTask.SetInputEnabled(false);
1942   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
1943   newTask.SetClearEnabled(true);
1944   newTask.SetExclusive(true);
1945   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1946   newTask.SetFrameBuffer(frameBuffer);
1947   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, true);
1948
1949   bool               finished = false;
1950   RenderTaskFinished renderTaskFinished(finished);
1951   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
1952
1953   // Flush the queue and render.
1954   application.SendNotification();
1955
1956   // 1 render to process render task, then wait for sync before finished msg is sent
1957   // from update to the event thread.
1958
1959   application.Render();
1960   application.SendNotification();
1961   DALI_TEST_CHECK(!finished);
1962
1963   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1964   DALI_TEST_CHECK(lastSyncObj != NULL);
1965
1966   application.Render();
1967   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
1968   application.SendNotification();
1969   DALI_TEST_CHECK(!finished);
1970
1971   application.Render();
1972   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
1973   application.SendNotification();
1974   DALI_TEST_CHECK(!finished);
1975
1976   sync.SetObjectSynced(lastSyncObj, true);
1977
1978   application.Render();
1979   application.SendNotification();
1980   DALI_TEST_CHECK(!finished);
1981
1982   application.Render();
1983   application.SendNotification();
1984   DALI_TEST_CHECK(finished);
1985
1986   DALI_TEST_EQUALS(application.GetUpdateStatus(), 0, TEST_LOCATION);
1987   END_TEST;
1988 }
1989
1990 int UtcDaliRenderTaskContinuous01(void)
1991 {
1992   TestApplication application;
1993
1994   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not staged)\nPOST:continuous renders, no Finished signal");
1995
1996   // SETUP AN OFFSCREEN RENDER TASK
1997   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1998   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1999   drawTrace.Enable(true);
2000
2001   Actor rootActor = Actor::New();
2002   application.GetScene().Add(rootActor);
2003
2004   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2005   application.GetScene().Add(offscreenCameraActor);
2006
2007   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2008
2009   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2010   bool               finished = false;
2011   RenderTaskFinished renderTaskFinished(finished);
2012   application.SendNotification();
2013
2014   // START PROCESS/RENDER                     Input,    Expected  Input, Expected, KeepUpdating
2015   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, false, __LINE__));
2016   application.GetPlatform().ClearReadyResources();
2017
2018   // ADD SOURCE ACTOR TO STAGE - expect continuous renders to start, no finished signal
2019   application.GetScene().Add(secondRootActor);
2020   application.SendNotification();
2021
2022   // CONTINUE PROCESS/RENDER                  Input,    Expected  Input,    Expected
2023   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2024   END_TEST;
2025 }
2026
2027 int UtcDaliRenderTaskContinuous02(void)
2028 {
2029   TestApplication application;
2030
2031   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not visible)\nPOST:continuous renders, no Finished signal");
2032
2033   // SETUP AN OFFSCREEN RENDER TASK
2034   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2035   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2036   drawTrace.Enable(true);
2037
2038   Actor rootActor = Actor::New();
2039   application.GetScene().Add(rootActor);
2040
2041   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2042   application.GetScene().Add(offscreenCameraActor);
2043
2044   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2045   application.GetScene().Add(secondRootActor);
2046   secondRootActor.SetProperty(Actor::Property::VISIBLE, false);
2047
2048   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2049   bool               finished = false;
2050   RenderTaskFinished renderTaskFinished(finished);
2051   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2052   application.SendNotification();
2053
2054   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected, KeepUpdating
2055   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, false, __LINE__));
2056   application.GetPlatform().ClearReadyResources();
2057
2058   // MAKE SOURCE ACTOR VISIBLE - expect continuous renders to start, no finished signal
2059   secondRootActor.SetProperty(Actor::Property::VISIBLE, true);
2060   application.SendNotification();
2061
2062   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
2063   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2064   END_TEST;
2065 }
2066
2067 int UtcDaliRenderTaskContinuous03(void)
2068 {
2069   TestApplication application;
2070
2071   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (camera actor not staged)\nPOST:continuous renders, no Finished signal");
2072
2073   // SETUP AN OFFSCREEN RENDER TASK
2074   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2075   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2076   drawTrace.Enable(true);
2077
2078   Actor rootActor = Actor::New();
2079   application.GetScene().Add(rootActor);
2080
2081   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2082   Actor       secondRootActor      = CreateRenderableActorSuccess(application, "aFile.jpg");
2083   application.GetScene().Add(secondRootActor);
2084
2085   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2086   bool               finished = false;
2087   RenderTaskFinished renderTaskFinished(finished);
2088   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2089   application.SendNotification();
2090
2091   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2092   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, false, __LINE__));
2093   application.GetPlatform().ClearReadyResources();
2094
2095   // ADD CAMERA ACTOR TO STAGE - expect continuous renders to start, no finished signal
2096   application.GetScene().Add(offscreenCameraActor);
2097   application.SendNotification();
2098
2099   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
2100   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2101   END_TEST;
2102 }
2103
2104 int UtcDaliRenderTaskContinuous04(void)
2105 {
2106   TestApplication application;
2107
2108   tet_infoline("Testing RenderTask Render Continuous using loaded image");
2109
2110   // SETUP AN OFFSCREEN RENDER TASK
2111   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2112   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2113   drawTrace.Enable(true);
2114
2115   Actor rootActor = Actor::New();
2116   application.GetScene().Add(rootActor);
2117
2118   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2119   application.GetScene().Add(offscreenCameraActor);
2120   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2121   application.GetScene().Add(secondRootActor);
2122
2123   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2124   bool               finished = false;
2125   RenderTaskFinished renderTaskFinished(finished);
2126   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2127   application.SendNotification();
2128
2129   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2130   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2131   END_TEST;
2132 }
2133
2134 int UtcDaliRenderTaskOnce01(void)
2135 {
2136   TestApplication application;
2137
2138   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image");
2139
2140   // SETUP AN OFFSCREEN RENDER TASK
2141   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2142   auto&           sync      = application.GetGraphicsSyncImpl();
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   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2152
2153   application.GetScene().Add(secondRootActor);
2154
2155   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2156   bool               finished = false;
2157   RenderTaskFinished renderTaskFinished(finished);
2158   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2159   application.SendNotification();
2160
2161   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2162
2163   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2164   DALI_TEST_CHECK(lastSyncObj != NULL);
2165   sync.SetObjectSynced(lastSyncObj, true);
2166
2167   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2168   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2169   END_TEST;
2170 }
2171
2172 int UtcDaliRenderTaskOnce02(void)
2173 {
2174   TestApplication application;
2175
2176   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n");
2177
2178   // SETUP AN OFFSCREEN RENDER TASK
2179   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2180   auto&           sync      = application.GetGraphicsSyncImpl();
2181   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2182   drawTrace.Enable(true);
2183
2184   Actor rootActor = Actor::New();
2185   application.GetScene().Add(rootActor);
2186
2187   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2188   application.GetScene().Add(offscreenCameraActor);
2189
2190   Shader     shader     = CreateShader();
2191   Texture    image      = CreateTexture();
2192   TextureSet textureSet = CreateTextureSet(image);
2193
2194   Geometry geometry = CreateQuadGeometry();
2195   Renderer renderer = Renderer::New(geometry, shader);
2196   renderer.SetTextures(textureSet);
2197   Actor secondRootActor = Actor::New();
2198   secondRootActor.AddRenderer(renderer);
2199   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2200   application.GetScene().Add(secondRootActor);
2201
2202   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2203   bool               finished = false;
2204   RenderTaskFinished renderTaskFinished(finished);
2205   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2206   application.SendNotification();
2207
2208   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2209
2210   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2211   DALI_TEST_CHECK(lastSyncObj != NULL);
2212   sync.SetObjectSynced(lastSyncObj, true);
2213
2214   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2215   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2216
2217   END_TEST;
2218 }
2219
2220 int UtcDaliRenderTaskOnce03(void)
2221 {
2222   TestApplication application;
2223
2224   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image. Switch from render always after ready to render once\n");
2225
2226   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2227   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2228   auto&           sync      = application.GetGraphicsSyncImpl();
2229   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2230   drawTrace.Enable(true);
2231
2232   Actor rootActor = Actor::New();
2233   application.GetScene().Add(rootActor);
2234
2235   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2236   application.GetScene().Add(offscreenCameraActor);
2237   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2238   application.GetScene().Add(secondRootActor);
2239
2240   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2241   bool               finished = false;
2242   RenderTaskFinished renderTaskFinished(finished);
2243   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2244   application.SendNotification();
2245
2246   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2247
2248   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2249   application.SendNotification();
2250   //                                                   drawn   sig    finished  Keep updating
2251   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2252
2253   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2254   DALI_TEST_CHECK(lastSyncObj != NULL);
2255   sync.SetObjectSynced(lastSyncObj, true);
2256
2257   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2258   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2259
2260   END_TEST;
2261 }
2262
2263 int UtcDaliRenderTaskOnce04(void)
2264 {
2265   TestApplication application;
2266   tet_infoline(
2267     "Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n"
2268     "Switch from render always after ready to render once\n");
2269
2270   // SETUP AN OFFSCREEN RENDER TASK
2271   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2272   auto&           sync      = application.GetGraphicsSyncImpl();
2273   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2274   drawTrace.Enable(true);
2275
2276   Actor rootActor = Actor::New();
2277   application.GetScene().Add(rootActor);
2278
2279   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2280   application.GetScene().Add(offscreenCameraActor);
2281
2282   Shader     shader     = CreateShader();
2283   Texture    image      = CreateTexture();
2284   TextureSet textureSet = CreateTextureSet(image);
2285
2286   Geometry geometry = CreateQuadGeometry();
2287   Renderer renderer = Renderer::New(geometry, shader);
2288   renderer.SetTextures(textureSet);
2289   Actor secondRootActor = Actor::New();
2290   secondRootActor.AddRenderer(renderer);
2291   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2292   application.GetScene().Add(secondRootActor);
2293
2294   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2295   bool               finished = false;
2296   RenderTaskFinished renderTaskFinished(finished);
2297   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2298   application.SendNotification();
2299
2300   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2301
2302   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2303   application.SendNotification();
2304   //   FAILS                                          drawn   sig    finished  Keep updating
2305   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2306
2307   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2308   DALI_TEST_CHECK(lastSyncObj != NULL);
2309   sync.SetObjectSynced(lastSyncObj, true);
2310
2311   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, false, true, __LINE__));
2312   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2313
2314   END_TEST;
2315 }
2316
2317 int UtcDaliRenderTaskOnceNoSync01(void)
2318 {
2319   TestApplication application;
2320
2321   tet_infoline("Testing RenderTask Render Once, \nPRE: Resources ready\nPOST: Finished signal sent once only");
2322
2323   // SETUP AN OFFSCREEN RENDER TASK
2324   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2325   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2326   drawTrace.Enable(true);
2327
2328   Actor rootActor = Actor::New();
2329   application.GetScene().Add(rootActor);
2330
2331   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2332   application.GetScene().Add(offscreenCameraActor);
2333   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2334   application.GetScene().Add(secondRootActor);
2335
2336   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2337   bool               finished = false;
2338   RenderTaskFinished renderTaskFinished(finished);
2339   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2340   application.SendNotification();
2341
2342   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2343   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2344   END_TEST;
2345 }
2346
2347 int UtcDaliRenderTaskOnceNoSync02(void)
2348 {
2349   TestApplication application;
2350
2351   tet_infoline(
2352     "Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loaded image.\n"
2353     "PRE: Resources ready\nPOST: Finished signal sent once only");
2354   // SETUP AN OFFSCREEN RENDER TASK
2355   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2356   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2357   drawTrace.Enable(true);
2358
2359   Actor rootActor = Actor::New();
2360   application.GetScene().Add(rootActor);
2361
2362   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2363   application.GetScene().Add(offscreenCameraActor);
2364
2365   Shader     shader     = CreateShader();
2366   Texture    image      = CreateTexture();
2367   TextureSet textureSet = CreateTextureSet(image);
2368
2369   Geometry geometry = CreateQuadGeometry();
2370   Renderer renderer = Renderer::New(geometry, shader);
2371   renderer.SetTextures(textureSet);
2372   Actor secondRootActor = Actor::New();
2373   secondRootActor.AddRenderer(renderer);
2374   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2375   application.GetScene().Add(secondRootActor);
2376
2377   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2378   bool               finished = false;
2379   RenderTaskFinished renderTaskFinished(finished);
2380   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2381   application.SendNotification();
2382
2383   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2384   application.GetPlatform().ClearReadyResources();
2385   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2386
2387   END_TEST;
2388 }
2389
2390 int UtcDaliRenderTaskOnceNoSync03(void)
2391 {
2392   TestApplication application;
2393
2394   tet_infoline(
2395     "Testing RenderTask Render Once, using loaded image. Switch from render always after ready to render once\n"
2396     "PRE: Render task ready, Image loaded\n"
2397     "POST: Finished signal sent only once");
2398
2399   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2400   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2401   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2402   drawTrace.Enable(true);
2403
2404   Actor rootActor = Actor::New();
2405   application.GetScene().Add(rootActor);
2406
2407   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2408   application.GetScene().Add(offscreenCameraActor);
2409   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2410   application.GetScene().Add(secondRootActor);
2411
2412   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2413   bool               finished = false;
2414   RenderTaskFinished renderTaskFinished(finished);
2415   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2416   application.SendNotification();
2417
2418   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2419
2420   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2421   application.SendNotification(); //         Input,    Expected  Input,    Expected
2422   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2423   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2424   END_TEST;
2425 }
2426
2427 int UtcDaliRenderTaskOnceNoSync04(void)
2428 {
2429   TestApplication application;
2430
2431   tet_infoline(
2432     "Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2433     "Switch from render always after ready to render once\n"
2434     "PRE: Render task ready, Image not loaded\n"
2435     "POST: Finished signal sent only once");
2436
2437   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2438   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2439   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2440   drawTrace.Enable(true);
2441
2442   Actor rootActor = Actor::New();
2443   application.GetScene().Add(rootActor);
2444
2445   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2446   application.GetScene().Add(offscreenCameraActor);
2447
2448   Shader     shader     = CreateShader();
2449   Texture    image      = CreateTexture();
2450   TextureSet textureSet = CreateTextureSet(image);
2451
2452   Geometry geometry = CreateQuadGeometry();
2453   Renderer renderer = Renderer::New(geometry, shader);
2454   renderer.SetTextures(textureSet);
2455   Actor secondRootActor = Actor::New();
2456   secondRootActor.AddRenderer(renderer);
2457   secondRootActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2458   application.GetScene().Add(secondRootActor);
2459
2460   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2461   bool               finished = false;
2462   RenderTaskFinished renderTaskFinished(finished);
2463   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2464   application.SendNotification();
2465
2466   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2467   auto&                                             sync        = application.GetGraphicsSyncImpl();
2468   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2469   DALI_TEST_CHECK(lastSyncObj == NULL);
2470
2471   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2472   application.SendNotification(); //         Input,    Expected  Input,    Expected
2473   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
2474   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, finished, true, false, __LINE__));
2475
2476   lastSyncObj = sync.GetLastSyncObject();
2477   DALI_TEST_CHECK(lastSyncObj == NULL);
2478
2479   END_TEST;
2480 }
2481
2482 int UtcDaliRenderTaskOnceNoSync05(void)
2483 {
2484   TestApplication application;
2485
2486   tet_infoline(
2487     "Testing RenderTask Render Once\n"
2488     "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
2489     "PRE: resources failed to load\n"
2490     "POST: No finished signal sent.");
2491
2492   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2493   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2494   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2495   drawTrace.Enable(true);
2496
2497   Actor rootActor = Actor::New();
2498   application.GetScene().Add(rootActor);
2499
2500   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2501   application.GetScene().Add(offscreenCameraActor);
2502   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2503   application.GetScene().Add(secondRootActor);
2504
2505   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2506   bool               finished = false;
2507   RenderTaskFinished renderTaskFinished(finished);
2508   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2509   application.SendNotification();
2510
2511   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
2512   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2513
2514   // CHANGE TO RENDER ONCE,
2515   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2516   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, false, __LINE__));
2517
2518   END_TEST;
2519 }
2520
2521 int UtcDaliRenderTaskOnceChain01(void)
2522 {
2523   TestApplication application;
2524
2525   tet_infoline(
2526     "Testing RenderTask Render Once Chained render tasks\n"
2527     "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
2528     "PRE: resources ready\n"
2529     "POST: 2 finished signals sent.");
2530
2531   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2532   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2533   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2534   drawTrace.Enable(true);
2535
2536   Actor defaultRootActor = Actor::New(); // Root for default RT
2537   application.GetScene().Add(defaultRootActor);
2538
2539   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2540   application.GetScene().Add(offscreenCameraActor);
2541   Actor firstRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2542   application.GetScene().Add(firstRootActor);
2543
2544   // first render task
2545   RenderTask         firstTask     = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
2546   bool               firstFinished = false;
2547   RenderTaskFinished renderTask1Finished(firstFinished);
2548   firstTask.FinishedSignal().Connect(&application, renderTask1Finished);
2549
2550   // Second render task
2551   FrameBuffer fbo             = firstTask.GetFrameBuffer();
2552   Actor       secondRootActor = CreateRenderableActor(fbo.GetColorTexture());
2553   application.GetScene().Add(secondRootActor);
2554   RenderTask         secondTask     = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2555   bool               secondFinished = false;
2556   RenderTaskFinished renderTask2Finished(secondFinished);
2557   secondTask.FinishedSignal().Connect(&application, renderTask2Finished);
2558
2559   application.SendNotification();
2560
2561   // Both render tasks are executed.
2562   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, firstFinished, false, true, __LINE__));
2563   DALI_TEST_CHECK(firstFinished == false);
2564   DALI_TEST_CHECK(secondFinished == false);
2565
2566   // Nothing else to render and both render task should have finished now
2567   DALI_TEST_CHECK(UpdateRender(application, drawTrace, false, firstFinished, true, false, __LINE__));
2568   DALI_TEST_CHECK(firstFinished == true);
2569   DALI_TEST_CHECK(secondFinished == true);
2570
2571   END_TEST;
2572 }
2573
2574 int UtcDaliRenderTaskProperties(void)
2575 {
2576   TestApplication application;
2577
2578   RenderTask task = application.GetScene().GetRenderTaskList().CreateTask();
2579
2580   Property::IndexContainer indices;
2581   task.GetPropertyIndices(indices);
2582   DALI_TEST_CHECK(indices.Size());
2583   DALI_TEST_EQUALS(indices.Size(), task.GetPropertyCount(), TEST_LOCATION);
2584   END_TEST;
2585 }
2586
2587 int UtcDaliRenderTaskFinishInvisibleSourceActor(void)
2588 {
2589   TestApplication application;
2590
2591   tet_infoline("Testing RenderTask::FinishInvisibleSourceActor()");
2592
2593   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2594   auto& sync = application.GetGraphicsSyncImpl();
2595
2596   CameraActor offscreenCameraActor = CameraActor::New();
2597
2598   application.GetScene().Add(offscreenCameraActor);
2599
2600   Texture image     = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 10, 10);
2601   Actor   rootActor = CreateRenderableActor(image);
2602   rootActor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
2603   rootActor.SetProperty(Actor::Property::VISIBLE, false);
2604   application.GetScene().Add(rootActor);
2605
2606   RenderTaskList          taskList           = application.GetScene().GetRenderTaskList();
2607   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
2608   Texture                 frameBufferTexture = Texture::New(*testNativeImagePtr);
2609   FrameBuffer             frameBuffer        = FrameBuffer::New(frameBufferTexture.GetWidth(), frameBufferTexture.GetHeight());
2610   frameBuffer.AttachColorTexture(frameBufferTexture);
2611
2612   // Flush all outstanding messages
2613   application.SendNotification();
2614   application.Render();
2615
2616   RenderTask newTask = taskList.CreateTask();
2617   newTask.SetCameraActor(offscreenCameraActor);
2618   newTask.SetSourceActor(rootActor);
2619   newTask.SetInputEnabled(false);
2620   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
2621   newTask.SetClearEnabled(true);
2622   newTask.SetExclusive(true);
2623   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2624   newTask.SetFrameBuffer(frameBuffer);
2625   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, true);
2626
2627   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
2628
2629   bool               finished = false;
2630   RenderTaskFinished renderTaskFinished(finished);
2631   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2632
2633   // Flush the queue and render.
2634   application.SendNotification();
2635
2636   // 1 render to process render task, then wait for sync before finished msg is sent
2637   // from update to the event thread.
2638
2639   application.Render();
2640   application.SendNotification();
2641   DALI_TEST_CHECK(!finished);
2642
2643   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2644   DALI_TEST_CHECK(lastSyncObj != NULL);
2645
2646   application.Render();
2647   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
2648   application.SendNotification();
2649   DALI_TEST_CHECK(!finished);
2650
2651   application.Render();
2652   DALI_TEST_EQUALS((Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION);
2653   application.SendNotification();
2654   DALI_TEST_CHECK(!finished);
2655
2656   sync.SetObjectSynced(lastSyncObj, true);
2657
2658   application.Render();
2659   application.SendNotification();
2660   DALI_TEST_CHECK(!finished);
2661
2662   application.Render();
2663   application.SendNotification();
2664   DALI_TEST_CHECK(finished);
2665   finished = false;
2666
2667   application.Render(); // Double check no more finished signal
2668   application.SendNotification();
2669   DALI_TEST_CHECK(!finished);
2670
2671   END_TEST;
2672 }
2673
2674 int UtcDaliRenderTaskFinishMissingImage(void)
2675 {
2676   TestApplication application;
2677
2678   // Previously we had bugs where not having a resource ID would cause render-tasks to wait forever
2679   tet_infoline("Testing RenderTask::SignalFinished() when an Actor has no Image set");
2680
2681   Integration::Scene stage = application.GetScene();
2682
2683   Texture image     = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 10, 10);
2684   Actor   rootActor = CreateRenderableActor(image);
2685   rootActor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
2686   stage.Add(rootActor);
2687
2688   Actor actorWithMissingImage = CreateRenderableActor(Texture());
2689   actorWithMissingImage.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
2690   stage.Add(actorWithMissingImage);
2691
2692   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2693   RenderTask     newTask  = taskList.CreateTask();
2694   newTask.SetInputEnabled(false);
2695   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
2696   newTask.SetClearEnabled(true);
2697   newTask.SetExclusive(true);
2698   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2699
2700   bool               finished = false;
2701   RenderTaskFinished renderTaskFinished(finished);
2702   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
2703
2704   // 1 render to process render task, then 1 before finished msg is sent from update to the event thread.
2705   application.SendNotification();
2706   application.Render();
2707   application.Render();
2708
2709   application.SendNotification();
2710   DALI_TEST_CHECK(finished);
2711
2712   END_TEST;
2713 }
2714
2715 int UtcDaliRenderTaskWorldToViewport(void)
2716 {
2717   TestApplication application(400u, 400u); // square surface
2718
2719   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2720
2721   Actor actor = Actor::New();
2722   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2723   actor.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 0.0));
2724
2725   actor.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5, 0.5, 0.5));
2726   actor.SetProperty(Actor::Property::ANCHOR_POINT, Vector3(0.5, 0.5, 0.5));
2727
2728   application.GetScene().Add(actor);
2729
2730   application.SendNotification();
2731   application.Render();
2732   application.SendNotification();
2733
2734   RenderTask task = taskList.GetTask(0u);
2735
2736   CameraActor camera = task.GetCameraActor();
2737
2738   Vector2 screenSize = task.GetCurrentViewportSize();
2739
2740   float screenX = 0.0;
2741   float screenY = 0.0;
2742
2743   bool ok = task.WorldToViewport(actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION), screenX, screenY);
2744   DALI_TEST_CHECK(ok == true);
2745
2746   DALI_TEST_EQUALS(screenX, screenSize.x / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2747   DALI_TEST_EQUALS(screenY, screenSize.y / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2748
2749   Actor actor2     = Actor::New();
2750   float actor2Size = 100.f;
2751   actor2.SetProperty(Actor::Property::SIZE, Vector2(actor2Size, actor2Size));
2752   actor2.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 0.0));
2753   actor2.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5, 0.5, 0.0));
2754   actor2.SetProperty(Actor::Property::ANCHOR_POINT, Vector3(0.5, 0.5, 0.0));
2755   application.GetScene().Add(actor2);
2756   actor2.Add(actor);
2757   actor.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0, 0, 0));
2758
2759   application.SendNotification();
2760   application.Render();
2761   application.SendNotification();
2762
2763   ok = task.WorldToViewport(actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION), screenX, screenY);
2764   DALI_TEST_CHECK(ok == true);
2765
2766   DALI_TEST_EQUALS(screenX, screenSize.x / 2 - actor2Size / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2767   DALI_TEST_EQUALS(screenY, screenSize.y / 2 - actor2Size / 2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2768
2769   END_TEST;
2770 }
2771
2772 int UtcDaliRenderTaskViewportToLocal(void)
2773 {
2774   TestApplication application;
2775   Actor           actor = Actor::New();
2776   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2777   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2778   actor.SetProperty(Actor::Property::POSITION, Vector2(10.0f, 10.0f));
2779   application.GetScene().Add(actor);
2780
2781   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2782   RenderTask     task     = taskList.GetTask(0u);
2783
2784   // flush the queue and render once
2785   application.SendNotification();
2786   application.Render();
2787   application.SendNotification();
2788   application.Render();
2789
2790   float localX;
2791   float localY;
2792
2793   float rtLocalX;
2794   float rtLocalY;
2795
2796   float screenX = 50.0f;
2797   float screenY = 50.0f;
2798
2799   DALI_TEST_CHECK(actor.ScreenToLocal(localX, localY, screenX, screenY));
2800
2801   DALI_TEST_CHECK(task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY));
2802
2803   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
2804   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
2805
2806   END_TEST;
2807 }
2808
2809 int UtcDaliRenderTaskOffscreenViewportToLocal(void)
2810 {
2811   TestApplication application;
2812   Actor           actor = Actor::New();
2813   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2814   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2815   actor.SetProperty(Actor::Property::POSITION, Vector2(10.0f, 10.0f));
2816   application.GetScene().Add(actor);
2817
2818   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2819   RenderTask     task     = taskList.CreateTask();
2820
2821   FrameBuffer newFrameBuffer = FrameBuffer::New(10, 10);
2822   task.SetFrameBuffer(newFrameBuffer);
2823   task.SetSourceActor(actor);
2824   task.SetScreenToFrameBufferMappingActor(actor);
2825
2826   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2827   application.GetScene().Add(offscreenCameraActor);
2828   task.SetCameraActor(offscreenCameraActor);
2829
2830   // flush the queue and render once
2831   application.SendNotification();
2832   application.Render();
2833   application.SendNotification();
2834   application.Render();
2835
2836   float localX;
2837   float localY;
2838
2839   float rtLocalX;
2840   float rtLocalY;
2841
2842   float screenX = 50.0f;
2843   float screenY = 50.0f;
2844
2845   DALI_TEST_CHECK(actor.ScreenToLocal(localX, localY, screenX, screenY));
2846
2847   DALI_TEST_CHECK(task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY));
2848
2849   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
2850   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
2851
2852   END_TEST;
2853 }
2854
2855 int UtcDaliRenderTaskRequiresSync(void)
2856 {
2857   TestApplication application;
2858   RenderTaskList  taskList = application.GetScene().GetRenderTaskList();
2859
2860   RenderTask newTask = taskList.CreateTask();
2861   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, false);
2862
2863   DALI_TEST_EQUALS(newTask.GetProperty<bool>(RenderTask::Property::REQUIRES_SYNC), false, TEST_LOCATION);
2864   DALI_TEST_EQUALS(newTask.GetCurrentProperty<bool>(RenderTask::Property::REQUIRES_SYNC), false, TEST_LOCATION);
2865
2866   newTask.SetProperty(RenderTask::Property::REQUIRES_SYNC, true);
2867
2868   DALI_TEST_EQUALS(newTask.GetProperty<bool>(RenderTask::Property::REQUIRES_SYNC), true, TEST_LOCATION);
2869   DALI_TEST_EQUALS(newTask.GetCurrentProperty<bool>(RenderTask::Property::REQUIRES_SYNC), true, TEST_LOCATION);
2870
2871   END_TEST;
2872 }
2873
2874 int UtcDaliRenderTaskSetClearEnabled(void)
2875 {
2876   TestApplication application;
2877
2878   tet_infoline("UtcDaliRenderTaskSetClearEnabled");
2879
2880   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
2881   TestGlAbstraction& gl = application.GetGlAbstraction();
2882
2883   Actor renderableActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2884   application.GetScene().Add(renderableActor);
2885
2886   Actor rootActor = Actor::New();
2887   application.GetScene().Add(rootActor);
2888
2889   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
2890   application.GetScene().Add(offscreenCameraActor);
2891
2892   Actor sourceActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2893   application.GetScene().Add(sourceActor);
2894
2895   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, sourceActor, RenderTask::REFRESH_ALWAYS, false);
2896
2897   DALI_TEST_EQUALS(gl.GetClearCountCalled(), 0, TEST_LOCATION);
2898
2899   application.SendNotification();
2900   application.Render();
2901
2902   // glClear should be called twice - default task and the new task.
2903   DALI_TEST_EQUALS(gl.GetClearCountCalled(), 2, TEST_LOCATION);
2904
2905   newTask.SetClearEnabled(false);
2906
2907   application.SendNotification();
2908   application.Render();
2909
2910   // The count should increase by 1 - default task only.
2911   DALI_TEST_EQUALS(gl.GetClearCountCalled(), 3, TEST_LOCATION);
2912
2913   END_TEST;
2914 }
2915
2916 int UtcDaliRenderTaskMoveConstrctor(void)
2917 {
2918   TestApplication application;
2919
2920   Vector4 testColor(1.0f, 2.0f, 3.0f, 4.0f);
2921
2922   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2923   RenderTask     task     = taskList.GetTask(0u);
2924   DALI_TEST_CHECK(task);
2925   DALI_TEST_EQUALS(2, task.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2926   DALI_TEST_CHECK(task.GetClearColor() != testColor);
2927
2928   task.SetClearColor(testColor);
2929
2930   // Wait a frame.
2931   Wait(application);
2932
2933   DALI_TEST_EQUALS(task.GetClearColor(), testColor, TEST_LOCATION);
2934
2935   RenderTask move = std::move(task);
2936   DALI_TEST_CHECK(move);
2937   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2938   DALI_TEST_EQUALS(move.GetClearColor(), testColor, TEST_LOCATION);
2939   DALI_TEST_CHECK(!task);
2940
2941   END_TEST;
2942 }
2943
2944 int UtcDaliRenderTaskMoveAssignment(void)
2945 {
2946   TestApplication application;
2947
2948   Vector4 testColor(1.0f, 2.0f, 3.0f, 4.0f);
2949
2950   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
2951   RenderTask     task     = taskList.GetTask(0u);
2952   DALI_TEST_CHECK(task);
2953   DALI_TEST_EQUALS(2, task.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2954   DALI_TEST_CHECK(task.GetClearColor() != testColor);
2955
2956   task.SetClearColor(testColor);
2957
2958   // Wait a frame.
2959   Wait(application);
2960
2961   DALI_TEST_EQUALS(task.GetClearColor(), testColor, TEST_LOCATION);
2962
2963   RenderTask move;
2964   move = std::move(task);
2965   DALI_TEST_CHECK(move);
2966   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
2967   DALI_TEST_EQUALS(move.GetClearColor(), testColor, TEST_LOCATION);
2968   DALI_TEST_CHECK(!task);
2969
2970   END_TEST;
2971 }
2972
2973 int UtcDaliRenderTaskSetCullModeNegative(void)
2974 {
2975   TestApplication  application;
2976   Dali::RenderTask instance;
2977   try
2978   {
2979     bool arg1(false);
2980     instance.SetCullMode(arg1);
2981     DALI_TEST_CHECK(false); // Should not get here
2982   }
2983   catch(...)
2984   {
2985     DALI_TEST_CHECK(true); // We expect an assert
2986   }
2987   END_TEST;
2988 }
2989
2990 int UtcDaliRenderTaskSetViewportNegative(void)
2991 {
2992   TestApplication  application;
2993   Dali::RenderTask instance;
2994   try
2995   {
2996     Dali::Rect<int> arg1;
2997     instance.SetViewport(arg1);
2998     DALI_TEST_CHECK(false); // Should not get here
2999   }
3000   catch(...)
3001   {
3002     DALI_TEST_CHECK(true); // We expect an assert
3003   }
3004   END_TEST;
3005 }
3006
3007 int UtcDaliRenderTaskSetExclusiveNegative(void)
3008 {
3009   TestApplication  application;
3010   Dali::RenderTask instance;
3011   try
3012   {
3013     bool arg1(false);
3014     instance.SetExclusive(arg1);
3015     DALI_TEST_CHECK(false); // Should not get here
3016   }
3017   catch(...)
3018   {
3019     DALI_TEST_CHECK(true); // We expect an assert
3020   }
3021   END_TEST;
3022 }
3023
3024 int UtcDaliRenderTaskSetClearColorNegative(void)
3025 {
3026   TestApplication  application;
3027   Dali::RenderTask instance;
3028   try
3029   {
3030     Dali::Vector4 arg1;
3031     instance.SetClearColor(arg1);
3032     DALI_TEST_CHECK(false); // Should not get here
3033   }
3034   catch(...)
3035   {
3036     DALI_TEST_CHECK(true); // We expect an assert
3037   }
3038   END_TEST;
3039 }
3040
3041 int UtcDaliRenderTaskFinishedSignalNegative(void)
3042 {
3043   TestApplication  application;
3044   Dali::RenderTask instance;
3045   try
3046   {
3047     instance.FinishedSignal();
3048     DALI_TEST_CHECK(false); // Should not get here
3049   }
3050   catch(...)
3051   {
3052     DALI_TEST_CHECK(true); // We expect an assert
3053   }
3054   END_TEST;
3055 }
3056
3057 int UtcDaliRenderTaskSetCameraActorNegative(void)
3058 {
3059   TestApplication  application;
3060   Dali::RenderTask instance;
3061   try
3062   {
3063     Dali::CameraActor arg1;
3064     instance.SetCameraActor(arg1);
3065     DALI_TEST_CHECK(false); // Should not get here
3066   }
3067   catch(...)
3068   {
3069     DALI_TEST_CHECK(true); // We expect an assert
3070   }
3071   END_TEST;
3072 }
3073
3074 int UtcDaliRenderTaskSetFrameBufferNegative(void)
3075 {
3076   TestApplication  application;
3077   Dali::RenderTask instance;
3078   try
3079   {
3080     Dali::FrameBuffer arg1;
3081     instance.SetFrameBuffer(arg1);
3082     DALI_TEST_CHECK(false); // Should not get here
3083   }
3084   catch(...)
3085   {
3086     DALI_TEST_CHECK(true); // We expect an assert
3087   }
3088   END_TEST;
3089 }
3090
3091 int UtcDaliRenderTaskSetRefreshRateNegative(void)
3092 {
3093   TestApplication  application;
3094   Dali::RenderTask instance;
3095   try
3096   {
3097     unsigned int arg1(0u);
3098     instance.SetRefreshRate(arg1);
3099     DALI_TEST_CHECK(false); // Should not get here
3100   }
3101   catch(...)
3102   {
3103     DALI_TEST_CHECK(true); // We expect an assert
3104   }
3105   END_TEST;
3106 }
3107
3108 int UtcDaliRenderTaskSetSourceActorNegative(void)
3109 {
3110   TestApplication  application;
3111   Dali::RenderTask instance;
3112   try
3113   {
3114     Dali::Actor arg1;
3115     instance.SetSourceActor(arg1);
3116     DALI_TEST_CHECK(false); // Should not get here
3117   }
3118   catch(...)
3119   {
3120     DALI_TEST_CHECK(true); // We expect an assert
3121   }
3122   END_TEST;
3123 }
3124
3125 int UtcDaliRenderTaskSetClearEnabledNegative(void)
3126 {
3127   TestApplication  application;
3128   Dali::RenderTask instance;
3129   try
3130   {
3131     bool arg1(false);
3132     instance.SetClearEnabled(arg1);
3133     DALI_TEST_CHECK(false); // Should not get here
3134   }
3135   catch(...)
3136   {
3137     DALI_TEST_CHECK(true); // We expect an assert
3138   }
3139   END_TEST;
3140 }
3141
3142 int UtcDaliRenderTaskSetInputEnabledNegative(void)
3143 {
3144   TestApplication  application;
3145   Dali::RenderTask instance;
3146   try
3147   {
3148     bool arg1(false);
3149     instance.SetInputEnabled(arg1);
3150     DALI_TEST_CHECK(false); // Should not get here
3151   }
3152   catch(...)
3153   {
3154     DALI_TEST_CHECK(true); // We expect an assert
3155   }
3156   END_TEST;
3157 }
3158
3159 int UtcDaliRenderTaskSetViewportSizeNegative(void)
3160 {
3161   TestApplication  application;
3162   Dali::RenderTask instance;
3163   try
3164   {
3165     Dali::Vector2 arg1;
3166     instance.SetViewportSize(arg1);
3167     DALI_TEST_CHECK(false); // Should not get here
3168   }
3169   catch(...)
3170   {
3171     DALI_TEST_CHECK(true); // We expect an assert
3172   }
3173   END_TEST;
3174 }
3175
3176 int UtcDaliRenderTaskSetViewportPositionNegative(void)
3177 {
3178   TestApplication  application;
3179   Dali::RenderTask instance;
3180   try
3181   {
3182     Dali::Vector2 arg1;
3183     instance.SetViewportPosition(arg1);
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 UtcDaliRenderTaskSetScreenToFrameBufferFunctionNegative(void)
3194 {
3195   TestApplication  application;
3196   Dali::RenderTask instance;
3197   try
3198   {
3199     RenderTask::ScreenToFrameBufferFunction arg1(nullptr);
3200     instance.SetScreenToFrameBufferFunction(arg1);
3201     DALI_TEST_CHECK(false); // Should not get here
3202   }
3203   catch(...)
3204   {
3205     DALI_TEST_CHECK(true); // We expect an assert
3206   }
3207   END_TEST;
3208 }
3209
3210 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActorNegative(void)
3211 {
3212   TestApplication  application;
3213   Dali::RenderTask instance;
3214   try
3215   {
3216     Dali::Actor arg1;
3217     instance.SetScreenToFrameBufferMappingActor(arg1);
3218     DALI_TEST_CHECK(false); // Should not get here
3219   }
3220   catch(...)
3221   {
3222     DALI_TEST_CHECK(true); // We expect an assert
3223   }
3224   END_TEST;
3225 }
3226
3227 int UtcDaliRenderTaskGetCullModeNegative(void)
3228 {
3229   TestApplication  application;
3230   Dali::RenderTask instance;
3231   try
3232   {
3233     instance.GetCullMode();
3234     DALI_TEST_CHECK(false); // Should not get here
3235   }
3236   catch(...)
3237   {
3238     DALI_TEST_CHECK(true); // We expect an assert
3239   }
3240   END_TEST;
3241 }
3242
3243 int UtcDaliRenderTaskGetViewportNegative(void)
3244 {
3245   TestApplication  application;
3246   Dali::RenderTask instance;
3247   try
3248   {
3249     instance.GetViewport();
3250     DALI_TEST_CHECK(false); // Should not get here
3251   }
3252   catch(...)
3253   {
3254     DALI_TEST_CHECK(true); // We expect an assert
3255   }
3256   END_TEST;
3257 }
3258
3259 int UtcDaliRenderTaskIsExclusiveNegative(void)
3260 {
3261   TestApplication  application;
3262   Dali::RenderTask instance;
3263   try
3264   {
3265     instance.IsExclusive();
3266     DALI_TEST_CHECK(false); // Should not get here
3267   }
3268   catch(...)
3269   {
3270     DALI_TEST_CHECK(true); // We expect an assert
3271   }
3272   END_TEST;
3273 }
3274
3275 int UtcDaliRenderTaskGetClearColorNegative(void)
3276 {
3277   TestApplication  application;
3278   Dali::RenderTask instance;
3279   try
3280   {
3281     instance.GetClearColor();
3282     DALI_TEST_CHECK(false); // Should not get here
3283   }
3284   catch(...)
3285   {
3286     DALI_TEST_CHECK(true); // We expect an assert
3287   }
3288   END_TEST;
3289 }
3290
3291 int UtcDaliRenderTaskGetCameraActorNegative(void)
3292 {
3293   TestApplication  application;
3294   Dali::RenderTask instance;
3295   try
3296   {
3297     instance.GetCameraActor();
3298     DALI_TEST_CHECK(false); // Should not get here
3299   }
3300   catch(...)
3301   {
3302     DALI_TEST_CHECK(true); // We expect an assert
3303   }
3304   END_TEST;
3305 }
3306
3307 int UtcDaliRenderTaskGetFrameBufferNegative(void)
3308 {
3309   TestApplication  application;
3310   Dali::RenderTask instance;
3311   try
3312   {
3313     instance.GetFrameBuffer();
3314     DALI_TEST_CHECK(false); // Should not get here
3315   }
3316   catch(...)
3317   {
3318     DALI_TEST_CHECK(true); // We expect an assert
3319   }
3320   END_TEST;
3321 }
3322
3323 int UtcDaliRenderTaskGetRefreshRateNegative(void)
3324 {
3325   TestApplication  application;
3326   Dali::RenderTask instance;
3327   try
3328   {
3329     instance.GetRefreshRate();
3330     DALI_TEST_CHECK(false); // Should not get here
3331   }
3332   catch(...)
3333   {
3334     DALI_TEST_CHECK(true); // We expect an assert
3335   }
3336   END_TEST;
3337 }
3338
3339 int UtcDaliRenderTaskGetSourceActorNegative(void)
3340 {
3341   TestApplication  application;
3342   Dali::RenderTask instance;
3343   try
3344   {
3345     instance.GetSourceActor();
3346     DALI_TEST_CHECK(false); // Should not get here
3347   }
3348   catch(...)
3349   {
3350     DALI_TEST_CHECK(true); // We expect an assert
3351   }
3352   END_TEST;
3353 }
3354
3355 int UtcDaliRenderTaskGetClearEnabledNegative(void)
3356 {
3357   TestApplication  application;
3358   Dali::RenderTask instance;
3359   try
3360   {
3361     instance.GetClearEnabled();
3362     DALI_TEST_CHECK(false); // Should not get here
3363   }
3364   catch(...)
3365   {
3366     DALI_TEST_CHECK(true); // We expect an assert
3367   }
3368   END_TEST;
3369 }
3370
3371 int UtcDaliRenderTaskGetInputEnabledNegative(void)
3372 {
3373   TestApplication  application;
3374   Dali::RenderTask instance;
3375   try
3376   {
3377     instance.GetInputEnabled();
3378     DALI_TEST_CHECK(false); // Should not get here
3379   }
3380   catch(...)
3381   {
3382     DALI_TEST_CHECK(true); // We expect an assert
3383   }
3384   END_TEST;
3385 }
3386
3387 int UtcDaliRenderTaskViewportToLocalNegative(void)
3388 {
3389   TestApplication  application;
3390   Dali::RenderTask instance;
3391   try
3392   {
3393     Dali::Actor arg1(Actor::New());
3394     float       arg2(0.0f);
3395     float       arg3(0.0f);
3396     float       arg4(0.0f);
3397     float       arg5(0.0f);
3398     instance.ViewportToLocal(arg1, arg2, arg3, arg4, arg5);
3399     DALI_TEST_CHECK(false); // Should not get here
3400   }
3401   catch(...)
3402   {
3403     DALI_TEST_CHECK(true); // We expect an assert
3404   }
3405   END_TEST;
3406 }
3407
3408 int UtcDaliRenderTaskWorldToViewportNegative(void)
3409 {
3410   TestApplication  application;
3411   Dali::RenderTask instance;
3412   try
3413   {
3414     Dali::Vector3 arg1;
3415     float         arg2(0.0f);
3416     float         arg3(0.0f);
3417     instance.WorldToViewport(arg1, arg2, arg3);
3418     DALI_TEST_CHECK(false); // Should not get here
3419   }
3420   catch(...)
3421   {
3422     DALI_TEST_CHECK(true); // We expect an assert
3423   }
3424   END_TEST;
3425 }
3426
3427 int UtcDaliRenderTaskGetCurrentViewportSizeNegative(void)
3428 {
3429   TestApplication  application;
3430   Dali::RenderTask instance;
3431   try
3432   {
3433     instance.GetCurrentViewportSize();
3434     DALI_TEST_CHECK(false); // Should not get here
3435   }
3436   catch(...)
3437   {
3438     DALI_TEST_CHECK(true); // We expect an assert
3439   }
3440   END_TEST;
3441 }
3442
3443 int UtcDaliRenderTaskGetCurrentViewportPositionNegative(void)
3444 {
3445   TestApplication  application;
3446   Dali::RenderTask instance;
3447   try
3448   {
3449     instance.GetCurrentViewportPosition();
3450     DALI_TEST_CHECK(false); // Should not get here
3451   }
3452   catch(...)
3453   {
3454     DALI_TEST_CHECK(true); // We expect an assert
3455   }
3456   END_TEST;
3457 }
3458
3459 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionNegative(void)
3460 {
3461   TestApplication  application;
3462   Dali::RenderTask instance;
3463   try
3464   {
3465     instance.GetScreenToFrameBufferFunction();
3466     DALI_TEST_CHECK(false); // Should not get here
3467   }
3468   catch(...)
3469   {
3470     DALI_TEST_CHECK(true); // We expect an assert
3471   }
3472   END_TEST;
3473 }
3474
3475 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorNegative(void)
3476 {
3477   TestApplication  application;
3478   Dali::RenderTask instance;
3479   try
3480   {
3481     instance.GetScreenToFrameBufferMappingActor();
3482     DALI_TEST_CHECK(false); // Should not get here
3483   }
3484   catch(...)
3485   {
3486     DALI_TEST_CHECK(true); // We expect an assert
3487   }
3488   END_TEST;
3489 }
3490
3491 int UtcDaliRenderTaskClippingMode01(void)
3492 {
3493   TestApplication application;
3494
3495   tet_infoline("Testing clipping mode: CLIP_TO_BOUNDING_BOX.\n");
3496
3497   TestGlAbstraction& glAbstraction       = application.GetGlAbstraction();
3498   TraceCallStack&    enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
3499   TraceCallStack&    scissorTrace        = glAbstraction.GetScissorTrace();
3500
3501   enabledDisableTrace.Enable(true);
3502   scissorTrace.Enable(true);
3503
3504   // SETUP AN OFFSCREEN RENDER TASK
3505   Actor rootActor = Actor::New();
3506   application.GetScene().Add(rootActor);
3507
3508   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
3509   offscreenCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3510   offscreenCameraActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
3511   application.GetScene().Add(offscreenCameraActor);
3512
3513   Shader     shader     = CreateShader();
3514   Texture    image      = CreateTexture();
3515   TextureSet textureSet = CreateTextureSet(image);
3516
3517   Geometry geometry = CreateQuadGeometry();
3518   Renderer renderer = Renderer::New(geometry, shader);
3519   renderer.SetTextures(textureSet);
3520
3521   Vector2 position(100.0f, 100.0f);
3522   Vector2 size(200.0f, 200.0f);
3523   Actor   secondRootActor = Actor::New();
3524   secondRootActor.AddRenderer(renderer);
3525   secondRootActor.SetProperty(Actor::Property::POSITION, position);
3526   secondRootActor.SetProperty(Actor::Property::SIZE, size);
3527   secondRootActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
3528   secondRootActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
3529   secondRootActor.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
3530   application.GetScene().Add(secondRootActor);
3531
3532   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
3533
3534   application.SendNotification();
3535   application.Render();
3536
3537   std::ostringstream scissor;
3538   scissor << std::hex << GL_SCISSOR_TEST;
3539   DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
3540
3541   // Check the scissor was set, and the coordinates are correct.
3542   Vector4           expectResults(position.x, TestApplication::DEFAULT_SURFACE_HEIGHT - size.height - position.y, size.width, size.height); // (100, 500, 200, 200)
3543   std::stringstream compareParametersString;
3544   compareParametersString << expectResults.x << ", " << expectResults.y << ", " << expectResults.z << ", " << expectResults.w;
3545   DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", compareParametersString.str())); // Compare with the expected result
3546
3547   END_TEST;
3548 }
3549
3550 int UtcDaliRenderTaskClippingMode02(void)
3551 {
3552   TestApplication application;
3553
3554   tet_infoline("Testing clipping mode with the inverted camera: CLIP_TO_BOUNDING_BOX.\n");
3555
3556   TestGlAbstraction& glAbstraction       = application.GetGlAbstraction();
3557   TraceCallStack&    enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
3558   TraceCallStack&    scissorTrace        = glAbstraction.GetScissorTrace();
3559
3560   enabledDisableTrace.Enable(true);
3561   scissorTrace.Enable(true);
3562
3563   // SETUP AN OFFSCREEN RENDER TASK
3564   Actor rootActor = Actor::New();
3565   application.GetScene().Add(rootActor);
3566
3567   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
3568   offscreenCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3569   offscreenCameraActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
3570   offscreenCameraActor.SetInvertYAxis(true);
3571   application.GetScene().Add(offscreenCameraActor);
3572
3573   Shader     shader     = CreateShader();
3574   Texture    image      = CreateTexture();
3575   TextureSet textureSet = CreateTextureSet(image);
3576
3577   Geometry geometry = CreateQuadGeometry();
3578   Renderer renderer = Renderer::New(geometry, shader);
3579   renderer.SetTextures(textureSet);
3580
3581   Vector2 position(100.0f, 100.0f);
3582   Vector2 size(200.0f, 200.0f);
3583   Actor   secondRootActor = Actor::New();
3584   secondRootActor.AddRenderer(renderer);
3585   secondRootActor.SetProperty(Actor::Property::POSITION, position);
3586   secondRootActor.SetProperty(Actor::Property::SIZE, size);
3587   secondRootActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
3588   secondRootActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
3589   secondRootActor.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
3590   application.GetScene().Add(secondRootActor);
3591
3592   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
3593
3594   application.SendNotification();
3595   application.Render();
3596
3597   std::ostringstream scissor;
3598   scissor << std::hex << GL_SCISSOR_TEST;
3599   DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
3600
3601   // Check the scissor was set, and the coordinates are correct.
3602   Vector4           expectResults(position.x, position.y, size.width, size.height); // (100, 100, 200, 200)
3603   std::stringstream compareParametersString;
3604   compareParametersString << expectResults.x << ", " << expectResults.y << ", " << expectResults.z << ", " << expectResults.w;
3605   DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", compareParametersString.str())); // Compare with the expected result
3606
3607   END_TEST;
3608 }
3609
3610 int UtcDaliRenderTaskUploadOnly(void)
3611 {
3612   TestApplication application;
3613
3614   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image");
3615
3616   // SETUP AN OFFSCREEN RENDER TASK
3617   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
3618   auto&           sync      = application.GetGraphicsSyncImpl();
3619   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3620   drawTrace.Enable(true);
3621
3622   Actor rootActor = Actor::New();
3623   application.GetScene().Add(rootActor);
3624
3625   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
3626   application.GetScene().Add(offscreenCameraActor);
3627   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
3628
3629   application.GetScene().Add(secondRootActor);
3630
3631   RenderTask         newTask  = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
3632   bool               finished = false;
3633   RenderTaskFinished renderTaskFinished(finished);
3634   newTask.FinishedSignal().Connect(&application, renderTaskFinished);
3635   application.SendNotification();
3636
3637   DALI_TEST_CHECK(UpdateRender(application, drawTrace, true, finished, false, true, __LINE__));
3638
3639   Integration::GraphicsSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
3640   DALI_TEST_CHECK(lastSyncObj != NULL);
3641   sync.SetObjectSynced(lastSyncObj, true);
3642
3643   application.SendNotification();
3644   application.Render(16, nullptr, true);
3645
3646   DALI_TEST_CHECK(!finished);
3647
3648   application.Render(16, nullptr, true);
3649   application.SendNotification();
3650
3651   DALI_TEST_CHECK(!finished);
3652   END_TEST;
3653 }
3654
3655 int UtcDaliRenderTaskSetGetViewportGuideActor(void)
3656 {
3657   TestApplication application;
3658   tet_infoline("Testing RenderTask with Set/Get ViewportGuideActor");
3659
3660   Stage   stage = Stage::GetCurrent();
3661   Vector2 stageSize(stage.GetSize());
3662
3663   Actor blue                                 = Actor::New();
3664   blue[Dali::Actor::Property::NAME]          = "Blue";
3665   blue[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
3666   blue[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
3667   blue[Dali::Actor::Property::SIZE]          = Vector2(300, 300);
3668   blue[Dali::Actor::Property::POSITION]      = Vector2(0, 0);
3669
3670   stage.Add(blue);
3671
3672   RenderTaskList renderTaskList = stage.GetRenderTaskList();
3673   RenderTask     renderTask     = renderTaskList.CreateTask();
3674
3675   renderTask.SetViewportGuideActor(blue);
3676
3677   Actor actor = renderTask.GetViewportGuideActor();
3678   DALI_TEST_EQUALS(actor, blue, TEST_LOCATION);
3679
3680   renderTask.ResetViewportGuideActor();
3681   actor = renderTask.GetViewportGuideActor();
3682
3683   DALI_TEST_CHECK(!actor);
3684
3685   END_TEST;
3686 }
3687
3688 int UtcDaliRenderTaskViewportGuideActor(void)
3689 {
3690   TestApplication application;
3691   tet_infoline("Testing RenderTask with ViewportGuideActor");
3692
3693   Stage   stage = Stage::GetCurrent();
3694   Vector2 stageSize(stage.GetSize());
3695
3696   Actor blue                                 = Actor::New();
3697   blue[Dali::Actor::Property::NAME]          = "Blue";
3698   blue[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
3699   blue[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
3700   blue[Dali::Actor::Property::SIZE]          = Vector2(300, 300);
3701   blue[Dali::Actor::Property::POSITION]      = Vector2(0, 0);
3702
3703   Geometry geometry = Geometry::New();
3704   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3705   Renderer renderer = Renderer::New(geometry, shader);
3706   blue.AddRenderer(renderer);
3707
3708   stage.Add(blue);
3709
3710   RenderTaskList renderTaskList = stage.GetRenderTaskList();
3711   RenderTask     renderTask     = renderTaskList.CreateTask();
3712
3713   Dali::CameraActor cameraActor                     = Dali::CameraActor::New(stageSize);
3714   cameraActor[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
3715   cameraActor[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
3716   stage.Add(cameraActor);
3717
3718   renderTask.SetExclusive(true);
3719   renderTask.SetInputEnabled(true);
3720   renderTask.SetCameraActor(cameraActor);
3721   renderTask.SetSourceActor(blue);
3722   renderTask.SetViewportGuideActor(blue);
3723
3724   // Render and notify
3725   application.SendNotification();
3726   application.Render(16);
3727
3728   Vector2 viewportPosition = renderTask.GetCurrentViewportPosition();
3729   Vector2 viewportSize     = renderTask.GetCurrentViewportSize();
3730
3731   DALI_TEST_EQUALS(viewportSize, Vector2(300, 300), TEST_LOCATION);
3732   DALI_TEST_EQUALS(viewportPosition, Vector2(90, 250), TEST_LOCATION);
3733
3734   END_TEST;
3735 }
3736
3737 int UtcDaliRenderTaskViewportGuideActor02(void)
3738 {
3739   TestApplication application(
3740     TestApplication::DEFAULT_SURFACE_WIDTH,
3741     TestApplication::DEFAULT_SURFACE_HEIGHT,
3742     TestApplication::DEFAULT_HORIZONTAL_DPI,
3743     TestApplication::DEFAULT_VERTICAL_DPI,
3744     true,
3745     true);
3746   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3747   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
3748   glAbstraction.EnableViewportCallTrace(true);
3749   tet_infoline("Testing RenderTask with ViewportGuideActor02");
3750
3751   Stage   stage = Stage::GetCurrent();
3752   Vector2 stageSize(stage.GetSize());
3753
3754   // Render and notify
3755   application.SendNotification();
3756   application.Render(16);
3757   glAbstraction.ResetViewportCallStack();
3758
3759   Geometry geometry = Geometry::New();
3760   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3761   Renderer renderer = Renderer::New(geometry, shader);
3762
3763   Actor blue                                 = Actor::New();
3764   blue[Dali::Actor::Property::NAME]          = "Blue";
3765   blue[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::TOP_LEFT;
3766   blue[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
3767   blue[Dali::Actor::Property::SIZE]          = Vector2(400, 300);
3768   blue[Dali::Actor::Property::POSITION]      = Vector2(100, 50);
3769   blue.AddRenderer(renderer);
3770   stage.Add(blue);
3771
3772   Actor green                                 = Actor::New();
3773   green[Dali::Actor::Property::NAME]          = "Green";
3774   green[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::TOP_LEFT;
3775   green[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
3776   green[Dali::Actor::Property::SIZE]          = Vector2(400, 300);
3777   green[Dali::Actor::Property::POSITION]      = Vector2(100, 50);
3778   green.AddRenderer(renderer);
3779   stage.Add(green);
3780
3781   RenderTaskList renderTaskList = stage.GetRenderTaskList();
3782   RenderTask     renderTask     = renderTaskList.CreateTask();
3783
3784   Dali::CameraActor cameraActor                     = Dali::CameraActor::New(stageSize);
3785   cameraActor[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
3786   cameraActor[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
3787   stage.Add(cameraActor);
3788
3789   renderTask.SetExclusive(true);
3790   renderTask.SetInputEnabled(true);
3791   renderTask.SetCameraActor(cameraActor);
3792   renderTask.SetSourceActor(blue);
3793   renderTask.SetViewportGuideActor(blue);
3794
3795   application.GetScene().SurfaceRotated(static_cast<float>(TestApplication::DEFAULT_SURFACE_HEIGHT),
3796                                         static_cast<float>(TestApplication::DEFAULT_SURFACE_WIDTH),
3797                                         90,
3798                                         0);
3799
3800   // Render and notify
3801   application.SendNotification();
3802   application.Render(16);
3803
3804   std::string viewportParams1("50, 100, 300, 400"); // to match newSize
3805   std::string viewportParams2("0, 0, 480, 800");    // to match newSize
3806
3807   // Check that the viewport is handled properly
3808   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams1) >= 0);
3809   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams2) >= 0);
3810
3811   END_TEST;
3812 }
3813
3814 int UtcDaliRenderTaskViewportGuideActor03(void)
3815 {
3816   TestApplication application(
3817     TestApplication::DEFAULT_SURFACE_WIDTH,
3818     TestApplication::DEFAULT_SURFACE_HEIGHT,
3819     TestApplication::DEFAULT_HORIZONTAL_DPI,
3820     TestApplication::DEFAULT_VERTICAL_DPI,
3821     true,
3822     true);
3823
3824   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3825   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
3826   glAbstraction.EnableViewportCallTrace(true);
3827   tet_infoline("Testing that adding a viewport guide actor to RenderTask will change the viewport");
3828
3829   Stage   stage = Stage::GetCurrent();
3830   Vector2 stageSize(stage.GetSize());
3831
3832   // Render and notify
3833   application.SendNotification();
3834   application.Render(16);
3835   glAbstraction.ResetViewportCallStack();
3836
3837   Geometry geometry = Geometry::New();
3838   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3839   Renderer renderer = Renderer::New(geometry, shader);
3840
3841   Actor blue                                 = Actor::New();
3842   blue[Dali::Actor::Property::NAME]          = "Blue";
3843   blue[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::TOP_LEFT;
3844   blue[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
3845   blue[Dali::Actor::Property::SIZE]          = Vector2(400, 300);
3846   blue[Dali::Actor::Property::POSITION]      = Vector2(100, 50);
3847   blue.AddRenderer(renderer);
3848   stage.Add(blue);
3849
3850   Actor green                                 = Actor::New();
3851   green[Dali::Actor::Property::NAME]          = "Green";
3852   green[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::TOP_LEFT;
3853   green[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
3854   green[Dali::Actor::Property::SIZE]          = Vector2(400, 300);
3855   green[Dali::Actor::Property::POSITION]      = Vector2(100, 50);
3856   green.AddRenderer(renderer);
3857   stage.Add(green);
3858
3859   RenderTaskList renderTaskList = stage.GetRenderTaskList();
3860   RenderTask     renderTask     = renderTaskList.CreateTask();
3861
3862   Dali::CameraActor cameraActor                     = Dali::CameraActor::New(stageSize);
3863   cameraActor[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
3864   cameraActor[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
3865   stage.Add(cameraActor);
3866
3867   renderTask.SetExclusive(true);
3868   renderTask.SetInputEnabled(true);
3869   renderTask.SetCameraActor(cameraActor);
3870   renderTask.SetSourceActor(green);
3871
3872   Viewport viewport(75, 55, 150, 250);
3873   renderTask.SetViewport(viewport);
3874
3875   // Render and notify
3876   application.SendNotification();
3877   application.Render(16);
3878
3879   // Note Y pos: 800 - (250+55) = 495
3880   std::string viewportParams1("75, 495, 150, 250");
3881   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams1) >= 0);
3882   glAbstraction.ResetViewportCallStack();
3883
3884   // Update to use viewport guide actor instead.
3885   renderTask.SetViewportGuideActor(blue);
3886
3887   // Render and notify
3888   application.SendNotification();
3889   application.Render(16);
3890
3891   // Note: Y pos: 800 - (300+50) = 450
3892   std::string viewportParams2("100, 450, 400, 300");
3893   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams2) >= 0);
3894   tet_infoline("Testing that removing viewport guide actor from RenderTask will revert the viewport");
3895   glAbstraction.ResetViewportCallStack();
3896
3897   // Remove guide actor, expect that the viewport is reset to its original values
3898   renderTask.SetViewportGuideActor(Actor());
3899   application.SendNotification();
3900   application.Render(16);
3901
3902   // Currently, update manager does not consider that added Resetters should cause another
3903   // update; this is probably right. But, we have to then force another update for the resetter to trigger, and this will register as un-necessary in the test output.
3904   //
3905   application.SendNotification();
3906   application.Render(16);
3907
3908   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams1) >= 0);
3909
3910   END_TEST;
3911 }
3912
3913 int UtcDaliRenderTaskViewportGuideActor04(void)
3914 {
3915   TestApplication application(
3916     TestApplication::DEFAULT_SURFACE_WIDTH,
3917     TestApplication::DEFAULT_SURFACE_HEIGHT,
3918     TestApplication::DEFAULT_HORIZONTAL_DPI,
3919     TestApplication::DEFAULT_VERTICAL_DPI,
3920     true,
3921     true);
3922
3923   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3924   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
3925   glAbstraction.EnableViewportCallTrace(true);
3926   tet_infoline("Testing that adding a viewport guide actor to RenderTask will change the viewport");
3927
3928   Stage   stage = Stage::GetCurrent();
3929   Vector2 stageSize(stage.GetSize());
3930
3931   // Render and notify
3932   application.SendNotification();
3933   application.Render(16);
3934   glAbstraction.ResetViewportCallStack();
3935
3936   Geometry geometry = Geometry::New();
3937   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3938   Renderer renderer = Renderer::New(geometry, shader);
3939
3940   Actor blue                                 = Actor::New();
3941   blue[Dali::Actor::Property::NAME]          = "Blue";
3942   blue[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::TOP_LEFT;
3943   blue[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
3944   blue[Dali::Actor::Property::SIZE]          = Vector2(400, 300);
3945   blue[Dali::Actor::Property::POSITION]      = Vector2(100, 50);
3946   blue.AddRenderer(renderer);
3947   stage.Add(blue);
3948
3949   Actor green                                 = Actor::New();
3950   green[Dali::Actor::Property::NAME]          = "Green";
3951   green[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::TOP_LEFT;
3952   green[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
3953   green[Dali::Actor::Property::SIZE]          = Vector2(400, 300);
3954   green[Dali::Actor::Property::POSITION]      = Vector2(100, 50);
3955   green.AddRenderer(renderer);
3956   stage.Add(green);
3957
3958   RenderTaskList renderTaskList = stage.GetRenderTaskList();
3959   RenderTask     renderTask     = renderTaskList.CreateTask();
3960
3961   Dali::CameraActor cameraActor                     = Dali::CameraActor::New(stageSize);
3962   cameraActor[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
3963   cameraActor[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
3964   stage.Add(cameraActor);
3965
3966   renderTask.SetExclusive(true);
3967   renderTask.SetInputEnabled(true);
3968   renderTask.SetCameraActor(cameraActor);
3969   renderTask.SetSourceActor(green);
3970
3971   Viewport viewport(75, 55, 150, 250);
3972   renderTask.SetViewport(viewport);
3973
3974   // Render and notify
3975   application.SendNotification();
3976   application.Render(16);
3977
3978   // Note Y pos: 800 - (250+55) = 495
3979   std::string viewportParams1("75, 495, 150, 250");
3980   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams1) >= 0);
3981   glAbstraction.ResetViewportCallStack();
3982
3983   // Update to use viewport guide actor instead.
3984   renderTask.SetViewportGuideActor(blue);
3985
3986   // Render and notify
3987   application.SendNotification();
3988   application.Render(16);
3989
3990   std::string viewportParams2("100, 450, 400, 300");
3991   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams2) >= 0);
3992   tet_infoline("Testing that removing viewport guide actor from RenderTask will revert the viewport");
3993
3994   glAbstraction.ResetViewportCallStack();
3995
3996   // Remove guide actor, expect that the viewport is reset to it's original values
3997   renderTask.ResetViewportGuideActor();
3998   application.SendNotification();
3999   application.Render(16);
4000
4001   // Currently, update manager does not consider that added Resetters should cause another
4002   // update; this is probably right. But, we have to then force another update for the resetter
4003   // to trigger, and this will register as un-necessary in the test output.
4004   application.SendNotification();
4005   application.Render(16);
4006
4007   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams1) >= 0);
4008
4009   // This should remove the baking resetters, but is again going to show up
4010   // as unnecessary. Also try and figure out if we can test the dirty flags
4011   // here, somehow (Can at least check the property's dirty flags in the debugger).
4012   application.SendNotification();
4013   application.Render(16);
4014
4015   END_TEST;
4016 }
4017
4018 int UtcDaliRenderTaskSetPartialUpdate(void)
4019 {
4020   TestApplication application(
4021     TestApplication::DEFAULT_SURFACE_WIDTH,
4022     TestApplication::DEFAULT_SURFACE_HEIGHT,
4023     TestApplication::DEFAULT_HORIZONTAL_DPI,
4024     TestApplication::DEFAULT_VERTICAL_DPI,
4025     true,
4026     true);
4027
4028   tet_infoline("Check the damaged rects with render task");
4029
4030   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4031
4032   Actor actor = CreateRenderableActor();
4033   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4034   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4035   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4036   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4037   application.GetScene().Add(actor);
4038
4039   Actor rootActor = CreateRenderableActor();
4040   rootActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4041   rootActor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4042   rootActor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4043   rootActor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4044   application.GetScene().Add(rootActor);
4045
4046   CameraActor cameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT));
4047   cameraActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
4048   cameraActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
4049   application.GetScene().Add(cameraActor);
4050
4051   Texture     frameBufferTexture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 16, 16);
4052   FrameBuffer frameBuffer        = FrameBuffer::New(frameBufferTexture.GetWidth(), frameBufferTexture.GetHeight());
4053   frameBuffer.AttachColorTexture(frameBufferTexture);
4054
4055   // Create a RenderTask and set a framebuffer
4056   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
4057   RenderTask     newTask  = taskList.CreateTask();
4058   newTask.SetCameraActor(cameraActor);
4059   newTask.SetSourceActor(rootActor);
4060   newTask.SetInputEnabled(false);
4061   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
4062   newTask.SetClearEnabled(true);
4063   newTask.SetExclusive(true);
4064   newTask.SetRefreshRate(RenderTask::REFRESH_ALWAYS);
4065   newTask.SetFrameBuffer(frameBuffer);
4066
4067   application.SendNotification();
4068
4069   std::vector<Rect<int>> damagedRects;
4070   Rect<int>              clippingRect;
4071
4072   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4073
4074   // Full update if there is off-screen rendering
4075   clippingRect = Rect<int>(0, 0, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
4076   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4077   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4078
4079   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4080   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4081   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4082   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4083   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4084
4085   // Remove framebuffer
4086   newTask.SetFrameBuffer(FrameBuffer());
4087
4088   application.SendNotification();
4089
4090   damagedRects.clear();
4091   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4092
4093   // Full update
4094   clippingRect = Rect<int>(0, 0, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
4095   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4096   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4097
4098   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4099
4100   // Set invalid viewport of the render task
4101   newTask.SetViewportSize(Vector2(-100.0f, -100.0f));
4102
4103   application.SendNotification();
4104
4105   damagedRects.clear();
4106   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4107
4108   // Full update because the camera orientation is changed
4109   clippingRect = Rect<int>(0, 0, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
4110   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4111   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4112
4113   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4114
4115   newTask.SetViewportSize(Vector2(0.0f, 0.0f));
4116
4117   // Change orientation of offscreen camera
4118   cameraActor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Degree(90.0f), Vector3::XAXIS));
4119
4120   application.SendNotification();
4121
4122   damagedRects.clear();
4123   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4124
4125   // Full update because the camera orientation is changed
4126   clippingRect = Rect<int>(0, 0, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
4127   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4128   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4129
4130   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4131
4132   // Change camera target
4133   cameraActor.SetTargetPosition(Vector3(10.0f, 10.0f, 0.0f));
4134
4135   application.SendNotification();
4136
4137   damagedRects.clear();
4138   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4139
4140   // Full update because the camera is moved
4141   clippingRect = Rect<int>(0, 0, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
4142   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4143   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4144
4145   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4146
4147   END_TEST;
4148 }
4149
4150 int UtcDaliRenderTaskRenderPassTag(void)
4151 {
4152   TestApplication application;
4153   tet_infoline("Testing RenderTask with RenderPassTag");
4154
4155   Stage   stage = Stage::GetCurrent();
4156   Vector2 stageSize(stage.GetSize());
4157
4158   Actor blue                                 = Actor::New();
4159   blue[Dali::Actor::Property::NAME]          = "Blue";
4160   blue[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
4161   blue[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
4162   blue[Dali::Actor::Property::SIZE]          = Vector2(300, 300);
4163   blue[Dali::Actor::Property::POSITION]      = Vector2(0, 0);
4164
4165   Geometry geometry = Geometry::New();
4166
4167   Property::Map map[2];
4168   map[0]["vertex"]        = SHADER_COLOR_TEST_SHADER_VERT1.data();
4169   map[0]["fragment"]      = SHADER_COLOR_TEST_SHADER_FRAG.data();
4170   map[0]["renderPassTag"] = 0;
4171
4172   map[1]["vertex"]        = SHADER_COLOR_TEST_SHADER_VERT2.data();
4173   map[1]["fragment"]      = SHADER_COLOR_TEST_SHADER_FRAG.data();
4174   map[1]["renderPassTag"] = 1;
4175
4176   Property::Array array;
4177   array.PushBack(map[0]);
4178   array.PushBack(map[1]);
4179
4180   Shader   shader   = Shader::New(array);
4181   Renderer renderer = Renderer::New(geometry, shader);
4182   blue.AddRenderer(renderer);
4183
4184   stage.Add(blue);
4185
4186   auto& gfx = application.GetGraphicsController();
4187   gfx.mCallStack.EnableLogging(true);
4188
4189   RenderTaskList renderTaskList = stage.GetRenderTaskList();
4190   DALI_TEST_EQUALS(0u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4191   // Render and notify
4192   application.SendNotification();
4193   application.Render(16);
4194   DALI_TEST_CHECK(gfx.mCallStack.FindMethod("CreatePipeline"));
4195   gfx.mCallStack.Reset();
4196   DALI_TEST_EQUALS(0u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4197
4198   renderTaskList.GetTask(0u).SetRenderPassTag(1u);
4199   DALI_TEST_EQUALS(1u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4200   // Render and notify
4201   application.SendNotification();
4202   application.Render(16);
4203   DALI_TEST_CHECK(gfx.mCallStack.FindMethod("CreatePipeline"));
4204   gfx.mCallStack.Reset();
4205   DALI_TEST_EQUALS(1u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4206
4207   renderTaskList.GetTask(0u).SetRenderPassTag(0u);
4208   DALI_TEST_EQUALS(0u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4209   // Render and notify
4210   application.SendNotification();
4211   application.Render(16);
4212   DALI_TEST_CHECK(!gfx.mCallStack.FindMethod("CreatePipeline"));
4213   gfx.mCallStack.Reset();
4214   DALI_TEST_EQUALS(0u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4215
4216   renderTaskList.GetTask(0u).SetRenderPassTag(1u);
4217   DALI_TEST_EQUALS(1u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4218   // Render and notify
4219   application.SendNotification();
4220   application.Render(16);
4221   DALI_TEST_CHECK(!gfx.mCallStack.FindMethod("CreatePipeline"));
4222   gfx.mCallStack.Reset();
4223   DALI_TEST_EQUALS(1u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4224
4225   END_TEST;
4226 }
4227
4228 int UtcDaliRenderTaskWithWrongShaderData(void)
4229 {
4230   TestApplication application;
4231   tet_infoline("Testing RenderTask with wrong shader data");
4232
4233   Stage   stage = Stage::GetCurrent();
4234   Vector2 stageSize(stage.GetSize());
4235
4236   Actor blue                                 = Actor::New();
4237   blue[Dali::Actor::Property::NAME]          = "Blue";
4238   blue[Dali::Actor::Property::ANCHOR_POINT]  = AnchorPoint::CENTER;
4239   blue[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
4240   blue[Dali::Actor::Property::SIZE]          = Vector2(300, 300);
4241   blue[Dali::Actor::Property::POSITION]      = Vector2(0, 0);
4242
4243   Geometry geometry = Geometry::New();
4244
4245   Shader   shader   = Shader::New(Property::Value(10.0f));
4246   Renderer renderer = Renderer::New(geometry, shader);
4247   blue.AddRenderer(renderer);
4248
4249   stage.Add(blue);
4250
4251   auto& gfx = application.GetGraphicsController();
4252
4253   RenderTaskList renderTaskList = stage.GetRenderTaskList();
4254   DALI_TEST_EQUALS(0u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4255   // Render and notify
4256   application.SendNotification();
4257   application.Render(16);
4258   DALI_TEST_CHECK(!gfx.mCallStack.FindMethod("CreatePipeline"));
4259   gfx.mCallStack.Reset();
4260   DALI_TEST_EQUALS(0u, renderTaskList.GetTask(0u).GetRenderPassTag(), TEST_LOCATION);
4261
4262   END_TEST;
4263 }
4264
4265 int UtcDaliRenderTaskOrderIndex01(void)
4266 {
4267   TestApplication application;
4268   tet_infoline("Testing RenderTask with OrderIndex");
4269
4270   Stage   stage = Stage::GetCurrent();
4271   Vector2 stageSize(stage.GetSize());
4272
4273   RenderTaskList renderTaskList = stage.GetRenderTaskList();
4274   RenderTask     renderTask1    = renderTaskList.CreateTask();
4275
4276   application.SendNotification();
4277   uint32_t       answer1[2]     = {0u, 0u};
4278   DALI_TEST_EQUALS(2, renderTaskList.GetTaskCount(), TEST_LOCATION);
4279   for(uint32_t i = 0; i < 2; ++i)
4280   {
4281     DALI_TEST_EQUALS(answer1[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4282   }
4283
4284   RenderTask renderTask2 = renderTaskList.CreateTask();
4285   application.SendNotification();
4286   int32_t answer2[3] = {0u, 0u, 0u};
4287   DALI_TEST_EQUALS(3, renderTaskList.GetTaskCount(), TEST_LOCATION);
4288   for(uint32_t i = 0; i < 3; ++i)
4289   {
4290     DALI_TEST_EQUALS(answer2[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4291   }
4292
4293   RenderTask renderTask3 = renderTaskList.CreateTask();
4294   application.SendNotification();
4295   int32_t answer3[4] = {0u, 0u, 0u, 0u};
4296   DALI_TEST_EQUALS(4, renderTaskList.GetTaskCount(), TEST_LOCATION);
4297   for(uint32_t i = 0; i < 4; ++i)
4298   {
4299     DALI_TEST_EQUALS(answer3[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4300   }
4301
4302   renderTask1.SetOrderIndex(3);
4303   application.SendNotification();
4304   int32_t answer4[4] = {0u, 0u, 0u, 3u};
4305   for(uint32_t i = 0; i < 4; ++i)
4306   {
4307     DALI_TEST_EQUALS(answer4[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4308   }
4309
4310   renderTask2.SetOrderIndex(7);
4311   application.SendNotification();
4312   int32_t answer5[4] = {0u, 0u, 3u, 7u};
4313   for(uint32_t i = 0; i < 4; ++i)
4314   {
4315     DALI_TEST_EQUALS(answer5[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4316   }
4317
4318   Dali::Integration::Scene scene = application.GetScene();
4319   scene.GetOverlayLayer();
4320   application.SendNotification();
4321   DALI_TEST_EQUALS(5, renderTaskList.GetTaskCount(), TEST_LOCATION);
4322   int32_t answer6[5] = {0u, 0u, 3u, 7u, INT32_MAX};
4323   for(uint32_t i = 0; i < 5; ++i)
4324   {
4325     DALI_TEST_EQUALS(answer6[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4326   }
4327
4328   renderTask3.SetOrderIndex(4);
4329   application.SendNotification();
4330   int32_t answer7[5] = {0u, 3u, 4u, 7u, INT32_MAX};
4331   for(uint32_t i = 0; i < 5; ++i)
4332   {
4333     DALI_TEST_EQUALS(answer7[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4334   }
4335
4336   renderTask2.SetOrderIndex(2);
4337   application.SendNotification();
4338   int32_t answer8[5] = {0u, 2u, 3u, 4u, INT32_MAX};
4339   for(uint32_t i = 0; i < 5; ++i)
4340   {
4341     DALI_TEST_EQUALS(answer8[i], renderTaskList.GetTask(i).GetOrderIndex(), TEST_LOCATION);
4342   }
4343
4344   END_TEST;
4345 }
4346
4347 int UtcDaliRenderTaskOrderIndex02(void)
4348 {
4349   TestApplication application;
4350   tet_infoline("Testing RenderTask with OrderIndex");
4351
4352   Stage   stage = Stage::GetCurrent();
4353   Vector2 stageSize(stage.GetSize());
4354
4355   RenderTaskList renderTaskList = stage.GetRenderTaskList();
4356   RenderTask     renderTask1    = renderTaskList.CreateTask();
4357   application.SendNotification();
4358   DALI_TEST_EQUALS(renderTask1, renderTaskList.GetTask(1u), TEST_LOCATION);
4359   
4360   RenderTask     renderTask2    = renderTaskList.CreateTask();
4361   application.SendNotification();
4362   DALI_TEST_EQUALS(renderTask1, renderTaskList.GetTask(1u), TEST_LOCATION);
4363   DALI_TEST_EQUALS(renderTask2, renderTaskList.GetTask(2u), TEST_LOCATION);
4364
4365   RenderTask     renderTask3    = renderTaskList.CreateTask();
4366   application.SendNotification();
4367   DALI_TEST_EQUALS(renderTask1, renderTaskList.GetTask(1u), TEST_LOCATION);
4368   DALI_TEST_EQUALS(renderTask2, renderTaskList.GetTask(2u), TEST_LOCATION);
4369   DALI_TEST_EQUALS(renderTask3, renderTaskList.GetTask(3u), TEST_LOCATION);
4370
4371   RenderTask     renderTask4    = renderTaskList.CreateTask();
4372   application.SendNotification();
4373   DALI_TEST_EQUALS(renderTask1, renderTaskList.GetTask(1u), TEST_LOCATION);
4374   DALI_TEST_EQUALS(renderTask2, renderTaskList.GetTask(2u), TEST_LOCATION);
4375   DALI_TEST_EQUALS(renderTask3, renderTaskList.GetTask(3u), TEST_LOCATION);
4376   DALI_TEST_EQUALS(renderTask4, renderTaskList.GetTask(4u), TEST_LOCATION);
4377
4378   renderTask2.SetOrderIndex(2);
4379   application.SendNotification();
4380   DALI_TEST_EQUALS(renderTask1, renderTaskList.GetTask(1u), TEST_LOCATION);
4381   DALI_TEST_EQUALS(renderTask3, renderTaskList.GetTask(2u), TEST_LOCATION);
4382   DALI_TEST_EQUALS(renderTask4, renderTaskList.GetTask(3u), TEST_LOCATION);
4383   DALI_TEST_EQUALS(renderTask2, renderTaskList.GetTask(4u), TEST_LOCATION);
4384
4385   END_TEST;
4386 }
4387
4388 int UtcDaliRenderTaskGetRenderTaskId(void)
4389 {
4390   TestApplication application;
4391   tet_infoline("Testing RenderTask Id get");
4392
4393   Stage   stage = Stage::GetCurrent();
4394   Vector2 stageSize(stage.GetSize());
4395
4396   RenderTaskList renderTaskList = stage.GetRenderTaskList();
4397
4398   RenderTask renderTask1 = renderTaskList.CreateTask();
4399   RenderTask renderTask2 = renderTaskList.CreateTask();
4400   RenderTask renderTask3 = renderTaskList.CreateTask();
4401
4402   DALI_TEST_CHECK(renderTask1.GetRenderTaskId() != 0u);
4403   DALI_TEST_CHECK(renderTask2.GetRenderTaskId() != 0u);
4404   DALI_TEST_CHECK(renderTask3.GetRenderTaskId() != 0u);
4405   
4406   DALI_TEST_CHECK(renderTask1.GetRenderTaskId() != renderTask2.GetRenderTaskId());
4407   DALI_TEST_CHECK(renderTask2.GetRenderTaskId() != renderTask3.GetRenderTaskId());
4408   DALI_TEST_CHECK(renderTask3.GetRenderTaskId() != renderTask1.GetRenderTaskId());
4409
4410   END_TEST;
4411 }